Background
Currently, our UTXO reconstruction logic involves an unnecessary three-step type conversion chain:
reconstructSingleUtxo returns a ReconstructedUtxos object
convertCaravanUtxoToCoin converts it to a Coin object
getUtxoFromCoin converts it back to a UTXO object
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
ReconstructedUtxos to Coin
- Adjust property names to match
Coin interface
- Derive
address from multisig.address
-
Update reconstructUtxosFromPendingTransactions
- Change return type to use
Coin[] instead of ReconstructedUtxos[]
- Update all internal references
-
Eliminate convertCaravanUtxoToCoin
- This function becomes unnecessary after consolidation
-
Update hook names and signatures:
- Consider renaming
useReconstructedUtxos to reflect coin terminology if appropriate
- Update
matchPsbtInputsToUtxos parameter types
-
Update buildUtxoFromSpendingTransaction
- Simplify by removing the conversion step
- Directly use reconstructed coin with
getUtxoFromCoin
Background
Currently, our UTXO reconstruction logic involves an unnecessary three-step type conversion chain:
reconstructSingleUtxoreturns aReconstructedUtxosobjectconvertCaravanUtxoToCoinconverts it to aCoinobjectgetUtxoFromCoinconverts it back to aUTXOobjectThis creates a confusing data flow and highlights unnecessary complexity in our type system.
Problem
The
ReconstructedUtxosandCointypes are conceptually the same thing with minor property naming differences:ReconstructedUtxos:
Coin
Having two types for essentially the same concept leads to:
Proposed Solution
Consolidate these types into a single
Cointype (or a unified type) that serves both purposes:Update
reconstructSingleUtxo→reconstructSingleCoinReconstructedUtxostoCoinCoininterfaceaddressfrommultisig.addressUpdate
reconstructUtxosFromPendingTransactionsCoin[]instead ofReconstructedUtxos[]Eliminate
convertCaravanUtxoToCoinUpdate hook names and signatures:
useReconstructedUtxosto reflect coin terminology if appropriatematchPsbtInputsToUtxosparameter typesUpdate
buildUtxoFromSpendingTransactiongetUtxoFromCoin