Options
All
  • Public
  • Public/Protected
  • All
Menu
description

This class serves as a connection handler for nodes on dHealth Network. It uses a node's REST interface to fetch data directly from the node.

Note that the connection is done upon instanciation. A possible refactor of this class may move this process such that the connection adapter is not always considered "connected", as is currently the case.

since

v0.1.0

Hierarchy

  • NetworkService

Index

Constructors

  • new NetworkService(configService: ConfigService<Record<string, unknown>, false>): NetworkService
  • Constructs an instance of the network service and connects to the configured defaultNode (config/network.json). Note that connection handling is currently automatic and executed upon instanciation of network service objects.

    access

    public

    Parameters

    • configService: ConfigService<Record<string, unknown>, false>

    Returns NetworkService

Properties

blockRepository: BlockRepository

The blocks repository that permits to execute REST requests on the /blocks namespace.

access

public

var

{BlockRepository}

chainRepository: ChainRepository

The chain repository that permits to execute REST requests on the /chain namespace.

access

public

var

{ChainRepository}

currentNetwork: NetworkConnectionPayload

The information related to the connected network. This is necessary to connect to other nodes of the network.

access

protected

var

{NetworkConnectionPayload}

The currently connected node.

access

protected

var

{NodeConnectionPayload}

httpService: HttpRequestHandler

This class' HTTP service. It's a handler for HTTP requests and contains methods for executing remote API calls, e.g. calling a GET HTTP API endpoint.

access

protected

var

{HttpRequestHandler}

nodeRepository: NodeRepository

The node repository that permits to execute REST requests on the /node namespace.

access

public

var

{NodeRepository}

repositoryFactoryHttp: RepositoryFactoryHttp

The repository factory used to communicate with the connected node's REST interface.

access

public

var

{RepositoryFactoryHttp}

transactionRepository: TransactionRepository

The transaction repository that permits to execute REST requests on the /transaction namespace.

access

public

var

{TransactionRepository}

Methods

  • delegatePromises<ResponseType>(promises: Promise<ResponseType>[], countTrials?: number): Promise<ResponseType[]>
  • This method forwards the execution of promises using Promise.all() and given request failure, connects to a different node that is currently in a healthy state.

    Note that this method debounces the API calls such that requests to a node are done at a maximum pace of 3 requests in a second.

    async
    access

    public

    Type Parameters

    • ResponseType

    Parameters

    • promises: Promise<ResponseType>[]

      An array of promises that will be executed.

    • countTrials: number = 0

    Returns Promise<ResponseType[]>

    An array of results as promised.

  • getChainInfo(): Promise<ChainInfo>
  • Public helper method to retrieve the network parameters from the runtime configuration. This is helpful to create new adapters that connect to nodes on dHealth Network.

    This method is used internally to populate the currentNetwork class property and can be used whenever network parameters must be fetched from the runtime configuration.

    Returns NetworkConnectionPayload

  • getNetworkCurrency(currencyMosaicId: string, tokenDivisibility: number): Currency
  • Public helper method to retrieve the network currenciy from the runtime configuration. This is helpful to create new adapters that connect to nodes on dHealth Network and to avoid extra requests to the node.

    This method is used internally to populate the networkCurrencies field in the currentNetwork class property and can be used whenever network currencies information is necessary.

    Parameters

    • currencyMosaicId: string
    • tokenDivisibility: number

    Returns Currency

  • Helper method to pick a healthy and available node from the runtime configuration. If none of the configured nodes is currently in a healthy state, this method will use the http://peers.dhealth.cloud:7903/network/nodes endpoint instead.

    Note that this method executes a call to the node's API using the endpoint /node/health to determine the health state of selected nodes. As of now, the nodes that are added to the runtime configuration will be iterated in a sequential and ascending order.

    async
    access

    protected

    Returns Promise<NodeConnectionPayload>

Generated using TypeDoc