feast: Add transaction history api route
All checks were successful
Build Docker / BuildImage (push) Successful in 31s
All checks were successful
Build Docker / BuildImage (push) Successful in 31s
This commit is contained in:
parent
5354abca42
commit
7b2a25592e
41
hsd.py
41
hsd.py
@ -1,4 +1,5 @@
|
||||
from functools import cache
|
||||
import functools
|
||||
import time
|
||||
import requests
|
||||
import dotenv
|
||||
import os
|
||||
@ -41,6 +42,27 @@ if not os.path.exists(wallet_file):
|
||||
with open(wallet_file, 'w') as f:
|
||||
json.dump([], f, indent=4)
|
||||
|
||||
def cache_with_ttl(max_age, maxsize=128, typed=False):
|
||||
"""Least-recently-used cache decorator with time-based cache invalidation.
|
||||
|
||||
Args:
|
||||
max_age: Time to live for cached results (in seconds).
|
||||
maxsize: Maximum cache size (see `functools.lru_cache`).
|
||||
typed: Cache on distinct input types (see `functools.lru_cache`).
|
||||
"""
|
||||
def _decorator(fn):
|
||||
@functools.lru_cache(maxsize=maxsize, typed=typed)
|
||||
def _new(*args, __time_salt, **kwargs):
|
||||
return fn(*args, **kwargs)
|
||||
|
||||
@functools.wraps(fn)
|
||||
def _wrapped(*args, **kwargs):
|
||||
return _new(*args, **kwargs, __time_salt=int(time.time() / max_age))
|
||||
|
||||
return _wrapped
|
||||
|
||||
return _decorator
|
||||
|
||||
|
||||
def url(walletURL:bool) -> str:
|
||||
if walletURL:
|
||||
@ -159,7 +181,7 @@ def import_wallet(name:str,userID:str,xpub:str) -> dict:
|
||||
}
|
||||
|
||||
|
||||
@cache
|
||||
@cache_with_ttl(60*60)
|
||||
def get_wallet_UUID(userID:str, name:str) -> str|None:
|
||||
accounts = get_accounts()
|
||||
|
||||
@ -217,7 +239,7 @@ def get_balance(userID:str, name:str) -> dict:
|
||||
return return_json
|
||||
|
||||
|
||||
@cache
|
||||
@cache_with_ttl(60*1)
|
||||
def get_domains(userID:str, name:str) -> dict:
|
||||
walletID = get_wallet_UUID(userID, name)
|
||||
if not walletID:
|
||||
@ -327,11 +349,22 @@ def send_to_address(userID:str, name:str, address:str, amount:str) -> dict:
|
||||
|
||||
return response.json()
|
||||
|
||||
@cache_with_ttl(60*1)
|
||||
def get_transactions(userID:str, name:str) -> dict:
|
||||
walletID = get_wallet_UUID(userID, name)
|
||||
if not walletID:
|
||||
return {
|
||||
'error': 'Wallet not found'
|
||||
}
|
||||
|
||||
request = requests.get(url(True)+'wallet/'+walletID+'/tx/history').json()
|
||||
return request
|
||||
|
||||
|
||||
|
||||
# region Auctions
|
||||
|
||||
@cache
|
||||
@cache_with_ttl(60*1)
|
||||
def get_auctions(userID:str, name:str) -> dict:
|
||||
walletID = get_wallet_UUID(userID, name)
|
||||
if not walletID:
|
||||
|
7
main.py
7
main.py
@ -75,6 +75,13 @@ def get_domains():
|
||||
domain_json = hsd.get_domains(userID, name)
|
||||
return jsonify(domain_json)
|
||||
|
||||
@app.route('/wallet/transactions', methods=['GET'])
|
||||
def get_transactions():
|
||||
userID = request.args.get('uuid')
|
||||
name = request.args.get('name')
|
||||
transaction_json = hsd.get_transactions(userID, name)
|
||||
return jsonify(transaction_json)
|
||||
|
||||
@app.route('/wallet/send', methods=['POST'])
|
||||
def send():
|
||||
userID = request.args.get('uuid')
|
||||
|
Loading…
Reference in New Issue
Block a user