Consolidate ReconstructedUtxos and Coin Types to Reduce Complexity
#386 创建于 2025年10月1日
仓库指标
- 星标
- (85 个星标)
- PR 合并指标
- (PR 指标待抓取)
描述
Background
Currently, our UTXO reconstruction logic involves an unnecessary three-step type conversion chain:
reconstructSingleUtxoreturns aReconstructedUtxosobjectconvertCaravanUtxoToCoinconverts it to aCoinobjectgetUtxoFromCoinconverts it back to aUTXOobject
This creates a confusing data flow and highlights unnecessary complexity in our type system.
Problem
The ReconstructedUtxos and Coin types are conceptually the same thing with minor property naming differences:
ReconstructedUtxos:
{
txid: string;
index: number;
amountSats: string;
amount: string;
confirmed: boolean;
transactionHex: string;
multisig: any;
bip32Path: string;
change: boolean;
}
Coin
{
prevTxId: string;
vout: number;
address: string;
value: string;
prevTxHex: string;
slice?: Slice;
}
Having two types for essentially the same concept leads to:
- Unnecessary conversions between types
- Harder maintenance - changes must be made in multiple places
- Cognitive overhead - developers must understand both types and conversion logic
- Reduced code clarity - the conversion chain makes the logic hard to follow
Proposed Solution
Consolidate these types into a single Coin type (or a unified type) that serves both purposes:
-
Update
reconstructSingleUtxo→reconstructSingleCoin- Change return type from
ReconstructedUtxostoCoin - Adjust property names to match
Coininterface - Derive
addressfrommultisig.address
- Change return type from
-
Update
reconstructUtxosFromPendingTransactions- Change return type to use
Coin[]instead ofReconstructedUtxos[] - Update all internal references
- Change return type to use
-
Eliminate
convertCaravanUtxoToCoin- This function becomes unnecessary after consolidation
-
Update hook names and signatures:
- Consider renaming
useReconstructedUtxosto reflect coin terminology if appropriate - Update
matchPsbtInputsToUtxosparameter types
- Consider renaming
-
Update
buildUtxoFromSpendingTransaction- Simplify by removing the conversion step
- Directly use reconstructed coin with
getUtxoFromCoin