mirror of
git://holbrook.no/eth-address-index
synced 2024-11-30 11:56:45 +01:00
Implement address declarator for token index
This commit is contained in:
parent
320db688db
commit
dbec6596cf
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
||||
[{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"uint8","name":"_decimals","type":"uint8"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":true,"internalType":"address","name":"_spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":true,"internalType":"address","name":"_spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"TransferFrom","type":"event"},{"inputs":[{"internalType":"address","name":"_minter","type":"address"}],"name":"addMinter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"allowances","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_spender","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"mint","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_minter","type":"address"}],"name":"removeMinter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]
|
1
python/eth_address_declarator/token_index/__init__.py
Normal file
1
python/eth_address_declarator/token_index/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .interface import *
|
77
python/eth_address_declarator/token_index/index.py
Normal file
77
python/eth_address_declarator/token_index/index.py
Normal file
@ -0,0 +1,77 @@
|
||||
# Author: Louis Holbrook <dev@holbrook.no> 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
# File-version: 1
|
||||
# Description: Python interface to abi and bin files for token index with address declarator backend
|
||||
|
||||
# standard imports
|
||||
import logging
|
||||
import json
|
||||
import os
|
||||
import hashlib
|
||||
|
||||
# external imports
|
||||
from chainlib.eth.contract import (
|
||||
ABIContractEncoder,
|
||||
ABIContractType,
|
||||
abi_decode_single,
|
||||
)
|
||||
from chainlib.eth.tx import (
|
||||
TxFactory,
|
||||
TxFormat,
|
||||
)
|
||||
from chainlib.jsonrpc import JSONRPCRequest
|
||||
from chainlib.eth.constant import ZERO_ADDRESS
|
||||
from hexathon import (
|
||||
add_0x,
|
||||
)
|
||||
|
||||
# local imports
|
||||
from .interface import (
|
||||
TokenUniqueSymbolIndex,
|
||||
to_identifier,
|
||||
)
|
||||
|
||||
logg = logging.getLogger(__name__)
|
||||
|
||||
moddir = os.path.dirname(__file__)
|
||||
datadir = os.path.join(moddir, '..', 'data')
|
||||
|
||||
|
||||
|
||||
class TokenUniqueSymbolIndexAddressDeclarator(TokenUniqueSymbolIndex):
|
||||
|
||||
__abi = None
|
||||
__bytecode = None
|
||||
|
||||
|
||||
@staticmethod
|
||||
def abi():
|
||||
if TokenUniqueSymbolIndexAddressDeclarator.__abi == None:
|
||||
f = open(os.path.join(datadir, 'TokenUniqueSymbolIndexAddressDeclarator.json'), 'r')
|
||||
TokenUniqueSymbolIndexAddressDeclarator.__abi = json.load(f)
|
||||
f.close()
|
||||
return TokenUniqueSymbolIndexAddressDeclarator.__abi
|
||||
|
||||
|
||||
@staticmethod
|
||||
def bytecode():
|
||||
if TokenUniqueSymbolIndexAddressDeclarator.__bytecode == None:
|
||||
f = open(os.path.join(datadir, 'TokenUniqueSymbolIndexAddressDeclarator.bin'))
|
||||
TokenUniqueSymbolIndexAddressDeclarator.__bytecode = f.read()
|
||||
f.close()
|
||||
return TokenUniqueSymbolIndexAddressDeclarator.__bytecode
|
||||
|
||||
|
||||
@staticmethod
|
||||
def gas(code=None):
|
||||
return 1200000
|
||||
|
||||
|
||||
def constructor(self, sender_address, address_declarator_address):
|
||||
code = TokenUniqueSymbolIndexAddressDeclarator.bytecode()
|
||||
tx = self.template(sender_address, None, use_nonce=True)
|
||||
enc = ABIContractEncoder()
|
||||
enc.address(address_declarator_address)
|
||||
code += enc.get()
|
||||
tx = self.set_code(tx, code)
|
||||
return self.build(tx)
|
113
python/eth_address_declarator/token_index/interface.py
Normal file
113
python/eth_address_declarator/token_index/interface.py
Normal file
@ -0,0 +1,113 @@
|
||||
# Author: Louis Holbrook <dev@holbrook.no> 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
# File-version: 1
|
||||
# Description: Python interface to abi and bin files for faucet contracts
|
||||
|
||||
# standard imports
|
||||
import logging
|
||||
import json
|
||||
import os
|
||||
import hashlib
|
||||
|
||||
# external imports
|
||||
from chainlib.eth.contract import (
|
||||
ABIContractEncoder,
|
||||
ABIContractType,
|
||||
abi_decode_single,
|
||||
)
|
||||
from chainlib.eth.tx import (
|
||||
TxFactory,
|
||||
TxFormat,
|
||||
)
|
||||
from chainlib.jsonrpc import JSONRPCRequest
|
||||
from chainlib.eth.constant import ZERO_ADDRESS
|
||||
from hexathon import (
|
||||
add_0x,
|
||||
)
|
||||
|
||||
logg = logging.getLogger(__name__)
|
||||
|
||||
moddir = os.path.dirname(__file__)
|
||||
datadir = os.path.join(moddir, '..', 'data')
|
||||
|
||||
|
||||
def to_identifier(s):
|
||||
h = hashlib.new('sha256')
|
||||
h.update(s.encode('utf-8'))
|
||||
return h.digest().hex()
|
||||
|
||||
|
||||
class TokenUniqueSymbolIndex(TxFactory):
|
||||
|
||||
def register(self, contract_address, sender_address, address, tx_format=TxFormat.JSONRPC):
|
||||
enc = ABIContractEncoder()
|
||||
enc.method('register')
|
||||
enc.typ(ABIContractType.ADDRESS)
|
||||
enc.address(address)
|
||||
data = enc.get()
|
||||
tx = self.template(sender_address, contract_address, use_nonce=True)
|
||||
tx = self.set_code(tx, data)
|
||||
tx = self.finalize(tx, tx_format)
|
||||
return tx
|
||||
|
||||
|
||||
def address_of(self, contract_address, token_symbol, sender_address=ZERO_ADDRESS, id_generator=None):
|
||||
j = JSONRPCRequest(id_generator)
|
||||
o = j.template()
|
||||
o['method'] = 'eth_call'
|
||||
enc = ABIContractEncoder()
|
||||
enc.method('addressOf')
|
||||
enc.typ(ABIContractType.BYTES32)
|
||||
token_symbol_digest = to_identifier(token_symbol)
|
||||
enc.bytes32(token_symbol_digest)
|
||||
data = add_0x(enc.get())
|
||||
tx = self.template(sender_address, contract_address)
|
||||
tx = self.set_code(tx, data)
|
||||
o['params'].append(self.normalize(tx))
|
||||
o = j.finalize(o)
|
||||
return o
|
||||
|
||||
|
||||
def entry(self, contract_address, idx, sender_address=ZERO_ADDRESS, id_generator=None):
|
||||
j = JSONRPCRequest(id_generator)
|
||||
o = j.template()
|
||||
o['method'] = 'eth_call'
|
||||
enc = ABIContractEncoder()
|
||||
enc.method('entry')
|
||||
enc.typ(ABIContractType.UINT256)
|
||||
enc.uint256(idx)
|
||||
data = add_0x(enc.get())
|
||||
tx = self.template(sender_address, contract_address)
|
||||
tx = self.set_code(tx, data)
|
||||
o['params'].append(self.normalize(tx))
|
||||
o = j.finalize(o)
|
||||
return o
|
||||
|
||||
|
||||
def entry_count(self, contract_address, sender_address=ZERO_ADDRESS, id_generator=None):
|
||||
j = JSONRPCRequest(id_generator)
|
||||
o = j.template()
|
||||
o['method'] = 'eth_call'
|
||||
enc = ABIContractEncoder()
|
||||
enc.method('entryCount')
|
||||
data = add_0x(enc.get())
|
||||
tx = self.template(sender_address, contract_address)
|
||||
tx = self.set_code(tx, data)
|
||||
o['params'].append(self.normalize(tx))
|
||||
o = j.finalize(o)
|
||||
return o
|
||||
|
||||
|
||||
@classmethod
|
||||
def parse_address_of(self, v):
|
||||
return abi_decode_single(ABIContractType.ADDRESS, v)
|
||||
|
||||
|
||||
@classmethod
|
||||
def parse_entry(self, v):
|
||||
return abi_decode_single(ABIContractType.ADDRESS, v)
|
||||
|
||||
|
||||
@classmethod
|
||||
def parse_entry_count(self, v):
|
||||
return abi_decode_single(ABIContractType.UINT256, v)
|
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
||||
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"addedAccount","type":"address"},{"indexed":true,"internalType":"uint256","name":"accountIndex","type":"uint256"}],"name":"AddressAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"acceptOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"}],"name":"add","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_key","type":"bytes32"}],"name":"addressOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_idx","type":"uint256"}],"name":"entry","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"entryCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"}],"name":"register","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"registry","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]
|
@ -37,7 +37,7 @@ def to_identifier(s):
|
||||
return h.digest().hex()
|
||||
|
||||
|
||||
class TokenUniqueSymbolIndex(TxFactory):
|
||||
class TokenUniqueSymbolIndexAddressDeclarator(TxFactory):
|
||||
|
||||
__abi = None
|
||||
__bytecode = None
|
||||
@ -45,20 +45,20 @@ class TokenUniqueSymbolIndex(TxFactory):
|
||||
|
||||
@staticmethod
|
||||
def abi():
|
||||
if TokenUniqueSymbolIndex.__abi == None:
|
||||
f = open(os.path.join(datadir, 'TokenUniqueSymbolIndex.json'), 'r')
|
||||
TokenUniqueSymbolIndex.__abi = json.load(f)
|
||||
if TokenUniqueSymbolIndexAddressDeclarator.__abi == None:
|
||||
f = open(os.path.join(datadir, 'TokenUniqueSymbolIndexAddressDeclarator.json'), 'r')
|
||||
TokenUniqueSymbolIndexAddressDeclarator.__abi = json.load(f)
|
||||
f.close()
|
||||
return TokenUniqueSymbolIndex.__abi
|
||||
return TokenUniqueSymbolIndexAddressDeclarator.__abi
|
||||
|
||||
|
||||
@staticmethod
|
||||
def bytecode():
|
||||
if TokenUniqueSymbolIndex.__bytecode == None:
|
||||
f = open(os.path.join(datadir, 'TokenUniqueSymbolIndex.bin'))
|
||||
TokenUniqueSymbolIndex.__bytecode = f.read()
|
||||
if TokenUniqueSymbolIndexAddressDeclarator.__bytecode == None:
|
||||
f = open(os.path.join(datadir, 'TokenUniqueSymbolIndexAddressDeclarator.bin'))
|
||||
TokenUniqueSymbolIndexAddressDeclarator.__bytecode = f.read()
|
||||
f.close()
|
||||
return TokenUniqueSymbolIndex.__bytecode
|
||||
return TokenUniqueSymbolIndexAddressDeclarator.__bytecode
|
||||
|
||||
|
||||
@staticmethod
|
||||
@ -67,7 +67,7 @@ class TokenUniqueSymbolIndex(TxFactory):
|
||||
|
||||
|
||||
def constructor(self, sender_address):
|
||||
code = TokenUniqueSymbolIndex.bytecode()
|
||||
code = TokenUniqueSymbolIndexAddressDeclarator.bytecode()
|
||||
tx = self.template(sender_address, None, use_nonce=True)
|
||||
tx = self.set_code(tx, code)
|
||||
return self.build(tx)
|
||||
|
@ -4,7 +4,6 @@ import logging
|
||||
import hashlib
|
||||
|
||||
# external imports
|
||||
from tests.test_addressdeclarator_base import TestBase
|
||||
from eth_accounts_index import AccountsIndex
|
||||
from chainlib.eth.nonce import RPCNonceOracle
|
||||
from giftable_erc20_token import GiftableToken
|
||||
@ -15,6 +14,9 @@ from chainlib.eth.contract import ABIContractEncoder
|
||||
from eth_address_declarator.accounts_index import AccountsIndexAddressDeclarator
|
||||
from eth_address_declarator import Declarator
|
||||
|
||||
# test imports
|
||||
from tests.test_addressdeclarator_base import TestBase
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
|
||||
|
@ -12,76 +12,76 @@ from chainlib.eth.tx import receipt
|
||||
from giftable_erc20_token import GiftableToken
|
||||
from chainlib.eth.tx import unpack
|
||||
from hexathon import strip_0x
|
||||
from chainlib.eth.contract import ABIContractEncoder
|
||||
|
||||
# local imports
|
||||
from eth_token_index import TokenUniqueSymbolIndex
|
||||
from eth_address_declarator.token_index.index import (
|
||||
TokenUniqueSymbolIndexAddressDeclarator as TokenIndex,
|
||||
to_identifier,
|
||||
)
|
||||
from eth_address_declarator import Declarator
|
||||
|
||||
# test imports
|
||||
from tests.test_addressdeclarator_base import TestBase
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
|
||||
logging.getLogger('web3').setLevel(logging.WARNING)
|
||||
logging.getLogger('eth.vm').setLevel(logging.WARNING)
|
||||
|
||||
testdir = os.path.dirname(__file__)
|
||||
|
||||
|
||||
class Test(EthTesterCase):
|
||||
class TestTokenIndex(TestBase):
|
||||
|
||||
def setUp(self):
|
||||
super(Test, self).setUp()
|
||||
super(TestTokenIndex, self).setUp()
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
||||
#c = TokenUniqueSymbolIndex(signer=self.signer, nonce_oracle=nonce_oracle, chain_id=self.chain_spec.chain_id())
|
||||
c = TokenUniqueSymbolIndex(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
(tx_hash_hex, o) = c.constructor(self.accounts[0])
|
||||
c = TokenIndex(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
(tx_hash_hex, o) = c.constructor(self.accounts[0], self.address)
|
||||
self.rpc.do(o)
|
||||
|
||||
o = receipt(tx_hash_hex)
|
||||
r = self.rpc.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
|
||||
self.address = r['contract_address']
|
||||
|
||||
#c = GiftableToken(signer=self.signer, nonce_oracle=nonce_oracle, chain_id=self.chain_spec.chain_id())
|
||||
c = GiftableToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
(tx_hash_hex, o) = c.constructor(self.accounts[0], 'FooToken', 'FOO', 6)
|
||||
self.rpc.do(o)
|
||||
|
||||
o = receipt(tx_hash_hex)
|
||||
r = self.rpc.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
|
||||
self.token_address = r['contract_address']
|
||||
self.token_index_address = r['contract_address']
|
||||
|
||||
|
||||
def test_register(self):
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
||||
#c = TokenUniqueSymbolIndex(signer=self.signer, nonce_oracle=nonce_oracle, chain_id=self.chain_spec.chain_id())
|
||||
c = TokenUniqueSymbolIndex(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
c = TokenIndex(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
|
||||
(tx_hash_hex, o) = c.register(self.address, self.accounts[0], self.token_address)
|
||||
(tx_hash_hex, o) = c.register(self.token_index_address, self.accounts[0], self.foo_token_address)
|
||||
self.rpc.do(o)
|
||||
e = unpack(bytes.fromhex(strip_0x(o['params'][0])), self.chain_spec)
|
||||
logg.debug('e {}'.format(e))
|
||||
|
||||
o = receipt(tx_hash_hex)
|
||||
r = self.rpc.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
|
||||
o = c.address_of(self.address, 'FOO', sender_address=self.accounts[0])
|
||||
o = c.address_of(self.token_index_address, 'FOO', sender_address=self.accounts[0])
|
||||
r = self.rpc.do(o)
|
||||
address = c.parse_address_of(r)
|
||||
self.assertEqual(address, self.token_address)
|
||||
self.assertEqual(address, self.foo_token_address)
|
||||
|
||||
o = c.entry(self.address, 0, sender_address=self.accounts[0])
|
||||
o = c.entry(self.token_index_address, 0, sender_address=self.accounts[0])
|
||||
r = self.rpc.do(o)
|
||||
address = c.parse_entry(r)
|
||||
self.assertEqual(address, self.token_address)
|
||||
self.assertEqual(address, self.foo_token_address)
|
||||
|
||||
o = c.entry_count(self.address, sender_address=self.accounts[0])
|
||||
o = c.entry_count(self.token_index_address, sender_address=self.accounts[0])
|
||||
r = self.rpc.do(o)
|
||||
count = c.parse_entry_count(r)
|
||||
self.assertEqual(count, 1)
|
||||
|
||||
c = Declarator(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
o = c.declaration(self.address, self.accounts[0], self.foo_token_address, sender_address=self.accounts[0])
|
||||
r = self.rpc.do(o)
|
||||
proofs = c.parse_declaration(r)
|
||||
|
||||
token_symbol_identifier = to_identifier('FOO')
|
||||
|
||||
self.assertEqual(token_symbol_identifier, proofs[0])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
@ -3,7 +3,7 @@ pragma solidity >0.6.11;
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
|
||||
contract AdccountsIndexAddressDeclarator {
|
||||
contract AccountsIndexAddressDeclarator {
|
||||
|
||||
address public tokenAddress;
|
||||
bytes32 tokenAddressHash;
|
||||
|
@ -8,9 +8,9 @@ address_declarator:
|
||||
truncate -s -1 AddressDeclarator.bin
|
||||
|
||||
token_index:
|
||||
$(SOLC) TokenUniqueSymbolIndex.sol --abi --evm-version byzantium | awk 'NR>3' > TokenUniqueSymbolIndex.json
|
||||
$(SOLC) TokenUniqueSymbolIndex.sol --bin --evm-version byzantium | awk 'NR>3' > TokenUniqueSymbolIndex.bin
|
||||
truncate -s -1 TokenUniqueSymbolIndex.bin
|
||||
$(SOLC) TokenUniqueSymbolIndexAddressDeclarator.sol --abi --evm-version byzantium | awk 'NR>3' > TokenUniqueSymbolIndexAddressDeclarator.json
|
||||
$(SOLC) TokenUniqueSymbolIndexAddressDeclarator.sol --bin --evm-version byzantium | awk 'NR>3' > TokenUniqueSymbolIndexAddressDeclarator.bin
|
||||
truncate -s -1 TokenUniqueSymbolIndexAddressDeclarator.bin
|
||||
|
||||
|
||||
accounts_index:
|
||||
@ -24,7 +24,7 @@ accounts_index:
|
||||
|
||||
install: all
|
||||
cp -v AddressDeclarator.{json,bin} ../python/eth_address_declarator/data/
|
||||
cp -v TokenUniqueSymbolIndex.{json,bin} ../python/eth_token_index/data/
|
||||
cp -v TokenUniqueSymbolIndexAddressDeclarator.{json,bin} ../python/eth_address_declarator/data/
|
||||
cp -v AccountsIndexAddressDeclarator.{json,bin} ../python/eth_address_declarator/data/
|
||||
|
||||
.PHONY: test install
|
||||
|
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
||||
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"addedAccount","type":"address"},{"indexed":true,"internalType":"uint256","name":"accountIndex","type":"uint256"}],"name":"AddressAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"acceptOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"}],"name":"add","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_key","type":"bytes32"}],"name":"addressOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_idx","type":"uint256"}],"name":"entry","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"entryCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"}],"name":"register","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"registry","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]
|
||||
[{"inputs":[{"internalType":"address","name":"_addressDeclaratorAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"addedAccount","type":"address"},{"indexed":true,"internalType":"uint256","name":"accountIndex","type":"uint256"}],"name":"AddressAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"acceptOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"}],"name":"add","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"addressDeclaratorAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_key","type":"bytes32"}],"name":"addressOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_idx","type":"uint256"}],"name":"entry","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"entryCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"}],"name":"register","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"registry","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]
|
||||
|
@ -2,11 +2,12 @@ pragma solidity >0.6.11;
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
contract TokenUniqueSymbolIndex {
|
||||
contract TokenUniqueSymbolIndexAddressDeclarator {
|
||||
|
||||
// EIP 173
|
||||
address public owner;
|
||||
address newOwner;
|
||||
address public addressDeclaratorAddress;
|
||||
|
||||
mapping ( bytes32 => uint256 ) public registry;
|
||||
address[] tokens;
|
||||
@ -14,8 +15,9 @@ contract TokenUniqueSymbolIndex {
|
||||
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); // EIP173
|
||||
event AddressAdded(address indexed addedAccount, uint256 indexed accountIndex); // AccountsIndex
|
||||
|
||||
constructor() public {
|
||||
constructor(address _addressDeclaratorAddress) public {
|
||||
owner = msg.sender;
|
||||
addressDeclaratorAddress = _addressDeclaratorAddress;
|
||||
tokens.push(address(0));
|
||||
}
|
||||
|
||||
@ -35,21 +37,29 @@ contract TokenUniqueSymbolIndex {
|
||||
function register(address _token) public returns (bool) {
|
||||
require(msg.sender == owner);
|
||||
|
||||
bool ok;
|
||||
bytes memory r;
|
||||
|
||||
bytes memory token_symbol;
|
||||
bytes32 token_symbol_key;
|
||||
uint256 idx;
|
||||
|
||||
(bool _ok, bytes memory _r) = _token.call(abi.encodeWithSignature('symbol()'));
|
||||
require(_ok);
|
||||
(ok, r) = _token.call(abi.encodeWithSignature('symbol()'));
|
||||
require(ok);
|
||||
|
||||
token_symbol = abi.decode(_r, (bytes));
|
||||
token_symbol = abi.decode(r, (bytes));
|
||||
token_symbol_key = sha256(token_symbol);
|
||||
|
||||
(ok, r) = addressDeclaratorAddress.call(abi.encodeWithSignature("addDeclaration(address,bytes32)", _token, token_symbol_key));
|
||||
require(ok);
|
||||
require(r[31] == 0x01);
|
||||
|
||||
idx = registry[token_symbol_key];
|
||||
require(idx == 0);
|
||||
|
||||
registry[token_symbol_key] = tokens.length;
|
||||
tokens.push(_token);
|
||||
|
||||
emit AddressAdded(_token, tokens.length - 1);
|
||||
return true;
|
||||
}
|
Loading…
Reference in New Issue
Block a user