import { Transaction } from "@interlay/esplora-btc-api"; import { AxiosResponse } from "axios"; import { Bytes } from "@polkadot/types"; import Big from "big.js"; export declare type TxStatus = { confirmed: boolean; confirmations: number; }; export declare type TxOutput = { scriptpubkey: string; scriptpubkeyAsm: string; scriptpubkeyType: string; scriptpubkeyAddress: string; value: number; }; export declare type TxInput = { txId: string; vout: number; isCoinbase: boolean; scriptsig: string; scriptsigAsm: string; innerRedeemscriptAsm: string; innerWitnessscriptAsm: string; sequence: number; witness: string[]; prevout: TxOutput; }; /** * Bitcoin Core API * @category Bitcoin Core */ export interface ElectrsAPI { /** * @returns The block hash of the latest Bitcoin block */ getLatestBlock(): Promise; /** * @returns The height of the latest Bitcoin block */ getLatestBlockHeight(): Promise; /** * @param txid The ID of a Bitcoin transaction * @returns The merkle inclusion proof for the transaction using bitcoind's merkleblock format. */ getMerkleProof(txid: string): Promise; /** * @param txid The ID of a Bitcoin transaction * @returns A TxStatus object, containing the confirmation status and number of confirmations */ getTransactionStatus(txid: string): Promise; /** * @param txid The ID of a Bitcoin transaction * @returns The height of the block the transaction was included in. If the block has not been confirmed, returns undefined. */ getTransactionBlockHeight(txid: string): Promise; /** * @param txid The ID of a Bitcoin transaction * @returns The raw transaction data, represented as a hex string */ getRawTransaction(txid: string): Promise; /** * Fetch the first bitcoin transaction ID based on the OP_RETURN field, recipient and amount. * Throw an error unless there is exactly one transaction with the given opcode. * * @remarks * Performs the lookup using an external service, Esplora. Requires the input string to be a hex * * @param opReturn Data string used for matching the OP_CODE of Bitcoin transactions * @param recipientAddress Match the receiving address of a transaction that contains said op_return * @param amount Match the amount (in BTC) of a transaction that contains said op_return and recipientAddress. * This parameter is only considered if `recipientAddress` is defined. * * @returns A Bitcoin transaction ID */ getTxIdByOpReturn(opReturn: string, recipientAddress?: string, amount?: Big): Promise; /** * Fetch the last bitcoin transaction ID based on the recipient address and amount. * Throw an error if no such transaction is found. * * @remarks * Performs the lookup using an external service, Esplora * * @param recipientAddress Match the receiving address of a UTXO * @param amountAsBTC Match the amount (in BTC) of a UTXO that contains said recipientAddress. * * @returns A Bitcoin transaction ID */ getTxIdByRecipientAddress(recipientAddress: string, amountAsBTC?: Big): Promise; /** * Fetch the Bitcoin transaction that matches the given TxId * * @remarks * Performs the lookup using an external service, Esplora * * @param txid A Bitcoin transaction ID * * @returns A Bitcoin Transaction object */ getTx(txid: string): Promise; /** * Fetch the Bitcoin UTXO amount that matches the given TxId and recipient * * @remarks * Performs the lookup using an external service, Esplora * * @param txid A Bitcoin transaction ID * @param recipient A Bitcoin scriptpubkey address * * @returns A UTXO amount if found, 0 otherwise */ getUtxoAmount(txid: string, recipient: string): Promise; /** * Get the parsed (as Bytes) merkle proof and raw transaction * * @remarks * Performs the lookup using an external service, Esplora * * @param txid A Bitcoin transaction ID * * @returns A tuple of Bytes object, representing [merkleProof, rawTx] */ getParsedExecutionParameters(txid: string): Promise<[Bytes, Bytes]>; /** * Return a promise that either resolves to the first txid with the given opreturn `data`, * or rejects if the `timeout` has elapsed. * * @remarks * Every 5 seconds, performs the lookup using an external service, Esplora * * @param data The opReturn of the bitcoin transaction * @param timeoutMs The duration until the Promise times out (in milliseconds) * @param retryIntervalMs The time to wait (in milliseconds) between retries * * @returns The Bitcoin txid */ waitForOpreturn(data: string, timeoutMs: number, retryIntervalMs: number): Promise; } export declare class DefaultElectrsAPI implements ElectrsAPI { private blockApi; private txApi; private scripthashApi; private addressApi; constructor(network?: string); getLatestBlock(): Promise; getLatestBlockHeight(): Promise; getMerkleProof(txid: string): Promise; getTx(txid: string): Promise; getUtxoAmount(txid: string, recipient: string): Promise; getTxIdByRecipientAddress(recipientAddress: string, amount?: Big): Promise; /** * Check if a given UTXO has at least `amountAsBTC` * * @param vout UTXO object * @param amountAsBTC (Optional) Amount the recipient must receive * @returns Boolean value */ private utxoHasAtLeastAmount; getTxIdByOpReturn(opReturn: string, recipientAddress?: string, amount?: Big): Promise; waitForOpreturn(data: string, timeoutMs: number, retryIntervalMs: number): Promise; /** * Check if a given UTXO sends at least `amountAsBTC` to a certain `recipientAddress` * * @param vout UTXO object * @param recipientAddress (Optional) Address of recipient * @param amountAsBTC (Optional) Amount the recipient must receive. This parameter is only considered if the * `recipientAddress` is defined too * @returns Boolean value */ private txOutputHasRecipientAndAmount; /** * Broadcasts a transaction to the Bitcoin network configured in the constructor * @param hex A hex-encoded raw transaction to be broadcast to the Bitcoin blockchain * @returns The txid of the transaction */ broadcastRawTransaction(hex: string): Promise>; getTransactionStatus(txid: string): Promise; getTransactionBlockHeight(txid: string): Promise; getParsedExecutionParameters(txid: string): Promise<[Bytes, Bytes]>; getRawTransaction(txid: string): Promise; /** * Use the TxAPI to get the confirmationation * @param txid The ID of a Bitcoin transaction * @returns A Status object, containing transaction settlement information */ private getTxStatus; /** * Parse an AxiosResponse Promise * @param response A generic AxiosResponse Promise * @returns The data in the response */ getData(response: Promise>): Promise; }