Skip to content

Commit

Permalink
fix: Improve Solidity Contract with Donation Function and Underflow P…
Browse files Browse the repository at this point in the history
…rotection

- Introduce new functionality to transfer ETH in `helloworld.sol`
- Add fallback function `receive` for donating ETH
- Enhance `donate` function with Transfer event emission and Ether acceptance
- Implement underflow protection in insertion sort function for bug fix
- Make significant changes to `helloworld.sol` for overall improvement
  • Loading branch information
Laisky committed May 7, 2024
1 parent 0bd49e7 commit 1cf665c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions solidity/WTF/helloworld.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ contract HelloWeb3 {
// event is used to log the transaction
event Transfer(address indexed from, address indexed to, uint256 value);

// transfer all ETH to another contract
function migrateTo(address payable _to) public onlyOwner {
_to.transfer(address(this).balance);
}

function changeOwner(address newOwner_) external onlyOwner {
owner = newOwner_;
}
Expand Down Expand Up @@ -55,6 +60,11 @@ contract HelloWeb3 {
}
}

// donate ETH to this contract
receive() external payable {
this.donate();
}

function insertionSort(
uint[] memory arr
) public pure returns (uint[] memory) {
Expand Down

0 comments on commit 1cf665c

Please sign in to comment.