Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CHIA-690] Add offer expiration to CLI #18193

Merged
merged 2 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion chia/_tests/cmds/wallet/test_wallet.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import datetime
import os
from pathlib import Path
from typing import Any, Dict, List, Optional, Tuple, Union, cast
Expand Down Expand Up @@ -855,7 +856,12 @@ async def get_all_offers(
],
trade_id=bytes32([1 + i] * 32),
status=uint32(TradeStatus.PENDING_ACCEPT.value),
valid_times=ConditionValidTimes(),
valid_times=ConditionValidTimes(
min_time=uint64(0),
max_time=uint64(100),
min_height=uint32(0),
max_height=uint32(100),
),
)
records.append(trade_offer)
return records
Expand Down Expand Up @@ -888,6 +894,26 @@ async def get_all_offers(
]
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)]}
command_args = [
"wallet",
"get_offers",
FINGERPRINT_ARG,
"--summaries",
]
tzinfo = datetime.datetime.now(datetime.timezone.utc).astimezone().tzinfo
# these are various things that should be in the output
assert_list = [
"Timelock information:",
" - Not valid until ",
" - Expires at ",
f"{datetime.datetime.fromtimestamp(0, tz=tzinfo).strftime('%Y-%m-%d %H:%M %Z')}",
f"{datetime.datetime.fromtimestamp(100, tz=tzinfo).strftime('%Y-%m-%d %H:%M %Z')}",
"height 0",
"height 100",
]
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))
test_rpc_clients.wallet_rpc_client.check_log(expected_calls)


Expand Down
16 changes: 15 additions & 1 deletion chia/cmds/wallet_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pathlib
import sys
import time
from datetime import datetime
from datetime import datetime, timezone
from decimal import Decimal
from typing import Any, Awaitable, Callable, Dict, List, Optional, Sequence, Tuple, Union

Expand Down Expand Up @@ -607,6 +607,11 @@ async def print_offer_summary(
print(output)


def format_timestamp_with_timezone(timestamp: int) -> str:
tzinfo = datetime.now(timezone.utc).astimezone().tzinfo
return datetime.fromtimestamp(timestamp, tz=tzinfo).strftime("%Y-%m-%d %H:%M %Z")


async def print_trade_record(record: TradeRecord, wallet_client: WalletRpcClient, summaries: bool = False) -> None:
print()
print(f"Record with id: {record.trade_id}")
Expand All @@ -629,6 +634,15 @@ async def print_trade_record(record: TradeRecord, wallet_client: WalletRpcClient
print("Pending Outbound Balances:")
await print_offer_summary(cat_name_resolver, outbound_balances, has_fee=(fees > 0))
print(f"Included Fees: {fees / units['chia']} XCH, {fees} mojos")
print("Timelock information:")
if record.valid_times.min_time is not None:
print(" - Not valid until " f"{format_timestamp_with_timezone(record.valid_times.min_time)}")
if record.valid_times.min_height is not None:
print(f" - Not valid until height {record.valid_times.min_height}")
if record.valid_times.max_time is not None:
print(" - Expires at " f"{format_timestamp_with_timezone(record.valid_times.max_time)} " "(+/- 10 min)")
if record.valid_times.max_height is not None:
print(f" - Expires at height {record.valid_times.max_height} (wait ~10 blocks after to be reorg safe)")
print("---------------")


Expand Down
Loading