Skip to content

Commit f4530eb

Browse files
authored
Merge pull request #5 from vsys-host/4-no-payment-notification-if-rpc-node-returns-error-while-retrieving-transaction-details
Fix payment notification if RPC node returns error
2 parents bbfd4a8 + fef3803 commit f4530eb

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

app/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ def create_app():
3636
from .api import metrics_blueprint
3737
app.register_blueprint(metrics_blueprint)
3838

39-
from .tasks import walletnotify_shkeeper
4039

4140
db.init_app(app)
4241
with app.app_context():

app/coin.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from decimal import Decimal
22
from flask import current_app as app
3+
import requests as rq
34
import time
45
import json
56
import copy
@@ -122,6 +123,24 @@ def get_rent_amount(self) -> Decimal:
122123
min_balance = to_sol(min_balance)
123124
return min_balance
124125

126+
def walletnotify_shkeeper(self, symbol, txid) -> bool:
127+
"""Notify SHKeeper about transaction"""
128+
logger.warning(f"Notifying about {symbol}/{txid}")
129+
while True:
130+
try:
131+
r = rq.post(
132+
f'http://{config["SHKEEPER_HOST"]}/api/v1/walletnotify/{symbol}/{txid}',
133+
headers={'X-Shkeeper-Backend-Key': config['SHKEEPER_KEY']}).json()
134+
if r["status"] == "success":
135+
logger.warning(f"The notification about {symbol}/{txid} was successful")
136+
return True
137+
else:
138+
logger.warning(f"Failed to notify SHKeeper about {symbol}/{txid}, received response: {r}")
139+
time.sleep(5)
140+
except Exception as e:
141+
logger.warning(f'Shkeeper notification failed for {symbol}/{txid}: {e}')
142+
time.sleep(10)
143+
125144
def parse_transaction(self, txid) -> list:
126145
"Return list of related transactions details for SHKeeper"
127146
if self.symbol == "SOL":

app/events.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
def log_loop(last_checked_block, check_interval):
12-
from .tasks import walletnotify_shkeeper, drain_account
12+
from .tasks import drain_account
1313
from app import create_app
1414
app = create_app()
1515
app.app_context().push()
@@ -66,7 +66,7 @@ def check_in_parallel(block):
6666
drain_account.delay(token_dict[balance["mint"]], balance['owner'])
6767
symbols_set = set(symbols)
6868
for symbol in symbols_set:
69-
walletnotify_shkeeper.delay(symbol, transaction_json['transaction']['signatures'][0])
69+
coin.walletnotify_shkeeper(symbol, transaction_json['transaction']['signatures'][0])
7070
return 1
7171
with ThreadPoolExecutor(max_workers=config['EVENTS_MAX_THREADS_NUMBER']) as executor:
7272
try:

app/tasks.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,6 @@ def post_payout_results(data, symbol):
4646
time.sleep(10)
4747

4848

49-
@celery.task()
50-
def walletnotify_shkeeper(symbol, txid):
51-
logger.warning(f"Notifying about {symbol}/{txid}")
52-
while True:
53-
try:
54-
r = rq.post(
55-
f'http://{config["SHKEEPER_HOST"]}/api/v1/walletnotify/{symbol}/{txid}',
56-
headers={'X-Shkeeper-Backend-Key': config['SHKEEPER_KEY']}
57-
)
58-
return r
59-
except Exception as e:
60-
logger.warning(f'Shkeeper notification failed for {symbol}/{txid}: {e}')
61-
time.sleep(10)
62-
63-
6449
@celery.task()
6550
def refresh_balances():
6651
updated = 0

0 commit comments

Comments
 (0)