Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. pragma solidity ^0.5.11;
  2.  
  3.  
  4. contract Bitmonds_one_main_Owner {
  5.  
  6.  
  7.  
  8. //parameter--------------------------------------------------------------------------------------------
  9.  
  10.  
  11.  
  12.  
  13. struct BitmondsOwner {
  14. string bitmond;
  15. string owner;
  16. }
  17. BitmondsOwner[] private registry;
  18.  
  19. mapping(address => bool) private authorized;
  20. address private owner;
  21.  
  22.  
  23.  
  24. //event-------------------------------------------------------------------------------------------
  25.  
  26.  
  27.  
  28.  
  29.  
  30. event AddedOwner(address newOwner);
  31. event RemovedOwner(address removedOwner);
  32. event transferMain_owner(address new_main_owner);
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39. //function for admin-------------------------------------------------------------------------------------------
  40.  
  41.  
  42. function addAuthorized(address _toAdd) onlyAuthorized() public
  43. {
  44. require(!authorized[_toAdd],"This owner already exists");
  45. authorized[_toAdd] = true;
  46. emit AddedOwner(_toAdd);
  47. }
  48.  
  49. function removeAuthorized(address _toRemove) onlyAuthorized() public
  50. {
  51. require(_toRemove != msg.sender && _toRemove != owner,"You cannot remove yourself or main owner");
  52. authorized[_toRemove] = false;
  53. emit RemovedOwner(_toRemove);
  54. }
  55.  
  56. function transferOwnership_Creator(address newOwner) public onlyCreator()
  57. {
  58.  
  59. owner = newOwner;
  60. emit transferMain_owner(newOwner);
  61.  
  62. }
  63.  
  64. function check_creator(address _admin) public view returns(bool Creator)
  65. {
  66. return(owner == _admin);
  67. }
  68.  
  69. function check_autorized(address _admin) public view returns(bool authorize)
  70. {
  71. return(authorized[_admin]);
  72. }
  73.  
  74.  
  75. //modifier-------------------------------------------------------------------------------------------
  76.  
  77.  
  78.  
  79. modifier onlyAuthorized()
  80. {
  81. require(authorized[msg.sender] || msg.sender == owner, "You are not Authorized!");
  82. _;
  83. }
  84.  
  85. modifier onlyCreator()
  86. {
  87. require(msg.sender == owner);
  88. _;
  89. }
  90.  
  91.  
  92.  
  93.  
  94. //constructor-------------------------------------------------------------------------------------------
  95.  
  96.  
  97.  
  98. constructor() public
  99. {
  100. owner = msg.sender;
  101.  
  102. }
  103.  
  104.  
  105.  
  106.  
  107. //write--------------------------------------------------------------------------------------------------
  108.  
  109.  
  110.  
  111. //in questa funzione è stato inserito "onlyAuthorized" per permettere la scrittura solo dal wallet autorizzato
  112. function push_Bitmonds(string memory Bitmond,string memory Owners) public onlyAuthorized
  113. {
  114. registry.push(BitmondsOwner(Bitmond, Owners));
  115. }
  116.  
  117.  
  118.  
  119. //read------------------------------------------------------------------------------------------------------------
  120.  
  121.  
  122.  
  123. //ho voluto aggiungere queste due funzioni per differenziare i due owner ovvero il primo
  124. //"check final owner" serve per trovare il propetario che attualmente possiede bitmond (quindi è la stessa della funzione del vecchio //smartcontract: "lookup")
  125. //mentre "check_FIRST_Owner" serve per vedere chi è stato il primo propetario (una funzionalità in più)
  126. function check_Final_Owner(string memory Bitmond) internal view returns (string memory Owner)
  127. {
  128. for (uint i = 0; i < registry.length; i++) {
  129. if (compareStrings(Bitmond, registry[i].bitmond)) {
  130. Owner=registry[i].owner;
  131. }
  132. }
  133.  
  134. }
  135.  
  136. function check_FIRST_Owner(string memory Bitmond) internal view returns (string memory Owner)
  137. {
  138. for (uint i = 0; i < registry.length; i++) {
  139. if (compareStrings(Bitmond, registry[i].bitmond)) {
  140. return(registry[i].owner);
  141. }
  142. }
  143.  
  144. }
  145.  
  146.  
  147.  
  148.  
  149. function compareStrings (string memory a, string memory b) internal pure returns (bool)
  150. {
  151. return (keccak256(abi.encodePacked((a))) == keccak256(abi.encodePacked((b))) );
  152. }
  153.  
  154.  
  155.  
  156.  
  157.  
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement