Skip to content

Commit a3082fc

Browse files
committed
Port delete_notifications
1 parent 62400d6 commit a3082fc

File tree

7 files changed

+31
-24
lines changed

7 files changed

+31
-24
lines changed

chia/_tests/cmds/wallet/test_notifications.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from pathlib import Path
4-
from typing import Optional, cast
4+
from typing import cast
55

66
from chia_rs.sized_bytes import bytes32
77
from chia_rs.sized_ints import uint32, uint64
@@ -12,7 +12,7 @@
1212
from chia.wallet.conditions import ConditionValidTimes
1313
from chia.wallet.notification_store import Notification
1414
from chia.wallet.transaction_record import TransactionRecord
15-
from chia.wallet.wallet_request_types import GetNotifications, GetNotificationsResponse
15+
from chia.wallet.wallet_request_types import DeleteNotifications, GetNotifications, GetNotificationsResponse
1616

1717
test_condition_valid_times: ConditionValidTimes = ConditionValidTimes(min_time=uint64(100), max_time=uint64(150))
1818

@@ -111,9 +111,8 @@ def test_notifications_delete(capsys: object, get_test_cli_clients: tuple[TestRp
111111

112112
# set RPC Client
113113
class NotificationsDeleteRpcClient(TestWalletRpcClient):
114-
async def delete_notifications(self, ids: Optional[list[bytes32]] = None) -> bool:
115-
self.add_to_log("delete_notifications", (ids,))
116-
return True
114+
async def delete_notifications(self, request: DeleteNotifications) -> None:
115+
self.add_to_log("delete_notifications", (request.ids,))
117116

118117
inst_rpc_client = NotificationsDeleteRpcClient()
119118
test_rpc_clients.wallet_rpc_client = inst_rpc_client

chia/_tests/wallet/rpc/test_wallet_rpc.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
CombineCoins,
109109
DefaultCAT,
110110
DeleteKey,
111+
DeleteNotifications,
111112
DeleteUnconfirmedTransactions,
112113
DIDCreateBackupFile,
113114
DIDGetDID,
@@ -2559,7 +2560,7 @@ async def test_notification_rpcs(wallet_rpc_environment: WalletRpcTestEnvironmen
25592560
assert [notification] == (await client_2.get_notifications(GetNotifications(None, None, uint32(1)))).notifications
25602561
assert [] == (await client_2.get_notifications(GetNotifications(None, uint32(1), None))).notifications
25612562
assert [notification] == (await client_2.get_notifications(GetNotifications(None, None, None))).notifications
2562-
assert await client_2.delete_notifications()
2563+
await client_2.delete_notifications(DeleteNotifications())
25632564
assert [] == (await client_2.get_notifications(GetNotifications([notification.id]))).notifications
25642565

25652566
async with wallet_2.wallet_state_manager.new_action_scope(DEFAULT_TX_CONFIG, push=True) as action_scope:
@@ -2581,7 +2582,7 @@ async def test_notification_rpcs(wallet_rpc_environment: WalletRpcTestEnvironmen
25812582
await time_out_assert(20, env.wallet_2.wallet.get_confirmed_balance, uint64(200000000000))
25822583

25832584
notification = (await client_2.get_notifications(GetNotifications())).notifications[0]
2584-
assert await client_2.delete_notifications([notification.id])
2585+
await client_2.delete_notifications(DeleteNotifications([notification.id]))
25852586
assert [] == (await client_2.get_notifications(GetNotifications([notification.id]))).notifications
25862587

25872588

chia/_tests/wallet/test_notifications.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from chia.util.db_wrapper import DBWrapper2
1818
from chia.wallet.notification_store import NotificationStore
1919
from chia.wallet.util.tx_config import DEFAULT_TX_CONFIG
20+
from chia.wallet.wallet_request_types import DeleteNotifications
2021

2122

2223
# For testing backwards compatibility with a DB change to add height
@@ -190,7 +191,9 @@ async def track_coin_state(*args: Any) -> bool:
190191
await notification_manager_2.notification_store.delete_all_notifications()
191192
assert len(await notification_manager_2.notification_store.get_all_notifications()) == 0
192193
await notification_manager_2.notification_store.add_notification(notifications[0])
193-
await notification_manager_2.notification_store.delete_notifications([n.id for n in notifications])
194+
await notification_manager_2.notification_store.delete_notifications(
195+
DeleteNotifications([n.id for n in notifications])
196+
)
194197
assert len(await notification_manager_2.notification_store.get_all_notifications()) == 0
195198

196199
assert not await func(*notification_manager_2.most_recent_args)

chia/cmds/wallet_funcs.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
from chia.wallet.wallet_coin_store import GetCoinRecords
4646
from chia.wallet.wallet_request_types import (
4747
CATSpendResponse,
48+
DeleteNotifications,
4849
DeleteUnconfirmedTransactions,
4950
DIDFindLostDID,
5051
DIDGetDID,
@@ -1602,9 +1603,11 @@ async def delete_notifications(
16021603
) -> None:
16031604
async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, _, _):
16041605
if delete_all:
1605-
print(f"Success: {await wallet_client.delete_notifications()}")
1606+
await wallet_client.delete_notifications(DeleteNotifications())
1607+
print("Success!")
16061608
else:
1607-
print(f"Success: {await wallet_client.delete_notifications(ids=list(ids))}")
1609+
await wallet_client.delete_notifications(DeleteNotifications(ids=list(ids)))
1610+
print("Success!")
16081611

16091612

16101613
async def sign_message(

chia/wallet/wallet_request_types.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,12 @@ class GetNotificationsResponse(Streamable):
353353
notifications: list[Notification]
354354

355355

356+
@streamable
357+
@dataclass(frozen=True)
358+
class DeleteNotifications(Streamable):
359+
ids: Optional[list[bytes32]] = None
360+
361+
356362
@streamable
357363
@dataclass(frozen=True)
358364
class VerifySignature(Streamable):

chia/wallet/wallet_rpc_api.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
CreateNewDL,
120120
CreateNewDLResponse,
121121
DeleteKey,
122+
DeleteNotifications,
122123
DeleteUnconfirmedTransactions,
123124
DIDCreateBackupFile,
124125
DIDCreateBackupFileResponse,
@@ -1935,16 +1936,16 @@ async def get_notifications(self, request: GetNotifications) -> GetNotifications
19351936

19361937
return GetNotificationsResponse(notifications)
19371938

1938-
async def delete_notifications(self, request: dict[str, Any]) -> EndpointResult:
1939-
ids: Optional[list[str]] = request.get("ids", None)
1940-
if ids is None:
1939+
@marshal
1940+
async def delete_notifications(self, request: DeleteNotifications) -> Empty:
1941+
if request.ids is None:
19411942
await self.service.wallet_state_manager.notification_manager.notification_store.delete_all_notifications()
19421943
else:
19431944
await self.service.wallet_state_manager.notification_manager.notification_store.delete_notifications(
1944-
[bytes32.from_hexstr(id) for id in ids]
1945+
request.ids
19451946
)
19461947

1947-
return {}
1948+
return Empty()
19481949

19491950
@tx_endpoint(push=True)
19501951
async def send_notification(

chia/wallet/wallet_rpc_client.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
from collections.abc import Sequence
43
from typing import Any, Optional, Union, cast
54

65
from chia_rs.sized_bytes import bytes32
@@ -36,6 +35,7 @@
3635
CreateOfferForIDsResponse,
3736
CreateSignedTransactionsResponse,
3837
DeleteKey,
38+
DeleteNotifications,
3939
DeleteUnconfirmedTransactions,
4040
DIDCreateBackupFile,
4141
DIDCreateBackupFileResponse,
@@ -1117,14 +1117,8 @@ async def get_notifications(self, request: GetNotifications) -> GetNotifications
11171117
response = await self.fetch("get_notifications", request.to_json_dict())
11181118
return json_deserialize_with_clvm_streamable(response, GetNotificationsResponse)
11191119

1120-
async def delete_notifications(self, ids: Optional[Sequence[bytes32]] = None) -> bool:
1121-
request = {}
1122-
if ids is not None:
1123-
request["ids"] = [id.hex() for id in ids]
1124-
response = await self.fetch("delete_notifications", request)
1125-
# TODO: casting due to lack of type checked deserialization
1126-
result = cast(bool, response["success"])
1127-
return result
1120+
async def delete_notifications(self, request: DeleteNotifications) -> None:
1121+
await self.fetch("delete_notifications", request.to_json_dict())
11281122

11291123
async def send_notification(
11301124
self,

0 commit comments

Comments
 (0)