Confirm Transaction (Solution)
Solution
git checkout exercise-03-solution
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");
_;
}
function confirmTransaction(uint _txIndex)
public
onlyOwner
txExists(_txIndex)
notExecuted(_txIndex)
notConfirmed(_txIndex)
{
Transaction storage transaction = transactions[_txIndex];
transaction.isConfirmed[msg.sender] = true;
transaction.numConfirmations += 1;
emit ConfirmTransaction(msg.sender, _txIndex);
}