1

Because name is no longer a uint64_t type I created my struct like this:

struct [[eosio::table]] game
{
    uint64_t id; //auto increment
    name host;
    name guest= name("none");
    name player_to_play =name("none");
    name winner = name("none");
    string2dvector game_state;
    string game_name;
    uint64_t primary_key() const { return id; }
    uint64_t by_host() const { return host.value; }
    EOSLIB_SERIALIZE(game, (id)(host)(guest)(player_to_play)(winner)(game_state)(game_name))

};

// table definition
typedef eosio::multi_index<"game"_n, game, 
indexed_by<"host"_n, const_mem_fun<game, uint64_t, &game::by_host>>
> games;

Then I try to get the table indexed by secondary key like this:

auto host_games = existing_games.get_index<"host"_n>();

but when I try to compile I get the following error:

error: no matching member function for call to 'find' auto iterator = host_games.find(host);

/usr/local/eosio.cdt/bin/../include/eosiolib/multi_index.hpp:429:28: note: candidate function not viable: no known conversion from 'const eosio::name' to 'eosio::multi_index<7035924439720001536, tablegame::game, eosio::indexed_by<7868228353667366912, eosio::const_mem_fun > >::index<7868228353667366912, eosio::const_mem_fun, 0, false>::secondary_key_type' (aka 'unsigned long long') for 1st argument const_iterator find( secondary_key_type&& secondary )const {

I tried to change the host type to uint64_t and return host; from by_host() or try auto host_games = existing_games.get_index<"host.value"_n>(); but didn't work.

Any thoughts?

P.S the new CDT is a pain in the ass. I should not have updated :P.

2

You can call name.value to get a uin64_t representation of the name. In your find call, you want to do auto iterator = host_games.find(host.value); to match the uint64_t type that your secondary index is returning.

|improve this answer|||||
  • Thanks for your reply. The problem was in creating the get_index<T>() I managed to solve it thanks to the developers group in telegram once again. – Savvas Vezyridis Oct 23 '18 at 21:17
  • Changing to name.value helped me with the error: no viable conversion from 'eosio::name' to 'uint64_t' (aka 'unsigned long long') – Kristian Nov 28 '18 at 11:57
1

To anyone having the same issues. I managed to fix it like this:

struct [[eosio::table]] game
{
    uint64_t id; //auto increment
    name host;
    name guest= name("none");
    name player_to_play =name("none");
    name winner = name("none");
    string2dvector game_state;
    string game_name;
    uint64_t primary_key() const { return id; }
    uint64_t get_host() const { return host.value; }
    EOSLIB_SERIALIZE(game, (id)(host)(guest)(player_to_play)(winner)(game_state)(game_name))

};
// table definition
typedef eosio::multi_index<"game"_n, game, 
indexed_by<"byhost"_n, const_mem_fun<game, uint64_t, &game::get_host>>
> games;

and

games existing_games(_self, _self.value);
auto host_games = existing_games.get_index<"byhost"_n>();
auto iterator = host_games.find(host.value);

Thanks for your time

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.