diff --git a/cic/attachment.py b/cic/attachment.py index 2dfeb54..434038f 100644 --- a/cic/attachment.py +++ b/cic/attachment.py @@ -55,6 +55,6 @@ class Attachment(Data): def __str__(self): s = '' 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 diff --git a/cic/base.py b/cic/base.py index fa3e379..5c8b752 100644 --- a/cic/base.py +++ b/cic/base.py @@ -29,6 +29,10 @@ class Data: raise RuntimeError('Object already initialized') + def verify(self): + return True + + def version(self): return self.__version diff --git a/cic/cmd/export.py b/cic/cmd/export.py index 77380cc..61ea0fd 100644 --- a/cic/cmd/export.py +++ b/cic/cmd/export.py @@ -7,6 +7,7 @@ from cic import Proof from cic.meta import Meta from cic.attachment import Attachment from cic.network import Network +from cic.token import Token logg = logging.getLogger(__name__) @@ -25,11 +26,13 @@ def execute(config, eargs): modname = 'cic.ext.{}'.format(eargs.target) cmd_mod = importlib.import_module(modname) + ct = Token(path=eargs.directory) cp = Proof(path=eargs.directory) cm = Meta(path=eargs.directory) ca = Attachment(path=eargs.directory) - cn = Network(eargs.directory) + cn = Network(path=eargs.directory) + ct.load() cp.load() cm.load() ca.load() diff --git a/cic/cmd/init.py b/cic/cmd/init.py index c82b2ed..0425a2a 100644 --- a/cic/cmd/init.py +++ b/cic/cmd/init.py @@ -7,11 +7,16 @@ from cic import Proof from cic.meta import Meta from cic.attachment import Attachment from cic.network import Network +from cic.token import Token + logg = logging.getLogger(__name__) def process_args(argparser): 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') @@ -22,11 +27,13 @@ def validate_args(args): def execute(config, eargs): os.makedirs(eargs.directory) + ct = Token(eargs.directory, name=eargs.name, symbol=eargs.symbol, precision=eargs.precision) cp = Proof(eargs.directory) cm = Meta(eargs.directory) ca = Attachment(eargs.directory) cn = Network(eargs.directory, targets=eargs.target) + ct.start() cp.start() cm.start() ca.start() diff --git a/cic/cmd/show.py b/cic/cmd/show.py index 50117f8..8186842 100644 --- a/cic/cmd/show.py +++ b/cic/cmd/show.py @@ -3,6 +3,7 @@ from cic import Proof from cic.meta import Meta from cic.attachment import Attachment from cic.network import Network +from cic.token import Token def process_args(argparser): @@ -15,18 +16,22 @@ def validate_args(args): def execute(config, eargs): + ct = Token(path=eargs.directory) cp = Proof(path=eargs.directory) cm = Meta(path=eargs.directory) ca = Attachment(path=eargs.directory) cn = Network(eargs.directory) + ct.load() cp.load() cm.load() ca.load() cn.load() - print("Version: {}\n".format(cp.version())) - print("Proof:\n{}".format(cp)) - print("Meta:\n{}".format(cm)) - print("Attachments:\n{}".format(ca)) - print("Network:\n{}".format(cn)) + print("""[cic.header] +version = {}\n""".format(cp.version())) + print("[cic.token]\n{}".format(ct)) + print("[cic.proof]\n{}".format(cp)) + print("[cic.meta]\n{}".format(cm)) + print("[cic.attachment]\n{}".format(ca)) + print("[cic.network]\n{}".format(cn)) diff --git a/cic/data/token_template_v0.json b/cic/data/token_template_v0.json new file mode 100644 index 0000000..91ae41e --- /dev/null +++ b/cic/data/token_template_v0.json @@ -0,0 +1,8 @@ +{ + "name": "", + "symbol": "", + "precision": 0, + "code": null, + "extra": {} +} + diff --git a/cic/meta.py b/cic/meta.py index becc79e..64e918b 100644 --- a/cic/meta.py +++ b/cic/meta.py @@ -47,11 +47,11 @@ class Meta(Data): def __str__(self): - s = '' + s = "contact.name = {}\n".format(self.name) for k in self.contact.keys(): if self.contact[k] == '': continue - s += "{}: {}\n".format(k.lower(), self.contact[k]) + s += "contact.{} = {}\n".format(k.lower(), self.contact[k]) return s diff --git a/cic/network.py b/cic/network.py index 16a905c..481b54f 100644 --- a/cic/network.py +++ b/cic/network.py @@ -26,7 +26,7 @@ class Network(Data): o = json.load(f) f.close() - self.references = o['references'] + self.resources = o['resources'] self.inited = True @@ -58,10 +58,11 @@ class Network(Data): def __str__(self): s = '' - for k in self.references.keys(): - v = self.references[k] - if v == None: - v = '' - s += '{}: {}\n'.format(k, v) + for k in self.resources.keys(): + for kk in self.resources[k].keys(): + v = self.resources[k][kk] + if v == None: + v = '' + s += '{}.{} = {}\n'.format(k, kk, v) return s diff --git a/cic/proof.py b/cic/proof.py index d9229a6..56b4346 100644 --- a/cic/proof.py +++ b/cic/proof.py @@ -46,8 +46,6 @@ class Proof(Data): json.dump(o, f) f.close() - def __str__(self): - return """description: {} -""".format(self.description) + return "description = {}\n".format(self.description) diff --git a/cic/token.py b/cic/token.py new file mode 100644 index 0000000..6b0901b --- /dev/null +++ b/cic/token.py @@ -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