mirror of
git://holbrook.no/eth-address-index
synced 2024-11-16 06:26:46 +01:00
Add test for address index for declarator implementation
This commit is contained in:
parent
507c379da8
commit
320db688db
1
python/eth_address_declarator/accounts_index/__init__.py
Normal file
1
python/eth_address_declarator/accounts_index/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from .accounts_index import *
|
@ -0,0 +1,54 @@
|
|||||||
|
# standard imports
|
||||||
|
import os
|
||||||
|
|
||||||
|
# external imports
|
||||||
|
from chainlib.eth.tx import (
|
||||||
|
TxFormat,
|
||||||
|
)
|
||||||
|
from chainlib.eth.contract import (
|
||||||
|
ABIContractEncoder,
|
||||||
|
ABIContractType,
|
||||||
|
)
|
||||||
|
from eth_accounts_index.interface import AccountsIndex
|
||||||
|
|
||||||
|
moddir = os.path.dirname(__file__)
|
||||||
|
datadir = os.path.join(moddir, '..', 'data')
|
||||||
|
|
||||||
|
|
||||||
|
class AccountsIndexAddressDeclarator(AccountsIndex):
|
||||||
|
|
||||||
|
__abi = None
|
||||||
|
__bytecode = None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def abi():
|
||||||
|
if AccountsIndexAddressDeclarator.__abi == None:
|
||||||
|
f = open(os.path.join(datadir, 'AccountsIndexAddressDeclarator.json'), 'r')
|
||||||
|
AccountsIndexAddressDeclarator.__abi = json.load(f)
|
||||||
|
f.close()
|
||||||
|
return AccountsIndexAddressDeclarator.__abi
|
||||||
|
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def bytecode():
|
||||||
|
if AccountsIndexAddressDeclarator.__bytecode == None:
|
||||||
|
f = open(os.path.join(datadir, 'AccountsIndexAddressDeclarator.bin'))
|
||||||
|
AccountsIndexAddressDeclarator.__bytecode = f.read()
|
||||||
|
f.close()
|
||||||
|
return AccountsIndexAddressDeclarator.__bytecode
|
||||||
|
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def gas(code=None):
|
||||||
|
return 1200000
|
||||||
|
|
||||||
|
|
||||||
|
def constructor(self, sender_address, context_address, address_declarator_address):
|
||||||
|
code = AccountsIndexAddressDeclarator.bytecode()
|
||||||
|
tx = self.template(sender_address, None, use_nonce=True)
|
||||||
|
enc = ABIContractEncoder()
|
||||||
|
enc.address(context_address)
|
||||||
|
enc.address(address_declarator_address)
|
||||||
|
code += enc.get()
|
||||||
|
tx = self.set_code(tx, code)
|
||||||
|
return self.build(tx)
|
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
|||||||
[{"inputs":[{"internalType":"bytes32","name":"_initialDescription","type":"bytes32"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_declarator","type":"address"},{"indexed":false,"internalType":"address","name":"_subject","type":"address"},{"indexed":false,"internalType":"bytes32","name":"_proof","type":"bytes32"}],"name":"DeclarationAdded","type":"event"},{"inputs":[{"internalType":"address","name":"_subject","type":"address"},{"internalType":"bytes32","name":"_proof","type":"bytes32"}],"name":"addDeclaration","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"contents","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_declarator","type":"address"},{"internalType":"address","name":"_subject","type":"address"}],"name":"declaration","outputs":[{"internalType":"bytes32[]","name":"","type":"bytes32[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_declarator","type":"address"},{"internalType":"uint256","name":"_idx","type":"uint256"}],"name":"declarationAddressAt","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_declarator","type":"address"}],"name":"declarationCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_subject","type":"address"},{"internalType":"uint256","name":"_idx","type":"uint256"}],"name":"declaratorAddressAt","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_subject","type":"address"}],"name":"declaratorCount","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":"bytes32","name":"_initialDescription","type":"bytes32"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_declarator","type":"address"},{"indexed":false,"internalType":"address","name":"_subject","type":"address"},{"indexed":false,"internalType":"bytes32","name":"_proof","type":"bytes32"}],"name":"DeclarationAdded","type":"event"},{"inputs":[{"internalType":"address","name":"_subject","type":"address"},{"internalType":"bytes32","name":"_proof","type":"bytes32"}],"name":"addDeclaration","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"contents","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_declarator","type":"address"},{"internalType":"address","name":"_subject","type":"address"}],"name":"declaration","outputs":[{"internalType":"bytes32[]","name":"","type":"bytes32[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_declarator","type":"address"},{"internalType":"uint256","name":"_idx","type":"uint256"}],"name":"declarationAddressAt","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_declarator","type":"address"}],"name":"declarationCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_subject","type":"address"},{"internalType":"uint256","name":"_idx","type":"uint256"}],"name":"declaratorAddressAt","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_subject","type":"address"}],"name":"declaratorCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_declarator","type":"address"},{"internalType":"address","name":"_subject","type":"address"},{"internalType":"bytes32","name":"_proof","type":"bytes32"}],"name":"haveDeclaration","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"}]
|
||||||
|
File diff suppressed because one or more lines are too long
@ -1,6 +1,6 @@
|
|||||||
[metadata]
|
[metadata]
|
||||||
name = eth-address-index
|
name = eth-address-index
|
||||||
version = 0.2.3a5
|
version = 0.2.4a1
|
||||||
description = Signed metadata declarations for ethereum addresses
|
description = Signed metadata declarations for ethereum addresses
|
||||||
author = Louis Holbrook
|
author = Louis Holbrook
|
||||||
author_email = dev@holbrook.no
|
author_email = dev@holbrook.no
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
eth-tester==0.5.0b3
|
eth-tester==0.5.0b3
|
||||||
py-evm==0.3.0a20
|
py-evm==0.3.0a20
|
||||||
|
eth-accounts-index>=0.1.2a3,<0.2.0
|
||||||
|
70
python/tests/test_accounts_index.py
Normal file
70
python/tests/test_accounts_index.py
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
# standard imports
|
||||||
|
import unittest
|
||||||
|
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
|
||||||
|
from chainlib.eth.tx import receipt
|
||||||
|
from chainlib.eth.contract import ABIContractEncoder
|
||||||
|
|
||||||
|
# local imports
|
||||||
|
from eth_address_declarator.accounts_index import AccountsIndexAddressDeclarator
|
||||||
|
from eth_address_declarator import Declarator
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
logg = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
|
class TestAccountsIndex(TestBase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestAccountsIndex, self).setUp()
|
||||||
|
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
||||||
|
|
||||||
|
c = AccountsIndexAddressDeclarator(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||||
|
(tx_hash_hex, o) = c.constructor(self.accounts[0], self.foo_token_address, self.address)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
|
||||||
|
o = receipt(tx_hash_hex)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
self.assertEqual(r['status'], 1)
|
||||||
|
|
||||||
|
self.accounts_index_address = r['contract_address']
|
||||||
|
logg.debug('accounts index deployed with address {}'.format(self.accounts_index_address))
|
||||||
|
|
||||||
|
|
||||||
|
def test_accounts_index_address_declarator(self):
|
||||||
|
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
||||||
|
c = AccountsIndex(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||||
|
(tx_hash, o) = c.add(self.accounts_index_address, self.accounts[0], self.accounts[1])
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
self.assertEqual(tx_hash, r)
|
||||||
|
|
||||||
|
o = receipt(tx_hash)
|
||||||
|
rcpt = self.rpc.do(o)
|
||||||
|
|
||||||
|
self.helper.mine_block()
|
||||||
|
o = c.have(self.accounts_index_address, self.accounts[1], sender_address=self.accounts[0])
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
|
||||||
|
c = Declarator(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||||
|
o = c.declaration(self.address, self.accounts[0], self.accounts[1], sender_address=self.accounts[0])
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
proofs = c.parse_declaration(r)
|
||||||
|
|
||||||
|
enc = ABIContractEncoder()
|
||||||
|
enc.address(self.foo_token_address)
|
||||||
|
token_address_padded = enc.get()
|
||||||
|
logg.debug('proof {} {}'.format(proofs, token_address_padded))
|
||||||
|
h = hashlib.sha256()
|
||||||
|
h.update(bytes.fromhex(token_address_padded))
|
||||||
|
r = h.digest()
|
||||||
|
self.assertEqual(r.hex(), proofs[0])
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
@ -14,49 +14,29 @@ from chainlib.eth.contract import (
|
|||||||
from chainlib.eth.nonce import RPCNonceOracle
|
from chainlib.eth.nonce import RPCNonceOracle
|
||||||
from chainlib.eth.tx import receipt
|
from chainlib.eth.tx import receipt
|
||||||
from giftable_erc20_token import GiftableToken
|
from giftable_erc20_token import GiftableToken
|
||||||
from hexathon import add_0x
|
from hexathon import (
|
||||||
|
add_0x,
|
||||||
|
strip_0x,
|
||||||
|
)
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from eth_address_declarator.declarator import AddressDeclarator
|
from eth_address_declarator.declarator import AddressDeclarator
|
||||||
from eth_address_declarator import Declarator
|
from eth_address_declarator import Declarator
|
||||||
|
from tests.test_addressdeclarator_base import TestBase
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
|
||||||
logging.getLogger('web3').setLevel(logging.WARNING)
|
|
||||||
logging.getLogger('eth.vm').setLevel(logging.WARNING)
|
|
||||||
|
|
||||||
testdir = os.path.dirname(__file__)
|
testdir = os.path.dirname(__file__)
|
||||||
|
|
||||||
description = '0x{:<064s}'.format(b'foo'.hex())
|
description = '0x{:<064s}'.format(b'foo'.hex())
|
||||||
|
|
||||||
class Test(EthTesterCase):
|
|
||||||
|
class TestAddressDeclarator(TestBase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(Test, self).setUp()
|
super(TestAddressDeclarator, self).setUp()
|
||||||
self.description = add_0x(os.urandom(32).hex())
|
|
||||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
||||||
#c = AddressDeclarator(signer=self.signer, nonce_oracle=nonce_oracle, chain_id=self.chain_spec.chain_id())
|
|
||||||
c = AddressDeclarator(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
|
||||||
(tx_hash_hex, o) = c.constructor(self.accounts[0], self.description)
|
|
||||||
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.foo_token_address = r['contract_address']
|
|
||||||
|
|
||||||
#c = GiftableToken(signer=self.signer, nonce_oracle=nonce_oracle, chain_id=self.chain_spec.chain_id())
|
#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)
|
c = GiftableToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||||
@ -98,6 +78,23 @@ class Test(EthTesterCase):
|
|||||||
self.assertEqual(c.parse_declarator_count(r), 1)
|
self.assertEqual(c.parse_declarator_count(r), 1)
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_single_declaration(self):
|
||||||
|
d = add_0x(os.urandom(32).hex())
|
||||||
|
|
||||||
|
nonce_oracle = RPCNonceOracle(self.accounts[1], self.rpc)
|
||||||
|
c = Declarator(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||||
|
(tx_hash_hex, o) = c.add_declaration(self.address, self.accounts[1], self.foo_token_address, d)
|
||||||
|
self.rpc.do(o)
|
||||||
|
o = receipt(tx_hash_hex)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
self.assertEqual(r['status'], 1)
|
||||||
|
|
||||||
|
o = c.declaration(self.address, self.accounts[1], self.foo_token_address, sender_address=self.accounts[0])
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
proofs = c.parse_declaration(r)
|
||||||
|
self.assertEqual(proofs[0], strip_0x(d))
|
||||||
|
|
||||||
|
|
||||||
def test_declaration(self):
|
def test_declaration(self):
|
||||||
|
|
||||||
d = add_0x(os.urandom(32).hex())
|
d = add_0x(os.urandom(32).hex())
|
||||||
@ -124,9 +121,8 @@ class Test(EthTesterCase):
|
|||||||
o = c.declaration(self.address, self.accounts[1], self.foo_token_address, sender_address=self.accounts[0])
|
o = c.declaration(self.address, self.accounts[1], self.foo_token_address, sender_address=self.accounts[0])
|
||||||
r = self.rpc.do(o)
|
r = self.rpc.do(o)
|
||||||
proofs = c.parse_declaration(r)
|
proofs = c.parse_declaration(r)
|
||||||
self.assertEqual(proofs[0], d[2:])
|
self.assertEqual(proofs[0], strip_0x(d))
|
||||||
self.assertEqual(proofs[1], d_two[2:])
|
self.assertEqual(proofs[1], strip_0x(d_two))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_declarator_to_subject(self):
|
def test_declarator_to_subject(self):
|
||||||
|
46
python/tests/test_addressdeclarator_base.py
Normal file
46
python/tests/test_addressdeclarator_base.py
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
# standard imports
|
||||||
|
import unittest
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
|
# external imports
|
||||||
|
from hexathon import add_0x
|
||||||
|
from chainlib.eth.unittest.ethtester import EthTesterCase
|
||||||
|
from chainlib.eth.nonce import RPCNonceOracle
|
||||||
|
from chainlib.eth.tx import receipt
|
||||||
|
from giftable_erc20_token import GiftableToken
|
||||||
|
|
||||||
|
# local imports
|
||||||
|
from eth_address_declarator.declarator import AddressDeclarator
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
logg = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
|
class TestBase(EthTesterCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestBase, self).setUp()
|
||||||
|
self.description = add_0x(os.urandom(32).hex())
|
||||||
|
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
||||||
|
c = AddressDeclarator(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||||
|
(tx_hash_hex, o) = c.constructor(self.accounts[0], self.description)
|
||||||
|
self.rpc.do(o)
|
||||||
|
|
||||||
|
o = receipt(tx_hash_hex)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
self.assertEqual(r['status'], 1)
|
||||||
|
|
||||||
|
self.address = r['contract_address']
|
||||||
|
logg.debug('address declarator deployed with address {}'.format(self.address))
|
||||||
|
|
||||||
|
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.foo_token_address = r['contract_address']
|
||||||
|
logg.debug('foo token deployed with address {}'.format(self.foo_token_address))
|
50
solidity/AccountsIndexAddressDeclarator.sol
Normal file
50
solidity/AccountsIndexAddressDeclarator.sol
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
pragma solidity >0.6.11;
|
||||||
|
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
|
||||||
|
contract AdccountsIndexAddressDeclarator {
|
||||||
|
|
||||||
|
address public tokenAddress;
|
||||||
|
bytes32 tokenAddressHash;
|
||||||
|
address public addressDeclaratorAddress;
|
||||||
|
mapping(address => uint256) entryIndex;
|
||||||
|
uint256 count;
|
||||||
|
|
||||||
|
address public owner;
|
||||||
|
address newOwner;
|
||||||
|
|
||||||
|
event AddressAdded(address indexed addedAccount, uint256 indexed accountIndex); // AccountsIndex
|
||||||
|
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); // EIP173
|
||||||
|
|
||||||
|
constructor(address _tokenAddress, address _addressDeclaratorAddress) public {
|
||||||
|
bytes memory _tokenAddressPadded;
|
||||||
|
owner = msg.sender;
|
||||||
|
addressDeclaratorAddress = _addressDeclaratorAddress;
|
||||||
|
tokenAddress = _tokenAddress;
|
||||||
|
_tokenAddressPadded = abi.encode(tokenAddress);
|
||||||
|
tokenAddressHash = sha256(_tokenAddressPadded);
|
||||||
|
count = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
function add(address _account) external returns (bool) {
|
||||||
|
bool ok;
|
||||||
|
bytes memory r;
|
||||||
|
uint256 oldEntryIndex;
|
||||||
|
|
||||||
|
(ok, r) = addressDeclaratorAddress.call(abi.encodeWithSignature("addDeclaration(address,bytes32)", _account, tokenAddressHash));
|
||||||
|
require(ok);
|
||||||
|
require(r[31] == 0x01);
|
||||||
|
|
||||||
|
oldEntryIndex = count;
|
||||||
|
entryIndex[_account] = oldEntryIndex;
|
||||||
|
count++;
|
||||||
|
|
||||||
|
emit AddressAdded(_account, oldEntryIndex);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function have(address _account) external view returns (bool) {
|
||||||
|
return entryIndex[_account] > 0;
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
|||||||
[{"inputs":[{"internalType":"bytes32","name":"_initialDescription","type":"bytes32"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_declarator","type":"address"},{"indexed":false,"internalType":"address","name":"_subject","type":"address"},{"indexed":false,"internalType":"bytes32","name":"_proof","type":"bytes32"}],"name":"DeclarationAdded","type":"event"},{"inputs":[{"internalType":"address","name":"_subject","type":"address"},{"internalType":"bytes32","name":"_proof","type":"bytes32"}],"name":"addDeclaration","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"contents","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_declarator","type":"address"},{"internalType":"address","name":"_subject","type":"address"}],"name":"declaration","outputs":[{"internalType":"bytes32[]","name":"","type":"bytes32[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_declarator","type":"address"},{"internalType":"uint256","name":"_idx","type":"uint256"}],"name":"declarationAddressAt","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_declarator","type":"address"}],"name":"declarationCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_subject","type":"address"},{"internalType":"uint256","name":"_idx","type":"uint256"}],"name":"declaratorAddressAt","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_subject","type":"address"}],"name":"declaratorCount","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":"bytes32","name":"_initialDescription","type":"bytes32"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_declarator","type":"address"},{"indexed":false,"internalType":"address","name":"_subject","type":"address"},{"indexed":false,"internalType":"bytes32","name":"_proof","type":"bytes32"}],"name":"DeclarationAdded","type":"event"},{"inputs":[{"internalType":"address","name":"_subject","type":"address"},{"internalType":"bytes32","name":"_proof","type":"bytes32"}],"name":"addDeclaration","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"contents","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_declarator","type":"address"},{"internalType":"address","name":"_subject","type":"address"}],"name":"declaration","outputs":[{"internalType":"bytes32[]","name":"","type":"bytes32[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_declarator","type":"address"},{"internalType":"uint256","name":"_idx","type":"uint256"}],"name":"declarationAddressAt","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_declarator","type":"address"}],"name":"declarationCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_subject","type":"address"},{"internalType":"uint256","name":"_idx","type":"uint256"}],"name":"declaratorAddressAt","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_subject","type":"address"}],"name":"declaratorCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_declarator","type":"address"},{"internalType":"address","name":"_subject","type":"address"},{"internalType":"bytes32","name":"_proof","type":"bytes32"}],"name":"haveDeclaration","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"}]
|
||||||
|
@ -5,9 +5,10 @@ pragma solidity >0.6.11;
|
|||||||
contract AddressDeclarator {
|
contract AddressDeclarator {
|
||||||
|
|
||||||
mapping( address => address[] ) declarationIndex;
|
mapping( address => address[] ) declarationIndex;
|
||||||
mapping( bytes32 => uint256 ) declarationContentIndex;
|
mapping( bytes32 => uint256 ) declarationContentIndex; // the _latest_ content pointer for the declarator to subject mapping
|
||||||
mapping( address => address[] ) declarator;
|
mapping( address => address[] ) declarator;
|
||||||
mapping( address => address[] ) declaratorReverse;
|
mapping( address => address[] ) declaratorReverse;
|
||||||
|
mapping( bytes32 => bool ) declarationExistIndex;
|
||||||
bytes32[][] public contents;
|
bytes32[][] public contents;
|
||||||
|
|
||||||
event DeclarationAdded(address _declarator, address _subject, bytes32 _proof);
|
event DeclarationAdded(address _declarator, address _subject, bytes32 _proof);
|
||||||
@ -36,6 +37,25 @@ contract AddressDeclarator {
|
|||||||
return k;
|
return k;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toReference(address _declarator, address _subject, bytes32 _proof) private pure returns ( bytes32[2] memory ) {
|
||||||
|
bytes32 k;
|
||||||
|
bytes32[2] memory ks;
|
||||||
|
bytes memory signMaterial = new bytes(64);
|
||||||
|
|
||||||
|
k = toReference(_declarator, _subject);
|
||||||
|
for (uint256 i = 0; i < 32; i++) {
|
||||||
|
signMaterial[i] = k[i];
|
||||||
|
}
|
||||||
|
for (uint256 i = 0; i < 32; i++) {
|
||||||
|
signMaterial[i+32] = _proof[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
ks[0] = k;
|
||||||
|
ks[1] = sha256(signMaterial);
|
||||||
|
|
||||||
|
return ks;
|
||||||
|
}
|
||||||
|
|
||||||
// Implements Declarator
|
// Implements Declarator
|
||||||
function declaratorCount(address _subject) public view returns ( uint256 ) {
|
function declaratorCount(address _subject) public view returns ( uint256 ) {
|
||||||
return declarator[_subject].length;
|
return declarator[_subject].length;
|
||||||
@ -48,20 +68,23 @@ contract AddressDeclarator {
|
|||||||
|
|
||||||
// Implements Declarator
|
// Implements Declarator
|
||||||
function addDeclaration(address _subject, bytes32 _proof) public returns ( bool ) {
|
function addDeclaration(address _subject, bytes32 _proof) public returns ( bool ) {
|
||||||
bytes32 k;
|
bytes32[2] memory ks;
|
||||||
bytes32[] memory declarationContents;
|
bytes32[] memory declarationContents;
|
||||||
uint256 idx;
|
uint256 idx;
|
||||||
k = toReference(msg.sender, _subject);
|
ks = toReference(tx.origin, _subject, _proof);
|
||||||
idx = declarationContentIndex[k];
|
idx = declarationContentIndex[ks[0]];
|
||||||
if (idx == 0) { // This also works for the constructor :)
|
if (idx == 0) { // This also works for the constructor :)
|
||||||
declarator[_subject].push(msg.sender);
|
declarator[_subject].push(tx.origin);
|
||||||
contents.push(declarationContents); //= contents[idx],
|
contents.push(declarationContents);
|
||||||
declarationIndex[msg.sender].push(_subject);
|
declarationIndex[tx.origin].push(_subject);
|
||||||
}
|
}
|
||||||
|
|
||||||
idx = contents.length-1;
|
idx = contents.length-1;
|
||||||
declarationContentIndex[k] = idx;
|
declarationContentIndex[ks[0]] = idx;
|
||||||
contents[idx].push(_proof);
|
contents[idx].push(_proof);
|
||||||
|
|
||||||
|
declarationExistIndex[ks[1]] = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,6 +97,15 @@ contract AddressDeclarator {
|
|||||||
return contents[idx];
|
return contents[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implements Declarator
|
||||||
|
function haveDeclaration(address _declarator, address _subject, bytes32 _proof) public view returns (bool) {
|
||||||
|
bytes32[2] memory ks;
|
||||||
|
|
||||||
|
ks = toReference(_declarator, _subject, _proof);
|
||||||
|
|
||||||
|
return declarationExistIndex[ks[1]];
|
||||||
|
}
|
||||||
|
|
||||||
// Implements Declarator
|
// Implements Declarator
|
||||||
function declarationCount(address _declarator) public view returns ( uint256 ) {
|
function declarationCount(address _declarator) public view returns ( uint256 ) {
|
||||||
return declarationIndex[_declarator].length;
|
return declarationIndex[_declarator].length;
|
||||||
@ -92,5 +124,6 @@ contract AddressDeclarator {
|
|||||||
if (_sum == 0x01ffc9a7) { // EIP165
|
if (_sum == 0x01ffc9a7) { // EIP165
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,30 @@
|
|||||||
SOLC = /usr/bin/solc
|
SOLC = /usr/bin/solc
|
||||||
|
|
||||||
all:
|
all: address_declarator token_index accounts_index
|
||||||
|
|
||||||
|
address_declarator:
|
||||||
$(SOLC) AddressDeclarator.sol --abi --evm-version byzantium | awk 'NR>3' > AddressDeclarator.json
|
$(SOLC) AddressDeclarator.sol --abi --evm-version byzantium | awk 'NR>3' > AddressDeclarator.json
|
||||||
$(SOLC) AddressDeclarator.sol --bin --evm-version byzantium | awk 'NR>3' > AddressDeclarator.bin
|
$(SOLC) AddressDeclarator.sol --bin --evm-version byzantium | awk 'NR>3' > AddressDeclarator.bin
|
||||||
truncate -s -1 AddressDeclarator.bin
|
truncate -s -1 AddressDeclarator.bin
|
||||||
|
|
||||||
|
token_index:
|
||||||
$(SOLC) TokenUniqueSymbolIndex.sol --abi --evm-version byzantium | awk 'NR>3' > TokenUniqueSymbolIndex.json
|
$(SOLC) TokenUniqueSymbolIndex.sol --abi --evm-version byzantium | awk 'NR>3' > TokenUniqueSymbolIndex.json
|
||||||
$(SOLC) TokenUniqueSymbolIndex.sol --bin --evm-version byzantium | awk 'NR>3' > TokenUniqueSymbolIndex.bin
|
$(SOLC) TokenUniqueSymbolIndex.sol --bin --evm-version byzantium | awk 'NR>3' > TokenUniqueSymbolIndex.bin
|
||||||
truncate -s -1 TokenUniqueSymbolIndex.bin
|
truncate -s -1 TokenUniqueSymbolIndex.bin
|
||||||
|
|
||||||
test: all
|
|
||||||
|
accounts_index:
|
||||||
|
$(SOLC) AccountsIndexAddressDeclarator.sol --abi --evm-version byzantium | awk 'NR>3' > AccountsIndexAddressDeclarator.json
|
||||||
|
$(SOLC) AccountsIndexAddressDeclarator.sol --bin --evm-version byzantium | awk 'NR>3' > AccountsIndexAddressDeclarator.bin
|
||||||
|
truncate -s -1 AccountsIndexAddressDeclarator.bin
|
||||||
|
|
||||||
|
#test: all
|
||||||
#python test.py
|
#python test.py
|
||||||
python test_tokenindex.py
|
#python test_tokenindex.py
|
||||||
|
|
||||||
install: all
|
install: all
|
||||||
cp -v AddressDeclarator.{json,bin} ../python/eth_address_declarator/data/
|
cp -v AddressDeclarator.{json,bin} ../python/eth_address_declarator/data/
|
||||||
cp -v TokenUniqueSymbolIndex.{json,bin} ../python/eth_token_index/data/
|
cp -v TokenUniqueSymbolIndex.{json,bin} ../python/eth_token_index/data/
|
||||||
|
cp -v AccountsIndexAddressDeclarator.{json,bin} ../python/eth_address_declarator/data/
|
||||||
|
|
||||||
.PHONY: test install
|
.PHONY: test install
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user