Correct token index identifier generation

This commit is contained in:
lash 2022-01-14 10:12:15 +00:00
parent 8d67bcdfd2
commit 397c1310f7
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
3 changed files with 19 additions and 8 deletions

View File

@ -23,9 +23,8 @@ from chainlib.jsonrpc import JSONRPCRequest
from chainlib.eth.constant import ZERO_ADDRESS from chainlib.eth.constant import ZERO_ADDRESS
from hexathon import ( from hexathon import (
add_0x, add_0x,
strip_0x,
) )
from cic_contracts.registry import to_identifier
# local imports # local imports
from .interface import ( from .interface import (
#TokenUniqueSymbolIndex, #TokenUniqueSymbolIndex,
@ -38,6 +37,13 @@ moddir = os.path.dirname(__file__)
datadir = os.path.join(moddir, '..', 'data') datadir = os.path.join(moddir, '..', 'data')
def to_identifier(txt):
identifier_bytes = txt.upper().encode('utf-8')
h = hashlib.sha256()
identifier_bytes = h.update(identifier_bytes)
identifier = h.digest()
return identifier.hex()
#class TokenUniqueSymbolIndexAddressDeclarator(TokenUniqueSymbolIndex): #class TokenUniqueSymbolIndexAddressDeclarator(TokenUniqueSymbolIndex):
class TokenUniqueSymbolIndexAddressDeclarator(CICTokenIndex): class TokenUniqueSymbolIndexAddressDeclarator(CICTokenIndex):

View File

@ -1,6 +1,6 @@
[metadata] [metadata]
name = okota name = okota
version = 0.2.5 version = 0.2.6
description = Registries for CIC using the eth-address-index backend description = Registries for CIC using the eth-address-index backend
author = Louis Holbrook author = Louis Holbrook
author_email = dev@holbrook.no author_email = dev@holbrook.no

View File

@ -88,11 +88,16 @@ class TestTokenIndex(TestAddressDeclaratorBase):
r = self.rpc.do(o) r = self.rpc.do(o)
proofs = c.parse_declaration(r) proofs = c.parse_declaration(r)
h = hashlib.sha256() identifier = to_identifier('FOO')
h.update('FOO'.encode('utf-8')) #h = hashlib.sha256()
z = h.digest() #h.update('FOO'.encode('utf-8'))
#z = h.digest()
self.assertEqual(proofs[0], z.hex()) #self.assertEqual(proofs[0], z.hex())
self.assertEqual(proofs[0], identifier)
identifier = to_identifier('foo')
self.assertEqual(proofs[0], identifier)
if __name__ == '__main__': if __name__ == '__main__':