0

I've got a multi-index table going with two secondary indices:

TABLE entry {
   uint64_t                id = 0;
   eosio::name             player;
   std::vector<uint16_t>   allocation;
   uint64_t                starttime;
   uint64_t                betroundid;
   double                  talliedpoints;
   bool                    funded;

   uint64_t primary_key() const { return id; }
   uint64_t by_secondary() const { return betroundid; }
   uint64_t by_tertiary() const { return player.value; }

   EOSLIB_SERIALIZE( entry, (id)(player)(allocation)(starttime)(betroundid)(talliedpoints)(funded) )
};


typedef eosio::multi_index<eosio::name("entry"), entry,
  eosio::indexed_by<eosio::name("betroundid"),
    eosio::const_mem_fun<entry, uint64_t, &entry::by_secondary>
  >,
  eosio::indexed_by<eosio::name("playerval"),
    eosio::const_mem_fun<entry, uint64_t, &entry::by_tertiary>
  >
> entry_index;


entry_index entries;

Creating, modifying, and getting entries as usual with entries.find(id) works fine. But when I try to pull the playerval index and find an eosio::name.value in it, I get an iterator in end state:

auto get_unfunded_entry_by_player( const name player_to_get, 
                                   const asset &funding )
{
   auto entries_idx = entries.get_index<name("playerval")>();
   auto entry_itr = entries_idx.find( player_to_get.value );

   eosio_assert( entry_itr != entries_idx.end(), "No entries found for this player!" );

   while ( entry_itr->funded == true || 
           entry_itr->totalbet != funding.amount )
   {
      eosio_assert( ++entry_itr != entries_idx.end(), "No matching unfunded entries found!" );
   }
   return get_entry( entry_itr->id );
}

"No entries found for this player!" is always thrown, even though by using eosio::print and cleos get table, I've verified that the player_to_get is the same name as the player in the table.

Does anything seem to be amiss? Appreciate any help in advance, been fighting with this for hours now:)

0

The problem here was the scope of the table in the contract constructor. The changes required to get the constructor up to speed with October's CDT updates hadn't been correctly completed, and so some things worked and others didn't. Once that was fixed, everything worked:

acontractname( name receiver, name code, datastream <const char *> ds ):
            contract( receiver, code, ds ),
            entries ( receiver, receiver.value )
            {}

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.