{"version":3,"sources":["../../src/api/general.ts"],"sourcesContent":["// Copyright © Aptos Foundation\n// SPDX-License-Identifier: Apache-2.0\n\nimport { AptosConfig } from \"./aptosConfig\";\nimport {\n  getBlockByHeight,\n  getBlockByVersion,\n  getChainTopUserTransactions,\n  getIndexerLastSuccessVersion,\n  getLedgerInfo,\n  getProcessorStatus,\n  queryIndexer,\n} from \"../internal/general\";\nimport { view } from \"../internal/view\";\nimport {\n  AnyNumber,\n  Block,\n  GetChainTopUserTransactionsResponse,\n  GetProcessorStatusResponse,\n  GraphqlQuery,\n  LedgerInfo,\n  LedgerVersionArg,\n  MoveValue,\n} from \"../types\";\nimport { ProcessorType } from \"../utils/const\";\nimport { InputViewFunctionData } from \"../transactions\";\n\n/**\n * A class to query all `General` Aptos related queries\n */\nexport class General {\n  readonly config: AptosConfig;\n\n  constructor(config: AptosConfig) {\n    this.config = config;\n  }\n\n  /**\n   * Queries for the Aptos ledger info\n   *\n   * @returns Aptos Ledger Info\n   *\n   * @example\n   * const ledgerInfo = await aptos.getLedgerInfo()\n   * // an example of the returned data\n   * ```\n   * {\n   * \"chain_id\": 4,\n   * \"epoch\": \"8\",\n   * \"ledger_version\": \"714\",\n   * \"oldest_ledger_version\": \"0\",\n   * \"ledger_timestamp\": \"1694695496521775\",\n   * \"node_role\": \"validator\",\n   * \"oldest_block_height\": \"0\",\n   * \"block_height\": \"359\",\n   * \"git_hash\": \"c82193f36f4e185fed9f68c4ad21f6c6dd390c6e\"\n   * }\n   * ```\n   */\n  async getLedgerInfo(): Promise<LedgerInfo> {\n    return getLedgerInfo({ aptosConfig: this.config });\n  }\n\n  /**\n   * Queries for the chain id\n   *\n   * @example\n   * const chainId = await aptos.getChainId()\n   *\n   * @returns The chain id\n   */\n  async getChainId(): Promise<number> {\n    const result = await this.getLedgerInfo();\n    return result.chain_id;\n  }\n\n  /**\n   * Queries for block by transaction version\n   *\n   * @example\n   * const block = await aptos.getBlockByVersion({ledgerVersion:5})\n   *\n   * @param args.ledgerVersion Ledger version to lookup block information for\n   * @param args.options.withTransactions If set to true, include all transactions in the block\n   *\n   * @returns Block information with optional transactions\n   */\n  async getBlockByVersion(args: {\n    ledgerVersion: AnyNumber;\n    options?: { withTransactions?: boolean };\n  }): Promise<Block> {\n    return getBlockByVersion({\n      aptosConfig: this.config,\n      ...args,\n    });\n  }\n\n  /**\n   * Get block by block height\n   *\n   * @example\n   * const block = await aptos.getBlockByVersion({blockHeight:5})\n   *\n   * @param args.blockHeight Block height to lookup.  Starts at 0\n   * @param args.options.withTransactions If set to true, include all transactions in the block\n   *\n   * @returns Block with optional transactions\n   */\n  async getBlockByHeight(args: { blockHeight: AnyNumber; options?: { withTransactions?: boolean } }): Promise<Block> {\n    return getBlockByHeight({ aptosConfig: this.config, ...args });\n  }\n\n  /**\n   * Queries for a Move view function\n   * @param args.payload Payload for the view function\n   * @param args.options.ledgerVersion The ledger version to query, if not provided it will get the latest version\n   *\n   * @example\n   * const data = await aptos.view({\n   *  payload: {\n   *   function: \"0x1::coin::balance\",\n   *   typeArguments: [\"0x1::aptos_coin::AptosCoin\"],\n   *   functionArguments: [accountAddress],\n   *  }\n   * })\n   *\n   * @returns an array of Move values\n   */\n  async view<T extends Array<MoveValue>>(args: {\n    payload: InputViewFunctionData;\n    options?: LedgerVersionArg;\n  }): Promise<T> {\n    return view<T>({ aptosConfig: this.config, ...args });\n  }\n\n  /**\n   * Queries top user transactions\n   *\n   * @example\n   * const topUserTransactions = await aptos.getChainTopUserTransactions({limit:5})\n   *\n   * @param args.limit The number of transactions to return\n   * @returns GetChainTopUserTransactionsResponse\n   */\n  async getChainTopUserTransactions(args: { limit: number }): Promise<GetChainTopUserTransactionsResponse> {\n    return getChainTopUserTransactions({\n      aptosConfig: this.config,\n      ...args,\n    });\n  }\n\n  /**\n   * A generic function for retrieving data from Aptos Indexer.\n   * For more detailed queries specification see\n   * {@link https://cloud.hasura.io/public/graphiql?endpoint=https://api.mainnet.aptoslabs.com/v1/graphql}\n   *\n   * @example\n   * const topUserTransactions = await aptos.queryIndexer({\n   *  query: `query MyQuery {\n   *   ledger_infos {\n   *     chain_id\n   *   }}`;\n   * })\n   *\n   * @param args.query.query A GraphQL query\n   * @param args.query.variables The variables for the query\n   *\n   * @return The provided T type\n   */\n  async queryIndexer<T extends {}>(args: { query: GraphqlQuery }): Promise<T> {\n    return queryIndexer<T>({\n      aptosConfig: this.config,\n      ...args,\n    });\n  }\n\n  /**\n   * Queries for the last successful indexer version\n   *\n   * This is useful to tell what ledger version the indexer is updated to, as it can be behind the full nodes.\n   *\n   * @example\n   * const version = await aptos.getIndexerLastSuccessVersion()\n   */\n  async getIndexerLastSuccessVersion(): Promise<bigint> {\n    return getIndexerLastSuccessVersion({ aptosConfig: this.config });\n  }\n\n  /**\n   * Query the processor status for a specific processor type.\n   *\n   * @example\n   * const status = await aptos.getProcessorStatus({processorType:\"account_transactions_processor\"})\n   *\n   * @param processorType The processor type to query\n   * @returns\n   */\n  async getProcessorStatus(processorType: ProcessorType): Promise<GetProcessorStatusResponse[0]> {\n    return getProcessorStatus({ aptosConfig: this.config, processorType });\n  }\n}\n"],"mappings":"4HA8BO,IAAMA,EAAN,KAAc,CAGnB,YAAYC,EAAqB,CAC/B,KAAK,OAASA,CAChB,CAwBA,MAAM,eAAqC,CACzC,OAAOC,EAAc,CAAE,YAAa,KAAK,MAAO,CAAC,CACnD,CAUA,MAAM,YAA8B,CAElC,OADe,MAAM,KAAK,cAAc,GAC1B,QAChB,CAaA,MAAM,kBAAkBC,EAGL,CACjB,OAAOC,EAAkB,CACvB,YAAa,KAAK,OAClB,GAAGD,CACL,CAAC,CACH,CAaA,MAAM,iBAAiBA,EAA4F,CACjH,OAAOE,EAAiB,CAAE,YAAa,KAAK,OAAQ,GAAGF,CAAK,CAAC,CAC/D,CAkBA,MAAM,KAAiCA,EAGxB,CACb,OAAOG,EAAQ,CAAE,YAAa,KAAK,OAAQ,GAAGH,CAAK,CAAC,CACtD,CAWA,MAAM,4BAA4BA,EAAuE,CACvG,OAAOI,EAA4B,CACjC,YAAa,KAAK,OAClB,GAAGJ,CACL,CAAC,CACH,CAoBA,MAAM,aAA2BA,EAA2C,CAC1E,OAAOK,EAAgB,CACrB,YAAa,KAAK,OAClB,GAAGL,CACL,CAAC,CACH,CAUA,MAAM,8BAAgD,CACpD,OAAOM,EAA6B,CAAE,YAAa,KAAK,MAAO,CAAC,CAClE,CAWA,MAAM,mBAAmBC,EAAsE,CAC7F,OAAOC,EAAmB,CAAE,YAAa,KAAK,OAAQ,cAAAD,CAAc,CAAC,CACvE,CACF","names":["General","config","getLedgerInfo","args","getBlockByVersion","getBlockByHeight","view","getChainTopUserTransactions","queryIndexer","getIndexerLastSuccessVersion","processorType","getProcessorStatus"]}