遵循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;
};