commit 310ace824442b6a9e8debe3ecabac106fc23fda0
parent 772781c1b86dce03213232d216fba33f1bbc5f4b
Author: lash <dev@holbrook.no>
Date: Sat, 21 May 2022 21:05:28 +0000
Apply block number accept for block cli, non-pending nonce bootstrap
Diffstat:
4 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/chainlib/eth/cli/rpc.py b/chainlib/eth/cli/rpc.py
@@ -23,7 +23,7 @@ class Rpc(BaseRpc):
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.
@@ -38,9 +38,9 @@ class Rpc(BaseRpc):
except KeyError:
pass
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:
- 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_limit = None
diff --git a/chainlib/eth/nonce.py b/chainlib/eth/nonce.py
@@ -42,12 +42,12 @@ class NonceOracle(BaseNonceOracle):
:param id_generator: json-rpc id generator
: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
- 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.
"""
raise NotImplementedError('Class must be extended')
@@ -74,12 +74,12 @@ class RPCNonceOracle(NonceOracle):
:param id_generator: json-rpc id generator
: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
- 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.
Note! First call to next_nonce after calling get_nonce will return the same value!
@@ -87,7 +87,7 @@ class RPCNonceOracle(NonceOracle):
:rtype: int
: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)
n = strip_0x(r)
return int(n, 16)
@@ -103,13 +103,13 @@ class OverrideNonceOracle(NonceOracle):
:param id_generator: json-rpc id generator (not used)
: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.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.
:rtype: int
diff --git a/chainlib/eth/runnable/block.py b/chainlib/eth/runnable/block.py
@@ -112,7 +112,11 @@ logg.debug('settings loaded:\n{}'.format(settings))
def get_block(settings):
- hsh = settings.get('HASH')[0]
+ hsh = None
+ try:
+ hsh = settings.get('HASH')[0]
+ except TypeError:
+ pass
r = None
if hsh == None:
r = get_block_number(
diff --git a/chainlib/eth/settings.py b/chainlib/eth/settings.py
@@ -14,7 +14,7 @@ from chainlib.eth.address import to_checksum_address
def process_settings_rpc(settings, config):
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('RPC_ID_GENERATOR', rpc.id_generator)