caravan-bitcoin/caravan

Consolidate ReconstructedUtxos and Coin Types to Reduce Complexity

Aberta

#386 aberto em 1 de out. de 2025

 (6 comentários) (0 reação) (1 responsável)TypeScript (102 forks)auto 404
@caravan/coordinatorgood first issuehelp wanted

Métricas do repositório

Stars
 (85 estrelas)
Métricas de merge de PR
 (Mesclagem média 1d 2h) (1 fundiu PR em 30d)

Description

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

Guia do colaborador