0

遵循EOS DOCS 数据持久性会引发错误。人们说“未找到用户定义的文字运算符”时出现错误曲线

typedef eosio::multi_index<"people"_n, person> address_index;

版本

  • eosio 2.0.0
  • eosio.cdt 1.6.3
  • Ubuntu 16.04

在此处查看完整代码

#include <eosio/eosio.hpp>

using namespace eosio;

class [[eosio::contract("addressbook")]] addressbook : public eosio::contract
{

public:
    addressbook(name receiver, name code, datastream<const char *> ds) : contract(receiver, code, ds) {}

    [[eosio::action]] void upsert(
        name user,
        std::string first_name,
        std::string last_name,
        std::string street,
        std::string city,
        std::string state)
    {
        require_auth(user);
        address_index addresses(get_self(), get_first_receiver().value);
        auto iterator = addresses.find(user.value);
        if (iterator == addresses.end())
        {
            addresses.emplace(user, [&](auto &row) {
                row.key = user;
                row.first_name = first_name;
                row.last_name = last_name;
                row.street = street;
                row.city = city;
                row.state = state;
            });
        }
        else
        {
            addresses.modify(iterator, user, [&](auto &row) {
                row.key = user;
                row.first_name = first_name;
                row.last_name = last_name;
                row.street = street;
                row.city = city;
                row.state = state;
            });
        }
    }

    [[eosio::action]] void erase(name user)
    {
        require_auth(user);

        address_index addresses(get_self(), get_first_receiver().value);

        auto iterator = addresses.find(user.value);
        check(iterator != addresses.end(), "Record does not exist");
        addresses.erase(iterator);
    }

private:
    struct [[eosio::table]] person
    {
        name key;
        std::string first_name;
        std::string last_name;
        std::string street;
        std::string city;
        std::string state;
        uint64_t primary_key() const { return key.value; }
    };
    typedef eosio::multi_index<"people"_n, person> address_index;
};
4

1 回答 1

0

这实际上不是一个错误。系统合同中也有“错误”。您的合约仍将正确编译/部署。

您可以采取一些措施来消除“错误”,将您的代码重构为以下内容:

typedef eosio::multi_index<eosio::name("people"), person> address_index;

将 _n 替换为 eosio::name() 并将您的表名放在括号内。

于 2021-03-10T15:46:41.000 回答