chainlib

Generic blockchain access library and tooling
Log | Files | Refs | README | LICENSE

commit 50c31e5994155b1c319a85d4c22465814bdde28d
parent 3937785df5c34812f71f6a8a8005bbca0e74eca7
Author: nolash <dev@holbrook.no>
Date:   Wed,  1 Sep 2021 09:38:24 +0200

Allow fee settings for read

Diffstat:
Mchainlib/cli/arg.py | 10+++++++---
Mchainlib/cli/base.py | 11+++++++----
Mchainlib/cli/config.py | 14++++++++++++--
Mchainlib/cli/rpc.py | 5+++--
Mchainlib/data/config/config.ini | 7++++---
Mdoc/texinfo/index.texi | 5++++-
Ddoc/texinfo/interface.texi | 59-----------------------------------------------------------
Msetup.cfg | 2+-
8 files changed, 38 insertions(+), 75 deletions(-)

diff --git a/chainlib/cli/arg.py b/chainlib/cli/arg.py @@ -136,9 +136,12 @@ class ArgumentParser(argparse.ArgumentParser): if arg_flags & Flag.ENV_PREFIX: 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('-p', '--rpc-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.RPC_AUTH: + self.add_argument('--rpc-auth', dest='rpc_auth', type=str, help='RPC autentication scheme') + self.add_argument('--rpc-credentials', dest='rpc_credentials', type=str, help='RPC autentication credential values') if arg_flags & Flag.CHAIN_SPEC: self.add_argument('-i', '--chain-spec', dest='i', type=str, help='Chain specification string') if arg_flags & Flag.UNSAFE: @@ -151,8 +154,9 @@ class ArgumentParser(argparse.ArgumentParser): self.add_argument('-s', '--send', dest='s', action='store_true', help='Send to network') if arg_flags & Flag.RAW: self.add_argument('--raw', action='store_true', help='Do not decode output') - if arg_flags & Flag.SIGN: + if arg_flags & (Flag.SIGN | Flag.NONCE): self.add_argument('--nonce', type=int, help='override nonce') + if arg_flags & (Flag.SIGN | Flag.FEE): self.add_argument('--fee-price', dest='fee_price', type=int, help='override fee price') self.add_argument('--fee-limit', dest='fee_limit', type=int, help='override fee limit') if arg_flags & argflag_std_target == 0: @@ -161,4 +165,4 @@ class ArgumentParser(argparse.ArgumentParser): self.add_argument('-e', '--exectuable-address', dest='executable_address', type=str, help='contract address') if arg_flags & Flag.WALLET: self.add_argument('-a', '--recipient', dest='recipient', type=str, help='recipient address') - + diff --git a/chainlib/cli/base.py b/chainlib/cli/base.py @@ -21,8 +21,10 @@ class Flag(enum.IntEnum): SEQ = 128 # read/write - nibble 3 KEY_FILE = 256 + FEE = 512 # this must be defined separately now since some rpcs demand minimum base fee price + NONCE = 1024 # write - nibble 4 - SIGN = 4096 + SIGN = 4096 NO_TARGET = 8192 EXEC = 16384 WALLET = 32768 @@ -30,9 +32,10 @@ class Flag(enum.IntEnum): WAIT = 65536 WAIT_ALL = 131072 SEND = 262144 + # rpc extras - nibble 6 + RPC_AUTH = 1048576 - -argflag_std_read = 0x2fff -argflag_std_write = 0xff3fff +argflag_std_read = 0x23ff +argflag_std_write = 0xff31ff argflag_std_base = 0x200f argflag_std_target = 0x00e000 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_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') @@ -171,15 +172,18 @@ class Config(confini.Config): config.add(getattr(args, 'height'), '_HEIGHT') if arg_flags & Flag.UNSAFE: config.add(getattr(args, 'u'), '_UNSAFE') - if arg_flags & Flag.SEND: + if arg_flags & (Flag.SIGN | Flag.FEE): + config.add(getattr(args, 'fee_price'), '_FEE_PRICE') fee_limit = getattr(args, 'fee_limit') if fee_limit == None: fee_limit = default_fee_limit if fee_limit == None: fee_limit = cls.default_fee_limit config.add(fee_limit, '_FEE_LIMIT') - config.add(getattr(args, 'fee_price'), '_FEE_PRICE') + if arg_flags & (Flag.SIGN | Flag.NONCE): config.add(getattr(args, 'nonce'), '_NONCE') + + if arg_flags & Flag.SIGN: config.add(getattr(args, 's'), '_RPC_SEND') # handle wait @@ -192,6 +196,8 @@ class Config(confini.Config): config.add(bool(wait_last), '_WAIT') wait_all = wait & Flag.WAIT_ALL config.add(bool(wait_all), '_WAIT_ALL') + + if arg_flags & Flag.SEQ: config.add(getattr(args, 'seq'), '_SEQ') if arg_flags & Flag.WALLET: @@ -204,6 +210,10 @@ class Config(confini.Config): if arg_flags & Flag.CONFIG: config.add(getattr(args, 'namespace'), 'CONFIG_USER_NAMESPACE') + if arg_flags & Flag.RPC_AUTH: + config.add(getattr(args, 'rpc_auth'), 'RPC_AUTH') + config.add(getattr(args, 'rpc_credentials'), 'RPC_CREDENTIALS') + for k in extra_args.keys(): v = extra_args[k] if v == None: diff --git a/chainlib/cli/rpc.py b/chainlib/cli/rpc.py @@ -48,9 +48,10 @@ class Rpc: :returns: An established rpc connection """ auth = None - if config.get('RPC_HTTP_AUTHENTICATION') == 'basic': + if config.get('RPC_AUTH') == 'basic': from chainlib.auth import BasicAuth - auth = BasicAuth(config.get('RPC_HTTP_USERNAME'), config.get('RPC_HTTP_PASSWORD')) + auth_parts = config.get('RPC_CREDENTIALS').split(':') + auth = BasicAuth(auth_parts[0], auth_parts[1]) logg.debug('using basic http auth') if config.get('_SEQ'): diff --git a/chainlib/data/config/config.ini b/chainlib/data/config/config.ini @@ -1,9 +1,10 @@ [rpc] http_provider = -http_authentication = -http_username = -http_password = +provider = +auth = +credentials = dialect = default +scheme = http [chain] spec = diff --git a/doc/texinfo/index.texi b/doc/texinfo/index.texi @@ -2,4 +2,7 @@ @chapter Chainlib -@include interface.texi +@include intro.texi +@include cli.texi +@include config.texi +@include code.texi diff --git a/doc/texinfo/interface.texi b/doc/texinfo/interface.texi @@ -1,59 +0,0 @@ -@node chainlib-interface -@section The chainlib implementation - -Chainlib is an attempt at employing a universal interface to manipulate and access blockchains regardless of underlying architecture. - -It makes the following assumptions: - -@itemize -@item A block MUST have a interpretable serializable format, and contains zero of more transactions -@item A transaction MUST have a interpretable serializable format -@item A transaction MUST have a nonce associated with a sender address. This uniquely identifies the transaction on the network. -@item A transaction MUST have a fee bid to get the transaction executed on the network (a network that does not care about bids can still ignore this property). -@item A transaction signature MAY be locked to a particular chain identifier -@item The sender key of a transaction MAY be recovered by the signature of the transaction -@end itemize - - -@subsection Pluggable method interface - -The base chainlib blockchain interface is defined by the chainlib.interface.ChainInterface class. The sum of the unimplemented methods in this class summarizes the expected scope of abstraction necessary to interface with @emph{any} blockchain backend. - -Methods in this class will return objects that can be passed to an RPC connection that fits the block context. - -The implemented concepts are as follows, listed by method names: - -@table @code -@item block_latest -Retrieve the latest block from the network -@item block_by_hash -Retrieve the block corresponding to the given block hash -@item block_by_number -Retrieve the block corresponding to the given block number -@item block_from_src -Render a chainlib.block.Block derivative object from an architecture-dependent block representation source -@item block_to_src -Render an architecture dependent transaction representation from the given Block object -@item tx_by_hash -Retrieve the transaction corresponding to the given transaction hash -@item tx_by_block -Retrieve the transaction corresponding to the given block hash and transaction index -@item tx_receipt -Retrieve the details of a confirmed transaction -@item tx_raw -Generate an RPC query from raw transaction wire data -@item tx_pack -Generate raw transaction wire data from an architecture dependent transaction representation -@item tx_unpack -Generate architecture dependent transaction representation from raw transaction wire data -@item tx_from_src -Render a chainlib.tx.Tx derivative object from an architecture-dependent tx representation source -@item tx_to_src -Render an architecture dependent transaction representation from the given Tx object -@item address_safe -Generate a checksum-safe network address -@item address_normal -Generate an unambiguous network address -@item src_normalize -Generate an unambiguous dictionary from the given dictionary. For example, this can mean generating camel-case key equivalents for snake-case values. -@end table diff --git a/setup.cfg b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = chainlib -version = 0.0.9a3 +version = 0.0.9a6 description = Generic blockchain access library and tooling author = Louis Holbrook author_email = dev@holbrook.no