From 90ec38953c7fb1ba5fc51f73d8b08d6d13e3ea6c Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 5 Nov 2024 12:08:28 -0800 Subject: [PATCH] Sort offers in CLI by `RELEVANCE` --- chia/_tests/cmds/wallet/test_wallet.py | 5 +++-- chia/cmds/wallet.py | 3 +++ chia/cmds/wallet_funcs.py | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/chia/_tests/cmds/wallet/test_wallet.py b/chia/_tests/cmds/wallet/test_wallet.py index ebd1a51d6bd8..6ce060a8ac03 100644 --- a/chia/_tests/cmds/wallet/test_wallet.py +++ b/chia/_tests/cmds/wallet/test_wallet.py @@ -923,6 +923,7 @@ async def get_all_offers( "--exclude-taken-offers", "--include-completed", "--reverse", + "--sort-by-relevance", ] # these are various things that should be in the output assert_list = [ @@ -940,7 +941,7 @@ async def get_all_offers( "Record with id: 0101010101010101010101010101010101010101010101010101010101010101", ] run_cli_command_and_assert(capsys, root_dir, command_args, assert_list) - expected_calls: logType = {"get_all_offers": [(0, 10, None, True, False, True, True, True)]} + expected_calls: logType = {"get_all_offers": [(0, 10, "RELEVANCE", True, False, True, True, True)]} command_args = [ "wallet", "get_offers", @@ -960,7 +961,7 @@ async def get_all_offers( ] run_cli_command_and_assert(capsys, root_dir, command_args, assert_list) assert expected_calls["get_all_offers"] is not None - expected_calls["get_all_offers"].append((0, 10, None, False, True, False, False, False)) + expected_calls["get_all_offers"].append((0, 10, "CONFIRMED_AT_HEIGHT", False, True, False, False, False)) test_rpc_clients.wallet_rpc_client.check_log(expected_calls) diff --git a/chia/cmds/wallet.py b/chia/cmds/wallet.py index 497a3592f569..e41bc2f0bd38 100644 --- a/chia/cmds/wallet.py +++ b/chia/cmds/wallet.py @@ -541,6 +541,7 @@ def make_offer_cmd( "-ic", "--include-completed", help="Include offers that have been confirmed/cancelled or failed", is_flag=True ) @click.option("-s", "--summaries", help="Show the assets being offered and requested for each offer", is_flag=True) +@click.option("--sort-by-relevance/--sort-by-confirmed-height", help="Sort the offers one of two ways", is_flag=True) @click.option("-r", "--reverse", help="Reverse the order of the output", is_flag=True) def get_offers_cmd( wallet_rpc_port: Optional[int], @@ -552,6 +553,7 @@ def get_offers_cmd( include_completed: bool, summaries: bool, reverse: bool, + sort_by_relevance: bool, ) -> None: from .wallet_funcs import get_offers @@ -566,6 +568,7 @@ def get_offers_cmd( include_completed=include_completed, summaries=summaries, reverse=reverse, + sort_by_relevance=sort_by_relevance, ) ) diff --git a/chia/cmds/wallet_funcs.py b/chia/cmds/wallet_funcs.py index 6e788b25c486..02766eab8da7 100644 --- a/chia/cmds/wallet_funcs.py +++ b/chia/cmds/wallet_funcs.py @@ -659,6 +659,7 @@ async def get_offers( include_completed: bool = False, summaries: bool = False, reverse: bool = False, + sort_by_relevance: bool = True, ) -> None: async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, _, _): file_contents: bool = (filepath is not None) or summaries @@ -673,6 +674,7 @@ async def get_offers( new_records: list[TradeRecord] = await wallet_client.get_all_offers( start, end, + sort_key="RELEVANCE" if sort_by_relevance else "CONFIRMED_AT_HEIGHT", reverse=reverse, file_contents=file_contents, exclude_my_offers=exclude_my_offers,