Solidity

支付映射中的所有項目

  • December 24, 2021

我想在一個函式呼叫中支付多個地址,但我盡量避免使用數組。

struct Receiver {
   address receiver;
   bool paidOut;
   bool isWinner;
}


mapping(address => Receiver) public receivers;

無論如何我可以一起支付在這個映射中註冊的所有地址嗎?還是我需要使用數組。謝謝。

您需要一個數組或映射中的某種索引才能這樣做。如果您選擇索引選項,您仍然需要在應用程序端進行迭代並為映射的每個成員呼叫支付函式。

實體文件:

struct Receiver {
   address receiver;
   bool paidOut;
   bool isWinner;
}
   
mapping(uint => mapping(address => Receiver)) public receivers;

function payout(uint index, address payer) public payable{
   //get the one Im working on
   Receiver receiver = receivers[index][payer];
  //...Some logic
}

引用自:https://ethereum.stackexchange.com/questions/117254