Skip to content

Consolidate ReconstructedUtxos and Coin Types to Reduce Complexity #386

@Legend101Zz

Description

@Legend101Zz

Background

Currently, our UTXO reconstruction logic involves an unnecessary three-step type conversion chain:

  1. reconstructSingleUtxo returns a ReconstructedUtxos object
  2. convertCaravanUtxoToCoin converts it to a Coin object
  3. 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:

  1. Update reconstructSingleUtxoreconstructSingleCoin

    • Change return type from ReconstructedUtxos to Coin
    • Adjust property names to match Coin interface
    • Derive address from multisig.address
  2. Update reconstructUtxosFromPendingTransactions

    • Change return type to use Coin[] instead of ReconstructedUtxos[]
    • Update all internal references
  3. Eliminate convertCaravanUtxoToCoin

    • This function becomes unnecessary after consolidation
  4. Update hook names and signatures:

    • Consider renaming useReconstructedUtxos to reflect coin terminology if appropriate
    • Update matchPsbtInputsToUtxos parameter types
  5. Update buildUtxoFromSpendingTransaction

    • Simplify by removing the conversion step
    • Directly use reconstructed coin with getUtxoFromCoin

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions