@btc-stamps/tx-builder
Version:
Transaction builder for Bitcoin Stamps and SRC-20 tokens with advanced UTXO selection
112 lines (106 loc) • 3.46 kB
TypeScript
import { U as UTXO } from './provider.interface-53Rg30ZJ.js';
/**
* Enhanced UTXO Selection Result Interface
* Provides structured responses for both success and failure cases
*/
/**
* Reasons why selection might fail
*/
declare enum SelectionFailureReason {
INSUFFICIENT_FUNDS = "INSUFFICIENT_FUNDS",
INSUFFICIENT_BALANCE = "INSUFFICIENT_BALANCE",
NO_UTXOS_AVAILABLE = "NO_UTXOS_AVAILABLE",
NO_UTXOS = "NO_UTXOS",
EXCEEDS_MAX_INPUTS = "EXCEEDS_MAX_INPUTS",
DUST_THRESHOLD_NOT_MET = "DUST_THRESHOLD_NOT_MET",
DUST_OUTPUT = "DUST_OUTPUT",
NO_SOLUTION_FOUND = "NO_SOLUTION_FOUND",
INVALID_OPTIONS = "INVALID_OPTIONS",
TIMEOUT = "TIMEOUT",
PROTECTED_UTXOS = "PROTECTED_UTXOS",
SELECTION_FAILED = "SELECTION_FAILED",
FEE_TOO_HIGH = "FEE_TOO_HIGH",
MAX_INPUTS_EXCEEDED = "MAX_INPUTS_EXCEEDED",
MIN_CONFIRMATIONS_NOT_MET = "MIN_CONFIRMATIONS_NOT_MET",
OPTIMIZATION_FAILED = "OPTIMIZATION_FAILED"
}
/**
* Successful selection result
*/
interface SelectionSuccess {
success: true;
inputs: UTXO[];
totalValue: number;
change: number;
fee: number;
wasteMetric?: number;
inputCount: number;
outputCount: number;
estimatedVSize: number;
effectiveFeeRate: number;
}
/**
* Failed selection result with debugging information
*/
interface SelectionFailure {
success: false;
reason: SelectionFailureReason;
message: string;
details?: {
availableBalance?: number;
requiredAmount?: number;
utxoCount?: number;
maxInputsAllowed?: number;
dustThreshold?: number;
attemptedStrategies?: string[];
minConfirmations?: number;
targetValue?: number;
feeRate?: number;
maxInputs?: number;
spendableCount?: number;
protectedCount?: number;
protectedBalance?: number;
};
}
/**
* Enhanced selection result that always provides structured feedback
*/
type EnhancedSelectionResult = SelectionSuccess | SelectionFailure;
/**
* UTXO Selection Strategy Interface
* Defines algorithms for selecting UTXOs for transactions
*/
type SelectionResult = EnhancedSelectionResult;
interface SelectionOptions {
targetValue: number;
feeRate: number;
longTermFeeRate?: number | undefined;
changeAddress?: string | undefined;
minConfirmations?: number | undefined;
maxInputs?: number | undefined;
dustThreshold?: number | undefined;
consolidate?: boolean | undefined;
protectedUTXODetector?: {
isProtected(utxo: UTXO): boolean;
} | undefined;
}
interface IUTXOSelector {
/**
* Select UTXOs for a transaction
* Always returns a structured result (never null)
*/
select(utxos: UTXO[], options: SelectionOptions): EnhancedSelectionResult;
/**
* Get the name of the selection algorithm
*/
getName(): string;
/**
* Estimate fee for given inputs and outputs
*/
estimateFee(numInputs: number, numOutputs: number, feeRate: number): number;
}
type SelectorAlgorithm = 'branch-and-bound' | 'knapsack' | 'single-random-draw' | 'blackjack' | 'accumulative' | 'fifo' | 'lifo' | 'waste-optimized';
interface SelectorFactory {
create(algorithm: SelectorAlgorithm): IUTXOSelector;
}
export type { EnhancedSelectionResult as E, IUTXOSelector as I, SelectionOptions as S, SelectionResult as a, SelectorAlgorithm as b, SelectionSuccess as c, SelectorFactory as d };