Add token symbol metadata pointer

This commit is contained in:
nolash 2021-10-21 15:11:05 +02:00
parent 4518c8b700
commit fd6e9c23a7
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
6 changed files with 19 additions and 11 deletions

View File

@ -44,7 +44,7 @@ class Attachment(Data):
return self.contents
def process(self, token_address=None, writer=None):
def process(self, token_address=None, token_symbol=None, writer=None):
if writer == None:
writer = self.writer

View File

@ -95,6 +95,7 @@ class Extension:
tasks = []
self.token_address = self.resources['token']['reference']
# TODO: get token details when token address is not none
if self.token_address == None:
if self.token_details['code'] == None:
raise RuntimeError('neither token address nor token code has been set')
@ -114,4 +115,4 @@ class Extension:
logg.debug('ciceth adapter process {}'.format(task))
r = getattr(self, 'process_' + task)(writer=writer)
return self.token_address
return (self.token_address, self.token_details['symbol'])

View File

@ -66,12 +66,18 @@ class Meta(Data):
}
def process(self, token_address=None, writer=None):
def process(self, token_address=None, token_symbol=None, writer=None):
if writer == None:
writer = self.writer
k = self.reference(token_address)
v = json.dumps(self.asdict())
token_address_bytes = bytes.fromhex(strip_0x(token_address))
k = generate_metadata_pointer(token_address_bytes, MetadataPointer.TOKEN_META)
writer.write(k, v.encode('utf-8'))
token_symbol_bytes = token_symbol.encode('utf-8')
k = generate_metadata_pointer(token_symbol_bytes, MetadataPointer.TOKEN_META_SYMBOL)
writer.write(k, v.encode('utf-8'))
return (k, v)
@ -91,5 +97,6 @@ class Meta(Data):
class MetadataWriter(OutputWriter):
def write(self, k, v):
rq = MetadataRequestsHandler(MetadataPointer.TOKEN_META, bytes.fromhex(k))
rq = MetadataRequestsHandler(MetadataPointer.NONE, bytes.fromhex(k))
return rq.create(json.loads(v.decode('utf-8')))
rq = urllib.request.Request(self.path)

View File

@ -39,7 +39,7 @@ class Processor:
]
for ext in self.extensions:
token_address = ext.process()
(token_address, token_symbol) = ext.process()
for task in tasks:
a = self.cores.get(task)
@ -47,5 +47,5 @@ class Processor:
if a == None:
logg.debug('skipping missing task receiver "{}"'.format(task))
continue
v = a.process(token_address=token_address, writer=self.__outputs_writer)
v = a.process(token_address=token_address, token_symbol=token_symbol, writer=self.__outputs_writer)
self.outputs.append(v)

View File

@ -99,7 +99,7 @@ class Proof(Data):
return (hsh, hshs)
def process(self, token_address=None, writer=None):
def process(self, token_address=None, token_symbol=None, writer=None):
if writer == None:
writer = self.writer

View File

@ -1,5 +1,5 @@
funga-eth>=0.5.0a1,<0.6.0
cic-types>=0.2.0a4,<=0.2.0
cic-types>=0.2.1a1,<=0.2.1
confini>=0.4.2rc3,<0.5.0
chainlib>=0.0.10a3,<0.1.0
cbor2==5.4.1