I’ve added the ability to get the contract balance and to check that a transfer cannot be made that exceeds the balance:
pragma solidity 0.7.5;
pragma abicoder v2;
contract Wallet {
address[3] public signers;
uint limit;
uint balance;
struct Transfer{
uint amount;
address payable recipient;
uint confirmations;
uint id;
bool Sent;
}
Transfer[] transferRequests;
constructor(address _signers1, address _signers2, address _signers3, uint _limit){
require(_signers1 != _signers2);
require(_signers1 != _signers3);
require(_signers2 != _signers3);
signers = [_signers1, _signers2, _signers3];
limit = _limit;
}
mapping(address => mapping (uint => bool)) confirmations;
modifier onlyOwners(){
require(msg.sender == signers[0]||msg.sender == signers[1]||msg.sender == signers[2]);
_;
}
function deposit() public payable returns (uint){
balance+= msg.value;
return balance;
}
function createTransfer(uint _amount, address payable _recipient) public onlyOwners{
require (msg.sender != _recipient, "You cannot send money to yourself");
transferRequests.push(
Transfer(_amount, _recipient, 0, transferRequests.length, false)
);
}
function confirm(uint _id, uint _amount) public onlyOwners{
require(confirmations[msg.sender][_id]==false);
require(transferRequests[_id].Sent == false);
confirmations[msg.sender][_id] = true;
transferRequests[_id].confirmations++;
if(transferRequests[_id].confirmations >= limit){
transferRequests[_id].Sent = true;
require (balance >= _amount, "Balance not sufficient");
transferRequests[_id].recipient.transfer(transferRequests[_id].amount);
balance = balance - _amount;
}
}
function getTransferRequests() public view returns(Transfer[] memory){
return transferRequests;
}
function getBalance() public view returns (uint){
return balance;
}
}