Add openethereum error parser, add dialect processor to config from args
This commit is contained in:
parent
5b1755e50d
commit
6c19cd38b0
@ -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
|
||||
|
@ -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,
|
||||
)
|
||||
|
@ -3,6 +3,7 @@ http_provider = http://localhost:8545
|
||||
http_authentication =
|
||||
http_username =
|
||||
http_password =
|
||||
dialect = default
|
||||
|
||||
[chain]
|
||||
spec = evm:ethereum:1
|
||||
|
9
chainlib/eth/dialect/__init__.py
Normal file
9
chainlib/eth/dialect/__init__.py
Normal 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))
|
17
chainlib/eth/dialect/openethereum.py
Normal file
17
chainlib/eth/dialect/openethereum.py
Normal 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)
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user