WIP make token deploy work with cli export stage

This commit is contained in:
nolash 2021-10-11 21:18:51 +02:00
parent 41e41ad220
commit 39becba3b2
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
4 changed files with 40 additions and 17 deletions

View File

@ -19,6 +19,7 @@ logg = logging.getLogger(__name__)
def process_args(argparser):
argparser.add_argument('-d', '--directory', type=str, dest='directory', default='.', help='directory')
argparser.add_argument('-y', '--signer', type=str, dest='y', help='target-specific signer to use for export')
argparser.add_argument('-p', type=str, help='RPC endpoint')
argparser.add_argument('target', type=str, help='target network type')
@ -61,12 +62,21 @@ def execute(config, eargs):
ca.load()
cn.load()
signer = cmd_mod.parse_signer(eargs.y)
chain_spec = None
try:
chain_spec = config.get('CHAIN_SPEC')
except KeyError:
chain_spec = cn.chain_spec
config.add(chain_spec, 'CHAIN_SPEC', exists_ok=True)
logg.debug('CHAIN_SPEC config set to {}'.format(str(chain_spec)))
#signer = cmd_mod.parse_signer(eargs.y)
(rpc, signer) = cmd_mod.parse_adapter(config, eargs.y)
ref = cn.resource(eargs.target)
chain_spec = cn.chain_spec(eargs.target)
logg.debug('found reference {} chain spec {} for target {}'.format(ref['contents'], chain_spec, eargs.target))
c = getattr(cmd_mod, 'new')(chain_spec, ref['contents'], cp, signer_hint=signer)
c = getattr(cmd_mod, 'new')(chain_spec, ref['contents'], cp, signer_hint=signer, rpc=rpc)
c.apply_token(ct)
p = Processor(proof=cp, attachment=ca, metadata=cm, extensions=[eargs.target])

View File

@ -17,13 +17,17 @@ from chainlib.eth.contract import (
)
from chainlib.eth.gas import OverrideGasOracle
from chainlib.eth.nonce import RPCNonceOracle
from chainlib.eth.address import is_address
from chainlib.eth.address import (
is_address,
to_checksum_address,
)
from hexathon import add_0x
from eth_token_index import TokenUniqueSymbolIndex
from eth_address_declarator import Declarator
from eth_address_declarator.declarator import AddressDeclarator
# local imports
from .signer import parse_signer
from cic.ext.eth.rpc import parse_adapter
logg = logging.getLogger(__name__)
@ -151,7 +155,7 @@ class CICEth:
code = self.token_details['code'] + enc.get()
logg.debug('resource {}'.format(self.resources))
signer_address = self.resources['token']['key_account']
signer_address = add_0x(to_checksum_address(self.resources['token']['key_account']))
nonce_oracle = None
if self.rpc != None:
nonce_oracle = RPCNonceOracle(signer_address, conn=self.rpc)
@ -164,10 +168,9 @@ class CICEth:
r = None
if self.rpc != None:
r = self.rpc.do(o[1])
ro = receipt(r)
rr = self.rpc.do(ro)
rr = Tx.src_normalize(rr)
self.token_address = rr['contract_address']
o = self.rpc.wait(r)
o = Tx.src_normalize(o)
self.token_address = o['contract_address']
elif self.signer != None:
r = o[1]
@ -261,5 +264,5 @@ class CICEth:
return self.token_address
def new(chain_spec, resources, proof, signer_hint=None):
return CICEth(chain_spec, resources, proof, signer=signer_hint)
def new(chain_spec, resources, proof, signer_hint=None, rpc=None):
return CICEth(chain_spec, resources, proof, signer=signer_hint, rpc=rpc)

View File

@ -6,6 +6,8 @@ import logging
# external imports
from funga.eth.keystore.dict import DictKeystore
from funga.eth.signer import EIP155Signer
from chainlib.eth.cli import Rpc
from chainlib.cli import Wallet
# local imports
from cic.keystore import KeystoreDirectory
@ -17,8 +19,9 @@ class EthKeystoreDirectory(DictKeystore, KeystoreDirectory):
pass
def parse_signer(signer_hint):
def parse_adapter(config, signer_hint):
keystore = None
if signer_hint == None:
logg.info('signer hint missing')
return None
@ -27,7 +30,10 @@ def parse_signer(signer_hint):
logg.debug('signer hint is directory')
keystore = EthKeystoreDirectory()
keystore.process_dir(signer_hint)
signer = EIP155Signer(keystore)
return signer
w = Wallet(EIP155Signer, keystore=keystore)
signer = EIP155Signer(keystore)
rpc = Rpc(wallet=w)
rpc.connect_by_config(config)
return (rpc.conn, signer)

View File

@ -19,7 +19,8 @@ data_dir = os.path.join(script_dir, '..', 'data')
base_config_dir = os.path.join(data_dir, 'config')
schema_dir = os.path.join(script_dir, '..', 'schema')
argparser = chainlib.cli.ArgumentParser(env=os.environ, description='CIC cli tool for generating and publishing tokens')
arg_flags = chainlib.cli.argflag_std_read | chainlib.cli.Flag.SEQ
argparser = chainlib.cli.ArgumentParser(env=os.environ, arg_flags=arg_flags, description='CIC cli tool for generating and publishing tokens')
sub = argparser.add_subparsers()
sub.dest = 'command'
@ -31,7 +32,6 @@ sub_export = sub.add_parser('export', help='export cic data directory state to a
cmd_export.process_args(sub_export)
args = argparser.parse_args(sys.argv[1:])
config = chainlib.cli.Config.from_args(args, base_config_dir=base_config_dir)
if args.command == None:
logg.critical('Subcommand missing')
@ -41,6 +41,10 @@ modname = 'cic.cmd.{}'.format(args.command)
logg.debug('using module {}'.format(modname))
cmd_mod = importlib.import_module(modname)
extra_args = {
'p': 'RPC_PROVIDER',
}
config = chainlib.cli.Config.from_args(args, arg_flags=arg_flags, base_config_dir=base_config_dir, extra_args=extra_args)
def main():
#try: