@pioneer-platform/blockbook 8.3.16 → 8.3.17
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/.claude/settings.local.json +11 -0
- package/lib/index.js +38 -4
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -777,7 +777,7 @@ function get_transaction(coin, txid) {
|
|
|
777
777
|
*/
|
|
778
778
|
function get_utxos_by_xpub(coin_1, xpub_1) {
|
|
779
779
|
return __awaiter(this, arguments, void 0, function (coin, xpub, confirmedOnly) {
|
|
780
|
-
var tag, baseUrl, url, resp, utxos, e_10;
|
|
780
|
+
var tag, baseUrl, url, hasApiKeyInUrl, resp, utxos, e_10;
|
|
781
781
|
if (confirmedOnly === void 0) { confirmedOnly = false; }
|
|
782
782
|
return __generator(this, function (_a) {
|
|
783
783
|
switch (_a.label) {
|
|
@@ -790,19 +790,33 @@ function get_utxos_by_xpub(coin_1, xpub_1) {
|
|
|
790
790
|
if (!baseUrl) {
|
|
791
791
|
throw new Error("Unknown coin '".concat(coin, "' or missing BLOCKBOOK_URLS entry"));
|
|
792
792
|
}
|
|
793
|
-
url = "".concat(baseUrl, "/api/v2/utxo/").concat(xpub);
|
|
793
|
+
url = "".concat(baseUrl, "/api/v2/utxo/").concat(encodeURIComponent(xpub));
|
|
794
794
|
log.debug(tag, "Fetching UTXOs from:", url);
|
|
795
|
+
log.debug(tag, "Base URL:", baseUrl);
|
|
796
|
+
log.debug(tag, "Full xpub:", xpub);
|
|
797
|
+
hasApiKeyInUrl = baseUrl.includes(NOW_NODES_API || '');
|
|
795
798
|
return [4 /*yield*/, axios({
|
|
796
799
|
method: 'GET',
|
|
797
800
|
url: url,
|
|
798
|
-
headers: __assign({ 'content-type': 'application/json', 'User-Agent': typeof fakeUa === 'function' ? fakeUa() : 'blockbook-client/1.0' }, (NOW_NODES_API && { 'api-key': NOW_NODES_API })),
|
|
801
|
+
headers: __assign({ 'content-type': 'application/json', 'User-Agent': typeof fakeUa === 'function' ? fakeUa() : 'blockbook-client/1.0' }, (NOW_NODES_API && !hasApiKeyInUrl && { 'api-key': NOW_NODES_API })),
|
|
799
802
|
params: {
|
|
800
803
|
confirmed: confirmedOnly
|
|
801
804
|
}
|
|
802
805
|
})];
|
|
803
806
|
case 2:
|
|
804
807
|
resp = _a.sent();
|
|
808
|
+
// Check if we got HTML instead of JSON (error page)
|
|
809
|
+
if (typeof resp.data === 'string' && resp.data.includes('<!doctype html>')) {
|
|
810
|
+
log.error(tag, "Received HTML error page instead of JSON data");
|
|
811
|
+
log.error(tag, "Response content:", resp.data.substring(0, 500) + "...");
|
|
812
|
+
throw new Error("Blockbook server returned HTML error page for ".concat(coin, ". Check server status and xpub format."));
|
|
813
|
+
}
|
|
805
814
|
utxos = resp.data;
|
|
815
|
+
if (!Array.isArray(utxos)) {
|
|
816
|
+
log.error(tag, "Invalid response format - expected array but got:", typeof utxos);
|
|
817
|
+
log.error(tag, "Response data:", utxos);
|
|
818
|
+
throw new Error("Invalid UTXO response format from Blockbook server for ".concat(coin));
|
|
819
|
+
}
|
|
806
820
|
log.info(tag, "Found ".concat(utxos.length, " UTXOs for xpub"));
|
|
807
821
|
return [2 /*return*/, utxos];
|
|
808
822
|
case 3:
|
|
@@ -832,17 +846,33 @@ function get_balance_by_xpub(coin, xpub) {
|
|
|
832
846
|
_a.trys.push([1, 3, , 4]);
|
|
833
847
|
log.debug(tag, "Getting balance for coin:", coin);
|
|
834
848
|
log.debug(tag, "xpub:", xpub);
|
|
849
|
+
// Validate xpub format before making API call
|
|
850
|
+
if (!xpub || typeof xpub !== 'string' || xpub.length < 50) {
|
|
851
|
+
throw new Error("Invalid xpub format: ".concat(xpub));
|
|
852
|
+
}
|
|
835
853
|
return [4 /*yield*/, get_utxos_by_xpub(coin, xpub, false)];
|
|
836
854
|
case 2:
|
|
837
855
|
utxos = _a.sent();
|
|
838
856
|
log.debug(tag, "Processing ".concat(utxos.length, " UTXOs"));
|
|
857
|
+
// Validate UTXOs array
|
|
858
|
+
if (!Array.isArray(utxos)) {
|
|
859
|
+
log.error(tag, "UTXOs response is not an array:", typeof utxos);
|
|
860
|
+
throw new Error("Invalid UTXOs response format");
|
|
861
|
+
}
|
|
839
862
|
balanceSatoshis = 0;
|
|
840
863
|
for (_i = 0, utxos_1 = utxos; _i < utxos_1.length; _i++) {
|
|
841
864
|
utxo = utxos_1[_i];
|
|
865
|
+
if (!utxo || typeof utxo !== 'object') {
|
|
866
|
+
log.warn(tag, "Invalid UTXO object:", utxo);
|
|
867
|
+
continue;
|
|
868
|
+
}
|
|
842
869
|
value = parseInt(utxo.value, 10);
|
|
843
|
-
if (!isNaN(value)) {
|
|
870
|
+
if (!isNaN(value) && value > 0) {
|
|
844
871
|
balanceSatoshis += value;
|
|
845
872
|
}
|
|
873
|
+
else {
|
|
874
|
+
log.warn(tag, "Invalid UTXO value:", utxo.value);
|
|
875
|
+
}
|
|
846
876
|
}
|
|
847
877
|
balanceBTC = balanceSatoshis / 100000000;
|
|
848
878
|
log.info(tag, "Total balance: ".concat(balanceBTC, " BTC (").concat(balanceSatoshis, " satoshis)"));
|
|
@@ -850,6 +880,10 @@ function get_balance_by_xpub(coin, xpub) {
|
|
|
850
880
|
case 3:
|
|
851
881
|
e_11 = _a.sent();
|
|
852
882
|
log.error(tag, "Failed to get balance for xpub:", e_11);
|
|
883
|
+
// Re-throw with more context if it's a generic error
|
|
884
|
+
if (e_11 instanceof Error && e_11.message.includes('<!doctype html>')) {
|
|
885
|
+
throw new Error("Blockbook server error: Received HTML response instead of JSON data for ".concat(coin, ". Server may be down or xpub format invalid."));
|
|
886
|
+
}
|
|
853
887
|
throw e_11;
|
|
854
888
|
case 4: return [2 /*return*/];
|
|
855
889
|
}
|