From e6120039fc89f9804fe94202f41275dcc84dcbc2 Mon Sep 17 00:00:00 2001 From: Node Date: Fri, 4 Aug 2017 03:17:54 +0400 Subject: [PATCH 1/2] http-api: Normalize API calls, fix getCoins by addr/addresses --- lib/http/client.js | 8 ++++---- lib/http/server.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/http/client.js b/lib/http/client.js index 48e1e935..321e6060 100644 --- a/lib/http/client.js +++ b/lib/http/client.js @@ -318,8 +318,8 @@ HTTPClient.prototype.getInfo = function getInfo() { * @returns {Promise} - Returns {@link Coin}[]. */ -HTTPClient.prototype.getCoinsByAddress = function getCoinsByAddress(address) { - return this._post('/coin/address', { address }); +HTTPClient.prototype.getCoinsByAddress = function getCoinsByAddress(addresses) { + return this._post('/coin/address', { addresses }); }; /** @@ -341,8 +341,8 @@ HTTPClient.prototype.getCoin = function getCoin(hash, index) { * @returns {Promise} - Returns {@link TX}[]. */ -HTTPClient.prototype.getTXByAddress = function getTXByAddress(address) { - return this._post('/tx/address', { address }); +HTTPClient.prototype.getTXByAddress = function getTXByAddress(addresses) { + return this._post('/tx/address', { addresses }); }; /** diff --git a/lib/http/server.js b/lib/http/server.js index c8f7b606..5d24833e 100644 --- a/lib/http/server.js +++ b/lib/http/server.js @@ -235,7 +235,7 @@ HTTPServer.prototype.initRouter = function initRouter() { // Bulk read TXs this.post('/tx/address', async (req, res) => { const valid = req.valid(); - const address = valid.array('address'); + const address = valid.array('addresses'); enforce(address, 'Address is required.'); enforce(!this.chain.options.spv, 'Cannot get TX in SPV mode.'); From 7cf63990d99346cca2eff6cf3044d905a8a49a35 Mon Sep 17 00:00:00 2001 From: Node Date: Fri, 4 Aug 2017 03:48:01 +0400 Subject: [PATCH 2/2] http-client: seperate address and addresses methods --- lib/http/client.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/http/client.js b/lib/http/client.js index 321e6060..75679dd9 100644 --- a/lib/http/client.js +++ b/lib/http/client.js @@ -318,7 +318,18 @@ HTTPClient.prototype.getInfo = function getInfo() { * @returns {Promise} - Returns {@link Coin}[]. */ -HTTPClient.prototype.getCoinsByAddress = function getCoinsByAddress(addresses) { +HTTPClient.prototype.getCoinsByAddress = function getCoinsByAddress(address) { + return this._get(`/coin/address/${address}`); +}; + +/** + * Get coins that pertain to addresses from the mempool or chain database. + * Takes into account spent coins in the mempool. + * @param {String[]} addresses + * @returns {Promise} - Returns {@link Coin}[]. + */ + +HTTPClient.prototype.getCoinsByAddresses = function getCoinsByAddresses(addresses) { return this._post('/coin/address', { addresses }); }; @@ -341,7 +352,18 @@ HTTPClient.prototype.getCoin = function getCoin(hash, index) { * @returns {Promise} - Returns {@link TX}[]. */ -HTTPClient.prototype.getTXByAddress = function getTXByAddress(addresses) { +HTTPClient.prototype.getTXByAddress = function getTXByAddress(address) { + return this._get(`/tx/address/${address}`); +}; + +/** + * Retrieve transactions pertaining to + * addresses from the mempool or chain database. + * @param {String[]} addresses + * @returns {Promise} - Returns {@link TX}[]. + */ + +HTTPClient.prototype.getTXByAddresses = function getTXByAddresses(addresses) { return this._post('/tx/address', { addresses }); };