-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSmartbank.sol
39 lines (30 loc) · 1.07 KB
/
Smartbank.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
contract SmartBank {
uint totalContractBalance = 0;
function getContractBlance() public view returns(uint){
return totalContractBalance;
}
mapping(address => uint) balances;
mapping(address => uint) depositTimestamps;
function addbalance() public payable{
balances[msg.sender] = msg.value;
totalContractBalance = totalContractBalance + msg.value;
depositTimestamps[msg.sender] = block.timestamp;
}
function getbalance(address userAddress) public view returns(uint){
uint principal = balances[userAddress];
uint timeElapsed = block.timestamp - depositTimestamps[userAddress];
return principal + uint((principal * 7 * timeElapsed)/(100*365*24*60*60)) + 1;
}
function withdraw() public payable{
address payable withdrawto = payable(msg.sender);
uint amountToTransfer = getbalance(msg.sender);
withdrawto.transfer(amountToTransfer);
totalContractBalance = totalContractBalance - amountToTransfer;
balances[msg.sender] = 0;
}
function addMoneytoContract() public payable{
totalContractBalance += msg.value;
}
}