I tired without watching the next videos, got a parsing error for an import directive that I could not figure out so not sure if it was going to work.
// SPDX-License-Identifier: MIT
pragma abicoder v2;
pragma solidity ^0.7.5;
contract MultisigWallet {
event Deposit(address indexed sender, uint amount, uint balance);
event SubmitTransaction(
address indexed owner,
uint indexed txIndex,
address indexed txIndex,
address indexed to,
uint value,
bytes data);
event ConfirmTransaction(address indexed owner, uint indexed txIndex);
event RevokeConfirmation(address indexed owner, uint indexed txIndex);
event ExecuteTransaction(address indexed owner, uint indexed txIndex);
// store owners in array of addresses
address[] public owners;
// check for no duplicate owners
mapping(address => bool) public isOwner;
// store # of confirmations required to execute a tx
uint public numConfirmationRequired;
// When a tx is proposed by calling SubmitTransaction >> create struct
struct Transaction {
address to;
uint value;
bytes data;
bool executed;
uint numConfirmations;
}
// mapping from tx index => owner => bool
mapping(uint => mapping(address => bool)) public isConfirmed;
// store struct inside array of transactions
Transaction[] public transactions;
modifier onlyOwner() {
require(isOwner[msg.sender], "not owner");
_; // if caller is owner execute the rest of the function
}
modifier txExists(uint _txIndex) {
require(_txIndex < transactions.length, "tx does not exist");
_;
}
modifier notExecuted(uint _txIndex) {
require(!transactions[_txIndex].executed, "tx already executed");
_;
}
modifier notConfirmed(uint _txIndex) {
require(!transactions[_txIndex].isConfirmed[msg.sender], "tx already confirmed");
}
constructor(address[] memory _owners, uint _numConfirmationsRequired) public {
require(_owners.length > 0, "owners required"); // require array of owners !empty
require( _numConfirmationsRequired > 0 && _numConfirmationsRequired <= _owners.length, "invalid number of required confirmations");
// copy owners from input into state variables
for (uint i = 0; i < _owners.length; i++)
address owner = _owners[i];
require(owner != address(0), "invalid owner");
require(!isOwner[owner], "owner not unique");
isOwner[owner] = true;
owners.push(owner);
}
numConfirmationsRequired _numConfirmationsRequired;
}
// define fallback function declared as payable so we can send Ether to contract
// when called emit deposit event
function deposit () payable external {
emit Deposit(msg.sender, msg.value, address(this).balance);
}
// owner submits tx that must be approved by other owners
function submitTransaction(address _to, uint _value, bytes memory _data) public onlyOwner {
uint txIndex = transactions.length; // id for tx created
// initialize a tx struct and append to array of transactions
transactions.push(Transaction({
to: _to,
value: _value,
data: _data,
executed: false,
numConfirmations: 0
}));
emit SumbitTransaction(msg.sender, txIndex, _to, _value, _data);
}
// allow owners to approve transaction
function confirmTransaction(uint _txIndex) public onlyOwner
txExists(_txIndex)
notExecuted(_txIndex)
notConfirmed(_txIndex){
// update tx struct
Transaction storage transaction = transactions[_txIndex];
// msg.sender has approved tx
transaction.numConfirmations += 1;
isConfirmed[_txIndex][msg.sender] = true;
emit ConfirmTransaction(msg.sender, _txIndex);
}
// if enough owners approve, execute transaction
function executeTransaction(uint _txIndex) public onlyOwner
txExists(_txIndex)
notExecuted(_txIndex) {
Transaction storage transaction = transactions[_txIndex];
// require min number of owners to confirm tx
require(transaction.numConfirmations >= numConfirmationsRequired, "cannot execute tx");
// if enough confirmations >> true
transaction.executed = true;
// execute tx using call method and check call was successful
(bool success, ) = transaction.to.call.value(transaction.value)(transaction.data);
require(success, "tx failed");
// emit execute tx with owner that called this function and the tx that was executed
emit ExecuteTransaction(msg.sender, _txIndex);
}
function revokeConfirmation(uint _txIndex)
public
onlyOwner
txExists(_txIndex)
notExecuted(_txIndex)
{
Transaction storage transaction = transactions[_txIndex];
require(isConfirmed[_txIndex][msg.sender], "tx not confirmed");
transaction.numConfirmations -= 1;
isConfirmed[_txIndex][msg.sender] = false;
emit RevokeConfirmation(msg.sender, _txIndex);
}
function getOwners() public view returns (address[] memory) {
return owners;
}
function getTransactionCount() public view returns (uint) {
return transactions.length;
}
function getTransaction(uint _txIndex)
public
view
returns (address to, uint value, bytes memory data, bool executed, uint numConfirmations)
{
Transaction storage transaction = transactions[_txIndex];
return (
transaction.to,
transaction.value,
transaction.data,
transaction.executed,
transaction.numConfirmations
);
}
}