Add eth initializer
This commit is contained in:
parent
817fc40d84
commit
24e2e62924
30
cic/cmd/ext.py
Normal file
30
cic/cmd/ext.py
Normal file
@ -0,0 +1,30 @@
|
||||
# standard imports
|
||||
import importlib
|
||||
|
||||
# external imports
|
||||
from chainlib.chain import ChainSpec
|
||||
# local imports
|
||||
from cic.network import Network
|
||||
|
||||
|
||||
def process_args(argparser):
|
||||
argparser.add_argument('--registry', required=True, type=str, help='contract registry address')
|
||||
argparser.add_argument('-d', '--directory', type=str, dest='directory', default='.', help='directory')
|
||||
argparser.add_argument('-p', type=str, help='RPC endpoint')
|
||||
argparser.add_argument('-i', type=str, help='chain spec string')
|
||||
argparser.add_argument('target', help='target to initialize')
|
||||
|
||||
|
||||
def validate_args(args):
|
||||
pass
|
||||
|
||||
|
||||
def execute(config, eargs):
|
||||
cn = Network(eargs.directory, targets=eargs.target)
|
||||
cn.load()
|
||||
|
||||
|
||||
chain_spec = ChainSpec.from_chain_str(eargs.i)
|
||||
m = importlib.import_module('cic.ext.{}.start'.format(eargs.target))
|
||||
m.extension_start(cn, registry_address=eargs.registry, chain_spec=chain_spec, rpc_provider=config.get('RPC_PROVIDER'))
|
||||
|
@ -1,4 +1,5 @@
|
||||
{
|
||||
"registry": null,
|
||||
"chain_spec": {
|
||||
"arch": null,
|
||||
"fork": null,
|
||||
|
21
cic/ext/eth/start.py
Normal file
21
cic/ext/eth/start.py
Normal file
@ -0,0 +1,21 @@
|
||||
# external imports
|
||||
from cic_eth_registry import CICRegistry
|
||||
from chainlib.eth.connection import RPCConnection
|
||||
|
||||
|
||||
def extension_start(network, *args, **kwargs):
|
||||
CICRegistry.address = kwargs['registry_address']
|
||||
|
||||
RPCConnection.register_location(kwargs['rpc_provider'], kwargs['chain_spec'])
|
||||
conn = RPCConnection.connect(kwargs['chain_spec'])
|
||||
|
||||
registry = CICRegistry(kwargs['chain_spec'], conn)
|
||||
|
||||
address_declarator = registry.by_name('AddressDeclarator')
|
||||
network.resource_set('eth', 'address_declarator', address_declarator)
|
||||
|
||||
token_index = registry.by_name('TokenRegistry')
|
||||
network.resource_set('eth', 'token_index', token_index)
|
||||
|
||||
network.set('eth', kwargs['chain_spec'])
|
||||
network.save()
|
@ -50,7 +50,7 @@ class Meta(Data):
|
||||
f.close()
|
||||
|
||||
f = open(self.meta_path, 'w')
|
||||
json.dump(o, f)
|
||||
json.dump(o, f, sort_keys=True, indent="\t")
|
||||
f.close()
|
||||
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
# standard imports
|
||||
import os
|
||||
import json
|
||||
import logging
|
||||
|
||||
# external imports
|
||||
from chainlib.chain import ChainSpec
|
||||
@ -11,12 +12,14 @@ from .base import (
|
||||
data_dir,
|
||||
)
|
||||
|
||||
logg = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Network(Data):
|
||||
|
||||
def __init__(self, path='.', targets=[]):
|
||||
super(Network, self).__init__()
|
||||
self.references = None
|
||||
self.resources = None
|
||||
self.path = path
|
||||
self.targets = targets
|
||||
self.network_path = os.path.join(self.path, 'network.json')
|
||||
@ -43,13 +46,18 @@ class Network(Data):
|
||||
o_part = json.load(f)
|
||||
f.close()
|
||||
|
||||
f = open(self.network_path, 'w')
|
||||
o = {'resources': {}}
|
||||
|
||||
self.resources = {}
|
||||
for v in self.targets:
|
||||
o['resources'][v] = o_part
|
||||
self.resources[v] = o_part
|
||||
|
||||
json.dump(o, f)
|
||||
self.save()
|
||||
|
||||
|
||||
def save(self):
|
||||
f = open(self.network_path, 'w')
|
||||
json.dump({
|
||||
'resources': self.resources,
|
||||
}, f, sort_keys=True, indent="\t")
|
||||
f.close()
|
||||
|
||||
|
||||
@ -60,11 +68,23 @@ class Network(Data):
|
||||
return v
|
||||
|
||||
|
||||
def resource_set(self, resource_key, content_key, reference, key_account=None):
|
||||
self.resources[resource_key]['contents'][content_key]['reference'] = reference
|
||||
self.resources[resource_key]['contents'][content_key]['key_account'] = key_account
|
||||
|
||||
|
||||
def chain_spec(self, k):
|
||||
v = self.resource(k)
|
||||
return ChainSpec.from_dict(v['chain_spec'])
|
||||
|
||||
|
||||
def set(self, resource_key, chain_spec):
|
||||
chain_spec_dict = chain_spec.asdict()
|
||||
for k in chain_spec_dict.keys():
|
||||
logg.debug('resources {}'.format(self.resources))
|
||||
self.resources[resource_key]['chain_spec'][k] = chain_spec_dict[k]
|
||||
|
||||
|
||||
def __str__(self):
|
||||
s = ''
|
||||
for k in self.resources.keys():
|
||||
|
@ -53,7 +53,7 @@ class Proof(Data):
|
||||
f.close()
|
||||
|
||||
f = open(self.proof_path, 'w')
|
||||
json.dump(o, f)
|
||||
json.dump(o, f, sort_keys=True, indent="\t")
|
||||
f.close()
|
||||
|
||||
|
||||
|
@ -9,6 +9,7 @@ import importlib
|
||||
import chainlib.cli
|
||||
import cic.cmd.init as cmd_init
|
||||
import cic.cmd.show as cmd_show
|
||||
import cic.cmd.ext as cmd_ext
|
||||
import cic.cmd.export as cmd_export
|
||||
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
@ -30,6 +31,9 @@ sub_show = sub.add_parser('show', help='display summary of current state of cic
|
||||
cmd_show.process_args(sub_show)
|
||||
sub_export = sub.add_parser('export', help='export cic data directory state to a specified target')
|
||||
cmd_export.process_args(sub_export)
|
||||
sub_ext = sub.add_parser('ext', help='extension helpers')
|
||||
cmd_ext.process_args(sub_ext)
|
||||
|
||||
|
||||
args = argparser.parse_args(sys.argv[1:])
|
||||
|
||||
|
@ -56,7 +56,7 @@ class Token(Data):
|
||||
o['supply'] = self.supply
|
||||
|
||||
f = open(self.token_path, 'w')
|
||||
json.dump(o, f)
|
||||
json.dump(o, f, sort_keys=True, indent="\t")
|
||||
f.close()
|
||||
|
||||
|
||||
|
6
eth_requirements.txt
Normal file
6
eth_requirements.txt
Normal file
@ -0,0 +1,6 @@
|
||||
chainlib-eth>=0.0.10a1,<0.1.0
|
||||
funga-eth>=0.5.1a1,<0.6.0
|
||||
eth-token-index>=0.2.4a1,<0.3.0
|
||||
eth-address-index>=0.2.4a1,<0.3.0
|
||||
okota>=0.2.4a6,<0.3.0
|
||||
cic_eth_registry>=0.6.1a1,<0.7.0
|
@ -29,6 +29,3 @@ packages =
|
||||
cic
|
||||
cic.runnable
|
||||
cic.ext.eth
|
||||
|
||||
[options.extras_require]
|
||||
eth = chainlib-eth>=0.0.10a1,<0.1.0; funga-eth>=0.5.1a1,<0.6.0; eth-token-index>=0.2.4a1,<0.3.0; eth-address-index>=0.2.4a1,<0.3.0, okota>=0.2.4a6,<0.3.0
|
||||
|
14
setup.py
14
setup.py
@ -12,6 +12,20 @@ while True:
|
||||
requirements.append(l.rstrip())
|
||||
f.close()
|
||||
|
||||
eth_requirements = []
|
||||
f = open('eth_requirements.txt', 'r')
|
||||
while True:
|
||||
l = f.readline()
|
||||
if l == '':
|
||||
break
|
||||
eth_requirements.append(l.rstrip())
|
||||
f.close()
|
||||
|
||||
|
||||
setup(
|
||||
install_requires=requirements,
|
||||
extras_require={
|
||||
'eth': eth_requirements,
|
||||
},
|
||||
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user