commit a2c71c87d140e03d31395d1c81638285328628a3
parent 9db62c29643877fb203cd50e7a2bd59f01b6f2d2
Author: nolash <dev@holbrook.no>
Date: Thu, 26 Aug 2021 17:08:45 +0200
Implement rpc dialect arg setting
Diffstat:
5 files changed, 26 insertions(+), 0 deletions(-)
diff --git a/chainlib/cli/arg.py b/chainlib/cli/arg.py
@@ -137,6 +137,7 @@ class ArgumentParser(argparse.ArgumentParser):
self.add_argument('--env-prefix', default=env.get('CONFINI_ENV_PREFIX'), dest='env_prefix', type=str, help='environment prefix for variables to overwrite configuration')
if arg_flags & Flag.PROVIDER:
self.add_argument('-p', '--provider', dest='p', type=str, help='RPC HTTP(S) provider url')
+ self.add_argument('--rpc-dialect', dest='rpc_dialect', type=str, help='RPC HTTP(S) backend dialect')
self.add_argument('--height', default='latest', help='Block height to execute against')
if arg_flags & Flag.CHAIN_SPEC:
self.add_argument('-i', '--chain-spec', dest='i', type=str, help='Chain specification string')
diff --git a/chainlib/cli/config.py b/chainlib/cli/config.py
@@ -159,6 +159,7 @@ class Config(confini.Config):
if arg_flags & Flag.PROVIDER:
args_override['RPC_HTTP_PROVIDER'] = getattr(args, 'p')
+ args_override['RPC_DIALECT'] = getattr(args, 'rpc_dialect')
if arg_flags & Flag.CHAIN_SPEC:
args_override['CHAIN_SPEC'] = getattr(args, 'i')
if arg_flags & Flag.KEY_FILE:
diff --git a/chainlib/cli/rpc.py b/chainlib/cli/rpc.py
@@ -29,6 +29,7 @@ class Rpc:
self.wallet = wallet
self.nonce_oracle = None
self.fee_oracle = None
+ self.error_parser = None
def connect_by_config(self, config):
diff --git a/chainlib/data/config/config.ini b/chainlib/data/config/config.ini
@@ -3,6 +3,7 @@ http_provider =
http_authentication =
http_username =
http_password =
+dialect = default
[chain]
spec =
diff --git a/chainlib/error.py b/chainlib/error.py
@@ -20,3 +20,25 @@ class ExecutionError(Exception):
class SignerMissingException(Exception):
"""Raised when attempting to retrieve a signer when none has been added
"""
+
+
+class RPCNonceException(RPCException):
+ """RPC error for invalid nonce in transaction
+ """
+
+
+class DefaultErrorParser:
+ """Base class for parsing RPC error repsonses
+ """
+
+ def translate(self, error):
+ """Interface method called by unspeficied rpc when encountering an error
+
+ This class method should be overriden to provide more fine-grained context for both general and implementation specific errors.
+
+ :param error: RPC error response object
+ :type error: dict
+ :rtype: chainlib.error.JSONRPCException
+ :returns: Descriptiv JSONRPCException
+ """
+ return RPCException('default parser codeĀ {}'.format(error))