mirror of
git://holbrook.no/eth-address-index
synced 2024-11-27 10:36:46 +01:00
Simplify new implementation
This commit is contained in:
parent
0b76e366b5
commit
4400240b3e
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
|||||||
[{"inputs":[{"internalType":"bytes32[]","name":"_descriptions","type":"bytes32[]"}],"stateMutability":"nonpayable","type":"constructor"},{"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":"_target","type":"address"}],"name":"declaration","outputs":[{"internalType":"bytes32[]","name":"","type":"bytes32[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_target","type":"address"},{"internalType":"uint256","name":"_idx","type":"uint256"}],"name":"declarator","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"declaratorCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]
|
[{"inputs":[{"internalType":"bytes32","name":"_initialDescription","type":"bytes32"}],"stateMutability":"nonpayable","type":"constructor"},{"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":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"declarator","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":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceID","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}]
|
||||||
|
@ -4,48 +4,74 @@ pragma solidity >=0.6.12;
|
|||||||
|
|
||||||
contract AddressDeclarator {
|
contract AddressDeclarator {
|
||||||
|
|
||||||
mapping( bytes32 => uint256[] )
|
// EIP 173
|
||||||
//mapping( address => uint256[] ) declaratorItemsIndex;
|
address public owner;
|
||||||
//mapping( address => uint256 ) public declaratorCount;
|
|
||||||
//mapping( address => mapping ( address => declaratorItem ) ) declarationByDeclaratorIndex;
|
|
||||||
bytes32[][] contents;
|
|
||||||
|
|
||||||
// constructor(bytes32[] memory _descriptions) {
|
mapping( bytes32 => uint256 ) declarations;
|
||||||
// for (uint i; i < _descriptions.length; i++) {
|
mapping( address => address[] ) public declarator;
|
||||||
// addDeclaration(msg.sender, _descriptions[i]);
|
bytes32[][] public contents;
|
||||||
// }
|
|
||||||
// }
|
constructor(bytes32 _initialDescription) {
|
||||||
//
|
bytes32[] memory foundation;
|
||||||
// function addDeclaration(address _subject, bytes32 _proof) public returns ( bool ) {
|
|
||||||
// declaratorItem storage item;
|
owner = msg.sender;
|
||||||
//
|
contents.push(foundation);
|
||||||
// item = declarationByDeclaratorIndex[msg.sender][_subject];
|
contents[contents.length-1].push(blockhash(block.number));
|
||||||
// if (item.signer == address(0)) {
|
|
||||||
// item.signer = msg.sender;
|
addDeclaration(msg.sender, _initialDescription);
|
||||||
// declaratorItemsIndex[_subject].push(declaratorItems.length);
|
}
|
||||||
// declaratorItems.push(item);
|
|
||||||
// declaratorCount[_subject]++;
|
// EIP 172
|
||||||
// }
|
function transferOwnership() public {
|
||||||
// item.content.push(_proof);
|
revert("owner cannot be changed");
|
||||||
//
|
}
|
||||||
// return true;
|
|
||||||
// }
|
// EIP-165
|
||||||
//
|
function supportsInterface(bytes4 interfaceID) public view returns ( bool ) {
|
||||||
// function declarator(address _target, uint256 _idx) public view returns ( address ) {
|
return false;
|
||||||
// uint256 idx;
|
}
|
||||||
// declaratorItem storage item;
|
|
||||||
//
|
function toReference(address _declarator, address _subject) private pure returns ( bytes32 ) {
|
||||||
// idx = declaratorItemsIndex[_target][_idx];
|
bytes32 k;
|
||||||
// item = declaratorItems[idx];
|
bytes memory signMaterial = new bytes(40);
|
||||||
//
|
bytes memory addrBytes = abi.encodePacked(_declarator);
|
||||||
// return item.signer;
|
for (uint256 i = 0; i < 20; i++) {
|
||||||
// }
|
signMaterial[i] = addrBytes[i];
|
||||||
//
|
}
|
||||||
// function declaration(address _declarator, address _target) public view returns ( bytes32[] memory ) {
|
addrBytes = abi.encodePacked(_subject);
|
||||||
// declaratorItem storage item;
|
for (uint256 i = 0; i < 20; i++) {
|
||||||
//
|
signMaterial[i+20] = addrBytes[i];
|
||||||
// item = declarationByDeclaratorIndex[_declarator][_target];
|
}
|
||||||
//
|
k = sha256(signMaterial);
|
||||||
// return item.content;
|
return k;
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
function declaratorCount(address _subject) public view returns ( uint256 ) {
|
||||||
|
return declarator[_subject].length;
|
||||||
|
}
|
||||||
|
|
||||||
|
function addDeclaration(address _subject, bytes32 _proof) public returns ( bool ) {
|
||||||
|
bytes32 k;
|
||||||
|
bytes32[] memory declarationContents;
|
||||||
|
uint256 declarationsIndex;
|
||||||
|
k = toReference(msg.sender, _subject);
|
||||||
|
declarationsIndex = declarations[k];
|
||||||
|
if (declarationsIndex == 0) { // This also works for the constructor :)
|
||||||
|
declarator[_subject].push(msg.sender);
|
||||||
|
contents.push(declarationContents); //= contents[declarationsIndex],
|
||||||
|
}
|
||||||
|
declarationsIndex = contents.length-1;
|
||||||
|
declarations[k] = declarationsIndex;
|
||||||
|
contents[declarationsIndex].push(_proof);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function declaration(address _declarator, address _subject) public view returns ( bytes32[] memory ) {
|
||||||
|
bytes32 k;
|
||||||
|
uint256 i;
|
||||||
|
k = toReference(_declarator, _subject);
|
||||||
|
i = declarations[k];
|
||||||
|
return contents[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,11 @@ all:
|
|||||||
solc AddressDeclarator.sol --bin | awk 'NR>3' > AddressDeclarator.bin
|
solc AddressDeclarator.sol --bin | awk 'NR>3' > AddressDeclarator.bin
|
||||||
truncate -s -1 AddressDeclarator.bin
|
truncate -s -1 AddressDeclarator.bin
|
||||||
|
|
||||||
|
old:
|
||||||
|
solc TokenEndorser.sol --abi | awk 'NR>3' > TokenEndorser.json
|
||||||
|
solc TokenEndorser.sol --bin | awk 'NR>3' > TokenEndorser.bin
|
||||||
|
truncate -s -1 TokenEndorser.bin
|
||||||
|
|
||||||
test: all
|
test: all
|
||||||
python test.py
|
python test.py
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ declarations = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
# Deployment is a self-signed declaration
|
# Deployment is a self-signed declaration
|
||||||
tx_hash = c.constructor(declarations[0]).transact({'from': w3.eth.accounts[0]})
|
tx_hash = c.constructor(declarations[0][0]).transact({'from': w3.eth.accounts[0]})
|
||||||
r = w3.eth.getTransactionReceipt(tx_hash)
|
r = w3.eth.getTransactionReceipt(tx_hash)
|
||||||
logg.debug('contract {}'.format(r.contractAddress))
|
logg.debug('contract {}'.format(r.contractAddress))
|
||||||
|
|
||||||
@ -53,7 +53,6 @@ assert r == w3.eth.accounts[0]
|
|||||||
|
|
||||||
r = c.functions.declaration(w3.eth.accounts[0], w3.eth.accounts[0]).call()
|
r = c.functions.declaration(w3.eth.accounts[0], w3.eth.accounts[0]).call()
|
||||||
assert r[0].hex() == declarations[0][0][2:]
|
assert r[0].hex() == declarations[0][0][2:]
|
||||||
assert r[1].hex() == declarations[0][1][2:]
|
|
||||||
|
|
||||||
|
|
||||||
# Add first declaration for 0 by 2
|
# Add first declaration for 0 by 2
|
||||||
|
Loading…
Reference in New Issue
Block a user