// SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 <0.9.0; // The goal here is to create a multi-sig wallet safe // Eventually the deployer will have to decide how many sigs are needed for the tranx to be approved // The deployer will also be able to add/remove the allowed addresses // BEFORE we get to that, let's create a SIMPLE wallet safe // We'll expand upon its functionalities to make it a multi-sig safe bit by bit // Create a cotract called Safe that: (This is how to make a wallet) // 1 - Keeps track of users balance (balances mapping) // 2 - Shows how many users have funds in the Safe // 3 - Each user is represented by a Struct with at least: address, balance, unique ID // 4 - A user can deposit, withdraw and tranfer funds to other users // 5 - Create a modifier called "hasFunds" instead of require statements // 6- Create events for each functions // NB - no need to create a new token: we'll use ETH // Use OpenZeppelin's SafeMath for uint operations contract Safe { mapping(address => uint256) public balances; //balances[msg.sender] (how to call mapping) struct User{ address userAddress; uint256 userBalance; uint256 userID; } User[] public users; // functions for withdraw, transfer and deposit go below here //function withdrawFunds() external { //require(msg.sender = User); // msg.sender.transfer(address(uint256)); //} modifier hasFunds() { require(balances[msg.sender] >= msg.value, "Error! Insufficient Funds"); _; } event transactionLogs(address sender, string message); // function withdrawFunds() public payable { //checks, effects, interactions // require(balances[msg.sender] >= msg.value, "Error! Insufficient Funds"); // balances[msg.sender] -= msg.value; // payable(msg.sender).transfer(msg.value); function withdrawFunds() public payable hasFunds { //my updated code payable(msg.sender).transfer(msg.value); emit transactionLogs(msg.sender, "Withdraw"); } // function transferFunds(address _to) public payable returns (bool) { // require(balances[msg.sender] >= msg.value, "Error! Insufficient Funds"); // balances[msg.sender] -= msg.value; // balances[_to] += msg.value; // payable(_to).transfer(msg.value); // return true; function transferFunds(address _to) public payable hasFunds returns (bool) { //my udpated code balances[msg.sender] -= msg.value; balances[_to] += msg.value; payable(_to).transfer(msg.value); emit transactionLogs(msg.sender, "Transfer"); return true; } function depositFunds() public payable returns (bool) { balances[msg.sender] += msg.value; emit transactionLogs(msg.sender, "Deposit"); return true; } }
0.4.18