@filip @jon_m
I decided to try this out on my own without checking for assistance in later videos. What I did was two functions; sign and action. Sign I think makes sure that the function caller is one of the three owners. Action I believe is the function that makes sure you are allowed to continue with the function if 2/3 individuals have signed. I am fairly certain I have gotten this terribly wrong but I am very open to receive critique.
In other words, roast my code please.
pragma solidity 0.7.5;
import â./Ownable.solâ;
import â./Destroyable.solâ;
interface externalInterface{
function addTransaction(address from, address to, uint amount) external;
}
contract helloworld is Ownable, Destroyable{
externalInterface InterfaceDesignation = externalInterface(0xddaAd340b0f1Ef65169Ae5E41A8b10776a75482d);
address owner1;
address owner2;
address owner3;
mapping(address => bool) signed;
mapping(address => uint256) balance;
constructor(){
owner1 = 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4;
owner2 = 0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2;
owner3 = 0x4B20993Bc481177ec7E8f571ceCaE8A9e22C02db;
}
function sign() public view{
require(msg.sender == owner1 || msg.sender == owner2 || msg.sender == owner3);
require(signed[msg.sender] == false);
signed[msg.sender] == true;
}
function action() public{
require((signed[owner1] == true && signed[owner2] == true)
|| (signed[owner1] == true && signed[owner3] == true)
|| (signed[owner2] == true && signed[owner3] == true));
signed[owner1] = false;
signed[owner2] = false;
signed[owner3] = false;
}
function deposit() public payable returns(uint){
balance[msg.sender] += msg.value;
return balance[msg.sender];
}
function withdraw(uint amount) public onlyOwner returns(uint){
sign();
action();
msg.sender.transfer(amount);
uint newBalance;
newBalance = balance[msg.sender] - amount;
return newBalance;
}
function getBalance() public view returns(uint){
return balance[msg.sender];
}
function transfer(address recipient, uint amount) public {
sign();
action();
require(balance[msg.sender] >= amount);
require(msg.sender != recipient);
_transfer(msg.sender, recipient, amount);
InterfaceDesignation.addTransaction(msg.sender, recipient, amount);
uint originalBalance = balance[msg.sender];
assert(balance[msg.sender] == originalBalance - amount);
}
function _transfer(address from, address to, uint amount) private {
balance[from] -= amount;
balance[to] += amount;
}
}