Untitled
unknown
plain_text
2 years ago
2.1 kB
4
Indexable
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract DepositContract { address public owner; mapping(address => uint256) public balances; event Deposit(address indexed account, uint256 amount); event ContractDestroyed(address indexed contractAddress); constructor() { owner = msg.sender; } modifier onlyOwner() { require(msg.sender == owner, "Only the owner can call this function"); _; } function deposit() external payable { require(msg.value > 0, "You must send some ether to deposit."); balances[msg.sender] += msg.value; emit Deposit(msg.sender, msg.value); } function selfDestructContract() external onlyOwner { emit ContractDestroyed(address(this)); selfdestruct(payable(owner)); } function getContractBalance() external view returns (uint256) { return address(this).balance; } } contract ReceiverContract { DepositContract public depositContract; address public owner; event FundsReceived(uint256 amount); event receiveTriggered(address, uint256); constructor() { depositContract = new DepositContract(); // Deploy DepositContract owner = msg.sender; } modifier onlyOwner() { require(msg.sender == owner, "Only the owner can call this function"); _; } function receiveFundsFrom() external onlyOwner { depositContract.selfDestructContract(); // The contract has been self-destructed, and the funds are transferred to this contract. // Now, the funds are available in this contract. emit FundsReceived(address(this).balance); } function withdrawFunds() external onlyOwner { uint256 amount = address(this).balance; (bool success, ) = owner.call{value: amount}(""); require(success, "Withdrawal failed"); } function recieve() external payable { emit receiveTriggered(msg.sender, msg.value); } }
Editor is loading...