Correct interface in solidity contract

This commit is contained in:
nolash 2021-11-14 05:23:44 +01:00
parent 7d27faa960
commit 8c1339aac5
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
7 changed files with 19 additions and 30 deletions

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
[{"inputs":[{"internalType":"bytes32[]","name":"_identifiers","type":"bytes32[]"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"bytes32","name":"_identifier","type":"bytes32"}],"name":"addressOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_identifier","type":"bytes32"}],"name":"chainOf","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_chain","type":"bytes32"}],"name":"configSumOf","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"identifiers","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_identifier","type":"bytes32"},{"internalType":"address","name":"_address","type":"address"},{"internalType":"bytes32","name":"_chainDescriptor","type":"bytes32"},{"internalType":"bytes32","name":"_chainConfig","type":"bytes32"}],"name":"set","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","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":"bytes32[]","name":"_identifiers","type":"bytes32[]"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"bytes32","name":"_identifier","type":"bytes32"}],"name":"addressOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_identifier","type":"bytes32"},{"internalType":"bytes32","name":"_reference","type":"bytes32"}],"name":"bind","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"identifiers","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_identifier","type":"bytes32"},{"internalType":"address","name":"_address","type":"address"}],"name":"set","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","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"}]

View File

@ -93,22 +93,14 @@ class ContractRegistry(Registry):
raise NotImplementedError() raise NotImplementedError()
def set(self, contract_address, sender_address, identifier_string, address, chain_spec, chain_config_hash): def set(self, contract_address, sender_address, identifier_string, address):
enc = ABIContractEncoder() enc = ABIContractEncoder()
enc.method('set') enc.method('set')
enc.typ(ABIContractType.BYTES32) enc.typ(ABIContractType.BYTES32)
enc.typ(ABIContractType.ADDRESS) enc.typ(ABIContractType.ADDRESS)
enc.typ(ABIContractType.BYTES32)
enc.typ(ABIContractType.BYTES32)
identifier = to_identifier(identifier_string) identifier = to_identifier(identifier_string)
enc.bytes32(identifier) enc.bytes32(identifier)
enc.address(address) enc.address(address)
chain_str = str(chain_spec)
h = hashlib.new('sha256')
h.update(chain_str.encode('utf-8'))
chain_description_hash_bytes = h.digest()
enc.bytes32(chain_description_hash_bytes.hex())
enc.bytes32(chain_config_hash)
data = enc.encode() data = enc.encode()
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)

View File

@ -76,7 +76,7 @@ def main():
raise ValueError('chain config hash must be 32 bytes') raise ValueError('chain config hash must be 32 bytes')
chain_config_hash = add_0x(chain_config_hash) chain_config_hash = add_0x(chain_config_hash)
(tx_hash_hex, o) = c.set(registry_address, signer_address, config.get('_IDENTIFIER'), subject_address, chain_spec, chain_config_hash) (tx_hash_hex, o) = c.set(registry_address, signer_address, config.get('_IDENTIFIER'), subject_address)
if config.get('_RPC_SEND'): if config.get('_RPC_SEND'):
conn.do(o) conn.do(o)

View File

@ -1,2 +1,2 @@
confini>=0.3.6rc3,<0.5.0 confini~=0.5.2
chainlib-eth>=0.0.9a3,<=0.1.0 chainlib-eth~=0.0.12

View File

@ -1,6 +1,6 @@
[metadata] [metadata]
name = eth-contract-registry name = eth-contract-registry
version = 0.6.3a3 version = 0.7.1a2
description = Ethereum Smart Contract key-value registry description = Ethereum Smart Contract key-value registry
author = Louis Holbrook author = Louis Holbrook
author_email = dev@holbrook.no author_email = dev@holbrook.no

View File

@ -12,8 +12,7 @@ contract CICRegistry {
bytes32[] public identifiers; bytes32[] public identifiers;
mapping (bytes32 => address) entries; // contractidentifier -> address mapping (bytes32 => address) entries; // contractidentifier -> address
mapping (bytes32 => bytes32) chainIdentifiers; // contractidentifier -> chainidentifier mapping (bytes32 => bytes32[]) entryBindings; // contractidentifier -> chainidentifier
mapping (bytes32 => bytes32) chainConfigs; // chainidentifier -> chainconfig
constructor(bytes32[] memory _identifiers) public { constructor(bytes32[] memory _identifiers) public {
owner = msg.sender; owner = msg.sender;
@ -22,9 +21,11 @@ contract CICRegistry {
} }
} }
function set(bytes32 _identifier, address _address, bytes32 _chainDescriptor, bytes32 _chainConfig) public returns (bool) { function set(bytes32 _identifier, address _address) public returns (bool) {
require(msg.sender == owner); require(msg.sender == owner);
require(entries[_identifier] == address(0)); require(entries[_identifier] == address(0));
require(_address != address(0));
bool found = false; bool found = false;
for (uint i = 0; i < identifiers.length; i++) { for (uint i = 0; i < identifiers.length; i++) {
if (identifiers[i] == _identifier) { if (identifiers[i] == _identifier) {
@ -34,11 +35,16 @@ contract CICRegistry {
require(found); require(found);
entries[_identifier] = _address; entries[_identifier] = _address;
chainIdentifiers[_identifier] = _chainDescriptor;
chainConfigs[_chainDescriptor] = _chainConfig;
return true; return true;
} }
function bind(bytes32 _identifier, bytes32 _reference) public returns (bool) {
require(msg.sender == owner);
require(entries[_identifier] != address(0));
entryBindings[_identifier].push(_reference);
}
// Implements EIP 173 // Implements EIP 173
function transferOwnership(address _newOwner) public returns (bool) { function transferOwnership(address _newOwner) public returns (bool) {
require(msg.sender == owner); require(msg.sender == owner);
@ -51,17 +57,8 @@ contract CICRegistry {
return entries[_identifier]; return entries[_identifier];
} }
function chainOf(bytes32 _identifier) public view returns (bytes32) {
return chainIdentifiers[_identifier];
}
function configSumOf(bytes32 _chain) public view returns (bytes32) {
return chainConfigs[_chain];
}
// Implements EIP 165
function supportsInterface(bytes4 _sum) public pure returns (bool) { function supportsInterface(bytes4 _sum) public pure returns (bool) {
if (_sum == 0xbb34534c) { // Registry if (_sum == 0x633ee8e7) { // Registry
return true; return true;
} }
if (_sum == 0x01ffc9a7) { // EIP165 if (_sum == 0x01ffc9a7) { // EIP165