为了人类,有人能帮忙吗?
splitValue是由msg.sender发送的--发送者是beneficiaryList的一部分--但在发送时被排除在列表之外。那在代码中会是什么样的呢?
我有个开始:
uint splitValue = uint(msg.value/beneficiaryList.length);
for (uint index = 0; index < beneficiaryList.length; index++) {
beneficiaryList [index].transfer(SplitValue);
if(participants[msg.sender] != 0){
beneficiaryList [index] != (msg.sender); }不确定最后两行是否正确。
发布于 2017-08-11 03:16:23
如果beneficiaryList是一个或多个地址,并且正在遍历该数组,则只需根据msg.sender检查它,如果匹配,则跳过它。所以,就像:
uint splitValue = uint(msg.value/beneficiaryList.length);
uint l = beneficiaryList.length;
for (uint index = 0; index < l; index++) {
address b = beneficiaryList[index];
if (b != msg.sender) {
b.transfer(splitValue);
}
}我无法控制最后两行,因为我不知道他们应该做什么。
顺便说一句,要注意的是,在您所做的工作中有一些代码气味,这可能表明您应该改变您的方法。除非您知道beneficiaryList的长度是有限的,否则您的代码可能会耗尽汽油,而且您可能永远无法运行它,因为它超过了块气体限制。另外,由于受益人地址可能是合同的地址,而transfer将调用默认支付函数,它可能会抛出异常或导致汽油耗尽,这也将阻止任何人使用该功能。根据其他代码的不同,它也可能存在重入问题。考虑使用退出模式代替。
https://ethereum.stackexchange.com/questions/24108
复制相似问题