Skip to content

Commit 2463c96

Browse files
committed
Port send_notifications to @marshal
1 parent d1d1386 commit 2463c96

File tree

5 files changed

+76
-51
lines changed

5 files changed

+76
-51
lines changed

chia/_tests/wallet/rpc/test_wallet_rpc.py

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
PushTX,
145145
RoyaltyAsset,
146146
SelectCoins,
147+
SendNotification,
147148
SendTransaction,
148149
SetWalletResyncOnStartup,
149150
SpendClawbackCoins,
@@ -2621,21 +2622,25 @@ async def test_notification_rpcs(wallet_rpc_environment: WalletRpcTestEnvironmen
26212622
env.wallet_2.node.config["enable_notifications"] = True
26222623
env.wallet_2.node.config["required_notification_amount"] = 100000000000
26232624
async with wallet_2.wallet_state_manager.new_action_scope(DEFAULT_TX_CONFIG, push=True) as action_scope:
2624-
tx = await client.send_notification(
2625-
await action_scope.get_puzzle_hash(wallet_2.wallet_state_manager),
2626-
b"hello",
2627-
uint64(100000000000),
2628-
fee=uint64(100000000000),
2625+
response = await client.send_notification(
2626+
SendNotification(
2627+
target=(await action_scope.get_puzzle_hash(wallet_2.wallet_state_manager)),
2628+
message=b"hello",
2629+
amount=uint64(100000000000),
2630+
fee=uint64(100000000000),
2631+
push=True,
2632+
),
2633+
tx_config=DEFAULT_TX_CONFIG,
26292634
)
26302635

2631-
assert tx.spend_bundle is not None
2636+
assert response.tx.spend_bundle is not None
26322637
await time_out_assert(
26332638
5,
26342639
full_node_api.full_node.mempool_manager.get_spendbundle,
2635-
tx.spend_bundle,
2636-
tx.spend_bundle.name(),
2640+
response.tx.spend_bundle,
2641+
response.tx.spend_bundle.name(),
26372642
)
2638-
await farm_transaction(full_node_api, wallet_node, tx.spend_bundle)
2643+
await farm_transaction(full_node_api, wallet_node, response.tx.spend_bundle)
26392644
await time_out_assert(20, env.wallet_2.wallet.get_confirmed_balance, uint64(100000000000))
26402645

26412646
notification = (await client_2.get_notifications(GetNotifications())).notifications[0]
@@ -2648,21 +2653,25 @@ async def test_notification_rpcs(wallet_rpc_environment: WalletRpcTestEnvironmen
26482653
assert [] == (await client_2.get_notifications(GetNotifications([notification.id]))).notifications
26492654

26502655
async with wallet_2.wallet_state_manager.new_action_scope(DEFAULT_TX_CONFIG, push=True) as action_scope:
2651-
tx = await client.send_notification(
2652-
await action_scope.get_puzzle_hash(wallet_2.wallet_state_manager),
2653-
b"hello",
2654-
uint64(100000000000),
2655-
fee=uint64(100000000000),
2656+
response = await client.send_notification(
2657+
SendNotification(
2658+
target=(await action_scope.get_puzzle_hash(wallet_2.wallet_state_manager)),
2659+
message=b"hello",
2660+
amount=uint64(100000000000),
2661+
fee=uint64(100000000000),
2662+
push=True,
2663+
),
2664+
tx_config=DEFAULT_TX_CONFIG,
26562665
)
26572666

2658-
assert tx.spend_bundle is not None
2667+
assert response.tx.spend_bundle is not None
26592668
await time_out_assert(
26602669
5,
26612670
full_node_api.full_node.mempool_manager.get_spendbundle,
2662-
tx.spend_bundle,
2663-
tx.spend_bundle.name(),
2671+
response.tx.spend_bundle,
2672+
response.tx.spend_bundle.name(),
26642673
)
2665-
await farm_transaction(full_node_api, wallet_node, tx.spend_bundle)
2674+
await farm_transaction(full_node_api, wallet_node, response.tx.spend_bundle)
26662675
await time_out_assert(20, env.wallet_2.wallet.get_confirmed_balance, uint64(200000000000))
26672676

26682677
notification = (await client_2.get_notifications(GetNotifications())).notifications[0]

chia/cmds/wallet_funcs.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
NFTSetNFTDID,
7575
NFTTransferNFT,
7676
RoyaltyAsset,
77+
SendNotification,
7778
SendTransaction,
7879
SendTransactionResponse,
7980
SignMessageByAddress,
@@ -1576,19 +1577,25 @@ async def send_notification(
15761577
async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, _):
15771578
amount: uint64 = cli_amount.convert_amount(units["chia"])
15781579

1579-
tx = await wallet_client.send_notification(
1580-
address.puzzle_hash,
1581-
message,
1582-
amount,
1583-
fee,
1584-
push=push,
1580+
response = await wallet_client.send_notification(
1581+
SendNotification(
1582+
address.puzzle_hash,
1583+
message,
1584+
amount,
1585+
fee=fee,
1586+
push=push,
1587+
),
1588+
tx_config=DEFAULT_TX_CONFIG,
15851589
timelock_info=condition_valid_times,
15861590
)
15871591

15881592
if push:
15891593
print("Notification sent successfully.")
1590-
print(f"To get status, use command: chia wallet get_transaction -f {fingerprint} -tx 0x{tx.name}")
1591-
return [tx]
1594+
print(
1595+
"To get status, use command: chia wallet get_transaction"
1596+
f" -f {fingerprint} -tx 0x{response.transactions[0].name}"
1597+
)
1598+
return response.transactions
15921599

15931600

15941601
async def get_notifications(

chia/wallet/wallet_request_types.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,20 @@ class SpendClawbackCoinsResponse(TransactionEndpointResponse):
12341234
transaction_ids: list[bytes32]
12351235

12361236

1237+
@streamable
1238+
@dataclass(frozen=True)
1239+
class SendNotification(TransactionEndpointRequest):
1240+
target: bytes32 = field(default_factory=default_raise)
1241+
message: bytes = field(default_factory=default_raise)
1242+
amount: uint64 = uint64(0)
1243+
1244+
1245+
@streamable
1246+
@dataclass(frozen=True)
1247+
class SendNotificationResponse(TransactionEndpointResponse):
1248+
tx: TransactionRecord
1249+
1250+
12371251
@streamable
12381252
@dataclass(frozen=True)
12391253
class PushTransactions(TransactionEndpointRequest):

chia/wallet/wallet_rpc_api.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@
248248
PWStatusResponse,
249249
SelectCoins,
250250
SelectCoinsResponse,
251+
SendNotification,
252+
SendNotificationResponse,
251253
SendTransaction,
252254
SendTransactionResponse,
253255
SetWalletResyncOnStartup,
@@ -1934,22 +1936,24 @@ async def delete_notifications(self, request: DeleteNotifications) -> Empty:
19341936
return Empty()
19351937

19361938
@tx_endpoint(push=True)
1939+
@marshal
19371940
async def send_notification(
19381941
self,
1939-
request: dict[str, Any],
1942+
request: SendNotification,
19401943
action_scope: WalletActionScope,
19411944
extra_conditions: tuple[Condition, ...] = tuple(),
1942-
) -> EndpointResult:
1945+
) -> SendNotificationResponse:
19431946
await self.service.wallet_state_manager.notification_manager.send_new_notification(
1944-
bytes32.from_hexstr(request["target"]),
1945-
bytes.fromhex(request["message"]),
1946-
uint64(request["amount"]),
1947+
request.target,
1948+
request.message,
1949+
request.amount,
19471950
action_scope,
1948-
request.get("fee", uint64(0)),
1951+
request.fee,
19491952
extra_conditions=extra_conditions,
19501953
)
19511954

1952-
return {"tx": None, "transactions": None} # tx_endpoint wrapper will take care of this
1955+
# tx_endpoint will take care of these default values
1956+
return SendNotificationResponse([], [], tx=REPLACEABLE_TRANSACTION_RECORD)
19531957

19541958
@marshal
19551959
async def verify_signature(self, request: VerifySignature) -> VerifySignatureResponse:

chia/wallet/wallet_rpc_client.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@
162162
PWStatusResponse,
163163
SelectCoins,
164164
SelectCoinsResponse,
165+
SendNotification,
166+
SendNotificationResponse,
165167
SendTransaction,
166168
SendTransactionMultiResponse,
167169
SendTransactionResponse,
@@ -1088,27 +1090,16 @@ async def delete_notifications(self, request: DeleteNotifications) -> None:
10881090

10891091
async def send_notification(
10901092
self,
1091-
target: bytes32,
1092-
msg: bytes,
1093-
amount: uint64,
1094-
fee: uint64 = uint64(0),
1093+
request: SendNotification,
1094+
tx_config: TXConfig,
10951095
extra_conditions: tuple[Condition, ...] = tuple(),
10961096
timelock_info: ConditionValidTimes = ConditionValidTimes(),
1097-
push: bool = True,
1098-
) -> TransactionRecord:
1099-
response = await self.fetch(
1100-
"send_notification",
1101-
{
1102-
"target": target.hex(),
1103-
"message": msg.hex(),
1104-
"amount": amount,
1105-
"fee": fee,
1106-
"extra_conditions": conditions_to_json_dicts(extra_conditions),
1107-
"push": push,
1108-
**timelock_info.to_json_dict(),
1109-
},
1097+
) -> SendNotificationResponse:
1098+
return SendNotificationResponse.from_json_dict(
1099+
await self.fetch(
1100+
"send_notification", request.json_serialize_for_transport(tx_config, extra_conditions, timelock_info)
1101+
)
11101102
)
1111-
return TransactionRecord.from_json_dict(response["tx"])
11121103

11131104
async def sign_message_by_address(self, request: SignMessageByAddress) -> SignMessageByAddressResponse:
11141105
return SignMessageByAddressResponse.from_json_dict(

0 commit comments

Comments
 (0)