~より大きい値を無視した available_primary_key()
code:multi_index_sample.cpp
using namespace eosio;
using namespace std;
class nft: public eosio::contract {
public:
nft( name receiver, name code, datastream<const char*> ds ):
contract::contract( receiver, code, ds ){}
struct token {
uint64_t id;
uint64_t primary_key() const { return id; }
};
typedef eosio::multi_index< name("token"), token > token_index;
uint64_t next_token_id( symbol_code sym ) {
token_index token_table( _self, sym.raw() );
/// 5 を超えない最大の id を持つ token
auto token_data = std::make_reverse_iterator( token_table.lower_bound( 5 ) );
uint64_t next_id = token_data->id + 1;
eosio::check( token_table.find( next_id ) != token_table.end(), "token already exists" );
return next_id;
}
}