我正在尝试使用一个程序,该程序使用JavaScript VM环境在remix ide上将测试醚从一个帐户转移到另一个帐户。我看不到资金转入受益人帐户。
我也输入了诊断代码,该代码可打印合同的当前余额,但始终显示0。
pragma solidity <=0.5.7;
contract MultiSigWallet{
address payable private owner;
address payable private beneficiary;
uint private minApprovers ;
uint private currentApprovals;
mapping(address => bool) approvedBy;
mapping(address =>bool) isApprover;
uint public contractBalance;
constructor (address payable _beneficiary, address [] memory _approvers, int32 _minApprovers) public payable{
require(_approvers.length > 0 && _minApprovers > 0,"At least one approver is required!");
require(_approvers.length >= minApprovers,"Number of minimum approvers cannot be more than total approvers count");
owner = msg.sender;
beneficiary = _beneficiary;
for(uint i = 0;i<_approvers.length;i++){
isApprover[_approvers[i]]= true;
}
}
function approve () public{
require(isApprover[msg.sender],"Not an Approver");
if(!approvedBy[msg.sender]){
approvedBy[msg.sender] = true;
currentApprovals++;
}
if(currentApprovals== minApprovers){
beneficiary.send(address(this).balance);
selfdestruct(owner);
}
}
function getContractBalance () public payable returns( uint){
contractBalance = address(this).balance;
}
function reject() public {
require(isApprover[msg.sender],"Not an approver!");
selfdestruct(owner);
}
}
如果我提供的收款人地址为a1,批准者列表为a2,a3,并且我通过在值字段中放置10个以太币来调用a4的构造函数,那么我可以看到a4余额减少了10个以太币。
接下来,在从帐户a2,a3批准后,我预计a1的余额将增加10个以太币,而合同的余额将变为0。
但是我看不到a1余额有变化,合同余额始终为0。
有人可以解释我做错了什么,或者我的理解是否有空白?
答案 0 :(得分:0)
您可能想在构造函数中执行类似minApprovers = _minApprovers
的操作。否则,minApprovers
始终为0
,并且您的==
检查将始终失败,因为第一次成功调用approve
将使currentApprovals == 1
。