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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/TransferOwnership.sol

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)

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

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

Choose a reason for hiding this comment

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

My new sol I wallet 8xC2rjDsFQvEeUxps8aZA7YWXk2HabS64JPxPhAwUGBA

Choose a reason for hiding this comment

The 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];
}
}