@psf/bch-js 4.20.15 → 4.20.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@psf/bch-js",
3
- "version": "4.20.15",
3
+ "version": "4.20.16",
4
4
  "description": "The FullStack.cash JavaScript library for Bitcoin Cash and SLP Tokens",
5
5
  "author": "Chris Troutner <chris.troutner@gmail.com>",
6
6
  "contributors": [
package/src/address.js CHANGED
@@ -145,7 +145,7 @@ class Address {
145
145
  * // qq50d800hgunr8u4trz3uuppspk3mds0dyug2v69da
146
146
  *
147
147
  */
148
- toEcashAddress (address, prefix = true) {
148
+ toEcashAddress (address, prefix = true) {
149
149
  const decoded = this._decode(address)
150
150
 
151
151
  const ecashAddress = cashaddr.encode(
@@ -173,7 +173,7 @@ class Address {
173
173
  * bchjs.Address.ecashtoCashAddress('ecash:qq50d800hgunr8u4trz3uuppspk3mds0dyug2v69da', false)
174
174
  * // qq50d800hgunr8u4trz3uuppspk3mds0dy9978plt2
175
175
  */
176
- ecashtoCashAddress (address, prefix = true) {
176
+ ecashtoCashAddress (address, prefix = true) {
177
177
  const decoded = this._decodeEcashAddress(address)
178
178
 
179
179
  const cashAddress = cashaddr.encode(
package/src/price.js CHANGED
@@ -128,7 +128,7 @@ class Price {
128
128
  * @apiGroup Price
129
129
  * @apiDescription Return current price of BCHA in USD.
130
130
  * This endpoint gets the USD price of XEC from the Coinex API. The price
131
- * denominated in BCHA comes from bch-api, so it has a better chance of
131
+ * denominated in BCHA comes from bch-api, so it has a better chance of
132
132
  * working in Tor.
133
133
  *
134
134
  * @apiExample Example usage:
@@ -150,7 +150,7 @@ class Price {
150
150
  this.axiosOptions
151
151
  )
152
152
  // console.log(`response.data: ${JSON.stringify(response.data, null, 2)}`)
153
-
153
+
154
154
  const bchaPrice = response.data.usd * 1000000
155
155
  // Convert XEC denomination to BCHA denomination
156
156
 
@@ -161,7 +161,7 @@ class Price {
161
161
  }
162
162
  }
163
163
 
164
- /**
164
+ /**
165
165
  * @api price.getXecUsd() getXecUsd()
166
166
  * @apiName Price getXecUsd()
167
167
  * @apiGroup Price
@@ -179,9 +179,9 @@ class Price {
179
179
  * }
180
180
  *})()
181
181
  *
182
- * // 0.00021234
182
+ * // 0.00021234
183
183
  */
184
- async getXecUsd () {
184
+ async getXecUsd () {
185
185
  try {
186
186
  const response = await this.axios.get(
187
187
  `${this.restURL}price/bchausd`,
@@ -127,11 +127,14 @@ class Transaction {
127
127
  tokenQty = inTokenData.qty
128
128
  // console.log(`tokenQty: ${JSON.stringify(tokenQty, null, 2)}`)
129
129
  }
130
+ } else if (inTokenData.txType === 'MINT') {
131
+ // vout=1 (second output) recieves the newly minted tokens.
132
+ tokenQty = inTokenData.qty
130
133
 
131
134
  //
132
135
  } else {
133
136
  console.log(
134
- 'Unexpected code path in Transaction.get(). Is this a MINT transaction?'
137
+ 'Unexpected code path in Transaction.get(). What is the txType?'
135
138
  )
136
139
  console.log(inTokenData)
137
140
  throw new Error('Unexpected code path')
@@ -266,14 +266,117 @@ const genesisTestInputTx = {
266
266
  blocktime: 1534271330
267
267
  }
268
268
 
269
- genesisTestOpReturnData01 = {
269
+ const mintTestInputTx = {
270
+ txid: '4640a734063ea79fa587a3cac38a70a2f6f3db0011e23514024185982110d0fa',
271
+ hash: '4640a734063ea79fa587a3cac38a70a2f6f3db0011e23514024185982110d0fa',
272
+ version: 1,
273
+ size: 585,
274
+ locktime: 543613,
275
+ vin: [
276
+ {
277
+ txid: '938cc18e618967d787897bbc64b9a8d201b94ec7c69b1a9949eab0433ba5cdf8',
278
+ vout: 1,
279
+ scriptSig: {
280
+ asm: '3045022100e3d5f9a48f9aa1cf7e9ed1992e0281e7300b734ba0e4bd5bb9265b2be60bd71002200ccde53ce7ea9da9df3e834f234f3bea65c2e58c96f8436f93333fd8946a1db2[ALL|FORKID] 02056220984cc2cf5261a27d4f66d31c9ef601a688ca1a5ab81e55b6f0d311be74',
281
+ hex: '483045022100e3d5f9a48f9aa1cf7e9ed1992e0281e7300b734ba0e4bd5bb9265b2be60bd71002200ccde53ce7ea9da9df3e834f234f3bea65c2e58c96f8436f93333fd8946a1db2412102056220984cc2cf5261a27d4f66d31c9ef601a688ca1a5ab81e55b6f0d311be74'
282
+ },
283
+ sequence: 4294967294,
284
+ address: 'bitcoincash:qpaf9wltgmpjlg2vxwwu7zdw5y4z7m277ckxn8cufl',
285
+ value: 0.00000546,
286
+ tokenQtyStr: '43545.34534',
287
+ tokenQty: 43545.34534
288
+ },
289
+ {
290
+ txid: 'ee9d3cf5153599c134147e3fac9844c68e216843f4452a1ce15a29452af6db34',
291
+ vout: 1,
292
+ scriptSig: {
293
+ asm: '3045022100bb90d52be9b568f643fdb1a302e9f063be27a9f914e2a6b192cbabf2cbdeaf9302203c275fc8d1b82390bc1726390d361c5266056bddd54dec23efa207c79eacea4a[ALL|FORKID] 024146cfcd0c02e99d6451dc48ad0f97114aeda18fe55c52a10bfc0490f314e6a2',
294
+ hex: '483045022100bb90d52be9b568f643fdb1a302e9f063be27a9f914e2a6b192cbabf2cbdeaf9302203c275fc8d1b82390bc1726390d361c5266056bddd54dec23efa207c79eacea4a4121024146cfcd0c02e99d6451dc48ad0f97114aeda18fe55c52a10bfc0490f314e6a2'
295
+ },
296
+ sequence: 4294967294,
297
+ address: 'bitcoincash:qqf89zzwd0fqc3npkks997r5l7dpfjf9kgx2rqu500',
298
+ value: 0.00000546,
299
+ tokenQtyStr: '2.34123',
300
+ tokenQty: 2.34123
301
+ },
302
+ {
303
+ txid: 'ee9d3cf5153599c134147e3fac9844c68e216843f4452a1ce15a29452af6db34',
304
+ vout: 3,
305
+ scriptSig: {
306
+ asm: '3044022029ab770c249f467b40bb90410429f6d657f9be299baa19a6838d04d972436b450220143660297e8e836bc16d317649fad8c310bdadb4fb61d4e9f6ba11203abe5dae[ALL|FORKID] 02eed4ac9dda3405d9b1ccbbf09f8056f3e7c615924274bd5643238b543d0a1d56',
307
+ hex: '473044022029ab770c249f467b40bb90410429f6d657f9be299baa19a6838d04d972436b450220143660297e8e836bc16d317649fad8c310bdadb4fb61d4e9f6ba11203abe5dae412102eed4ac9dda3405d9b1ccbbf09f8056f3e7c615924274bd5643238b543d0a1d56'
308
+ },
309
+ sequence: 4294967294,
310
+ address: 'bitcoincash:qqt30r33k0jx3sxe34tmupaujpaljnglmvqgrrfp2x',
311
+ value: 0.00054848,
312
+ tokenQtyStr: '2.34123',
313
+ tokenQty: 2.34123
314
+ }
315
+ ],
316
+ vout: [
317
+ {
318
+ value: 0,
319
+ n: 0,
320
+ scriptPubKey: {
321
+ asm: 'OP_RETURN 5262419 1 1145980243 938cc18e618967d787897bbc64b9a8d201b94ec7c69b1a9949eab0433ba5cdf8 0000000103907f11',
322
+ hex: '6a04534c500001010453454e4420938cc18e618967d787897bbc64b9a8d201b94ec7c69b1a9949eab0433ba5cdf8080000000103907f11',
323
+ type: 'nulldata'
324
+ },
325
+ tokenQty: null
326
+ },
327
+ {
328
+ value: 0.00000546,
329
+ n: 1,
330
+ scriptPubKey: {
331
+ asm: 'OP_DUP OP_HASH160 059775ff94f65c04e8a6847e74eb9809d8cd779b OP_EQUALVERIFY OP_CHECKSIG',
332
+ hex: '76a914059775ff94f65c04e8a6847e74eb9809d8cd779b88ac',
333
+ reqSigs: 1,
334
+ type: 'pubkeyhash',
335
+ addresses: [
336
+ 'bitcoincash:qqzewa0ljnm9cp8g56z8ua8tnqya3nthnvhv5hpu8y'
337
+ ]
338
+ },
339
+ tokenQtyStr: '43547.68657',
340
+ tokenQty: 43547.68657
341
+ },
342
+ {
343
+ value: 0.00054808,
344
+ n: 2,
345
+ scriptPubKey: {
346
+ asm: 'OP_DUP OP_HASH160 0e330dc9009e1e07831f5a22d4ade8977ab674c8 OP_EQUALVERIFY OP_CHECKSIG',
347
+ hex: '76a9140e330dc9009e1e07831f5a22d4ade8977ab674c888ac',
348
+ reqSigs: 1,
349
+ type: 'pubkeyhash',
350
+ addresses: [
351
+ 'bitcoincash:qq8rxrwfqz0pupurradz949dazth4dn5eqs3mhrucv'
352
+ ]
353
+ },
354
+ tokenQty: null
355
+ }
356
+ ],
357
+ hex: '0100000003f8cda53b43b0ea49991a9bc6c74eb901d2a8b964bc7b8987d76789618ec18c93010000006b483045022100e3d5f9a48f9aa1cf7e9ed1992e0281e7300b734ba0e4bd5bb9265b2be60bd71002200ccde53ce7ea9da9df3e834f234f3bea65c2e58c96f8436f93333fd8946a1db2412102056220984cc2cf5261a27d4f66d31c9ef601a688ca1a5ab81e55b6f0d311be74feffffff34dbf62a45295ae11c2a45f44368218ec64498ac3f7e1434c1993515f53c9dee010000006b483045022100bb90d52be9b568f643fdb1a302e9f063be27a9f914e2a6b192cbabf2cbdeaf9302203c275fc8d1b82390bc1726390d361c5266056bddd54dec23efa207c79eacea4a4121024146cfcd0c02e99d6451dc48ad0f97114aeda18fe55c52a10bfc0490f314e6a2feffffff34dbf62a45295ae11c2a45f44368218ec64498ac3f7e1434c1993515f53c9dee030000006a473044022029ab770c249f467b40bb90410429f6d657f9be299baa19a6838d04d972436b450220143660297e8e836bc16d317649fad8c310bdadb4fb61d4e9f6ba11203abe5dae412102eed4ac9dda3405d9b1ccbbf09f8056f3e7c615924274bd5643238b543d0a1d56feffffff030000000000000000376a04534c500001010453454e4420938cc18e618967d787897bbc64b9a8d201b94ec7c69b1a9949eab0433ba5cdf8080000000103907f1122020000000000001976a914059775ff94f65c04e8a6847e74eb9809d8cd779b88ac18d60000000000001976a9140e330dc9009e1e07831f5a22d4ade8977ab674c888ac7d4b0800',
358
+ blockhash: '00000000000000000140f0d813052da59c811a936494a8d8b2d60b215d19e3dc',
359
+ confirmations: 167007,
360
+ time: 1534391953,
361
+ blocktime: 1534391953,
362
+ isValidSLPTx: true,
363
+ tokenTxType: 'SEND',
364
+ tokenId: '938cc18e618967d787897bbc64b9a8d201b94ec7c69b1a9949eab0433ba5cdf8',
365
+ tokenTicker: 'Bubb2',
366
+ tokenName: 'the new bubbles!',
367
+ tokenDecimals: 5,
368
+ tokenUri: '',
369
+ tokenDocHash: ''
370
+ }
371
+
372
+ const genesisTestOpReturnData01 = {
270
373
  tokenType: 1,
271
374
  txType: 'SEND',
272
375
  tokenId: '323a1e35ae0b356316093d20f2d9fbc995d19314b5c0148b78dc8d9c0dab9d35',
273
376
  amounts: ['5000000', '5000000']
274
377
  }
275
378
 
276
- genesisTestOpReturnData02 = {
379
+ const genesisTestOpReturnData02 = {
277
380
  tokenType: 1,
278
381
  txType: 'GENESIS',
279
382
  ticker: '',
@@ -286,6 +389,36 @@ genesisTestOpReturnData02 = {
286
389
  qty: '10000000'
287
390
  }
288
391
 
392
+ const mintTestOpReturnData01 = {
393
+ tokenType: 1,
394
+ txType: 'SEND',
395
+ tokenId: '938cc18e618967d787897bbc64b9a8d201b94ec7c69b1a9949eab0433ba5cdf8',
396
+ amounts: [
397
+ '4354768657'
398
+ ]
399
+ }
400
+
401
+ const mintTestOpReturnData02 = {
402
+ tokenType: 1,
403
+ txType: 'GENESIS',
404
+ ticker: 'Bubb2',
405
+ name: 'the new bubbles!',
406
+ tokenId: '938cc18e618967d787897bbc64b9a8d201b94ec7c69b1a9949eab0433ba5cdf8',
407
+ documentUri: '',
408
+ documentHash: '',
409
+ decimals: 5,
410
+ mintBatonVout: 2,
411
+ qty: '4354534534'
412
+ }
413
+
414
+ const mintTestOpReturnData03 = {
415
+ tokenType: 1,
416
+ txType: 'MINT',
417
+ tokenId: '938cc18e618967d787897bbc64b9a8d201b94ec7c69b1a9949eab0433ba5cdf8',
418
+ mintBatonVout: 2,
419
+ qty: '234123'
420
+ }
421
+
289
422
  module.exports = {
290
423
  nonSlpTxDetails,
291
424
  slpTxDetails,
@@ -293,6 +426,10 @@ module.exports = {
293
426
  mockOpReturnData02,
294
427
  mockOpReturnData03,
295
428
  genesisTestInputTx,
429
+ mintTestInputTx,
296
430
  genesisTestOpReturnData01,
297
- genesisTestOpReturnData02
431
+ genesisTestOpReturnData02,
432
+ mintTestOpReturnData01,
433
+ mintTestOpReturnData02,
434
+ mintTestOpReturnData03
298
435
  }
@@ -164,5 +164,52 @@ describe('#TransactionLib', () => {
164
164
  assert.equal(result.vin[0].tokenQty, 10000000)
165
165
  assert.equal(result.vin[1].tokenQty, null)
166
166
  })
167
+
168
+ it('should get input details when input is a mint tx', async () => {
169
+ // Mock dependencies
170
+ sandbox
171
+ .stub(bchjs.Transaction.rawTransaction, 'getTxData')
172
+ .resolves(mockData.mintTestInputTx)
173
+ sandbox
174
+ .stub(bchjs.Transaction.slpUtils, 'decodeOpReturn')
175
+ .onCall(0)
176
+ .resolves(mockData.mintTestOpReturnData01)
177
+ .onCall(1)
178
+ .resolves(mockData.mintTestOpReturnData02)
179
+ .onCall(2)
180
+ .resolves(mockData.mintTestOpReturnData02)
181
+ .onCall(3)
182
+ .resolves(mockData.mintTestOpReturnData03)
183
+ .onCall(4)
184
+ .resolves(mockData.mintTestOpReturnData03)
185
+ sandbox
186
+ .stub(bchjs.Transaction.slpUtils, 'waterfallValidateTxid')
187
+ .resolves(true)
188
+
189
+ const txid =
190
+ '4640a734063ea79fa587a3cac38a70a2f6f3db0011e23514024185982110d0fa'
191
+
192
+ const result = await bchjs.Transaction.get(txid)
193
+ // console.log(`result: ${JSON.stringify(result, null, 2)}`)
194
+
195
+ // Assert that there are stanardized properties.
196
+ assert.property(result, 'txid')
197
+ assert.property(result, 'vin')
198
+ assert.property(result, 'vout')
199
+ assert.property(result.vout[0], 'value')
200
+ assert.property(result.vout[1].scriptPubKey, 'addresses')
201
+
202
+ // Assert that added properties exist.
203
+ assert.property(result.vout[0], 'tokenQty')
204
+ assert.equal(result.vout[0].tokenQty, null)
205
+ assert.property(result.vin[0], 'address')
206
+ assert.property(result.vin[0], 'value')
207
+ assert.property(result.vin[0], 'tokenQty')
208
+ assert.property(result, 'isValidSLPTx')
209
+ assert.equal(result.isValidSLPTx, true)
210
+
211
+ // Assert inputs values unique to a Mint input have the proper values.
212
+ assert.equal(result.vin[2].tokenQty, 2.34123)
213
+ })
167
214
  })
168
215
  })