Add token part
This commit is contained in:
parent
7f18b6d6d2
commit
538b352cf7
@ -55,6 +55,6 @@ class Attachment(Data):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
s = ''
|
s = ''
|
||||||
for i in range(len(self.contents)):
|
for i in range(len(self.contents)):
|
||||||
s += '{}\t{}\n'.format(self.digests[i].hex(), self.contents[i])
|
s += '{} = {}\n'.format(self.digests[i].hex(), self.contents[i])
|
||||||
|
|
||||||
return s
|
return s
|
||||||
|
@ -29,6 +29,10 @@ class Data:
|
|||||||
raise RuntimeError('Object already initialized')
|
raise RuntimeError('Object already initialized')
|
||||||
|
|
||||||
|
|
||||||
|
def verify(self):
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def version(self):
|
def version(self):
|
||||||
return self.__version
|
return self.__version
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ from cic import Proof
|
|||||||
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
|
||||||
|
from cic.token import Token
|
||||||
|
|
||||||
logg = logging.getLogger(__name__)
|
logg = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -25,11 +26,13 @@ def execute(config, eargs):
|
|||||||
modname = 'cic.ext.{}'.format(eargs.target)
|
modname = 'cic.ext.{}'.format(eargs.target)
|
||||||
cmd_mod = importlib.import_module(modname)
|
cmd_mod = importlib.import_module(modname)
|
||||||
|
|
||||||
|
ct = Token(path=eargs.directory)
|
||||||
cp = Proof(path=eargs.directory)
|
cp = Proof(path=eargs.directory)
|
||||||
cm = Meta(path=eargs.directory)
|
cm = Meta(path=eargs.directory)
|
||||||
ca = Attachment(path=eargs.directory)
|
ca = Attachment(path=eargs.directory)
|
||||||
cn = Network(eargs.directory)
|
cn = Network(path=eargs.directory)
|
||||||
|
|
||||||
|
ct.load()
|
||||||
cp.load()
|
cp.load()
|
||||||
cm.load()
|
cm.load()
|
||||||
ca.load()
|
ca.load()
|
||||||
|
@ -7,11 +7,16 @@ from cic import Proof
|
|||||||
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
|
||||||
|
from cic.token import Token
|
||||||
|
|
||||||
logg = logging.getLogger(__name__)
|
logg = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def process_args(argparser):
|
def process_args(argparser):
|
||||||
argparser.add_argument('--target', action='append', type=str, help='initialize network specification file with target')
|
argparser.add_argument('--target', action='append', type=str, help='initialize network specification file with target')
|
||||||
|
argparser.add_argument('--name', type=str, help='token name')
|
||||||
|
argparser.add_argument('--symbol', type=str, help='token symbol')
|
||||||
|
argparser.add_argument('--precision', type=str, help='token unit precision')
|
||||||
argparser.add_argument('directory', help='directory to initialize')
|
argparser.add_argument('directory', help='directory to initialize')
|
||||||
|
|
||||||
|
|
||||||
@ -22,11 +27,13 @@ def validate_args(args):
|
|||||||
def execute(config, eargs):
|
def execute(config, eargs):
|
||||||
os.makedirs(eargs.directory)
|
os.makedirs(eargs.directory)
|
||||||
|
|
||||||
|
ct = Token(eargs.directory, name=eargs.name, symbol=eargs.symbol, precision=eargs.precision)
|
||||||
cp = Proof(eargs.directory)
|
cp = Proof(eargs.directory)
|
||||||
cm = Meta(eargs.directory)
|
cm = Meta(eargs.directory)
|
||||||
ca = Attachment(eargs.directory)
|
ca = Attachment(eargs.directory)
|
||||||
cn = Network(eargs.directory, targets=eargs.target)
|
cn = Network(eargs.directory, targets=eargs.target)
|
||||||
|
|
||||||
|
ct.start()
|
||||||
cp.start()
|
cp.start()
|
||||||
cm.start()
|
cm.start()
|
||||||
ca.start()
|
ca.start()
|
||||||
|
@ -3,6 +3,7 @@ from cic import Proof
|
|||||||
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
|
||||||
|
from cic.token import Token
|
||||||
|
|
||||||
|
|
||||||
def process_args(argparser):
|
def process_args(argparser):
|
||||||
@ -15,18 +16,22 @@ def validate_args(args):
|
|||||||
|
|
||||||
|
|
||||||
def execute(config, eargs):
|
def execute(config, eargs):
|
||||||
|
ct = Token(path=eargs.directory)
|
||||||
cp = Proof(path=eargs.directory)
|
cp = Proof(path=eargs.directory)
|
||||||
cm = Meta(path=eargs.directory)
|
cm = Meta(path=eargs.directory)
|
||||||
ca = Attachment(path=eargs.directory)
|
ca = Attachment(path=eargs.directory)
|
||||||
cn = Network(eargs.directory)
|
cn = Network(eargs.directory)
|
||||||
|
|
||||||
|
ct.load()
|
||||||
cp.load()
|
cp.load()
|
||||||
cm.load()
|
cm.load()
|
||||||
ca.load()
|
ca.load()
|
||||||
cn.load()
|
cn.load()
|
||||||
|
|
||||||
print("Version: {}\n".format(cp.version()))
|
print("""[cic.header]
|
||||||
print("Proof:\n{}".format(cp))
|
version = {}\n""".format(cp.version()))
|
||||||
print("Meta:\n{}".format(cm))
|
print("[cic.token]\n{}".format(ct))
|
||||||
print("Attachments:\n{}".format(ca))
|
print("[cic.proof]\n{}".format(cp))
|
||||||
print("Network:\n{}".format(cn))
|
print("[cic.meta]\n{}".format(cm))
|
||||||
|
print("[cic.attachment]\n{}".format(ca))
|
||||||
|
print("[cic.network]\n{}".format(cn))
|
||||||
|
8
cic/data/token_template_v0.json
Normal file
8
cic/data/token_template_v0.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"name": "",
|
||||||
|
"symbol": "",
|
||||||
|
"precision": 0,
|
||||||
|
"code": null,
|
||||||
|
"extra": {}
|
||||||
|
}
|
||||||
|
|
@ -47,11 +47,11 @@ class Meta(Data):
|
|||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
s = ''
|
s = "contact.name = {}\n".format(self.name)
|
||||||
|
|
||||||
for k in self.contact.keys():
|
for k in self.contact.keys():
|
||||||
if self.contact[k] == '':
|
if self.contact[k] == '':
|
||||||
continue
|
continue
|
||||||
s += "{}: {}\n".format(k.lower(), self.contact[k])
|
s += "contact.{} = {}\n".format(k.lower(), self.contact[k])
|
||||||
|
|
||||||
return s
|
return s
|
||||||
|
@ -26,7 +26,7 @@ class Network(Data):
|
|||||||
o = json.load(f)
|
o = json.load(f)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
self.references = o['references']
|
self.resources = o['resources']
|
||||||
|
|
||||||
self.inited = True
|
self.inited = True
|
||||||
|
|
||||||
@ -58,10 +58,11 @@ class Network(Data):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
s = ''
|
s = ''
|
||||||
for k in self.references.keys():
|
for k in self.resources.keys():
|
||||||
v = self.references[k]
|
for kk in self.resources[k].keys():
|
||||||
|
v = self.resources[k][kk]
|
||||||
if v == None:
|
if v == None:
|
||||||
v = ''
|
v = ''
|
||||||
s += '{}: {}\n'.format(k, v)
|
s += '{}.{} = {}\n'.format(k, kk, v)
|
||||||
|
|
||||||
return s
|
return s
|
||||||
|
@ -47,7 +47,5 @@ class Proof(Data):
|
|||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return """description: {}
|
return "description = {}\n".format(self.description)
|
||||||
""".format(self.description)
|
|
||||||
|
65
cic/token.py
Normal file
65
cic/token.py
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
# standard imports
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
|
||||||
|
# local imports
|
||||||
|
from .base import (
|
||||||
|
Data,
|
||||||
|
data_dir,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class Token(Data):
|
||||||
|
|
||||||
|
def __init__(self, path='.', name=None, symbol=None, precision=1, code=None):
|
||||||
|
super(Token, self).__init__()
|
||||||
|
self.name = name
|
||||||
|
self.symbol = symbol
|
||||||
|
self.precision = precision
|
||||||
|
self.code = code
|
||||||
|
self.extra_args = None
|
||||||
|
self.path = path
|
||||||
|
self.token_path = os.path.join(self.path, 'token.json')
|
||||||
|
|
||||||
|
|
||||||
|
def load(self):
|
||||||
|
super(Token, self).load()
|
||||||
|
|
||||||
|
f = open(self.token_path, 'r')
|
||||||
|
o = json.load(f)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
self.name = o['name']
|
||||||
|
self.symbol = o['symbol']
|
||||||
|
self.precision = o['precision']
|
||||||
|
self.code = o['code']
|
||||||
|
self.extra_args = o['extra']
|
||||||
|
|
||||||
|
self.inited = True
|
||||||
|
|
||||||
|
|
||||||
|
def start(self):
|
||||||
|
super(Token, self).load()
|
||||||
|
|
||||||
|
token_template_file_path = os.path.join(data_dir, 'token_template_v{}.json'.format(self.version()))
|
||||||
|
|
||||||
|
f = open(token_template_file_path)
|
||||||
|
o = json.load(f)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
o['name'] = self.name
|
||||||
|
o['symbol'] = self.symbol
|
||||||
|
o['precision'] = self.precision
|
||||||
|
o['code'] = self.code
|
||||||
|
|
||||||
|
f = open(self.token_path, 'w')
|
||||||
|
json.dump(o, f)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
s = """name = {}
|
||||||
|
symbol = {}
|
||||||
|
precision = {}
|
||||||
|
""".format(self.name, self.symbol, self.precision)
|
||||||
|
return s
|
Loading…
Reference in New Issue
Block a user