EOSIO / eos

An open source smart contract platform
https://developers.eos.io/manuals/eos
MIT License
11.27k stars 3.6k forks source link

Feature request: Provide table scope index for smart-contracts #5380

Open jcalfee opened 6 years ago

jcalfee commented 6 years ago

In some cases developers are choosing not to use the table scope because it lacks an iterator or a lookup function. Seems like that is not a security concern. If not, if that were added I think we would get contracts that are a little easier to query (get_table_rows contract >>scope<<) and make use of that built-in index.

Kevin

It acts kind of like a sub-table name we have no way to iterate over tables either. Something to consider.

James :+1:

mgravitt commented 6 years ago

This would be greatly beneficial. I very rarely use the scope feature because it prevents me from getting all records. Additional filtering capabilities would also be highly beneficial.

jcalfee commented 6 years ago

I guess there could be a scalability or performance concerns. No guarantee that you can do everything within the CPU limit for the block so that may need in-contract paging. Still probably better to have it than to find out after a contract deployed that this is not possible.

tbfleming commented 6 years ago

Internally, table_id_multi_index has the by_code_scope_table index. We could expose lower_bound, find, and iteration on this index to contracts in a future hard fork.

tbfleming commented 6 years ago

by_code_table_scope would probably be more convenient, but since it doesn't already exist it would increase row ram costs.

taokayan commented 6 years ago

scope can be useful when you need to store something between 2 different accounts. For example, delegatebw uses scope as delegator and key as the account receiving the resources. But I agree there's no way to iterate over a scope.

taokayan commented 6 years ago

Please follow https://github.com/EOSIO/eos/pull/5486

spartucus commented 5 years ago

Any progress on this?

znebby commented 5 years ago

In addition to allowing iterating over scope, the get scope cleos command and API should be changed to only iterate over the scopes of the specified table (when given).

For example, if there is a token contract with several tokens (and 100k account owners). I want to get just all the tokens types from the contract (that is, I want all the scopes of the stats table).

However, the way it works, because it iterates over all scopes (and because of the accounts table, there will be thousands), I will have to keep running this command several times with new lower bounds to get all my token types.

tbfleming commented 5 years ago

@znebby The iteration order is controlled by the available indexes. Adding indexes to nodeos increases ram consumption. This particular application is better suited for external databases.