Apply block number accept for block cli, non-pending nonce bootstrap

This commit is contained in:
lash 2022-05-21 21:05:28 +00:00
parent 772781c1b8
commit 310ace8244
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
4 changed files with 19 additions and 15 deletions

View File

@ -23,7 +23,7 @@ class Rpc(BaseRpc):
super(Rpc, self).__init__(EthHTTPConnection, wallet=wallet) super(Rpc, self).__init__(EthHTTPConnection, wallet=wallet)
def connect_by_config(self, config): def connect_by_config(self, config, nonce_confirmed=True):
""" """
If the standard arguments for nonce and fee price/price have been defined (which generate the configuration keys "_NONCE", "_FEE_PRICE" and "_FEE_LIMIT" respectively) , the corresponding overrides for fee and nonce generators will be defined. If the standard arguments for nonce and fee price/price have been defined (which generate the configuration keys "_NONCE", "_FEE_PRICE" and "_FEE_LIMIT" respectively) , the corresponding overrides for fee and nonce generators will be defined.
@ -38,9 +38,9 @@ class Rpc(BaseRpc):
except KeyError: except KeyError:
pass pass
if nonce != None: if nonce != None:
self.nonce_oracle = OverrideNonceOracle(self.get_sender_address(), nonce, id_generator=self.id_generator) self.nonce_oracle = OverrideNonceOracle(self.get_sender_address(), nonce, confirmed=nonce_confirmed, id_generator=self.id_generator)
else: else:
self.nonce_oracle = RPCNonceOracle(self.get_sender_address(), self.conn, id_generator=self.id_generator) self.nonce_oracle = RPCNonceOracle(self.get_sender_address(), self.conn, confirmed=nonce_confirmed, id_generator=self.id_generator)
fee_price = None fee_price = None
fee_limit = None fee_limit = None

View File

@ -42,12 +42,12 @@ class NonceOracle(BaseNonceOracle):
:param id_generator: json-rpc id generator :param id_generator: json-rpc id generator
:type id_generator: chainlib.connection.JSONRPCIdGenerator :type id_generator: chainlib.connection.JSONRPCIdGenerator
""" """
def __init__(self, address, id_generator=None): def __init__(self, address, id_generator=None, confirmed=None):
self.id_generator = id_generator self.id_generator = id_generator
super(NonceOracle, self).__init__(add_0x(address)) super(NonceOracle, self).__init__(add_0x(address), confirmed=confirmed)
def get_nonce(self): def get_nonce(self, confirmed=False):
"""Load initial nonce value. """Load initial nonce value.
""" """
raise NotImplementedError('Class must be extended') raise NotImplementedError('Class must be extended')
@ -74,12 +74,12 @@ class RPCNonceOracle(NonceOracle):
:param id_generator: json-rpc id generator :param id_generator: json-rpc id generator
:type id_generator: chainlib.connection.JSONRPCIdGenerator :type id_generator: chainlib.connection.JSONRPCIdGenerator
""" """
def __init__(self, address, conn, id_generator=None): def __init__(self, address, conn, id_generator=None, confirmed=False):
self.conn = conn self.conn = conn
super(RPCNonceOracle, self).__init__(address, id_generator=id_generator) super(RPCNonceOracle, self).__init__(address, id_generator=id_generator, confirmed=confirmed)
def get_nonce(self): def get_nonce(self, confirmed=False):
"""Load and return nonce value from network. """Load and return nonce value from network.
Note! First call to next_nonce after calling get_nonce will return the same value! Note! First call to next_nonce after calling get_nonce will return the same value!
@ -87,7 +87,7 @@ class RPCNonceOracle(NonceOracle):
:rtype: int :rtype: int
:returns: Initial nonce :returns: Initial nonce
""" """
o = nonce(self.address, id_generator=self.id_generator) o = nonce(self.address, confirmed=confirmed, id_generator=self.id_generator)
r = self.conn.do(o) r = self.conn.do(o)
n = strip_0x(r) n = strip_0x(r)
return int(n, 16) return int(n, 16)
@ -103,13 +103,13 @@ class OverrideNonceOracle(NonceOracle):
:param id_generator: json-rpc id generator (not used) :param id_generator: json-rpc id generator (not used)
:type id_generator: chainlib.connection.JSONRPCIdGenerator :type id_generator: chainlib.connection.JSONRPCIdGenerator
""" """
def __init__(self, address, nonce, id_generator=None): def __init__(self, address, nonce, id_generator=None, confirmed=False):
self.initial_nonce = nonce self.initial_nonce = nonce
self.nonce = self.initial_nonce self.nonce = self.initial_nonce
super(OverrideNonceOracle, self).__init__(address, id_generator=id_generator) super(OverrideNonceOracle, self).__init__(address, id_generator=id_generator, confirmed=confirmed)
def get_nonce(self): def get_nonce(self, confirmed=False):
"""Returns initial nonce value set at object construction. """Returns initial nonce value set at object construction.
:rtype: int :rtype: int

View File

@ -112,7 +112,11 @@ logg.debug('settings loaded:\n{}'.format(settings))
def get_block(settings): def get_block(settings):
hsh = settings.get('HASH')[0] hsh = None
try:
hsh = settings.get('HASH')[0]
except TypeError:
pass
r = None r = None
if hsh == None: if hsh == None:
r = get_block_number( r = get_block_number(

View File

@ -14,7 +14,7 @@ from chainlib.eth.address import to_checksum_address
def process_settings_rpc(settings, config): def process_settings_rpc(settings, config):
rpc = chainlib.eth.cli.Rpc(settings.get('WALLET')) rpc = chainlib.eth.cli.Rpc(settings.get('WALLET'))
conn = rpc.connect_by_config(config) conn = rpc.connect_by_config(config, nonce_confirmed=True)
settings.set('CONN', conn) settings.set('CONN', conn)
settings.set('RPC_ID_GENERATOR', rpc.id_generator) settings.set('RPC_ID_GENERATOR', rpc.id_generator)