Compare commits
10 Commits
732466de27
...
master
Author | SHA1 | Date | |
---|---|---|---|
9bad5b5ccf | |||
|
179a6d4e03 | ||
|
f3f69c937f | ||
|
5413295dc7 | ||
|
f299d9921a | ||
|
1961da25ab | ||
|
24e697ad37 | ||
|
397c1310f7 | ||
|
8d67bcdfd2 | ||
|
be175dc8d3 |
5
python/CHANGELOG
Normal file
5
python/CHANGELOG
Normal file
@ -0,0 +1,5 @@
|
||||
- 0.3.0
|
||||
* Upgrade eth-address-index aliasing -a for --declarator-address
|
||||
- 0.2.7
|
||||
* Replace --declarator-address with -a for view cli cmd
|
||||
* Update compiled bytecode for python package
|
31
python/README.md
Normal file
31
python/README.md
Normal file
@ -0,0 +1,31 @@
|
||||
# Okota
|
||||
|
||||
Okota implements smart contract registries for the CIC network with the [Address Declarator](https://gitlab.com/cicnet/eth-address-index) backend.
|
||||
|
||||
For every entry added to the registry, a declaration is added aswell.
|
||||
|
||||
In all the below:
|
||||
|
||||
* `contract_address` is the address of the deployed Address Declarator contract.
|
||||
* `subject_address` is the address a declaration is being made about.
|
||||
* `declarer` is the entity making a declaration about the `subject_address`.
|
||||
* `proof` a 256-bit proof
|
||||
|
||||
|
||||
## Contract declaration translations
|
||||
|
||||
| registry call | declarer | subject | proof |
|
||||
|---|---|---|---|
|
||||
| ContractRegistry.set(registry\_identifier, contract\_address) | sender | contract\_address | registry\_identifier |
|
||||
| AccountsIndex.register(wallet\_address) | sender | wallet\_address | token address of accounts index |
|
||||
| TokenRegistry.registry(token\_address) | sender | token\_address | sha256(token symbol) |
|
||||
|
||||
|
||||
## Query the declarator with CLI
|
||||
|
||||
`eth-accounts-index-view -e <contract_address> -a <declarer_address> <subject_address>`
|
||||
|
||||
|
||||
## Add arbitrary other proofs with CLI
|
||||
|
||||
`eth-accounts-index-add -e <contract_address> -y <declarer_keyfile> -a <subject_address> <proof>`
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -23,9 +23,8 @@ from chainlib.jsonrpc import JSONRPCRequest
|
||||
from chainlib.eth.constant import ZERO_ADDRESS
|
||||
from hexathon import (
|
||||
add_0x,
|
||||
strip_0x,
|
||||
)
|
||||
from cic_contracts.registry import to_identifier
|
||||
|
||||
# local imports
|
||||
from .interface import (
|
||||
#TokenUniqueSymbolIndex,
|
||||
@ -38,6 +37,13 @@ moddir = os.path.dirname(__file__)
|
||||
datadir = os.path.join(moddir, '..', 'data')
|
||||
|
||||
|
||||
def to_identifier(txt):
|
||||
identifier_bytes = txt.upper().encode('utf-8')
|
||||
h = hashlib.sha256()
|
||||
identifier_bytes = h.update(identifier_bytes)
|
||||
identifier = h.digest()
|
||||
return identifier.hex()
|
||||
|
||||
|
||||
#class TokenUniqueSymbolIndexAddressDeclarator(TokenUniqueSymbolIndex):
|
||||
class TokenUniqueSymbolIndexAddressDeclarator(CICTokenIndex):
|
||||
|
@ -1,9 +1,9 @@
|
||||
confini~=0.5.1
|
||||
funga-eth~=0.5.1
|
||||
chainlib-eth~=0.0.10
|
||||
eth_erc20~=0.1.2
|
||||
eth-address-index~=0.2.4
|
||||
eth-accounts-index~=0.1.2
|
||||
eth-token-index~=0.2.4
|
||||
eth-contract-registry~=0.6.3
|
||||
cic-contracts~=0.0.5
|
||||
confini~=0.6.0
|
||||
funga-eth~=0.6.0
|
||||
chainlib-eth>=0.1.0b1,<0.2.0
|
||||
eth_erc20~=0.3.0
|
||||
eth-address-index~=0.5.0
|
||||
eth-accounts-index~=0.2.0
|
||||
#eth-token-index~=0.3.0
|
||||
eth-contract-registry~=0.8.0
|
||||
cic-contracts~=0.1.0
|
||||
|
@ -1,6 +1,6 @@
|
||||
[metadata]
|
||||
name = okota
|
||||
version = 0.2.5a1
|
||||
version = 0.4.1
|
||||
description = Registries for CIC using the eth-address-index backend
|
||||
author = Louis Holbrook
|
||||
author_email = dev@holbrook.no
|
||||
|
@ -49,7 +49,7 @@ class TestContractRegistry(TestAddressDeclaratorBase):
|
||||
bogus_hash_two = bytearray(32)
|
||||
bogus_hash_two[0] = 0x01
|
||||
bogus_hash_two_hex = add_0x(bogus_hash_two.hex())
|
||||
(tx_hash_hex, o) = c.set(self.registry_address, self.accounts[0], 'FOO', self.registry_address, str(self.chain_spec), bogus_hash_two_hex)
|
||||
(tx_hash_hex, o) = c.set(self.registry_address, self.accounts[0], 'FOO', self.registry_address)
|
||||
r = self.rpc.do(o)
|
||||
o = receipt(r)
|
||||
rcpt = self.rpc.do(o)
|
||||
@ -75,18 +75,18 @@ class TestContractRegistry(TestAddressDeclaratorBase):
|
||||
h = hashlib.sha256()
|
||||
h.update(str(self.chain_spec).encode('utf-8'))
|
||||
chain_description_hash = h.digest()
|
||||
|
||||
h = hashlib.sha256()
|
||||
h.update(z)
|
||||
h.update(chain_description_hash)
|
||||
z = h.digest()
|
||||
self.assertEqual(z.hex(), proofs[1])
|
||||
|
||||
h = hashlib.sha256()
|
||||
h.update(z)
|
||||
h.update(bogus_hash_two)
|
||||
z = h.digest()
|
||||
self.assertEqual(z.hex(), proofs[2])
|
||||
#
|
||||
# h = hashlib.sha256()
|
||||
# h.update(z)
|
||||
# h.update(chain_description_hash)
|
||||
# z = h.digest()
|
||||
# self.assertEqual(z.hex(), proofs[1])
|
||||
#
|
||||
# h = hashlib.sha256()
|
||||
# h.update(z)
|
||||
# h.update(bogus_hash_two)
|
||||
# z = h.digest()
|
||||
# self.assertEqual(z.hex(), proofs[2])
|
||||
|
||||
|
||||
|
||||
|
@ -25,7 +25,7 @@ from okota.token_index.index import (
|
||||
# test imports
|
||||
from eth_address_declarator.unittest import TestAddressDeclaratorBase
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logg = logging.getLogger()
|
||||
|
||||
testdir = os.path.dirname(__file__)
|
||||
@ -54,12 +54,11 @@ class TestTokenIndex(TestAddressDeclaratorBase):
|
||||
r = self.rpc.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
|
||||
|
||||
|
||||
def test_register(self):
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
||||
c = CICTokenIndex(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
|
||||
logg.info('using token index {}'.format(self.token_index_address))
|
||||
(tx_hash_hex, o) = c.add(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)
|
||||
@ -87,13 +86,46 @@ class TestTokenIndex(TestAddressDeclaratorBase):
|
||||
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)
|
||||
|
||||
h = hashlib.sha256()
|
||||
h.update('FOO'.encode('utf-8'))
|
||||
z = h.digest()
|
||||
|
||||
identifier = to_identifier('FOO')
|
||||
#h = hashlib.sha256()
|
||||
#h.update('FOO'.encode('utf-8'))
|
||||
#z = h.digest()
|
||||
|
||||
self.assertEqual(proofs[0], z.hex())
|
||||
#self.assertEqual(proofs[0], z.hex())
|
||||
self.assertEqual(proofs[0], identifier)
|
||||
|
||||
identifier = to_identifier('foo')
|
||||
self.assertEqual(proofs[0], identifier)
|
||||
|
||||
def test_duplicate_entry(self):
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
||||
gft = GiftableToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
(tx_hash_hex, o) = gft.constructor(self.accounts[0], 'FooTokenRedeploy', '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_redeploy = r['contract_address']
|
||||
logg.info('second foo token deployed with address {}'.format(self.foo_token_address_redeploy))
|
||||
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
||||
c = CICTokenIndex(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
logg.info('using token index {}'.format(self.token_index_address))
|
||||
(tx_hash_hex, o) = c.add(self.token_index_address, self.accounts[0], self.foo_token_address_redeploy)
|
||||
self.rpc.do(o)
|
||||
e = unpack(bytes.fromhex(strip_0x(o['params'][0])), self.chain_spec)
|
||||
|
||||
o = receipt(tx_hash_hex)
|
||||
r = self.rpc.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
|
||||
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, strip_0x(self.foo_token_address_redeploy))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
@ -24,7 +24,7 @@ contract ContractRegistryAddressDeclarator {
|
||||
addressDeclarator = _addressDeclarator;
|
||||
}
|
||||
|
||||
function set(bytes32 _identifier, address _address, bytes32 _chainDescriptor, bytes32 _chainConfig) public returns (bool) {
|
||||
function set(bytes32 _identifier, address _address) public returns (bool) { //, bytes32 _chainDescriptor, bytes32 _chainConfig) public returns (bool) {
|
||||
require(msg.sender == owner);
|
||||
require(entries[_identifier] == address(0));
|
||||
|
||||
@ -51,38 +51,72 @@ contract ContractRegistryAddressDeclarator {
|
||||
require(ok);
|
||||
require(r[31] == 0x01);
|
||||
|
||||
buf = new bytes(64);
|
||||
for (i = 0; i < 32; i++) {
|
||||
buf[i] = identifierHash[i];
|
||||
}
|
||||
for (i = 0; i < 32; i++) {
|
||||
buf[i+32] = _chainDescriptor[i];
|
||||
}
|
||||
|
||||
identifierHash = sha256(buf);
|
||||
(ok, r) = addressDeclarator.call(abi.encodeWithSignature("addDeclaration(address,bytes32)", _address, identifierHash));
|
||||
require(ok);
|
||||
require(r[31] == 0x01);
|
||||
|
||||
|
||||
for (i = 0; i < 32; i++) {
|
||||
buf[i] = identifierHash[i];
|
||||
}
|
||||
for (i = 0; i < 32; i++) {
|
||||
buf[i+32] = _chainConfig[i];
|
||||
}
|
||||
identifierHash = sha256(buf);
|
||||
(ok, r) = addressDeclarator.call(abi.encodeWithSignature("addDeclaration(address,bytes32)", _address, identifierHash));
|
||||
require(ok);
|
||||
require(r[31] == 0x01);
|
||||
|
||||
entries[_identifier] = _address;
|
||||
chainIdentifiers[_identifier] = _chainDescriptor;
|
||||
chainConfigs[_chainDescriptor] = _chainConfig;
|
||||
///chainIdentifiers[_identifier] = _chainDescriptor;
|
||||
//chainConfigs[_chainDescriptor] = _chainConfig;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// function set(bytes32 _identifier, address _address, bytes32 _chainDescriptor, bytes32 _chainConfig) public returns (bool) {
|
||||
// require(msg.sender == owner);
|
||||
// require(entries[_identifier] == address(0));
|
||||
//
|
||||
// bool ok;
|
||||
// bytes memory r;
|
||||
// bool found = false;
|
||||
// bytes32 identifierHash;
|
||||
// bytes memory buf;
|
||||
// uint8 i;
|
||||
//
|
||||
// for (i = 0; i < identifiers.length; i++) {
|
||||
// if (identifiers[i] == _identifier) {
|
||||
// found = true;
|
||||
// }
|
||||
// }
|
||||
// require(found, 'ERR_IDENTIFIER');
|
||||
//
|
||||
// buf = new bytes(32);
|
||||
// for (i = 0; i < 32; i++) {
|
||||
// buf[i] = _identifier[i];
|
||||
// }
|
||||
// identifierHash = sha256(buf);
|
||||
// (ok, r) = addressDeclarator.call(abi.encodeWithSignature("addDeclaration(address,bytes32)", _address, identifierHash));
|
||||
// require(ok);
|
||||
// require(r[31] == 0x01);
|
||||
//
|
||||
// buf = new bytes(64);
|
||||
// for (i = 0; i < 32; i++) {
|
||||
// buf[i] = identifierHash[i];
|
||||
// }
|
||||
// for (i = 0; i < 32; i++) {
|
||||
// buf[i+32] = _chainDescriptor[i];
|
||||
// }
|
||||
//
|
||||
// identifierHash = sha256(buf);
|
||||
// (ok, r) = addressDeclarator.call(abi.encodeWithSignature("addDeclaration(address,bytes32)", _address, identifierHash));
|
||||
// require(ok);
|
||||
// require(r[31] == 0x01);
|
||||
//
|
||||
//
|
||||
// for (i = 0; i < 32; i++) {
|
||||
// buf[i] = identifierHash[i];
|
||||
// }
|
||||
// for (i = 0; i < 32; i++) {
|
||||
// buf[i+32] = _chainConfig[i];
|
||||
// }
|
||||
// identifierHash = sha256(buf);
|
||||
// (ok, r) = addressDeclarator.call(abi.encodeWithSignature("addDeclaration(address,bytes32)", _address, identifierHash));
|
||||
// require(ok);
|
||||
// require(r[31] == 0x01);
|
||||
//
|
||||
// entries[_identifier] = _address;
|
||||
// chainIdentifiers[_identifier] = _chainDescriptor;
|
||||
// chainConfigs[_chainDescriptor] = _chainConfig;
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// Implements EIP 173
|
||||
function transferOwnership(address _newOwner) public returns (bool) {
|
||||
require(msg.sender == owner);
|
||||
|
@ -55,9 +55,6 @@ contract TokenUniqueSymbolIndexAddressDeclarator {
|
||||
require(ok);
|
||||
require(r[31] == 0x01);
|
||||
|
||||
idx = registry[token_symbol_key];
|
||||
require(idx == 0);
|
||||
|
||||
registry[token_symbol_key] = tokens.length;
|
||||
tokens.push(_token);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user