// Copyright BigchainDB GmbH and BigchainDB contributors // SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0) // Code is Apache-2.0 and docs are CC-BY-4.0 import type { RequestConfig } from './baseRequest'; import type { Node } from './request'; import type Transport from './transport'; import type { CreateTransaction, TransactionOperations, TransferTransaction, TransactionCommon, } from './transaction'; declare const DEFAULT_NODE = 'http://localhost:9984/api/v1/'; declare const DEFAULT_TIMEOUT = 20000; // The default value is 20 seconds export interface InputNode { endpoint: string; } export type AssetResult = { id: string; data: Record; }; export type MetadataResult = { id: string; metadata: Record; }; export enum Endpoints { blocks = 'blocks', blocksDetail = 'blocksDetail', outputs = 'outputs', transactions = 'transactions', transactionsSync = 'transactionsSync', transactionsAsync = 'transactionsAsync', transactionsCommit = 'transactionsCommit', transactionsDetail = 'transactionsDetail', assets = 'assets', metadata = 'metadata', } export interface EndpointsUrl { [Endpoints.blocks]: 'blocks'; [Endpoints.blocksDetail]: 'blocks/%(blockHeight)s'; [Endpoints.outputs]: 'outputs'; [Endpoints.transactions]: 'transactions'; [Endpoints.transactionsSync]: 'transactions?mode=sync'; [Endpoints.transactionsAsync]: 'transactions?mode=async'; [Endpoints.transactionsCommit]: 'transactions?mode=commit'; [Endpoints.transactionsDetail]: 'transactions/%(transactionId)s'; [Endpoints.assets]: 'assets'; [Endpoints.metadata]: 'metadata'; } export interface EndpointsResponse< O = TransactionOperations.CREATE, A = Record, M = Record > { [Endpoints.blocks]: number[]; [Endpoints.blocksDetail]: { height: number; transactions: (CreateTransaction | TransferTransaction)[]; }; [Endpoints.outputs]: { transaction_id: string; output_index: number; }[]; [Endpoints.transactions]: O extends TransactionOperations.CREATE ? CreateTransaction[] : O extends TransactionOperations.TRANSFER ? TransferTransaction[] : (CreateTransaction | TransferTransaction)[]; [Endpoints.transactionsSync]: O extends TransactionOperations.CREATE ? CreateTransaction : TransferTransaction; [Endpoints.transactionsAsync]: O extends TransactionOperations.CREATE ? CreateTransaction : TransferTransaction; [Endpoints.transactionsCommit]: O extends TransactionOperations.CREATE ? CreateTransaction : TransferTransaction; [Endpoints.transactionsDetail]: O extends TransactionOperations.CREATE ? CreateTransaction : TransferTransaction; [Endpoints.assets]: AssetResult[]; [Endpoints.metadata]: MetadataResult[]; } export default class Connection { private transport: Transport; private normalizedNodes: Node[]; private headers: Record; constructor( nodes: string | InputNode | (string | InputNode)[], headers?: Record, timeout?: number ); static normalizeNode( node: string | InputNode, headers: Record ): Node; static getApiUrls(endpoint: E): EndpointsUrl[E]; private _req>( path: EndpointsUrl[E], options: RequestConfig ): Promise; getBlock( blockHeight: number | string ): Promise; getTransaction( transactionId: string ): Promise[Endpoints.transactionsDetail]>; listBlocks( transactionId: string ): Promise; listOutputs( publicKey: string, spent?: boolean ): Promise; listTransactions( assetId: string, operation?: TransactionOperations ): Promise[Endpoints.transactions]>; postTransaction< O extends TransactionOperations = TransactionOperations.CREATE, A = Record, M = Record >( transaction: TransactionCommon ): Promise[Endpoints.transactionsCommit]>; postTransactionSync< O extends TransactionOperations = TransactionOperations.CREATE, A = Record, M = Record >( transaction: TransactionCommon ): Promise[Endpoints.transactionsSync]>; postTransactionAsync< O extends TransactionOperations = TransactionOperations.CREATE, A = Record, M = Record >( transaction: TransactionCommon ): Promise[Endpoints.transactionsAsync]>; postTransactionCommit< O extends TransactionOperations = TransactionOperations.CREATE, A = Record, M = Record >( transaction: TransactionCommon ): Promise[Endpoints.transactionsCommit]>; searchAssets( search: string, limit?: number ): Promise; searchMetadata( search: string, limit?: number ): Promise; }