Skip to content

Commit 2eac3c4

Browse files
committed
apikey detection
1 parent 0462bc5 commit 2eac3c4

File tree

3 files changed

+31
-43
lines changed

3 files changed

+31
-43
lines changed

assets_js_bitrequest_fetchblocks.js

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -887,12 +887,9 @@ function omniscan_fetch(rd, api_data, rdo, contract, chainid) {
887887
api_proxy(eth_payload).done(function(e) {
888888
const data = br_result(e).result;
889889
if (data) {
890-
const error = data.error;
890+
const error = (q_obj(data, "status") == 0) || data.error;
891891
if (error) {
892-
const error_object = {
893-
"error": error.message,
894-
"console": true
895-
};
892+
const error_object = data.error || data;
896893
tx_api_scan_fail(rd, api_data, rdo, error_object, null, network);
897894
return
898895
}
@@ -932,12 +929,9 @@ function omniscan_fetch(rd, api_data, rdo, contract, chainid) {
932929
api_proxy(erc20_payload).done(function(e) {
933930
const data = br_result(e).result;
934931
if (data) {
935-
const error = data.error;
932+
const error = (q_obj(data, "status") == 0) || data.error;
936933
if (error) {
937-
const error_object = {
938-
"error": error.message,
939-
"console": true
940-
};
934+
const error_object = data.error || data;
941935
tx_api_scan_fail(rd, api_data, rdo, error_object, null, network);
942936
return
943937
}
@@ -982,12 +976,9 @@ function omniscan_fetch(rd, api_data, rdo, contract, chainid) {
982976
api_proxy(eth_payload).done(function(e) {
983977
const data = br_result(e).result;
984978
if (data) {
985-
const error = data.error;
979+
const error = (q_obj(data, "status") == 0) || data.error;
986980
if (error) {
987-
const error_object = {
988-
"error": error.message,
989-
"console": true
990-
};
981+
const error_object = data.error || data;
991982
tx_api_scan_fail(rd, api_data, rdo, error_object, null, network);
992983
return
993984
}
@@ -1027,12 +1018,9 @@ function omniscan_fetch(rd, api_data, rdo, contract, chainid) {
10271018
api_proxy(erc20_payload).done(function(e) {
10281019
const data = br_result(e).result;
10291020
if (data) {
1030-
const error = data.error;
1021+
const error = (q_obj(data, "status") == 0) || data.error;
10311022
if (error) {
1032-
const error_object = {
1033-
"error": error.message,
1034-
"console": true
1035-
};
1023+
const error_object = data.error || data;
10361024
tx_api_scan_fail(rd, api_data, rdo, error_object, null, network);
10371025
return
10381026
}

assets_js_bitrequest_monitors.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,6 @@ function handle_rpc_fails(rd, rdo, error, api_data, is_proxy, l2) {
422422
error_data = get_api_error_data(error, is_proxy),
423423
timeout = rdo.timeout,
424424
cachetime = rdo.cachetime;
425-
426425
function next_proxy(type) { // try next proxy
427426
if (type === "api_fail" && (error_data.apikey || glob_let.apikey_fails)) return false; // only try next proxy if api key is expired or missing
428427
if (get_next_proxy()) {
@@ -600,21 +599,23 @@ function api_eror_msg(apisrc, error) {
600599
// Extracts and formats error data from various API responses
601600
function get_api_error_data(error, proxy) {
602601
if (!error) return;
603-
const errorcode = error.code || error.status || error.error_code || 0,
604-
errormessage = error.error || error.message || error.type || error.error_message || error.statusText || error,
602+
const result = error.result,
603+
error_code = error.code || error.status || error.error_code || error || 0,
604+
error_message = error.message || error.error_message || error.statusText || error.type || error.error || error,
605605
cons = error.console,
606606
ak_check = (typeof error === "string") ? (error.indexOf("API calls limits have been reached") > -1 || error.indexOf("Limits reached") > -1) : false, // blockcypher
607+
ak_check2 = (result) ? result.indexOf("API Key") > -1 : null, // etherscan
607608
apikey = (
608-
errorcode === 101 || // fixer
609-
errorcode === 402 || // blockchair
610-
errorcode === 403 || errorcode === 1 || // ethplorer => invalid or missing API key
611-
errorcode === 1001 || // coinmarketcap => invalid API key
612-
errorcode === 1002 || // coinmarketcap => missing API key
613-
ak_check
609+
error_code === 101 || // fixer
610+
error_code === 402 || // blockchair
611+
error_code === 403 || error_code === 1 || // ethplorer => invalid or missing API key
612+
error_code === 1001 || // coinmarketcap => invalid API key
613+
error_code === 1002 || // coinmarketcap => missing API key
614+
ak_check || ak_check2
614615
);
615616
const error_dat = {
616-
"errorcode": errorcode,
617-
"errormessage": errormessage,
617+
"errorcode": error_code,
618+
"errormessage": error_message,
618619
"apikey": apikey,
619620
"console": cons
620621
},

assets_js_bitrequest_payments.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,11 +1043,9 @@ function getccexchangerates(apilist, api) {
10431043
error_val = "unable to get " + payment + " rate";
10441044
if (data) {
10451045
if (!empty_obj(data)) {
1046-
const status = data.status,
1047-
has_error = data.statusCode === 404 || data.error || (status && status.error_message);
1046+
const has_error = data.error || q_obj(data, "status.error_code");
10481047
if (has_error) {
1049-
const error_val = data.error || "Unable to get " + payment + " Exchangerate";
1050-
cc_fail(apilist, api, error_val);
1048+
cc_fail(apilist, api, has_error);
10511049
return
10521050
}
10531051
const pnode = iserc ? contract : payment,
@@ -1081,6 +1079,7 @@ function getccexchangerates(apilist, api) {
10811079

10821080
// Handles failure scenarios when fetching cryptocurrency rates
10831081
function cc_fail(apilist, api, error_val, is_proxy) {
1082+
const error_data = get_api_error_data(error_val, is_proxy);
10841083
function next_proxy() { // try next proxy
10851084
if (get_next_proxy()) {
10861085
glob_let.api_attempt[apilist] = {};
@@ -1149,7 +1148,7 @@ function get_fiat_exchangerate(apilist, fiatapi, ccrate, currencystring, ccapi,
11491148
fiatapi === "currencylayer" ? "live" :
11501149
fiatapi === "coinbase" ? "exchange-rates" :
11511150
false;
1152-
if (search === false) {
1151+
if (!search) {
11531152
loadertext(translate("error"));
11541153
closeloader();
11551154
cancelpaymentdialog();
@@ -1231,15 +1230,15 @@ function get_fiat_exchangerate(apilist, fiatapi, ccrate, currencystring, ccapi,
12311230
}
12321231
}
12331232
const nextfiatapi = try_next_api(apilist, fiatapi);
1234-
if (nextfiatapi === false) {
1235-
loadertext(translate("error"));
1236-
closeloader();
1237-
cancelpaymentdialog();
1238-
const errorcode = data.error || "Failed to load data from " + fiatapi;
1239-
fail_dialogs(fiatapi, errorcode);
1233+
if (nextfiatapi) {
1234+
get_fiat_exchangerate(apilist, nextfiatapi, ccrate, currencystring, ccapi, cachetime);
12401235
return
12411236
}
1242-
get_fiat_exchangerate(apilist, nextfiatapi, ccrate, currencystring, ccapi, cachetime);
1237+
loadertext(translate("error"));
1238+
closeloader();
1239+
cancelpaymentdialog();
1240+
const errorcode = data.error || "Failed to load data from " + fiatapi;
1241+
fail_dialogs(fiatapi, errorcode);
12431242
}).fail(function(xhr, stat, err) {
12441243
const is_proxy = is_proxy_fail(this.url),
12451244
error_object = xhr || stat || err;

0 commit comments

Comments
 (0)