Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

SIDHARTH20K4
Copy link

transfer ownership feature is added with securities.

transfer ownership feature is added with securities.
contract DepositWithdraw is Ownable(msg.sender), ReentrancyGuard {
mapping(address => uint256) private _balances;

event Deposited(address indexed depositor, uint256 amount);

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!!

mapping(address => uint256) private _balances;

event Deposited(address indexed depositor, uint256 amount);
event Withdrew(address indexed withdrawer, uint256 amount);

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

function withdraw(uint256 amount) public nonReentrant {
require(amount <= _balances[msg.sender], "Insufficient balance");
_balances[msg.sender] -= amount;
(bool success, ) = msg.sender.call{value: amount}("");

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.

Copy link
Author

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!!


contract DepositWithdraw is Ownable(msg.sender), ReentrancyGuard {
mapping(address => uint256) private _balances;

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);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added!

emit Withdrew(msg.sender, amount);
}

function transferOwnership(address newOwner) public onlyOwner override {

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

emit Withdrew(msg.sender, amount);
}

function transferOwnership(address newOwner) public onlyOwner override {

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.

Copy link
Author

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!

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!!
check it!

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contract renamed!

pragma solidity ^0.8.24;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";

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

Copy link
Author

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);

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

Copy link
Author

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!!


function transferOwnership(address newOwner) public onlyOwner override {
require(newOwner == address(0),"invalid address");
super.transferOwnership(newOwner);
Copy link

@luislucena16 luislucena16 Mar 1, 2024

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?

Copy link
Author

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!

@luislucena16
Copy link

hey @SIDHARTH20K4 I have made some other corrections and I think there were some things missing, you can reply to each comment with done when you have made the corrections and if you like you can leave a link in each comment to the specific commit, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants