diff --git a/lib/node/http.js b/lib/node/http.js index ae82bca06..391b7ae44 100644 --- a/lib/node/http.js +++ b/lib/node/http.js @@ -188,14 +188,27 @@ 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 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); + 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)); + } + + const coins = await this.node.getCoinsByAddress(addrs); const result = []; for (const coin of coins) @@ -245,14 +258,27 @@ 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 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); + 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)); + } + + const metas = await this.node.getMetaByAddress(addrs); const result = []; for (const meta of metas) {