Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lack of Default Primary Index Information in Antelope ABIs #197

Open
dafuga opened this issue Jun 28, 2023 · 4 comments
Open

Lack of Default Primary Index Information in Antelope ABIs #197

dafuga opened this issue Jun 28, 2023 · 4 comments

Comments

@dafuga
Copy link

dafuga commented Jun 28, 2023

Hello,

I am part of the team developing Wharf (https://github.com/wharfkit), we've come across an issue where Antelope's ABIs does not provide a mechanism to determine the default or primary index of a table. It seems that the ABI only provides information on the primary index if there's a secondary index present.

For example, in the eosio namebids table, the primary index is not included in the key_names field:

{
  "name": "namebids",
  "index_type": "i64",
  "key_names": [],
  "key_types": [],
  "type": "name_bid"
}

However, in the case of a table where secondary indexes exist, the key_names field does seem to include the primary index. For example, the decentiumorg trending table has the primary index data included in that array:

{
  "name": "trending",
  "index_type": "i64",
  "key_names": [
    "id",
    "score",
    "cscore",
    "permlink"
  ],
  "key_types": [
    "uint64",
    "uint64",
    "uint128",
    "uint128"
  ],
  "type": "trending_row"
}

As part of our ongoing development of the Wharf Contract kit, we are working on creating contract-specific helper functions to facilitate developers' use of the get_table_rows API. Our goal is to provide strongly typed functions to Wharf users. This will only be possible if we can determine the primary index of any given table from the contract ABI.

Given these requirements, could you consider always including the primary index information in the key_names and key_types arrays, regardless of whether a secondary index exists or not? This change would ensure a consistent understanding of the default indices across all tables and greatly assist in the creation of developer-friendly functions in the Wharf Contract kit.

Thanks,
Daniel

@enf-ci-bot enf-ci-bot moved this to Todo in Team Backlog Jun 28, 2023
@BenjaminGormanPMP BenjaminGormanPMP added 👍 lgtm bug Something isn't working and removed triage labels Aug 3, 2023
@BenjaminGormanPMP BenjaminGormanPMP moved this from Todo to In Progress in Team Backlog Aug 7, 2023
@dimas1185
Copy link
Contributor

dimas1185 commented Aug 7, 2023

@dafuga currently cdt doesn't fill out key_names and key_types. We can consider adding this feature.
Please let me know what generated those abi's. when you call cleos get abi it returns you an abi that was used while deploying the contract. If someone edited it manually before uploading it, you can edit it by yourself and update using cleos set abi command

@dimas1185
Copy link
Contributor

dimas1185 commented Aug 9, 2023

Here is some scrutiny results:

[larryk85](https://github.com/larryk85) commented [on Oct 10, 2018](https://github.com/EOSIO/eosio.cdt/issues/106#issuecomment-428804975)
The type is invalid issue with vectors has been resolved in v1.3.0. As for key_names and key_types, they are ignored, as they are a deprecated part of the abi, these fields are a hold over from a different system for secondary tables and no longer make any sense.

And here is original commit (due to different project structore 5 years ago this file is in a different repo):
EOSIO/clang#8
corresponding eosio.cdt PR - EOSIO/eosio.cdt#67

So key_names and key_types are deprecated fields and your contract was likely generated using 5 years old cdt. Are you looking for adding them back?

@BenjaminGormanPMP BenjaminGormanPMP moved this from In Progress to Icebox in Team Backlog Aug 9, 2023
@BenjaminGormanPMP BenjaminGormanPMP removed the bug Something isn't working label Aug 9, 2023
@ericpassmore
Copy link
Contributor

@dafuga from our research this has not been supported for several years, and was deprecated. For contracts compiled with CDT version 3.x or 4.x are you able to see a primary index when there is a secondary index? From our review of the code the index fields are never returned.

We are removing the bug label, and treating this as a feature request. We will discussion the right priority for this work.

@ericpassmore ericpassmore added this to the CDT 5.0.0-rc1 milestone Aug 11, 2023
@ericpassmore ericpassmore modified the milestones: CDT 5.0.0-rc1, Future Milestone Aug 11, 2023
@aaroncox
Copy link

aaroncox commented Aug 31, 2023

Apologies for the delayed response!

The contract in question @dafuga was mentioning was probably 4-5 years old at this point, so this makes sense.

If they've been gone that long and deprecated, then we could consider this a feature request (of somewhat high priority?).

We need some way to identify what the table indices are, preferably by interpreting the ABI. We are using that information to map our new table querying language to the appropriate indices when calling get_table_rows in @wharfkit.

To illustrate the mapping we're doing, the SDKs converting the index_position and key_type fields in get_table_rows requests like this:

{
  code: 'eosio',
  table: 'namebids',
  scope: 'eosio',
  index_position: 2,
  key_type: 'i64',
}

Into a more simply syntax where you can simply specify the field name.

contract.table('namebids').query({
    index: 'high_bid',
})

It maps that high_bid field name to index_position: 2 and key_type: 'i64' through the ABI.

@BenjaminGormanPMP BenjaminGormanPMP moved this from Icebox to Todo in Team Backlog Sep 14, 2023
@arhag arhag removed this from the Future Milestone milestone Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo
Development

No branches or pull requests

7 participants