transaction list
This commit is contained in:
parent
1e4613fd8a
commit
e6a9417988
4 changed files with 22 additions and 34 deletions
|
@ -243,24 +243,15 @@ def get_raw_transactions(tx_hashes):
|
|||
)
|
||||
|
||||
|
||||
def get_transactions(**constraints) -> Tuple[List[Transaction], Optional[int]]:
|
||||
txs = []
|
||||
sql = select(TX.c.raw, TX.c.height, TX.c.position).select_from(TX)
|
||||
rows = context().fetchall(query([TX], sql, **constraints))
|
||||
for row in rows:
|
||||
txs.append(Transaction(row['raw'], height=row['height'], position=row['position']))
|
||||
return txs, 0
|
||||
|
||||
|
||||
def _get_transactions(
|
||||
wallet=None, include_total=False, **constraints
|
||||
) -> Tuple[List[Transaction], Optional[int]]:
|
||||
def get_transactions(include_total=False, **constraints) -> Tuple[List[Transaction], Optional[int]]:
|
||||
account_ids = constraints.pop('account_ids', None)
|
||||
include_is_my_input = constraints.pop('include_is_my_input', False)
|
||||
include_is_my_output = constraints.pop('include_is_my_output', False)
|
||||
|
||||
tx_rows = select_transactions(
|
||||
[TX.c.tx_hash, TX.c.raw, TX.c.height, TX.c.position, TX.c.is_verified],
|
||||
[TX.c.tx_hash, TX.c.raw, TX.c.height, TX.c.position, TX.c.timestamp, TX.c.is_verified],
|
||||
order_by=constraints.pop('order_by', ["height=0 DESC", "height DESC", "position DESC"]),
|
||||
account_ids=account_ids,
|
||||
**constraints
|
||||
)
|
||||
|
||||
|
@ -269,7 +260,7 @@ def _get_transactions(
|
|||
txids.append(row['tx_hash'])
|
||||
txs.append(Transaction(
|
||||
raw=row['raw'], height=row['height'], position=row['position'],
|
||||
is_verified=bool(row['is_verified'])
|
||||
timestamp=row['timestamp'], is_verified=bool(row['is_verified'])
|
||||
))
|
||||
for txi in txs[-1].inputs:
|
||||
txi_txoids.append(txi.txo_ref.hash)
|
||||
|
@ -279,7 +270,7 @@ def _get_transactions(
|
|||
annotated_txos.update({
|
||||
txo.id: txo for txo in
|
||||
get_txos(
|
||||
wallet=wallet,
|
||||
wallet_account_ids=account_ids,
|
||||
tx_hash__in=txids[offset:offset + MAX_QUERY_VARIABLES], order_by='txo.tx_hash',
|
||||
include_is_my_input=include_is_my_input,
|
||||
include_is_my_output=include_is_my_output,
|
||||
|
@ -291,7 +282,7 @@ def _get_transactions(
|
|||
referenced_txos.update({
|
||||
txo.id: txo for txo in
|
||||
get_txos(
|
||||
wallet=wallet,
|
||||
wallet_account_ids=account_ids,
|
||||
txo_hash__in=txi_txoids[offset:offset + MAX_QUERY_VARIABLES], order_by='txo.txo_hash',
|
||||
include_is_my_output=include_is_my_output,
|
||||
)[0]
|
||||
|
|
|
@ -2644,13 +2644,11 @@ class API:
|
|||
|
||||
"""
|
||||
wallet = self.wallets.get_or_default(wallet_id)
|
||||
if account_id:
|
||||
account = wallet.get_account_or_error(account_id)
|
||||
transactions = account.get_transaction_history
|
||||
else:
|
||||
transactions = partial(
|
||||
self.ledger.get_transaction_history, wallet=wallet, accounts=wallet.accounts)
|
||||
return await paginate_rows(transactions, page, page_size)
|
||||
return await Paginated.from_getter(
|
||||
wallet.list_transactions,
|
||||
accounts=wallet.accounts.get_or_all(account_id),
|
||||
**pagination_kwargs
|
||||
)
|
||||
|
||||
async def transaction_search(
|
||||
self,
|
||||
|
|
|
@ -262,7 +262,7 @@ class Wallet:
|
|||
async def list_transactions(self, **constraints):
|
||||
return txs_to_dict(await self.db.get_transactions(
|
||||
include_is_my_output=True, **constraints
|
||||
), self.ledger)
|
||||
), self.ledger, await self.db.get_best_block_height())
|
||||
|
||||
async def create_transaction(
|
||||
self, inputs: Iterable[Input], outputs: Iterable[Output],
|
||||
|
@ -870,15 +870,14 @@ class PurchaseListManager(BaseListManager):
|
|||
raise NotImplementedError
|
||||
|
||||
|
||||
def txs_to_dict(txs, ledger):
|
||||
def txs_to_dict(txs, ledger, tip_height):
|
||||
history = []
|
||||
for tx in txs: # pylint: disable=too-many-nested-blocks
|
||||
ts = ledger.headers.estimated_timestamp(tx.height)
|
||||
item = {
|
||||
'txid': tx.id,
|
||||
'timestamp': ts,
|
||||
'date': datetime.fromtimestamp(ts).isoformat(' ')[:-3] if tx.height > 0 else None,
|
||||
'confirmations': (ledger.headers.height + 1) - tx.height if tx.height > 0 else 0,
|
||||
'timestamp': tx.timestamp,
|
||||
'date': datetime.fromtimestamp(tx.timestamp).isoformat(' ')[:-3] if tx.height > 0 else None,
|
||||
'confirmations': (tip_height + 1) - tx.height if tx.height > 0 else 0,
|
||||
'claim_info': [],
|
||||
'update_info': [],
|
||||
'support_info': [],
|
||||
|
@ -976,4 +975,5 @@ def txs_to_dict(txs, ledger):
|
|||
'is_spent': txo.is_spent,
|
||||
})
|
||||
history.append(item)
|
||||
return history
|
||||
txs.rows = history
|
||||
return txs
|
||||
|
|
|
@ -122,8 +122,7 @@ class AccountManagement(CommandTestCase):
|
|||
self.assertEqual([support2['txid']], [txo['txid'] for txo in await self.support_list(account_id=account2)])
|
||||
|
||||
history = await self.transaction_list()
|
||||
self.assertItemCount(history, 8)
|
||||
history = history['items']
|
||||
self.assertEqual(len(history), 8)
|
||||
self.assertEqual(extract(history[0]['support_info'][0], ['claim_name', 'is_tip', 'amount', 'balance_delta']), {
|
||||
'claim_name': 'stream-in-account2',
|
||||
'is_tip': False,
|
||||
|
@ -160,7 +159,7 @@ class AccountManagement(CommandTestCase):
|
|||
self.assertEqual(history[7]['value'], '10.0')
|
||||
|
||||
async def test_address_validation(self):
|
||||
address = await self.daemon.jsonrpc_address_unused()
|
||||
address = await self.address_unused()
|
||||
bad_address = address[0:20] + '9999999' + address[27:]
|
||||
with self.assertRaisesRegex(Exception, f"'{bad_address}' is not a valid address"):
|
||||
await self.daemon.jsonrpc_account_send('0.1', addresses=[bad_address])
|
||||
await self.wallet_send('0.1', bad_address)
|
||||
|
|
Loading…
Add table
Reference in a new issue