postchain-client
Version:
Client library for accessing a Postchain node through REST.
79 lines (78 loc) • 6.86 kB
TypeScript
/// <reference types="node" />
import { Web3PromiEvent } from "../promiEvent/promiEvents";
import { GTX, RellOperation } from "../gtx/types";
import { BlockInfo, BlockInfoResponse, ClientConfig, Endpoint, KeyPair, NetworkSettings, Operation, SignedTransaction, Transaction, TransactionInfo, TransactionInfoResponse, TransactionStatusReponse, ClusterAnchoringConfirmation, TransactionReceipt, BufferId, AnchoringClientAndSystemBrid, StatusPolling, FailOverConfig, ClientCallback, RejectedTransactionResponse, RejectedTransaction } from "./types";
import { AnchoringStatus, ChainConfirmationLevel, FailoverStrategy } from "./enums";
import { NodeManager } from "./nodeManager";
import { IClient } from "./interface";
import { AnchoringTransaction } from "../ICCF/types";
import { RawGtv } from "../gtv/types";
import { Web3EventMap } from "../promiEvent/promiEventEmitter";
export declare function getClientConfigFromSettings(settings: NetworkSettings): Promise<ClientConfig>;
export declare function getMerkleHashVersionFromDapp(config: ClientConfig): Promise<number>;
export declare function validTxRid(txRID: Buffer): boolean;
interface NodeDiscoveryProps {
nodeManager: NodeManager;
directoryEndpointPool: Endpoint[];
failOverConfig?: FailOverConfig;
blockchainRid?: string;
blockchainIid?: number;
}
export declare function nodeDiscovery({ nodeManager, directoryEndpointPool, failOverConfig, blockchainRid, blockchainIid, }: NodeDiscoveryProps): Promise<string[] | null>;
export declare function getBlockchainApiUrls(directoryClient: IClient, blockchainRid: Buffer): Promise<string[] | null>;
export declare function convertToRellOperation(operations: Operation[]): RellOperation[];
export declare function getSerializedGTX(gtx: GTX): Buffer;
export declare function getGTXFromBufferOrTransactionOrOperation(transaction: SignedTransaction | Transaction | Operation, blockchainRid: BufferId): GTX;
export declare const callbackPromiseBuilder: <T, U = T>(reject: (reason?: Error | null) => void, resolve: (value: T | PromiseLike<T>) => void, callback?: ((error: Error | null, result: U | null) => void) | undefined) => ClientCallback<T>;
export declare const handlePostResponsePromisified: (error: Error | null, statusCode: number | null, rspBody: RawGtv | null | undefined) => Promise<void>;
export declare const formatTransactionInfoResponse: (transactionInfoResponse: TransactionInfoResponse) => TransactionInfo;
export declare const formatBlockInfoResponse: (blockInfoResponse: BlockInfoResponse) => BlockInfo;
export declare function formatRejectedTransactionFromResponse(rejectedTransactionResponse: RejectedTransactionResponse): RejectedTransaction;
export declare const isKeyPair: (keypair: unknown) => keypair is KeyPair;
export declare function getSystemClient(directoryNodeUrlPool: string[], directoryChainRid: string): Promise<IClient>;
export declare function getSystemAnchoringChain(directoryClient: IClient): Promise<Buffer>;
export declare const defaultFailoverConfig: {
strategy: FailoverStrategy.AbortOnError;
attemptsPerEndpoint: number;
attemptInterval: number;
unreachableDuration: number;
};
export declare const createEndpointObjects: (endpointPoolUrls: readonly string[]) => Endpoint[];
export declare const getUrlsFromEndpoints: (endpointPool: Endpoint[]) => string[];
export declare function awaitDappConfirmation(txRID: Buffer, dappStatusPolling: StatusPolling, getTransactionStatus: (txRID: Buffer) => Promise<TransactionStatusReponse>): Promise<TransactionStatusReponse>;
export declare function awaitClusterAnchoringChainConfirmation(txRID: Buffer, clusterAnchoringStatusPolling: StatusPolling, getClusterAnchoringTransactionConfirmation: (txRID: Buffer) => Promise<AnchoringTransaction | AnchoringStatus>): Promise<ClusterAnchoringConfirmation>;
export declare function handleDappConfirmations(transactionRid: Buffer, doStatusPolling: boolean, confirmationLevel: ChainConfirmationLevel, promiEvent: Web3PromiEvent<TransactionReceipt, Web3EventMap>, dappStatusPolling: StatusPolling, getTransactionStatus: () => Promise<TransactionStatusReponse>): Promise<TransactionReceipt>;
export declare function handleSystemConfirmations(transactionReceipt: TransactionReceipt, confirmationLevel: ChainConfirmationLevel, promiEvent: Web3PromiEvent<TransactionReceipt, Web3EventMap>, statusPollingConfig: {
dappStatusPolling: StatusPolling;
clusterAnchoringStatusPolling: StatusPolling;
systemAnchoringStatusPolling: StatusPolling;
}, anchoringClient: IClient, systemAnchoringChainBrid: string, getClusterAnchoringTransactionConfirmation: () => Promise<AnchoringTransaction | AnchoringStatus>, getSystemAnchoringTransactionConfirmation: (anchoredTxRid: Buffer, anchoringClient: IClient, systemAnchoringChainBrid: string) => Promise<AnchoringTransaction | null>): Promise<TransactionReceipt>;
export declare function getAnchoringClientAndSystemChainRid(client: IClient): Promise<AnchoringClientAndSystemBrid>;
export declare function getSystemAnchoringTransaction(dappClientEndpointPool: Endpoint[], anchoredTxRid: BufferId, anchoringClient: IClient, systemAnchoringChainRid: string, systemAnchoringStatusPolling: StatusPolling, merkleHashVersion: number): Promise<AnchoringTransaction | null>;
export declare function setStatusPolling(statusPolling?: Partial<StatusPolling>): StatusPolling;
export declare function linkPromiEvents(event1: Web3PromiEvent<TransactionReceipt, Web3EventMap>, event2: Web3PromiEvent<TransactionReceipt, Web3EventMap>): void;
/**
* @param error response error
* @param statusCode response status code
* @param responseObject the responsebody from the server
* @param callback the callback function to propagate the error and response back to the caller
*/
export declare function handleGetResponse<T>(error: Error | null | undefined, statusCode: number | null, responseObject: RawGtv | null | undefined, callback: ClientCallback<T>): void;
/**
* @param error response error
* @param statusCode response status code
* @param responseObject the responsebody from the server
* @param callback the callback function to propagate the error and response back to the caller
*/
export declare function handlePostResponse<T extends RawGtv>(error: Error | null | undefined, statusCode: number | null, responseObject: RawGtv | null | undefined, callback: ClientCallback<T>): void;
interface BlockchainRidFromIidPops {
endpointPool: Endpoint[];
chainId: number;
nodeManager: NodeManager;
failOverConfig?: FailOverConfig;
merkleHashVersion: number;
}
export declare function getBlockchainRidFromIid({ endpointPool, chainId, failOverConfig, nodeManager, }: BlockchainRidFromIidPops): Promise<string>;
export declare const sleep: (ms: number) => Promise<unknown>;
export declare function convertToPrintable(responseObject: unknown): string;
export {};