Advertisement
amu2002

BankBCT

Nov 20th, 2023
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. // SPDX-License-Identifier: UNLICENSED
  2. pragma solidity >=0.8.0;
  3.  
  4. contract BankAccount {
  5. mapping(address => uint256) public balances;
  6. address payable public owner;
  7.  
  8. modifier onlyOwner() {
  9. require(msg.sender == owner, "Only the owner can call this function");
  10. _;
  11. }
  12.  
  13. constructor() {
  14. owner = payable(msg.sender);
  15. }
  16.  
  17. function deposit() public payable {
  18. require(msg.value > 0, "Deposit amount must be greater than 0.");
  19. balances[msg.sender] += msg.value;
  20. }
  21.  
  22. function withdraw(uint256 amount) public onlyOwner {
  23. require(amount <= balances[msg.sender], "Insufficient funds.");
  24. require(amount > 0, "Withdrawal amount must be greater than 0.");
  25. payable(msg.sender).transfer(amount);
  26. balances[msg.sender] -= amount;
  27. }
  28.  
  29. function transfer(address payable recipient, uint256 amount) public {
  30. require(amount <= balances[msg.sender], "Insufficient funds.");
  31. require(amount > 0, "Transfer amount must be greater than 0.");
  32. balances[msg.sender] -= amount;
  33. balances[recipient] += amount;
  34. }
  35.  
  36. function getBalance(address payable user) public view returns (uint256) {
  37. return balances[user];
  38. }
  39.  
  40. function grantAccess(address payable user) public onlyOwner {
  41. owner = user;
  42. }
  43.  
  44. function revokeAccess(address payable user) public onlyOwner {
  45. require(user != owner, "Cannot revoke access for the current owner.");
  46. owner = payable(msg.sender);
  47. }
  48.  
  49. function destroy() public onlyOwner {
  50. selfdestruct(owner);
  51. }
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement