UNPKG

@xchainjs/xchain-litecoin

Version:

Custom Litecoin client and utilities used by XChainJS clients

137 lines (136 loc) 4.92 kB
import { AssetInfo, FeeRate } from '@xchainjs/xchain-client'; import { Address } from '@xchainjs/xchain-util'; import { Client as UTXOClient, PreparedTx, TxParams, UTXO, UtxoClientParams, UtxoSelectionPreferences } from '@xchainjs/xchain-utxo'; import * as Litecoin from 'bitcoinjs-lib'; /** * Default parameters for the Litecoin client. */ export declare const defaultLtcParams: UtxoClientParams; /** * Custom Litecoin client. */ declare abstract class Client extends UTXOClient { /** * Constructs a new `Client` with the provided parameters. * * @param {UtxoClientParams} params The parameters for initializing the client. */ constructor(params?: UtxoClientParams); /** * Returns information about the asset used by the client. * * @returns {AssetInfo} Information about the asset. */ getAssetInfo(): AssetInfo; /** * Validates the given Litecoin address. * * @param {string} address The Litecoin address to validate. * @returns {boolean} `true` if the address is valid, `false` otherwise. */ validateAddress(address: string): boolean; /** * Builds a Litecoin (LTC) transaction. * * @param {BuildParams} params The transaction build options. * @returns {Transaction} A promise that resolves to the PSBT (Partially Signed Bitcoin Transaction) and UTXOs (Unspent Transaction Outputs). * @deprecated This function will eventually be removed. Use `prepareTx` instead. */ buildTx({ amount, recipient, memo, feeRate, sender, }: TxParams & { feeRate: FeeRate; sender: Address; }): Promise<{ psbt: Litecoin.Psbt; utxos: UTXO[]; inputs: UTXO[]; }>; /** * Prepares a Litecoin (LTC) transaction. * * @deprecated Use `prepareTxEnhanced` instead for better UTXO selection and error handling. * @param {TxParams&Address&FeeRate&boolean} params The transfer options. * @returns {PreparedTx} A promise that resolves to the raw unsigned transaction. */ prepareTx({ sender, memo, amount, recipient, feeRate, }: TxParams & { sender: Address; feeRate: FeeRate; spendPendingUTXO?: boolean; }): Promise<PreparedTx & { utxos: UTXO[]; inputs: UTXO[]; }>; /** * Compile memo. * * @param {string} memo The memo to be compiled. * @returns {Buffer} The compiled memo. */ protected compileMemo(memo: string): Buffer; /** * Calculates the transaction fee based on the provided UTXOs, fee rate, and optional compiled memo. * * @param {UTXO[]} inputs The The UTXOs used as inputs in the transaction. * @param {FeeRate} feeRate The fee rate. * @param {Buffer} data The compiled memo (Optional). * @returns {number} The calculated fee amount. */ protected getFeeFromUtxos(inputs: UTXO[], feeRate: FeeRate, data?: Buffer | null): number; /** * Build transaction with enhanced UTXO selection */ buildTxEnhanced({ amount, recipient, memo, feeRate, sender, spendPendingUTXO, utxoSelectionPreferences, selectedUtxos, }: TxParams & { feeRate: FeeRate; sender: Address; spendPendingUTXO?: boolean; utxoSelectionPreferences?: UtxoSelectionPreferences; selectedUtxos?: UTXO[]; }): Promise<{ psbt: Litecoin.Psbt; utxos: UTXO[]; inputs: UTXO[]; }>; /** * Prepare transaction with enhanced UTXO selection */ prepareTxEnhanced({ sender, memo, amount, recipient, spendPendingUTXO, feeRate, utxoSelectionPreferences, selectedUtxos, }: TxParams & { sender: Address; feeRate: FeeRate; spendPendingUTXO?: boolean; utxoSelectionPreferences?: UtxoSelectionPreferences; selectedUtxos?: UTXO[]; }): Promise<PreparedTx>; /** * Send maximum possible amount (sweep) */ sendMax({ sender, recipient, memo, feeRate, spendPendingUTXO, utxoSelectionPreferences, selectedUtxos, }: { sender: Address; recipient: Address; memo?: string; feeRate: FeeRate; spendPendingUTXO?: boolean; utxoSelectionPreferences?: UtxoSelectionPreferences; selectedUtxos?: UTXO[]; }): Promise<{ psbt: Litecoin.Psbt; utxos: UTXO[]; inputs: UTXO[]; maxAmount: number; fee: number; }>; /** * Prepare max send transaction */ prepareMaxTx({ sender, recipient, memo, feeRate, spendPendingUTXO, utxoSelectionPreferences, selectedUtxos, }: { sender: Address; recipient: Address; memo?: string; feeRate: FeeRate; spendPendingUTXO?: boolean; utxoSelectionPreferences?: UtxoSelectionPreferences; selectedUtxos?: UTXO[]; }): Promise<PreparedTx & { maxAmount: number; fee: number; }>; } export { Client };