From 363ef03057889e9bb1e44f529c968a6e3a8aff73 Mon Sep 17 00:00:00 2001 From: Manav Desai Date: Thu, 1 Jun 2023 16:23:37 -0500 Subject: [PATCH] feat: add checkKeyFilter --- lib/client/node.js | 4 ++++ lib/node/http.js | 7 +++++++ lib/wallet/client.js | 13 +++++++++++++ lib/wallet/index.js | 1 - lib/wallet/nodeclient.js | 13 +++++++++++++ lib/wallet/nullclient.js | 13 +++++++++++++ 6 files changed, 50 insertions(+), 1 deletion(-) diff --git a/lib/client/node.js b/lib/client/node.js index 50800cac1..7822408d1 100644 --- a/lib/client/node.js +++ b/lib/client/node.js @@ -169,6 +169,10 @@ class NodeClient extends Client { return this.get(`/filter/${filter}`); } + checkKeyFilter(key, filter) { + return this.call('check key filter', key, filter); + } + /** * Add a transaction to the mempool and broadcast it. * @param {TX} tx diff --git a/lib/node/http.js b/lib/node/http.js index 8448ec015..838aa9be7 100644 --- a/lib/node/http.js +++ b/lib/node/http.js @@ -498,6 +498,13 @@ class HTTP extends Server { return null; }); + socket.hook('check key filter', (...args) => { + const valid = new Validator(args); + const key = valid.buf(0); + const filter = valid.buf(1); + return this.pool.checkKeyFilter(key, filter); + }); + socket.hook('estimate fee', (...args) => { const valid = new Validator(args); const blocks = valid.u32(0); diff --git a/lib/wallet/client.js b/lib/wallet/client.js index 768f38e50..93c521581 100644 --- a/lib/wallet/client.js +++ b/lib/wallet/client.js @@ -12,6 +12,8 @@ const NodeClient = require('../client/node'); const util = require('../utils/util'); const TX = require('../primitives/tx'); const hash256 = require('bcrypto/lib/hash256'); +const WalletKey = require('./walletkey'); +const Filter = require('../primitives/filter'); const parsers = { 'block connect': (entry, txs) => parseBlock(entry, txs), @@ -71,6 +73,17 @@ class WalletClient extends NodeClient { return super.setFilter(filter.toRaw()); } + /** + * Check filter against wallet key ring + * @param {WalletKey} ring + * @param {Filter} filter + * @returns {Promise} + */ + + async checkKeyFilter(ring, filter) { + return super.checkKeyFilter(ring, filter); + } + async rescan(start) { if (Buffer.isBuffer(start)) start = util.revHex(start); diff --git a/lib/wallet/index.js b/lib/wallet/index.js index 3e49f823a..304662ab7 100644 --- a/lib/wallet/index.js +++ b/lib/wallet/index.js @@ -12,7 +12,6 @@ exports.Account = require('./account'); exports.Client = require('./client'); -exports.NeutrinoClient = require('./neutrinoclient'); exports.common = require('./common'); exports.HTTP = require('./http'); exports.layout = require('./layout'); diff --git a/lib/wallet/nodeclient.js b/lib/wallet/nodeclient.js index 9f6c43600..8372b73c0 100644 --- a/lib/wallet/nodeclient.js +++ b/lib/wallet/nodeclient.js @@ -8,6 +8,8 @@ const assert = require('bsert'); const AsyncEmitter = require('bevent'); +const WalletKey = require('./walletkey'); +const Filter = require('../primitives/filter'); /** * Node Client @@ -174,6 +176,17 @@ class NodeClient extends AsyncEmitter { this.node.pool.queueFilterLoad(); } + /** + * Check filter against wallet key ring + * @param {WalletKey} ring + * @param {Filter} filter + * @returns {Promise} + */ + + async checkKeyFilter(ring, filter) { + this.node.pool.checkKeyFilter(ring, filter); + } + /** * Estimate smart fee. * @param {Number?} blocks diff --git a/lib/wallet/nullclient.js b/lib/wallet/nullclient.js index 744629d4b..68221a397 100644 --- a/lib/wallet/nullclient.js +++ b/lib/wallet/nullclient.js @@ -8,6 +8,8 @@ const assert = require('bsert'); const EventEmitter = require('events'); +const WalletKey = require('./walletkey'); +const Filter = require('../primitives/filter'); /** * Null Client @@ -130,6 +132,17 @@ class NullClient extends EventEmitter { this.wdb.emit('reset filter'); } + /** + * Check filter against wallet key ring + * @param {WalletKey} ring + * @param {Filter} filter + * @returns {Promise} + */ + + async checkKeyFilter(ring, filter) { + ; + } + /** * Esimate smart fee. * @param {Number?} blocks