Merge branch 'lash/fix-docs-compile' into 'master'
feat: chainspec, positional args, docfix See merge request chaintool/chainlib!8
This commit is contained in:
commit
a71ec59fb2
@ -16,12 +16,12 @@ class ChainSpec:
|
|||||||
:param tag: Descriptive tag
|
:param tag: Descriptive tag
|
||||||
:type tag: str
|
:type tag: str
|
||||||
"""
|
"""
|
||||||
def __init__(self, engine, common_name, network_id, tag=None):
|
def __init__(self, arch, fork, network_id, common_name=None):
|
||||||
self.o = {
|
self.o = {
|
||||||
'engine': engine,
|
'arch': arch,
|
||||||
'common_name': common_name,
|
'fork': fork,
|
||||||
'network_id': network_id,
|
'network_id': network_id,
|
||||||
'tag': tag,
|
'common_name': common_name,
|
||||||
}
|
}
|
||||||
|
|
||||||
def network_id(self):
|
def network_id(self):
|
||||||
@ -48,7 +48,7 @@ class ChainSpec:
|
|||||||
:rtype: str
|
:rtype: str
|
||||||
:returns: engine
|
:returns: engine
|
||||||
"""
|
"""
|
||||||
return self.o['engine']
|
return self.o['arch']
|
||||||
|
|
||||||
|
|
||||||
def common_name(self):
|
def common_name(self):
|
||||||
@ -78,10 +78,10 @@ class ChainSpec:
|
|||||||
o = chain_str.split(':')
|
o = chain_str.split(':')
|
||||||
if len(o) < 3:
|
if len(o) < 3:
|
||||||
raise ValueError('Chain string must have three sections, got {}'.format(len(o)))
|
raise ValueError('Chain string must have three sections, got {}'.format(len(o)))
|
||||||
tag = None
|
common_name = None
|
||||||
if len(o) == 4:
|
if len(o) == 4:
|
||||||
tag = o[3]
|
common_name = o[3]
|
||||||
return ChainSpec(o[0], o[1], int(o[2]), tag)
|
return ChainSpec(o[0], o[1], int(o[2]), common_name)
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -100,7 +100,7 @@ class ChainSpec:
|
|||||||
:rtype: chainlib.chain.ChainSpec
|
:rtype: chainlib.chain.ChainSpec
|
||||||
:returns: Resulting chain spec
|
:returns: Resulting chain spec
|
||||||
"""
|
"""
|
||||||
return ChainSpec(o['engine'], o['common_name'], o['network_id'], tag=o['tag'])
|
return ChainSpec(o['arch'], o['fork'], o['network_id'], common_name=o['common_name'])
|
||||||
|
|
||||||
|
|
||||||
def asdict(self):
|
def asdict(self):
|
||||||
@ -113,7 +113,7 @@ class ChainSpec:
|
|||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
s = '{}:{}:{}'.format(self.o['engine'], self.o['common_name'], self.o['network_id'])
|
s = '{}:{}:{}'.format(self.o['arch'], self.o['fork'], self.o['network_id'])
|
||||||
if self.o['tag'] != None:
|
if self.o['common_name'] != None:
|
||||||
s += ':' + self.o['tag']
|
s += ':' + self.o['common_name']
|
||||||
return s
|
return s
|
||||||
|
@ -57,7 +57,7 @@ class ArgumentParser(argparse.ArgumentParser):
|
|||||||
self.pos_args = []
|
self.pos_args = []
|
||||||
|
|
||||||
|
|
||||||
def add_positional(self, name, type=str, help=None, required=True):
|
def add_positional(self, name, type=str, help=None, append=False, required=True):
|
||||||
"""Add a positional argument.
|
"""Add a positional argument.
|
||||||
|
|
||||||
Stdin piping will only be possible in the event a single positional argument is defined.
|
Stdin piping will only be possible in the event a single positional argument is defined.
|
||||||
@ -73,7 +73,7 @@ class ArgumentParser(argparse.ArgumentParser):
|
|||||||
:param required: If true, argument will be set to required
|
:param required: If true, argument will be set to required
|
||||||
:type required: bool
|
:type required: bool
|
||||||
"""
|
"""
|
||||||
self.pos_args.append((name, type, help, required,))
|
self.pos_args.append((name, type, help, required, append,))
|
||||||
|
|
||||||
|
|
||||||
def parse_args(self, argv=sys.argv[1:]):
|
def parse_args(self, argv=sys.argv[1:]):
|
||||||
@ -88,13 +88,23 @@ class ArgumentParser(argparse.ArgumentParser):
|
|||||||
"""
|
"""
|
||||||
if len(self.pos_args) == 1:
|
if len(self.pos_args) == 1:
|
||||||
arg = self.pos_args[0]
|
arg = self.pos_args[0]
|
||||||
|
if arg[4]:
|
||||||
|
self.add_argument(arg[0], nargs='*', type=arg[1], default=stdin_arg(), help=arg[2])
|
||||||
|
else:
|
||||||
self.add_argument(arg[0], nargs='?', type=arg[1], default=stdin_arg(), help=arg[2])
|
self.add_argument(arg[0], nargs='?', type=arg[1], default=stdin_arg(), help=arg[2])
|
||||||
else:
|
else:
|
||||||
for arg in self.pos_args:
|
for arg in self.pos_args:
|
||||||
if arg[3]:
|
if arg[3]:
|
||||||
|
if arg[4]:
|
||||||
|
logg.debug('argumen')
|
||||||
|
self.add_argument(arg[0], nargs='+', type=arg[1], help=arg[2])
|
||||||
|
else:
|
||||||
self.add_argument(arg[0], type=arg[1], help=arg[2])
|
self.add_argument(arg[0], type=arg[1], help=arg[2])
|
||||||
else:
|
else:
|
||||||
self.add_argument(arg[0], nargs='?', type=arg[1], help=arg[2])
|
if arg[4]:
|
||||||
|
self.add_argument(arg[0], nargs='*', type=arg[1], help=arg[2])
|
||||||
|
else:
|
||||||
|
self.add_argument(arg[0], type=arg[1], help=arg[2])
|
||||||
args = super(ArgumentParser, self).parse_args(args=argv)
|
args = super(ArgumentParser, self).parse_args(args=argv)
|
||||||
|
|
||||||
if args.dumpconfig:
|
if args.dumpconfig:
|
||||||
|
@ -170,7 +170,6 @@ class Config(confini.Config):
|
|||||||
args_override = {}
|
args_override = {}
|
||||||
|
|
||||||
if arg_flags & Flag.PROVIDER:
|
if arg_flags & Flag.PROVIDER:
|
||||||
args_override['RPC_HTTP_PROVIDER'] = getattr(args, 'p')
|
|
||||||
args_override['RPC_PROVIDER'] = getattr(args, 'p')
|
args_override['RPC_PROVIDER'] = getattr(args, 'p')
|
||||||
args_override['RPC_DIALECT'] = getattr(args, 'rpc_dialect')
|
args_override['RPC_DIALECT'] = getattr(args, 'rpc_dialect')
|
||||||
if arg_flags & Flag.CHAIN_SPEC:
|
if arg_flags & Flag.CHAIN_SPEC:
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
# standard imports
|
# standard imports
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
# external imports
|
|
||||||
from crypto_dev_signer.keystore.dict import DictKeystore
|
|
||||||
|
|
||||||
logg = logging.getLogger(__name__)
|
logg = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@ -19,7 +16,7 @@ class Wallet:
|
|||||||
:todo: sign_transaction_to_rlp from chainlib-eth must be renamed to sign_transaction_to_wire, and included as part of signer interface
|
:todo: sign_transaction_to_rlp from chainlib-eth must be renamed to sign_transaction_to_wire, and included as part of signer interface
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, signer_cls, keystore=DictKeystore(), checksummer=None):
|
def __init__(self, signer_cls, keystore=None, checksummer=None):
|
||||||
self.signer_constructor = signer_cls
|
self.signer_constructor = signer_cls
|
||||||
self.keystore = keystore
|
self.keystore = keystore
|
||||||
self.signer = None
|
self.signer = None
|
||||||
|
@ -23,7 +23,10 @@ from .jsonrpc import (
|
|||||||
ErrorParser,
|
ErrorParser,
|
||||||
)
|
)
|
||||||
from .http import PreemptiveBasicAuthHandler
|
from .http import PreemptiveBasicAuthHandler
|
||||||
from .error import JSONRPCException
|
from .error import (
|
||||||
|
JSONRPCException,
|
||||||
|
RPCException,
|
||||||
|
)
|
||||||
from .auth import Auth
|
from .auth import Auth
|
||||||
|
|
||||||
logg = logging.getLogger(__name__)
|
logg = logging.getLogger(__name__)
|
||||||
@ -309,7 +312,10 @@ class JSONRPCHTTPConnection(HTTPConnection):
|
|||||||
ho = build_opener(handler)
|
ho = build_opener(handler)
|
||||||
install_opener(ho)
|
install_opener(ho)
|
||||||
|
|
||||||
|
try:
|
||||||
r = urlopen(req, data=data.encode('utf-8'))
|
r = urlopen(req, data=data.encode('utf-8'))
|
||||||
|
except URLError as e:
|
||||||
|
raise RPCException(e)
|
||||||
|
|
||||||
result = json.load(r)
|
result = json.load(r)
|
||||||
logg.debug('(HTTP) recv {}'.format(result))
|
logg.debug('(HTTP) recv {}'.format(result))
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
[rpc]
|
[rpc]
|
||||||
http_provider =
|
|
||||||
provider =
|
provider =
|
||||||
auth =
|
auth =
|
||||||
credentials =
|
credentials =
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
crypto-dev-signer>=0.4.15rc2,<=0.4.15
|
funga>=0.5.1a1,<0.6.0
|
||||||
pysha3==1.0.2
|
pysha3==1.0.2
|
||||||
hexathon~=0.0.1a8
|
hexathon~=0.0.1a8
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[metadata]
|
[metadata]
|
||||||
name = chainlib
|
name = chainlib
|
||||||
version = 0.0.9rc1
|
version = 0.0.10a7
|
||||||
description = Generic blockchain access library and tooling
|
description = Generic blockchain access library and tooling
|
||||||
author = Louis Holbrook
|
author = Louis Holbrook
|
||||||
author_email = dev@holbrook.no
|
author_email = dev@holbrook.no
|
||||||
|
@ -7,6 +7,13 @@ from tests.base import TestBase
|
|||||||
|
|
||||||
class TestChain(TestBase):
|
class TestChain(TestBase):
|
||||||
|
|
||||||
|
def test_chain_spec_str(self):
|
||||||
|
s = ChainSpec('foo', 'bar', 3, 'baz')
|
||||||
|
self.assertEqual('foo:bar:3:baz', str(s))
|
||||||
|
|
||||||
|
s = ChainSpec('foo', 'bar', 3)
|
||||||
|
self.assertEqual('foo:bar:3', str(s))
|
||||||
|
|
||||||
def test_chain_spec(self):
|
def test_chain_spec(self):
|
||||||
|
|
||||||
s = ChainSpec.from_chain_str('foo:bar:3')
|
s = ChainSpec.from_chain_str('foo:bar:3')
|
||||||
@ -18,5 +25,18 @@ class TestChain(TestBase):
|
|||||||
s = ChainSpec.from_chain_str('foo')
|
s = ChainSpec.from_chain_str('foo')
|
||||||
|
|
||||||
|
|
||||||
|
def test_chain_spec_dict(self):
|
||||||
|
s = 'foo:bar:3:baz'
|
||||||
|
c = ChainSpec.from_chain_str('foo:bar:3:baz')
|
||||||
|
d = c.asdict()
|
||||||
|
self.assertEqual(d['arch'], 'foo')
|
||||||
|
self.assertEqual(d['fork'], 'bar')
|
||||||
|
self.assertEqual(d['network_id'], 3)
|
||||||
|
self.assertEqual(d['common_name'], 'baz')
|
||||||
|
cc = ChainSpec.from_dict(d)
|
||||||
|
self.assertEqual(s, str(cc))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user