Skip to content

Instantly share code, notes, and snippets.

@OdionOseiwe
Created August 12, 2022 14:24
Show Gist options
  • Select an option

  • Save OdionOseiwe/5ac0c1244aa923804b0086688c9c20c8 to your computer and use it in GitHub Desktop.

Select an option

Save OdionOseiwe/5ac0c1244aa923804b0086688c9c20c8 to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.5;
//a contract that before a person can withdraw an amount of money a number of people will approve before before the
//withdraw can occur
//1. put in some checks like a person has approved before
//2. check if a person who wants to approve is among the people to approve
contract Multisig{ //["0x5B38Da6a701c568545dCfcB03FcB875f56beddC4", "0x4B20993Bc481177ec7E8f571ceCaE8A9e22C02db", "0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2", "0x617F2E2fD72FD9D5503197092aC168c91465E7f2"]
address[] public onlyOwners;
//check if the person has approved
mapping(address => mapping(uint => bool)) checkApproved;
//////////////////////////
//the uint linking to a particular transaction that has been submitted
mapping(uint => Transaction) public submit;
//////////////////////////////////////////////////
///to check if this particular transaction with this particular approvals has been approved or not
mapping(uint256 => mapping(uint256 => bool)) _approved;
//transaction details
struct Transaction{
address to;
uint amount;
uint id;
bool submitted;
uint no_of_approval;
}
uint ID = 1;
constructor(address[] memory _onlyOwners) payable{
onlyOwners = _onlyOwners;
}
function submitted( uint _value ) external {
bool valid = validOnly();
require(valid, "You are not a valid signer!");
Transaction storage TR = submit[ID];
TR.to = msg.sender;
TR.amount = _value;
TR.id = ID;
TR.submitted = true;
ID++;
}
function validOnly() private view returns(bool){
bool foundOwner;
for(uint i; i < onlyOwners.length; i++){
if(msg.sender == onlyOwners[i]) {
foundOwner = true;
break;
}
}
return foundOwner;
}
function approval(uint id) external {
Transaction storage TR = submit[id];
bool valid = validOnly();
require(valid, "You are not a valid signer!");
require(msg.sender != TR.to, "not allowed to approve");
bool sub = TR.submitted;
uint amount = TR.amount;
address ben = TR.to;
require(sub == true, "not submitted");
require(checkApproved[msg.sender][id] != true, "approved this particular transaction");
checkApproved[msg.sender][id] = true;
uint minRequire = averageRe();
//noOfApproval[id] = noOfApproval[id]+ 1;
TR.no_of_approval = TR.no_of_approval + 1;
uint noOfApprovals = TR.no_of_approval;
if (noOfApprovals >= minRequire) {
_approved[id][noOfApprovals] = true;
(bool sent,) = payable(ben).call{value: amount}("");
require(sent, "failed");
}
}
function averageRe() public view returns(uint) {
uint owners = onlyOwners.length;
return (owners * 80) / 100;
}
function conBal() external view returns(uint){
return address(this).balance;
}
receive() external payable{}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment