Skip to content

Commit a5f421e

Browse files
committed
proxy version v0.029
1 parent f37f4d8 commit a5f421e

File tree

7 files changed

+113
-47
lines changed

7 files changed

+113
-47
lines changed

assets_js_bitrequest_config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ const glob_multi_wallets = {
288288
{
289289
"name": "sochain api",
290290
"url": "wss://ws.chain.so/",
291-
"display": true
291+
"display": false
292292
}
293293
],
294294
"options": [],
@@ -443,7 +443,7 @@ const glob_multi_wallets = {
443443
{
444444
"name": "sochain api",
445445
"url": "wss://ws.chain.so/",
446-
"display": true
446+
"display": false
447447
}
448448
],
449449
"options": [],
@@ -562,7 +562,7 @@ const glob_multi_wallets = {
562562
{
563563
"name": "sochain api",
564564
"url": "wss://ws.chain.so/",
565-
"display": true
565+
"display": false
566566
}
567567
],
568568
"options": [],

assets_js_bitrequest_fetchblocks.js

Lines changed: 84 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,7 +1793,8 @@ function current_block_height(rd, api_data, rdo) {
17931793

17941794
// Routes Electrum server API requests between address polling and block height verification for Bitcoin transactions
17951795
function electrum_rpc_init(rd, api_data, rdo) {
1796-
if (rdo.source === "addr_polling") {
1796+
const source = rdo.source;
1797+
if (source === "addr_polling" || source === "after_scan") {
17971798
electrum_rpc(rd, api_data, rdo);
17981799
return
17991800
}
@@ -1847,12 +1848,15 @@ function electrum_rpc(rd, api_data, rdo, latest_block) {
18471848
script_hash = script_pub.hash,
18481849
script_pub_key = script_pub.script_pub_key,
18491850
rpc_url = api_data.url,
1850-
pending = rdo.pending;
1851+
pending = rdo.pending,
1852+
cachetime = rdo.cachetime,
1853+
addr_polling = (source === "addr_polling" || source === "after_scan"),
1854+
endpoint = addr_polling ? "get_mempool" : "get_history";
18511855
let matched_tx = false;
18521856
if (pending === "scanning") { // scan incoming transactions on address
18531857
api_proxy({
18541858
"api": currency,
1855-
"cachetime": rdo.cachetime,
1859+
cachetime,
18561860
"cachefolder": "1h",
18571861
"custom": "electrum",
18581862
"api_url": rpc_url,
@@ -1862,7 +1866,7 @@ function electrum_rpc(rd, api_data, rdo, latest_block) {
18621866
"cache": true,
18631867
"data": {
18641868
"id": "scanning",
1865-
"method": "blockchain.scripthash.get_history",
1869+
"method": "blockchain.scripthash." + endpoint,
18661870
"ref": script_hash,
18671871
"node": rpc_url
18681872
}
@@ -1876,19 +1880,81 @@ function electrum_rpc(rd, api_data, rdo, latest_block) {
18761880
}, rd, api_data, rdo);
18771881
return
18781882
}
1879-
if (has_tx(api_result)) {
1880-
$.each(api_result, function(key, tx) {
1881-
const parsed_tx = electrum_scan_data(tx, rdo.setconfirmations, rd.currencysymbol, script_pub_key, latest_block);
1882-
if (parsed_tx.transactiontime > rdo.request_timestamp && parsed_tx.ccval) {
1883-
matched_tx = parsed_tx;
1884-
if (source === "requests") {
1885-
const tx_item = create_transaction_item(parsed_tx, rd.requesttype);
1886-
if (tx_item) {
1887-
tx_list.append(tx_item.data(parsed_tx));
1883+
if (addr_polling) {
1884+
if (empty_obj(api_result)) {
1885+
glob_let.tx_count = 0; // set tx count
1886+
process_scan_results(rd, api_data, rdo, matched_tx);
1887+
return
1888+
}
1889+
const glob_tx_count = glob_let.tx_count,
1890+
tx_count = api_result.length;
1891+
if (tx_count > glob_let.tx_count) { // new tx detected
1892+
const latest_tx = api_result[0].tx_hash;
1893+
api_proxy({
1894+
"api": currency,
1895+
cachetime,
1896+
"cachefolder": "1h",
1897+
"custom": "electrum",
1898+
"api_url": rpc_url,
1899+
"proxy": true,
1900+
"params": {
1901+
"method": "POST",
1902+
"cache": true,
1903+
"data": {
1904+
"id": "scanning",
1905+
"method": "blockchain.transaction.get",
1906+
"ref": latest_tx,
1907+
"node": rpc_url
18881908
}
18891909
}
1890-
}
1891-
});
1910+
}).done(function(e) {
1911+
const tx_result = br_result(e),
1912+
res = q_obj(tx_result, "result");
1913+
if (res) {
1914+
const parsed_tx = electrum_scan_data(res, rdo.setconfirmations, rd.currencysymbol, script_pub_key, latest_block, latest_tx);
1915+
if (parsed_tx.ccval) {
1916+
matched_tx = parsed_tx;
1917+
}
1918+
process_scan_results(rd, api_data, rdo, matched_tx);
1919+
return
1920+
}
1921+
handle_scan_failure(null, rd, api_data, rdo);
1922+
}).fail(function(xhr, stat, err) {
1923+
const is_proxy_error = is_proxy_fail(this.url),
1924+
error_data = xhr || stat || err;
1925+
handle_scan_failure({
1926+
"error": error_data,
1927+
"is_proxy": is_proxy_error
1928+
}, rd, api_data, rdo, network);
1929+
}).always(function() {
1930+
update_api_source(rdo, api_data);
1931+
});
1932+
return
1933+
}
1934+
if (glob_tx_count === 1000000) { // tx count not set
1935+
// set initial tx count
1936+
glob_let.tx_count = tx_count;
1937+
}
1938+
return
1939+
}
1940+
if (api_result) {
1941+
const tx_arr = api_result.tx_hash ? [api_result] : api_result; // convert to array
1942+
if (has_tx(tx_arr)) {
1943+
$.each(tx_arr, function(key, tx) {
1944+
const parsed_tx = electrum_scan_data(tx, rdo.setconfirmations, rd.currencysymbol, script_pub_key, latest_block);
1945+
if (parsed_tx.transactiontime > rdo.request_timestamp && parsed_tx.ccval) {
1946+
matched_tx = parsed_tx;
1947+
if (source === "requests") {
1948+
const tx_item = create_transaction_item(parsed_tx, rd.requesttype);
1949+
if (tx_item) {
1950+
tx_list.append(tx_item.data(parsed_tx));
1951+
}
1952+
} else {
1953+
return false
1954+
}
1955+
}
1956+
});
1957+
}
18921958
}
18931959
process_scan_results(rd, api_data, rdo, matched_tx);
18941960
return
@@ -1910,7 +1976,7 @@ function electrum_rpc(rd, api_data, rdo, latest_block) {
19101976
const tx_hash = rd.txhash;
19111977
api_proxy({
19121978
"api": currency,
1913-
"cachetime": rdo.cachetime,
1979+
cachetime,
19141980
"cachefolder": "1h",
19151981
"custom": "electrum",
19161982
"api_url": rpc_url,
@@ -2533,7 +2599,7 @@ function mempoolspace_scan_data(data, setconfirmations, ccsymbol, address, lates
25332599
function electrum_scan_data(data, setconfirmations, ccsymbol, script_pub, latest_block, tx_hash) {
25342600
const outputs = data.outputs,
25352601
height = data.height || 0,
2536-
transactiontime = normalize_timestamp(data.timestamp, true),
2602+
transactiontime = height ? normalize_timestamp(data.timestamp, true) : now_utc() - 3000,
25372603
confirmations = latest_block ? get_block_confirmations(height, latest_block) : height;
25382604
let outputsum = 0;
25392605
if (outputs) {
@@ -2546,7 +2612,7 @@ function electrum_scan_data(data, setconfirmations, ccsymbol, script_pub, latest
25462612
return {
25472613
"ccval": (outputsum) ? outputsum / 100000000 : null,
25482614
transactiontime,
2549-
"txhash": data.tx_hash || tx_hash,
2615+
"txhash": tx_hash || data.tx_hash,
25502616
confirmations,
25512617
setconfirmations,
25522618
ccsymbol

assets_js_bitrequest_rpcs.js

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ $(document).ready(function() {
1212
//nodes_match
1313
//match_url
1414
//validate_rpc_connection
15-
//is_valid_tx_hex
1615
//save_rpc_settings
1716
delete_rpc_node();
1817
//get_node_icon
@@ -219,8 +218,8 @@ function fetch_electrum_nodes(currency, node_url, predefined_nodes, custom_nodes
219218
}
220219
}).done(function(e) {
221220
const api_result = br_result(e),
222-
result2 = q_obj(api_result, "result");
223-
if (is_valid_tx_hex(result2)) {
221+
result2 = q_obj(api_result, "result.tx_hash");
222+
if (result2) {
224223
const is_selected = rpc_url2 === node_url;
225224
create_rpc_node_element(api_options, true, node_id, node_config, is_selected);
226225
node_list_obj.push({
@@ -340,11 +339,7 @@ function validate_and_add_rpc_node(currency_name, api_list, node_id, node_config
340339
}
341340
}).done(function(e) {
342341
const api_result = br_result(e),
343-
result = q_obj(api_result, "result");
344-
let is_live = false
345-
if (result) {
346-
is_live = is_valid_tx_hex(result);
347-
}
342+
is_live = q_obj(api_result, "result.tx_hash");
348343
create_rpc_node_element(api_list, is_live, node_id, node_config, is_selected);
349344
}).fail(function(xhr, stat, err) {
350345
create_rpc_node_element(api_list, false, node_id, node_config, is_selected);
@@ -663,9 +658,10 @@ function validate_rpc_connection(input_section, node_config, currency_name) {
663658
"node": rpc_url
664659
}
665660
}
666-
}).done(function(response) {
667-
const api_result = br_result(response).result;
668-
if (is_valid_tx_hex(api_result)) {
661+
}).done(function(e) {
662+
const parsed_data = br_result(e),
663+
api_result = q_obj(parsed_data, "result.tx_hash");
664+
if (api_result) {
669665
const script_pub = address_to_scripthash(test_address, currency_name),
670666
script_hash = script_pub.hash,
671667
script_pub_key = script_pub.script_pub_key;
@@ -687,10 +683,10 @@ function validate_rpc_connection(input_section, node_config, currency_name) {
687683
}
688684
}
689685
}).done(function(response) {
690-
const parsed_data = br_result(response),
691-
api_result = parsed_data.result;
692-
if (api_result) {
693-
const first_tx = api_result[0];
686+
const parsed_data2 = br_result(response),
687+
api_result2 = q_obj(parsed_data2, "result");
688+
if (api_result2) {
689+
const first_tx = api_result2[0];
694690
if (first_tx) {
695691
if (first_tx.version) {
696692
input_section.addClass("live").removeClass("offline");
@@ -836,12 +832,6 @@ function validate_rpc_connection(input_section, node_config, currency_name) {
836832
}
837833
}
838834

839-
// Check if it's a string and matches hex format (0-9, a-f, A-F)
840-
function is_valid_tx_hex(hex_string) {
841-
const is_hex = typeof hex_string === "string" && /^[0-9a-fA-F]+$/.test(hex_string);
842-
return is_hex && hex_string.length > 250;
843-
}
844-
845835
function test_mempoolspace(input_section, node_config, currency_name) {
846836
const test_address = glob_const.test_address[currency_name],
847837
error_message = tl("unabletoconnect"),

assets_js_lib_global_queries.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ const br_bipobj = br_get_local("bpdat", true),
119119
"paymentpopup": $("#payment"),
120120
"phpsupport": false,
121121
"proxy_list": br_proxy_list,
122-
"proxy_version": "0.028",
122+
"proxy_version": "0.029",
123123
"redirect_uri": br_w_loc.origin + br_w_loc.pathname + "?p=settings",
124124
"ref_match": br_ref_match,
125125
"referrer": br_referrer,

assets_styles_styles.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,7 @@ html.dragmode .currentpage .applist li.dragging {
12541254

12551255
.requestlist li[data-status="new"] .metalist li.receivedamount,
12561256
.requestlist li[data-status="new"] .metalist li.payday {
1257-
display: block;
1257+
display: none;
12581258
}
12591259

12601260
.requestlist li.rqli.lightning .metalist li.receivedamount,

proxy/v1/api.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
// PROXY
3-
const VERSION = "0.028";
3+
const VERSION = "0.029";
44
const CACHE_DURATIONS = [
55
"2m" => 6220800, // 2 months in seconds
66
"1w" => 604800, // 1 week in seconds

proxy/v1/custom/rpcs/electrum/index.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,9 @@ function fetch_methods($response, $pl) {
282282
if (is_numeric($result)) {
283283
return ["value" => $result];
284284
}
285+
if ($method == "blockchain.transaction.get") {
286+
return decode_bitcoin_tx($result);
287+
}
285288
return $result;
286289
}
287290
return err_obj("4112", "no result");
@@ -331,7 +334,11 @@ function output_tx_hashes($node, $transactions) {
331334

332335
// Fetches additional transaction data and block details to enrich transaction information
333336
function complement_tx($node, $transaction) {
334-
$tx_hash = $transaction["tx_hash"];
337+
$tx = isset($transaction["tx_hash"]) ? $transaction : $transaction[0];
338+
if (!isset($tx)) {
339+
return ["error" => "No transaction data", "error_code" => 4119];
340+
}
341+
$tx_hash = $tx["tx_hash"];
335342

336343
// First TOR request
337344
$tx_hex = socket_fetch([
@@ -348,7 +355,7 @@ function complement_tx($node, $transaction) {
348355
// Process transaction data
349356
$fetch_tx = decode_bitcoin_tx($tx_hex);
350357
// Second TOR request
351-
$height = $transaction["height"];
358+
$height = $tx["height"];
352359
$fetch_block = socket_fetch([
353360
"id" => get_random_id(),
354361
"method" => "blockchain.block.header",
@@ -375,6 +382,9 @@ function get_random_id() {
375382

376383
// Decodes a Bitcoin transaction from hex format into structured data
377384
function decode_bitcoin_tx($hex_data) {
385+
if (is_array($hex_data)) {
386+
return $hex_data;
387+
}
378388
// Initialize position and convert hex to binary
379389
$position = 0;
380390
$data = hex2bin($hex_data);

0 commit comments

Comments
 (0)