commit 65af3c9e32e7f8e6b518d5127a10a9cc5f556db5
parent b4531c22ccbc37e3200dc2be0127f06cd22ddfc2
Author: nolash <dev@holbrook.no>
Date: Mon, 15 Feb 2021 19:23:26 +0100
Prevent nonce advance on call for erc20 methods
Diffstat:
3 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/chainlib/eth/erc20.py b/chainlib/eth/erc20.py
@@ -52,6 +52,6 @@ class ERC20TxFactory(TxFactory):
data += abi_encode('address', recipient_address).hex()
data += abi_encode('uint256', value).hex()
data = add_0x(data)
- tx = self.template(sender_address, contract_address)
+ tx = self.template(sender_address, contract_address, use_nonce=True)
tx = self.set_code(tx, data)
return self.build(tx)
diff --git a/chainlib/eth/tx.py b/chainlib/eth/tx.py
@@ -117,25 +117,26 @@ class TxFactory:
return (tx_hash_hex, o)
- def template(self, sender, recipient):
+ def template(self, sender, recipient, use_nonce=False):
gas_price = MINIMUM_FEE_PRICE
if self.gas_oracle != None:
gas_price = self.gas_oracle.get()
logg.debug('using gas price {}'.format(gas_price))
nonce = 0
- if self.nonce_oracle != None:
- nonce = self.nonce_oracle.next()
- logg.debug('using nonce {} for address {}'.format(nonce, sender))
- return {
+ o = {
'from': sender,
'to': recipient,
'value': 0,
'data': '0x',
- 'nonce': nonce,
'gasPrice': gas_price,
'gas': MINIMUM_FEE_UNITS,
'chainId': self.chain_id,
}
+ if self.nonce_oracle != None and use_nonce:
+ nonce = self.nonce_oracle.next()
+ logg.debug('using nonce {} for address {}'.format(nonce, sender))
+ o['nonce'] = nonce
+ return o
def normalize(self, tx):
diff --git a/setup.cfg b/setup.cfg
@@ -1,6 +1,6 @@
[metadata]
name = chainlib
-version = 0.0.1a7
+version = 0.0.1a9
description = Generic blockchain access library and tooling
author = Louis Holbrook
author_email = dev@holbrook.no