Skip to content

Commit b1cf13d

Browse files
committed
filter out electrum ip addresses
1 parent 7a32fe7 commit b1cf13d

File tree

3 files changed

+76
-59
lines changed

3 files changed

+76
-59
lines changed

assets_js_bitrequest_fetchblocks.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,8 @@ function mempoolspace_rpc(rd, api_data, rdo, rpc, latest_block) {
19861986
if (rdo.pending === "scanning") { // scan incoming transactions on address
19871987
api_proxy({
19881988
"api_url": base_url + "/api/address/" + rd.address + "/txs",
1989+
"cachetime": rdo.cachetime,
1990+
"cachefolder": "1h",
19891991
"proxy": is_onion,
19901992
"params": {
19911993
"method": "GET"
@@ -2030,6 +2032,8 @@ function mempoolspace_rpc(rd, api_data, rdo, rpc, latest_block) {
20302032
}
20312033
api_proxy({ // poll mempool.space transaction id
20322034
"api_url": base_url + "/api/tx/" + rd.txhash,
2035+
"cachetime": rdo.cachetime,
2036+
"cachefolder": "1h",
20332037
"proxy": is_onion,
20342038
"params": {
20352039
"method": "GET"

assets_js_bitrequest_rpcs.js

Lines changed: 66 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -155,67 +155,74 @@ function fetch_electrum_nodes(currency, node_url, predefined_nodes, custom_nodes
155155
result = q_obj(api_result, "result"),
156156
list_length = result.length;
157157
let done = false;
158-
if (list_length && result) {
159-
$.each(result, function(node_id, nd) {
160-
const url = nd[0];
161-
let tport = null;
162-
if (url) {
163-
const port_arr = nd[2];
164-
if (is_array(port_arr)) {
165-
tport = port_arr[1];
166-
}
158+
if (list_length && is_array(result)) {
159+
short_list = (list_length > 75) ? result.slice(0, 75) : result;
160+
$.each(short_list, function(node_id, nd) {
161+
const url = nd[1] || nd[0],
162+
filter_ips = is_valid_ipv4(url);
163+
if (filter_ips) {
164+
// filter out electrum ip's and only add regular urls
167165
}
168-
const port = tport ? ((/^\d/.test(tport)) ? ":" + port : ":" + tport.slice(1)) : "",
169-
rpc_url2 = url + port,
170-
node_exists = check_node_exists(rpc_url2, existing_nodes);
171-
if (!node_exists) {
172-
const node_data = {
173-
"name": "electrum",
174-
"url": rpc_url2,
175-
"display": true
176-
},
177-
test_tx = glob_const.test_tx[currency];
178-
api_proxy({
179-
"api": currency,
180-
"cachetime": 25,
181-
"cachefolder": "1h",
182-
"custom": "electrum",
183-
"api_url": rpc_url2,
184-
"proxy": true,
185-
"params": {
186-
"method": "POST",
187-
"cache": true,
188-
"data": JSON.stringify({
189-
"id": sha_sub(rpc_url2, 6),
190-
"method": "blockchain.transaction.get",
191-
"ref": test_tx,
192-
"node": rpc_url2
193-
})
194-
}
195-
}).done(function(e) {
196-
const api_result = br_result(e),
197-
result = q_obj(api_result, "result");
198-
if (is_valid_tx_hex(result)) {
199-
const is_selected = rpc_url2 === node_url;
200-
create_rpc_node_element(api_options, true, node_id, node_data, is_selected, true);
201-
node_list_obj.push({
202-
node_id,
203-
rpc_url2
204-
});
166+
else {
167+
let tport = null;
168+
if (url) {
169+
const port_arr = nd[2];
170+
if (is_array(port_arr)) {
171+
tport = port_arr[1];
205172
}
206-
}).always(function() {
207-
if (done) return;
208-
const count = list_length - node_id;
209-
if (count === 1 || count === 2 || count === 3) { // some margin for flexibility
210-
done = true;
211-
const margin_timeout = setTimeout(function() {
212-
br_set_session("electrum_" + currency, node_list_obj, true);
213-
rpc_list.addClass("show_select");
214-
}, 500, function() {
215-
clearTimeout(margin_timeout);
216-
});
217-
}
218-
});
173+
}
174+
const port = tport ? ((/^\d/.test(tport)) ? ":" + port : ":" + tport.slice(1)) : "",
175+
rpc_url2 = url + port,
176+
node_exists = check_node_exists(rpc_url2, existing_nodes);
177+
if (!node_exists) {
178+
const node_data = {
179+
"name": "electrum",
180+
"url": rpc_url2,
181+
"display": true
182+
},
183+
test_tx = glob_const.test_tx[currency];
184+
api_proxy({
185+
"api": currency,
186+
"cachetime": 25,
187+
"cachefolder": "1h",
188+
"custom": "electrum",
189+
"api_url": rpc_url2,
190+
"proxy": true,
191+
"params": {
192+
"method": "POST",
193+
"cache": true,
194+
"data": JSON.stringify({
195+
"id": sha_sub(rpc_url2, 6),
196+
"method": "blockchain.transaction.get",
197+
"ref": test_tx,
198+
"node": rpc_url2
199+
})
200+
}
201+
}).done(function(e) {
202+
const api_result = br_result(e),
203+
result2 = q_obj(api_result, "result");
204+
if (is_valid_tx_hex(result2)) {
205+
const is_selected = rpc_url2 === node_url;
206+
create_rpc_node_element(api_options, true, node_id, node_data, is_selected, true);
207+
node_list_obj.push({
208+
node_id,
209+
rpc_url2
210+
});
211+
}
212+
}).always(function() {
213+
if (done) return;
214+
const count = list_length - node_id;
215+
if (count === 1 || count === 2 || count === 3) { // some margin for flexibility
216+
done = true;
217+
const margin_timeout = setTimeout(function() {
218+
br_set_session("electrum_" + currency, node_list_obj, true);
219+
rpc_list.addClass("show_select");
220+
}, 500, function() {
221+
clearTimeout(margin_timeout);
222+
});
223+
}
224+
});
225+
}
219226
}
220227
});
221228
}

assets_js_lib_global_queries.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ let request = null,
319319
//get_erc20_settings
320320
//add_prefix_to_keys
321321
//get_cached_tokens
322+
//is_valid_ipv4
322323

323324
// ** Core Storage Functions: **
324325

@@ -1314,4 +1315,9 @@ function get_cached_tokens(check) {
13141315
}
13151316
}
13161317
return false;
1318+
}
1319+
1320+
function is_valid_ipv4(ip) {
1321+
const regex = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
1322+
return regex.test(ip);
13171323
}

0 commit comments

Comments
 (0)