diff --git a/index.js b/index.js index 7f57c1c..06ef7c1 100755 --- a/index.js +++ b/index.js @@ -15,7 +15,7 @@ const repl = require("repl") const SLP = require("./lib/SLP").default const clone = require("git-clone") -program.version("1.2.0", "-v, --version") +program.version("1.2.2", "-v, --version") program .command("new ") diff --git a/lib/Address.js b/lib/Address.js index afcdda3..f59178b 100644 --- a/lib/Address.js +++ b/lib/Address.js @@ -48,6 +48,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) { } }; Object.defineProperty(exports, "__esModule", { value: true }); +// require deps var BITBOXAddress = require("bitbox-sdk/lib/Address").default; var BITBOXSDK = require("bitbox-sdk/lib/bitbox-sdk").default; var BITBOX = new BITBOXSDK(); diff --git a/lib/Utils.js b/lib/Utils.js index df8edf5..708b9d2 100644 --- a/lib/Utils.js +++ b/lib/Utils.js @@ -37,10 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) { Object.defineProperty(exports, "__esModule", { value: true }); // require deps var BITBOXSDK = require("bitbox-sdk/lib/bitbox-sdk").default; -var utils = require("slpjs").Utils; var slpjs = require("slpjs"); -//const slpjs = require("../../slpjs") -var BigNumber = require("bignumber.js"); var axios_1 = require("axios"); // Used for debugging and iterrogating JS objects. var util = require("util"); @@ -80,91 +77,27 @@ var Utils = /** @class */ (function () { }); }); }; - // Get raw SLP balances and utxos from the REST server. - // This function was created to faciliate unit and integration tests. - Utils.prototype.slpBalancesUtxos = function (bitboxNetwork, addr) { - return __awaiter(this, void 0, void 0, function () { - var balances; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, bitboxNetwork.getAllSlpBalancesAndUtxos(addy.toSLPAddress(addr))]; - case 1: - balances = _a.sent(); - return [2 /*return*/, balances]; - } - }); - }); - }; - // Retrieve token metadata from the REST server using an input array of txids - // This function was created to faciliate unit and integration tests. - Utils.prototype.getTokenMetadata = function (keys, bitboxNetwork, balances) { - return __awaiter(this, void 0, void 0, function () { - var axiosPromises, axiosResult; - var _this = this; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - axiosPromises = keys.map(function (key) { return __awaiter(_this, void 0, void 0, function () { - var tokenMetadata; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, bitboxNetwork.getTokenInformation(key)]; - case 1: - tokenMetadata = _a.sent(); - return [2 /*return*/, { - tokenId: key, - balance: balances.slpTokenBalances[key] - .div(Math.pow(10, tokenMetadata.decimals)) - .toString(), - decimalCount: tokenMetadata.decimals - }]; - } - }); - }); }); - return [4 /*yield*/, axios_1.default.all(axiosPromises)]; - case 1: - axiosResult = _a.sent(); - return [2 /*return*/, axiosResult]; - } - }); - }); - }; // Retrieve token balances for a given address. Utils.prototype.balancesForAddress = function (address) { return __awaiter(this, void 0, void 0, function () { - var network, tmpBITBOX, getRawTransactions, slpValidator, bitboxNetwork, balances, keys, tokenMeta; - var _this = this; + var path, response, error_2; return __generator(this, function (_a) { switch (_a.label) { case 0: - network = addy.detectAddressNetwork(address); - // Determine network (mainnet or testnet) - if (network === "mainnet") { - tmpBITBOX = new BITBOXSDK({ restURL: "https://rest.bitcoin.com/v2/" }); - } - else { - tmpBITBOX = new BITBOXSDK({ restURL: "https://trest.bitcoin.com/v2/" }); - } - getRawTransactions = function (txids) { return __awaiter(_this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, tmpBITBOX.RawTransactions.getRawTransaction(txids)]; - case 1: return [2 /*return*/, _a.sent()]; - } - }); - }); }; - slpValidator = new slpjs.LocalValidator(tmpBITBOX, getRawTransactions); - bitboxNetwork = new slpjs.BitboxNetwork(tmpBITBOX, slpValidator); - return [4 /*yield*/, this.slpBalancesUtxos(bitboxNetwork, address) - // Get the TXIDs for tokens associated with this address. - ]; + path = this.restURL + "slp/balancesForAddress/" + address; + _a.label = 1; case 1: - balances = _a.sent(); - keys = Object.keys(balances.slpTokenBalances); - return [4 /*yield*/, this.getTokenMetadata(keys, bitboxNetwork, balances)]; + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, axios_1.default.get(path)]; case 2: - tokenMeta = _a.sent(); - return [2 /*return*/, tokenMeta]; + response = _a.sent(); + return [2 /*return*/, response.data]; + case 3: + error_2 = _a.sent(); + if (error_2.response && error_2.response.data) + throw error_2.response.data; + throw error_2; + case 4: return [2 /*return*/]; } }); }); @@ -172,38 +105,24 @@ var Utils = /** @class */ (function () { // Retrieve a balance for a specific address and token ID Utils.prototype.balance = function (address, tokenId) { return __awaiter(this, void 0, void 0, function () { - var network, tmpBITBOX, getRawTransactions, slpValidator, bitboxNetwork, balances, tokenMeta; - var _this = this; + var path, response, error_3; return __generator(this, function (_a) { switch (_a.label) { case 0: - network = addy.detectAddressNetwork(address); - // Determine network (mainnet or testnet) - if (network === "mainnet") { - tmpBITBOX = new BITBOXSDK({ restURL: "https://rest.bitcoin.com/v2/" }); - } - else { - tmpBITBOX = new BITBOXSDK({ restURL: "https://trest.bitcoin.com/v2/" }); - } - getRawTransactions = function (txids) { return __awaiter(_this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, tmpBITBOX.RawTransactions.getRawTransaction(txids)]; - case 1: return [2 /*return*/, _a.sent()]; - } - }); - }); }; - slpValidator = new slpjs.LocalValidator(tmpBITBOX, getRawTransactions); - bitboxNetwork = new slpjs.BitboxNetwork(tmpBITBOX, slpValidator); - return [4 /*yield*/, this.slpBalancesUtxos(bitboxNetwork, address) - // Get the metadata for this single token. - ]; + path = this.restURL + "slp/balance/" + address + "/" + tokenId; + _a.label = 1; case 1: - balances = _a.sent(); - return [4 /*yield*/, this.getTokenMetadata([tokenId], bitboxNetwork, balances)]; + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, axios_1.default.get(path)]; case 2: - tokenMeta = _a.sent(); - return [2 /*return*/, tokenMeta[0]]; + response = _a.sent(); + return [2 /*return*/, response.data]; + case 3: + error_3 = _a.sent(); + if (error_3.response && error_3.response.data) + throw error_3.response.data; + throw error_3; + case 4: return [2 /*return*/]; } }); }); diff --git a/package-lock.json b/package-lock.json index de8935b..1200ea3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "slp-sdk", - "version": "1.2.1", + "version": "1.2.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 51aefb2..db38f1e 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,12 @@ { "name": "slp-sdk", - "version": "1.2.1", + "version": "1.2.2", "description": "SLP SDK powered by BITBOX", "main": "index.js", "scripts": { "build": "node ./node_modules/gulp/bin/gulp.js build && ./node_modules/typescript/bin/tsc", - "test": "TEST=unit nyc --reporter=text mocha --require babel-core/register --timeout 300000 test/", - "test:integration": "TEST=integration nyc --reporter=text mocha --require babel-core/register --timeout 300000 test/", + "test": "TEST=unit nyc --reporter=text mocha --require babel-core/register --timeout 10000 test/", + "test:integration": "TEST=integration nyc --reporter=text mocha --require babel-core/register --timeout 10000 test/", "coverage": "nyc report --reporter=text-lcov | coveralls", "coverage:report": "nyc --reporter=html mocha --require babel-core/register --timeout 10000", "semantic-release": "semantic-release" diff --git a/src/Address.ts b/src/Address.ts index 8ec8411..baef204 100644 --- a/src/Address.ts +++ b/src/Address.ts @@ -1,3 +1,4 @@ +// require deps const BITBOXAddress = require("bitbox-sdk/lib/Address").default const BITBOXSDK = require("bitbox-sdk/lib/bitbox-sdk").default const BITBOX = new BITBOXSDK() diff --git a/src/Utils.ts b/src/Utils.ts index f56562c..1e78102 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -1,9 +1,6 @@ // require deps const BITBOXSDK = require("bitbox-sdk/lib/bitbox-sdk").default -const utils = require("slpjs").Utils const slpjs = require("slpjs") -//const slpjs = require("../../slpjs") -const BigNumber: any = require("bignumber.js") import axios from "axios" // Used for debugging and iterrogating JS objects. @@ -36,110 +33,30 @@ class Utils { } } - // Get raw SLP balances and utxos from the REST server. - // This function was created to faciliate unit and integration tests. - async slpBalancesUtxos(bitboxNetwork: any, addr: any) { - let balances: any = await bitboxNetwork.getAllSlpBalancesAndUtxos( - addy.toSLPAddress(addr) - ) - - return balances - } - - // Retrieve token metadata from the REST server using an input array of txids - // This function was created to faciliate unit and integration tests. - async getTokenMetadata( - keys: Array, - bitboxNetwork: any, - balances: any - ) { - const axiosPromises = keys.map(async (key: any) => { - let tokenMetadata: any = await bitboxNetwork.getTokenInformation(key) - - return { - tokenId: key, - balance: balances.slpTokenBalances[key] - .div(10 ** tokenMetadata.decimals) - .toString(), - decimalCount: tokenMetadata.decimals - } - }) - - // Wait for all parallel promises to return. - const axiosResult: Array = await axios.all(axiosPromises) - - return axiosResult - } - // Retrieve token balances for a given address. async balancesForAddress(address: string): Promise { - let network: string = addy.detectAddressNetwork(address) - let tmpBITBOX: any - - // Determine network (mainnet or testnet) - if (network === "mainnet") { - tmpBITBOX = new BITBOXSDK({ restURL: "https://rest.bitcoin.com/v2/" }) - } else { - tmpBITBOX = new BITBOXSDK({ restURL: "https://trest.bitcoin.com/v2/" }) - } + let path: string = `${this.restURL}slp/balancesForAddress/${address}` - const getRawTransactions = async (txids: any) => { - return await tmpBITBOX.RawTransactions.getRawTransaction(txids) + try { + const response = await axios.get(path) + return response.data + } catch (error) { + if (error.response && error.response.data) throw error.response.data + throw error } - - // Instantiate a local SLP TX validator - const slpValidator: any = new slpjs.LocalValidator( - tmpBITBOX, - getRawTransactions - ) - - // Get raw SLP information for this address. - const bitboxNetwork: any = new slpjs.BitboxNetwork(tmpBITBOX, slpValidator) - let balances: any = await this.slpBalancesUtxos(bitboxNetwork, address) - - // Get the TXIDs for tokens associated with this address. - let keys: Array = Object.keys(balances.slpTokenBalances) - - // Retrieve the token metadata for the TXIDs. - const tokenMeta = await this.getTokenMetadata(keys, bitboxNetwork, balances) - - return tokenMeta } // Retrieve a balance for a specific address and token ID async balance(address: string, tokenId: string): Promise { - let network: string = addy.detectAddressNetwork(address) - let tmpBITBOX: any + let path: string = `${this.restURL}slp/balance/${address}/${tokenId}` - // Determine network (mainnet or testnet) - if (network === "mainnet") { - tmpBITBOX = new BITBOXSDK({ restURL: "https://rest.bitcoin.com/v2/" }) - } else { - tmpBITBOX = new BITBOXSDK({ restURL: "https://trest.bitcoin.com/v2/" }) - } - - const getRawTransactions = async (txids: any) => { - return await tmpBITBOX.RawTransactions.getRawTransaction(txids) + try { + const response = await axios.get(path) + return response.data + } catch (error) { + if (error.response && error.response.data) throw error.response.data + throw error } - - // Instantiate a local SLP TX validator - const slpValidator: any = new slpjs.LocalValidator( - tmpBITBOX, - getRawTransactions - ) - - // Get raw SLP information for this address. - const bitboxNetwork: any = new slpjs.BitboxNetwork(tmpBITBOX, slpValidator) - let balances: any = await this.slpBalancesUtxos(bitboxNetwork, address) - - // Get the metadata for this single token. - const tokenMeta = await this.getTokenMetadata( - [tokenId], - bitboxNetwork, - balances - ) - - return tokenMeta[0] } async validateTxid( diff --git a/test/Utils.js b/test/Utils.js index 3ea8e12..75dfac8 100644 --- a/test/Utils.js +++ b/test/Utils.js @@ -92,127 +92,19 @@ describe("#Utils", () => { }) }) - describe("#slpBalancesUtxos", () => { - it(`should fetch raw UTXO balances from server`, async () => { - // When run as a unit test, this test case serves to prove that the - // SLP.Utils.slpBalancesUtxos() function can be successfully stubbed by - // sinon, which is needed for other tests. When run as an integration - // test, it confirms that mocked data matches the real data coming from - // the REST server. - - // Mock the call to rest.bitcoin.com for unit tests. - if (process.env.TEST === "unit") { - sandbox - .stub(SLP.Utils, "slpBalancesUtxos") - .resolves(mockData.mockBalance) - } - - // Instantiate BITBOX - const tmpBITBOX = new BITBOXSDK({ - restURL: `${SERVER}/v2/` - }) - - const getRawTransactions = async txids => - await tmpBITBOX.RawTransactions.getRawTransaction(txids) - - // Instantiate a local validator - const slpValidator = new slpjs.LocalValidator( - tmpBITBOX, - getRawTransactions - ) - - // Instantiate the bitboxNetwork object - const bitboxNetwork = new slpjs.BitboxNetwork(tmpBITBOX, slpValidator) - - const addr = "simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9" - const balances = await SLP.Utils.slpBalancesUtxos(bitboxNetwork, addr) - //console.log(`balances: ${JSON.stringify(balances, null, 2)}`) - - assert2.hasAnyKeys(balances, [ - "satoshis_available_bch", - "satoshis_in_slp_baton", - "satoshis_in_slp_token", - "satoshis_in_invalid_token_dag", - "satoshis_in_invalid_baton_dag", - "slpTokenBalances", - "slpTokenUtxos", - "slpBatonUtxos", - "nonSlpUtxos", - "invalidTokenUtxos", - "invalidBatonUtxos" - ]) - }) - }) - - describe("#getTokenMetadata", () => { - it(`should fetch token metadata from the REST server`, async () => { - // When run as a unit test, this test case serves to prove that the - // SLP.Utils.getTokenMetadata() function can be successfully stubbed by - // sinon, which is needed for other tests. When run as an integration - // test, it confirms that mocked data matches the real data coming from - // the REST server. - - // Mock the call to rest.bitcoin.com for unit tests. - if (process.env.TEST === "unit") { - sandbox - .stub(SLP.Utils, "getTokenMetadata") - .resolves(mockData.mockTokenMeta) - } - - // Instantiate BITBOX - const tmpBITBOX = new BITBOXSDK({ - restURL: `${SERVER}/v2/` - }) - - // Instantiate a local validator - const slpValidator = new slpjs.LocalValidator( - tmpBITBOX, - tmpBITBOX.RawTransactions.getRawTransaction - ) - - // Instantiate the bitboxNetwork object - const bitboxNetwork = new slpjs.BitboxNetwork(tmpBITBOX, slpValidator) - - // Prep data for the test. - const balances = mockData.mockBalance - const keys = Object.keys(balances.slpTokenBalances) - balances.slpTokenBalances[keys[0]] = new BigNumber( - balances.slpTokenBalances[keys[0]] - ) - balances.slpTokenBalances[keys[1]] = new BigNumber( - balances.slpTokenBalances[keys[1]] - ) - - // Call the function under test. - const tokenMeta = await SLP.Utils.getTokenMetadata( - keys, - bitboxNetwork, - balances - ) - //console.log(`tokenMeta: ${util.inspect(tokenMeta)}`) - - assert2.isArray(tokenMeta) - assert2.hasAllKeys(tokenMeta[0], ["tokenId", "balance", "decimalCount"]) - }) - }) - describe("#balancesForAddress", () => { it(`should fetch all balances for address: simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9`, async () => { // Mock the call to rest.bitcoin.com if (process.env.TEST === "unit") { sandbox - .stub(SLP.Utils, "getTokenMetadata") - .resolves(mockData.mockTokenMeta) - - sandbox - .stub(SLP.Utils, "slpBalancesUtxos") - .resolves(mockData.mockBalance) + .stub(SLP.Utils, "balancesForAddress") + .resolves(mockData.balancesForAddress) } const balances = await SLP.Utils.balancesForAddress( "simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9" ) - //console.log(`balances: ${JSON.stringify(balances, null, 2)}`) + // console.log(`balances: ${JSON.stringify(balances, null, 2)}`) assert2.isArray(balances) assert2.hasAllKeys(balances[0], ["tokenId", "balance", "decimalCount"]) @@ -224,12 +116,8 @@ describe("#Utils", () => { // Mock the call to rest.bitcoin.com if (process.env.TEST === "unit") { sandbox - .stub(SLP.Utils, "getTokenMetadata") - .resolves(mockData.mockTokenMeta) - - sandbox - .stub(SLP.Utils, "slpBalancesUtxos") - .resolves(mockData.mockBalance) + .stub(SLP.Utils, "balancesForAddress") + .resolves(mockData.balancesForAddress) } const balance = await SLP.Utils.balance( diff --git a/test/fixtures/mock-utils.js b/test/fixtures/mock-utils.js index bbf32c2..5e9e543 100644 --- a/test/fixtures/mock-utils.js +++ b/test/fixtures/mock-utils.js @@ -68,361 +68,7 @@ const mockToken = { initialTokenQty: 10000000000000000 } -const mockBalance = { - satoshis_available_bch: 0, - satoshis_in_slp_baton: 0, - satoshis_in_slp_token: 1092, - satoshis_in_invalid_token_dag: 0, - satoshis_in_invalid_baton_dag: 0, - slpTokenBalances: { - df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb: - "100000000", - a436c8e1b6bee3d701c6044d190f76f774be83c36de8d34a988af4489e86dd37: "10000000" - }, - slpTokenUtxos: { - df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb: [ - { - satoshis: 546, - txid: - "4fc789405d58ec612c69eba29aa56cf0c7f228349801114138424eb68df4479d", - amount: 0.00000546, - confirmations: 348, - height: 569108, - vout: 1, - cashAddress: "bitcoincash:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvg8nfhq4m", - legacyAddress: "1ExLo45Z6CVXe7wS7SMN47W4khCZ2RqMRK", - scriptPubKey: "76a9149911094b189e64075d2ebfcaef4c0aa767750fb388ac", - tx: { - txid: - "4fc789405d58ec612c69eba29aa56cf0c7f228349801114138424eb68df4479d", - version: 2, - locktime: 0, - vin: [ - { - txid: - "1b642e6b4cff7f928a67e3d425e7e9c2e13595c899c3cd4eec10ef165ece912d", - vout: 1, - sequence: 4294967295, - n: 0, - scriptSig: { - hex: - "483045022100dc79a9bc3ab729eda54fe5f5764e32ab6c17f55ed1301f84c218dcb02c52c30f022025090a2eb3e396a7dab5bd98687aa8c79adda8d36b1860350f6f72857e2373a0412102b2a5564a9e8f3a268f0fdd155d318616cac19930dad11e982f3ecdb4fe319aed", - asm: - "3045022100dc79a9bc3ab729eda54fe5f5764e32ab6c17f55ed1301f84c218dcb02c52c30f022025090a2eb3e396a7dab5bd98687aa8c79adda8d36b1860350f6f72857e2373a0[ALL|FORKID] 02b2a5564a9e8f3a268f0fdd155d318616cac19930dad11e982f3ecdb4fe319aed" - }, - value: 17166589, - legacyAddress: "1NKNdfgPq1EApuNaf5mrNRUPbwVHQt3MeB", - cashAddress: - "bitcoincash:qr5agtachyxvrwxu76vzszan5pnvuzy8dumh7ynrwg" - }, - { - txid: - "692bd3d08ab653a21735d0bb56dcc19726a6d4afa6bcfe17117c55af26cf6e32", - vout: 0, - sequence: 4294967295, - n: 1, - scriptSig: { - hex: - "47304402207365c6b8070a74b63bfdcf746562d7ad9b55cc0b6ebb166429aff323aca6854302207f4bbdb171f620ad5586db29123b28bfc23934a4f8b4e6de797767cf0a93312d412102b2a5564a9e8f3a268f0fdd155d318616cac19930dad11e982f3ecdb4fe319aed", - asm: - "304402207365c6b8070a74b63bfdcf746562d7ad9b55cc0b6ebb166429aff323aca6854302207f4bbdb171f620ad5586db29123b28bfc23934a4f8b4e6de797767cf0a93312d[ALL|FORKID] 02b2a5564a9e8f3a268f0fdd155d318616cac19930dad11e982f3ecdb4fe319aed" - }, - value: 200000, - legacyAddress: "1NKNdfgPq1EApuNaf5mrNRUPbwVHQt3MeB", - cashAddress: - "bitcoincash:qr5agtachyxvrwxu76vzszan5pnvuzy8dumh7ynrwg" - }, - { - txid: - "587e1522ff1ff6109e760cc7080791975fca5e28419b6f7342af7bb69598d48b", - vout: 0, - sequence: 4294967295, - n: 2, - scriptSig: { - hex: - "47304402202994dc27cef14a49823ba8e81a5e382aa8c2c890747de93e5ab6cce098fb4f47022070330f5f820309fe2646767d37f48e44724d6ed391ee6ec788335ef3b3f640da412102b2a5564a9e8f3a268f0fdd155d318616cac19930dad11e982f3ecdb4fe319aed", - asm: - "304402202994dc27cef14a49823ba8e81a5e382aa8c2c890747de93e5ab6cce098fb4f47022070330f5f820309fe2646767d37f48e44724d6ed391ee6ec788335ef3b3f640da[ALL|FORKID] 02b2a5564a9e8f3a268f0fdd155d318616cac19930dad11e982f3ecdb4fe319aed" - }, - value: 100000, - legacyAddress: "1NKNdfgPq1EApuNaf5mrNRUPbwVHQt3MeB", - cashAddress: - "bitcoincash:qr5agtachyxvrwxu76vzszan5pnvuzy8dumh7ynrwg" - }, - { - txid: - "cc86cca45a0be4d7bd1fad47261342a00d5492c9a94312aec8ead37c716ecb30", - vout: 2, - sequence: 4294967295, - n: 3, - scriptSig: { - hex: - "47304402203b514bdcb317479bae02df487bca209a1c159bc02e1fd31f0c4665f23442a8700220418e14dfd07f626d98673d0c18d49cca2071f34da3df58de784a398dda7a8e3e412102b2a5564a9e8f3a268f0fdd155d318616cac19930dad11e982f3ecdb4fe319aed", - asm: - "304402203b514bdcb317479bae02df487bca209a1c159bc02e1fd31f0c4665f23442a8700220418e14dfd07f626d98673d0c18d49cca2071f34da3df58de784a398dda7a8e3e[ALL|FORKID] 02b2a5564a9e8f3a268f0fdd155d318616cac19930dad11e982f3ecdb4fe319aed" - }, - value: 546, - legacyAddress: "1NKNdfgPq1EApuNaf5mrNRUPbwVHQt3MeB", - cashAddress: - "bitcoincash:qr5agtachyxvrwxu76vzszan5pnvuzy8dumh7ynrwg" - } - ], - vout: [ - { - value: "0.00000000", - n: 0, - scriptPubKey: { - hex: - "6a04534c500001010453454e4420df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb080000000005f5e1000800005ae270b4b600", - asm: - "OP_RETURN 5262419 1 1145980243 df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb 0000000005f5e100 00005ae270b4b600" - }, - spentTxId: null, - spentIndex: null, - spentHeight: null - }, - { - value: "0.00000546", - n: 1, - scriptPubKey: { - hex: "76a9149911094b189e64075d2ebfcaef4c0aa767750fb388ac", - asm: - "OP_DUP OP_HASH160 9911094b189e64075d2ebfcaef4c0aa767750fb3 OP_EQUALVERIFY OP_CHECKSIG", - addresses: ["1ExLo45Z6CVXe7wS7SMN47W4khCZ2RqMRK"], - type: "pubkeyhash" - }, - spentTxId: null, - spentIndex: null, - spentHeight: null - }, - { - value: "0.00000546", - n: 2, - scriptPubKey: { - hex: "76a914e9d42fb8b90cc1b8dcf698280bb3a066ce08876f88ac", - asm: - "OP_DUP OP_HASH160 e9d42fb8b90cc1b8dcf698280bb3a066ce08876f OP_EQUALVERIFY OP_CHECKSIG", - addresses: ["1NKNdfgPq1EApuNaf5mrNRUPbwVHQt3MeB"], - type: "pubkeyhash" - }, - spentTxId: - "de69468f85f54f889b1a915274c8935e9d68245e9593a524a89647bc21a44b2d", - spentIndex: 1, - spentHeight: 569197 - }, - { - value: "0.17465231", - n: 3, - scriptPubKey: { - hex: "76a914e9d42fb8b90cc1b8dcf698280bb3a066ce08876f88ac", - asm: - "OP_DUP OP_HASH160 e9d42fb8b90cc1b8dcf698280bb3a066ce08876f OP_EQUALVERIFY OP_CHECKSIG", - addresses: ["1NKNdfgPq1EApuNaf5mrNRUPbwVHQt3MeB"], - type: "pubkeyhash" - }, - spentTxId: - "384e1b8197e8de7d38f98317af2cf5f6bcb50007c46943b3498a6fab6e8aeb7c", - spentIndex: 0, - spentHeight: 569108 - } - ], - blockhash: - "0000000000000000025fdf811ef86348ebd0511f4045c4cd83f6b75fcd8c2661", - blockheight: 569108, - confirmations: 348, - time: 1549788135, - blocktime: 1549788135, - valueOut: 0.17466323, - size: 774, - valueIn: 0.17467135, - fees: 0.00000812 - }, - slpTransactionDetails: { - versionType: 1, - transactionType: 2, - tokenIdHex: - "df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb", - sendOutputs: ["0", "100000000", "99928600000000"] - }, - slpUtxoJudgement: 1, - slpUtxoJudgementAmount: "100000000" - } - ], - a436c8e1b6bee3d701c6044d190f76f774be83c36de8d34a988af4489e86dd37: [ - { - satoshis: 546, - txid: - "384e1b8197e8de7d38f98317af2cf5f6bcb50007c46943b3498a6fab6e8aeb7c", - amount: 0.00000546, - confirmations: 348, - height: 569108, - vout: 1, - cashAddress: "bitcoincash:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvg8nfhq4m", - legacyAddress: "1ExLo45Z6CVXe7wS7SMN47W4khCZ2RqMRK", - scriptPubKey: "76a9149911094b189e64075d2ebfcaef4c0aa767750fb388ac", - tx: { - txid: - "384e1b8197e8de7d38f98317af2cf5f6bcb50007c46943b3498a6fab6e8aeb7c", - version: 2, - locktime: 0, - vin: [ - { - txid: - "4fc789405d58ec612c69eba29aa56cf0c7f228349801114138424eb68df4479d", - vout: 3, - sequence: 4294967295, - n: 0, - scriptSig: { - hex: - "483045022100d77ee0c0c1129c658637bcf9ccb215a2c79ab31095ee2078457f51b7e8de047502205edb6710f0f00377a04c8c06449618b2ba41a65e44665fac93e81072b1710fe4412102b2a5564a9e8f3a268f0fdd155d318616cac19930dad11e982f3ecdb4fe319aed", - asm: - "3045022100d77ee0c0c1129c658637bcf9ccb215a2c79ab31095ee2078457f51b7e8de047502205edb6710f0f00377a04c8c06449618b2ba41a65e44665fac93e81072b1710fe4[ALL|FORKID] 02b2a5564a9e8f3a268f0fdd155d318616cac19930dad11e982f3ecdb4fe319aed" - }, - value: 17465231, - legacyAddress: "1NKNdfgPq1EApuNaf5mrNRUPbwVHQt3MeB", - cashAddress: - "bitcoincash:qr5agtachyxvrwxu76vzszan5pnvuzy8dumh7ynrwg" - }, - { - txid: - "1baa9662b3a9e7fc690cfee1b3baa125875219cb79c5faf1d338ef1bba8ea9fc", - vout: 2, - sequence: 4294967295, - n: 1, - scriptSig: { - hex: - "483045022100eaa65ccd71c8d76843ac03cd3abd9b6dd1618bb191600f816a3af35c2ebcea98022073dc30d8fe8b1712b07b4dc98a0a7ac74674b228e991036b956e064c28e149e0412102b2a5564a9e8f3a268f0fdd155d318616cac19930dad11e982f3ecdb4fe319aed", - asm: - "3045022100eaa65ccd71c8d76843ac03cd3abd9b6dd1618bb191600f816a3af35c2ebcea98022073dc30d8fe8b1712b07b4dc98a0a7ac74674b228e991036b956e064c28e149e0[ALL|FORKID] 02b2a5564a9e8f3a268f0fdd155d318616cac19930dad11e982f3ecdb4fe319aed" - }, - value: 546, - legacyAddress: "1NKNdfgPq1EApuNaf5mrNRUPbwVHQt3MeB", - cashAddress: - "bitcoincash:qr5agtachyxvrwxu76vzszan5pnvuzy8dumh7ynrwg" - }, - { - txid: - "e60f61b24b2e55b18522c573395023f0ead6b86b6c6fb036b07e6acd4cb3540d", - vout: 1, - sequence: 4294967295, - n: 2, - scriptSig: { - hex: - "47304402202c9f9bd78541e6436019a8fc51623cdaa6dbe19560eaed350de000463656f46a02203b1558a88a7270fbaf854fa0238ac37d3248f46d7016c6d331e1f36720ab253f412102b2a5564a9e8f3a268f0fdd155d318616cac19930dad11e982f3ecdb4fe319aed", - asm: - "304402202c9f9bd78541e6436019a8fc51623cdaa6dbe19560eaed350de000463656f46a02203b1558a88a7270fbaf854fa0238ac37d3248f46d7016c6d331e1f36720ab253f[ALL|FORKID] 02b2a5564a9e8f3a268f0fdd155d318616cac19930dad11e982f3ecdb4fe319aed" - }, - value: 546, - legacyAddress: "1NKNdfgPq1EApuNaf5mrNRUPbwVHQt3MeB", - cashAddress: - "bitcoincash:qr5agtachyxvrwxu76vzszan5pnvuzy8dumh7ynrwg" - }, - { - txid: - "88dd5769ec767420c499c77152d67950333392c41b98387e0994f069d16dd0d3", - vout: 1, - sequence: 4294967295, - n: 3, - scriptSig: { - hex: - "483045022100890318fbbf5409f5c3d84083983871cfb1e7b7c6f01692de26ff33254f32e62102202436d29d3755d6d50103188f94a9d3165a051478f2d0f69bf242ec6cdb275d0f412102b2a5564a9e8f3a268f0fdd155d318616cac19930dad11e982f3ecdb4fe319aed", - asm: - "3045022100890318fbbf5409f5c3d84083983871cfb1e7b7c6f01692de26ff33254f32e62102202436d29d3755d6d50103188f94a9d3165a051478f2d0f69bf242ec6cdb275d0f[ALL|FORKID] 02b2a5564a9e8f3a268f0fdd155d318616cac19930dad11e982f3ecdb4fe319aed" - }, - value: 546, - legacyAddress: "1NKNdfgPq1EApuNaf5mrNRUPbwVHQt3MeB", - cashAddress: - "bitcoincash:qr5agtachyxvrwxu76vzszan5pnvuzy8dumh7ynrwg" - } - ], - vout: [ - { - value: "0.00000000", - n: 0, - scriptPubKey: { - hex: - "6a04534c500001010453454e4420a436c8e1b6bee3d701c6044d190f76f774be83c36de8d34a988af4489e86dd370800000000009896800800000001ab01f700", - asm: - "OP_RETURN 5262419 1 1145980243 a436c8e1b6bee3d701c6044d190f76f774be83c36de8d34a988af4489e86dd37 0000000000989680 00000001ab01f700" - }, - spentTxId: null, - spentIndex: null, - spentHeight: null - }, - { - value: "0.00000546", - n: 1, - scriptPubKey: { - hex: "76a9149911094b189e64075d2ebfcaef4c0aa767750fb388ac", - asm: - "OP_DUP OP_HASH160 9911094b189e64075d2ebfcaef4c0aa767750fb3 OP_EQUALVERIFY OP_CHECKSIG", - addresses: ["1ExLo45Z6CVXe7wS7SMN47W4khCZ2RqMRK"], - type: "pubkeyhash" - }, - spentTxId: null, - spentIndex: null, - spentHeight: null - }, - { - value: "0.00000546", - n: 2, - scriptPubKey: { - hex: "76a914e9d42fb8b90cc1b8dcf698280bb3a066ce08876f88ac", - asm: - "OP_DUP OP_HASH160 e9d42fb8b90cc1b8dcf698280bb3a066ce08876f OP_EQUALVERIFY OP_CHECKSIG", - addresses: ["1NKNdfgPq1EApuNaf5mrNRUPbwVHQt3MeB"], - type: "pubkeyhash" - }, - spentTxId: null, - spentIndex: null, - spentHeight: null - }, - { - value: "0.17464965", - n: 3, - scriptPubKey: { - hex: "76a914e9d42fb8b90cc1b8dcf698280bb3a066ce08876f88ac", - asm: - "OP_DUP OP_HASH160 e9d42fb8b90cc1b8dcf698280bb3a066ce08876f OP_EQUALVERIFY OP_CHECKSIG", - addresses: ["1NKNdfgPq1EApuNaf5mrNRUPbwVHQt3MeB"], - type: "pubkeyhash" - }, - spentTxId: - "7193686a145f35fb88aef0a7b21c4455d922adfb4054ee99b16ad1086a7419d5", - spentIndex: 0, - spentHeight: 569123 - } - ], - blockhash: - "0000000000000000025fdf811ef86348ebd0511f4045c4cd83f6b75fcd8c2661", - blockheight: 569108, - confirmations: 348, - time: 1549788135, - blocktime: 1549788135, - valueOut: 0.17466057, - size: 776, - valueIn: 0.17466869, - fees: 0.00000812 - }, - slpTransactionDetails: { - versionType: 1, - transactionType: 2, - tokenIdHex: - "a436c8e1b6bee3d701c6044d190f76f774be83c36de8d34a988af4489e86dd37", - sendOutputs: ["0", "10000000", "7164000000"] - }, - slpUtxoJudgement: 1, - slpUtxoJudgementAmount: "10000000" - } - ] - }, - slpBatonUtxos: {}, - nonSlpUtxos: [], - invalidTokenUtxos: [], - invalidBatonUtxos: [] -} - -const mockTokenMeta = [ +const balancesForAddress = [ { tokenId: "df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb", balance: "1", @@ -441,8 +87,7 @@ const mockRawTx = [ module.exports = { mockList, - mockBalance, mockToken, - mockTokenMeta, + balancesForAddress, mockRawTx }