-
Notifications
You must be signed in to change notification settings - Fork 3.7k
5380 support iteration over scopes & tables in cleos #5486
Conversation
uint32_t count; | ||
}; | ||
struct get_table_by_scope_result { | ||
vector<fc::variant> rows; ///< one row per item, either encoded as hex String or JSON object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this a variant? Also the comment seems wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix this accordingly.
("lower_bound",lower) | ||
("upper_bound",upper) | ||
("limit",limit) | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to have some tests for this and the other get table functionality. Not required for this PR, but something to do when you have some time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree. let me make some tests for "get table" related functionality.
New features should target develop branch not release/1.2.x branch |
}; | ||
struct get_table_by_scope_result { | ||
vector<get_table_by_scope_result_row> rows; | ||
bool more = false; ///< true if last element in data is not the end and sizeof data() < limit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to move away from true/false for more. Instead fill it with the next value to pass to lower bound if there is more. See, for example, get_producers or get_scheduled_transactions. Would be nice to also make that change for get table row as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not {next : "nextitem", more: 12345} or is there an other way to get the length of a table? I got referenced to this issue from here #5543
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kasperfish there's no way to know the remaining number unless you iterate all of them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BUG issue
decltype(idx.upper_bound(boost::make_tuple(0, 0, 0))) upper; | ||
|
||
if (p.lower_bound.size()) { | ||
uint64_t scope = convert_to_type<uint64_t>(p.lower_bound, "lower_bound scope"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is a bug!
If I pass '313313313313' to lower_bound, then it's 313313313313 (0x48F2EDC221), SHOULD be 1749138884762583600 (0x1846308C6118C230)
1111111.bank is 595056260428703488 (0x084210842039A700)
313313313313 < N(1111111.bank) < N(313313313313)
You can reproduce BUG by:
`
cleos -u https://mainnet.meet.one --print-request get scope eosio.token -t accounts -l 1 -L 313313313313
REQUEST:
POST /v1/chain/get_table_by_scope HTTP/1.0
Host: mainnet.meet.one
content-length: 118
Accept: /
Connection: close
{
"code": "eosio.token",
"table": "accounts",
"lower_bound": "313313313313",
"upper_bound": "",
"limit": 1
}
{
"rows": [{
"code": "eosio.token",
"scope": "1111111.bank",
"table": "accounts",
"payer": "1111111.bank",
"count": 1
}
],
"more": "111111111111"
}
`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a bug. The value of scope will be read as uint64_t first, then be read as account_name if failed to be read as uint64_t, as for different contracts the meaning of scopes may defer. If you want to read it as account_name always, you need to use cleos -u https://mainnet.meet.one --print-request get scope eosio.token -t accounts -l 1 -L " 313313313313"
Is it possible to get a contract scope in contract? |
#5380 This allow user to off-chain iterate over scopes and tables for a given contract.
Adds new
/v1/chain/get_table_by_scope
rpc.Usage: ./cleos get scope [OPTIONS] contract
Positionals:
contract TEXT The contract who owns the table (required)
Options:
-t,--table TEXT The name of the table as filter
-l,--limit UINT The maximum number of rows to return
-L,--lower TEXT lower bound of scope
-U,--upper TEXT upper bound of scope
for example: to iterate over all accounts that has EOS balance table: