@@ -58,11 +58,17 @@ def confirm_payments_for_event(self, event: Event, no_dry_run, log_verbosity=0):
5858 )
5959 )
6060 if log_verbosity > 0 :
61- logger .info (f" * Found { unconfirmed_order_payments .count ()} unconfirmed order payments" )
61+ logger .info (
62+ f" * Found { unconfirmed_order_payments .count ()} "
63+ f"unconfirmed order payments"
64+ )
6265
6366 for order_payment in unconfirmed_order_payments :
6467 if log_verbosity > 0 :
65- logger .info (f" * trying to confirm payment: { order_payment } (has { order_payment .signed_messages .all ().count ()} signed messages)" )
68+ logger .info (
69+ f" * trying to confirm payment: { order_payment } "
70+ f"(has { order_payment .signed_messages .all ().count ()} signed messages)"
71+ )
6672 # it is tempting to put .filter(invalid=False) here, but remember
6773 # there is still a chance that low-gas txs are mined later on.
6874 for signed_message in order_payment .signed_messages .all ():
@@ -89,44 +95,69 @@ def confirm_payments_for_event(self, event: Event, no_dry_run, log_verbosity=0):
8995 # Get balance
9096 w3 = Web3 (load_provider_from_uri (network_rpc_url ))
9197 if log_verbosity > 0 :
92- logger .info (f" * Looking for a receip for a transaction with hash={ signed_message .transaction_hash } " )
98+ logger .info (
99+ f" * Looking for a receip for a transaction with "
100+ f"hash={ signed_message .transaction_hash } "
101+ )
93102 try :
94103 receipt = w3 .eth .getTransactionReceipt (signed_message .transaction_hash )
95104 except TransactionNotFound :
96105 if log_verbosity > 0 :
97- logger .info (f" * Transaction hash={ signed_message .transaction_hash } not found, skipping." )
98- if signed_message .age > 30 * 60 :
106+ logger .info (
107+ f" * Transaction"
108+ f" hash={ signed_message .transaction_hash } not found,"
109+ f" skipping."
110+ )
111+ if signed_message .age > 30 * 60 :
99112 signed_message .invalidate ()
100113 continue
101114
102115 if receipt .status == 0 :
103116 if log_verbosity > 0 :
104- logger .info (f" * Transaction hash={ signed_message .transaction_hash } was has status=0, invalidating." )
117+ logger .info (
118+ f" * Transaction hash={ signed_message .transaction_hash } "
119+ f" was has status=0, invalidating."
120+ )
105121 signed_message .invalidate ()
106122 continue
107123
108124 block_number = receipt .blockNumber
109125
110- if block_number is None or block_number + SAFETY_BLOCK_COUNT > w3 .eth .get_block_number ():
111- logger .warning (f" * Transfer found in a block that is too young, waiting until at least { SAFETY_BLOCK_COUNT } more blocks are confirmed." )
126+ if (
127+ block_number is None
128+ or block_number + SAFETY_BLOCK_COUNT > w3 .eth .get_block_number ()
129+ ):
130+ logger .warning (
131+ f" * Transfer found in a block that is too young, "
132+ f"waiting until at least { SAFETY_BLOCK_COUNT } more blocks are confirmed."
133+ )
112134 continue
113135
114136 if token .IS_NATIVE_ASSET :
115137 # ETH
116- payment_amount = w3 .eth .getTransaction (signed_message .transaction_hash ).value
138+ payment_amount = w3 .eth .getTransaction (
139+ signed_message .transaction_hash ).value
117140 receipt_reciever = receipt .to .lower ()
118141 correct_recipient = receipt_reciever == signed_message .recipient_address .lower ()
119142
120143 else :
121144 # DAI
122- contract = w3 .eth .contract (address = token .ADDRESS , abi = TOKEN_ABI )
123- transaction_details = contract .events .Transfer ().processReceipt (receipt )[0 ].args
145+ contract = w3 .eth .contract (address = token .ADDRESS ,
146+ abi = TOKEN_ABI )
147+ transaction_details = \
148+ contract .events .Transfer ().processReceipt (receipt )[0 ].args
124149 payment_amount = transaction_details .value
125150 # check that the payment happened on the right contract address
126151 correct_contract = token .ADDRESS .lower () == receipt .to .lower ()
127- # take recipient address from the topics, not from the "from" field, as that's the contract address
128- receipt_reciever = receipt .logs [0 ].topics [2 ][12 :].hex ().lower ()
129- correct_recipient = correct_contract and (receipt_reciever == signed_message .recipient_address .lower ())
152+ # take recipient address from the topics,
153+ # not from the "from" field, as that's the contract address
154+ receipt_reciever = receipt .logs [0 ].topics [2 ][
155+ 12 :].hex ().lower ()
156+ correct_recipient = (
157+ correct_contract
158+ and (
159+ receipt_reciever == signed_message .recipient_address .lower ())
160+ )
130161
131162
132163 receipt_sender = getattr (receipt , 'from' ).lower ()
@@ -137,18 +168,26 @@ def confirm_payments_for_event(self, event: Event, no_dry_run, log_verbosity=0):
137168 f" * Transaction hash provided does not match correct sender and recipient"
138169 )
139170 if log_verbosity > 0 :
140- logger .info (f"receipt sender={ receipt_sender } , expected sender={ signed_message .sender_address .lower ()} " )
141- logger .info (f"receipt recipient={ receipt_reciever } , expected recipient={ signed_message .recipient_address .lower ()} " )
171+ logger .info (
172+ f"receipt sender={ receipt_sender } , "
173+ f"expected sender={ signed_message .sender_address .lower ()} "
174+ )
175+ logger .info (
176+ f"receipt recipient={ receipt_reciever } , "
177+ f"expected recipient={ signed_message .recipient_address .lower ()} "
178+ )
142179 continue
143180
144181 if payment_amount > 0 :
145182 logger .info (f"Payments found for { full_id } at { signed_message .sender_address } :" )
146183 if payment_amount < expected_amount :
147184 logger .warning (
148- f" * Expected payment of at least { expected_amount } { token .TOKEN_SYMBOL } "
185+ f" * Expected payment of at least"
186+ f" { expected_amount } { token .TOKEN_SYMBOL } "
149187 )
150188 logger .warning (
151- f" * Given payment was { payment_amount } { token .TOKEN_SYMBOL } "
189+ f" * Given payment was"
190+ f" { payment_amount } { token .TOKEN_SYMBOL } "
152191 )
153192 logger .warning (f" * Skipping" ) # noqa: F541
154193 continue
0 commit comments