From 33c0dac6783a048167cc07adc02128997536b735 Mon Sep 17 00:00:00 2001 From: nolash Date: Tue, 12 Oct 2021 11:27:26 +0200 Subject: [PATCH] Add writers to core processors from export cli cmd --- cic/attachment.py | 5 +++-- cic/cmd/export.py | 13 ++++++------- cic/ext/eth/__init__.py | 9 ++++++--- cic/processor.py | 4 +++- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/cic/attachment.py b/cic/attachment.py index d4f1cd9..436c0d0 100644 --- a/cic/attachment.py +++ b/cic/attachment.py @@ -58,7 +58,8 @@ class Attachment(Data): def __str__(self): s = '' - for i in range(len(self.contents)): - s += '{} = {}\n'.format(self.digests[i].hex(), self.contents[i]) + #for i in range(len(self.contents)): + for k in self.contents.keys(): + s += '{} = {}\n'.format(k, self.contents[k]) #self.digests[i].hex(), self.contents[i]) return s diff --git a/cic/cmd/export.py b/cic/cmd/export.py index a94c75e..50e8830 100644 --- a/cic/cmd/export.py +++ b/cic/cmd/export.py @@ -52,9 +52,9 @@ def execute(config, eargs): writers = init_writers_from_config(config) ct = Token(path=eargs.directory) - cm = Meta(path=eargs.directory, writer=writers['meta']) - ca = Attachment(path=eargs.directory, writer=writers['attachment']) - cp = Proof(path=eargs.directory, attachments=ca, writer=writers['proof']) + cm = Meta(path=eargs.directory, writer=writers['meta'](path=eargs.output_directory)) + ca = Attachment(path=eargs.directory, writer=writers['attachment'](path=eargs.output_directory)) + cp = Proof(path=eargs.directory, attachments=ca, writer=writers['proof'](path=eargs.output_directory)) cn = Network(path=eargs.directory) ct.load() @@ -77,9 +77,8 @@ def execute(config, eargs): 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, rpc=rpc) + c = getattr(cmd_mod, 'new')(chain_spec, ref['contents'], cp, signer_hint=signer, rpc=rpc, outputs_writer=writers['ext'](path=eargs.output_directory)) c.apply_token(ct) - p = Processor(proof=cp, attachment=ca, metadata=cm, extensions=[eargs.target]) - - c.process(writer=writers['ext'](path=eargs.output_directory)) + p = Processor(proof=cp, attachment=ca, metadata=cm, extensions=[c]) + p.process() diff --git a/cic/ext/eth/__init__.py b/cic/ext/eth/__init__.py index f4c2f68..1797aec 100644 --- a/cic/ext/eth/__init__.py +++ b/cic/ext/eth/__init__.py @@ -156,7 +156,9 @@ class CICEth(Extension): if r == None: r = code - self.add_outputs('token', r) + writer.write('token_address', self.token_address.encode('utf-8')) + writer.write('token', r.encode('utf-8')) + self.add_outputs('token', r.encode('utf-8')) return r @@ -183,6 +185,7 @@ class CICEth(Extension): else: r = o + writer.write('token_index', r.encode('utf-8')) self.add_outputs('token_index', r) return r @@ -230,5 +233,5 @@ class CICEth(Extension): self.token_address = add_0x(to_checksum_address(self.token_address)) -def new(chain_spec, resources, proof, signer_hint=None, rpc=None): - return CICEth(chain_spec, resources, proof, signer=signer_hint, rpc=rpc) +def new(chain_spec, resources, proof, signer_hint=None, rpc=None, outputs_writer=None): + return CICEth(chain_spec, resources, proof, signer=signer_hint, rpc=rpc, outputs_writer=outputs_writer) diff --git a/cic/processor.py b/cic/processor.py index a2ecb62..508576b 100644 --- a/cic/processor.py +++ b/cic/processor.py @@ -30,7 +30,8 @@ class Processor: return outputs - def process(self): + def process(self, writer=None): + tasks = [ 'proof', 'attachment', @@ -42,6 +43,7 @@ class Processor: for task in tasks: a = self.cores.get(task) + logg.debug('>>>>>>> checking task {} {}'.format(task, a)) if a == None: logg.debug('skipping missing task receiver "{}"'.format(task)) continue