Solidity

提取的 ETH 作為內部交易發送到黑洞地址

  • September 28, 2022

我試圖在資助後退出這份契約。資助後,我在 goerli etherscan 上檢查了余額,其中有我發送的 goerliETH,但我注意到一旦我呼叫提款,餘額變為 0,而沒有按預期將其發送到我的錢包地址。

提現交易被記錄但沒有任何價值,但在內部交易中我發現餘額被轉移到了goerli黑洞地址。

我似乎無法找到解決此問題的方法,任何幫助將不勝感激。這是下面的腳本:

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

contract TimeControlled {
   address public owner;
   address[] private ownerArr;
   uint256 dateForWithdrawal;
   address public contractAddress;

   mapping(address => bool) private addressToBool;

   constructor(bool isAllowed) public {
       owner == msg.sender;
       contractAddress == address(this);
       addressToBool[msg.sender] = isAllowed;
       addressToBool[address(this)] = isAllowed;
       ownerArr.push(owner);
       ownerArr.push(contractAddress);
   }

   // fund the contract and return a true value
   function fund() public payable returns (bool) {
   return true;
   }

   // Check if the contract is being called by the owners
   // Require the owner to be the creators address or the contracts address
   modifier owners() {
       require(addressToBool[msg.sender], "You are not allowed!");
       _;
   }

   // withdraw at a certain time
   function withdraw() public payable owners returns (bool) {
       require(address(this).balance > 0);
       payable(owner).transfer(address(this).balance);
       return true; /// @notice for withdrawing from the contract
       /// @dev Withdraw by using the owners modifier and returns a boolean value
   }
}

注意:我從繼承它的另一個合約的建構子中部署了這個合約。這是下面的契約,以備不時之需:

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol";
import "./Timecontrolled.sol";

contract CallWithdraw is ChainlinkClient, TimeControlled {
   using Chainlink for Chainlink.Request;
   address public linkToken;
   uint256 public oraclePayment;
   address public oracle;
   bytes32 public jobId;
   uint256 public fundingPeriod = 5;

   constructor(
       address _linkToken,
       uint256 _oraclepayment,
       address _oracle,
       bytes32 _jobId
   ) public TimeControlled(true) {
       owner == msg.sender;
       oraclePayment = _oraclepayment;
       linkToken = _linkToken;
       oracle = _oracle;
       jobId = _jobId;
   }

   function callWithdraw() external {
       // if owner does not call the withdraw function at the set time
       // the contract calls withdraw on its own
       require(address(this).balance > 0);
       Chainlink.Request memory req = buildChainlinkRequest(
           jobId,
           address(this),
           this.fulfill.selector
       );
       req.addUint("until", block.timestamp + fundingPeriod * 1 minutes);
       withdraw();
       sendChainlinkRequestTo(oracle, req, oraclePayment);
   }

   function fulfill(bytes32 _requestId)
       public
       recordChainlinkFulfillment(_requestId)
   {
       address(this).balance == 0;
   }
}

這也是我的部署腳本

from brownie import CallWithdraw, config
from scripts.helpful_scripts import get_account, network, get_contract
from web3 import Web3


oracle_payment = config["networks"][network.show_active()]["payment"]
oracle = config["networks"][network.show_active()]["oracle"]
job_Id = config["networks"][network.show_active()]["jobId"]


def deploy_call_withdraw_and_time_controlled():
   print(f"The network is {network.show_active()}")
   account = get_account()
   link_token = get_contract("link_token")
   print("Deploying contract...")
   call_withdraw = CallWithdraw.deploy(
       link_token.address,
       oracle_payment,
       oracle,
       job_Id,
       {"from": account},
   )
   """
   print("Transferring linktoken...")
       link_token.transfer(
       call_withdraw.address, Web3.toWei(1, "ether"), {"from": account}
   )
   print("Linktoken transferred successfully!")
   """

   print(account.balance())
   return call_withdraw


def fund():

   call_withdraw = CallWithdraw[-1]
   account = get_account()
   call_withdraw.fund({"value": Web3.toWei(0.03, "ether"), "from": account})
   print(f"{account.balance()} is the current balance")
   call_withdraw.withdraw({"from": account})
   print(f"{account.balance()} is the current balance")


def get_contract_balance():
   call_withdraw = CallWithdraw[-1]
   print(f"{call_withdraw.balance()} is {call_withdraw.address} balance")


def main():
   deploy_call_withdraw_and_time_controlled()
   fund()
   get_contract_balance()

owner == msg.sender;在你的建構子中;)

引用自:https://ethereum.stackexchange.com/questions/136486