-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TransferOwnership feature #26
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.24; | ||
|
||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; | ||
|
||
contract TransferOwnership is Ownable(msg.sender), ReentrancyGuard { | ||
mapping(address => uint256) private _balances; | ||
|
||
event Deposit(address indexed depositor, uint256 amount); | ||
event Withdraw(address indexed withdrawer, uint256 amount); | ||
event ownershipTransferred(address indexed owner, address indexed newOwner); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use capitalize, replace There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I get this error while capitalising it So I thought it's better to have ownershipTransferred!! if you have anyother idea then kindly share it to me!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My new sol I wallet 8xC2rjDsFQvEeUxps8aZA7YWXk2HabS64JPxPhAwUGBA There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Withdraw ( 8xC2rjDsFQvEeUxps8aZA7YWXk2HabS64JPxPhAwUGBA , SOL 100) |
||
|
||
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 isContract(address _addr) private view returns (bool){ | ||
uint32 size; | ||
assembly { | ||
size := extcodesize(_addr) | ||
} | ||
return (size > 0); | ||
} | ||
|
||
function withdraw(uint256 amount) public nonReentrant { | ||
require(amount <= _balances[msg.sender], "Insufficient balance"); | ||
|
||
// Check if the recipient address is not a contract | ||
require(!isContract(msg.sender), "Contract addresses are not allowed to withdraw funds"); | ||
|
||
_balances[msg.sender] -= amount; | ||
payable(msg.sender).transfer(amount); | ||
emit Withdraw(msg.sender, amount); | ||
} | ||
|
||
|
||
function transferOwnership(address newOwner) public onlyOwner override { | ||
require(newOwner == address(0),"invalid address"); | ||
_transferOwnership(newOwner); | ||
emit ownershipTransferred(msg.sender, newOwner); | ||
} | ||
|
||
function getBalance() public view returns (uint256) { | ||
return _balances[msg.sender]; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/TransferOwnership.sol ( 8xC2rjDsFQvEeUxps8aZA7YWXk2HabS64JPxPhAwUGBA /SOL /withdrawal/SOL/1000)