Hey @theurer, hope you are great.
I’ve tested your contract, it does looks quite amazing to be honest, you have made a very nice job man! congrats
- After deployment,
setOwners
to set the 2 extra owners. - Deposit 3 eth and check balance on
getContractInfo
andgetUserBalance
, all good. -
requestTransfer
with 1st owner to transfer 3 eth to an external address (non-owner), check withgetPendingTransfer
-
approveTransfer
with 2nd and 3rd owner, checkgetPendingTransfer
again, it have 3approvalCounter
- Now for
completeTransfer
i tried it with the external address that should get the funds, so it triggers properly and thenwithdraw
with the same account, I got my 3 eth perfectly in its wallet.
Now here are some improvements (cuz there is always room for improvements )
Instead of returning an string message when a transaction is completed properly, you could use an Event, that way you could achieve the same goal but scalabe for further develops (events are the way that you track your conctract activity for the dapp, if you want to show a success message in your dapp after the transaction is completed, you have to track the complete event instead the returned value of the function).
function completeTransfer() public returns(string memory){
require(approvalCounter == 2 || approvalCounter == 3);
for(uint i = 0; i <= 2; i++){
ownersList[i].hasApprovedTransfer = false;
}
uint previousSenderBalance = balance[transferRequester];
_transfer(transferRequester, transctionLog[0].recipient, transctionLog[0].amount);
pendingTransfer = false;
approvalCounter = 0;
assert(balance[transferRequester] == previousSenderBalance - transctionLog[0].amount);
return ("Transfer was successful!");
}
This 2 functions shares almost the same require
conditions, might be better to create a modifier
for them.
function requestTransfer(uint _amount, address _recipient)public {
require(balance[msg.sender] >= _amount, "Balance not sufficient.");
require(msg.sender == ownersList[0].owner || msg.sender == ownersList[1].owner || msg.sender == ownersList[2].owner, "You don't have access to this contract!");
transctionLog.push(Transactions(_recipient, _amount));
pendingTransfer = true;
transferRequester = msg.sender;
approvalCounter = 1;
}
function approveTransfer() public {
require((msg.sender == ownersList[0].owner || msg.sender == ownersList[1].owner || msg.sender == ownersList[2].owner) && msg.sender != transferRequester, "You are not allowed to approve this transfer.");
for(uint i = 0; i <= 2; i++){
if(ownersList[i].owner == msg.sender && ownersList[i].hasApprovedTransfer == false){
approvalCounter++;
ownersList[i].hasApprovedTransfer = true;
}
}
}
Should be something like this
modifier onlySetOwners(){
require(msg.sender == ownersList[0].owner || msg.sender == ownersList[1].owner || msg.sender == ownersList[2].owner, "You don't have access to this contract!");
_;
}
Then your functions will looks like this:
function requestTransfer(uint _amount, address _recipient)public onlySetOwners{
require(balance[msg.sender] >= _amount, "Balance not sufficient.");
transctionLog.push(Transactions(_recipient, _amount));
pendingTransfer = true;
transferRequester = msg.sender;
approvalCounter = 1;
}
function approveTransfer() public onlySetOwners{
require(msg.sender != transferRequester, "You are not allowed to approve this transfer.");
for(uint i = 0; i <= 2; i++){
if(ownersList[i].owner == msg.sender && ownersList[i].hasApprovedTransfer == false){
approvalCounter++;
ownersList[i].hasApprovedTransfer = true;
}
}
}
Overall you have made a great work if you did not peak into the solutions
Amazing work man, congrats!
Carlos Z