From f24fb51da94350f35bf9d28e802c95f998020d8c Mon Sep 17 00:00:00 2001 From: Nodari Chkuaselidze Date: Mon, 20 Jan 2025 11:34:40 +0400 Subject: [PATCH] lib: don't use public class fields usage. --- lib/client/node.js | 4 ++-- lib/client/wallet.js | 30 +++++++++++++----------------- lib/wallet/nodeclient.js | 6 ++---- lib/wallet/nullclient.js | 2 +- lib/wallet/txdb.js | 4 +--- lib/wallet/walletdb.js | 3 +++ test/util/node-context.js | 13 ++++--------- test/util/nodes-context.js | 4 +--- 8 files changed, 27 insertions(+), 39 deletions(-) diff --git a/lib/client/node.js b/lib/client/node.js index dd4cc12b7..fac54b69b 100644 --- a/lib/client/node.js +++ b/lib/client/node.js @@ -10,7 +10,7 @@ // Don't introduce any unnecessary dependencies to this. const assert = require('bsert'); -const {Client} = require('bcurl'); +const bcurl = require('bcurl'); /** * Node Client @@ -18,7 +18,7 @@ const {Client} = require('bcurl'); * @extends {bcurl.Client} */ -class NodeClient extends Client { +class NodeClient extends bcurl.Client { /** * Creat a node client. * @param {Object?} options diff --git a/lib/client/wallet.js b/lib/client/wallet.js index 699cc848e..571d224cd 100644 --- a/lib/client/wallet.js +++ b/lib/client/wallet.js @@ -11,7 +11,7 @@ const assert = require('bsert'); const EventEmitter = require('events'); -const {Client} = require('bcurl'); +const bcurl = require('bcurl'); /** * Wallet Client @@ -19,7 +19,7 @@ const {Client} = require('bcurl'); * @extends {bcurl.Client} */ -class WalletClient extends Client { +class WalletClient extends bcurl.Client { /** * Create a wallet client. * @param {Object?} options @@ -32,8 +32,6 @@ class WalletClient extends Client { /** * Open the client. - * @private - * @returns {Promise} */ init() { @@ -878,29 +876,27 @@ class WalletClient extends Client { */ class Wallet extends EventEmitter { - /** @type {WalletClient} */ - client; - - /** @type {WalletClient} */ - parent; - - /** @type {String} */ - id; - - /** @type {String} */ - token; - /** * Create a wallet client. - * @param {Object?} options + * @param {WalletClient} parent + * @param {String} id + * @param {String} [token] */ constructor(parent, id, token) { super(); + + /** @type {WalletClient} */ this.parent = parent; + + /** @type {WalletClient} */ this.client = parent.clone(); this.client.token = token; + + /** @type {String} */ this.id = id; + + /** @type {String} */ this.token = token; } diff --git a/lib/wallet/nodeclient.js b/lib/wallet/nodeclient.js index 4a98ea33d..524d2972e 100644 --- a/lib/wallet/nodeclient.js +++ b/lib/wallet/nodeclient.js @@ -18,9 +18,6 @@ const AsyncEmitter = require('bevent'); */ class NodeClient extends AsyncEmitter { - /** @type {Node} */ - node; - /** * Create a node client. * @constructor @@ -30,6 +27,7 @@ class NodeClient extends AsyncEmitter { constructor(node) { super(); + /** @type {Node} */ this.node = node; this.network = node.network; this.filter = null; @@ -78,7 +76,7 @@ class NodeClient extends AsyncEmitter { * @returns {Promise} */ - async open(options) { + async open() { assert(!this.opened, 'NodeClient is already open.'); this.opened = true; setImmediate(() => this.emit('connect')); diff --git a/lib/wallet/nullclient.js b/lib/wallet/nullclient.js index 03cb521ea..a27d6d968 100644 --- a/lib/wallet/nullclient.js +++ b/lib/wallet/nullclient.js @@ -36,7 +36,7 @@ class NullClient extends EventEmitter { * @returns {Promise} */ - async open(options) { + async open() { assert(!this.opened, 'NullClient is already open.'); this.opened = true; setImmediate(() => this.emit('connect')); diff --git a/lib/wallet/txdb.js b/lib/wallet/txdb.js index 9ca75cedd..7d0b92ca0 100644 --- a/lib/wallet/txdb.js +++ b/lib/wallet/txdb.js @@ -58,9 +58,6 @@ const UNCONFIRMED_HEIGHT = 0xffffffff; */ class TXDB { - /** @type {WalletDB} */ - wdb; - /** * Create a TXDB. * @constructor @@ -69,6 +66,7 @@ class TXDB { */ constructor(wdb, wid) { + /** @type {WalletDB} */ this.wdb = wdb; this.db = wdb.db; this.logger = wdb.logger; diff --git a/lib/wallet/walletdb.js b/lib/wallet/walletdb.js index eb0dc6e8a..a9200c430 100644 --- a/lib/wallet/walletdb.js +++ b/lib/wallet/walletdb.js @@ -44,6 +44,8 @@ const {scanActions} = require('../blockchain/common'); /** @typedef {import('./records').BlockMeta} BlockMeta */ /** @typedef {import('./txdb').BlockExtraInfo} BlockExtraInfo */ /** @typedef {import('./walletkey')} WalletKey */ +/** @typedef {import('./nodeclient')} NodeClient */ +/** @typedef {import('./client')} NodeHTTPClient */ const { ChainState, @@ -84,6 +86,7 @@ class WalletDB extends EventEmitter { this.network = this.options.network; this.logger = this.options.logger.context('wallet'); this.workers = this.options.workers; + /** @type {NullClient|NodeClient|NodeHTTPClient} */ this.client = this.options.client || new NullClient(this); this.feeRate = this.options.feeRate; /** @type {bdb.DB} */ diff --git a/test/util/node-context.js b/test/util/node-context.js index 32277506d..9fc15958d 100644 --- a/test/util/node-context.js +++ b/test/util/node-context.js @@ -12,15 +12,6 @@ const {NodeClient, WalletClient} = require('../../lib/client'); const Logger = require('blgr'); class NodeContext { - /** @type {FullNode|SPVNode} */ - node; - - /** @type {WalletClient} */ - wclient; - - /** @type {NodeClient} */ - nclient; - constructor(options = {}) { this.name = 'node-test'; this.options = {}; @@ -33,9 +24,13 @@ class NodeContext { }); this.initted = false; + /** @type {FullNode|SPVNode|null} */ this.node = null; + /** @type {WalletNode|null} */ this.walletNode = null; + /** @type {NodeClient|null} */ this.nclient = null; + /** @type {WalletClient|null} */ this.wclient = null; this.clients = []; diff --git a/test/util/nodes-context.js b/test/util/nodes-context.js index eae77d457..6a5864df3 100644 --- a/test/util/nodes-context.js +++ b/test/util/nodes-context.js @@ -5,12 +5,10 @@ const Network = require('../../lib/protocol/network'); const NodeContext = require('./node-context'); class NodesContext { - /** @type {NodeContext[]} */ - nodeCtxs; - constructor(network, size = 1) { this.network = Network.get(network); this.size = size; + /** @type {NodeContext[]} */ this.nodeCtxs = []; assert(this.size > 0);