From 88482707a25b832dbe78f2dd1ff8d83120460fb0 Mon Sep 17 00:00:00 2001 From: Boyma Fahnbulleh Date: Fri, 21 Sep 2018 17:40:11 -0700 Subject: [PATCH 1/2] http: use Address for bulk tx and utxo reads --- lib/node/http.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/node/http.js b/lib/node/http.js index ae82bca06..df2346df2 100644 --- a/lib/node/http.js +++ b/lib/node/http.js @@ -190,12 +190,17 @@ class HTTP extends Server { // Bulk read UTXOs this.post('/coin/address', async (req, res) => { const valid = Validator.fromRequest(req); - const address = valid.array('addresses'); + const addresses = valid.array('addresses'); - enforce(address, 'Address is required.'); + enforce(addresses, 'Addresses is required.'); enforce(!this.chain.options.spv, 'Cannot get coins in SPV mode.'); - const coins = await this.node.getCoinsByAddress(address); + const addrs = []; + for (const address of addresses) { + addrs.push(Address.fromString(address, this.network)); + } + + const coins = await this.node.getCoinsByAddress(addrs); const result = []; for (const coin of coins) @@ -247,12 +252,17 @@ class HTTP extends Server { // Bulk read TXs this.post('/tx/address', async (req, res) => { const valid = Validator.fromRequest(req); - const address = valid.array('addresses'); + const addresses = valid.array('addresses'); - enforce(address, 'Address is required.'); + enforce(addresses, 'Addresses is required.'); enforce(!this.chain.options.spv, 'Cannot get TX in SPV mode.'); - const metas = await this.node.getMetaByAddress(address); + const addrs = []; + for (const address of addresses) { + addrs.push(Address.fromString(address, this.network)); + } + + const metas = await this.node.getMetaByAddress(addrs); const result = []; for (const meta of metas) { From 7b6b203fc59fa2dda1989d56f23b4fac8df40e1b Mon Sep 17 00:00:00 2001 From: Boyma Fahnbulleh Date: Wed, 26 Sep 2018 12:26:35 -0700 Subject: [PATCH 2/2] http: include warning of deprecation --- lib/node/http.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/node/http.js b/lib/node/http.js index df2346df2..391b7ae44 100644 --- a/lib/node/http.js +++ b/lib/node/http.js @@ -188,6 +188,9 @@ class HTTP extends Server { }); // Bulk read UTXOs + // TODO(boymanjor): Deprecate this endpoint + // once the equivalent functionality is included + // in the wallet API. this.post('/coin/address', async (req, res) => { const valid = Validator.fromRequest(req); const addresses = valid.array('addresses'); @@ -195,6 +198,11 @@ class HTTP extends Server { enforce(addresses, 'Addresses is required.'); enforce(!this.chain.options.spv, 'Cannot get coins in SPV mode.'); + this.logger.warning('%s %s %s', + 'Warning: endpoint being considered for deprecation.', + 'Known to cause CPU exhaustion if too many addresses', + 'are queried or too many results are found.'); + const addrs = []; for (const address of addresses) { addrs.push(Address.fromString(address, this.network)); @@ -250,6 +258,9 @@ class HTTP extends Server { }); // Bulk read TXs + // TODO(boymanjor): Deprecate this endpoint + // once the equivalent functionality is included + // in the wallet API. this.post('/tx/address', async (req, res) => { const valid = Validator.fromRequest(req); const addresses = valid.array('addresses'); @@ -257,6 +268,11 @@ class HTTP extends Server { enforce(addresses, 'Addresses is required.'); enforce(!this.chain.options.spv, 'Cannot get TX in SPV mode.'); + this.logger.warning('%s %s %s', + 'Warning: endpoint being considered for deprecation.', + 'Known to cause CPU exhaustion if too many addresses', + 'are queried or too many results are found.'); + const addrs = []; for (const address of addresses) { addrs.push(Address.fromString(address, this.network));