@pioneer-platform/utxo-network 8.11.9 → 8.11.11

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.
@@ -1 +1,2 @@
1
- $ tsc -p .
1
+
2
+ $ tsc -p .
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @pioneer-platform/utxo-network
2
2
 
3
+ ## 8.11.11
4
+
5
+ ### Patch Changes
6
+
7
+ - cache work
8
+ - Updated dependencies
9
+ - @pioneer-platform/blockbook@8.11.1
10
+ - @pioneer-platform/unchained@8.11.2
11
+
12
+ ## 8.11.10
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies
17
+ - @pioneer-platform/nodes@8.11.10
18
+
3
19
  ## 8.11.9
4
20
 
5
21
  ### Patch Changes
package/lib/index.js CHANGED
@@ -236,15 +236,51 @@ const init_network = async function (servers) {
236
236
  }
237
237
  };
238
238
  exports.init_network = init_network;
239
+ /**
240
+ * Normalize pubkey info response to ensure consistent data structure
241
+ *
242
+ * @param coin - Coin symbol (BTC, DOGE, LTC, etc.)
243
+ * @param rawData - Raw data from blockbook API
244
+ * @returns Normalized pubkey info with guaranteed tokens array structure
245
+ */
246
+ let normalize_pubkey_info = function (coin, rawData) {
247
+ const tag = TAG + " | normalize_pubkey_info | ";
248
+ // Ensure tokens array exists
249
+ if (!rawData.tokens || !Array.isArray(rawData.tokens)) {
250
+ log.warn(tag, `Missing or invalid tokens array for ${coin}, initializing empty array`);
251
+ rawData.tokens = [];
252
+ }
253
+ // Validate usedTokens field
254
+ if (typeof rawData.usedTokens !== 'number') {
255
+ rawData.usedTokens = rawData.tokens.length;
256
+ log.debug(tag, `Calculated usedTokens from tokens array length: ${rawData.usedTokens}`);
257
+ }
258
+ // Ensure numeric fields are properly typed
259
+ rawData.balance = rawData.balance || '0';
260
+ rawData.totalReceived = rawData.totalReceived || '0';
261
+ rawData.totalSent = rawData.totalSent || '0';
262
+ rawData.txs = typeof rawData.txs === 'number' ? rawData.txs : 0;
263
+ // If we have transactions but no tokens, log a warning
264
+ if (rawData.txs > 0 && rawData.tokens.length === 0) {
265
+ log.warn(tag, `⚠️ ${coin} xpub has ${rawData.txs} transactions but 0 address tokens!`);
266
+ log.warn(tag, `This may indicate blockbook is not returning ?details=tokens properly`);
267
+ log.warn(tag, `Address index calculations may be incorrect - fallback to index 0`);
268
+ }
269
+ return rawData;
270
+ };
239
271
  let get_pubkey_info = async function (coin, xpub) {
240
272
  let tag = TAG + " | get_pubkey_info | ";
241
273
  try {
242
- let output = await blockbook.getPubkeyInfo(coin, xpub);
243
- log.debug(tag, "output: ", output);
274
+ let rawOutput = await blockbook.getPubkeyInfo(coin, xpub);
275
+ log.debug(tag, "raw blockbook output: ", rawOutput);
276
+ // Normalize the response to ensure consistent structure
277
+ let output = normalize_pubkey_info(coin, rawOutput);
278
+ log.debug(tag, "normalized output: ", output);
244
279
  return output;
245
280
  }
246
281
  catch (e) {
247
282
  console.error(tag, e);
283
+ throw e;
248
284
  }
249
285
  };
250
286
  let get_fees_with_memo = async function (coin, memo) {
@@ -469,7 +505,22 @@ let get_utxos_by_xpub = async function (coin, xpub) {
469
505
  let get_balance_by_xpub = async function (coin, xpub) {
470
506
  let tag = TAG + " | get_balance_by_xpub | ";
471
507
  try {
508
+ const isBitcoin = coin === 'BTC';
509
+ if (isBitcoin)
510
+ log.info(tag, '🔍 [BITCOIN] Calling blockbook.utxosByXpub with:', {
511
+ coin,
512
+ xpub: xpub.substring(0, 20) + '...'
513
+ });
472
514
  let output = await blockbook.utxosByXpub(coin, xpub);
515
+ if (isBitcoin)
516
+ log.info(tag, '🔍 [BITCOIN] Blockbook response:', {
517
+ utxoCount: output.length,
518
+ utxos: output.map((u) => ({
519
+ value: u.value,
520
+ confirmations: u.confirmations,
521
+ txid: u.txid?.substring(0, 16) + '...'
522
+ }))
523
+ });
473
524
  log.info(tag, "output: ", output);
474
525
  let balance = 0;
475
526
  //tally
@@ -477,10 +528,13 @@ let get_balance_by_xpub = async function (coin, xpub) {
477
528
  let uxto = output[i];
478
529
  balance = balance + parseInt(uxto.value);
479
530
  }
531
+ if (isBitcoin)
532
+ log.info(tag, '🔍 [BITCOIN] Total balance (satoshis):', balance);
480
533
  return balance;
481
534
  }
482
535
  catch (e) {
483
536
  console.error(tag, e);
537
+ throw e; // Propagate error instead of returning undefined
484
538
  }
485
539
  };
486
540
  let get_block_hash = async function (coin, height) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pioneer-platform/utxo-network",
3
- "version": "8.11.9",
3
+ "version": "8.11.11",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "scripts": {
@@ -11,11 +11,11 @@
11
11
  "build:live": "nodemon --watch 'src/**/*.ts' --exec 'ts-node' src/index.ts"
12
12
  },
13
13
  "dependencies": {
14
- "@pioneer-platform/blockbook": "^8.11.0",
14
+ "@pioneer-platform/blockbook": "^8.11.1",
15
15
  "@pioneer-platform/loggerdog": "^8.11.0",
16
- "@pioneer-platform/nodes": "8.11.9",
16
+ "@pioneer-platform/nodes": "^8.11.10",
17
17
  "@pioneer-platform/pioneer-caip": "^9.10.0",
18
- "@pioneer-platform/unchained": "^8.11.1",
18
+ "@pioneer-platform/unchained": "^8.11.2",
19
19
  "@types/request-promise-native": "^1.0.17",
20
20
  "@xchainjs/xchain-client": "^0.7.0",
21
21
  "@xchainjs/xchain-util": "^0.2.6",
@@ -34,4 +34,4 @@
34
34
  "typescript": "^5.0.4"
35
35
  },
36
36
  "gitHead": "a76012f6693a12181c4744e53e977a9eaeef0ed3"
37
- }
37
+ }