diff --git a/cic/cmd/export.py b/cic/cmd/export.py index 095b95b..4fc634f 100644 --- a/cic/cmd/export.py +++ b/cic/cmd/export.py @@ -12,6 +12,7 @@ from cic import ( Proof, Processor, ) +from cic.proof import ProofWriter from cic.meta import ( Meta, MetadataWriter, @@ -26,6 +27,7 @@ logg = logging.getLogger(__name__) def process_args(argparser): argparser.add_argument('-d', '--directory', type=str, dest='directory', default='.', help='directory') argparser.add_argument('-o', '--output-directory', type=str, dest='output_directory', help='output directory') + argparser.add_argument('--metadata-endpoint', dest='metadata_endpoint', type=str, help='metadata endpoint to interact with') argparser.add_argument('-y', '--signer', type=str, dest='y', help='target-specific signer to use for export') argparser.add_argument('-p', type=str, help='RPC endpoint') argparser.add_argument('target', type=str, help='target network type') @@ -57,17 +59,21 @@ def execute(config, eargs): cmd_mod = importlib.import_module(modname) writers = init_writers_from_config(config) - - MetadataRequestsHandler.base_url = 'http://localhost:63380' - MetadataSigner.gpg_path = os.path.join('/tmp') - MetadataSigner.key_file_path = '/home/lash/src/client/cic/grassrootseconomics/cic-internal-integration/apps/cic-ussd/tests/data/pgp/privatekeys_meta.asc' - MetadataSigner.gpg_passphrase = 'merman' + + output_writer_path_meta = eargs.output_directory + if eargs.metadata_endpoint != None: + MetadataRequestsHandler.base_url = eargs.metadata_endpoint + MetadataSigner.gpg_path = os.path.join('/tmp') + MetadataSigner.key_file_path = '/home/lash/src/client/cic/grassrootseconomics/cic-internal-integration/apps/cic-ussd/tests/data/pgp/privatekeys_meta.asc' + MetadataSigner.gpg_passphrase = 'merman' + writers['proof'] = ProofWriter + writers['meta'] = MetadataWriter + output_writer_path_meta = eargs.metadata_endpoint ct = Token(path=eargs.directory) - #cm = Meta(path=eargs.directory, writer=writers['meta'](path=eargs.output_directory)) - cm = Meta(path=eargs.directory, writer=MetadataWriter()) - 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)) + cm = Meta(path=eargs.directory, writer=writers['meta'](path=output_writer_path_meta)) + ca = Attachment(path=eargs.directory, writer=writers['attachment'](path=output_writer_path_meta)) + cp = Proof(path=eargs.directory, attachments=ca, writer=writers['proof'](path=output_writer_path_meta)) cn = Network(path=eargs.directory) ct.load() diff --git a/cic/ext/eth/__init__.py b/cic/ext/eth/__init__.py index 3aa2311..0d8a393 100644 --- a/cic/ext/eth/__init__.py +++ b/cic/ext/eth/__init__.py @@ -204,6 +204,7 @@ class CICEth(Extension): else: r = o + logg.debug('>>>>>>>>>>>>>>>>>>>>>>>>>> token index result {} {}'.format(r, o)) writer.write('token_index', r.encode('utf-8')) self.add_outputs('token_index', r) return r diff --git a/cic/meta.py b/cic/meta.py index 3263dfe..fa08415 100644 --- a/cic/meta.py +++ b/cic/meta.py @@ -93,4 +93,3 @@ class MetadataWriter(OutputWriter): def write(self, k, v): rq = MetadataRequestsHandler(MetadataPointer.TOKEN_META, bytes.fromhex(k)) return rq.create(json.loads(v.decode('utf-8'))) - diff --git a/cic/output.py b/cic/output.py index 5ef5449..b392d23 100644 --- a/cic/output.py +++ b/cic/output.py @@ -24,7 +24,10 @@ class StdoutWriter(OutputWriter): class KVWriter(OutputWriter): def __init__(self, path=None, *args, **kwargs): - os.stat(path) + try: + os.stat(path) + except FileNotFoundError: + os.makedirs(path) self.path = path diff --git a/cic/processor.py b/cic/processor.py index acd0b34..e3f164d 100644 --- a/cic/processor.py +++ b/cic/processor.py @@ -49,4 +49,3 @@ class Processor: continue v = a.process(token_address=token_address, writer=self.__outputs_writer) self.outputs.append(v) - diff --git a/cic/proof.py b/cic/proof.py index fc0ab82..0d6282c 100644 --- a/cic/proof.py +++ b/cic/proof.py @@ -4,12 +4,18 @@ import json import logging import tempfile import cbor2 +import base64 +import urllib.request # external imports from hexathon import strip_0x +from cic_types import MetadataPointer +from cic_types.processor import generate_metadata_pointer +from cic_types.ext.metadata import MetadataRequestsHandler # local imports from .base import * +from cic.output import OutputWriter logg = logging.getLogger(__name__) @@ -121,3 +127,17 @@ class Proof(Data): def __str__(self): return "description = {}\n".format(self.description) + + +class ProofWriter(OutputWriter): + + + def __init__(self, path=None, *args, **kwargs): + super(ProofWriter, self).__init__(*args, **kwargs) + self.path = path + + + def write(self, k, v): + rq = urllib.request.Request(self.path, method='POST', data=v) + r = urllib.request.urlopen(rq) + logg.info('proof submited at {}'.format(r.read(dd))) diff --git a/eth_requirements.txt b/eth_requirements.txt index 2b836b5..7b46917 100644 --- a/eth_requirements.txt +++ b/eth_requirements.txt @@ -1,4 +1,4 @@ -chainlib-eth>=0.0.10a1,<0.1.0 +chainlib-eth>=0.0.10a5,<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 diff --git a/requirements.txt b/requirements.txt index 8cfa0e6..94b1a28 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ funga-eth>=0.5.0a1,<0.6.0 cic-types>=0.2.0a4,<=0.2.0 confini>=0.4.2rc3,<0.5.0 -chainlib>=0.0.10a1,<0.1.0 +chainlib>=0.0.10a3,<0.1.0 cbor2==5.4.1