Skip to content

Commit c4feed9

Browse files
committed
rpc caching
1 parent 36651de commit c4feed9

6 files changed

+271
-188
lines changed

assets_js_bitrequest_bip39.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ function format_keys(seed, key_data, bip32_config, index, coin) {
13611361
return {
13621362
"index": index,
13631363
"address": xmr_keys.address,
1364-
"vk": xmr_keys.account + xmr_keys.svk
1364+
"vk": xmr_keys.svk
13651365
}
13661366
}
13671367
return formatted_keys;

assets_js_bitrequest_core.js

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,24 +1134,15 @@ function triggertx_function(trigger_elem) {
11341134
triggertx_function(trigger_elem);
11351135
return
11361136
}
1137-
const use_random = cs_node(currency, "Use random address", true).selected,
1138-
derives = check_derivations(currency),
1139-
address_list = filter_addressli(currency, "checked", true),
1140-
first_address = address_list.first(),
1141-
manual_addresses = address_list.not(".seed"),
1142-
address_count = manual_addresses.length,
1143-
random_pool = (address_count > 1) ? manual_addresses : first_address,
1144-
random_index = generate_random_number(1, address_count) - 1,
1145-
selected_address = (use_random === true) ? (first_address.hasClass("seed")) ? first_address : manual_addresses.eq(random_index) : first_address,
1146-
address_data = selected_address.data();
1137+
const address_data = get_address_data(currency);
11471138
if (address_data) {
11481139
const wallet_address = address_data.address,
11491140
request_title = trigger_elem.attr("title"),
11501141
saved_url = trigger_elem.data("url"),
11511142
seed_id = address_data.seedid;
11521143
if (seed_id) {
11531144
if (seed_id != glob_let.bipid) {
1154-
if (addr_whitelist(wallet_address) === true) {} else {
1145+
if (!addr_whitelist(wallet_address)) {
11551146
const dialog_data = {
11561147
"currency": currency,
11571148
"address": wallet_address,
@@ -1387,7 +1378,7 @@ function toggle_address() {
13871378
if (address_item.hasClass("seedu")) {
13881379
const wallet_address = address_data.address,
13891380
seed_id = address_data.seedid;
1390-
if (addr_whitelist(wallet_address) !== true) {
1381+
if (!addr_whitelist(wallet_address)) {
13911382
const dialog_data = {
13921383
"address": wallet_address,
13931384
"pli": address_item,
@@ -1399,7 +1390,7 @@ function toggle_address() {
13991390
}
14001391
} else if (address_item.hasClass("xpubu")) {
14011392
const wallet_address = address_data.address;
1402-
if (addr_whitelist(wallet_address) !== true) {
1393+
if (!addr_whitelist(wallet_address)) {
14031394
const has_pub_key = has_xpub(currency),
14041395
pub_key_id = address_data.xpubid;
14051396
if (has_pub_key === false || (has_pub_key && has_pub_key.key_id != pub_key_id)) {
@@ -2646,7 +2637,7 @@ function newrequest() {
26462637
seed_id = addr_data.seedid;
26472638
if (seed_id) {
26482639
if (seed_id !== glob_let.bipid) {
2649-
if (addr_whitelist(address) !== true) {
2640+
if (!addr_whitelist(address)) {
26502641
const warning_data = {
26512642
"currency": currency,
26522643
"address": address,
@@ -2755,24 +2746,12 @@ function addressinfo() {
27552746
$(document).on("click", ".address_info", function() {
27562747
const dialog_wrap = $(this).closest("ul"),
27572748
dialog_data = dialog_wrap.data(),
2758-
label = dialog_data.label || dialog_data.a_id || "",
27592749
currency = dialog_data.currency,
2760-
hasbip32 = has_bip32(currency),
2761-
bip32_data = hasbip32 ? get_bip32dat(currency) : null,
2762-
seed_id = dialog_data.seedid,
2763-
xpub_id = dialog_data.xpubid,
2764-
view_key = dialog_data.vk,
2765-
source_type = seed_id ? "seed" : xpub_id ? "xpub" : false,
2766-
is_seed = source_type === "seed",
2767-
xpub = source_type === "xpub",
2768-
active_xpub_data = active_xpub(currency),
2769-
is_active_source = is_seed ? (seed_id === glob_let.bipid) : (xpub ? (active_xpub_data && xpub_id === active_xpub_data.key_id) : false),
2770-
address = dialog_data.address,
2771-
addr_whitelist_status = addr_whitelist(address),
2772-
restore_btn = is_seed ? (glob_let.hasbip === true) ? "" : "<div id='rest_seed' class='ref' data-seedid='" + seed_id + "'>" + tl("resoresecretphrase") + "</div>" : "",
2773-
source_label = source_type ? (is_active_source) ? source_type + " <span class='icon-checkmark'>" : source_type + " (Unavailable)" + restore_btn : "external",
27742750
derive_index = dialog_data.derive_index,
2775-
purpose = dialog_data.purpose;
2751+
purpose = dialog_data.purpose,
2752+
address = dialog_data.address,
2753+
hasbip32 = has_bip32(currency),
2754+
bip32_data = hasbip32 ? get_bip32dat(currency) : null;
27762755
let deriv_path = bip32_data ? bip32_data.root_path + derive_index : "";
27772756
if (purpose) {
27782757
const path_parts = deriv_path.split("/");
@@ -2783,15 +2762,27 @@ function addressinfo() {
27832762
dialog_data.bip32dat = bip32_data,
27842763
dialog_data.address = address;
27852764
const currency_icon = getcc_icon(dialog_data.cmcid, dialog_data.ccsymbol + "-" + currency, dialog_data.erc20),
2786-
path_info = is_seed ? "<li><strong>" + tl("derivationpath") + ":</strong> " + deriv_path + "</li>" : "",
2765+
xpub_id = dialog_data.xpubid,
2766+
seed_id = dialog_data.seedid,
2767+
source_type = seed_id ? "seed" : xpub_id ? "xpub" : false,
27872768
pk_verified = "Unknown <span class='icon-checkmark'></span>",
2769+
show_label = tl("show"),
2770+
addr_whitelist_status = addr_whitelist(address),
2771+
active_xpub_data = active_xpub(currency),
2772+
xpub = source_type === "xpub",
2773+
is_seed = source_type === "seed",
2774+
is_active_source = is_seed ? (seed_id === glob_let.bipid) : (xpub ? (active_xpub_data && xpub_id === active_xpub_data.key_id) : false),
2775+
view_key = dialog_data.vk,
27882776
view_key_obj = view_key ? vk_obj(view_key) : false,
27892777
view_key_data = view_key_obj ? (is_seed && is_active_source ? "derive" : view_key_obj.vk) : false,
2790-
show_label = tl("show"),
27912778
pk_display = view_key_data ? "<span id='show_vk' class='ref' data-vk='" + view_key_data + "'>" + show_label + "</span>" :
2792-
(is_seed ? (is_active_source ? "<span id='show_pk' class='ref'>" + show_label + "</span>" :
2793-
(addr_whitelist_status === true ? pk_verified : "Unknown")) : pk_verified);
2794-
privatekey_label = tl("privatekey"),
2779+
is_seed ? is_active_source ? "<span id='show_pk' class='ref'>" + show_label + "</span>" :
2780+
addr_whitelist_status ? pk_verified : "Unknown" : pk_verified,
2781+
privatekey_label = tl("privatekey"),
2782+
label = dialog_data.label || dialog_data.a_id || "",
2783+
restore_btn = is_seed ? (glob_let.hasbip === true) ? "" : "<div id='rest_seed' class='ref' data-seedid='" + seed_id + "'>" + tl("resoresecretphrase") + "</div>" : "",
2784+
source_label = source_type ? (is_active_source) ? source_type + " <span class='icon-checkmark'>" : source_type + " (Unavailable)" + restore_btn : "external",
2785+
path_info = is_seed ? "<li><strong>" + tl("derivationpath") + ":</strong> " + deriv_path + "</li>" : "",
27952786
info_content = $("<div id='ad_info_wrap'><h2>" + currency_icon + " <span>" + label + "</span></h2><ul>\
27962787
<li><strong>" + tl("address") + ": </strong><span class='adbox adboxl select'>" + address + "</span>\
27972788
<div id='qrcodea' class='qrwrap flex'><div class='qrcode'></div>" + currency_icon + "</div>\
@@ -3692,7 +3683,7 @@ function recent_requests_list(recent_payments) {
36923683
explorer_url = blockexplorer_url(currency, false, is_erc20, tx_source, eth_layer) + wallet_addr;
36933684
request_html += "<li class='rp_li'>" + getcc_icon(coin_id, coin_symbol + "-" + currency, is_erc20) + "<strong style='opacity:0.5'>" + short_date(request_time) + "</strong><br/>\
36943685
<a href='" + explorer_url + "' target='_blank' class='ref check_recent'>\
3695-
<span class='select'>" + wallet_addr + "</span> <span class='icon-new-tab'></a></li>";
3686+
<span class='select'>" + wallet_addr + "</span> <span class='icon-new-tab'></span></a></li>";
36963687
}
36973688
});
36983689
return request_html;

assets_js_bitrequest_fetchblocks.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ function monero_lws_login(rd, api_data, rdo) {
10351035
xmr_settings = active_coinsettings("monero"),
10361036
set_lws_host = q_obj(xmr_settings, "apis.lws_selected.url"),
10371037
lws_host = set_lws_host || lws_proxy;
1038-
if (monero_lws_node_access(view_key)) {
1038+
if (monero_lws_node_access(lws_host, view_key)) {
10391039
monero_lws_get_address_txs(rd, api_data, rdo, viewkey, lws_host);
10401040
return
10411041
}
@@ -1065,7 +1065,7 @@ function monero_lws_login(rd, api_data, rdo) {
10651065
if (api_result) {
10661066
const new_address = api_result.new_address;
10671067
if (new_address === true || new_address === false) { // confirm response
1068-
set_monero_lws_node_access(view_key);
1068+
set_monero_lws_node_access(lws_host, view_key);
10691069
monero_lws_get_address_txs(rd, api_data, rdo, viewkey, lws_host);
10701070
return
10711071
}
@@ -1082,22 +1082,24 @@ function monero_lws_login(rd, api_data, rdo) {
10821082
}
10831083

10841084
// Stores Monero view key in session storage
1085-
function set_monero_lws_node_access(view_key) {
1086-
const stored_keys = br_get_session("xmrvks", true);
1085+
function set_monero_lws_node_access(host, view_key) {
1086+
const hostkey_hash = sha_sub(host + view_key, 6),
1087+
stored_keys = br_get_session("xmrvks", true);
10871088
if (stored_keys) {
1088-
stored_keys.push(view_key);
1089+
stored_keys.push(hostkey_hash);
10891090
br_set_session("xmrvks", stored_keys, true);
10901091
return
10911092
}
1092-
br_set_session("xmrvks", [view_key], true);
1093+
br_set_session("xmrvks", [hostkey_hash], true);
10931094
}
10941095

10951096
// Verifies if view key has existing authenticated session with Monero node
1096-
function monero_lws_node_access(vk) {
1097-
if (vk) {
1097+
function monero_lws_node_access(host, view_key) {
1098+
if (host && view_key) {
10981099
const stored_keys = br_get_session("xmrvks", true);
10991100
if (stored_keys) {
1100-
if (stored_keys.includes(vk)) {
1101+
const hostkey_hash = sha_sub(host + view_key, 6);
1102+
if (stored_keys.includes(hostkey_hash)) {
11011103
return true
11021104
}
11031105
}

0 commit comments

Comments
 (0)