Refactor interfaces

This commit is contained in:
nolash 2020-12-29 16:11:32 +01:00
parent 2b207135d7
commit 0b76e366b5
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746

View File

@ -4,52 +4,48 @@ pragma solidity >=0.6.12;
contract AddressDeclarator { contract AddressDeclarator {
struct declaratorItem { mapping( bytes32 => uint256[] )
address signer; //mapping( address => uint256[] ) declaratorItemsIndex;
bytes32[] content; //mapping( address => uint256 ) public declaratorCount;
} //mapping( address => mapping ( address => declaratorItem ) ) declarationByDeclaratorIndex;
bytes32[][] contents;
mapping( address => uint256[] ) declaratorItemsIndex; // constructor(bytes32[] memory _descriptions) {
mapping( address => uint256 ) public declaratorCount; // for (uint i; i < _descriptions.length; i++) {
mapping( address => mapping ( address => declaratorItem ) ) declarationByDeclaratorIndex; // addDeclaration(msg.sender, _descriptions[i]);
declaratorItem[] declaratorItems; // }
// }
constructor(bytes32[] memory _descriptions) { //
for (uint i; i < _descriptions.length; i++) { // function addDeclaration(address _subject, bytes32 _proof) public returns ( bool ) {
addDeclaration(msg.sender, _descriptions[i]); // declaratorItem storage item;
} //
} // item = declarationByDeclaratorIndex[msg.sender][_subject];
// if (item.signer == address(0)) {
function addDeclaration(address _subject, bytes32 _proof) public returns ( bool ) { // item.signer = msg.sender;
declaratorItem storage item; // declaratorItemsIndex[_subject].push(declaratorItems.length);
// declaratorItems.push(item);
item = declarationByDeclaratorIndex[msg.sender][_subject]; // declaratorCount[_subject]++;
if (item.signer == address(0)) { // }
item.signer = msg.sender; // item.content.push(_proof);
declaratorItemsIndex[_subject].push(declaratorItems.length); //
declaratorItems.push(item); // return true;
declaratorCount[_subject]++; // }
} //
item.content.push(_proof); // function declarator(address _target, uint256 _idx) public view returns ( address ) {
// uint256 idx;
return true; // declaratorItem storage item;
} //
// idx = declaratorItemsIndex[_target][_idx];
function declarator(address _target, uint256 _idx) public view returns ( address ) { // item = declaratorItems[idx];
uint256 idx; //
declaratorItem storage item; // return item.signer;
// }
idx = declaratorItemsIndex[_target][_idx]; //
item = declaratorItems[idx]; // function declaration(address _declarator, address _target) public view returns ( bytes32[] memory ) {
// declaratorItem storage item;
return item.signer; //
} // item = declarationByDeclaratorIndex[_declarator][_target];
//
function declaration(address _declarator, address _target) public view returns ( bytes32[] memory ) { // return item.content;
declaratorItem storage item; // }
item = declarationByDeclaratorIndex[_declarator][_target];
return item.content;
}
} }