import { Transaction as ElectrsTransaction } from "@interlay/esplora-btc-api"; import { AxiosResponse } from "axios"; import { BitcoinAmount } from "@interlay/monetary-js"; import { BitcoinMerkleProof } from "../utils"; import { Transaction as BitcoinTransaction } from "bitcoinjs-lib"; import { TxStatus } from "../types"; export declare const MAINNET_ESPLORA_BASE_PATH = "https://btc-mainnet.interlay.io"; export declare const TESTNET_ESPLORA_BASE_PATH = "https://btc-testnet.interlay.io"; export declare const REGTEST_ESPLORA_BASE_PATH = "http://localhost:3002"; /** * 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, plus block height if * the tx is included in the blockchain */ 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?: BitcoinAmount): Promise; /** * Fetch the bitcoin transaction ID with the largest payment based on the recipient address. * Throw an error if no transactions are found. * * @remarks * Performs the lookup using an external service, Esplora * * @param recipientAddress Match the receiving address of a transaction output * * @returns A Bitcoin transaction ID */ getLargestPaymentToRecipientAddressTxId(recipientAddress: string): Promise; /** * Fetch the earliest/oldest 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 transaction output * @param amount Match the amount (in BTC) of a transaction output that contains said recipientAddress. * * @returns A Bitcoin transaction ID * @deprecated For most cases where this is used today, {@link getLargestPaymentToRecipientAddressTxId} is better suited. */ getEarliestPaymentToRecipientAddressTxId(recipientAddress: string, amount?: BitcoinAmount): 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 representing [merkleProof, transaction] */ getParsedExecutionParameters(txid: string): Promise<[BitcoinMerkleProof, BitcoinTransaction]>; /** * Returns tx id of the coinbase tx of block in which `userTxId` was included. * * @param userTxId User tx ID which block's txId will be returned. * @returns {string} Tx ID of coinbase transaction or undefined if block was not found. */ getCoinbaseTxId(userTxId: string): Promise; /** * 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; /** * @param txid The ID of a Bitcoin transaction * @returns A TxStatus object, containing the confirmation status and number of confirmations, plus block height if * the tx is included in the blockchain */ waitForTxInclusion(txid: 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; getLargestPaymentToRecipientAddressTxId(recipientAddress: string): Promise; getEarliestPaymentToRecipientAddressTxId(recipientAddress: string, amount?: BitcoinAmount): 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 txoHasAtLeastAmount; getTxIdByOpReturn(opReturn: string, recipientAddress?: string, amount?: BitcoinAmount): Promise; waitForOpreturn(data: string, timeoutMs: number, retryIntervalMs: number): Promise; waitForTxInclusion(txid: 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<[BitcoinMerkleProof, BitcoinTransaction]>; getRawTransaction(txid: string): Promise; getCoinbaseTxId(userTxId: 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; }