Declaration
警告:未使用的函式參數。刪除或註釋掉變數名稱以消除此警告。此聲明隱藏了現有聲明
function Createvault(string memory name, address[] memory users, uint initialamount)public returns(uint vaultId){ vault storage vault = vaults[totalvaults]; vault.creator = msg.sender; vault.name = name; vault.amount = initialamount; totalvaults <=1; return totalvaults -1; } function addAmount(uint vaultId, uint amount)public { vault storage vault = vaults[vaultId]; require(msg.sender == vault.creator,"not vault owner"); vault.amount += amount; } function distribute( uint vaultId)public { vault storage vault = vaults[vaultId]; uint amountperuser =vault.amount / vault.users.length; if(vault.amount !=0){ for(uint i; i < vault.users.length;i++){ vault.amount = amountperuser; balance[vault.users[i]] = amountperuser; }} else{ revert ("no funds avelible"); } emit vaultdistribution(vaultId,amountperuser*vault.users.length); } }
警告 1
我假設你的結構聲明是這樣的:
struct vault { address creator; string name; uint amount; }
vault storage vault = vaults[vaultId];
這一行給你警告,因為你用 name 聲明變數vault
,它已經用於聲明結構解決方案:使用名稱重命名結構,
Vault
您應該擺脫第一個警告。在 Pascal 情況下命名 Struct 也是一種命名約定做法。警告 2
在
Createvault(string memory name, address[] memory users, uint initialamount)
您沒有users
在函式中的任何位置使用數組的值。解決方法:如果函式中不需要使用,可以將其從參數中去掉。
嘗試重命名您的 Vault 變數——該變數不應與它的結構類型同名。