Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SPDX-License-Identifier: UNLICENSED
- pragma solidity >=0.8.0;
- contract BankAccount {
- mapping(address => uint256) public balances;
- address payable public owner;
- modifier onlyOwner() {
- require(msg.sender == owner, "Only the owner can call this function");
- _;
- }
- constructor() {
- owner = payable(msg.sender);
- }
- function deposit() public payable {
- require(msg.value > 0, "Deposit amount must be greater than 0.");
- balances[msg.sender] += msg.value;
- }
- function withdraw(uint256 amount) public onlyOwner {
- require(amount <= balances[msg.sender], "Insufficient funds.");
- require(amount > 0, "Withdrawal amount must be greater than 0.");
- payable(msg.sender).transfer(amount);
- balances[msg.sender] -= amount;
- }
- function transfer(address payable recipient, uint256 amount) public {
- require(amount <= balances[msg.sender], "Insufficient funds.");
- require(amount > 0, "Transfer amount must be greater than 0.");
- balances[msg.sender] -= amount;
- balances[recipient] += amount;
- }
- function getBalance(address payable user) public view returns (uint256) {
- return balances[user];
- }
- function grantAccess(address payable user) public onlyOwner {
- owner = user;
- }
- function revokeAccess(address payable user) public onlyOwner {
- require(user != owner, "Cannot revoke access for the current owner.");
- owner = payable(msg.sender);
- }
- function destroy() public onlyOwner {
- selfdestruct(owner);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement