// Copyright © Endless // Copyright © Aptos Foundation // SPDX-License-Identifier: Apache-2.0 import { EndlessConfig } from "./endlessConfig"; import { getIndexerStatus, getLedgerInfo, search } from "../internal/general"; import { getBlockByHeight, getBlockByVersion } from "../internal/transaction"; import { view } from "../internal/view"; import { AnyNumber, Block, LedgerInfo, LedgerVersionArg, MoveValue, SearchResponse, Status } from "../types"; import { InputViewFunctionData } from "../transactions"; /** * A class to query all `General` Endless related queries */ export class General { readonly config: EndlessConfig; constructor(config: EndlessConfig) { this.config = config; } /** * Queries for the Endless ledger info * * @returns Endless Ledger Info * * @example * const ledgerInfo = await endless.getLedgerInfo() * // an example of the returned data * ``` * { * "chain_id": 4, * "epoch": "8", * "ledger_version": "714", * "oldest_ledger_version": "0", * "ledger_timestamp": "1694695496521775", * "node_role": "validator", * "oldest_block_height": "0", * "block_height": "359", * "git_hash": "c82193f36f4e185fed9f68c4ad21f6c6dd390c6e" * } * ``` */ async getLedgerInfo(): Promise { return getLedgerInfo({ endlessConfig: this.config }); } /** * Queries for indexer service status * * @param args.durationSecs The interval between latest indexed tx time and service time * @returns Indexer status */ async getIndexerStatus(args?: { durationSecs?: number }): Promise { return getIndexerStatus({ endlessConfig: this.config, ...args }); } /** * Queries for the chain id * * @example * const chainId = await endless.getChainId() * * @returns The chain id */ async getChainId(): Promise { const result = await this.getLedgerInfo(); return result.chain_id; } /** * Queries for block by transaction version * * @example * const block = await endless.getBlockByVersion({ledgerVersion:5}) * * @param args.ledgerVersion Ledger version to lookup block information for * @param args.options.withTransactions If set to true, include all transactions in the block * * @returns Block information with optional transactions */ async getBlockByVersion(args: { ledgerVersion: AnyNumber; options?: { withTransactions?: boolean }; }): Promise { return getBlockByVersion({ endlessConfig: this.config, ...args, }); } /** * Get block by block height * * @example * const block = await endless.getBlockByVersion({blockHeight:5}) * * @param args.blockHeight Block height to lookup. Starts at 0 * @param args.options.withTransactions If set to true, include all transactions in the block * * @returns Block with optional transactions */ async getBlockByHeight(args: { blockHeight: AnyNumber; options?: { withTransactions?: boolean } }): Promise { return getBlockByHeight({ endlessConfig: this.config, ...args }); } /** * Queries for a Move view function * @param args.payload Payload for the view function * @param args.options.ledgerVersion The ledger version to query, if not provided it will get the latest version * * @example * const data = await endless.view({ * payload: { * function: "0x1::coin::balance", * typeArguments: ["0x1::endless_coin::EndlessCoin"], * functionArguments: [accountAddress], * } * }) * * @returns an array of Move values */ async view>(args: { payload: InputViewFunctionData; options?: LedgerVersionArg; }): Promise { return view({ endlessConfig: this.config, ...args }); } /** * Search coin or collection by name * * @param args.query Search keyword * @returns Search results */ async search(args: { query: string }): Promise { return search({ endlessConfig: this.config, ...args }); } }