fix: Update pending tx display and transaction paging
All checks were successful
Build Docker / Build Image (push) Successful in 50s
All checks were successful
Build Docker / Build Image (push) Successful in 50s
This commit is contained in:
parent
86c93da5a2
commit
26633c1c61
Binary file not shown.
48
account.py
48
account.py
@ -202,15 +202,19 @@ def getAddress(account: str):
|
|||||||
return info['receiveAddress']
|
return info['receiveAddress']
|
||||||
|
|
||||||
def getPendingTX(account: str):
|
def getPendingTX(account: str):
|
||||||
# Get the pending transactions
|
|
||||||
info = hsw.getWalletTxHistory(account)
|
|
||||||
if 'error' in info:
|
|
||||||
return 0
|
|
||||||
pending = 0
|
pending = 0
|
||||||
for tx in info:
|
page = 1
|
||||||
|
pageSize = 10
|
||||||
|
while True:
|
||||||
|
txs = getTransactions(account,page,pageSize)
|
||||||
|
page+=1
|
||||||
|
pendingPage = 0
|
||||||
|
for tx in txs:
|
||||||
if tx['confirmations'] < 1:
|
if tx['confirmations'] < 1:
|
||||||
pending += 1
|
pending+=1
|
||||||
|
pendingPage+=1
|
||||||
|
if pendingPage < pageSize:
|
||||||
|
break
|
||||||
return pending
|
return pending
|
||||||
|
|
||||||
def getDomains(account,own=True):
|
def getDomains(account,own=True):
|
||||||
@ -235,8 +239,8 @@ def getDomains(account,own=True):
|
|||||||
|
|
||||||
return domains
|
return domains
|
||||||
|
|
||||||
def getPageTXCache(account,page):
|
def getPageTXCache(account,page,size=100):
|
||||||
page = str(page)
|
page = f"{page}-{size}"
|
||||||
if not os.path.exists(f'cache'):
|
if not os.path.exists(f'cache'):
|
||||||
os.mkdir(f'cache')
|
os.mkdir(f'cache')
|
||||||
|
|
||||||
@ -250,8 +254,8 @@ def getPageTXCache(account,page):
|
|||||||
return pageCache[page]['txid']
|
return pageCache[page]['txid']
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def pushPageTXCache(account,page,txid):
|
def pushPageTXCache(account,page,txid,size=100):
|
||||||
page = str(page)
|
page = f"{page}-{size}"
|
||||||
if not os.path.exists(f'cache/{account}_page.json'):
|
if not os.path.exists(f'cache/{account}_page.json'):
|
||||||
with open(f'cache/{account}_page.json', 'w') as f:
|
with open(f'cache/{account}_page.json', 'w') as f:
|
||||||
f.write('{}')
|
f.write('{}')
|
||||||
@ -267,18 +271,18 @@ def pushPageTXCache(account,page,txid):
|
|||||||
|
|
||||||
return pageCache[page]['txid']
|
return pageCache[page]['txid']
|
||||||
|
|
||||||
def getTXFromPage(account,page):
|
def getTXFromPage(account,page,size=100):
|
||||||
if page == 1:
|
if page == 1:
|
||||||
return getTransactions(account)[-1]['hash']
|
return getTransactions(account,1,size)[-1]['hash']
|
||||||
|
|
||||||
cached = getPageTXCache(account,page)
|
cached = getPageTXCache(account,page,size)
|
||||||
if cached:
|
if cached:
|
||||||
return getPageTXCache(account,page)
|
return getPageTXCache(account,page,size)
|
||||||
previous = getTransactions(account,page)
|
previous = getTransactions(account,page,size)
|
||||||
if len(previous) == 0:
|
if len(previous) == 0:
|
||||||
return None
|
return None
|
||||||
hash = previous[-1]['hash']
|
hash = previous[-1]['hash']
|
||||||
pushPageTXCache(account,page,hash)
|
pushPageTXCache(account,page,hash,size)
|
||||||
return hash
|
return hash
|
||||||
|
|
||||||
|
|
||||||
@ -286,6 +290,8 @@ def getTXFromPage(account,page):
|
|||||||
def getTransactions(account,page=1,limit=100):
|
def getTransactions(account,page=1,limit=100):
|
||||||
# Get the transactions
|
# Get the transactions
|
||||||
if hsdVersion() < 7:
|
if hsdVersion() < 7:
|
||||||
|
if page != 1:
|
||||||
|
return []
|
||||||
info = hsw.getWalletTxHistory(account)
|
info = hsw.getWalletTxHistory(account)
|
||||||
if 'error' in info:
|
if 'error' in info:
|
||||||
return []
|
return []
|
||||||
@ -295,7 +301,7 @@ def getTransactions(account,page=1,limit=100):
|
|||||||
if page < 1:
|
if page < 1:
|
||||||
return []
|
return []
|
||||||
if page > 1:
|
if page > 1:
|
||||||
lastTX = getTXFromPage(account,page-1)
|
lastTX = getTXFromPage(account,page-1,limit)
|
||||||
|
|
||||||
if lastTX:
|
if lastTX:
|
||||||
response = requests.get(f'http://x:{APIKEY}@{ip}:12039/wallet/{account}/tx/history?reverse=true&limit={limit}&after={lastTX}')
|
response = requests.get(f'http://x:{APIKEY}@{ip}:12039/wallet/{account}/tx/history?reverse=true&limit={limit}&after={lastTX}')
|
||||||
@ -310,10 +316,10 @@ def getTransactions(account,page=1,limit=100):
|
|||||||
data = response.json()
|
data = response.json()
|
||||||
|
|
||||||
# Refresh the cache if the next page is different
|
# Refresh the cache if the next page is different
|
||||||
nextPage = getPageTXCache(account,page)
|
nextPage = getPageTXCache(account,page,limit)
|
||||||
if nextPage is not None and nextPage != data[-1]['hash']:
|
if nextPage is not None and nextPage != data[-1]['hash']:
|
||||||
print(f'Refreshing page {page}')
|
print(f'Refreshing page {page}')
|
||||||
pushPageTXCache(account,page,data[-1]['hash'])
|
pushPageTXCache(account,page,data[-1]['hash'],limit)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def getAllTransactions(account):
|
def getAllTransactions(account):
|
||||||
@ -321,7 +327,7 @@ def getAllTransactions(account):
|
|||||||
page = 0
|
page = 0
|
||||||
txs = []
|
txs = []
|
||||||
while True:
|
while True:
|
||||||
txs += getTransactions(account,page)
|
txs += getTransactions(account,page,1000)
|
||||||
if len(txs) == 0:
|
if len(txs) == 0:
|
||||||
break
|
break
|
||||||
page += 1
|
page += 1
|
||||||
|
Loading…
Reference in New Issue
Block a user