aptos-ts-sdk
aptos-ts-sdk copied to clipboard
Introduce `table` function API. Add `getTableItemsData` and `getTableItemsMetadata` queries
Description
This PR
- Adds
decimalprop back tocurrent_token_ownerships_v2.current_token_dataresponse - Solves https://github.com/aptos-labs/aptos-ts-sdk/issues/376 , by adding 2 new
tablerelated queries -getTableItemsDataandgetTableItemsMetadata.
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
decimalprop doesnt break queries (as happened in https://aptos-org.slack.com/archives/C05NLAKJM9U/p1709164127936519 ) - tests are passing
Related Links
hey @0xmaayan i have a few questions:
- what does PFN mean?
- 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?
- is there any delay between "table item becomes available in normal fullnode" and "table item decoded data available in indexer"?
- is there any chance
/v1/tables/{table_handle}/itemreturns decoded data?
appreciate your help here!!
hey @0xmaayan i have a few questions:
- what does PFN mean?
- 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?
- is there any delay between "table item becomes available in normal fullnode" and "table item decoded data available in indexer"?
- is there any chance
/v1/tables/{table_handle}/itemreturns decoded data?appreciate your help here!!
- Public FullNode
- By doing its indexing magic, Indexer is able to know and store chain data that the fullnode is not able
- There is probably a super minimal delay, but the SDK can help with handling it
/v1/tables/{table_handle}/itemreturns the table item by providing the types, i.e you should know the types in advanced. When querying for a transaction details (for example withgetTransactionByVersion) - 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 )