Skip to content

Commit

Permalink
Add nftTotalSupply
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanzhenzhen committed Jun 2, 2020
1 parent 3310736 commit 1d5d824
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
18 changes: 17 additions & 1 deletion lib/services/bitcoind.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "bitcore-node-crown",
"description": "Full node with extended capabilities using Bitcore and Crown Core",
"author": "Crown Developers <[email protected]>",
"version": "0.3.2",
"version": "0.4.0",
"publishConfig": {
"tag": "next"
},
Expand Down
2 changes: 1 addition & 1 deletion scripts/download
Original file line number Diff line number Diff line change
Expand Up @@ -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)/.."
Expand Down
35 changes: 35 additions & 0 deletions test/services/bitcoind.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1d5d824

Please sign in to comment.