ElectrumCluster

ElectrumCluster

High-level electrum client that provides transparent load balancing, confidence checking and/or low-latency polling.

Constructor

new ElectrumCluster(application, version, confidence, distribution, order, timeout, pingInterval)

Parameters:
Name Type Description
application string your application name, used to identify to the electrum hosts.
version string protocol version to use with the hosts.
confidence number wait for this number of hosts to provide identical results.
distribution number request information from this number of hosts.
order ClusterOrder select hosts to communicate with in this order.
timeout number how long network delays we will wait for before taking action, in milliseconds.
pingInterval number the time between sending pings to the electrum host, in milliseconds.

Methods

(async) addServer(host, port, scheme, autoConnect)

Adds a server to the cluster.
Parameters:
Name Type Default Description
host string fully qualified domain name or IP number of the host.
port number the TCP network port of the host.
scheme TransportScheme the transport scheme to use for connection
autoConnect boolean true flag indicating whether the server should automatically connect (default true)
Throws:
if the cluster's version is not a valid version string.
Type
Error
Returns:
a promise that resolves when the connection has been initiated.

(async) ready()

Provides a method to check or wait for the cluster to become ready.
Returns:
a promise that resolves when the required servers are available.

(async) request(method, …parameters)

Calls a method on the remote server with the supplied parameters.
Parameters:
Name Type Attributes Description
method string name of the method to call.
parameters string <repeatable>
one or more parameters for the method.
Throws:
  • if not enough clients are connected
    Type
    Error
  • if no response is received with sufficient integrity
    Type
    Error
Returns:
a promise that resolves with the result of the method.

(async) shutdown(retainSubscriptions)

Disconnects all servers from the cluster. Removes all event listeners and handlers from all underlying clients and connections. This includes all active subscriptions, unless retainSubscriptions is set to true.
Parameters:
Name Type Default Description
retainSubscriptions boolean false retain subscription data so they will be restored on reconnection.
Returns:
a list with the disconnection result for every client

(async) startup()

Connects all servers from the cluster and attaches event listeners and handlers for all underlying clients and connections.
Throws:
if the cluster's version is not a valid version string.
Type
Error

(async) subscribe(callback, method, …parameters)

Subscribes to the method at the cluster and attaches the callback function to the event feed.
Parameters:
Name Type Attributes Description
callback function a function that should get notification messages.
method string one of the subscribable methods the server supports.
parameters string <repeatable>
one or more parameters for the method.
Throws:
  • if not enough clients are connected
    Type
    Error
  • if no response is received with sufficient integrity for the initial request
    Type
    Error
Returns:
a promise resolving to true when the subscription is set up.

(async) unsubscribe(callback, method, …parameters)

Unsubscribes to the method at the cluster and removes any callback functions when there are no more subscriptions for the method.
Parameters:
Name Type Attributes Description
callback function a function that has previously been subscribed for this method.
method string one of the subscribable methods the server supports.
parameters string <repeatable>
one or more parameters for the method.
Throws:
if, for any of the clients, no subscriptions exist for the combination of the passed `callback`, `method` and `parameters.
Type
Error
Returns:
a promise resolving to true when the subscription has been cancelled.

Events

degraded

Triggers when the cluster loses a connection and can no longer satisfy the cluster distribution policy.

disabled

Triggers when the cluster loses a connection and can no longer satisfy the cluster confidence policy.

ready

Triggers when the cluster connects to enough servers to satisfy both the cluster confidence and distribution policies.