Hello,
This is what I came up with for the multisig wallet, before looking at the assistance videos. It’s a bit different from Filips solution but seemed to work in my remix testing. I used a mapping inside the struct instead of double mapping. I also used a mapping for owner addresses instead of an array.
Any feedback or improvement ideas are appriciated.
Code:
pragma solidity 0.8.1;
contract MultisigWallet {
mapping (address => bool) ownerAddresses;
uint approvalsNeeded;
constructor(address[] memory _ownerAddresses, uint _approvalsNeeded) {
uint i = 0;
while (i < _ownerAddresses.length) {
ownerAddresses[_ownerAddresses[i]] = true;
i++;
}
approvalsNeeded = _approvalsNeeded;
}
struct transferRequest {
uint amount;
address recipientAddress;
uint approvals;
mapping (address => bool) ownerApprovals;
}
transferRequest[] tRarray;
function deposit() public payable {
}
function requestTransfer(uint _amount, address _address) public returns (uint){
require(ownerAddresses[msg.sender] == true, "Not owner");
uint id = tRarray.length;
tRarray.push();
transferRequest storage tR = tRarray[id];
tR.amount = _amount;
tR.recipientAddress = _address;
return id;
}
function approve(uint _id) public {
require(ownerAddresses[msg.sender] == true, "Not owner");
require(tRarray[_id].ownerApprovals[msg.sender] != true, "Already approved");
tRarray[_id].ownerApprovals[msg.sender] = true;
tRarray[_id].approvals++;
if (tRarray[_id].approvals >= approvalsNeeded) {
payable(address(tRarray[_id].recipientAddress)).transfer(tRarray[_id].amount);
delete tRarray[_id];
}
}
}
Thanks!