UTXO API Controllers

Purpose

This component addresses the unique requirements of UTXO-based blockchains such as Bitcoin. Unlike account-based chains, UTXO blockchains track spendable outputs rather than balances directly, necessitating specialized logic to retrieve account details, transaction history, unspent outputs, and raw transaction data. The UTXO API Controllers provide a standardized RESTful interface for clients to interact with these features, abstracting blockchain-specific complexities while maintaining consistency within the unified API layer.

Functionality

The UTXO API Controllers expose several key workflows essential for UTXO blockchain interactions:

These workflows are implemented by the `UTXO` controller class delegating to a `Service` layer that interacts with the Blockbook indexer and blockchain RPC endpoints.

Example Controller Method

@Get('account/{pubkey}/txs')
async getTxHistory(@Path() pubkey: string, @Query() cursor?: string, @Query() pageSize = 10): Promise<TxHistory> {
  return UTXO.service.getTxHistory(pubkey, cursor, pageSize)
}

This method handles paginated transaction history requests by forwarding parameters to the service, which manages cursor decoding, pagination logic, and data transformation.

Key Service Responsibilities

Integration

UTXO API Controllers form a critical submodule within the broader Unified API Layer. They complement sibling subtopics such as the EVM API Controllers by specializing in UTXO blockchain semantics and data models. The `Service` class depends on the Blockbook indexer component to retrieve cached blockchain data efficiently, while the controller layer exposes this data via the REST API.

This subtopic introduces UTXO-specific handling that is not covered by the parent topic or EVM-focused subtopics, such as managing extended public keys (xpubs), UTXO sets, and raw transaction broadcasting via RPC. It integrates seamlessly with shared infrastructure like error handling, logging, and API routing established in the parent Unified API Layer.

Diagram

The following flowchart illustrates the core process of handling a transaction history request in the UTXO API Controllers, highlighting the interaction between client requests, controller methods, service logic, and external blockchain data sources.

flowchart TD
  Client[Client Request: Tx History] --> Controller[UTXO Controller]
  Controller --> Service[UTXO Service]
  Service -->|Is XPUB?| Decision{Is XPUB?}
  Decision -->|Yes| BlockbookXpub[Blockbook getXpub API]
  Decision -->|No| BlockbookAddr[Blockbook getAddress API]
  BlockbookXpub --> DataFormat[Format Tx Data]
  BlockbookAddr --> DataFormat
  DataFormat --> Pagination[Handle Pagination & Cursor]
  Pagination --> Response[Return Paginated TxHistory]
  Response --> Client

This flow highlights the decision logic for address vs. xpub handling and the layered processing before returning the response.


This subtopic encapsulates the UTXO blockchain-specific API logic, enabling clients to efficiently query and operate on UTXO-based blockchains within the unified API framework.