0

I need help for deploy below smart contract on remix IDE. I have facing a problem as I need to input to 'setgrantaddress' as address[], How to input data in it? enter image description here

There is two file name owned.sol and PublicAddress.sol.

 //owned.sol
pragma solidity >=0.4.21 <0.6.0;

contract Owned {

address owner;

  constructor () public{
   owner=msg.sender;
  }
  modifier onlyOwner(){
 if(msg.sender==owner){
     _;
    }
  }
}

owned.sol is simple file which is decide the owner of contract. then main contract PublicAddress.sol

    pragma solidity >=0.4.21 <0.6.0;
    import "./Owned.sol";

contract PublicAddress is Owned{

//Store addresses with Owner account and to which accounts the access is granted
struct addressStore{
    address[] grantAddresses;
    address accountOwner;
    mapping(address => uint) grantees;
    bool flag;
}

//Structure to the list of account to which the msg.sender address has access
struct accessAddress{
    address[] grantedAddresses;
}

//To set and get the addressStore
mapping(address => addressStore) StoreMap;

//To set and get the accessAddress
mapping(address => accessAddress) AccessStoreMap;
event addressStoreDetails(address, address, uint, bool, uint);

//Function where AccountOwner grant access to another account. The owner account is the sender account
function setGrantAddress(address[] memory grantees) public returns (bool) {
    StoreMap[msg.sender].accountOwner = msg.sender;
    for(uint i = 0; i< grantees.length; i++){
        if(StoreMap[msg.sender].grantees[grantees[i]] == 0){
        StoreMap[msg.sender].grantAddresses.push(grantees[i]);   
        StoreMap[msg.sender].grantees[grantees[i]] = 1;
        AccessStoreMap[grantees[i]].grantedAddresses.push(msg.sender);
        }
    }
    StoreMap[msg.sender].flag = true;
    return true;
  }

//Function used by external contracts to get details iff sender account has appropriate rights
function checkPermission(address _address) external view returns (bool) {
    require(StoreMap[_address].flag == true,"Invalid Address");
    if(StoreMap[_address].accountOwner == msg.sender){revert("Sender address same as Owner");}
    for(uint i =0; i < StoreMap[_address].grantAddresses.length; i++){
        if(StoreMap[_address].grantAddresses[i] == msg.sender){
            return  true;               
        }
     }
  }

//Function to get all the addresses to whom the sender has granted access
function getGrantAddresses() view public returns (address[] memory){
    require(StoreMap[msg.sender].flag == true, "Invalid Address");
    require(StoreMap[msg.sender].accountOwner == msg.sender,"Access Denied");
    return StoreMap[msg.sender].grantAddresses;
  }


//Function to remove grantee from the list of the sender account if its available
function removeGrantee(address _address) public{
    bool grantee = false;
    uint index;
    uint indexk;

    require(StoreMap[msg.sender].flag == true, "Sender Address mapping does not exist");

    for (uint i = 0; i < StoreMap[msg.sender].grantAddresses.length; i++){
        if(StoreMap[msg.sender].grantAddresses[i] == _address){
            grantee = true;
            index = i;
            break;
        }
    }

    require(grantee != false,"Address yet not granted access");
    emit addressStoreDetails(msg.sender, StoreMap[msg.sender].accountOwner, index, grantee, StoreMap[msg.sender].grantAddresses.length-1);
    StoreMap[msg.sender].grantAddresses[index] = StoreMap[msg.sender].grantAddresses[StoreMap[msg.sender].grantAddresses.length-1];
    delete StoreMap[msg.sender].grantAddresses[StoreMap[msg.sender].grantAddresses.length-1];
    StoreMap[msg.sender].grantAddresses.length--;
    delete StoreMap[msg.sender].grantees[_address];

    for (uint k = 0; k < AccessStoreMap[_address].grantedAddresses.length; k++){
        if(AccessStoreMap[_address].grantedAddresses[k] == msg.sender){
            indexk = k;
            break;
        }
    }
    AccessStoreMap[_address].grantedAddresses[indexk] = AccessStoreMap[_address].grantedAddresses[AccessStoreMap[_address].grantedAddresses.length -1];
    delete AccessStoreMap[_address].grantedAddresses[AccessStoreMap[_address].grantedAddresses.length -1];
    AccessStoreMap[_address].grantedAddresses.length--;
 }

function getGrantLength(address _address) public view returns (uint) {
    return StoreMap[_address].grantAddresses.length;
}

function accessableAddresses() view public returns(address[] memory){
    return AccessStoreMap[msg.sender].grantedAddresses;
   }
}

The smart contract details below.

Ethereum smart contract that can record a user's public address as having granted permission to another user’s public address. Assume that the contract will eventually be used by a DApp where users can grant permission and other users can check if they have permission for some entity. Use the setGrantAddress() to allow public addresses to have access to the msg.sender account. Use removeGrantee() to revoke the access privileges again from the msg.sender account. Use checkPermission() (input address in the msg.sender) from any account to check whether the access is provided to any other valid account. getGrantAddresses() to see all those accounts to which access has been granted. accessableAddresses() to see all those those accounts to which the msg.sender account has access to.

  • 1
    What do you mean when you say you are "unable to do that." What did you try, and what went wrong? Was there an error message? – user19510 Jan 24 at 21:40
  • Thanks for replying actually I am new to rinkeby testnet and unable to understand however I tried in remix it deploy perfectly but while deploying on rinkeby testnet I am confused lot could you help me on this if possible – Abhijeet Samanta Jan 24 at 21:44
  • No, it's not possible to help if you can't tell us what the problem is. – user19510 Jan 24 at 21:45
1

If you want to input the address array in the contract mask generated by remix, you have to do it like this:

["0x1234....", "0x2345...", ...]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.