Solidity
無法輸入地址混音中的參數
我需要幫助以在 remix IDE 上部署以下智能合約。我遇到了一個問題,因為我需要輸入“setgrantaddress”作為地址
$$ $$,如何輸入數據呢? 有兩個文件名owned.sol 和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){ _; } } }
own.sol 是一個簡單的文件,它決定了合約的所有者。然後是主契約 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; } }
智能合約詳情如下。
乙太坊智能合約,可以記錄一個使用者的公共地址,因為它已經授予了另一個使用者的公共地址的權限。假設合約最終將被 DApp 使用,使用者可以授予權限,其他使用者可以檢查他們是否對某個實體具有權限。使用 setGrantAddress() 允許公共地址訪問 msg.sender 帳戶。使用 removeGrantee() 再次撤銷 msg.sender 帳戶的訪問權限。使用任何帳戶的 checkPermission()(在 msg.sender 中輸入地址)檢查是否向任何其他有效帳戶提供了訪問權限。getGrantAddresses() 以查看所有已授予訪問權限的帳戶。accessableAddresses() 以查看 msg.sender 帳戶有權訪問的所有那些帳戶。
如果你想在 remix 生成的合約遮罩中輸入地址數組,你必須這樣做:
["0x1234....", "0x2345...", ...]