Prevent nonce advance on call for erc20 methods

This commit is contained in:
nolash 2021-02-15 19:23:26 +01:00
parent b4531c22cc
commit 65af3c9e32
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
3 changed files with 9 additions and 8 deletions

View File

@ -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)

View File

@ -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):

View File

@ -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