I have a table of prices where I want to store 2 prices per cross defined like this:
struct [[eosio::table]] _prices {
symbol base;
symbol quote;
float value = 0.0;
uint128_t primary_key() const {
return base.code().raw() << 64 | quote.code().raw();
}
};
originally the primary key was defined to return base.code().raw() + quote.code().raw()
but that approached produced constraint violations:
could not insert object, most likely a uniqueness constraint was violated
because adding "USD" to "EUR" is (I guess) the same as adding "EUR" to "USD"... so what I need is to use "USDEUR" or "EURUSD" as the primary key
the problem is that since these are represented as integers, I need to shift, and since each of the components is 64bits in width (as per the symbol definition) then the composite must be 128 bit long, which produces a warning when compiling:
./token.hpp:154:30: warning: shift count >= width of type [-Wshift-count-overflow] return base.code().raw() << 64 | quote.code().raw();
and moreover doesn't work. what is the recommended approach to creating composite keys?
addendum I
of course, it would be great to just define the return value as a string (so I could concatenate the strings together), but it demands an integer. I get this error:
/usr/local/Cellar/eosio.cdt/1.5.0/opt/eosio.cdt/bin/../include/libcxx/memory:1759:31: error: no matching constructor for initialization of 'eosio::multi_index<12528034910801231872, eosio::token::_prices>::item_ptr'