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('address', recipient_address).hex()
data += abi_encode('uint256', value).hex() data += abi_encode('uint256', value).hex()
data = add_0x(data) 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) tx = self.set_code(tx, data)
return self.build(tx) return self.build(tx)

View File

@ -117,25 +117,26 @@ class TxFactory:
return (tx_hash_hex, o) return (tx_hash_hex, o)
def template(self, sender, recipient): def template(self, sender, recipient, use_nonce=False):
gas_price = MINIMUM_FEE_PRICE gas_price = MINIMUM_FEE_PRICE
if self.gas_oracle != None: if self.gas_oracle != None:
gas_price = self.gas_oracle.get() gas_price = self.gas_oracle.get()
logg.debug('using gas price {}'.format(gas_price)) logg.debug('using gas price {}'.format(gas_price))
nonce = 0 nonce = 0
if self.nonce_oracle != None: o = {
nonce = self.nonce_oracle.next()
logg.debug('using nonce {} for address {}'.format(nonce, sender))
return {
'from': sender, 'from': sender,
'to': recipient, 'to': recipient,
'value': 0, 'value': 0,
'data': '0x', 'data': '0x',
'nonce': nonce,
'gasPrice': gas_price, 'gasPrice': gas_price,
'gas': MINIMUM_FEE_UNITS, 'gas': MINIMUM_FEE_UNITS,
'chainId': self.chain_id, '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): def normalize(self, tx):

View File

@ -1,6 +1,6 @@
[metadata] [metadata]
name = chainlib name = chainlib
version = 0.0.1a7 version = 0.0.1a9
description = Generic blockchain access library and tooling description = Generic blockchain access library and tooling
author = Louis Holbrook author = Louis Holbrook
author_email = dev@holbrook.no author_email = dev@holbrook.no