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

This commit is contained in:
nolash 2021-08-26 17:10:39 +02:00
parent 5b1755e50d
commit 6c19cd38b0
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
7 changed files with 50 additions and 12 deletions

View File

@ -81,6 +81,11 @@ class Rpc(BaseRpc):
else: else:
self.fee_oracle = RPCGasOracle(self.conn, id_generator=self.id_generator) 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 return self.conn
@ -93,3 +98,18 @@ class Config(BaseConfig):
""" """
default_base_config_dir = os.path.join(script_dir, 'data', 'config') default_base_config_dir = os.path.join(script_dir, 'data', 'config')
default_fee_limit = 21000 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

View File

@ -17,10 +17,8 @@ from hexathon import (
) )
# local imports # local imports
from .error import ( from .error import RevertEthException
DefaultErrorParser, from chainlib.eth.dialect import DefaultErrorParser
RevertEthException,
)
from .sign import ( from .sign import (
sign_transaction, sign_transaction,
) )

View File

@ -3,6 +3,7 @@ http_provider = http://localhost:8545
http_authentication = http_authentication =
http_username = http_username =
http_password = http_password =
dialect = default
[chain] [chain]
spec = evm:ethereum:1 spec = evm:ethereum:1

View File

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

View File

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

View File

@ -24,10 +24,3 @@ class RequestMismatchException(EthException):
"""Raised when a request data parser is given unexpected input data. """Raised when a request data parser is given unexpected input data.
""" """
pass 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))

View File

@ -1,6 +1,6 @@
[metadata] [metadata]
name = chainlib-eth name = chainlib-eth
version = 0.0.9a4 version = 0.0.9a5
description = Ethereum implementation of the chainlib interface description = Ethereum implementation of the chainlib interface
author = Louis Holbrook author = Louis Holbrook
author_email = dev@holbrook.no author_email = dev@holbrook.no