Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. struct [[eosio::table]] _prices {
  2. symbol base;
  3. symbol quote;
  4. float value = 0.0;
  5. uint64_t primary_key() const {
  6. return base.code().raw();
  7. }
  8. uint128_t uniquekey() const {
  9. return ((uint128_t) base.code().raw()) << 64 | quote.code().raw();
  10. }
  11. };
  12.  
  13. typedef eosio::multi_index<name("prices"), _prices,
  14. indexed_by<
  15. name("uniquekey"),
  16. const_mem_fun<
  17. _prices, uint128_t, &_prices::uniquekey
  18. >
  19. >
  20. > prices;
  21.  
  22. symbol base("TTF", 2), quote("USD", 2);
  23. float val = 1.0;
  24. prices p(_self, _self.value);
  25. auto m = p.get_index<name("uniquekey")>();
  26. auto o = m.find((((uint128_t) base.code().raw()) << 64) | quote.code().raw());
  27. if (o == m.end())
  28. p.emplace(_self, [&](auto &r) {
  29. r.base = base;
  30. r.quote = quote;
  31. r.value = val;
  32. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement