File tree Expand file tree Collapse file tree 4 files changed +21
-18
lines changed
Expand file tree Collapse file tree 4 files changed +21
-18
lines changed Original file line number Diff line number Diff 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 ():
Original file line number Diff line number Diff line change 11from decimal import Decimal
22from flask import current_app as app
3+ import requests as rq
34import time
45import json
56import 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" :
Original file line number Diff line number Diff line change 99
1010
1111def 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 :
Original file line number Diff line number Diff 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 ()
6550def refresh_balances ():
6651 updated = 0
You can’t perform that action at this time.
0 commit comments