4

I'm following this explanation https://developers.eos.io/eosio-cpp/v1.1.0/docs/multi-index-table-tutorial using v1.5.0 of the CDT. Here's what I've got:

struct [[eosio::table]] order_struct {
    name cust;
    asset qty;
    uint32_t ts; 
    uint64_t primary_key() const {
        return ts; 
     }   
     uint64_t matches() const {
        return qty.symbol.code().raw();
     }
};  

typedef eosio::multi_index<
    name("orderbook"), 
    order_struct, 
    indexed_by<
        name("idxmatches"), 
        const_mem_fun<
            order_struct, uint64_t, &order_struct::matches
        >   
     >   
> orderbook;

after which I proceed to use the index as prescribed:

orderbook b(_self, _self.value);
auto m = b.get_index<name("idxmatches")>();

for (auto &o : m) {
    print(o.cust, " ", o.qty, " ", o.ts, "\n");
}

but this is what I get:

[(t,exchange)->t]: CONSOLE OUTPUT BEGIN ===================== 
alice 5.00000 NAVC 1549087727
bob 1.00000000 NAVG 1549088004
bob 1.00000000 NAVG 1549088036
alice 3.00000 NAVC 1549087912 
bob 7.00000000 NAVG 1549088304
alice 1.00000 NAVC 1549105457
[(t,exchange)->t]: CONSOLE OUTPUT END   =====================

which is clearly not sorted. what am I missing?

p.s. the link includes a call to the EOSLIB_SERIALIZE macro. I've tested behaviour with it but it doesn't help

p.p.s. another approach, which I picked up from [https://forum.toshitimes.com/t/advanced-eos-003-table-secondary-indexes/6329] also failed:

auto iter = m.lower_bound(NAVC.code().raw());
while (iter != m.end()) {
    print(iter->cust, " ", iter->qty, " ", iter->ts, "\n");
    iter++;
}
  • Feel free to hit up the EOS Dev telegram if you don't get a response: t.me/joinchat/Esi1OkPktgcFeJ3Lmlcrqg – Nat Feb 2 '19 at 15:53
  • thanks. I'm in there. it's a good channel. I like to ask questions on the channel by writing here and then posting a link – ekkis Feb 2 '19 at 19:18
0

I figured it out. the code works as expected but I had to refresh (completely destroy and rebuild) my network. it's something about EOS getting confused when the table definition changes

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.