From 0b76e366b5e632a73a39855720225177dd444820 Mon Sep 17 00:00:00 2001 From: nolash Date: Tue, 29 Dec 2020 16:11:32 +0100 Subject: [PATCH] Refactor interfaces --- solidity/AddressDeclarator.sol | 90 ++++++++++++++++------------------ 1 file changed, 43 insertions(+), 47 deletions(-) diff --git a/solidity/AddressDeclarator.sol b/solidity/AddressDeclarator.sol index d290133..fdebef1 100644 --- a/solidity/AddressDeclarator.sol +++ b/solidity/AddressDeclarator.sol @@ -4,52 +4,48 @@ pragma solidity >=0.6.12; contract AddressDeclarator { - struct declaratorItem { - address signer; - bytes32[] content; - } + mapping( bytes32 => uint256[] ) + //mapping( address => uint256[] ) declaratorItemsIndex; + //mapping( address => uint256 ) public declaratorCount; + //mapping( address => mapping ( address => declaratorItem ) ) declarationByDeclaratorIndex; + bytes32[][] contents; - mapping( address => uint256[] ) declaratorItemsIndex; - mapping( address => uint256 ) public declaratorCount; - mapping( address => mapping ( address => declaratorItem ) ) declarationByDeclaratorIndex; - declaratorItem[] declaratorItems; - - constructor(bytes32[] memory _descriptions) { - for (uint i; i < _descriptions.length; i++) { - addDeclaration(msg.sender, _descriptions[i]); - } - } - - function addDeclaration(address _subject, bytes32 _proof) public returns ( bool ) { - declaratorItem storage item; - - item = declarationByDeclaratorIndex[msg.sender][_subject]; - if (item.signer == address(0)) { - item.signer = msg.sender; - declaratorItemsIndex[_subject].push(declaratorItems.length); - declaratorItems.push(item); - declaratorCount[_subject]++; - } - item.content.push(_proof); - - return true; - } - - function declarator(address _target, uint256 _idx) public view returns ( address ) { - uint256 idx; - declaratorItem storage item; - - idx = declaratorItemsIndex[_target][_idx]; - item = declaratorItems[idx]; - - return item.signer; - } - - function declaration(address _declarator, address _target) public view returns ( bytes32[] memory ) { - declaratorItem storage item; - - item = declarationByDeclaratorIndex[_declarator][_target]; - - return item.content; - } +// constructor(bytes32[] memory _descriptions) { +// for (uint i; i < _descriptions.length; i++) { +// addDeclaration(msg.sender, _descriptions[i]); +// } +// } +// +// function addDeclaration(address _subject, bytes32 _proof) public returns ( bool ) { +// declaratorItem storage item; +// +// item = declarationByDeclaratorIndex[msg.sender][_subject]; +// if (item.signer == address(0)) { +// item.signer = msg.sender; +// declaratorItemsIndex[_subject].push(declaratorItems.length); +// declaratorItems.push(item); +// declaratorCount[_subject]++; +// } +// item.content.push(_proof); +// +// return true; +// } +// +// function declarator(address _target, uint256 _idx) public view returns ( address ) { +// uint256 idx; +// declaratorItem storage item; +// +// idx = declaratorItemsIndex[_target][_idx]; +// item = declaratorItems[idx]; +// +// return item.signer; +// } +// +// function declaration(address _declarator, address _target) public view returns ( bytes32[] memory ) { +// declaratorItem storage item; +// +// item = declarationByDeclaratorIndex[_declarator][_target]; +// +// return item.content; +// } }