Skip to content

Commit a55f196

Browse files
committed
misc improvements
1 parent 76e2096 commit a55f196

5 files changed

+85
-75
lines changed

assets_js_bitrequest_coin_settings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ function save_confirmation_settings() {
135135
if (inj(conf_value)) return
136136
const settings_node = cs_node(currency, "confirmations");
137137
if (settings_node) {
138-
settings_node.data("selected", conf_value).find("p").html(conf_value);
138+
settings_node.data("selected", parseInt(conf_value, 10)).find("p").html(conf_value);
139139
canceldialog();
140140
notify(tl("datasaved"));
141141
save_cc_settings(currency, true);

assets_js_bitrequest_core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1982,7 +1982,7 @@ function keyup() {
19821982
flip_left2();
19831983
return
19841984
}
1985-
if (glob_const.paymentdialogbox.hasClass("norequest") && (glob_const.paymentdialogbox.attr("data-pending") == "ispending" || (glob_const.offline === true))) {
1985+
if (glob_const.paymentdialogbox.hasClass("norequest") && (glob_const.paymentdialogbox.attr("data-pending") === "ispending" || (glob_const.offline === true))) {
19861986
play_audio(glob_const.funk);
19871987
return
19881988
}

assets_js_bitrequest_fetchblocks.js

Lines changed: 76 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818

1919
// ** RPC Interactions: **
2020
//current_block_height
21+
//electrum_rpc_init
2122
//electrum_rpc_blockheight
23+
//electrum_rpc
2224
//mempoolspace_rpc_init
2325
//mempoolspace_rpc_blockheight
2426
//mempoolspace_blockheight_fails
25-
//electrum_rpc
2627
//mempoolspace_rpc
2728
//infura_txd_rpc
2829
//eth_params
@@ -1810,7 +1811,7 @@ function process_dash_transactions(rd, api_data, rdo) {
18101811
function current_block_height(rd, api_data, rdo) {
18111812
const api_name = api_data.name;
18121813
if (api_name === "electrum") {
1813-
electrum_rpc_blockheight(rd, api_data, rdo);
1814+
electrum_rpc_init(rd, api_data, rdo);
18141815
return
18151816
}
18161817
if (api_name === "blockchain.info") {
@@ -1820,6 +1821,15 @@ function current_block_height(rd, api_data, rdo) {
18201821
mempoolspace_rpc_init(rd, api_data, rdo, true);
18211822
}
18221823

1824+
// Routes Electrum server API requests between address polling and block height verification for Bitcoin transactions
1825+
function electrum_rpc_init(rd, api_data, rdo) {
1826+
if (rdo.source === "addr_polling") {
1827+
electrum_rpc(rd, api_data, rdo);
1828+
return
1829+
}
1830+
electrum_rpc_blockheight(rd, api_data, rdo);
1831+
}
1832+
18231833
// Fetches current Bitcoin block height from Electrum servers for confirmation calculations
18241834
function electrum_rpc_blockheight(rd, api_data, rdo) {
18251835
const rpc_url = api_data.url;
@@ -1857,60 +1867,6 @@ function electrum_rpc_blockheight(rd, api_data, rdo) {
18571867
});
18581868
}
18591869

1860-
// Routes mempool.space API requests between address polling and block height verification for Bitcoin transactions
1861-
function mempoolspace_rpc_init(rd, api_data, rdo, rpc) {
1862-
if (rdo.source === "addr_polling") {
1863-
mempoolspace_rpc(rd, api_data, rdo, rpc, false);
1864-
return
1865-
}
1866-
mempoolspace_rpc_blockheight(rd, api_data, rdo, rpc);
1867-
}
1868-
1869-
// Fetches current Bitcoin block height from mempool.space API for confirmation calculations
1870-
function mempoolspace_rpc_blockheight(rd, api_data, rdo, rpc) {
1871-
const currency = rd.payment,
1872-
btc_base = glob_const.mempool_space[currency];
1873-
if (!btc_base) {
1874-
mempoolspace_blockheight_fails(rd, api_data, rdo, rpc);
1875-
return
1876-
}
1877-
const api_url = api_data.url,
1878-
base_url = rpc ? api_url : btc_base,
1879-
api_name = api_data.name;
1880-
let block_height = null;
1881-
api_proxy({ // get latest blockheight
1882-
"api_url": base_url + "/api/blocks/tip/height",
1883-
"proxy": base_url.includes(".onion"),
1884-
"params": {
1885-
"method": "GET"
1886-
}
1887-
}).done(function(response) {
1888-
const api_result = br_result(response).result;
1889-
if (api_result) {
1890-
if (!api_result.error) {
1891-
block_height = api_result;
1892-
}
1893-
}
1894-
if (api_name === "electrum") {
1895-
electrum_rpc(rd, api_data, rdo, block_height);
1896-
return
1897-
}
1898-
mempoolspace_rpc(rd, api_data, rdo, rpc, block_height);
1899-
}).fail(function(xhr, stat, err) {
1900-
mempoolspace_blockheight_fails(rd, api_data, rdo, rpc);
1901-
}).always(function() {
1902-
update_api_source(rdo, api_data);
1903-
});
1904-
}
1905-
1906-
function mempoolspace_blockheight_fails(rd, api_data, rdo, rpc) {
1907-
if (api_data.name === "electrum") {
1908-
electrum_rpc(rd, api_data, rdo);
1909-
return
1910-
}
1911-
mempoolspace_rpc(rd, api_data, rdo, rpc);
1912-
}
1913-
19141870
// Processes Electrum transactions via RPC with support for account scanning and block verification
19151871
function electrum_rpc(rd, api_data, rdo, latest_block) {
19161872
const currency = rd.payment,
@@ -1921,8 +1877,7 @@ function electrum_rpc(rd, api_data, rdo, latest_block) {
19211877
script_hash = script_pub.hash,
19221878
script_pub_key = script_pub.script_pub_key,
19231879
rpc_url = api_data.url,
1924-
pending = rdo.pending,
1925-
set_confirmations = latest_block ? rdo.setconfirmations : 1;
1880+
pending = rdo.pending;
19261881
let tx_count = 0,
19271882
matched_tx = false;
19281883
if (pending === "scanning") { // scan incoming transactions on address
@@ -1954,7 +1909,7 @@ function electrum_rpc(rd, api_data, rdo, latest_block) {
19541909
}
19551910
if (has_tx(api_result)) {
19561911
$.each(api_result, function(key, tx) {
1957-
const parsed_tx = electrum_scan_data(tx, set_confirmations, rd.currencysymbol, script_pub_key, latest_block);
1912+
const parsed_tx = electrum_scan_data(tx, rdo.setconfirmations, rd.currencysymbol, script_pub_key, latest_block);
19581913
if (parsed_tx.transactiontime > rdo.request_timestamp && parsed_tx.ccval) {
19591914
matched_tx = parsed_tx;
19601915
if (source === "requests") {
@@ -1977,7 +1932,7 @@ function electrum_rpc(rd, api_data, rdo, latest_block) {
19771932
handle_scan_failure({
19781933
"error": error_data,
19791934
"is_proxy": is_proxy_error
1980-
}, rd, api_data, rdo, network);
1935+
}, rd, api_data, rdo);
19811936
}).always(function() {
19821937
update_api_source(rdo, api_data);
19831938
});
@@ -2012,7 +1967,7 @@ function electrum_rpc(rd, api_data, rdo, latest_block) {
20121967
}, rd, api_data, rdo);
20131968
return
20141969
}
2015-
const parsed_tx = electrum_scan_data(api_result, set_confirmations, rd.currencysymbol, script_pub_key, latest_block, tx_hash);
1970+
const parsed_tx = electrum_scan_data(api_result, rdo.setconfirmations, rd.currencysymbol, script_pub_key, latest_block, tx_hash);
20161971
if (parsed_tx.ccval) {
20171972
matched_tx = parsed_tx;
20181973
tx_count = 1;
@@ -2040,6 +1995,60 @@ function electrum_rpc(rd, api_data, rdo, latest_block) {
20401995
}
20411996
}
20421997

1998+
// Routes mempool.space API requests between address polling and block height verification for Bitcoin transactions
1999+
function mempoolspace_rpc_init(rd, api_data, rdo, rpc) {
2000+
if (rdo.source === "addr_polling") {
2001+
mempoolspace_rpc(rd, api_data, rdo, rpc, false);
2002+
return
2003+
}
2004+
mempoolspace_rpc_blockheight(rd, api_data, rdo, rpc);
2005+
}
2006+
2007+
// Fetches current Bitcoin block height from mempool.space API for confirmation calculations
2008+
function mempoolspace_rpc_blockheight(rd, api_data, rdo, rpc) {
2009+
const currency = rd.payment,
2010+
btc_base = glob_const.mempool_space[currency];
2011+
if (!btc_base) {
2012+
mempoolspace_blockheight_fails(rd, api_data, rdo, rpc);
2013+
return
2014+
}
2015+
const api_url = api_data.url,
2016+
base_url = rpc ? api_url : btc_base,
2017+
api_name = api_data.name;
2018+
let block_height = null;
2019+
api_proxy({ // get latest blockheight
2020+
"api_url": base_url + "/api/blocks/tip/height",
2021+
"proxy": base_url.includes(".onion"),
2022+
"params": {
2023+
"method": "GET"
2024+
}
2025+
}).done(function(response) {
2026+
const api_result = br_result(response).result;
2027+
if (api_result) {
2028+
if (!api_result.error) {
2029+
block_height = api_result;
2030+
}
2031+
}
2032+
if (api_name === "electrum") {
2033+
electrum_rpc(rd, api_data, rdo, block_height);
2034+
return
2035+
}
2036+
mempoolspace_rpc(rd, api_data, rdo, rpc, block_height);
2037+
}).fail(function(xhr, stat, err) {
2038+
mempoolspace_blockheight_fails(rd, api_data, rdo, rpc);
2039+
}).always(function() {
2040+
update_api_source(rdo, api_data);
2041+
});
2042+
}
2043+
2044+
function mempoolspace_blockheight_fails(rd, api_data, rdo, rpc) {
2045+
if (api_data.name === "electrum") {
2046+
electrum_rpc(rd, api_data, rdo);
2047+
return
2048+
}
2049+
mempoolspace_rpc(rd, api_data, rdo, rpc);
2050+
}
2051+
20432052
// Processes Bitcoin transactions through mempool.space API with transaction filtering and block height validation
20442053
function mempoolspace_rpc(rd, api_data, rdo, rpc, latest_block) {
20452054
const tx_list = rdo.transactionlist,
@@ -2070,11 +2079,10 @@ function mempoolspace_rpc(rd, api_data, rdo, rpc, latest_block) {
20702079
return
20712080
}
20722081
if (has_tx(api_result)) {
2073-
const sorted_txs = sort_transactions_by_date(mempoolspace_scan_data, api_result),
2074-
set_confirmations = latest_block ? rdo.setconfirmations : 1;
2082+
const sorted_txs = sort_transactions_by_date(mempoolspace_scan_data, api_result);
20752083
$.each(sorted_txs, function(date, tx) {
20762084
if (tx.txid) { // filter outgoing transactions
2077-
const parsed_tx = mempoolspace_scan_data(tx, set_confirmations, rd.currencysymbol, rd.address, latest_block);
2085+
const parsed_tx = mempoolspace_scan_data(tx, rdo.setconfirmations, rd.currencysymbol, rd.address, latest_block);
20782086
if (parsed_tx.transactiontime > rdo.request_timestamp && parsed_tx.ccval) {
20792087
matched_tx = parsed_tx;
20802088
if (source === "requests") {
@@ -2459,7 +2467,8 @@ function calculate_total_outputs(outputs, address, value_processor) {
24592467
function normalize_timestamp(raw_timestamp, convert_utc) {
24602468
if (!raw_timestamp) return convert_utc ? now_utc() : now();
24612469
const timestamp_ms = raw_timestamp * 1000;
2462-
return convert_utc ? timestamp_ms + glob_const.timezone : timestamp_ms;
2470+
tx_time_margin = timestamp_ms - 3000; // 3 second margin for unknown timestamps in mempool default to now()
2471+
return convert_utc ? tx_time_margin + glob_const.timezone : tx_time_margin;
24632472
}
24642473

24652474
// Computes blockchain confirmation count with validation against latest block height
@@ -2532,7 +2541,7 @@ function mempoolspace_ws_data(data, setconfirmations, ccsymbol, address) {
25322541
// Processes mempool.space transaction data with block height confirmation calculation
25332542
function mempoolspace_scan_data(data, setconfirmations, ccsymbol, address, latest_block) {
25342543
const status = data.status,
2535-
tx_timestamp = status.block_time ? status.block_time * 1000 : now(),
2544+
tx_timestamp = normalize_timestamp(status.block_time),
25362545
transactiontime = tx_timestamp ? tx_timestamp + glob_const.timezone : null;
25372546
if (setconfirmations === "sort") {
25382547
return transactiontime;
@@ -2544,7 +2553,7 @@ function mempoolspace_scan_data(data, setconfirmations, ccsymbol, address, lates
25442553
const total_output = calculate_total_outputs(data.vout, address, process_value),
25452554
height = status.block_height,
25462555
min_confs = status.confirmed ? 1 : 0,
2547-
confirmations = latest_block ? get_block_confirmations(status.block_height, latest_block) : min_confs || height;
2556+
confirmations = (height && latest_block) ? get_block_confirmations(status.block_height, latest_block) : min_confs || height || 0;
25482557
return {
25492558
"ccval": total_output ? total_output / 1e8 : null,
25502559
transactiontime,

assets_js_bitrequest_polling.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function start_address_monitor(time_out, api_dat, retry) {
109109
poll_interval = time_out || 7000,
110110
init_time = request.rq_init,
111111
req_time_utc = init_time + glob_const.timezone,
112-
req_time = req_time_utc - 15000, // 15 second margin
112+
req_time = req_time_utc,
113113
conf_required = request.set_confirmations || 0,
114114
cache_time = (poll_interval - 1000) / 1000,
115115
rdo = { // request data object

assets_js_lib_global_queries.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -808,17 +808,18 @@ function get_next_proxy() {
808808
current_index = proxies.indexOf(current),
809809
safe_index = current_index === -1 ? 0 : current_index,
810810
next_proxy = proxies[safe_index + 1],
811-
next_active = next_proxy || proxies[0];
812-
if (glob_let.proxy_attempts[next_active] !== true) {
811+
next_active = next_proxy || proxies[0],
812+
next_url = next_active.proxy;
813+
if (glob_let.proxy_attempts[next_url] !== true) {
813814
glob_let.rpc_attempts = {};
814815
set_setting("api_proxy", { // save next proxy
815-
"selected": next_active
816-
}, next_active);
816+
"selected": next_url
817+
}, next_url);
817818
save_settings();
818819
reset_overflow("rpc");
819820
reset_overflow("l2");
820821
glob_let.apikey_fails = false;
821-
return next_active;
822+
return next_url;
822823
}
823824
return false;
824825
}

0 commit comments

Comments
 (0)