Проблемы со смарт-контрактами EOS

Я практикуюсь в написании смарт-контрактов в EOS, и я пытаюсь создать свою версию крестиков-ноликов, которая была на портале разработчика EOS в качестве примера.

Однако по какой-то причине, когда я пытаюсь сгенерировать файл .wast, я получаю сообщение об ошибке: «test.cpp: 173: 1: error: конструктор, унаследованный от 'test' от 'contract' базового класса, неявно удаляется».

До того, как эта проблема возникла, мне отказали в создании файла abi, потому что у меня не было рикардианских контрактов. Однако в примере с крестиками-ноликами на портале разработчиков EOS их тоже не было ....

(весь код - это файл .cpp)

#include <eosiolib/eosio.hpp>
#include <stdint.h>

using namespace eosio;

class test : public eosio::contract{

public:
using contract::contract;

test(account_name challenger_id, account_name host_id) :
        contract(challenger_id), games_table(_self, _self) { }

bool board_is_full(uint32_t const board[9]) {
    for (int a = 0; a <= 8; a++) {
        if (board[a] != 0)
            continue;
        else
            return false;
    }
    return true;
}

bool is_valid_move(uint8_t loc, uint32_t const board[9]) {
    if (board[loc] == 0)
        return true;
    else
        return false;
}

bool three_in_a_row(uint32_t const board[9], int num) {
    for (int a = 0; a <= 2; a++) {
        for (int b = 0; b <= 6; b += 3) {
            if (board[a + b] == num) {
                if (b == 6) {
                    return true;
                }
                continue;
            }
            break;
        }
    }

    for (int a = 0; a <= 2; a+=2) {
        if(a==0) {
            for (int b = 0; b <= 8; b += 4) {
                if (board[a + b] == num) {
                    if (b == 8) {
                        return true;
                    }
                    continue;
                }
                else {
                    break;
                }
            }
        }
        else{
            for(int b = 0; b<=4; b++) {
                if (board[a + b] == num) {
                    if (b == 4) {
                        return true;
                    }
                    continue;
                }
                else {
                    break;
                }
            }
        }
    }
    return false;
}

int winner_scanner(uint32_t const board[9]) {
    if (three_in_a_row(board, 1)) {
        return 1;
    }
    if (three_in_a_row(board, 2)) {
        return 2;
    }
    return 0;
}

///@abi action
void create(account_name challenger, account_name host) {
    auto itr = games_table.find(challenger);
    eosio_assert(static_cast<uint32_t>(itr != games_table.end()), "game already exists");

    games_table.emplace(challenger, [&](auto& g) {
        g.challenger = challenger;
        g.host = host;
        g.turn = host;
    });
}

///@abi action
void place(account_name challenger, account_name turn, int loc){
    auto itr = games_table.find(challenger);
    require_auth(turn);
    require_auth(itr->challenger);

    eosio_assert(games_table.end() == itr, "game does not exist");
    eosio_assert(itr->turn == turn, "not this player's turn");
    eosio_assert(!board_is_full(itr->board), "board is full");
    eosio_assert(is_valid_move(loc, itr->board), "invalid move");

    games_table.modify(itr, challenger, [&](auto& g){
        if(challenger == turn){
            g.turn = g.host;
            g.board[loc] = 2;
        }
        else{
            g.turn = g.challenger;
            g.board[loc] = 1;
        }
    });

    int winner = winner_scanner(itr->board);

    if (winner != 0) {
        if (winner == 2) {
            eosio_assert(true, "Challenger wins!");
        }
        if (winner == 1) {
            eosio_assert(true, "Host wins!");
        }
    }
}

///@abi action
void restart(account_name challenger){
    auto itr = games_table.find(challenger);
    eosio_assert(itr!=games_table.end(), "game doesn't exist");

    games_table.modify(itr, challenger, [&](auto& g){
        for(int a= 0; a<=8; a++){
            g.board[a] = 0;
        }
    });
}

///@abi action
void forfeit(account_name challenger, account_name forfeiter){
    auto itr = games_table.find(challenger);
    eosio_assert(itr==games_table.end(), "game does not exist");

    games_table.erase(itr);
}

private:
///@abi table
struct game{
    account_name challenger;
    account_name host;
    account_name turn;

    uint32_t board[9];

    account_name primary_key() const {return challenger;}

    EOSLIB_SERIALIZE(game, (challenger)(host)(turn))
};

multi_index<N(games_table), game> games_table;
};

EOSIO_ABI(test, (create)(place)(restart)(forfeit))

person Ethan Shin    schedule 28.06.2018    source источник


Ответы (1)


Прежде всего, чтобы сгенерировать abi, вам нужен рикардианский контракт. Если вы хотите просто выполнить tic_tac_toe, просто возьмите рикардианский контракт из примера hello и измените его имя.

Для другой ошибки, возможно, вам нужно удалить

using contract::contract;
person Nikos Chatzivasileiadis    schedule 13.07.2018