Skip to content

Commit ddc3c30

Browse files
authored
Merge pull request #105 from vsys-host/104-add-option-to-disable-invoice-creation-for-lagging-or-unsynced-crypto-nodes
Add option to disable invoice creation for lagging or unsynced crypto
2 parents bc1f0b3 + 82597ae commit ddc3c30

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

shkeeper/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def create_app(test_config=None):
6868
DEV_MODE_ENC_PW=os.environ.get("DEV_MODE_ENC_PW"),
6969
NOTIFICATION_TASK_DELAY=int(os.environ.get("NOTIFICATION_TASK_DELAY", 60)),
7070
TEMPLATES_AUTO_RELOAD=True,
71+
DISABLE_CRYPTO_WHEN_LAGS=bool(os.environ.get("DISABLE_CRYPTO_WHEN_LAGS", False)),
7172
)
7273

7374
if test_config is None:

shkeeper/api_v1.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ def list_crypto():
4646
crypto_list = []
4747
for crypto in Crypto.instances.values():
4848
if crypto.wallet.enabled and (crypto.getstatus() != "Offline"):
49-
filtered_list.append(crypto.crypto)
50-
crypto_list.append(
51-
{"name": crypto.crypto, "display_name": crypto.display_name}
52-
)
49+
if (not app.config.get("DISABLE_CRYPTO_WHEN_LAGS") or
50+
(app.config.get("DISABLE_CRYPTO_WHEN_LAGS") and crypto.getstatus() == "Synced")):
51+
filtered_list.append(crypto.crypto)
52+
crypto_list.append(
53+
{"name": crypto.crypto, "display_name": crypto.display_name}
54+
)
5355
return {
5456
"status": "success",
5557
"crypto": filtered_list,
@@ -81,6 +83,11 @@ def payment_request(crypto_name):
8183
"status": "error",
8284
"message": f"{crypto_name} payment gateway is unavailable",
8385
}
86+
if app.config.get("DISABLE_CRYPTO_WHEN_LAGS") and crypto.getstatus() != "Synced":
87+
return {
88+
"status": "error",
89+
"message": f"{crypto_name} payment gateway is unavailable because of lagging",
90+
}
8491

8592
req = request.get_json(force=True)
8693
invoice = Invoice.add(crypto=crypto, request=req)
@@ -116,6 +123,11 @@ def get_crypto_quote(crypto_name):
116123
"status": "error",
117124
"message": f"{crypto_name} payment gateway is unavailable",
118125
}
126+
if app.config.get("DISABLE_CRYPTO_WHEN_LAGS") and crypto.getstatus() != "Synced":
127+
return {
128+
"status": "error",
129+
"message": f"{crypto_name} payment gateway is unavailable because of lagging",
130+
}
119131

120132
req = request.get_json(force=True)
121133
fiat = req.get("fiat")

0 commit comments

Comments
 (0)