Skip to content

Commit 7a32fe7

Browse files
committed
scan rpc node
1 parent 5d8cc12 commit 7a32fe7

File tree

4 files changed

+21
-22
lines changed

4 files changed

+21
-22
lines changed

assets_js_bitrequest_core.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1548,6 +1548,8 @@ function set_result(result) {
15481548
handle_address(result, payment_type);
15491549
} else if (scan_subtype === "viewkey") {
15501550
handle_viewkey(result, payment_type);
1551+
} else if (scan_subtype === "add_node") {
1552+
$("#popup .formbox input#rpc_url_input").val(result);
15511553
}
15521554
window.history.back();
15531555
return false;
@@ -5010,7 +5012,7 @@ function append_coinsetting(currency, settings) {
50105012

50115013
// Subtitle for settings
50125014
function setting_sub_address(currency, name, url) {
5013-
const sub_title = (name === "electrum" || currency === "ethereum") ? url || name : name || url;
5015+
const sub_title = (name === "electrum" || name === "mempool.space" || currency === "ethereum") ? url || name : name || url;
50145016
return exists(sub_title) ? truncate(sub_title) : "";
50155017
}
50165018

assets_js_bitrequest_fetchblocks.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,7 +1771,6 @@ function electrum_rpc_blockheight(rd, api_data, rdo) {
17711771
"params": {
17721772
"method": "POST",
17731773
"cache": true,
1774-
"timeout": 20000,
17751774
"data": JSON.stringify({
17761775
"id": "blockheight",
17771776
"method": "blockchain.headers.subscribe",
@@ -1819,7 +1818,7 @@ function mempoolspace_rpc_blockheight(rd, api_data, rdo, rpc) {
18191818
let block_height = null;
18201819
api_proxy({ // get latest blockheight
18211820
"api_url": base_url + "/api/blocks/tip/height",
1822-
"proxy": false,
1821+
"proxy": base_url.includes(".onion"),
18231822
"params": {
18241823
"method": "GET"
18251824
}
@@ -1875,7 +1874,6 @@ function electrum_rpc(rd, api_data, rdo, latest_block) {
18751874
"params": {
18761875
"method": "POST",
18771876
"cache": true,
1878-
"timeout": 20000,
18791877
"data": JSON.stringify({
18801878
"id": "scanning",
18811879
"method": "blockchain.scripthash.get_history",
@@ -1931,7 +1929,6 @@ function electrum_rpc(rd, api_data, rdo, latest_block) {
19311929
"params": {
19321930
"method": "POST",
19331931
"cache": true,
1934-
"timeout": 20000,
19351932
"data": JSON.stringify({
19361933
"id": "polling",
19371934
"tx_hash": tx_hash,
@@ -1980,6 +1977,7 @@ function mempoolspace_rpc(rd, api_data, rdo, rpc, latest_block) {
19801977
const tx_list = rdo.transactionlist,
19811978
api_url = api_data.url,
19821979
base_url = (rpc) ? api_url : "https://" + api_url,
1980+
is_onion = base_url.includes(".onion"),
19831981
request_id = rd.requestid,
19841982
source = rdo.source;
19851983
let tx_count = 0,
@@ -1988,7 +1986,7 @@ function mempoolspace_rpc(rd, api_data, rdo, rpc, latest_block) {
19881986
if (rdo.pending === "scanning") { // scan incoming transactions on address
19891987
api_proxy({
19901988
"api_url": base_url + "/api/address/" + rd.address + "/txs",
1991-
"proxy": false,
1989+
"proxy": is_onion,
19921990
"params": {
19931991
"method": "GET"
19941992
}
@@ -2032,7 +2030,7 @@ function mempoolspace_rpc(rd, api_data, rdo, rpc, latest_block) {
20322030
}
20332031
api_proxy({ // poll mempool.space transaction id
20342032
"api_url": base_url + "/api/tx/" + rd.txhash,
2035-
"proxy": false,
2033+
"proxy": is_onion,
20362034
"params": {
20372035
"method": "GET"
20382036
}

assets_js_bitrequest_rpcs.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ function edit_rpcnode() {
4646
url_placeholder = get_rpc_placeholder(currency_name)[placeholder_key],
4747
btc_chain = is_btchain(currency_name) === true,
4848
default_placeholder = "some.node:port",
49-
node_select = btc_chain ? "<div class='selectarrows icon-menu2' data-pe='none'></div><div class='options'></div>" : "",
49+
scan_btn = glob_let.hascam ? "<div class='qrscanner' data-currency='" + currency_name + "' data-id='add_node' title='scan qr-code'><span class='icon-qrcode'></span></div>" : "<div class='selectarrows icon-menu2' data-pe='none'></div>",
50+
node_select = btc_chain ? scan_btn + "<div class='options'></div>" : "",
5051
input_form = custom_nodes ? "<div id='rpc_input_box' data-currency='" + currency_name + "' data-erc20='" + glob_let.is_erc20t + "'>\
5152
<h3 class='icon-plus'>" + dialog_title + "</h3>\
5253
<div id='rpc_input'>\
@@ -59,7 +60,7 @@ function edit_rpcnode() {
5960
current_node = item_data.selected,
6061
node_name = current_node.name,
6162
node_url = current_node.url,
62-
node_title = (node_name === "electrum") ? node_url : node_name || node_url,
63+
node_title = (node_name === "electrum" || node_name === "mempool.space") ? node_url : node_name || node_url,
6364
dialog_html = "\
6465
<div class='formbox' id='settingsbox' data-id='" + glob_let.ap_id + "'>\
6566
<h2 class='icon-sphere'>" + tl("choose") + " " + currency_name + " " + glob_let.ap_id + "</h2>\
@@ -102,8 +103,8 @@ function edit_rpcnode() {
102103
}
103104

104105
function fetch_electrum_nodes(currency, node_url, predefined_nodes, custom_nodes) {
105-
const coin_settings = get_coinsettings(currency),
106-
random_node = get_random_electrum_node(predefined_nodes);
106+
const existing_nodes = $.extend(predefined_nodes, custom_nodes),
107+
random_node = get_random_electrum_node(existing_nodes);
107108
if (random_node) {
108109
const rpc_list = $("#rpc_list"),
109110
api_options = rpc_list.find(".options"),
@@ -184,7 +185,6 @@ function fetch_electrum_nodes(currency, node_url, predefined_nodes, custom_nodes
184185
"params": {
185186
"method": "POST",
186187
"cache": true,
187-
"timeout": 20000,
188188
"data": JSON.stringify({
189189
"id": sha_sub(rpc_url2, 6),
190190
"method": "blockchain.transaction.get",
@@ -303,7 +303,6 @@ function validate_and_add_rpc_node(currency_name, api_list, node_id, node_data,
303303
"params": {
304304
"method": "POST",
305305
"cache": true,
306-
"timeout": 20000,
307306
"data": JSON.stringify({
308307
"id": sha_sub(rpc_url, 6),
309308
"method": "blockchain.transaction.get",
@@ -328,12 +327,13 @@ function validate_and_add_rpc_node(currency_name, api_list, node_id, node_data,
328327
const api_rpc_url = node_data.api ? glob_const.mempool_space[currency_name] : rpc_url;
329328
api_proxy({ // mempoolspace API
330329
"api_url": api_rpc_url + "/api/v1/difficulty-adjustment",
331-
"proxy": false,
330+
"proxy": api_rpc_url.includes(".onion"),
332331
"params": {
333332
"method": "GET"
334333
}
335334
}).done(function(e) {
336-
const result = e.progressPercent || e.difficultyChange || e.estimatedRetargetDate;
335+
const ar = br_result(e).result,
336+
result = ar.progressPercent || ar.difficultyChange || ar.estimatedRetargetDate;
337337
is_live = (result) ? true : false;
338338
create_rpc_node_element(api_list, is_live, node_id, node_data, is_selected, true);
339339
}).fail(function(xhr, stat, err) {
@@ -591,7 +591,6 @@ function validate_rpc_connection(input_section, node_config, currency_name) {
591591
"params": {
592592
"method": "POST",
593593
"cache": true,
594-
"timeout": 20000,
595594
"data": JSON.stringify({
596595
"id": sha_sub(rpc_url, 6),
597596
"method": "blockchain.transaction.get",
@@ -615,7 +614,6 @@ function validate_rpc_connection(input_section, node_config, currency_name) {
615614
"params": {
616615
"method": "POST",
617616
"cache": true,
618-
"timeout": 20000,
619617
"data": JSON.stringify({
620618
"id": "scanning",
621619
"method": "blockchain.scripthash.get_history",
@@ -633,22 +631,20 @@ function validate_rpc_connection(input_section, node_config, currency_name) {
633631
input_section.addClass("live").removeClass("offline");
634632
node_config.name = "electrum";
635633
save_rpc_settings(currency_name, node_config, true);
634+
closeloader();
636635
return
637636
}
638637
}
639638
}
640639
test_mempoolspace(input_section, node_config, rpc_url, currency_name);
641640
}).fail(function(xhr, stat, err) {
642641
test_mempoolspace(input_section, node_config, rpc_url, currency_name);
643-
}).always(function() {
644-
closeloader();
645642
});
646643
return
647644
}
648645
test_mempoolspace(input_section, node_config, rpc_url, currency_name);
649646
}).fail(function(xhr, stat, err) {
650647
test_mempoolspace(input_section, node_config, rpc_url, currency_name);
651-
closeloader();
652648
});
653649
return
654650
}
@@ -754,7 +750,7 @@ function test_mempoolspace(input_section, node_config, rpc_url, currency_name) {
754750
error_message = tl("unabletoconnect");
755751
api_proxy({
756752
"api_url": rpc_url + "/api/address/" + test_address + "/txs",
757-
"proxy": false,
753+
"proxy": rpc_url.includes(".onion"),
758754
"params": {
759755
"method": "GET"
760756
}
@@ -768,6 +764,7 @@ function test_mempoolspace(input_section, node_config, rpc_url, currency_name) {
768764
input_section.addClass("live").removeClass("offline");
769765
node_config.name = "mempool.space";
770766
save_rpc_settings(currency_name, node_config, true);
767+
closeloader();
771768
return
772769
}
773770
}
@@ -777,6 +774,8 @@ function test_mempoolspace(input_section, node_config, rpc_url, currency_name) {
777774
}).fail(function(error) {
778775
input_section.addClass("offline").removeClass("live");
779776
popnotify("error", error_message);
777+
}).always(function() {
778+
closeloader();
780779
});
781780
}
782781

assets_js_lib_global_queries.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ function api_proxy(ad, p_proxy) {
10241024
ad.api = c_apiname(api_name);
10251025
const api_path = "proxy/v1/",
10261026
root_url = ad.localhost ? "" : active_proxy,
1027-
timeout = q_obj(ad, "params.timeout") || 5000,
1027+
timeout = (custom_url && custom_url !== true) && custom_url.includes(".onion") ? glob_const.tor_timeout : 5000,
10281028
proxy_config = {
10291029
"method": "POST",
10301030
"cache": false,

0 commit comments

Comments
 (0)