Solidity

新手學習 Solidity - 解析器錯誤

  • March 8, 2022

嘗試編譯時出現此錯誤

Airlines.sol:49:5: ParserError: Expected ‘{’ but got ‘illegal’ ➥ public{

這是程式碼:

pragma solidity ^0.6.0;    
//SPDX-License-Identifier: UNLICENSED for non-open-source code.  Please see https://spdx.org for more information
   contract Airlines  {
   address chairperson;
   struct details{
       uint escrow; // deposit for payment settlement
       uint status;
       uint hashOfDetails;
   }
   
   mapping (address=>details) public balanceDetails;
   mapping (address=>uint) membership;
   
   // modifiers or rules
   modifier onlyChairperson{
       require(msg.sender==chairperson);
       _;
   }
   modifier onlyMember{
       require(membership[msg.sender]==1);
       _;
   }
   
   // constructor function
   constructor () public payable  {
     
       chairperson=msg.sender;
       membership[msg.sender]=1; // automatically registered
       balanceDetails[msg.sender].escrow = msg.value;
   }
   
   function register ( ) public payable{
       
       address AirlineA = msg.sender;
       membership[AirlineA]=1;
       balanceDetails[msg.sender].escrow = msg.value;
   }
       
  function unregister (address payable AirlineZ) onlyChairperson public {
       if(chairperson!=msg.sender){
           revert(); }
       membership[AirlineZ]=0;
       // return escrow to leaving airline: verify other conditions 
       AirlineZ.transfer(balanceDetails[AirlineZ].escrow);
       balanceDetails[AirlineZ].escrow = 0; 
   }
   
   function request(address toAirline, uint hashOfDetails) onlyMember
   ➥ public{
       if(membership[toAirline]!=1){
           revert(); }
       balanceDetails[msg.sender].status=0;
       balanceDetails[msg.sender].hashOfDetails = hashOfDetails;
   }
   
   function  response(address fromAirline, uint hashOfDetails, uint done) 
                              onlyMember public{
     
       if(membership[fromAirline]!=1){
           revert();  }
       balanceDetails[msg.sender].status=done;
       balanceDetails[fromAirline].hashOfDetails = hashOfDetails;
   }
   
   
function settlePayment  (address payable toAirline) onlyMember payable     
                                      public{
       address fromAirline=msg.sender;
       uint amt = msg.value; 
       balanceDetails[toAirline].escrow = balanceDetails[toAirline].escrow 
                                                  + amt;
       balanceDetails[fromAirline].escrow =      
               balanceDetails[fromAirline].escrow - amt;
      
      // amt subtracted from msg.sender and given to toAirline
       toAirline.transfer(amt

嘗試在一行中設置方法的簽名。在您的程式碼中,使用以下方法更改您的request()功能:

function request(address toAirline, uint hashOfDetails) onlyMember public{
       if(membership[toAirline]!=1){
           revert(); }
       balanceDetails[msg.sender].status=0;
       balanceDetails[msg.sender].hashOfDetails = hashOfDetails;
}

如果您從程式碼中刪除,該問題將得到解決。

無論如何,我建議您閱讀Solidity 編碼的樣式指南。它可能會讓您在未來更容易發現問題,使程式碼更具可讀性和可維護性。

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