-
Notifications
You must be signed in to change notification settings - Fork 0
/
thrift.sol
41 lines (31 loc) · 1.21 KB
/
thrift.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
39
40
41
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
contract SimpleThriftContract {
address public owner;
mapping(address => uint256) public balances;
event Deposit(address indexed depositor, uint256 amount);
event Withdrawal(address indexed withdrawer, uint256 amount);
constructor() {
owner = msg.sender;
}
function deposit() public payable {
require(msg.value > 0, "Deposit amount must be greater than 0");
balances[msg.sender] += msg.value;
emit Deposit(msg.sender, msg.value);
}
function withdraw(uint256 amount) public {
require(amount > 0, "Withdrawal amount must be greater than 0");
require(balances[msg.sender] >= amount, "Insufficient balance");
balances[msg.sender] -= amount;
payable(msg.sender).transfer(amount);
emit Withdrawal(msg.sender, amount);
}
// View function to check the balance of a specific address
function getBalance(address account) public view returns (uint256) {
return balances[account];
}
// View function to check the contract's total balance
function getContractBalance() public view returns (uint256) {
return address(this).balance;
}
}