56 lines
1.5 KiB
Solidity
56 lines
1.5 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
pragma solidity >=0.4.22 <0.9.0;
|
|
|
|
|
|
import "./Owner.sol";
|
|
|
|
contract Wallet is Owner{
|
|
|
|
event received(uint _newAmount);
|
|
|
|
event sended(uint _amount);
|
|
|
|
struct Payment{
|
|
uint amount;
|
|
uint timeStamp;
|
|
}
|
|
|
|
struct Balance{
|
|
uint totalBalance;
|
|
uint numPayment;
|
|
mapping(uint => Payment) payments;
|
|
}
|
|
|
|
mapping(address => Balance) wallet;
|
|
|
|
function getBalances() public isOwner() view returns(uint){
|
|
return address(this).balance;
|
|
}
|
|
|
|
function getBalance() public view returns(uint){
|
|
return wallet[msg.sender].totalBalance;
|
|
}
|
|
|
|
function withdrawAllMoney(address payable _to) public{
|
|
uint amount = wallet[msg.sender].totalBalance;
|
|
wallet[msg.sender].totalBalance = 0;
|
|
_to.transfer(amount);
|
|
}
|
|
|
|
function withdrawMoney(address payable _to, uint val) public{
|
|
uint thisBalance = wallet[msg.sender].totalBalance;
|
|
require(thisBalance >= val,"not enough balance");
|
|
//envoyer a l'addr _to
|
|
wallet[msg.sender].totalBalance -= val;
|
|
_to.transfer(val);
|
|
emit sended(val);
|
|
}
|
|
|
|
receive() payable external{
|
|
Payment memory thisPayment = Payment(msg.value, block.timestamp);
|
|
wallet[msg.sender].totalBalance += msg.value;
|
|
wallet[msg.sender].payments[wallet[msg.sender].numPayment] = thisPayment;
|
|
wallet[msg.sender].numPayment++;
|
|
emit received(wallet[msg.sender].totalBalance);
|
|
}
|
|
} |