index.ts


Overview

`index.ts` serves as an aggregation and utility entry point within the project’s blockchain-related modules. Its primary purpose is to:

This file acts as a bridge between raw blockchain data structures and higher-level application logic, simplifying the integration and handling of blockchain events and transaction data.


Exported Entities

Re-exports

These re-exports allow external modules to import blockchain controller logic, data models, and websocket utilities from a single entry point.


Interfaces

1. NewBlock

Represents a new block event in the blockchain.

Property

Type

Description

height

number

The height (index) of the block in the blockchain.

hash

string

The unique hash identifier of the block.


2. NewTx

Represents a new blockchain transaction event related to a specific address.

Property

Type

Description

address

string

The blockchain address involved in the transaction.

tx

`Tx`

The transaction object (imported from `./models`).


3. SubscriptionResponse

Represents the response status for a subscription request over a websocket or API.

Property

Type

Description

subscribed

boolean

Indicates if the subscription was successful (`true`) or not (`false`).


4. WebsocketRepsonse

Represents the structure of a message received via websocket.

Property

Type

Description

id

string

Unique identifier of the websocket message.

data

`NewBlock` \

`NewTx` \

**Note:** There is a typographical error in the interface name: `WebsocketRepsonse` should likely be `WebsocketResponse`.


Function: getAddresses

function getAddresses(tx: Tx): Array<string>

Description

Extracts a unique set of all blockchain addresses referenced in a given transaction (`Tx`). It scans through the transaction’s inputs (`vin`), outputs (`vout`), and token transfers to collect all associated addresses.

Parameters

Returns

Detailed Behavior

Usage Example

import { getAddresses } from './index'
import { Tx } from './models'

const transaction: Tx = /* fetched or constructed transaction */

const addresses = getAddresses(transaction)
console.log(addresses)
// Output: ['addr1...', 'addr2...', ...] - unique addresses involved in the transaction

Important Implementation Details


Interaction with Other Modules


Mermaid Diagram: Structure of index.ts

classDiagram
    class index {
        <<interface>>
        +NewBlock
        +NewTx
        +SubscriptionResponse
        +WebsocketRepsonse
        --
        +getAddresses(tx: Tx): Array~string~
    }

    class Tx {
        <<imported>>
    }

    class Blockbook {
        <<exported>>
    }

    index ..> Tx : uses
    index ..> Blockbook : exports

Summary

`index.ts` is a critical integration file within the blockchain module, offering:

This design promotes modularity, type safety, and ease of use for other parts of the system interacting with blockchain data and events.