Skip to main content

dig_node_control_interface/
traits.rs

1//! The two contract traits: the client-facing call builder/parser and the node-facing handler.
2//!
3//! * [`ControlCall`] binds a typed params struct to its [`ControlMethod`] and its typed result — so
4//!   a caller writes `client.request(&SetCapParams { cap_bytes })` and gets back a `SetCapResult`,
5//!   never a stringly-typed `Value`.
6//! * [`ControlClient`] is what a CLIENT depends on: build a JSON-RPC request from a typed call, and
7//!   parse a response back into the typed result (or a [`ControlError`]). Pure — no transport; the
8//!   consumer carries the bytes over dig-ipc / loopback-mTLS itself.
9//! * [`ControlHandler`] is what a NODE implements to SERVE the surface: one typed method per control
10//!   method, plus a provided [`dispatch`](ControlHandler::dispatch) that routes a raw request to the
11//!   right method — the single anti-drift seam the conformance KATs exercise.
12
13use async_trait::async_trait;
14use serde::de::DeserializeOwned;
15use serde::Serialize;
16use serde_json::Value;
17
18use crate::envelope::{JsonRpcRequest, JsonRpcResponse, RequestId};
19use crate::error::{ControlError, ControlErrorCode};
20use crate::method::ControlMethod;
21use crate::params;
22use crate::results;
23
24/// A typed control call: a params struct that knows its [`ControlMethod`] and its result type.
25///
26/// Implemented by every struct in [`crate::params`]; this is what makes
27/// [`ControlClient::parse_response`] return the right typed result for each method at compile time.
28pub trait ControlCall: Serialize {
29    /// The wire method this call invokes.
30    const METHOD: ControlMethod;
31    /// The typed result this call returns on success.
32    type Output: DeserializeOwned;
33}
34
35/// Serialize a typed call's params into a JSON object (`{}` for a no-param call, never `null`).
36fn params_value<C: ControlCall>(call: &C) -> Value {
37    match serde_json::to_value(call) {
38        Ok(Value::Null) => Value::Object(Default::default()),
39        Ok(v) => v,
40        Err(_) => Value::Object(Default::default()),
41    }
42}
43
44/// Build the JSON-RPC request envelope for a typed control call. Pure.
45pub fn build_request<C: ControlCall>(id: RequestId, call: &C) -> JsonRpcRequest {
46    JsonRpcRequest::new(id, C::METHOD.name(), params_value(call))
47}
48
49/// Parse a JSON-RPC response into a typed result, or the [`ControlError`] it carried. Pure.
50pub fn parse_response<C: ControlCall>(
51    response: JsonRpcResponse,
52) -> Result<C::Output, ControlError> {
53    let value = response.into_result()?;
54    serde_json::from_value(value).map_err(|e| {
55        ControlError::of(
56            ControlErrorCode::ControlError,
57            format!("failed to parse {} result: {e}", C::METHOD.name()),
58        )
59    })
60}
61
62/// The client-facing half of the contract: turn typed calls into requests and responses back into
63/// typed results.
64///
65/// The default implementations cover every client; a consumer implements this trait only to
66/// customise request construction (e.g. attaching the control token in a bespoke way). The blanket
67/// [`DefaultControlClient`] gives callers the standard behaviour for free.
68pub trait ControlClient {
69    /// Build the request envelope for a typed call with the given request `id`.
70    fn build_request<C: ControlCall>(&self, id: RequestId, call: &C) -> JsonRpcRequest {
71        build_request(id, call)
72    }
73
74    /// Parse a response envelope into the typed result for call type `C`.
75    fn parse_response<C: ControlCall>(
76        &self,
77        response: JsonRpcResponse,
78    ) -> Result<C::Output, ControlError> {
79        parse_response::<C>(response)
80    }
81}
82
83/// The standard, zero-configuration [`ControlClient`] using the default request/response behaviour.
84#[derive(Debug, Clone, Copy, Default)]
85pub struct DefaultControlClient;
86
87impl ControlClient for DefaultControlClient {}
88
89/// The node-facing half of the contract: a running node implements this to SERVE the control
90/// surface. Each method is typed to the catalog's params/results; the provided
91/// [`dispatch`](ControlHandler::dispatch) routes a raw [`JsonRpcRequest`] to the right method so a
92/// server needs only one entry point and can never mis-route.
93///
94/// Open/proxied shapes (the updater beacon status, the pairing list, the peer-pool snapshot) return
95/// [`Value`] rather than a frozen struct, matching the catalog's [`ControlCall::Output`] for those
96/// methods.
97#[async_trait]
98pub trait ControlHandler: Sync {
99    /// `control.status`
100    async fn status(&self) -> Result<results::StatusResult, ControlError>;
101    /// `control.config.get`
102    async fn config_get(&self) -> Result<results::ConfigResult, ControlError>;
103    /// `control.config.setUpstream`
104    async fn config_set_upstream(
105        &self,
106        params: params::SetUpstreamParams,
107    ) -> Result<results::SetUpstreamResult, ControlError>;
108    /// `control.log.setLevel`
109    async fn log_set_level(
110        &self,
111        params: params::SetLevelParams,
112    ) -> Result<results::SetLevelResult, ControlError>;
113    /// `control.cache.get`
114    async fn cache_get(&self) -> Result<results::CacheView, ControlError>;
115    /// `control.cache.setCap`
116    async fn cache_set_cap(
117        &self,
118        params: params::SetCapParams,
119    ) -> Result<results::SetCapResult, ControlError>;
120    /// `control.cache.clear`
121    async fn cache_clear(&self) -> Result<results::CacheClearResult, ControlError>;
122    /// `control.hostedStores.list`
123    async fn hosted_stores_list(&self) -> Result<results::HostedStoresListResult, ControlError>;
124    /// `control.hostedStores.pin`
125    async fn hosted_stores_pin(
126        &self,
127        params: params::PinParams,
128    ) -> Result<results::PinResult, ControlError>;
129    /// `control.hostedStores.unpin`
130    async fn hosted_stores_unpin(
131        &self,
132        params: params::UnpinParams,
133    ) -> Result<results::UnpinResult, ControlError>;
134    /// `control.hostedStores.status`
135    async fn hosted_stores_status(
136        &self,
137        params: params::HostedStoreStatusParams,
138    ) -> Result<results::HostedStoreStatusResult, ControlError>;
139    /// `control.sync.status`
140    async fn sync_status(&self) -> Result<results::SyncStatusResult, ControlError>;
141    /// `control.sync.trigger`
142    async fn sync_trigger(
143        &self,
144        params: params::SyncTriggerParams,
145    ) -> Result<results::SyncTriggerResult, ControlError>;
146    /// `control.updater.status`
147    async fn updater_status(&self) -> Result<Value, ControlError>;
148    /// `control.updater.setChannel`
149    async fn updater_set_channel(
150        &self,
151        params: params::SetChannelParams,
152    ) -> Result<Value, ControlError>;
153    /// `control.updater.pause`
154    async fn updater_pause(&self, params: params::PauseParams) -> Result<Value, ControlError>;
155    /// `control.updater.resume`
156    async fn updater_resume(&self) -> Result<Value, ControlError>;
157    /// `control.updater.checkNow`
158    async fn updater_check_now(&self) -> Result<Value, ControlError>;
159    /// `control.pairing.list`
160    async fn pairing_list(&self) -> Result<Value, ControlError>;
161    /// `control.pairing.approve`
162    async fn pairing_approve(
163        &self,
164        params: params::ApproveParams,
165    ) -> Result<results::PairingApproveResult, ControlError>;
166    /// `control.pairing.revoke`
167    async fn pairing_revoke(
168        &self,
169        params: params::RevokeParams,
170    ) -> Result<results::PairingRevokeResult, ControlError>;
171    /// `control.peerStatus`
172    async fn peer_status(&self) -> Result<Value, ControlError>;
173    /// `control.peers.connect`
174    async fn peers_connect(
175        &self,
176        params: params::PeersConnectParams,
177    ) -> Result<results::PeersConnectResult, ControlError>;
178    /// `control.peers.disconnect`
179    async fn peers_disconnect(
180        &self,
181        params: params::PeersDisconnectParams,
182    ) -> Result<results::PeersDisconnectResult, ControlError>;
183    /// `control.subscribe`
184    ///
185    /// `params.kind` is OPTIONAL on the wire and absent means
186    /// [`SubscriptionKind::Capsule`](params::SubscriptionKind::Capsule). An implementation MUST
187    /// persist untagged rows it already holds as capsules rather than discarding them: a node that
188    /// refuses to read its own pre-existing `subscriptions.json` starts with an empty one, and the
189    /// upgrade silently unsubscribes the user from everything.
190    async fn subscribe(
191        &self,
192        params: params::SubscribeParams,
193    ) -> Result<results::SubscribeResult, ControlError>;
194    /// `control.unsubscribe`
195    async fn unsubscribe(
196        &self,
197        params: params::UnsubscribeParams,
198    ) -> Result<results::UnsubscribeResult, ControlError>;
199    /// `control.listSubscriptions`
200    async fn list_subscriptions(&self) -> Result<results::ListSubscriptionsResult, ControlError>;
201    /// `control.wallet.balance` (READ-only)
202    async fn wallet_balance(
203        &self,
204        params: params::WalletBalanceParams,
205    ) -> Result<results::WalletBalanceResult, ControlError>;
206    /// `control.wallet.coins` (READ-only, OPEN)
207    ///
208    /// An empty `coins` list MUST mean "a chain was consulted and this address holds nothing".
209    /// A read that could not consult a chain MUST return the matching catalogued error instead.
210    async fn wallet_coins(
211        &self,
212        params: params::WalletCoinsParams,
213    ) -> Result<results::WalletCoinsResult, ControlError>;
214    /// `control.wallet.coinById` (READ-only, OPEN)
215    ///
216    /// `Ok(coin: None)` MUST mean "a chain was consulted and holds no such coin". A read that could
217    /// not consult a chain MUST return the matching catalogued error instead — a caller that cannot
218    /// tell those apart reports a spent mint as pending forever.
219    ///
220    /// The params are validated at DESERIALIZATION (lowercase 64-hex, `0x` stripped), so any path
221    /// that decodes `WalletCoinByIdParams` refuses malformed ids as `INVALID_PARAMS` before this
222    /// method is called.
223    async fn wallet_coin_by_id(
224        &self,
225        params: params::WalletCoinByIdParams,
226    ) -> Result<results::WalletCoinByIdResult, ControlError>;
227    /// `control.wallet.coinSpend` (READ-only, OPEN)
228    ///
229    /// `Ok(spend: None)` MUST mean "a chain was consulted and holds no spend of that coin" — the
230    /// coin is unspent, or unknown. A read that could not consult a chain MUST return the matching
231    /// catalogued error instead: a caller following a singleton forward reads "no spend" as *this is
232    /// the tip* and stops walking, so a failure disguised as absence produces a spend built against
233    /// a superseded singleton.
234    ///
235    /// A returned spend's `puzzle_reveal` MUST tree-hash to the spent coin's own `puzzle_hash`, and
236    /// the implementation MUST fail closed — an error, never an unverified reveal — when it does not
237    /// or when the reveal will not parse. The reveal comes from a peer, and a peer can lie.
238    ///
239    /// The params are validated at DESERIALIZATION (lowercase 64-hex, `0x` stripped), so any path
240    /// that decodes `WalletCoinSpendParams` refuses malformed ids as `INVALID_PARAMS` before this
241    /// method is called.
242    async fn wallet_coin_spend(
243        &self,
244        params: params::WalletCoinSpendParams,
245    ) -> Result<results::WalletCoinSpendResult, ControlError>;
246    /// `control.wallet.coinsByParent` (READ-only, OPEN)
247    ///
248    /// Returns the parent's DIRECT children and nothing further. An implementation MUST NOT recurse:
249    /// a transitive walk over caller-supplied input is unbounded work the caller cannot bound, and a
250    /// partial walk returned as a complete one is a lineage with a silent hole in it.
251    ///
252    /// An empty list MUST mean "a chain was consulted and this parent created no known children".
253    /// A read that could not consult a chain MUST return the matching catalogued error instead.
254    ///
255    /// The answer is ONE PAGE. An implementation MUST return at most
256    /// `params.effective_limit()` records, in ASCENDING `coin_id` order, starting strictly after
257    /// `params.after_coin_id` when one is given; it MUST set `complete` to whether the page carries
258    /// the last child; and it MUST set `cursor` to the last record it actually returned (`None` for
259    /// an empty page). It MUST NOT report `complete: true` on a page it truncated — a caller reads
260    /// that as the end of a lineage branch. The params are validated at DESERIALIZATION, so an
261    /// out-of-range page size is refused as `INVALID_PARAMS` before this method is called.
262    ///
263    /// Every record MUST report `asset: None`: naming a coin by its parent classifies nothing, and
264    /// asserting a class this read never verified is a claim a caller would then spend against.
265    async fn wallet_coins_by_parent(
266        &self,
267        params: params::WalletCoinsByParentParams,
268    ) -> Result<results::WalletCoinsByParentResult, ControlError>;
269    /// `control.wallet.arrivals` (READ-only, TOKEN-GATED)
270    ///
271    /// Gated although it is a read: the caller supplies only a cursor, so the answer names this
272    /// node's OWN watched puzzle hashes and the receive history behind them.
273    ///
274    /// Every returned row MUST be a CONFIRMED arrival that the node itself judged: above its arrival
275    /// baseline, not previously reported, and not the wallet's own change. An implementation MUST NOT
276    /// emit a mempool sighting here, and MUST answer an empty page rather than an error when it has
277    /// no baseline — "nothing arrived" is the honest answer from a wallet that cannot yet tell
278    /// history from news.
279    ///
280    /// `cursor` MUST be the position of the last row actually returned (or the caller's `after_seq`
281    /// for an empty page) and MUST NOT be `latest`; see
282    /// [`WalletArrivalsResult::latest`](results::WalletArrivalsResult::latest).
283    async fn wallet_arrivals(
284        &self,
285        params: params::WalletArrivalsParams,
286    ) -> Result<results::WalletArrivalsResult, ControlError>;
287    /// `control.wallet.peak` (READ-only, OPEN)
288    async fn wallet_peak(&self) -> Result<results::WalletPeakResult, ControlError>;
289    /// `control.peerCounts` (READ-only, OPEN)
290    ///
291    /// `dig_peer_count` MUST be dig-node-core's `connected_peers` — the same figure
292    /// `control.peerStatus` reports — and `chia_peer_count` MUST be the SAME observation
293    /// `wallet_sync_status` reports, served from ONE source so the two answers agree. `None` means
294    /// the count cannot be observed; a network that is not running is UNKNOWN, never `Some(0)`.
295    async fn peer_counts(&self) -> Result<results::PeerCountsResult, ControlError>;
296    /// `control.wallet.syncStatus` (READ-only, OPEN)
297    ///
298    /// `WalletSyncPhase::Synced` MUST require BOTH that the initial catch-up completed and that at
299    /// least one Chia peer connection is live now, which makes it strictly stronger than
300    /// `WalletPeakResult::synced`. `peak_height` MUST be the node's OWN replica's height or `None`,
301    /// never an oracle's, and `chia_peer_count` counts CHIA full-node peers -- never DIG peers.
302    async fn wallet_sync_status(&self) -> Result<results::WalletSyncStatusResult, ControlError>;
303    /// `control.wallet.broadcast` (TOKEN-GATED)
304    ///
305    /// Pushes an ALREADY-SIGNED bundle: the implementation never signs, and never receives anything
306    /// it could sign with (§908). A mempool refusal is `Ok` with `accepted: false`; failing to
307    /// reach a mempool is `Err`.
308    async fn wallet_broadcast(
309        &self,
310        params: params::WalletBroadcastParams,
311    ) -> Result<results::WalletBroadcastResult, ControlError>;
312    /// `control.wallet.watch` (TOKEN-GATED)
313    ///
314    /// Enrols PUBLIC keys for the node's chain replica to follow. The implementation MUST derive the
315    /// addresses itself, from the SAME derivation it applies to the keys already in its own custody
316    /// — a second derivation is a second opinion about which addresses a key covers, and the client
317    /// would read the difference as missing money.
318    ///
319    /// It MUST be IDEMPOTENT: keys already enrolled are reported as `added: 0` and the call
320    /// succeeds. It MUST persist the enrolment across restarts — a set that evaporates on restart
321    /// makes a node that syncs today and reports a zero balance tomorrow.
322    ///
323    /// The params are validated at DESERIALIZATION (lowercase 96-hex, `0x` stripped), so any path
324    /// that decodes `WalletWatchParams` refuses a malformed key as `INVALID_PARAMS` — for the WHOLE
325    /// request — before this method is called.
326    async fn wallet_watch(
327        &self,
328        params: params::WalletWatchParams,
329    ) -> Result<results::WalletWatchResult, ControlError>;
330    /// `control.wallet.unwatch` (TOKEN-GATED)
331    ///
332    /// Deregisters keys, and the following MUST actually stop: the addresses leave the replica's
333    /// watched set, not merely the list this node reports. A registry that keeps syncing what it
334    /// says it forgot is the failure this method exists to make impossible.
335    ///
336    /// Deregistering a key that was never enrolled is a success reporting `removed: 0`.
337    async fn wallet_unwatch(
338        &self,
339        params: params::WalletUnwatchParams,
340    ) -> Result<results::WalletUnwatchResult, ControlError>;
341    /// `control.wallet.watched` (READ-only, TOKEN-GATED)
342    ///
343    /// Gated although it is a read: the caller supplies nothing, so the answer names this node's OWN
344    /// enrolled keys.
345    ///
346    /// MUST return exactly the keys enrolment added, in the wire form they were accepted in, so a
347    /// client can compare its own set against the node's by value. MUST NOT include the node's own
348    /// custody keys: this method reports what was ENROLLED through it, and a caller reconciling
349    /// against a superset would unwatch keys it never watched.
350    async fn wallet_watched(&self) -> Result<results::WalletWatchedResult, ControlError>;
351    /// `control.profile.putBody` (TOKEN-GATED)
352    ///
353    /// An implementation MUST independently resolve the profile's root ON CHAIN, recompute the root
354    /// of the supplied body, and REFUSE the call unless the two agree and that root is confirmed.
355    /// The caller's `root` is a claim to be checked — never a fact to be trusted — and dig-app gets
356    /// no exemption: it holds the key and signs the root (§908), but the bytes reach the node the
357    /// same way a peer's bytes do, and the same check binds both. An implementation that stores
358    /// what it is handed makes this node serve arbitrary bytes under someone else's profile id.
359    ///
360    /// A body whose DECODED length exceeds [`MAX_BODY_BYTES`](params::MAX_BODY_BYTES) (4 MiB) MUST
361    /// be refused as `INVALID_PARAMS`, before it is persisted: a body larger than that cannot be
362    /// served to a peer inside dig-gossip's frame ceiling, so accepting it would store something
363    /// permanently unsyncable.
364    ///
365    /// Returning `Ok` therefore asserts BOTH that the root was confirmed on chain and that the body
366    /// is persisted and servable. A refusal is an error, never an `Ok` carrying `stored: false`.
367    async fn profile_put_body(
368        &self,
369        params: params::ProfilePutBodyParams,
370    ) -> Result<results::ProfilePutBodyResult, ControlError>;
371    /// `control.profile.getBody` (READ-only, TOKEN-GATED)
372    ///
373    /// `Ok(body_b64: None)` MUST mean "this node was consulted and holds no body at that root". A
374    /// read that FAILED MUST return a catalogued error instead — a caller that reads a failure as
375    /// absence renders an existing profile as an empty one.
376    ///
377    /// The returned `root` MUST be the root the caller asked for; a node MUST NOT substitute a
378    /// newer body it happens to hold.
379    async fn profile_get_body(
380        &self,
381        params: params::ProfileGetBodyParams,
382    ) -> Result<results::ProfileGetBodyResult, ControlError>;
383    /// `pairing.request` (OPEN)
384    async fn pairing_request(
385        &self,
386        params: params::RequestParams,
387    ) -> Result<results::PairingRequestResult, ControlError>;
388    /// `pairing.poll` (OPEN)
389    async fn pairing_poll(
390        &self,
391        params: params::PollParams,
392    ) -> Result<results::PairingPollResult, ControlError>;
393
394    /// Route a raw JSON-RPC request to the right typed method and build the response envelope.
395    ///
396    /// Deserializes the params for methods that take them, calls the handler, and serializes the
397    /// typed result. An unknown method → `METHOD_NOT_FOUND`; malformed params → `INVALID_PARAMS`.
398    /// This is the single seam a server dispatches through — the KATs exercise it end-to-end.
399    async fn dispatch(&self, request: JsonRpcRequest) -> JsonRpcResponse {
400        let id = request.id.clone();
401        let Some(method) = ControlMethod::from_name(&request.method) else {
402            return JsonRpcResponse::error(
403                id,
404                ControlError::of(
405                    ControlErrorCode::MethodNotFound,
406                    format!("unknown control method: {}", request.method),
407                ),
408            );
409        };
410        match self.dispatch_method(method, request.params).await {
411            Ok(result) => JsonRpcResponse::success(id, result),
412            Err(err) => JsonRpcResponse::error(id, err),
413        }
414    }
415
416    /// Route to the typed method by [`ControlMethod`], returning the result as a [`Value`]. Split
417    /// from [`dispatch`](ControlHandler::dispatch) so the envelope wrapping stays in one place.
418    #[doc(hidden)]
419    async fn dispatch_method(
420        &self,
421        method: ControlMethod,
422        params: Value,
423    ) -> Result<Value, ControlError> {
424        /// Deserialize a method's params, mapping a shape error to `INVALID_PARAMS`.
425        fn decode<T: DeserializeOwned>(params: Value) -> Result<T, ControlError> {
426            serde_json::from_value(params)
427                .map_err(|e| ControlError::of(ControlErrorCode::InvalidParams, e.to_string()))
428        }
429        /// Serialize a typed result to a `Value` (infallible for our derive-Serialize results).
430        fn encode<T: Serialize>(value: T) -> Result<Value, ControlError> {
431            serde_json::to_value(value)
432                .map_err(|e| ControlError::of(ControlErrorCode::ControlError, e.to_string()))
433        }
434        match method {
435            ControlMethod::Status => encode(self.status().await?),
436            ControlMethod::ConfigGet => encode(self.config_get().await?),
437            ControlMethod::ConfigSetUpstream => {
438                encode(self.config_set_upstream(decode(params)?).await?)
439            }
440            ControlMethod::LogSetLevel => encode(self.log_set_level(decode(params)?).await?),
441            ControlMethod::CacheGet => encode(self.cache_get().await?),
442            ControlMethod::CacheSetCap => encode(self.cache_set_cap(decode(params)?).await?),
443            ControlMethod::CacheClear => encode(self.cache_clear().await?),
444            ControlMethod::HostedStoresList => encode(self.hosted_stores_list().await?),
445            ControlMethod::HostedStoresPin => {
446                encode(self.hosted_stores_pin(decode(params)?).await?)
447            }
448            ControlMethod::HostedStoresUnpin => {
449                encode(self.hosted_stores_unpin(decode(params)?).await?)
450            }
451            ControlMethod::HostedStoresStatus => {
452                encode(self.hosted_stores_status(decode(params)?).await?)
453            }
454            ControlMethod::SyncStatus => encode(self.sync_status().await?),
455            ControlMethod::SyncTrigger => encode(self.sync_trigger(decode(params)?).await?),
456            ControlMethod::UpdaterStatus => self.updater_status().await,
457            ControlMethod::UpdaterSetChannel => self.updater_set_channel(decode(params)?).await,
458            ControlMethod::UpdaterPause => self.updater_pause(decode(params)?).await,
459            ControlMethod::UpdaterResume => self.updater_resume().await,
460            ControlMethod::UpdaterCheckNow => self.updater_check_now().await,
461            ControlMethod::PairingList => self.pairing_list().await,
462            ControlMethod::PairingApprove => encode(self.pairing_approve(decode(params)?).await?),
463            ControlMethod::PairingRevoke => encode(self.pairing_revoke(decode(params)?).await?),
464            ControlMethod::PeerStatus => self.peer_status().await,
465            ControlMethod::PeerCounts => encode(self.peer_counts().await?),
466            ControlMethod::PeersConnect => encode(self.peers_connect(decode(params)?).await?),
467            ControlMethod::PeersDisconnect => encode(self.peers_disconnect(decode(params)?).await?),
468            ControlMethod::Subscribe => encode(self.subscribe(decode(params)?).await?),
469            ControlMethod::Unsubscribe => encode(self.unsubscribe(decode(params)?).await?),
470            ControlMethod::ListSubscriptions => encode(self.list_subscriptions().await?),
471            ControlMethod::WalletBalance => encode(self.wallet_balance(decode(params)?).await?),
472            ControlMethod::WalletCoins => encode(self.wallet_coins(decode(params)?).await?),
473            // Re-validated here idempotently; deserialization already enforced the same rule.
474            ControlMethod::WalletCoinById => {
475                let params: params::WalletCoinByIdParams = decode(params)?;
476                encode(self.wallet_coin_by_id(params.validated()?).await?)
477            }
478            // Re-validated here idempotently; deserialization already enforced the same rule.
479            ControlMethod::WalletCoinSpend => {
480                let params: params::WalletCoinSpendParams = decode(params)?;
481                encode(self.wallet_coin_spend(params.validated()?).await?)
482            }
483            ControlMethod::WalletCoinsByParent => {
484                let params: params::WalletCoinsByParentParams = decode(params)?;
485                encode(self.wallet_coins_by_parent(params.validated()?).await?)
486            }
487            ControlMethod::WalletArrivals => encode(self.wallet_arrivals(decode(params)?).await?),
488            ControlMethod::WalletPeak => encode(self.wallet_peak().await?),
489            ControlMethod::WalletSyncStatus => encode(self.wallet_sync_status().await?),
490            ControlMethod::WalletBroadcast => encode(self.wallet_broadcast(decode(params)?).await?),
491            // Re-validated here idempotently; deserialization already enforced the same rule.
492            ControlMethod::WalletWatch => {
493                let params: params::WalletWatchParams = decode(params)?;
494                encode(self.wallet_watch(params.validated()?).await?)
495            }
496            // Re-validated here idempotently; deserialization already enforced the same rule.
497            ControlMethod::WalletUnwatch => {
498                let params: params::WalletUnwatchParams = decode(params)?;
499                encode(self.wallet_unwatch(params.validated()?).await?)
500            }
501            ControlMethod::WalletWatched => encode(self.wallet_watched().await?),
502            ControlMethod::ProfilePutBody => encode(self.profile_put_body(decode(params)?).await?),
503            ControlMethod::ProfileGetBody => encode(self.profile_get_body(decode(params)?).await?),
504            ControlMethod::PairingRequest => encode(self.pairing_request(decode(params)?).await?),
505            ControlMethod::PairingPoll => encode(self.pairing_poll(decode(params)?).await?),
506        }
507    }
508}