Hi!
Need some help. This is my take on the assignment:
pragma solidity 0.8.1;
contract MultiSigWallet{
address creator;
constructor(){
creator = msg.sender;
}
modifier onlyCreator{
require(msg.sender == creator, "You need to be creator.");
_;
}
mapping(address => bool) wallOwners;
uint addedOwners = 0;
function addOwners(address _owner) public onlyCreator {
wallOwners[_owner] = true;
addedOwners += 1;
}
uint nApprovals;
function setApprovals(uint _reqApprovals) public onlyCreator {
require(_reqApprovals <= addedOwners, "Amount of approvers has to be less or equal than the amount of owners.");
nApprovals = _reqApprovals;
}
modifier onlyOwners{
require(wallOwners[msg.sender], "You need to be an owner.");
_;
}
mapping(address => uint) balance;
event depositDone(uint amount, address indexed depositedTo);
event transferDone(uint amount, address indexed depositedTo);
function deposit() public payable returns(uint){
balance[address(this)] += msg.value;
emit depositDone(msg.value, address(this));
return balance[address(this)];
}
function getBalance() public view returns(uint){
return address(this).balance;
}
struct Transaction {
address payable rec;
uint amt;
address[] signatures;
}
mapping(uint => Transaction) Transactions;
function createTransferRequest(address payable recipient, uint amount, uint id) public onlyOwners {
require(balance[address(this)] >= amount, "Balance not enough");
require(address(this) != recipient, "Don't transfer to yourself");
Transactions[id] = Transaction(recipient, amount, new address[](0));
}
function signAndTransfer(uint inputID) public onlyOwners {
uint amountOfSignatures = Transactions[inputID].signatures.length;
bool signedBySender = false;
for (uint i=0; i < amountOfSignatures; i++) {
if(Transactions[inputID].signatures[i]==msg.sender){
signedBySender = true;
break;
}
}
if (signedBySender = false){
Transactions[inputID].signatures.push(msg.sender);
amountOfSignatures = Transactions[inputID].signatures.length;
if(amountOfSignatures == nApprovals){
uint previousSenderBalance = balance[address(this)];
_transfer(address(this), Transactions[inputID].rec, Transactions[inputID].amt);
assert(balance[address(this)] == previousSenderBalance - Transactions[inputID].amt);
emit transferDone(Transactions[inputID].amt, Transactions[inputID].rec);
}
}
}
function _transfer(address from, address payable to, uint amount) private {
to.transfer(amount);
balance[from] -= amount;
balance[to] += amount;
}
}
The Transactions
mapping points to a Transaction
struct for each transaction request. Inside each Transaction
struct there is an array that holds the signatures
in form of addresses of the signers.
The idea is that the signAndTransfer
function pushes the addresses of the signers to the signatures
array of each transaction request and once the length of the array reaches nApprovals
the transfer should execute.
The issue Iām facing seems to be that the signatures/addresses donāt get added to the signatures
array. However I canāt figure out why. This is in this line:
Transactions[inputID].signatures.push(msg.sender);
Could you please help me with that?
Thanks!
Max