Remix

如何在混音中呼叫備份函式

  • September 9, 2021

我在混音中有以下程式碼。我記得混音有“備份”按鈕來檢查備份方法。很久以後我回來了。我沒有找到“備份”按鈕。我想知道如何使用 Remix 呼叫和測試回退方法。

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.6.0 <0.9.0;


contract FuncConcert {
uint constant price = .1 ether;
address public owner;
uint public tickets;
mapping (address => uint ) public purchasers;

constructor (uint t) public payable {
   owner = msg.sender;
   tickets = t;
}

event Received(address sender, uint value);   // declaring event

receive() external payable {
   emit Received(msg.sender, msg.value);
}

// ------------------- FallBack Function --------------------------
fallback () external payable    {
   buyTickets(1);
}
// ------------------- FallBack Function -------------------------- 

function buyTickets(uint reqTkts) public payable {  
   
   require (msg.value == (reqTkts * price) && reqTkts <= tickets);
   
   purchasers[msg.sender] += reqTkts;
   tickets-= reqTkts;
   if (tickets ==0 ) {
       require(msg.sender == owner);
       selfdestruct(payable(msg.sender));
   }
}

function buyTickets(uint reqTkts,uint freeTickets) public payable { 
   require (msg.value == (reqTkts * price) && (reqTkts+freeTickets) <= tickets);
   
   purchasers[msg.sender] += (freeTickets+reqTkts);
   tickets-= (freeTickets+reqTkts);
   
   if (tickets ==0 ) {
       require(msg.sender == owner);
       selfdestruct(payable(msg.sender));
   }
}

function website() public pure returns (string memory){ 
   return "www.FuncConcert.com"; 
}


// this is how we add a modifier to the function 
// there can be zero of more number of modifiers
function kill() public onlyCreator {  
   selfdestruct(payable(msg.sender));
}

modifier onlyCreator() {
   // if a condition is not met then throw an exception 
    require (msg.sender == owner); 
   // or else just continue executing the function
   _;
}
  

}

當我部署契約時,我把它放在左側。它稱為“低級互動”,取決於呼叫接收器或回退函式的輸入。我的契約沒有它們,因此我得到了紅色提示。正如我所說,由於該功能的氣體限制,您的備份功能將無法工作,您需要找到另一種方法來做到這一點。

點擊 Transact without Data 將呼叫接收函式,如果您提供任何或虛擬數據(例如“0x001122”),它將呼叫回退函式

在此處輸入圖像描述

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