history-tools icon indicating copy to clipboard operation
history-tools copied to clipboard

Double Data In Table Not Unpacking Properly

Open baxterjfinch opened this issue 4 years ago • 3 comments

I built out a wasm-ql query service that currently searches the chain for certain actions. Here is one action table in my smart contract that I am currently trying to get working:

 ACTION create(const name& issuer,
                      const name& rev_partner,
                      const name& category,
                       const name& token_name,
                       const bool& fungible,
                       const bool& burnable,
                       const bool& sellable,
                       const bool& transferable,
                       const double& rev_split,
                       const string& base_uri,
                       const uint32_t& max_issue_days,
                       const asset& max_supply);

Everything returns properly except for the double value. Here is what the data looks like on chain:

"data": {
        "issuer": "some.p.234",
        "rev_partner": "some.p.234",
        "category": "c1",
        "token_name": "t1",
        "fungible": 0,
        "burnable": 1,
        "sellable": 1,
        "transferable": 1,
        "rev_split": "0.14999999999999999",
        "base_uri": "some.url.",
        "max_issue_days": 0,
        "max_supply": "1000 COIN"
},

Here is what my wasm-server file is unpacking into currently:

 struct create_action {
    eosio::name                            issuer               = {};
    eosio::name                            rev_partner          = {};
    eosio::name                            category             = {};
    eosio::name                            token_name           = {};
    bool                                   fungible             = {};
    bool                                   burnable             = {};
    bool                                   sellable             = {};
    bool                                   transferable         = {};
    ????                                 rev_split            = {};
    eosio::shared_memory<std::string_view>  base_uri             = {};
    uint32_t                               max_issue_days       = {};
    eosio::asset                           max_supply           = {};
};

And here is what the struct that the unpacked data is being returned to the client in:

struct tx_create_action {
  tx_action_key                          key              = {};
  eosio::name                            issuer           = {};
  eosio::name                            rev_partner      = {};
  eosio::name                            category         = {};
  eosio::name                            token_name       = {};
  bool                                   fungible         = {};
  bool                                   burnable         = {};
  bool                                   sellable         = {};
  bool                                   transferable     = {};
  ????                                     rev_split        = {};
   eosio::shared_memory<std::string_view>  base_uri         = {};
  uint32_t                               max_issue_days   = {};
  eosio::extended_asset                  max_supply       = {};

  EOSLIB_SERIALIZE(tx_create_action, (key)(issuer)(rev_partner)(category)(token_name)(fungible)(burnable)(sellable)(transferable)(rev_split)(base_uri)(max_issue_days)(max_supply))
};

However, I currently am not unpacking or returning the rev_split to the client because it will not unpack properly.

If I uncomment rev_split and try unpacking it as a double which is what the contract table stores it as, I get the following when trying to compile the client cpp file (the server cpp file compiles fine):

./libraries/eosiolib/wasmql/eosio/schema.hpp:60:39: note: candidate function not viable: no known conversion from 'double *' to 'shared_memory<std::string_view> *' (aka 'shared_memory<basic_string_view<char> > *') for 1st argument
__attribute__((noinline)) inline rope make_json_schema(shared_memory<std::string_view>*) { return "\"type\":\"string\""; }

So given that, I try unpacking it into the structs as a eosio::shared_memory<std::string_view>. If this is set, the code compiles properly, however I get the following error if I try to call the query service for that action:

Error: 500: Internal Server Error: query failed: assert failed

There is no additional error logging returned.

baxterjfinch avatar Apr 28 '20 18:04 baxterjfinch

The json schema generator doesn't have support for double. Since a replacement for that schema system is currently being written, the existing one won't be updated.

tbfleming avatar Apr 28 '20 18:04 tbfleming

Awesome, thanks for the quick reply! So for now, it's best to just wait for the new schema to be released?

baxterjfinch avatar Apr 28 '20 18:04 baxterjfinch

yes. The entire approach to schemas, including the way you interface with it, is being redesigned.

tbfleming avatar Apr 28 '20 18:04 tbfleming