Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.5.11;
- contract Bitmonds_one_main_Owner {
- //parameter--------------------------------------------------------------------------------------------
- struct BitmondsOwner {
- string bitmond;
- string owner;
- }
- BitmondsOwner[] private registry;
- mapping(address => bool) private authorized;
- address private owner;
- //event-------------------------------------------------------------------------------------------
- event AddedOwner(address newOwner);
- event RemovedOwner(address removedOwner);
- event transferMain_owner(address new_main_owner);
- //function for admin-------------------------------------------------------------------------------------------
- function addAuthorized(address _toAdd) onlyAuthorized() public
- {
- require(!authorized[_toAdd],"This owner already exists");
- authorized[_toAdd] = true;
- emit AddedOwner(_toAdd);
- }
- function removeAuthorized(address _toRemove) onlyAuthorized() public
- {
- require(_toRemove != msg.sender && _toRemove != owner,"You cannot remove yourself or main owner");
- authorized[_toRemove] = false;
- emit RemovedOwner(_toRemove);
- }
- function transferOwnership_Creator(address newOwner) public onlyCreator()
- {
- owner = newOwner;
- emit transferMain_owner(newOwner);
- }
- function check_creator(address _admin) public view returns(bool Creator)
- {
- return(owner == _admin);
- }
- function check_autorized(address _admin) public view returns(bool authorize)
- {
- return(authorized[_admin]);
- }
- //modifier-------------------------------------------------------------------------------------------
- modifier onlyAuthorized()
- {
- require(authorized[msg.sender] || msg.sender == owner, "You are not Authorized!");
- _;
- }
- modifier onlyCreator()
- {
- require(msg.sender == owner);
- _;
- }
- //constructor-------------------------------------------------------------------------------------------
- constructor() public
- {
- owner = msg.sender;
- }
- //write--------------------------------------------------------------------------------------------------
- //in questa funzione è stato inserito "onlyAuthorized" per permettere la scrittura solo dal wallet autorizzato
- function push_Bitmonds(string memory Bitmond,string memory Owners) public onlyAuthorized
- {
- registry.push(BitmondsOwner(Bitmond, Owners));
- }
- //read------------------------------------------------------------------------------------------------------------
- //ho voluto aggiungere queste due funzioni per differenziare i due owner ovvero il primo
- //"check final owner" serve per trovare il propetario che attualmente possiede bitmond (quindi è la stessa della funzione del vecchio //smartcontract: "lookup")
- //mentre "check_FIRST_Owner" serve per vedere chi è stato il primo propetario (una funzionalità in più)
- function check_Final_Owner(string memory Bitmond) internal view returns (string memory Owner)
- {
- for (uint i = 0; i < registry.length; i++) {
- if (compareStrings(Bitmond, registry[i].bitmond)) {
- Owner=registry[i].owner;
- }
- }
- }
- function check_FIRST_Owner(string memory Bitmond) internal view returns (string memory Owner)
- {
- for (uint i = 0; i < registry.length; i++) {
- if (compareStrings(Bitmond, registry[i].bitmond)) {
- return(registry[i].owner);
- }
- }
- }
- function compareStrings (string memory a, string memory b) internal pure returns (bool)
- {
- return (keccak256(abi.encodePacked((a))) == keccak256(abi.encodePacked((b))) );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement