diff --git a/CHANGELOG.md b/CHANGELOG.md index 887bd9d5e..f2344f69d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ All notable changes to the Aptos TypeScript SDK will be captured in this file. T - [`Breaking`] Change any generate transaction function to return `SimpleTransaction` or `MultiAgentTransaction` instance - Adds `getUserTransactionHash` which can generate a transaction hash after signing, but before submission - Add function to create resource address locally +- Add `getAccountAllTransactionVersions` which returns versions of all transactions related to the given address. +- Update the behavior of existing `getAccountTransactions` so it returns all transactions related to given address instead of only ones sent by address. This makes the result has same length as calling `getAccountTransactionsCount`. # 1.11.0 (2024-03-26) diff --git a/src/api/account.ts b/src/api/account.ts index dd76abd97..c75d186a2 100644 --- a/src/api/account.ts +++ b/src/api/account.ts @@ -22,6 +22,7 @@ import { } from "../types"; import { deriveAccountFromPrivateKey, + getAccountAllTransactionVersions, getAccountCoinAmount, getAccountCoinsCount, getAccountCoinsData, @@ -137,6 +138,27 @@ export class Account { }); } + /** + * Queries account's all transaction versions given an account address + * + * Note: This returns both the transaction sent by the account and the transaction received by the account. + * + * @param args.accountAddress Aptos account address + * @param args.options.offset The number transaction to start returning results from + * @param args.options.limit The number of results to return + * + * @returns The account transaction versions + */ + async getAccountAllTransactionVersions(args: { + accountAddress: AccountAddressInput; + options?: PaginationArgs; + }): Promise { + return getAccountAllTransactionVersions({ + aptosConfig: this.config, + ...args, + }); + } + /** * Queries all account resources given an account address * diff --git a/src/internal/account.ts b/src/internal/account.ts index 62c420894..857d0d2fe 100644 --- a/src/internal/account.ts +++ b/src/internal/account.ts @@ -16,6 +16,7 @@ import { AnyPublicKey, Ed25519PublicKey, PrivateKey } from "../core/crypto"; import { getTableItem, queryIndexer } from "./general"; import { AccountData, + AnyNumber, GetAccountCoinsDataResponse, GetAccountCollectionsWithOwnedTokenResponse, GetAccountOwnedObjectsResponse, @@ -33,6 +34,7 @@ import { WhereArg, } from "../types"; import { + GetAccountAllTransactionVersionsQuery, GetAccountCoinsCountQuery, GetAccountCoinsDataQuery, GetAccountCollectionsWithOwnedTokensQuery, @@ -43,6 +45,7 @@ import { GetAccountTransactionsCountQuery, } from "../types/generated/operations"; import { + GetAccountAllTransactionVersions, GetAccountCoinsCount, GetAccountCoinsData, GetAccountCollectionsWithOwnedTokens, @@ -55,6 +58,7 @@ import { import { memoizeAsync } from "../utils/memoize"; import { Secp256k1PrivateKey, AuthenticationKey, Ed25519PrivateKey } from "../core"; import { CurrentFungibleAssetBalancesBoolExp } from "../types/generated/types"; +import { getTransactionByVersion } from "./transaction"; export async function getInfo(args: { aptosConfig: AptosConfig; @@ -137,12 +141,45 @@ export async function getTransactions(args: { options?: PaginationArgs; }): Promise { const { aptosConfig, accountAddress, options } = args; - return paginateWithCursor<{}, TransactionResponse[]>({ + // TODO: Ideally indexer should provide one API that returns all transactions details in one go + // But now we have to query all transaction versions first and then query each transaction by version + const versions = await getAccountAllTransactionVersions({ aptosConfig, accountAddress, options }); + const results = []; + for (const version of versions) { + const tx = getTransactionByVersion({ aptosConfig, ledgerVersion: version }); + results.push(tx); + } + return Promise.all(results); +} + +export async function getAccountAllTransactionVersions(args: { + aptosConfig: AptosConfig; + accountAddress: AccountAddressInput; + options?: PaginationArgs; +}): Promise { + const { aptosConfig, accountAddress, options } = args; + const address = AccountAddress.from(accountAddress).toStringLong(); + + const whereCondition: { account_address: { _eq: string } } = { + account_address: { _eq: address }, + }; + + const graphqlQuery = { + query: GetAccountAllTransactionVersions, + variables: { + where_condition: whereCondition, + offset: options?.offset, + limit: options?.limit, + }, + }; + + const data = await queryIndexer({ aptosConfig, - originMethod: "getTransactions", - path: `accounts/${AccountAddress.from(accountAddress).toString()}/transactions`, - params: { start: options?.offset, limit: options?.limit }, + query: graphqlQuery, + originMethod: "getAccountAllTransactionVersions", }); + + return data.account_transactions.map((tx) => tx.transaction_version); } export async function getResources(args: { diff --git a/src/internal/queries/getAccountAllTransactionVersions.graphql b/src/internal/queries/getAccountAllTransactionVersions.graphql new file mode 100644 index 000000000..b6b1a290a --- /dev/null +++ b/src/internal/queries/getAccountAllTransactionVersions.graphql @@ -0,0 +1,10 @@ +query getAccountAllTransactionVersions($where_condition: account_transactions_bool_exp!, $offset: Int, $limit: Int) { + account_transactions( + where: $where_condition + order_by: { transaction_version: desc } + limit: $limit + offset: $offset + ) { + transaction_version + } +} diff --git a/src/types/generated/operations.ts b/src/types/generated/operations.ts index d8b8f96ec..b31dbc477 100644 --- a/src/types/generated/operations.ts +++ b/src/types/generated/operations.ts @@ -55,7 +55,6 @@ export type CurrentTokenOwnershipFieldsFragment = { token_properties: any; token_standard: string; token_uri: string; - decimals: any; current_collection?: { collection_id: string; collection_name: string; @@ -75,6 +74,14 @@ export type CurrentTokenOwnershipFieldsFragment = { } | null; }; +export type GetAccountAllTransactionVersionsQueryVariables = Types.Exact<{ + where_condition: Types.AccountTransactionsBoolExp; + offset?: Types.InputMaybe; + limit?: Types.InputMaybe; +}>; + +export type GetAccountAllTransactionVersionsQuery = { account_transactions: Array<{ transaction_version: any }> }; + export type GetAccountCoinsCountQueryVariables = Types.Exact<{ address?: Types.InputMaybe; }>; @@ -212,7 +219,6 @@ export type GetAccountOwnedTokensQuery = { token_properties: any; token_standard: string; token_uri: string; - decimals: any; current_collection?: { collection_id: string; collection_name: string; @@ -268,7 +274,6 @@ export type GetAccountOwnedTokensByTokenDataQuery = { token_properties: any; token_standard: string; token_uri: string; - decimals: any; current_collection?: { collection_id: string; collection_name: string; @@ -324,7 +329,6 @@ export type GetAccountOwnedTokensFromCollectionQuery = { token_properties: any; token_standard: string; token_uri: string; - decimals: any; current_collection?: { collection_id: string; collection_name: string; @@ -597,7 +601,6 @@ export type GetCurrentTokenOwnershipQuery = { token_properties: any; token_standard: string; token_uri: string; - decimals: any; current_collection?: { collection_id: string; collection_name: string; diff --git a/src/types/generated/queries.ts b/src/types/generated/queries.ts index eb5e18dd7..325882944 100644 --- a/src/types/generated/queries.ts +++ b/src/types/generated/queries.ts @@ -60,7 +60,6 @@ export const CurrentTokenOwnershipFieldsFragmentDoc = ` token_properties token_standard token_uri - decimals current_collection { collection_id collection_name @@ -80,6 +79,18 @@ export const CurrentTokenOwnershipFieldsFragmentDoc = ` } } `; +export const GetAccountAllTransactionVersions = ` + query getAccountAllTransactionVersions($where_condition: account_transactions_bool_exp!, $offset: Int, $limit: Int) { + account_transactions( + where: $where_condition + order_by: {transaction_version: desc} + limit: $limit + offset: $offset + ) { + transaction_version + } +} + `; export const GetAccountCoinsCount = ` query getAccountCoinsCount($address: String) { current_fungible_asset_balances_aggregate( @@ -465,6 +476,20 @@ const defaultWrapper: SdkFunctionWrapper = (action, _operationName, _operationTy export function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper = defaultWrapper) { return { + getAccountAllTransactionVersions( + variables: Types.GetAccountAllTransactionVersionsQueryVariables, + requestHeaders?: GraphQLClientRequestHeaders, + ): Promise { + return withWrapper( + (wrappedRequestHeaders) => + client.request(GetAccountAllTransactionVersions, variables, { + ...requestHeaders, + ...wrappedRequestHeaders, + }), + "getAccountAllTransactionVersions", + "query", + ); + }, getAccountCoinsCount( variables?: Types.GetAccountCoinsCountQueryVariables, requestHeaders?: GraphQLClientRequestHeaders, diff --git a/src/types/generated/types.ts b/src/types/generated/types.ts index 872de886c..3cb80ed8c 100644 --- a/src/types/generated/types.ts +++ b/src/types/generated/types.ts @@ -1875,6 +1875,7 @@ export type CurrentAnsLookupV2StreamCursorValueInput = { /** columns and relationships of "current_aptos_names" */ export type CurrentAptosNames = { domain?: Maybe; + domain_expiration_timestamp?: Maybe; domain_with_suffix?: Maybe; expiration_timestamp?: Maybe; is_active?: Maybe; @@ -1885,6 +1886,7 @@ export type CurrentAptosNames = { owner_address?: Maybe; registered_address?: Maybe; subdomain?: Maybe; + subdomain_expiration_policy?: Maybe; token_name?: Maybe; token_standard?: Maybe; }; @@ -1961,11 +1963,13 @@ export type CurrentAptosNamesAggregateOrderBy = { /** aggregate avg on columns */ export type CurrentAptosNamesAvgFields = { last_transaction_version?: Maybe; + subdomain_expiration_policy?: Maybe; }; /** order by avg() on columns of table "current_aptos_names" */ export type CurrentAptosNamesAvgOrderBy = { last_transaction_version?: InputMaybe; + subdomain_expiration_policy?: InputMaybe; }; /** Boolean expression to filter rows from the table "current_aptos_names". All fields are combined with a logical 'AND'. */ @@ -1974,6 +1978,7 @@ export type CurrentAptosNamesBoolExp = { _not?: InputMaybe; _or?: InputMaybe>; domain?: InputMaybe; + domain_expiration_timestamp?: InputMaybe; domain_with_suffix?: InputMaybe; expiration_timestamp?: InputMaybe; is_active?: InputMaybe; @@ -1983,6 +1988,7 @@ export type CurrentAptosNamesBoolExp = { owner_address?: InputMaybe; registered_address?: InputMaybe; subdomain?: InputMaybe; + subdomain_expiration_policy?: InputMaybe; token_name?: InputMaybe; token_standard?: InputMaybe; }; @@ -1990,12 +1996,14 @@ export type CurrentAptosNamesBoolExp = { /** aggregate max on columns */ export type CurrentAptosNamesMaxFields = { domain?: Maybe; + domain_expiration_timestamp?: Maybe; domain_with_suffix?: Maybe; expiration_timestamp?: Maybe; last_transaction_version?: Maybe; owner_address?: Maybe; registered_address?: Maybe; subdomain?: Maybe; + subdomain_expiration_policy?: Maybe; token_name?: Maybe; token_standard?: Maybe; }; @@ -2003,12 +2011,14 @@ export type CurrentAptosNamesMaxFields = { /** order by max() on columns of table "current_aptos_names" */ export type CurrentAptosNamesMaxOrderBy = { domain?: InputMaybe; + domain_expiration_timestamp?: InputMaybe; domain_with_suffix?: InputMaybe; expiration_timestamp?: InputMaybe; last_transaction_version?: InputMaybe; owner_address?: InputMaybe; registered_address?: InputMaybe; subdomain?: InputMaybe; + subdomain_expiration_policy?: InputMaybe; token_name?: InputMaybe; token_standard?: InputMaybe; }; @@ -2016,12 +2026,14 @@ export type CurrentAptosNamesMaxOrderBy = { /** aggregate min on columns */ export type CurrentAptosNamesMinFields = { domain?: Maybe; + domain_expiration_timestamp?: Maybe; domain_with_suffix?: Maybe; expiration_timestamp?: Maybe; last_transaction_version?: Maybe; owner_address?: Maybe; registered_address?: Maybe; subdomain?: Maybe; + subdomain_expiration_policy?: Maybe; token_name?: Maybe; token_standard?: Maybe; }; @@ -2029,12 +2041,14 @@ export type CurrentAptosNamesMinFields = { /** order by min() on columns of table "current_aptos_names" */ export type CurrentAptosNamesMinOrderBy = { domain?: InputMaybe; + domain_expiration_timestamp?: InputMaybe; domain_with_suffix?: InputMaybe; expiration_timestamp?: InputMaybe; last_transaction_version?: InputMaybe; owner_address?: InputMaybe; registered_address?: InputMaybe; subdomain?: InputMaybe; + subdomain_expiration_policy?: InputMaybe; token_name?: InputMaybe; token_standard?: InputMaybe; }; @@ -2042,6 +2056,7 @@ export type CurrentAptosNamesMinOrderBy = { /** Ordering options when selecting data from "current_aptos_names". */ export type CurrentAptosNamesOrderBy = { domain?: InputMaybe; + domain_expiration_timestamp?: InputMaybe; domain_with_suffix?: InputMaybe; expiration_timestamp?: InputMaybe; is_active?: InputMaybe; @@ -2051,6 +2066,7 @@ export type CurrentAptosNamesOrderBy = { owner_address?: InputMaybe; registered_address?: InputMaybe; subdomain?: InputMaybe; + subdomain_expiration_policy?: InputMaybe; token_name?: InputMaybe; token_standard?: InputMaybe; }; @@ -2060,6 +2076,8 @@ export enum CurrentAptosNamesSelectColumn { /** column name */ Domain = "domain", /** column name */ + DomainExpirationTimestamp = "domain_expiration_timestamp", + /** column name */ DomainWithSuffix = "domain_with_suffix", /** column name */ ExpirationTimestamp = "expiration_timestamp", @@ -2076,6 +2094,8 @@ export enum CurrentAptosNamesSelectColumn { /** column name */ Subdomain = "subdomain", /** column name */ + SubdomainExpirationPolicy = "subdomain_expiration_policy", + /** column name */ TokenName = "token_name", /** column name */ TokenStandard = "token_standard", @@ -2100,31 +2120,37 @@ export enum CurrentAptosNamesSelectColumnCurrentAptosNamesAggregateBoolExpBoolOr /** aggregate stddev on columns */ export type CurrentAptosNamesStddevFields = { last_transaction_version?: Maybe; + subdomain_expiration_policy?: Maybe; }; /** order by stddev() on columns of table "current_aptos_names" */ export type CurrentAptosNamesStddevOrderBy = { last_transaction_version?: InputMaybe; + subdomain_expiration_policy?: InputMaybe; }; /** aggregate stddev_pop on columns */ export type CurrentAptosNamesStddevPopFields = { last_transaction_version?: Maybe; + subdomain_expiration_policy?: Maybe; }; /** order by stddev_pop() on columns of table "current_aptos_names" */ export type CurrentAptosNamesStddevPopOrderBy = { last_transaction_version?: InputMaybe; + subdomain_expiration_policy?: InputMaybe; }; /** aggregate stddev_samp on columns */ export type CurrentAptosNamesStddevSampFields = { last_transaction_version?: Maybe; + subdomain_expiration_policy?: Maybe; }; /** order by stddev_samp() on columns of table "current_aptos_names" */ export type CurrentAptosNamesStddevSampOrderBy = { last_transaction_version?: InputMaybe; + subdomain_expiration_policy?: InputMaybe; }; /** Streaming cursor of the table "current_aptos_names" */ @@ -2138,6 +2164,7 @@ export type CurrentAptosNamesStreamCursorInput = { /** Initial value of the column from where the streaming should start */ export type CurrentAptosNamesStreamCursorValueInput = { domain?: InputMaybe; + domain_expiration_timestamp?: InputMaybe; domain_with_suffix?: InputMaybe; expiration_timestamp?: InputMaybe; is_active?: InputMaybe; @@ -2146,6 +2173,7 @@ export type CurrentAptosNamesStreamCursorValueInput = { owner_address?: InputMaybe; registered_address?: InputMaybe; subdomain?: InputMaybe; + subdomain_expiration_policy?: InputMaybe; token_name?: InputMaybe; token_standard?: InputMaybe; }; @@ -2153,41 +2181,49 @@ export type CurrentAptosNamesStreamCursorValueInput = { /** aggregate sum on columns */ export type CurrentAptosNamesSumFields = { last_transaction_version?: Maybe; + subdomain_expiration_policy?: Maybe; }; /** order by sum() on columns of table "current_aptos_names" */ export type CurrentAptosNamesSumOrderBy = { last_transaction_version?: InputMaybe; + subdomain_expiration_policy?: InputMaybe; }; /** aggregate var_pop on columns */ export type CurrentAptosNamesVarPopFields = { last_transaction_version?: Maybe; + subdomain_expiration_policy?: Maybe; }; /** order by var_pop() on columns of table "current_aptos_names" */ export type CurrentAptosNamesVarPopOrderBy = { last_transaction_version?: InputMaybe; + subdomain_expiration_policy?: InputMaybe; }; /** aggregate var_samp on columns */ export type CurrentAptosNamesVarSampFields = { last_transaction_version?: Maybe; + subdomain_expiration_policy?: Maybe; }; /** order by var_samp() on columns of table "current_aptos_names" */ export type CurrentAptosNamesVarSampOrderBy = { last_transaction_version?: InputMaybe; + subdomain_expiration_policy?: InputMaybe; }; /** aggregate variance on columns */ export type CurrentAptosNamesVarianceFields = { last_transaction_version?: Maybe; + subdomain_expiration_policy?: Maybe; }; /** order by variance() on columns of table "current_aptos_names" */ export type CurrentAptosNamesVarianceOrderBy = { last_transaction_version?: InputMaybe; + subdomain_expiration_policy?: InputMaybe; }; /** columns and relationships of "current_coin_balances" */ @@ -3495,8 +3531,10 @@ export type CurrentTokenDatasV2 = { collection_id: Scalars["String"]["output"]; /** An object relationship */ current_collection?: Maybe; - /** An object relationship */ - current_token_ownership?: Maybe; + /** An array relationship */ + current_token_ownerships: Array; + /** An aggregate relationship */ + current_token_ownerships_aggregate: CurrentTokenOwnershipsV2Aggregate; decimals: Scalars["bigint"]["output"]; description: Scalars["String"]["output"]; is_fungible_v2?: Maybe; @@ -3512,6 +3550,24 @@ export type CurrentTokenDatasV2 = { token_uri: Scalars["String"]["output"]; }; +/** columns and relationships of "current_token_datas_v2" */ +export type CurrentTokenDatasV2CurrentTokenOwnershipsArgs = { + distinct_on?: InputMaybe>; + limit?: InputMaybe; + offset?: InputMaybe; + order_by?: InputMaybe>; + where?: InputMaybe; +}; + +/** columns and relationships of "current_token_datas_v2" */ +export type CurrentTokenDatasV2CurrentTokenOwnershipsAggregateArgs = { + distinct_on?: InputMaybe>; + limit?: InputMaybe; + offset?: InputMaybe; + order_by?: InputMaybe>; + where?: InputMaybe; +}; + /** columns and relationships of "current_token_datas_v2" */ export type CurrentTokenDatasV2TokenPropertiesArgs = { path?: InputMaybe; @@ -3526,7 +3582,8 @@ export type CurrentTokenDatasV2BoolExp = { cdn_asset_uris?: InputMaybe; collection_id?: InputMaybe; current_collection?: InputMaybe; - current_token_ownership?: InputMaybe; + current_token_ownerships?: InputMaybe; + current_token_ownerships_aggregate?: InputMaybe; decimals?: InputMaybe; description?: InputMaybe; is_fungible_v2?: InputMaybe; @@ -3548,7 +3605,7 @@ export type CurrentTokenDatasV2OrderBy = { cdn_asset_uris?: InputMaybe; collection_id?: InputMaybe; current_collection?: InputMaybe; - current_token_ownership?: InputMaybe; + current_token_ownerships_aggregate?: InputMaybe; decimals?: InputMaybe; description?: InputMaybe; is_fungible_v2?: InputMaybe; @@ -3938,6 +3995,7 @@ export type CurrentTokenOwnershipsV2 = { is_soulbound_v2?: Maybe; last_transaction_timestamp: Scalars["timestamp"]["output"]; last_transaction_version: Scalars["bigint"]["output"]; + non_transferrable_by_owner?: Maybe; owner_address: Scalars["String"]["output"]; property_version_v1: Scalars["numeric"]["output"]; storage_id: Scalars["String"]["output"]; @@ -4066,6 +4124,7 @@ export type CurrentTokenOwnershipsV2BoolExp = { is_soulbound_v2?: InputMaybe; last_transaction_timestamp?: InputMaybe; last_transaction_version?: InputMaybe; + non_transferrable_by_owner?: InputMaybe; owner_address?: InputMaybe; property_version_v1?: InputMaybe; storage_id?: InputMaybe; @@ -4136,6 +4195,7 @@ export type CurrentTokenOwnershipsV2OrderBy = { is_soulbound_v2?: InputMaybe; last_transaction_timestamp?: InputMaybe; last_transaction_version?: InputMaybe; + non_transferrable_by_owner?: InputMaybe; owner_address?: InputMaybe; property_version_v1?: InputMaybe; storage_id?: InputMaybe; @@ -4158,6 +4218,8 @@ export enum CurrentTokenOwnershipsV2SelectColumn { /** column name */ LastTransactionVersion = "last_transaction_version", /** column name */ + NonTransferrableByOwner = "non_transferrable_by_owner", + /** column name */ OwnerAddress = "owner_address", /** column name */ PropertyVersionV1 = "property_version_v1", @@ -4179,6 +4241,8 @@ export enum CurrentTokenOwnershipsV2SelectColumnCurrentTokenOwnershipsV2Aggregat IsFungibleV2 = "is_fungible_v2", /** column name */ IsSoulboundV2 = "is_soulbound_v2", + /** column name */ + NonTransferrableByOwner = "non_transferrable_by_owner", } /** select "current_token_ownerships_v2_aggregate_bool_exp_bool_or_arguments_columns" columns of table "current_token_ownerships_v2" */ @@ -4187,6 +4251,8 @@ export enum CurrentTokenOwnershipsV2SelectColumnCurrentTokenOwnershipsV2Aggregat IsFungibleV2 = "is_fungible_v2", /** column name */ IsSoulboundV2 = "is_soulbound_v2", + /** column name */ + NonTransferrableByOwner = "non_transferrable_by_owner", } /** aggregate stddev on columns */ @@ -4246,6 +4312,7 @@ export type CurrentTokenOwnershipsV2StreamCursorValueInput = { is_soulbound_v2?: InputMaybe; last_transaction_timestamp?: InputMaybe; last_transaction_version?: InputMaybe; + non_transferrable_by_owner?: InputMaybe; owner_address?: InputMaybe; property_version_v1?: InputMaybe; storage_id?: InputMaybe; @@ -7072,6 +7139,10 @@ export type QueryRoot = { proposal_votes_aggregate: ProposalVotesAggregate; /** fetch data from the table: "proposal_votes" using primary key columns */ proposal_votes_by_pk?: Maybe; + /** fetch data from the table: "signatures" */ + signatures: Array; + /** fetch data from the table: "signatures" using primary key columns */ + signatures_by_pk?: Maybe; /** fetch data from the table: "table_items" */ table_items: Array; /** fetch data from the table: "table_items" using primary key columns */ @@ -7802,6 +7873,21 @@ export type QueryRootProposalVotesByPkArgs = { voter_address: Scalars["String"]["input"]; }; +export type QueryRootSignaturesArgs = { + distinct_on?: InputMaybe>; + limit?: InputMaybe; + offset?: InputMaybe; + order_by?: InputMaybe>; + where?: InputMaybe; +}; + +export type QueryRootSignaturesByPkArgs = { + is_sender_primary: Scalars["Boolean"]["input"]; + multi_agent_index: Scalars["bigint"]["input"]; + multi_sig_index: Scalars["bigint"]["input"]; + transaction_version: Scalars["bigint"]["input"]; +}; + export type QueryRootTableItemsArgs = { distinct_on?: InputMaybe>; limit?: InputMaybe; @@ -7925,6 +8011,108 @@ export type QueryRootUserTransactionsByPkArgs = { version: Scalars["bigint"]["input"]; }; +/** columns and relationships of "signatures" */ +export type Signatures = { + is_sender_primary: Scalars["Boolean"]["output"]; + multi_agent_index: Scalars["bigint"]["output"]; + multi_sig_index: Scalars["bigint"]["output"]; + public_key: Scalars["String"]["output"]; + public_key_indices: Scalars["jsonb"]["output"]; + signature: Scalars["String"]["output"]; + signer: Scalars["String"]["output"]; + threshold: Scalars["bigint"]["output"]; + transaction_block_height: Scalars["bigint"]["output"]; + transaction_version: Scalars["bigint"]["output"]; + type: Scalars["String"]["output"]; +}; + +/** columns and relationships of "signatures" */ +export type SignaturesPublicKeyIndicesArgs = { + path?: InputMaybe; +}; + +/** Boolean expression to filter rows from the table "signatures". All fields are combined with a logical 'AND'. */ +export type SignaturesBoolExp = { + _and?: InputMaybe>; + _not?: InputMaybe; + _or?: InputMaybe>; + is_sender_primary?: InputMaybe; + multi_agent_index?: InputMaybe; + multi_sig_index?: InputMaybe; + public_key?: InputMaybe; + public_key_indices?: InputMaybe; + signature?: InputMaybe; + signer?: InputMaybe; + threshold?: InputMaybe; + transaction_block_height?: InputMaybe; + transaction_version?: InputMaybe; + type?: InputMaybe; +}; + +/** Ordering options when selecting data from "signatures". */ +export type SignaturesOrderBy = { + is_sender_primary?: InputMaybe; + multi_agent_index?: InputMaybe; + multi_sig_index?: InputMaybe; + public_key?: InputMaybe; + public_key_indices?: InputMaybe; + signature?: InputMaybe; + signer?: InputMaybe; + threshold?: InputMaybe; + transaction_block_height?: InputMaybe; + transaction_version?: InputMaybe; + type?: InputMaybe; +}; + +/** select columns of table "signatures" */ +export enum SignaturesSelectColumn { + /** column name */ + IsSenderPrimary = "is_sender_primary", + /** column name */ + MultiAgentIndex = "multi_agent_index", + /** column name */ + MultiSigIndex = "multi_sig_index", + /** column name */ + PublicKey = "public_key", + /** column name */ + PublicKeyIndices = "public_key_indices", + /** column name */ + Signature = "signature", + /** column name */ + Signer = "signer", + /** column name */ + Threshold = "threshold", + /** column name */ + TransactionBlockHeight = "transaction_block_height", + /** column name */ + TransactionVersion = "transaction_version", + /** column name */ + Type = "type", +} + +/** Streaming cursor of the table "signatures" */ +export type SignaturesStreamCursorInput = { + /** Stream column input with initial value */ + initial_value: SignaturesStreamCursorValueInput; + /** cursor ordering */ + ordering?: InputMaybe; +}; + +/** Initial value of the column from where the streaming should start */ +export type SignaturesStreamCursorValueInput = { + is_sender_primary?: InputMaybe; + multi_agent_index?: InputMaybe; + multi_sig_index?: InputMaybe; + public_key?: InputMaybe; + public_key_indices?: InputMaybe; + signature?: InputMaybe; + signer?: InputMaybe; + threshold?: InputMaybe; + transaction_block_height?: InputMaybe; + transaction_version?: InputMaybe; + type?: InputMaybe; +}; + export type SubscriptionRoot = { /** fetch data from the table: "account_transactions" */ account_transactions: Array; @@ -8226,6 +8414,12 @@ export type SubscriptionRoot = { proposal_votes_by_pk?: Maybe; /** fetch data from the table in a streaming manner: "proposal_votes" */ proposal_votes_stream: Array; + /** fetch data from the table: "signatures" */ + signatures: Array; + /** fetch data from the table: "signatures" using primary key columns */ + signatures_by_pk?: Maybe; + /** fetch data from the table in a streaming manner: "signatures" */ + signatures_stream: Array; /** fetch data from the table: "table_items" */ table_items: Array; /** fetch data from the table: "table_items" using primary key columns */ @@ -9260,6 +9454,27 @@ export type SubscriptionRootProposalVotesStreamArgs = { where?: InputMaybe; }; +export type SubscriptionRootSignaturesArgs = { + distinct_on?: InputMaybe>; + limit?: InputMaybe; + offset?: InputMaybe; + order_by?: InputMaybe>; + where?: InputMaybe; +}; + +export type SubscriptionRootSignaturesByPkArgs = { + is_sender_primary: Scalars["Boolean"]["input"]; + multi_agent_index: Scalars["bigint"]["input"]; + multi_sig_index: Scalars["bigint"]["input"]; + transaction_version: Scalars["bigint"]["input"]; +}; + +export type SubscriptionRootSignaturesStreamArgs = { + batch_size: Scalars["Int"]["input"]; + cursor: Array>; + where?: InputMaybe; +}; + export type SubscriptionRootTableItemsArgs = { distinct_on?: InputMaybe>; limit?: InputMaybe; diff --git a/tests/e2e/api/account.test.ts b/tests/e2e/api/account.test.ts index 84f77a10e..49cfac56d 100644 --- a/tests/e2e/api/account.test.ts +++ b/tests/e2e/api/account.test.ts @@ -109,32 +109,61 @@ describe("account api", () => { test("it fetches account transactions", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const senderAccount = Account.generate(); + const alice = Account.generate(); await aptos.fundAccount({ - accountAddress: senderAccount.accountAddress, + accountAddress: alice.accountAddress, amount: FUND_AMOUNT, }); const bob = Account.generate(); - const rawTxn = await aptos.transaction.build.simple({ - sender: senderAccount.accountAddress, + await aptos.fundAccount({ + accountAddress: bob.accountAddress, + amount: FUND_AMOUNT, + }); + const rawTxn1 = await aptos.transaction.build.simple({ + sender: alice.accountAddress, data: { function: "0x1::aptos_account::transfer", functionArguments: [bob.accountAddress, new U64(10)], }, }); - const authenticator = aptos.transaction.sign({ - signer: senderAccount, - transaction: rawTxn, + const authenticator1 = aptos.transaction.sign({ + signer: alice, + transaction: rawTxn1, }); - const response = await aptos.transaction.submit.simple({ - transaction: rawTxn, - senderAuthenticator: authenticator, + const response1 = await aptos.transaction.submit.simple({ + transaction: rawTxn1, + senderAuthenticator: authenticator1, }); - const txn = await aptos.waitForTransaction({ transactionHash: response.hash }); - const accountTransactions = await aptos.getAccountTransactions({ - accountAddress: senderAccount.accountAddress, + const txn1 = await aptos.waitForTransaction({ transactionHash: response1.hash }); + const rawTxn2 = await aptos.transaction.build.simple({ + sender: bob.accountAddress, + data: { + function: "0x1::aptos_account::transfer", + functionArguments: [alice.accountAddress, new U64(10)], + }, + }); + const authenticator2 = aptos.transaction.sign({ + signer: bob, + transaction: rawTxn2, + }); + const response2 = await aptos.transaction.submit.simple({ + transaction: rawTxn2, + senderAuthenticator: authenticator2, + }); + const txn2 = await aptos.waitForTransaction({ transactionHash: response2.hash }); + const aliceTransactions = await aptos.getAccountTransactions({ + accountAddress: alice.accountAddress, + }); + const bobAccountTransactions = await aptos.getAccountTransactions({ + accountAddress: bob.accountAddress, }); - expect(accountTransactions[0]).toStrictEqual(txn); + // getAccountTransactions returns all txs related to the account in descending order + // both alice and bob's third tx is the fund tx + // therefore, the first tx is alice transfers to bob and second tx is bob transfers to alice + expect(aliceTransactions[0]).toStrictEqual(txn2); + expect(aliceTransactions[1]).toStrictEqual(txn1); + expect(bobAccountTransactions[0]).toStrictEqual(txn2); + expect(bobAccountTransactions[1]).toStrictEqual(txn1); }); test("it fetches account transactions count", async () => {