Solidity Ожидаемая неопознанная ошибка в коде смарт-контракта - Remix

Компилятор сообщает об ошибке, указанной ниже; довольно странно, поскольку я слежу за наставником курса, который предложил мне использовать старую версию ремикса, я читал в аналогичных вопросах, что «возвраты» должны быть единичными, но его код компилируется без проблем, я все равно пробовал, не сработало; он использует ^ 0.4.11. Я работаю на ^ 0.8.4, хотя проблема не исчезла после перехода на предыдущую версию.

Ошибка:

ParseError: Expected '{' but
got 'constant' -->
tests/pendulum_ico.sol:28:60: |
28 | function 
equity_in_pendulum(address 
investor) external constant 
returns (uint) { | ^^^^^^^^

Код:

pragma solidity ^0.8.3;

contract pendulum_ico {
    
// Introducing the maximum number of Pendulum available for sale

    uint public max_pendulum = 1000000;
    
// Introducing the USD to Pendulum conversion relocatable

    uint public usd_to_pendulum = 1000;
    
// Introducing the total number of Pendulum that have been bought by the investors

    uint public total_pendulum_bought = 0;
    
// Mapping from the investor address to its equity in Pendulum and usd_to_pendulum

    mapping(address => uint) equity_pendulum;
    mapping(address => uint) equity_usd;
    
// Checking if an investor can buy Pendulum

    modifier can_buy_pendulum(uint usd_invested) {
        require (usd_invested * usd_to_pendulum + total_pendulum_bought <= max_pendulum);
        _;
    }
    
// Getting the equity in Pendulum of an investor

    function equity_in_pendulum(address investor) external constant returns (uint) { 
        return equity_pendulum[investor];
    }                             
    
// Getting the equity in USD of an investor

    function equity_in_usd(address investor) external constant returns (uint) {
        return equity_usd[investor];
    }
    
// Buying Pendulum 

    function buy_pendulum(address investor, uint usd_invested) external
    can_buy_pendulum(usd_invested) {
        uint pendulum_bought = usd_invested * usd_to_pendulum;
        equity_pendulum[investor] += pendulum_bought;
        equity_usd[investor] = equity_pendulum[investor] / 1000;
        total_pendulum_bought += hadcoins_bought;
        
    }
    
// Selling Pendulum 

    function sell_pendulum(address investor, uint pendulum_sold) external {
        equity_pendulum[investor] -= pendulum_sold;
        equity_usd[investor] = equity_pendulum[investor] / 1000;
        total_pendulum_bought -= pendulum_sold;
    }
    
}

person Charlie_83    schedule 09.04.2021    source источник


Ответы (1)


Из списка критических изменений от 0,4 до и 0,5:

Использование constant в качестве модификатора изменчивости состояния функции теперь запрещено.


В версии 0.8 вы также можете объявить функцию как функцию просмотра, который соответствует критериям неизменности состояния, определенным в 0.4 constant.

function equity_in_pendulum(address investor) external view returns (uint) { 
    return equity_pendulum[investor];
}
person Petr Hejda    schedule 09.04.2021
comment
Проблема исправлена ​​Петр, вы не представляете, насколько вы были полезны. - person Charlie_83; 09.04.2021