UNPKG

@hashgraph/sdk

Version:
128 lines (127 loc) 3.99 kB
/** * @typedef {import("./account/AccountId.js").default} AccountId * @typedef {import("./channel/Channel.js").default} Channel * @typedef {import("./channel/MirrorChannel.js").default} MirrorChannel * @typedef {import("./address_book/NodeAddress.js").default} NodeAddress */ /** * @template {Channel | MirrorChannel} ChannelT * @typedef {object} NewNode * @property {string | ManagedNodeAddress} address * @property {(address: string, cert?: string) => ChannelT} channelInitFunction */ /** * @template {Channel | MirrorChannel} ChannelT * @typedef {object} CloneNode * @property {ManagedNode<ChannelT>} node * @property {ManagedNodeAddress} address */ /** * @abstract * @template {Channel | MirrorChannel} ChannelT */ export default class ManagedNode<ChannelT extends Channel | MirrorChannel> { /** * @param {object} props * @param {NewNode<ChannelT>=} [props.newNode] * @param {CloneNode<ChannelT>=} [props.cloneNode] */ constructor(props?: { newNode?: NewNode<ChannelT> | undefined; cloneNode?: CloneNode<ChannelT> | undefined; }); _address: ManagedNodeAddress; /** @type {string=} */ _cert: string | undefined; /** @type {ChannelT | null} */ _channel: ChannelT | null; /** @type {(address: string, cert?: string) => ChannelT} */ _channelInitFunction: (address: string, cert?: string) => ChannelT; _lastUsed: number; _readmitTime: number; _useCount: number; _badGrpcStatusCount: number; _minBackoff: number; _maxBackoff: number; _currentBackoff: number; /** * @abstract * @returns {string} */ getKey(): string; /** * @param {string} ledgerId * @returns {this} */ setCert(ledgerId: string): this; /** * @returns {ManagedNodeAddress} */ get address(): ManagedNodeAddress; /** * @returns {number} */ get attempts(): number; /** * @returns {number} */ get minBackoff(): number; /** * @param {number} minBackoff * @returns {this} */ setMinBackoff(minBackoff: number): this; /** * @returns {number} */ get maxBackoff(): number; /** * @param {number} maxBackoff * @returns {this} */ setMaxBackoff(maxBackoff: number): this; getChannel(): ChannelT; __lastUsed: number | undefined; /** * Determines if this node is healthy by checking if this node hasn't been * in use for a the required `_currentBackoff` period. Since this looks at `this._lastUsed` * and that value is only set in the `wait()` method, any node that has not * returned a bad gRPC status will always be considered healthy. * * @returns {boolean} */ isHealthy(): boolean; increaseBackoff(): void; decreaseBackoff(): void; /** * @returns {number} */ getRemainingTime(): number; /** * This is only ever called if the node itself is down. * A node returning a transaction with a bad status code does not indicate * the node is down, and hence this method will not be called. * * @returns {Promise<void>} */ backoff(): Promise<void>; /** * @param {ManagedNode<*>} node * @returns {number} */ compare(node: ManagedNode<any>): number; close(): void; } export type AccountId = import("./account/AccountId.js").default; export type Channel = import("./channel/Channel.js").default; export type MirrorChannel = import("./channel/MirrorChannel.js").default; export type NodeAddress = import("./address_book/NodeAddress.js").default; export type NewNode<ChannelT extends Channel | MirrorChannel> = { address: string | ManagedNodeAddress; channelInitFunction: (address: string, cert?: string) => ChannelT; }; export type CloneNode<ChannelT extends Channel | MirrorChannel> = { node: ManagedNode<ChannelT>; address: ManagedNodeAddress; }; import ManagedNodeAddress from "./ManagedNodeAddress.js";