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 {
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;
// }
}