update transaction_get_height

This commit is contained in:
Jack Robison 2022-02-16 13:30:45 -05:00
parent 7a9e8c6769
commit 07ee73b653
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2

View file

@ -8,7 +8,7 @@ import asyncio
import logging import logging
import itertools import itertools
import collections import collections
from bisect import bisect_right
from asyncio import Event, sleep from asyncio import Event, sleep
from collections import defaultdict from collections import defaultdict
from functools import partial from functools import partial
@ -1034,13 +1034,14 @@ class LBRYElectrumX(SessionBase):
async def transaction_get_height(self, tx_hash): async def transaction_get_height(self, tx_hash):
self.assert_tx_hash(tx_hash) self.assert_tx_hash(tx_hash)
transaction_info = await self.daemon.getrawtransaction(tx_hash, True)
if transaction_info and 'hex' in transaction_info and 'confirmations' in transaction_info: def get_height():
# an unconfirmed transaction from lbrycrdd will not have a 'confirmations' field v = self.db.prefix_db.tx_num.get(tx_hash)
return (self.db.db_height - transaction_info['confirmations']) + 1 if v:
elif transaction_info and 'hex' in transaction_info: return bisect_right(self.db.tx_counts, v.tx_num)
return -1 return self.mempool.get_mempool_height(tx_hash)
return None
return await asyncio.get_event_loop().run_in_executor(self.db._executor, get_height)
async def claimtrie_getclaimbyid(self, claim_id): async def claimtrie_getclaimbyid(self, claim_id):
rows = [] rows = []