Add keystore dir parsing for signer for eth target
This commit is contained in:
parent
1fce3245d8
commit
41e41ad220
@ -1 +1,2 @@
|
|||||||
from .proof import Proof
|
from .proof import Proof
|
||||||
|
from .processor import Processor
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
# standard imports
|
# standard imports
|
||||||
import logging
|
import logging
|
||||||
import importlib
|
import importlib
|
||||||
|
import os
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from cic import Proof
|
from cic import (
|
||||||
|
Proof,
|
||||||
|
Processor,
|
||||||
|
)
|
||||||
from cic.meta import Meta
|
from cic.meta import Meta
|
||||||
from cic.attachment import Attachment
|
from cic.attachment import Attachment
|
||||||
from cic.network import Network
|
from cic.network import Network
|
||||||
@ -14,7 +18,7 @@ logg = logging.getLogger(__name__)
|
|||||||
|
|
||||||
def process_args(argparser):
|
def process_args(argparser):
|
||||||
argparser.add_argument('-d', '--directory', type=str, dest='directory', default='.', help='directory')
|
argparser.add_argument('-d', '--directory', type=str, dest='directory', default='.', help='directory')
|
||||||
argparser.add_argument('-y', '--signer', type=str, dest='signer', help='target-specific signer to use for export')
|
argparser.add_argument('-y', '--signer', type=str, dest='y', help='target-specific signer to use for export')
|
||||||
argparser.add_argument('target', type=str, help='target network type')
|
argparser.add_argument('target', type=str, help='target network type')
|
||||||
|
|
||||||
|
|
||||||
@ -27,6 +31,7 @@ def init_writers_from_config(config):
|
|||||||
'meta': None,
|
'meta': None,
|
||||||
'attachment': None,
|
'attachment': None,
|
||||||
'proof': None,
|
'proof': None,
|
||||||
|
'ext': None,
|
||||||
}
|
}
|
||||||
for v in w.keys():
|
for v in w.keys():
|
||||||
k = 'CIC_CORE_{}_WRITER'.format(v.upper())
|
k = 'CIC_CORE_{}_WRITER'.format(v.upper())
|
||||||
@ -36,7 +41,7 @@ def init_writers_from_config(config):
|
|||||||
w[v] = o
|
w[v] = o
|
||||||
|
|
||||||
return w
|
return w
|
||||||
|
|
||||||
|
|
||||||
def execute(config, eargs):
|
def execute(config, eargs):
|
||||||
modname = 'cic.ext.{}'.format(eargs.target)
|
modname = 'cic.ext.{}'.format(eargs.target)
|
||||||
@ -56,7 +61,13 @@ def execute(config, eargs):
|
|||||||
ca.load()
|
ca.load()
|
||||||
cn.load()
|
cn.load()
|
||||||
|
|
||||||
|
signer = cmd_mod.parse_signer(eargs.y)
|
||||||
|
|
||||||
ref = cn.resource(eargs.target)
|
ref = cn.resource(eargs.target)
|
||||||
chain_spec = cn.chain_spec(eargs.target)
|
chain_spec = cn.chain_spec(eargs.target)
|
||||||
logg.debug('found reference {} for target {}'.format(ref, eargs.target))
|
logg.debug('found reference {} chain spec {} for target {}'.format(ref['contents'], chain_spec, eargs.target))
|
||||||
getattr(cmd_mod, 'new')(chain_spec, ref, cp, signer_hint=eargs.signer)
|
c = getattr(cmd_mod, 'new')(chain_spec, ref['contents'], cp, signer_hint=signer)
|
||||||
|
c.apply_token(ct)
|
||||||
|
|
||||||
|
p = Processor(proof=cp, attachment=ca, metadata=cm, extensions=[eargs.target])
|
||||||
|
c.process(writer=writers['ext'])
|
||||||
|
@ -2,3 +2,4 @@
|
|||||||
meta_writer = cic.output.KVWriter
|
meta_writer = cic.output.KVWriter
|
||||||
attachment_writer = cic.output.KVWriter
|
attachment_writer = cic.output.KVWriter
|
||||||
proof_writer = cic.output.KVWriter
|
proof_writer = cic.output.KVWriter
|
||||||
|
ext_writer = cic.output.KVWriter
|
||||||
|
@ -22,6 +22,9 @@ from eth_token_index import TokenUniqueSymbolIndex
|
|||||||
from eth_address_declarator import Declarator
|
from eth_address_declarator import Declarator
|
||||||
from eth_address_declarator.declarator import AddressDeclarator
|
from eth_address_declarator.declarator import AddressDeclarator
|
||||||
|
|
||||||
|
# local imports
|
||||||
|
from .signer import parse_signer
|
||||||
|
|
||||||
logg = logging.getLogger(__name__)
|
logg = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@ -48,12 +51,16 @@ class CICEth:
|
|||||||
self.tx_format = TxFormat.RLP_SIGNED
|
self.tx_format = TxFormat.RLP_SIGNED
|
||||||
|
|
||||||
|
|
||||||
|
def apply_token(self, token):
|
||||||
|
return self.prepare_token(token.name, token.symbol, token.precision, token.code)
|
||||||
|
|
||||||
|
|
||||||
def prepare_token(self, name, symbol, precision, code, extra=[], extra_types=[], positions=None):
|
def prepare_token(self, name, symbol, precision, code, extra=[], extra_types=[], positions=None):
|
||||||
self.token_details = {
|
self.token_details = {
|
||||||
'name': name,
|
'name': name,
|
||||||
'symbol': symbol,
|
'symbol': symbol,
|
||||||
'precision': precision,
|
'precision': precision,
|
||||||
'code': code,
|
'code': code or '',
|
||||||
'extra': extra,
|
'extra': extra,
|
||||||
'extra_types': extra_types,
|
'extra_types': extra_types,
|
||||||
'positions': positions,
|
'positions': positions,
|
||||||
@ -143,7 +150,8 @@ class CICEth:
|
|||||||
|
|
||||||
code = self.token_details['code'] + enc.get()
|
code = self.token_details['code'] + enc.get()
|
||||||
|
|
||||||
signer_address = self.resources['token']['key_address']
|
logg.debug('resource {}'.format(self.resources))
|
||||||
|
signer_address = self.resources['token']['key_account']
|
||||||
nonce_oracle = None
|
nonce_oracle = None
|
||||||
if self.rpc != None:
|
if self.rpc != None:
|
||||||
nonce_oracle = RPCNonceOracle(signer_address, conn=self.rpc)
|
nonce_oracle = RPCNonceOracle(signer_address, conn=self.rpc)
|
||||||
@ -254,4 +262,4 @@ class CICEth:
|
|||||||
|
|
||||||
|
|
||||||
def new(chain_spec, resources, proof, signer_hint=None):
|
def new(chain_spec, resources, proof, signer_hint=None):
|
||||||
return CICEth(chain_spec, resources, proof, signer=None)
|
return CICEth(chain_spec, resources, proof, signer=signer_hint)
|
||||||
|
33
cic/ext/eth/signer.py
Normal file
33
cic/ext/eth/signer.py
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
# standard imports
|
||||||
|
import stat
|
||||||
|
import os
|
||||||
|
import logging
|
||||||
|
|
||||||
|
# external imports
|
||||||
|
from funga.eth.keystore.dict import DictKeystore
|
||||||
|
from funga.eth.signer import EIP155Signer
|
||||||
|
|
||||||
|
# local imports
|
||||||
|
from cic.keystore import KeystoreDirectory
|
||||||
|
|
||||||
|
logg = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class EthKeystoreDirectory(DictKeystore, KeystoreDirectory):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def parse_signer(signer_hint):
|
||||||
|
|
||||||
|
if signer_hint == None:
|
||||||
|
logg.info('signer hint missing')
|
||||||
|
return None
|
||||||
|
st = os.stat(signer_hint)
|
||||||
|
if stat.S_ISDIR(st.st_mode):
|
||||||
|
logg.debug('signer hint is directory')
|
||||||
|
keystore = EthKeystoreDirectory()
|
||||||
|
keystore.process_dir(signer_hint)
|
||||||
|
signer = EIP155Signer(keystore)
|
||||||
|
|
||||||
|
return signer
|
||||||
|
|
@ -72,17 +72,23 @@ class TestCICEthBase(EthTesterCase):
|
|||||||
self.resources = {
|
self.resources = {
|
||||||
'token': {
|
'token': {
|
||||||
'reference': self.token_address,
|
'reference': self.token_address,
|
||||||
'key_address': addresses[0],
|
'key_account': addresses[0],
|
||||||
},
|
},
|
||||||
'token_index': {
|
'token_index': {
|
||||||
'reference': self.token_index_address,
|
'reference': self.token_index_address,
|
||||||
'key_address': addresses[1],
|
'key_account': addresses[1],
|
||||||
},
|
},
|
||||||
'address_declarator': {
|
'address_declarator': {
|
||||||
'reference': self.address_declarator_address,
|
'reference': self.address_declarator_address,
|
||||||
'key_address': addresses[2],
|
'key_account': addresses[2],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
self.chain_spec_dict = {
|
||||||
|
'arch': 'evm',
|
||||||
|
'fork': 'byzantine',
|
||||||
|
'network_id': 42,
|
||||||
|
'common_name': 'foo',
|
||||||
|
}
|
||||||
proof_dir = os.path.join(test_data_dir, 'proof')
|
proof_dir = os.path.join(test_data_dir, 'proof')
|
||||||
attach = Attachment(path=proof_dir)
|
attach = Attachment(path=proof_dir)
|
||||||
attach.load()
|
attach.load()
|
||||||
|
Loading…
Reference in New Issue
Block a user