Skip to content

Commit 328a7a2

Browse files
committed
Add show_unconfirmed param for get transactions endpoints
1 parent fb377c8 commit 328a7a2

File tree

1 file changed

+16
-5
lines changed
  • counterparty-core/counterpartycore/lib/api

1 file changed

+16
-5
lines changed

counterparty-core/counterpartycore/lib/api/queries.py

+16-5
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ def get_last_block(ledger_db):
385385
)
386386

387387

388-
def prepare_transactions_where(type, other_conditions=None):
388+
def prepare_transactions_where(type, other_conditions=None, show_unconfirmed=False):
389389
where = []
390390
type_list = type.split(",")
391391
for transaction_type in type_list:
@@ -397,19 +397,24 @@ def prepare_transactions_where(type, other_conditions=None):
397397
if other_conditions:
398398
where_status.update(other_conditions)
399399
where.append(where_status)
400+
if not show_unconfirmed:
401+
for cond in where:
402+
cond["confirmed"] = True
400403
return where
401404

402405

403406
def get_transactions(
404407
ledger_db,
405408
type: TransactionType = "all",
409+
show_unconfirmed: bool = False,
406410
cursor: str = None,
407411
limit: int = 10,
408412
offset: int = None,
409413
):
410414
"""
411415
Returns the list of the last ten transactions
412416
:param str type: The type of the transaction to return
417+
:param bool show_unconfirmed: Show unconfirmed transactions
413418
:param str cursor: The index of the most recent transactions to return (e.g. $LAST_TX_INDEX)
414419
:param int limit: The number of transactions to return (e.g. 2)
415420
:param int offset: The number of lines to skip before returning results (overrides the `cursor` parameter)
@@ -421,14 +426,15 @@ def get_transactions(
421426
last_cursor=cursor,
422427
limit=limit,
423428
offset=offset,
424-
where=prepare_transactions_where(type),
429+
where=prepare_transactions_where(type, show_unconfirmed=show_unconfirmed),
425430
)
426431

427432

428433
def get_transactions_by_block(
429434
ledger_db,
430435
block_index: int,
431436
type: TransactionType = "all",
437+
show_unconfirmed: bool = False,
432438
cursor: str = None,
433439
limit: int = 10,
434440
offset: int = None,
@@ -437,6 +443,7 @@ def get_transactions_by_block(
437443
Returns the transactions of a block
438444
:param int block_index: The index of the block to return (e.g. $LAST_BLOCK_INDEX)
439445
:param str type: The type of the transaction to return
446+
:param bool show_unconfirmed: Show unconfirmed transactions
440447
:param str cursor: The last transaction index to return (e.g. $LAST_TX_INDEX)
441448
:param int limit: The maximum number of transactions to return (e.g. 5)
442449
:param int offset: The number of lines to skip before returning results (overrides the `cursor` parameter)
@@ -445,7 +452,7 @@ def get_transactions_by_block(
445452
return select_rows(
446453
ledger_db,
447454
"transactions",
448-
where=prepare_transactions_where(type, where),
455+
where=prepare_transactions_where(type, where, show_unconfirmed=show_unconfirmed),
449456
cursor_field="tx_index",
450457
last_cursor=cursor,
451458
limit=limit,
@@ -457,6 +464,7 @@ def get_transactions_by_address(
457464
ledger_db,
458465
address: str,
459466
type: TransactionType = "all",
467+
show_unconfirmed: bool = False,
460468
cursor: str = None,
461469
limit: int = 10,
462470
offset: int = None,
@@ -465,6 +473,7 @@ def get_transactions_by_address(
465473
Returns the transactions of an address
466474
:param str address: The address to return (e.g. $ADDRESS_1)
467475
:param str type: The type of the transaction to return
476+
:param bool show_unconfirmed: Show unconfirmed transactions
468477
:param str cursor: The last transaction index to return (e.g. $LAST_TX_INDEX)
469478
:param int limit: The maximum number of transactions to return (e.g. 5)
470479
:param int offset: The number of lines to skip before returning results (overrides the `cursor` parameter)
@@ -473,7 +482,7 @@ def get_transactions_by_address(
473482
return select_rows(
474483
ledger_db,
475484
"transactions",
476-
where=prepare_transactions_where(type, where),
485+
where=prepare_transactions_where(type, where, show_unconfirmed=show_unconfirmed),
477486
cursor_field="tx_index",
478487
last_cursor=cursor,
479488
limit=limit,
@@ -485,6 +494,7 @@ def get_transactions_by_addresses(
485494
ledger_db,
486495
addresses: str,
487496
type: TransactionType = "all",
497+
show_unconfirmed: bool = False,
488498
cursor: str = None,
489499
limit: int = 100,
490500
offset: int = None,
@@ -493,6 +503,7 @@ def get_transactions_by_addresses(
493503
Returns the transactions of a list of addresses
494504
:param str addresses: Comma separated list of addresses to return (e.g. $ADDRESS_1,$ADDRESS_2)
495505
:param str type: The type of the transaction to return
506+
:param bool show_unconfirmed: Show unconfirmed transactions
496507
:param str cursor: The last transaction index to return (e.g. $LAST_TX_INDEX)
497508
:param int limit: The maximum number of transactions to return (e.g. 5)
498509
:param int offset: The number of lines to skip before returning results (overrides the `cursor` parameter)
@@ -501,7 +512,7 @@ def get_transactions_by_addresses(
501512
return select_rows(
502513
ledger_db,
503514
"transactions",
504-
where=prepare_transactions_where(type, where),
515+
where=prepare_transactions_where(type, where, show_unconfirmed=show_unconfirmed),
505516
cursor_field="tx_index",
506517
last_cursor=cursor,
507518
limit=limit,

0 commit comments

Comments
 (0)