mirror of
https://github.com/cryptoadvance/specter-desktop.git
synced 2026-08-13 12:33:29 +02:00
Bugfix: Better error-management for run the numbers (#1790)
* Bugfix: Longer Timeout for run_the_numbers * make run_the_numbers more robust * again error management * fixed (now even tested)
This commit is contained in:
parent
cbf1029595
commit
a61793d241
4 changed files with 46 additions and 8 deletions
|
|
@ -397,7 +397,11 @@ class BitcoinRPC:
|
|||
self.trace_call_after(url, payload, ts)
|
||||
self.r = r
|
||||
if r.status_code != 200:
|
||||
logger.debug(f"last call FAILED: {r.text} (raising RpcError)")
|
||||
logger.debug(f"last call FAILED: {r.text}")
|
||||
if r.text.startswith("Work queue depth exceeded"):
|
||||
raise SpecterError(
|
||||
"Your Bitcoind is running hot (Work queue depth exceeded)! Bitcoind gets more requests than it can process. Please refrain from doing anything for some minutes."
|
||||
)
|
||||
raise RpcError(
|
||||
"Server responded with error code %d: %s" % (r.status_code, r.text), r
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import csv
|
||||
import json
|
||||
import logging
|
||||
import threading
|
||||
import time
|
||||
from binascii import b2a_base64
|
||||
from datetime import datetime
|
||||
|
|
@ -36,6 +37,8 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
wallets_endpoint_api = Blueprint("wallets_endpoint_api", __name__)
|
||||
|
||||
get_txout_set_info_lock = threading.Lock()
|
||||
|
||||
|
||||
@wallets_endpoint_api.route("/wallets_loading/", methods=["GET", "POST"])
|
||||
@login_required
|
||||
|
|
@ -67,8 +70,17 @@ def generatemnemonic():
|
|||
@login_required
|
||||
@app.csrf.exempt
|
||||
def txout_set_info():
|
||||
res = app.specter.rpc.gettxoutsetinfo(timeout=3600)
|
||||
return res
|
||||
if get_txout_set_info_lock.locked():
|
||||
return {
|
||||
"error": "Run the numbers is quite work intensive and there is already a call running. Stay calm and let it do its work!"
|
||||
}, 429
|
||||
with get_txout_set_info_lock:
|
||||
try:
|
||||
res = app.specter.rpc.gettxoutsetinfo(timeout=3600)
|
||||
return res, 200
|
||||
except Exception as e:
|
||||
logger.exception(e)
|
||||
return {"error": str(e)}, 429
|
||||
|
||||
|
||||
@wallets_endpoint_api.route("/get_scantxoutset_status")
|
||||
|
|
|
|||
|
|
@ -50,17 +50,28 @@
|
|||
{
|
||||
method: 'GET'
|
||||
}
|
||||
);
|
||||
).catch((err) => {
|
||||
showError(err)
|
||||
return
|
||||
});
|
||||
let result = await response.json();
|
||||
console.log(result)
|
||||
if (result.error) {
|
||||
showError(result.error)
|
||||
return
|
||||
}
|
||||
if (totalUserBalance==0) {
|
||||
document.getElementById('total_supply').innerHTML = `Your wallet holds 0 BTC and so, you're effectively a precoiner! Get off zero! `
|
||||
return
|
||||
}
|
||||
let userBalanceFromTotal = parseFloat((100 / (result.total_amount / totalUserBalance)).toFixed(8));
|
||||
document.getElementById('total_supply').innerHTML = `{{ _("Bitcoin Total Supply") }}: ${result.total_amount} BTC<br>` +
|
||||
( userBalanceFromTotal > 1e-8 ?
|
||||
`<span class="note" style="margin: 7px auto;">{{ _("Your wallets hold") }} ${totalUserBalance} BTC (~${userBalanceFromTotal}% {{ _("from the total supply") }}</span>` :
|
||||
''
|
||||
)
|
||||
`<span class="note" style="margin: 7px auto;">{{ _("Your wallets hold") }} ` +
|
||||
`${totalUserBalance} BTC (~${userBalanceFromTotal.toFixed(8)}% ` +
|
||||
`{{ _("from the total supply") }}</span>`
|
||||
} catch(e) {
|
||||
console.log('Caught error:', e);
|
||||
showError(e)
|
||||
return { success: false, error: e };
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ from datetime import datetime
|
|||
import json
|
||||
import logging
|
||||
from unittest.mock import MagicMock, patch
|
||||
import mock
|
||||
|
||||
import pytest
|
||||
from werkzeug.wrappers import Response
|
||||
|
|
@ -134,6 +135,16 @@ def test_addresses_list_to_csv(
|
|||
assert float(addr[4].strip()) > 0
|
||||
|
||||
|
||||
def test_txout_set_info(caplog, app, client):
|
||||
caplog.set_level(logging.DEBUG)
|
||||
caplog.set_level(logging.DEBUG, logger="cryptoadvance.specter")
|
||||
login(client, "secret")
|
||||
res = client.get("/wallets/get_txout_set_info")
|
||||
assert res.status == "200 OK"
|
||||
print(json.loads(res.data))
|
||||
assert json.loads(res.data)["total_amount"] > 0
|
||||
|
||||
|
||||
# Ugly: Code duplication. Cannot import from other test_modules
|
||||
def login(client, password):
|
||||
"""login helper-function"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue