aptos-ts-sdk icon indicating copy to clipboard operation
aptos-ts-sdk copied to clipboard

Introduce `table` function API. Add `getTableItemsData` and `getTableItemsMetadata` queries

Open 0xmaayan opened this issue 1 year ago • 2 comments

Description

This PR

  1. Adds decimal prop back to current_token_ownerships_v2.current_token_data response
  2. Solves https://github.com/aptos-labs/aptos-ts-sdk/issues/376 , by adding 2 new table related queries - getTableItemsData and getTableItemsMetadata.

Currently, PFN doesnt return the table item data or metadata (i.e data field is always null, see https://fullnode.mainnet.aptoslabs.com/v1/transactions/by_version/563060087 ) and Indexer doesnt have a join query that can return all the data in one response.

This PR adds the 2 different Indexer queries where one can fetch the decoded table item data.

For example, consider https://explorer.aptoslabs.com/txn/563060087/changes?network=mainnet (index 5) Indexer is able to get us the decoded values.

With this change, the SDK uses indexer to fetch the decoded values

const data = await aptos.getTableItemsData({
      options: { where: { table_handle: { _eq:"0x7a36d3935ebd2045f49fab033acad5212782ff81c4b79bd55cc1af3ce7c8418b" }, transaction_version: { _eq: "563060087" } } },
}); 

const metadata = await aptos.getTableItemsMetadata({
      options: { where: { handle: { _eq:"0x7a36d3935ebd2045f49fab033acad5212782ff81c4b79bd55cc1af3ce7c8418b" } } },
});

Can compare with aptoscan.com

Test Plan

  • new tests have been added for the 2 new functions
  • new test has been added to make sure decimal prop doesnt break queries (as happened in https://aptos-org.slack.com/archives/C05NLAKJM9U/p1709164127936519 )
  • tests are passing

Related Links

0xmaayan avatar May 01 '24 18:05 0xmaayan

hey @0xmaayan i have a few questions:

  1. what does PFN mean?
  2. it looks right that indexer request returns decoded value, but wondering why is that the case? what data does indexer have while normal fullnode doesn't in order to decode the table item data?
  3. is there any delay between "table item becomes available in normal fullnode" and "table item decoded data available in indexer"?
  4. is there any chance /v1/tables/{table_handle}/item returns decoded data?

appreciate your help here!!

0xbe1 avatar May 02 '24 02:05 0xbe1

hey @0xmaayan i have a few questions:

  1. what does PFN mean?
  2. it looks right that indexer request returns decoded value, but wondering why is that the case? what data does indexer have while normal fullnode doesn't in order to decode the table item data?
  3. is there any delay between "table item becomes available in normal fullnode" and "table item decoded data available in indexer"?
  4. is there any chance /v1/tables/{table_handle}/item returns decoded data?

appreciate your help here!!

  1. Public FullNode
  2. By doing its indexing magic, Indexer is able to know and store chain data that the fullnode is not able
  3. There is probably a super minimal delay, but the SDK can help with handling it
  4. /v1/tables/{table_handle}/item returns the table item by providing the types, i.e you should know the types in advanced. When querying for a transaction details (for example with getTransactionByVersion) - it queries fullnode and the response does not contain the types or decoded values of the item (see here https://fullnode.mainnet.aptoslabs.com/v1/transactions/by_version/563060087 )

0xmaayan avatar May 02 '24 12:05 0xmaayan