chainlib-eth

Ethereum implementation of the chainlib interface
Log | Files | Refs | README | LICENSE

commit 6c19cd38b075fff1a794688d96030f6a203d4061
parent 5b1755e50d5ab74194cc5140ee1315aa5012aa69
Author: nolash <dev@holbrook.no>
Date:   Thu, 26 Aug 2021 17:10:39 +0200

Add openethereum error parser, add dialect processor to config from args

Diffstat:
Mchainlib/eth/cli.py | 20++++++++++++++++++++
Mchainlib/eth/connection.py | 6++----
Mchainlib/eth/data/config/config.ini | 1+
Achainlib/eth/dialect/__init__.py | 9+++++++++
Achainlib/eth/dialect/openethereum.py | 17+++++++++++++++++
Mchainlib/eth/error.py | 7-------
Msetup.cfg | 2+-
7 files changed, 50 insertions(+), 12 deletions(-)

diff --git a/chainlib/eth/cli.py b/chainlib/eth/cli.py @@ -81,6 +81,11 @@ class Rpc(BaseRpc): else: self.fee_oracle = RPCGasOracle(self.conn, id_generator=self.id_generator) + error_parser = None + if config.get('RPC_DIALECT') == 'openethereum': + from chainlib.eth.dialect.openethereum import DialectErrorParser + self.error_parser = DialectErrorParser() + return self.conn @@ -93,3 +98,18 @@ class Config(BaseConfig): """ default_base_config_dir = os.path.join(script_dir, 'data', 'config') default_fee_limit = 21000 + + + @classmethod + def from_args(cls, args, arg_flags=0x0f, env=os.environ, extra_args={}, base_config_dir=None, default_config_dir=None, user_config_dir=None, default_fee_limit=None, logger=None, load_callback=None): + config = BaseConfig.from_args(args, arg_flags=arg_flags, env=env, extra_args=extra_args, base_config_dir=base_config_dir, default_config_dir=default_config_dir, user_config_dir=user_config_dir, default_fee_limit=default_fee_limit, logger=logger, load_callback=load_callback) + + if not config.get('RPC_DIALECT'): + config.add('default', 'RPC_DIALECT', exists_ok=True) + elif config.get('RPC_DIALECT') not in [ + 'openethereum', + 'default', + ]: + raise ValueError('unknown rpc dialect {}'.format(config.get('RPC_DIALECT'))) + + return config diff --git a/chainlib/eth/connection.py b/chainlib/eth/connection.py @@ -17,10 +17,8 @@ from hexathon import ( ) # local imports -from .error import ( - DefaultErrorParser, - RevertEthException, - ) +from .error import RevertEthException +from chainlib.eth.dialect import DefaultErrorParser from .sign import ( sign_transaction, ) diff --git a/chainlib/eth/data/config/config.ini b/chainlib/eth/data/config/config.ini @@ -3,6 +3,7 @@ http_provider = http://localhost:8545 http_authentication = http_username = http_password = +dialect = default [chain] spec = evm:ethereum:1 diff --git a/chainlib/eth/dialect/__init__.py b/chainlib/eth/dialect/__init__.py @@ -0,0 +1,9 @@ +# local imports +from chainlib.eth.error import EthException + + +class DefaultErrorParser: + """Generate eth specific exception for the default json-rpc query error parser. + """ + def translate(self, error): + return EthException('default parser codeĀ {}'.format(error)) diff --git a/chainlib/eth/dialect/openethereum.py b/chainlib/eth/dialect/openethereum.py @@ -0,0 +1,17 @@ +# standard imports +import logging + +# local imports +from chainlib.eth.dialect import DefaultErrorParser +from chainlib.error import RPCNonceException + +logg = logging.getLogger(__name__) + + +class DialectErrorParser(DefaultErrorParser): + + def translate(self, error): + if error['error']['code'] == -32010: + if 'nonce is too low' in error['error']['message']: + return RPCNonceException(error) + return super(DialectErrorParser, self).translate(error) diff --git a/chainlib/eth/error.py b/chainlib/eth/error.py @@ -24,10 +24,3 @@ class RequestMismatchException(EthException): """Raised when a request data parser is given unexpected input data. """ pass - - -class DefaultErrorParser: - """Generate eth specific exception for the default json-rpc query error parser. - """ - def translate(self, error): - return EthException('default parser codeĀ {}'.format(error)) diff --git a/setup.cfg b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = chainlib-eth -version = 0.0.9a4 +version = 0.0.9a5 description = Ethereum implementation of the chainlib interface author = Louis Holbrook author_email = dev@holbrook.no