-
Notifications
You must be signed in to change notification settings - Fork 180
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?
Conversation
transfer ownership feature is added with securities.
src/DepositWithdraw.sol
Outdated
contract DepositWithdraw is Ownable(msg.sender), ReentrancyGuard { | ||
mapping(address => uint256) private _balances; | ||
|
||
event Deposited(address indexed depositor, uint256 amount); |
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.
the event names would be better to relate them to the function they go with, here it would be Deposit
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.
done!!
src/DepositWithdraw.sol
Outdated
mapping(address => uint256) private _balances; | ||
|
||
event Deposited(address indexed depositor, uint256 amount); | ||
event Withdrew(address indexed withdrawer, uint256 amount); |
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.
the event names would be better to relate them to the function they go with, here it would be Withdraw
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.
done!
src/DepositWithdraw.sol
Outdated
function withdraw(uint256 amount) public nonReentrant { | ||
require(amount <= _balances[msg.sender], "Insufficient balance"); | ||
_balances[msg.sender] -= amount; | ||
(bool success, ) = msg.sender.call{value: amount}(""); |
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.
you could use .transfer
here instead of .call
.
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.
payable(msg.sender).transfer(amount);
updated!!
src/DepositWithdraw.sol
Outdated
|
||
contract DepositWithdraw is Ownable(msg.sender), ReentrancyGuard { | ||
mapping(address => uint256) private _balances; | ||
|
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.
add an event that registers the change of ownership:
event OwnershipTransferred(address indexed owner, address indexed newOwner);
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.
added!
src/DepositWithdraw.sol
Outdated
emit Withdrew(msg.sender, amount); | ||
} | ||
|
||
function transferOwnership(address newOwner) public onlyOwner override { |
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.
emit here the OwnershipTransferred
event
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.
done!
src/DepositWithdraw.sol
Outdated
emit Withdrew(msg.sender, amount); | ||
} | ||
|
||
function transferOwnership(address newOwner) public onlyOwner override { |
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.
add more validations here so that it does not check that the new owner is not address(0) either the address of a contract.
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.
require(newOwner == address(0),"invalid address");
validation added!
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.
you can add another validation so that the input address is not a contract address
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.
done!!
check it!
src/DepositWithdraw.sol
Outdated
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.
rename the contract with TransferOwnership
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.
contract renamed!
src/DepositWithdraw.sol
Outdated
pragma solidity ^0.8.24; | ||
|
||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; |
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.
the route is not correct, check this ReentrancyGuard
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.
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
done!
used .transfer instead of .call for security purpose.
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
use capitalize, replace ownershipTransferred
to OwnershipTransferred
and change it on the other sites
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.
I get this error while capitalising it
DeclarationError: Event with same name and parameter types defined twice.
@openzeppelin/contracts/access/Ownable.sol
So I thought it's better to have ownershipTransferred!!
if you have anyother idea then kindly share it to me!!
src/TransferOwnership.sol
Outdated
|
||
function transferOwnership(address newOwner) public onlyOwner override { | ||
require(newOwner == address(0),"invalid address"); | ||
super.transferOwnership(newOwner); |
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.
why the choice to use super?
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.
calling the transferOwnership
function from the Ownable
contract to actually transfer the ownership to the new owner!
hey @SIDHARTH20K4 I have made some other corrections and I think there were some things missing, you can reply to each comment with |
adding more validations
transfer ownership feature is added with securities.