EOSIO / eosjs

General purpose library for the EOSIO blockchain.
http://eosio.github.io/eosjs
MIT License
1.43k stars 463 forks source link

lower bound numeric helper #224

Closed robertkowalski closed 6 years ago

robertkowalski commented 6 years ago

Hi James,

I work with lower bounds to read paginated data from a table. My primary keys start with 0.

It turns out that I just receive more results when I pad the integers with 0 to fill up the space for the uint64 buffer. This goes in line with cleos, but its a bit unhandy for development.

cleos:

cleos get table organiccandy shop sweet -l 2 -L 1
{
  "rows": [],
  "more": false
}
cleos get table  organiccandy shop sweet -l 2 -L 00000000000000000001

{
  "rows": [{
      "id": 1,
      "type": "bubblegum"
    },{
      "id": 2,
      "type": "cookie"
    }
  ],
  "more": true
}

In JS I do something along these lines in order to receive a result

const current = 0
const lower_bound = '0000000000000000000' + (current + 1)

Question:

a) I checked the format helpers, I did not found a helper suitable - am I missing something? b) Would you review & merge a PR with a helper? Or would you add one yourself? Or should this happen in userland?

jcalfee commented 6 years ago

What does organiccandy in "tables" look like? I wonder if that needs to be parsed along with any structs to make a helper function ..

Here is a case where the "name" field has to be encoded to a number just for the query to work: https://github.com/EOSIO/eos/issues/3948#issuecomment-395802721

I wonder if this is related to your case only using a different type.

jcalfee commented 6 years ago

I have suggested that a version 2 of the get_table_rows (v2/chain/get_table_rows) provide de-serialization on its parameters.

jcalfee commented 6 years ago

Encode "name" fields (like account name) .. See https://github.com/EOSIO/eosjs/issues/154#issuecomment-394914254

robertkowalski commented 6 years ago

hm, whats the conclusion here @jcalfee ?

jcalfee commented 6 years ago

Maybe getTableRows can accept some options as the last parameter similar to what is done here:

https://github.com/EOSIO/eos/pull/4053

However, it seems like /v2/chain/get_table_rows could do this decoding automatically. I prefer to have this information from the back-end rather than adding extra parameters to the API. Even after adding a feature like this it will still be error prone to use. I really wish I had the field types in the table to work with..

jcalfee commented 6 years ago

Published eosjs@16.0.0 .. This adds two parameters to get_table_rows .. key_type and index_position.