2021-10-11 15:28:09 +02:00
|
|
|
# standard imports
|
|
|
|
import logging
|
|
|
|
|
|
|
|
logg = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2021-10-11 12:23:08 +02:00
|
|
|
class Processor:
|
2021-11-29 08:02:12 +01:00
|
|
|
"""Drives the serialization and publishing of contracts, proofs and metadata for the token.
|
|
|
|
|
|
|
|
:param proof: Proof object to publish
|
|
|
|
:type proof: cic.proof.Proof
|
|
|
|
:param attachment: Attachment object to publish
|
|
|
|
:type attachment: cic.attachment.Attachment
|
|
|
|
:param metadata: Metadata object to publish
|
|
|
|
:type metadata: cic.meta.Meta
|
|
|
|
:param writer: Writer interface receiving the output of the processor
|
|
|
|
:type writer: cic.output.OutputWriter
|
|
|
|
:param extensions: Extension contexts to publish to
|
|
|
|
:type extensions: list of cic.extension.Extension
|
|
|
|
"""
|
2021-10-11 19:13:21 +02:00
|
|
|
def __init__(self, proof=None, attachment=None, metadata=None, outputs_writer=None, extensions=[]):
|
2021-10-11 12:23:08 +02:00
|
|
|
self.token_address = None
|
2021-10-11 15:28:09 +02:00
|
|
|
self.extensions = extensions
|
2021-10-11 17:39:01 +02:00
|
|
|
self.cores = {
|
|
|
|
'metadata': metadata,
|
|
|
|
'attachment': attachment,
|
2021-10-11 19:13:21 +02:00
|
|
|
'proof': proof,
|
2021-10-11 17:39:01 +02:00
|
|
|
}
|
2021-10-11 15:28:09 +02:00
|
|
|
self.outputs = []
|
2021-10-11 12:23:08 +02:00
|
|
|
self.__outputs_writer = outputs_writer
|
|
|
|
|
|
|
|
|
|
|
|
def writer(self):
|
2021-11-29 08:02:12 +01:00
|
|
|
"""Return the writer instance that the process is using.
|
|
|
|
|
|
|
|
:rtype: cic.output.OutputWriter
|
|
|
|
:return: Writer
|
|
|
|
"""
|
2021-10-11 12:23:08 +02:00
|
|
|
return self.__outputs_writer
|
|
|
|
|
|
|
|
|
2021-10-11 15:28:09 +02:00
|
|
|
def get_outputs(self):
|
2021-11-29 08:02:12 +01:00
|
|
|
"""Return all written outputs.
|
|
|
|
|
|
|
|
This will return nothing unless the process method has been executed.
|
|
|
|
|
|
|
|
:rtype: bytes
|
|
|
|
:return: Outputs
|
|
|
|
"""
|
2021-10-11 15:28:09 +02:00
|
|
|
outputs = []
|
|
|
|
for ext in self.extensions:
|
|
|
|
outputs += ext.outputs
|
|
|
|
outputs += self.outputs
|
|
|
|
return outputs
|
2021-10-11 12:23:08 +02:00
|
|
|
|
|
|
|
|
2021-10-12 11:27:26 +02:00
|
|
|
def process(self, writer=None):
|
2021-11-29 08:02:12 +01:00
|
|
|
"""Serializes and publishes all token data.
|
|
|
|
|
|
|
|
Calls the process method on each extension. For each extension, the process method on attachment, proof and metadata, in that order, for any of them that have provided at processor object instantiation.
|
|
|
|
|
|
|
|
All output written to the publish writer will also be cached so that it subsequently be recalled using the get_outputs method.
|
|
|
|
|
|
|
|
:param writer: Writer to use for publishing.
|
|
|
|
:type writer: cic.output.OutputWriter
|
|
|
|
"""
|
2021-10-12 11:27:26 +02:00
|
|
|
|
2021-10-11 12:23:08 +02:00
|
|
|
tasks = [
|
2021-10-15 12:48:14 +02:00
|
|
|
'attachment',
|
|
|
|
'proof',
|
2021-10-11 19:13:21 +02:00
|
|
|
'metadata',
|
2021-10-11 12:23:08 +02:00
|
|
|
]
|
|
|
|
|
2021-10-11 15:28:09 +02:00
|
|
|
for ext in self.extensions:
|
2021-10-21 15:11:05 +02:00
|
|
|
(token_address, token_symbol) = ext.process()
|
2021-10-11 12:23:08 +02:00
|
|
|
|
2021-10-11 15:28:09 +02:00
|
|
|
for task in tasks:
|
2021-10-11 17:39:01 +02:00
|
|
|
a = self.cores.get(task)
|
2021-10-11 15:28:09 +02:00
|
|
|
if a == None:
|
|
|
|
logg.debug('skipping missing task receiver "{}"'.format(task))
|
|
|
|
continue
|
2021-10-21 15:11:05 +02:00
|
|
|
v = a.process(token_address=token_address, token_symbol=token_symbol, writer=self.__outputs_writer)
|
2021-10-11 15:28:09 +02:00
|
|
|
self.outputs.append(v)
|