Compare commits

..

No commits in common. "master" and "v0.6.2" have entirely different histories.

16 changed files with 62 additions and 336 deletions

View File

@ -1,11 +1,3 @@
- 0.7.2
* Set bytes32(0) as topic for topic-less declaration
- 0.7.1
* Add topic option to declarations
- 0.7.0
* Change license
- 0.6.3
* Add contract metadata
- 0.6.2 - 0.6.2
* Remove haveDeclaration solidity method * Remove haveDeclaration solidity method
- 0.6.1 - 0.6.1

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
[{"inputs":[{"internalType":"bytes32","name":"_initial","type":"bytes32"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_declarator","type":"address"},{"indexed":true,"internalType":"address","name":"_subject","type":"address"},{"indexed":true,"internalType":"bytes32","name":"_topic","type":"bytes32"},{"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"},{"internalType":"bytes32","name":"_topic","type":"bytes32"}],"name":"addDeclaration","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"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":"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":"address","name":"_subject","type":"address"},{"internalType":"bytes32","name":"_topic","type":"bytes32"}],"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":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"}]

View File

@ -1 +0,0 @@
{"compiler":{"version":"0.8.18+commit.87f61d96"},"language":"Solidity","output":{"abi":[{"inputs":[{"internalType":"bytes32","name":"_initial","type":"bytes32"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_declarator","type":"address"},{"indexed":true,"internalType":"address","name":"_subject","type":"address"},{"indexed":true,"internalType":"bytes32","name":"_topic","type":"bytes32"},{"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"},{"internalType":"bytes32","name":"_topic","type":"bytes32"}],"name":"addDeclaration","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"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":"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":"address","name":"_subject","type":"address"},{"internalType":"bytes32","name":"_topic","type":"bytes32"}],"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"}],"devdoc":{"kind":"dev","methods":{},"version":1},"userdoc":{"kind":"user","methods":{},"version":1}},"settings":{"compilationTarget":{"AddressDeclarator.sol":"AddressDeclarator"},"evmVersion":"byzantium","libraries":{},"metadata":{"bytecodeHash":"ipfs"},"optimizer":{"enabled":false,"runs":200},"remappings":[]},"sources":{"AddressDeclarator.sol":{"keccak256":"0x44cf5a059a1525a4015b98dfad9ff85c7736a7c3dbd950fc06cf9f833cf46385","license":"AGPL-3.0-or-later","urls":["bzz-raw://0cfcaf0cb346885ba4bac8c9b2bd4bbdacc9d55ce263d04150ab4c1293747b15","dweb:/ipfs/QmTs821JYsbvnF3qDcyzSSaFpNXLBqcGuoRdZa6kLtAXWa"]}},"version":1}

View File

@ -69,10 +69,11 @@ class AddressDeclarator(Declarator):
return 2000000 return 2000000
def constructor(self, sender_address, description): def constructor(self, sender_address, initial_description):
code = AddressDeclarator.bytecode() code = AddressDeclarator.bytecode()
enc = ABIContractEncoder() enc = ABIContractEncoder()
enc.bytes32(description) initial_description_hex = add_0x(initial_description)
enc.bytes32(initial_description_hex)
code += enc.get() code += enc.get()
tx = self.template(sender_address, None, use_nonce=True) tx = self.template(sender_address, None, use_nonce=True)
tx = self.set_code(tx, code) tx = self.set_code(tx, code)

View File

@ -27,17 +27,13 @@ logg = logging.getLogger(__name__)
class Declarator(TxFactory): class Declarator(TxFactory):
def add_declaration(self, contract_address, sender_address, subject_address, proof, topic=None, tx_format=TxFormat.JSONRPC): def add_declaration(self, contract_address, sender_address, subject_address, proof, tx_format=TxFormat.JSONRPC):
enc = ABIContractEncoder() enc = ABIContractEncoder()
enc.method('addDeclaration') enc.method('addDeclaration')
enc.typ(ABIContractType.ADDRESS) enc.typ(ABIContractType.ADDRESS)
enc.typ(ABIContractType.BYTES32) enc.typ(ABIContractType.BYTES32)
if topic != None:
enc.typ(ABIContractType.BYTES32)
enc.address(subject_address) enc.address(subject_address)
enc.bytes32(proof) enc.bytes32(proof)
if topic != None:
enc.bytes32(topic)
data = enc.get() data = enc.get()
tx = self.template(sender_address, contract_address, use_nonce=True) tx = self.template(sender_address, contract_address, use_nonce=True)
tx = self.set_code(tx, data) tx = self.set_code(tx, data)
@ -63,7 +59,7 @@ class Declarator(TxFactory):
return o return o
def declaration(self, contract_address, declarator_address, subject_address, topic=None, sender_address=ZERO_ADDRESS, id_generator=None, height=BlockSpec.LATEST): def declaration(self, contract_address, declarator_address, subject_address, sender_address=ZERO_ADDRESS, id_generator=None, height=BlockSpec.LATEST):
j = JSONRPCRequest(id_generator) j = JSONRPCRequest(id_generator)
o = j.template() o = j.template()
o['method'] = 'eth_call' o['method'] = 'eth_call'
@ -71,12 +67,8 @@ class Declarator(TxFactory):
enc.method('declaration') enc.method('declaration')
enc.typ(ABIContractType.ADDRESS) enc.typ(ABIContractType.ADDRESS)
enc.typ(ABIContractType.ADDRESS) enc.typ(ABIContractType.ADDRESS)
if topic != None:
enc.typ(ABIContractType.BYTES32)
enc.address(declarator_address) enc.address(declarator_address)
enc.address(subject_address) enc.address(subject_address)
if topic != None:
enc.bytes32(topic)
data = add_0x(enc.get()) data = add_0x(enc.get())
tx = self.template(sender_address, contract_address) tx = self.template(sender_address, contract_address)
tx = self.set_code(tx, data) tx = self.set_code(tx, data)

View File

@ -12,7 +12,6 @@ from giftable_erc20_token import GiftableToken
# local imports # local imports
from eth_address_declarator.declarator import AddressDeclarator from eth_address_declarator.declarator import AddressDeclarator
#from eth_address_declarator.kv import AddressDeclaratorKV
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger() logg = logging.getLogger()
@ -33,7 +32,7 @@ class TestAddressDeclaratorBase(EthTesterCase):
self.assertEqual(r['status'], 1) self.assertEqual(r['status'], 1)
self.address = r['contract_address'] self.address = r['contract_address']
logg.debug('address declarator published with address {}'.format(self.address)) logg.debug('address declarator deployed with address {}'.format(self.address))
c = GiftableToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) c = GiftableToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
(tx_hash_hex, o) = c.constructor(self.accounts[0], 'FooToken', 'FOO', 6) (tx_hash_hex, o) = c.constructor(self.accounts[0], 'FooToken', 'FOO', 6)
@ -44,4 +43,4 @@ class TestAddressDeclaratorBase(EthTesterCase):
self.assertEqual(r['status'], 1) self.assertEqual(r['status'], 1)
self.foo_token_address = r['contract_address'] self.foo_token_address = r['contract_address']
logg.debug('foo token published with address {}'.format(self.foo_token_address)) logg.debug('foo token deployed with address {}'.format(self.foo_token_address))

View File

@ -1,29 +1,28 @@
[metadata] [metadata]
name = eth-address-index name = eth-address-index
version = 0.7.2 version = 0.6.2
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
url = https://holbrook.no/src/eth-address-index/log.html url = https://gitlab.com/cicnet/eth-address-index
keywords = keywords =
ethereum ethereum
classifiers = classifiers =
Programming Language :: Python :: 3 Programming Language :: Python :: 3
Operating System :: OS Independent Operating System :: OS Independent
Development Status :: 4 - Beta Development Status :: 3 - Alpha
Environment :: Console Environment :: No Input/Output (Daemon)
Intended Audience :: Developers Intended Audience :: Developers
License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+) License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
Topic :: Internet Topic :: Internet
Topic :: Software Development :: Libraries
#Topic :: Blockchain :: EVM #Topic :: Blockchain :: EVM
license = AGPLv3+ license = GPL3
licence_files = licence_files =
LICENSE LICENSE
[options] [options]
include_package_data = True include_package_data = True
python_requires = >= 3.7 python_requires = >= 3.6
packages = packages =
eth_address_declarator eth_address_declarator
eth_address_declarator.runnable eth_address_declarator.runnable

View File

@ -51,6 +51,7 @@ class TestAddressDeclarator(TestAddressDeclaratorBase):
def test_basic(self): def test_basic(self):
d = add_0x(os.urandom(32).hex()) d = add_0x(os.urandom(32).hex())
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc) nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)

View File

@ -1,266 +0,0 @@
# standard imports
import os
import unittest
import json
import logging
import hashlib
# external imports
from chainlib.eth.unittest.ethtester import EthTesterCase
from chainlib.eth.contract import (
ABIContractEncoder,
ABIContractType,
)
from chainlib.eth.nonce import RPCNonceOracle
from chainlib.eth.tx import receipt
from giftable_erc20_token import GiftableToken
from hexathon import (
add_0x,
strip_0x,
)
# local imports
from eth_address_declarator.declarator import AddressDeclarator
from eth_address_declarator import Declarator
from eth_address_declarator.unittest import TestAddressDeclaratorBase
logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger()
testdir = os.path.dirname(__file__)
description = '0x{:<064s}'.format(b'foo'.hex())
class TestAddressDeclarator(TestAddressDeclaratorBase):
def setUp(self):
super(TestAddressDeclarator, self).setUp()
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
#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], 'BarToken', 'BAR', 6)
self.rpc.do(o)
o = receipt(tx_hash_hex)
r = self.rpc.do(o)
self.assertEqual(r['status'], 1)
self.bar_token_address = r['contract_address']
def test_basic(self):
k = add_0x(os.urandom(32).hex())
v = add_0x(os.urandom(32).hex())
nonce_oracle = RPCNonceOracle(self.accounts[0], 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[0], self.foo_token_address, v, topic=k)
self.rpc.do(o)
o = receipt(tx_hash_hex)
r = self.rpc.do(o)
self.assertEqual(r['status'], 1)
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, v, topic=k)
self.rpc.do(o)
o = receipt(tx_hash_hex)
r = self.rpc.do(o)
self.assertEqual(r['status'], 1)
nonce_oracle = RPCNonceOracle(self.accounts[0], 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[0], self.bar_token_address, v, topic=k)
self.rpc.do(o)
o = c.declarator_count(self.address, self.foo_token_address, sender_address=self.accounts[0])
r = self.rpc.do(o)
self.assertEqual(c.parse_declarator_count(r), 2)
o = c.declarator_count(self.address, self.bar_token_address, sender_address=self.accounts[0])
r = self.rpc.do(o)
self.assertEqual(c.parse_declarator_count(r), 1)
def test_get_single_declaration(self):
k = add_0x(os.urandom(32).hex())
v = 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, v, topic=k)
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, topic=k, sender_address=self.accounts[0])
r = self.rpc.do(o)
self.assertEqual(strip_0x(r)[128:], strip_0x(v))
def test_kv_declarations(self):
k = add_0x(os.urandom(32).hex())
v = add_0x(os.urandom(32).hex())
w = add_0x(os.urandom(32).hex())
k_two = add_0x(os.urandom(32).hex())
v_two = 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, v, topic=k)
self.rpc.do(o)
o = receipt(tx_hash_hex)
r = self.rpc.do(o)
self.assertEqual(r['status'], 1)
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, w, topic=k)
self.rpc.do(o)
o = receipt(tx_hash_hex)
r = self.rpc.do(o)
self.assertEqual(r['status'], 1)
(tx_hash_hex, o) = c.add_declaration(self.address, self.accounts[1], self.foo_token_address, v_two, topic=k_two)
self.rpc.do(o)
o = receipt(tx_hash_hex)
r = self.rpc.do(o)
self.assertEqual(r['status'], 1)
# nonce_oracle = RPCNonceOracle(self.accounts[2], 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[2], self.foo_token_address, k, v)
# self.rpc.do(o)
#
# c = Declarator(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
# (tx_hash_hex, o) = c.add_declaration(self.address, self.accounts[2], self.bar_token_address, k, v)
# self.rpc.do(o)
o = c.declaration(self.address, self.accounts[1], self.foo_token_address, topic=k, sender_address=self.accounts[0])
r = self.rpc.do(o)
self.assertEqual(strip_0x(r)[128:], strip_0x(v) + strip_0x(w))
o = c.declaration(self.address, self.accounts[1], self.foo_token_address, topic=k_two, sender_address=self.accounts[0])
r = self.rpc.do(o)
self.assertEqual(strip_0x(r)[128:], strip_0x(v_two))
def test_declarator_to_subject(self):
k = add_0x(os.urandom(32).hex())
v = 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, v, topic=k)
self.rpc.do(o)
nonce_oracle = RPCNonceOracle(self.accounts[2], 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[2], self.foo_token_address, v, topic=k)
self.rpc.do(o)
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.bar_token_address, v, topic=k)
self.rpc.do(o)
o = c.declaration_address_at(self.address, self.accounts[1], 0, sender_address=self.accounts[0])
r = self.rpc.do(o)
self.assertEqual(c.parse_declaration_address_at(r), strip_0x(self.foo_token_address))
o = c.declaration_address_at(self.address, self.accounts[2], 0, sender_address=self.accounts[0])
r = self.rpc.do(o)
self.assertEqual(c.parse_declaration_address_at(r), strip_0x(self.foo_token_address))
o = c.declaration_address_at(self.address, self.accounts[1], 1, sender_address=self.accounts[0])
r = self.rpc.do(o)
self.assertEqual(c.parse_declaration_address_at(r), strip_0x(self.bar_token_address))
def test_subject_to_declarator(self):
k = add_0x(os.urandom(32).hex())
v = 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, v, topic=k)
self.rpc.do(o)
nonce_oracle = RPCNonceOracle(self.accounts[2], 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[2], self.foo_token_address, v, topic=k)
self.rpc.do(o)
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.bar_token_address, v, topic=k)
self.rpc.do(o)
o = c.declarator_address_at(self.address, self.foo_token_address, 0, sender_address=self.accounts[0])
r = self.rpc.do(o)
self.assertEqual(c.parse_declaration_address_at(r), strip_0x(self.accounts[1]))
o = c.declarator_address_at(self.address, self.foo_token_address, 1, sender_address=self.accounts[0])
r = self.rpc.do(o)
self.assertEqual(c.parse_declaration_address_at(r), strip_0x(self.accounts[2]))
def test_three_first(self):
k = add_0x(os.urandom(32).hex())
v = []
for i in range(3):
v.append(add_0x(os.urandom(32).hex()))
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
c = Declarator(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
for proof in v:
(tx_hash_hex, o) = c.add_declaration(self.address, self.accounts[0], self.foo_token_address, proof, topic=k)
self.rpc.do(o)
o = c.declarator_count(self.address, self.foo_token_address, sender_address=self.accounts[0])
r = self.rpc.do(o)
self.assertEqual(c.parse_declarator_count(r), 1)
o = c.declaration(self.address, self.accounts[0], self.foo_token_address, topic=k, sender_address=self.accounts[0])
r = self.rpc.do(o)
proofs = c.parse_declaration(r)
self.assertEqual(len(proofs), 3)
for i in range(3):
self.assertEqual(proofs[i], strip_0x(v[i]))
def test_three_first_different(self):
k = add_0x(os.urandom(32).hex())
v = []
a = []
for i in range(3):
v.append(add_0x(os.urandom(32).hex()))
a.append(add_0x(os.urandom(20).hex()))
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
c = Declarator(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
for i in range(3):
(tx_hash_hex, o) = c.add_declaration(self.address, self.accounts[0], a[i], v[i], topic=k)
self.rpc.do(o)
for i in range(3):
o = c.declarator_count(self.address, a[i], sender_address=self.accounts[0])
r = self.rpc.do(o)
self.assertEqual(c.parse_declarator_count(r), 1)
o = c.declaration(self.address, self.accounts[0], a[i], topic=k, sender_address=self.accounts[0])
r = self.rpc.do(o)
proofs = c.parse_declaration(r)
self.assertEqual(len(proofs), 1)
self.assertEqual(proofs[0], strip_0x(v[i]))
if __name__ == '__main__':
unittest.main()

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
[{"inputs":[{"internalType":"bytes32","name":"_initial","type":"bytes32"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_declarator","type":"address"},{"indexed":true,"internalType":"address","name":"_subject","type":"address"},{"indexed":true,"internalType":"bytes32","name":"_topic","type":"bytes32"},{"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"},{"internalType":"bytes32","name":"_topic","type":"bytes32"}],"name":"addDeclaration","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"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":"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":"address","name":"_subject","type":"address"},{"internalType":"bytes32","name":"_topic","type":"bytes32"}],"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":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"}]

View File

@ -1,6 +1,6 @@
pragma solidity >=0.8.0; pragma solidity >0.6.11;
// SPDX-License-Identifier: AGPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
contract AddressDeclarator { contract AddressDeclarator {
@ -8,17 +8,20 @@ contract AddressDeclarator {
mapping( bytes32 => uint256 ) declarationContentIndex; // the _latest_ content pointer for the declarator to subject mapping 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;
bytes32[][] public contents;
bytes32[][] contents; event DeclarationAdded(address _declarator, address _subject, bytes32 _proof);
// Implements Declarator constructor(bytes32 _initialDescription) {
event DeclarationAdded(address indexed _declarator, address indexed _subject, bytes32 indexed _topic, bytes32 _proof); bytes32[] memory foundation;
contents.push(foundation);
contents[contents.length-1].push(blockhash(block.number));
addDeclaration(msg.sender, _initialDescription);
constructor(bytes32 _initial) {
addDeclaration(address(this), _initial);
} }
// Create a digest reference for a declarator and subject pair
function toReference(address _declarator, address _subject) private pure returns ( bytes32 ) { function toReference(address _declarator, address _subject) private pure returns ( bytes32 ) {
bytes32 k; bytes32 k;
bytes memory addrMaterial = new bytes(40); bytes memory addrMaterial = new bytes(40);
@ -34,8 +37,7 @@ contract AddressDeclarator {
return k; return k;
} }
// Create a digest reference for a declarator and subject pair on top of the given digest function toReference(address _declarator, address _subject, bytes32 _proof) private pure returns ( bytes32[2] memory ) {
function toReference(address _declarator, address _subject, bytes32 _digest) private pure returns ( bytes32[2] memory ) {
bytes32 k; bytes32 k;
bytes32[2] memory ks; bytes32[2] memory ks;
bytes memory signMaterial = new bytes(64); bytes memory signMaterial = new bytes(64);
@ -45,7 +47,7 @@ contract AddressDeclarator {
signMaterial[i] = k[i]; signMaterial[i] = k[i];
} }
for (uint256 i = 0; i < 32; i++) { for (uint256 i = 0; i < 32; i++) {
signMaterial[i+32] = _digest[i]; signMaterial[i+32] = _proof[i];
} }
ks[0] = k; ks[0] = k;
@ -65,12 +67,12 @@ contract AddressDeclarator {
} }
// Implements Declarator // Implements Declarator
function addDeclaration(address _subject, bytes32 _proof, bytes32 _topic) public returns ( bool ) { function addDeclaration(address _subject, bytes32 _proof) public returns ( bool ) {
bytes32[2] memory ks; bytes32[2] memory ks;
bytes32[] memory declarationContents; bytes32[] memory declarationContents;
uint256 idx; uint256 idx;
ks = toReference(tx.origin, _subject, _topic); ks = toReference(tx.origin, _subject, _proof);
idx = declarationContentIndex[ks[1]]; 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(tx.origin); declarator[_subject].push(tx.origin);
contents.push(declarationContents); contents.push(declarationContents);
@ -78,28 +80,18 @@ contract AddressDeclarator {
idx = contents.length-1; idx = contents.length-1;
} }
declarationContentIndex[ks[1]] = idx; declarationContentIndex[ks[0]] = idx;
contents[idx].push(_proof); contents[idx].push(_proof);
return true; return true;
} }
// Implements Declarator
function addDeclaration(address _subject, bytes32 _proof) public returns ( bool ) {
return addDeclaration(_subject, _proof, bytes32(0));
}
// Implements Declarator // Implements Declarator
function declaration(address _declarator, address _subject) public view returns ( bytes32[] memory ) { function declaration(address _declarator, address _subject) public view returns ( bytes32[] memory ) {
return declaration(_declarator, _subject, bytes32(0)); bytes32 k;
}
// Implements Declarator
function declaration(address _declarator, address _subject, bytes32 _topic) public view returns ( bytes32[] memory ) {
bytes32[2] memory k;
uint256 idx; uint256 idx;
k = toReference(_declarator, _subject, _topic); k = toReference(_declarator, _subject);
idx = declarationContentIndex[k[1]]; idx = declarationContentIndex[k];
return contents[idx]; return contents[idx];
} }
@ -115,7 +107,7 @@ contract AddressDeclarator {
// Implements EIP165 // Implements EIP165
function supportsInterface(bytes4 _sum) public pure returns (bool) { function supportsInterface(bytes4 _sum) public pure returns (bool) {
if (_sum == 0x21b7493b) { // Implements Declarator if (_sum == 0x27beb910) { // Implements Declarator
return true; return true;
} }
if (_sum == 0x01ffc9a7) { // EIP165 if (_sum == 0x01ffc9a7) { // EIP165

View File

@ -1,15 +1,30 @@
SOLC = /usr/bin/solc SOLC = /usr/bin/solc
all: address_declarator all: address_declarator token_index accounts_index
address_declarator: 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
$(SOLC) AddressDeclarator.sol --metadata --evm-version byzantium | awk 'NR>3' > AddressDeclarator.metadata.json
truncate -s -1 AddressDeclarator.bin truncate -s -1 AddressDeclarator.bin
token_index:
$(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:
$(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_tokenindex.py
install: all install: all
cp -v *.json ../python/eth_address_declarator/data/ cp -v AddressDeclarator.{json,bin} ../python/eth_address_declarator/data/
cp -v *.bin ../python/eth_address_declarator/data/ cp -v TokenUniqueSymbolIndexAddressDeclarator.{json,bin} ../python/eth_address_declarator/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

View File

@ -0,0 +1 @@
[{"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"}]