1, 注意使用eosio.cdt 1.3及以上版本工具, c11语法
定义table, "bankerlist" 是表名, 生成abi文件使用
struct [[eosio::table("bankerlist")]] bankerlist {
uint64_t issue;
uint64_t roomid;
uint64_t stop;
uint64_t gameover;
uint64_t total_amount;
mutable std::vector<betinfo> betinfoList;
uint64_t primary_key() const { return issue; }
EOSLIB_SERIALIZE(bankerlist, (issue)(roomid)(stop)(gameover)(total_amount)(betinfoList));
};
typedef eosio::multi_index<"bankerlist"_n, bankerlist> BANKER_LIST;
定义action
[[eosio::action]]
void gamestart() {
BANKER_LIST banker_list(_self, _self.value);
auto it = banker_list.find(1);
eosio_assert(it->gameover != 1, "status err");
banker_list.modify(it, _self, [&](auto &formerInfo) {
formerInfo.gameover = 1;
});
}
使用table
BANKER_LIST banker_list(_self, _self.value);
auto b_it = banker_list.find(1);
入口宏
取消了, EOSIO_ABI 采用EOSIO_DISPATCH_HELPER代替
extern "C" {
void apply(uint64_t receiver, uint64_t code, uint64_t action) {
auto self = receiver;
if(code == self || code == "eosio.token"_n.value) {
if(action == "transfer"_n.value){
eosio_assert(code == "eosio.token"_n.value, "Must transfer EOS");
}
switch(action) {
EOSIO_DISPATCH_HELPER(xxxxclassname, (transfer)(stopgame)(gamestart)(clear)(resolvebet))
}
}
}
}
重要的类型名变化,
account_name => name
N(x) => _n
N(x) 可以引入 <eosiolib/name.hpp>, #define N(X) name(#X), 以减少代码更改
S(EOS,4) => symbol(symbol_code("EOS"), 4)
更多更新相关资料
智能合约之 eosio.cdt 我们需要知道的那些事 非常值得一看
https://blog.csdn.net/bnbjin/article/details/84027200 eosio.cdt心得
https://developers.eos.io/eosio-home/docs/ 官方案例, 合约编写案例, api文档