From 1d5d8240eb6f6529b5200dec3caac1b0b4c93fb7 Mon Sep 17 00:00:00 2001 From: Zhenzhen Zhan Date: Wed, 3 Jun 2020 01:54:50 +0800 Subject: [PATCH] Add `nftTotalSupply` --- lib/services/bitcoind.js | 18 ++++++++++++++++- package.json | 2 +- scripts/download | 2 +- test/services/bitcoind.unit.js | 35 ++++++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/lib/services/bitcoind.js b/lib/services/bitcoind.js index e06ab8f04..86fb66288 100644 --- a/lib/services/bitcoind.js +++ b/lib/services/bitcoind.js @@ -181,7 +181,8 @@ Bitcoin.prototype.getAPIMethods = function() { ['getAddressUnspentOutputs', this, this.getAddressUnspentOutputs, 2], ['getAddressHistory', this, this.getAddressHistory, 2], ['getAddressSummary', this, this.getAddressSummary, 1], - ['generateBlock', this, this.generateBlock, 1] + ['generateBlock', this, this.generateBlock, 1], + ['nftTotalSupply', this, this.nftTotalSupply, 1] ]; return methods; }; @@ -2138,6 +2139,21 @@ Bitcoin.prototype.generateBlock = function(num, callback) { }); }; +/** + * Will get NFTs current total supply. + * @param {Number} protocolId - NFT protocol ID. + * @param {Function} callback + */ +Bitcoin.prototype.nftTotalSupply = function(protocolId, callback) { + var self = this; + this.client.nfToken("totalsupply", protocolId, function(err, response) { + if (err) { + return callback(self._wrapRPCError(err)); + } + callback(null, response.result); + }); +}; + /** * Called by Node to stop the service. * @param {Function} callback diff --git a/package.json b/package.json index bc90dc89d..321d2f060 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "bitcore-node-crown", "description": "Full node with extended capabilities using Bitcore and Crown Core", "author": "Crown Developers ", - "version": "0.3.2", + "version": "0.4.0", "publishConfig": { "tag": "next" }, diff --git a/scripts/download b/scripts/download index 9a38b0fbc..879b57415 100755 --- a/scripts/download +++ b/scripts/download @@ -2,7 +2,7 @@ set -e -binary_url="https://gitlab.crown.tech/crown/crown-core/uploads/0fd9b78c91770dd2d767519a51eda5dd/crownd.tar.gz" +binary_url="https://gitlab.crownplatform.com/crown/crown-core/uploads/d98c7718d41d539eb6840e9def2d6f86/crownd.tar.gz" #binary_url="" # uncomment this line if you want to copy file from ~/zzz-crown-binaries rather than download root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.." diff --git a/test/services/bitcoind.unit.js b/test/services/bitcoind.unit.js index ae8cd35bd..c8155ea75 100644 --- a/test/services/bitcoind.unit.js +++ b/test/services/bitcoind.unit.js @@ -5059,6 +5059,41 @@ describe('Bitcoin Service', function() { }); }); + describe('#nftTotalSupply', function() { + it('will give rpc error', function(done) { + var bitcoind = new BitcoinService(baseConfig); + var nfToken = sinon.stub().callsArgWith(2, {message: 'error', code: -1}); + bitcoind.nodes.push({ + client: { + nfToken: nfToken + } + }); + bitcoind.nftTotalSupply('test', function(err) { + should.exist(err); + err.should.be.an.instanceof(errors.RPCError); + done(); + }); + }); + it('will call client nftTotalSupply and give result', function(done) { + var bitcoind = new BitcoinService(baseConfig); + var nfToken = sinon.stub().callsArgWith(2, null, { + result: -1 + }); + bitcoind.nodes.push({ + client: { + nfToken: nfToken + } + }); + bitcoind.nftTotalSupply('test', function(err, totalSupply) { + if (err) { + return done(err); + } + totalSupply.should.equal(-1); + done(); + }); + }); + }); + describe('#stop', function() { it('will callback if spawn is not set', function(done) { var bitcoind = new BitcoinService(baseConfig);