1#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22pub enum Routing {
23 Owned,
25 Delegated,
27 OpenBootstrap,
29}
30
31#[non_exhaustive]
37#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
38pub enum Category {
39 Status,
41 Config,
43 Log,
45 Cache,
47 HostedStores,
49 Sync,
51 Updater,
53 Pairing,
55 Peers,
57 Subscriptions,
59 Wallet,
62 Spends,
65 Profile,
69 Collateral,
73}
74
75#[non_exhaustive]
81#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
82pub enum ControlMethod {
83 Status,
86 ConfigGet,
88 ConfigSetUpstream,
90 LogSetLevel,
92
93 CacheGet,
96 CacheSetCap,
98 CacheClear,
100
101 HostedStoresList,
104 HostedStoresPin,
106 HostedStoresUnpin,
108 HostedStoresStatus,
110 CapsuleFetch,
113
114 SyncStatus,
117 SyncTrigger,
119
120 UpdaterStatus,
123 UpdaterSetChannel,
125 UpdaterPause,
127 UpdaterResume,
129 UpdaterCheckNow,
131
132 PairingList,
135 PairingApprove,
137 PairingRevoke,
139
140 PeerStatus,
143 PeerCounts,
145 PeersConnect,
147 PeersDisconnect,
149
150 ChiaPeersAdd,
166 ChiaPeersList,
168 ChiaPeersRemove,
170
171 Subscribe,
174 Unsubscribe,
176 ListSubscriptions,
178
179 WalletBalance,
182 WalletCoins,
184 WalletCoinById,
186 WalletCoinSpend,
188 WalletCoinsByParent,
190 WalletArrivals,
192 WalletPeak,
194 WalletSyncStatus,
196 WalletBroadcast,
198 WalletWatch,
200 WalletUnwatch,
202 WalletWatched,
204 WalletReservationsHeld,
206 WalletReservationsReserve,
208 WalletReservationsRelease,
210
211 SpendsList,
214
215 CollateralRequirement,
218 CollateralMarginGet,
220 CollateralMarginSet,
222 CollateralBuffer,
224 MirrorBondStates,
227
228 ProfilePutBody,
231 ProfileGetBody,
233
234 PairingRequest,
237 PairingPoll,
239}
240
241impl ControlMethod {
242 pub const fn name(self) -> &'static str {
244 match self {
245 ControlMethod::Status => "control.status",
246 ControlMethod::ConfigGet => "control.config.get",
247 ControlMethod::ConfigSetUpstream => "control.config.setUpstream",
248 ControlMethod::LogSetLevel => "control.log.setLevel",
249 ControlMethod::CacheGet => "control.cache.get",
250 ControlMethod::CacheSetCap => "control.cache.setCap",
251 ControlMethod::CacheClear => "control.cache.clear",
252 ControlMethod::HostedStoresList => "control.hostedStores.list",
253 ControlMethod::HostedStoresPin => "control.hostedStores.pin",
254 ControlMethod::HostedStoresUnpin => "control.hostedStores.unpin",
255 ControlMethod::HostedStoresStatus => "control.hostedStores.status",
256 ControlMethod::CapsuleFetch => "control.capsule.fetch",
257 ControlMethod::SyncStatus => "control.sync.status",
258 ControlMethod::SyncTrigger => "control.sync.trigger",
259 ControlMethod::UpdaterStatus => "control.updater.status",
260 ControlMethod::UpdaterSetChannel => "control.updater.setChannel",
261 ControlMethod::UpdaterPause => "control.updater.pause",
262 ControlMethod::UpdaterResume => "control.updater.resume",
263 ControlMethod::UpdaterCheckNow => "control.updater.checkNow",
264 ControlMethod::PairingList => "control.pairing.list",
265 ControlMethod::PairingApprove => "control.pairing.approve",
266 ControlMethod::PairingRevoke => "control.pairing.revoke",
267 ControlMethod::PeerStatus => "control.peerStatus",
268 ControlMethod::PeerCounts => "control.peerCounts",
269 ControlMethod::PeersConnect => "control.peers.connect",
270 ControlMethod::PeersDisconnect => "control.peers.disconnect",
271 ControlMethod::ChiaPeersAdd => "control.chiaPeers.add",
272 ControlMethod::ChiaPeersList => "control.chiaPeers.list",
273 ControlMethod::ChiaPeersRemove => "control.chiaPeers.remove",
274 ControlMethod::Subscribe => "control.subscribe",
275 ControlMethod::Unsubscribe => "control.unsubscribe",
276 ControlMethod::ListSubscriptions => "control.listSubscriptions",
277 ControlMethod::WalletBalance => "control.wallet.balance",
278 ControlMethod::WalletCoins => "control.wallet.coins",
279 ControlMethod::WalletCoinById => "control.wallet.coinById",
280 ControlMethod::WalletCoinSpend => "control.wallet.coinSpend",
281 ControlMethod::WalletCoinsByParent => "control.wallet.coinsByParent",
282 ControlMethod::WalletArrivals => "control.wallet.arrivals",
283 ControlMethod::WalletPeak => "control.wallet.peak",
284 ControlMethod::WalletSyncStatus => "control.wallet.syncStatus",
285 ControlMethod::WalletBroadcast => "control.wallet.broadcast",
286 ControlMethod::WalletWatch => "control.wallet.watch",
287 ControlMethod::WalletUnwatch => "control.wallet.unwatch",
288 ControlMethod::WalletWatched => "control.wallet.watched",
289 ControlMethod::WalletReservationsHeld => "control.wallet.reservations.held",
290 ControlMethod::WalletReservationsReserve => "control.wallet.reservations.reserve",
291 ControlMethod::WalletReservationsRelease => "control.wallet.reservations.release",
292 ControlMethod::SpendsList => "control.spends.list",
293 ControlMethod::CollateralRequirement => "control.collateral.requirement",
294 ControlMethod::CollateralMarginGet => "control.collateral.margin.get",
295 ControlMethod::CollateralMarginSet => "control.collateral.margin.set",
296 ControlMethod::CollateralBuffer => "control.collateral.buffer",
297 ControlMethod::MirrorBondStates => "control.mirror.bondStates",
298 ControlMethod::ProfilePutBody => "control.profile.putBody",
299 ControlMethod::ProfileGetBody => "control.profile.getBody",
300 ControlMethod::PairingRequest => "pairing.request",
301 ControlMethod::PairingPoll => "pairing.poll",
302 }
303 }
304
305 pub fn from_name(name: &str) -> Option<ControlMethod> {
307 ControlMethod::ALL
308 .iter()
309 .copied()
310 .find(|m| m.name() == name)
311 }
312
313 pub const fn requires_auth(self) -> bool {
340 !self.is_open_read()
341 && !matches!(
342 self,
343 ControlMethod::PairingRequest | ControlMethod::PairingPoll
344 )
345 }
346
347 pub const fn is_open_read(self) -> bool {
381 matches!(
382 self,
383 ControlMethod::WalletBalance
384 | ControlMethod::WalletCoins
385 | ControlMethod::WalletCoinById
386 | ControlMethod::WalletCoinSpend
387 | ControlMethod::WalletCoinsByParent
388 | ControlMethod::WalletPeak
389 | ControlMethod::WalletSyncStatus
390 | ControlMethod::PeerCounts
391 )
392 }
393
394 pub const fn is_pairing_admin(self) -> bool {
403 matches!(
404 self,
405 ControlMethod::PairingList
406 | ControlMethod::PairingApprove
407 | ControlMethod::PairingRevoke
408 )
409 }
410
411 pub const fn requires_master_token(self) -> bool {
438 self.is_pairing_admin()
439 || matches!(
440 self,
441 ControlMethod::ChiaPeersAdd | ControlMethod::ChiaPeersRemove
442 )
443 }
444
445 pub const fn routing(self) -> Routing {
447 match self {
448 ControlMethod::PeerStatus
449 | ControlMethod::PeerCounts
450 | ControlMethod::PeersConnect
451 | ControlMethod::PeersDisconnect
452 | ControlMethod::Subscribe
453 | ControlMethod::Unsubscribe
454 | ControlMethod::ListSubscriptions
455 | ControlMethod::WalletBalance
456 | ControlMethod::WalletCoins
457 | ControlMethod::WalletCoinById
458 | ControlMethod::WalletCoinSpend
459 | ControlMethod::WalletCoinsByParent
460 | ControlMethod::WalletArrivals
461 | ControlMethod::WalletPeak
462 | ControlMethod::WalletSyncStatus
463 | ControlMethod::WalletBroadcast
464 | ControlMethod::WalletWatch
465 | ControlMethod::WalletUnwatch
466 | ControlMethod::WalletWatched
467 | ControlMethod::WalletReservationsHeld
468 | ControlMethod::WalletReservationsReserve
469 | ControlMethod::WalletReservationsRelease
470 | ControlMethod::ProfilePutBody
471 | ControlMethod::ProfileGetBody => Routing::Delegated,
472 ControlMethod::PairingRequest | ControlMethod::PairingPoll => Routing::OpenBootstrap,
473 _ => Routing::Owned,
474 }
475 }
476
477 pub const fn category(self) -> Category {
479 match self {
480 ControlMethod::Status => Category::Status,
481 ControlMethod::ConfigGet | ControlMethod::ConfigSetUpstream => Category::Config,
482 ControlMethod::LogSetLevel => Category::Log,
483 ControlMethod::CacheGet | ControlMethod::CacheSetCap | ControlMethod::CacheClear => {
484 Category::Cache
485 }
486 ControlMethod::HostedStoresList
487 | ControlMethod::HostedStoresPin
488 | ControlMethod::HostedStoresUnpin
489 | ControlMethod::HostedStoresStatus
490 | ControlMethod::CapsuleFetch => Category::HostedStores,
491 ControlMethod::SyncStatus | ControlMethod::SyncTrigger => Category::Sync,
492 ControlMethod::UpdaterStatus
493 | ControlMethod::UpdaterSetChannel
494 | ControlMethod::UpdaterPause
495 | ControlMethod::UpdaterResume
496 | ControlMethod::UpdaterCheckNow => Category::Updater,
497 ControlMethod::PairingList
498 | ControlMethod::PairingApprove
499 | ControlMethod::PairingRevoke
500 | ControlMethod::PairingRequest
501 | ControlMethod::PairingPoll => Category::Pairing,
502 ControlMethod::PeerStatus
503 | ControlMethod::PeerCounts
504 | ControlMethod::PeersConnect
505 | ControlMethod::PeersDisconnect
506 | ControlMethod::ChiaPeersAdd
507 | ControlMethod::ChiaPeersList
508 | ControlMethod::ChiaPeersRemove => Category::Peers,
509 ControlMethod::Subscribe
510 | ControlMethod::Unsubscribe
511 | ControlMethod::ListSubscriptions => Category::Subscriptions,
512 ControlMethod::WalletBalance
513 | ControlMethod::WalletCoins
514 | ControlMethod::WalletCoinById
515 | ControlMethod::WalletCoinSpend
516 | ControlMethod::WalletCoinsByParent
517 | ControlMethod::WalletArrivals
518 | ControlMethod::WalletPeak
519 | ControlMethod::WalletSyncStatus
520 | ControlMethod::WalletBroadcast
521 | ControlMethod::WalletWatch
522 | ControlMethod::WalletUnwatch
523 | ControlMethod::WalletWatched
524 | ControlMethod::WalletReservationsHeld
525 | ControlMethod::WalletReservationsReserve
526 | ControlMethod::WalletReservationsRelease => Category::Wallet,
527 ControlMethod::SpendsList => Category::Spends,
528 ControlMethod::CollateralRequirement
529 | ControlMethod::CollateralMarginGet
530 | ControlMethod::CollateralMarginSet
531 | ControlMethod::CollateralBuffer
532 | ControlMethod::MirrorBondStates => Category::Collateral,
533 ControlMethod::ProfilePutBody | ControlMethod::ProfileGetBody => Category::Profile,
534 }
535 }
536
537 pub const fn summary(self) -> &'static str {
539 match self {
540 ControlMethod::ChiaPeersAdd => "Trust a Chia full node by IP. A trusted peer BYPASSES CORROBORATION: this node normally believes a chain answer only when several independently-dialled peers agree, and a trusted peer is believed on its own -- so a wrong or hostile one can feed this node a false view of the chain. Add only a node you run yourself.",
541 ControlMethod::ChiaPeersList => "The Chia full-node peers this node tracks, each flagged user_managed: true where a person added it by hand and it is therefore trusted without corroboration.",
542 ControlMethod::ChiaPeersRemove => "Stop trusting a Chia full node, optionally banning it. Removing restores corroboration for that peer: chain answers must once again be agreed by independently-dialled peers.",
543 ControlMethod::Status => "A rich node status snapshot (version, uptime, addr, cache, hosted/pinned counts, sync availability).",
544 ControlMethod::ConfigGet => "The node's effective configuration (addr/port, upstream + override, cache dir/shared, config path, sync availability).",
545 ControlMethod::ConfigSetUpstream => "Persist an upstream-RPC override; takes effect on next node start (requires_restart).",
546 ControlMethod::LogSetLevel => "Live-swap the running node's tracing EnvFilter directive (not persisted).",
547 ControlMethod::CacheGet => "The on-disk content-cache view: cap_bytes, used_bytes, dir, shared.",
548 ControlMethod::CacheSetCap => "Set the on-disk cache size cap in bytes (floored at 64 MiB).",
549 ControlMethod::CacheClear => "Delete all locally cached DIG content.",
550 ControlMethod::HostedStoresList => "Every held/pinned store, merged, with each store's cached capsules and a pinned flag.",
551 ControlMethod::HostedStoresPin => "Pin a store (storeId[:rootHash]); pre-fetches the capsule when a root is given and §21 sync is available.",
552 ControlMethod::HostedStoresUnpin => "Unpin a store and evict its cached capsules.",
553 ControlMethod::HostedStoresStatus => "Per-store status: pinned flag, cached capsules, total bytes.",
554 ControlMethod::CapsuleFetch => "Start a P2P whole-capsule pull for one store+root over the recursive discover-then-dial path (distinct from the §21 HTTP sync `control.sync.trigger` uses). Answers `already_cached` without dialling out when the capsule is already on disk.",
555 ControlMethod::SyncStatus => "Whether authenticated §21 whole-store sync is available, plus pinned-store cache coverage.",
556 ControlMethod::SyncTrigger => "Trigger a §21 sync for one capsule (storeId + root).",
557 ControlMethod::UpdaterStatus => "The DIG auto-update beacon's current status (proxied from dig-updater).",
558 ControlMethod::UpdaterSetChannel => "Set the beacon's update channel (\"nightly\" | \"stable\").",
559 ControlMethod::UpdaterPause => "Suspend the beacon's auto-updates (optionally until a unix time).",
560 ControlMethod::UpdaterResume => "Resume the beacon's auto-updates.",
561 ControlMethod::UpdaterCheckNow => "Force an immediate beacon update check.",
562 ControlMethod::PairingList => "List pending pairing requests and issued paired tokens (MASTER token only).",
563 ControlMethod::PairingApprove => "Approve a pending pairing, minting a scoped token (MASTER token only).",
564 ControlMethod::PairingRevoke => "Revoke an issued paired token by token_id (MASTER token only).",
565 ControlMethod::PeerStatus => "Live peer-pool + relay-reservation snapshot, including the per-peer connected array; each entry carries an always-present `software` field (the peer's advertised build). Its `relay.peer_count` counts peers connected to THE RELAY, not to this node, and is never the answer to \"how many peers does this node have\" -- that is control.peerCounts.",
566 ControlMethod::PeerCounts => "READ-only: how many peers this node holds on EACH network -- dig_peer_count (DIG content/gossip, port 9445) and chia_peer_count (Chia full nodes serving the wallet chain sync). Two unrelated numbers, each named for its network.",
567 ControlMethod::PeersConnect => "Dial a peer by address, or resolve an already-connected peer_id, via the live gossip pool.",
568 ControlMethod::PeersDisconnect => "Drop a pooled peer by peer_id, closing its mTLS link (idempotent).",
569 ControlMethod::Subscribe => "Subscribe the node to a store it actively watches and gap-fills.",
570 ControlMethod::Unsubscribe => "Stop watching a store.",
571 ControlMethod::ListSubscriptions => "The node's persisted subscription set + count.",
572 ControlMethod::WalletCoins => "READ-only: the spendable coin records for an address + asset, with the tier that answered and the height they reflect.",
573 ControlMethod::WalletCoinById => "READ-only: ONE coin record by coin id, spent or unspent, with no address and no asset scope; `coin: null` means the chain holds no such coin.",
574 ControlMethod::WalletCoinSpend => "READ-only: the SPEND that spent a coin -- its puzzle reveal, its solution and the coin itself -- named by the coin's own id. `spend: null` means the consulted chain shows that coin as unspent or unknown; it NEVER means the chain could not be reached, which is an error.",
575 ControlMethod::WalletCoinsByParent => "READ-only: the DIRECT children created by spending one coin, named by that parent's coin id. ONE hop, never a recursive walk: an empty list means the parent created no known children, and a caller wanting a lineage composes hops itself.",
576 ControlMethod::WalletArrivals => "READ-only: confirmed INCOMING funds recorded since a cursor position, oldest first -- the answer to `was I just paid?`, which no balance or coin list can give. Each row is a coin the node determined ARRIVED: confirmed on chain, above the wallet's arrival baseline, not previously reported, and not the wallet's own change. Resume from `cursor` (the last row you were handed), never from `latest`.",
577 ControlMethod::WalletPeak => "READ-only: the node's current chain peak height, independent of any address.",
578 ControlMethod::WalletSyncStatus => "READ-only: whether the wallet's CHAIN replica is being kept current (not_started/syncing/synced/no_wallet_enrolled/wallet_not_unlocked), the replica's own height, and its CHIA full-node peer count -- unrelated to control.sync.status (DIG stores) and to control.peerStatus (DIG peers).",
579 ControlMethod::WalletBroadcast => "Push an ALREADY-SIGNED spend bundle to the network; the node never signs. TOKEN-GATED.",
580 ControlMethod::WalletBalance => "READ-only: the confirmed spendable balance for an address + asset (plus pending, sync freshness, and the peak height it reflects).",
581 ControlMethod::WalletWatch => "Enrol PUBLIC keys (48-byte G1, lowercase 96-hex) for the node's chain replica to follow, so their addresses are synced and readable. IDEMPOTENT: re-enrolling a key already enrolled succeeds and changes nothing. Keys, never puzzle hashes -- the node derives the addresses itself, so one derivation serves every client. TOKEN-GATED.",
582 ControlMethod::WalletUnwatch => "Deregister enrolled public keys, so the node stops following their addresses. IDEMPOTENT: a key that was never enrolled is not an error. TOKEN-GATED.",
583 ControlMethod::SpendsList => "READ-only: the record of spends this node made WITHOUT per-transaction approval -- what moved, when, on whose standing authority, and whether the chain confirmed it. It NEVER initiates, signs, cancels or alters a spend, and there is no verb here that edits an entry. A failed spend is reported WITH the stage it died at, because only a signing failure means the money definitely did not move; a broadcast or confirmation failure is an UNKNOWN outcome, as is `unresolved`. A page is bounded and says so via `complete`; `unreadable_lines` reports entries the node could not parse, so an audit trail that lost rows can never read as a tidy shorter one. TOKEN-GATED although it is a read: the caller supplies no identifier, so the answer is this node's OWN state.",
584 ControlMethod::CollateralRequirement => "READ-only: this epoch's per-store mirror-collateral requirement in DIG base units, the collateral protocol version that computed it, and the census inputs behind it (advertised stores, collateralised owners, controller multiplier, small-network handicap) so a client can show WHY the figure moved rather than only that it did. A node that has not censused the epoch, or that is inside the census finality depth, answers `unknown` WITH the reason -- never a zero, which would read as a free requirement. `stores` counts qualifying (owner, store, root) advertisements and `owners` counts distinct owner puzzle hashes: neither is a node count. It NEVER returns the local safety margin, which is not a consensus value.",
585 ControlMethod::CollateralMarginGet => "Read the node's LOCAL safety margin in BASIS POINTS over the epoch requirement (`100` is +1%). The margin is an operator preference that changes only how much THIS node chooses to lock; it is never a census input and no value derived from it reaches another node. Basis points are the unit the collateral crate's own presets and rounding use, and are never converted.",
586 ControlMethod::CollateralMarginSet => "Set the node's LOCAL safety margin in BASIS POINTS (`100` is +1%), returning the margin now in force. Bounded at 10000 bp (+100%): the margin multiplies what the node locks on every store, so an unbounded value would commit the operator to an arbitrary posting. A margin above the bound is REFUSED as -32602 INVALID_PARAMS rather than clamped, so the applied value can never differ silently from the requested one. A margin gives room if the requirement rises; it does NOT guarantee a store is counted, because the requirement is re-derived every epoch and can rise by more than any margin.",
587 ControlMethod::ProfilePutBody => "Hand the node the dig-profile BODY that a chain root commits to. The node INDEPENDENTLY resolves that root on chain and REFUSES any body whose recomputed root is not the confirmed one -- the caller's `root` is a claim to be checked, never a fact to be trusted, and dig-app is a caller like any other. Bodies are capped at MAX_BODY_BYTES (4 MiB). TOKEN-GATED.",
588 ControlMethod::ProfileGetBody => "READ-only: the dig-profile body this node holds at a given store id + root, or `body: null` when it holds none. `null` NEVER means the body could not be read, which is an error. TOKEN-GATED.",
589 ControlMethod::WalletWatched => "READ-only: the public keys currently enrolled, so a client can reconcile what it asked for against what the node holds. TOKEN-GATED although it is a read -- the caller supplies nothing, so the answer is this node's OWN key set.",
590 ControlMethod::WalletReservationsHeld => "READ-only: every coin currently committed to an in-flight spend, each with the reservation holding it and the unix second that hold lapses, plus the node's own clock. `reserved: []` means NOTHING is held; a set that cannot be read is an error, never an empty list. Narrows what a caller may SELECT; never subtract these from a balance -- the coins are still the user's money. TOKEN-GATED although it is a read: the caller supplies nothing, so the answer is this node's OWN state.",
591 ControlMethod::WalletReservationsReserve => "Atomically hold coins against further selection: EVERY named coin or none. A coin already held refuses the whole call and reserves nothing, as WALLET_COINS_RESERVED -- a WAIT, never a shortfall. Reserving an empty list succeeds with a handle that releases nothing. The requested ttl_secs is clamped by the node, which returns the lifetime it actually applied. Bookkeeping only: it holds no key and authorizes nothing (§908). TOKEN-GATED.",
592 ControlMethod::WalletReservationsRelease => "Free a hold now rather than waiting out its TTL -- call it the moment a spend is known settled or known dead. A handle that names no live reservation is a SUCCESS with released: false, because a caller releasing on confirmation cannot know whether the TTL got there first. Every hold also lapses on its own, so an abandoned reservation is recoverable and never a permanent funds lockout. TOKEN-GATED.",
593 ControlMethod::CollateralBuffer => "READ-only: the $DIG this node recommends HOLDING, in DIG base units, and the funding state it is in -- plus the working behind the figure: the (owner, store, root) pairs THIS NODE serves, the epoch's pre-margin per-store requirement, the local margin in force (BASIS POINTS, `100` is +1%, never converted), the unreclaimed transition overlap, and the escalation headroom. Amounts are DIG base units (3 decimals, one base unit is 0.001 DIG) and never mojos, which are XCH's 1e-12 unit. The HORIZON the headroom assumed travels in the payload and is never implied: escalation is bounded at +12.5% per epoch and COMPOUNDS (x1.12 at one epoch, x1.60 at four, x4.62 at thirteen), so the same buffer over a different horizon is a different claim; `escalation_ceiling_micros` is a WORST CASE, not a forecast -- in the dead band the multiplier does not move. The FUNDING STATE is carried rather than left to each client to re-derive from thresholds, because two clients deriving it will disagree and the one that disagrees about a funding warning is the one an operator acts on; `short_now` and `dangerously_low` leave an epoch uncovered, `below_recommended_buffer` covers every epoch with no cushion and is a READOUT, never a notification. A node that cannot enumerate its served set, cannot read its reclaim state, cannot see its balance, or has no requirement to scale answers `unknown` WITH the reason -- never a zero, which here reads as NO BUFFER NEEDED and would have an operator post nothing. It is a SEPARATE method from `control.collateral.requirement` because that figure is consensus-derived while this one is local: it depends on this node's own served set, an operator preference, and a horizon this node chose. TOKEN-GATED although it is a read: the caller supplies nothing, so the answer is this node's OWN served set, preference and balance.",
594 ControlMethod::MirrorBondStates => "READ-only: the state of every mirror bond this node holds, keyed per (store, root), plus the $DIG those bonds have LOCKED. Seven states, and six of them mean `no coin yet` for entirely different reasons: `bonded` (a coin id, epoch and the amount THAT COIN locks, read from the coin and not from today's requirement), `pending` (submitted, unconfirmed -- never a shortfall), `unfunded` (the ONLY genuine out-of-funds state, carrying how many DIG BASE UNITS this bond alone is short), `deferred` (the epoch requirement is unknown so no create can be priced -- the wallet may be full), `withheld` (Relayed provenance: held and deliberately never advertised), `disabled` (collateralisation is switched off node-wide) and `reclaiming` (a live coin whose money is STILL LOCKED until the reclaim confirms). Conflating `unfunded` with `withheld` or `disabled` produces hourly out-of-funds alarms about a healthy node, which is the defect this method removes. Amounts are DIG base units (3 decimals, one base unit is 0.001 DIG) and NEVER mojos, which are XCH's 1e-12 unit. `locked_dig_base_units` is the WHOLE-SET total including reclaiming coins, computed by the node: a client MUST NOT sum the page, which would under-report locked money by a page boundary and show unspendable funds as available. A node that cannot enumerate its bonds, cannot read chain, cannot see its own in-flight creates, or cannot determine the provenance of what it holds answers `unknown` for the WHOLE call WITH the reason -- there is no per-row unknown and no empty-list fallback, because a truncated list and a complete one read the same. A page is bounded, ordered by ascending (store_id, root), and says via `complete` whether it is the whole set; resume from the `cursor` key you were HANDED. TOKEN-GATED although it is a read: the caller supplies nothing, so the answer is this node's OWN bond set and funding position.",
595 ControlMethod::PairingRequest => "OPEN: request a control-token pairing; returns a pairing_id + pairing_code to compare.",
596 ControlMethod::PairingPoll => "OPEN: poll a pairing by id; once the operator approves, returns the scoped token once.",
597 }
598 }
599
600 pub const ALL: &'static [ControlMethod] = &[
603 ControlMethod::Status,
604 ControlMethod::ConfigGet,
605 ControlMethod::ConfigSetUpstream,
606 ControlMethod::LogSetLevel,
607 ControlMethod::CacheGet,
608 ControlMethod::CacheSetCap,
609 ControlMethod::CacheClear,
610 ControlMethod::HostedStoresList,
611 ControlMethod::HostedStoresPin,
612 ControlMethod::HostedStoresUnpin,
613 ControlMethod::HostedStoresStatus,
614 ControlMethod::CapsuleFetch,
615 ControlMethod::SyncStatus,
616 ControlMethod::SyncTrigger,
617 ControlMethod::UpdaterStatus,
618 ControlMethod::UpdaterSetChannel,
619 ControlMethod::UpdaterPause,
620 ControlMethod::UpdaterResume,
621 ControlMethod::UpdaterCheckNow,
622 ControlMethod::PairingList,
623 ControlMethod::PairingApprove,
624 ControlMethod::PairingRevoke,
625 ControlMethod::PeerStatus,
626 ControlMethod::PeerCounts,
627 ControlMethod::PeersConnect,
628 ControlMethod::PeersDisconnect,
629 ControlMethod::ChiaPeersAdd,
630 ControlMethod::ChiaPeersList,
631 ControlMethod::ChiaPeersRemove,
632 ControlMethod::Subscribe,
633 ControlMethod::Unsubscribe,
634 ControlMethod::ListSubscriptions,
635 ControlMethod::WalletBalance,
636 ControlMethod::WalletCoins,
637 ControlMethod::WalletCoinById,
638 ControlMethod::WalletCoinSpend,
639 ControlMethod::WalletCoinsByParent,
640 ControlMethod::WalletArrivals,
641 ControlMethod::WalletPeak,
642 ControlMethod::WalletSyncStatus,
643 ControlMethod::WalletBroadcast,
644 ControlMethod::WalletWatch,
645 ControlMethod::WalletUnwatch,
646 ControlMethod::WalletWatched,
647 ControlMethod::WalletReservationsHeld,
648 ControlMethod::WalletReservationsReserve,
649 ControlMethod::WalletReservationsRelease,
650 ControlMethod::SpendsList,
651 ControlMethod::CollateralRequirement,
652 ControlMethod::CollateralMarginGet,
653 ControlMethod::CollateralMarginSet,
654 ControlMethod::CollateralBuffer,
655 ControlMethod::MirrorBondStates,
656 ControlMethod::ProfilePutBody,
657 ControlMethod::ProfileGetBody,
658 ControlMethod::PairingRequest,
659 ControlMethod::PairingPoll,
660 ];
661}
662
663#[cfg(test)]
664mod tests {
665 use super::*;
666 use std::collections::BTreeSet;
667
668 #[test]
669 fn every_method_has_a_unique_wire_name() {
670 let names: BTreeSet<&str> = ControlMethod::ALL.iter().map(|m| m.name()).collect();
671 assert_eq!(
672 names.len(),
673 ControlMethod::ALL.len(),
674 "duplicate or missing wire names in the catalog"
675 );
676 }
677
678 #[test]
679 fn from_name_round_trips_every_method() {
680 for &m in ControlMethod::ALL {
681 assert_eq!(ControlMethod::from_name(m.name()), Some(m));
682 }
683 assert_eq!(ControlMethod::from_name("control.nope"), None);
684 assert_eq!(ControlMethod::from_name(""), None);
685 }
686
687 #[test]
688 fn the_token_less_surface_is_exactly_the_bootstrap_plus_the_chain_reads() {
689 let expected_open: BTreeSet<&str> = [
693 "pairing.request",
694 "pairing.poll",
695 "control.wallet.balance",
696 "control.wallet.coins",
697 "control.wallet.coinById",
698 "control.wallet.coinSpend",
699 "control.wallet.coinsByParent",
700 "control.wallet.peak",
701 "control.wallet.syncStatus",
702 "control.peerCounts",
703 ]
704 .into_iter()
705 .collect();
706 assert_eq!(
707 expected_open.len(),
708 10,
709 "the open surface is ten named methods"
710 );
711 let actual_open: BTreeSet<&str> = ControlMethod::ALL
712 .iter()
713 .filter(|m| !m.requires_auth())
714 .map(|m| m.name())
715 .collect();
716 assert_eq!(actual_open, expected_open);
717 }
718
719 #[test]
728 fn the_gated_wallet_methods_are_the_push_the_cursor_and_enrolment() {
729 let gated: Vec<&str> = ControlMethod::ALL
730 .iter()
731 .filter(|m| m.category() == Category::Wallet && m.requires_auth())
732 .map(|m| m.name())
733 .collect();
734 assert_eq!(
735 gated,
736 vec![
737 "control.wallet.arrivals",
738 "control.wallet.broadcast",
739 "control.wallet.watch",
740 "control.wallet.unwatch",
741 "control.wallet.watched",
742 "control.wallet.reservations.held",
743 "control.wallet.reservations.reserve",
744 "control.wallet.reservations.release",
745 ]
746 );
747 assert!(!ControlMethod::WalletBroadcast.is_open_read());
748 }
749
750 #[test]
762 fn the_arrival_cursor_is_not_an_open_read() {
763 assert!(
764 !ControlMethod::WalletArrivals.is_open_read(),
765 "control.wallet.arrivals discloses this node's OWN watched puzzle hashes to a caller \
766 that supplied nothing, so it MUST NOT be served token-less"
767 );
768 assert!(ControlMethod::WalletArrivals.requires_auth());
769 assert!(
770 ControlMethod::WalletCoinById.is_open_read(),
771 "the caller-addressed reads stay open -- the fix is the membership rule, not gating \
772 the wallet category"
773 );
774 }
775
776 #[test]
795 fn the_catalog_serves_every_chain_source_primitive() {
796 for wire in [
797 "control.wallet.coinById", "control.wallet.coins", "control.wallet.peak", "control.wallet.coinsByParent", "control.wallet.coinSpend", ] {
803 assert!(
804 ControlMethod::from_name(wire).is_some(),
805 "{wire} is required to implement ChainSource over the control plane"
806 );
807 }
808 }
809
810 #[test]
817 fn the_chain_primitives_are_caller_named_open_reads() {
818 for method in [
819 ControlMethod::WalletCoinSpend,
820 ControlMethod::WalletCoinsByParent,
821 ] {
822 assert!(
823 method.is_open_read(),
824 "{} names its subject in the request and discloses no node-to-address \
825 association, exactly like control.wallet.coinById",
826 method.name()
827 );
828 assert!(!method.requires_auth());
829 }
830 assert!(
831 ControlMethod::WalletArrivals.requires_auth(),
832 "the caller-supplies-nothing read stays gated -- the rule is who names the subject, \
833 not whether the bytes are on chain"
834 );
835 assert!(ControlMethod::WalletBroadcast.requires_auth());
836 }
837
838 #[test]
852 fn the_enrolment_methods_are_gated_including_the_read() {
853 for wire in [
854 "control.wallet.watch",
855 "control.wallet.unwatch",
856 "control.wallet.watched",
857 ] {
858 let method = ControlMethod::from_name(wire)
859 .unwrap_or_else(|| panic!("{wire} must be in the catalog"));
860 assert!(
861 !method.is_open_read(),
862 "{wire} either aims this node's subscriptions or names the keys it already \
863 follows, so it MUST NOT be served token-less"
864 );
865 assert!(method.requires_auth(), "{wire} must require the token");
866 assert_eq!(method.category(), Category::Wallet);
867 assert_eq!(method.routing(), Routing::Delegated);
868 }
869 assert!(
870 ControlMethod::WalletCoinById.is_open_read(),
871 "the caller-addressed reads stay open -- enrolment is gated by the membership rule, \
872 not by gating the wallet category"
873 );
874 }
875
876 #[test]
877 fn only_pairing_bootstrap_is_open_bootstrap_routed() {
878 for &m in ControlMethod::ALL {
879 let open_bootstrap = matches!(
880 m,
881 ControlMethod::PairingRequest | ControlMethod::PairingPoll
882 );
883 assert_eq!(
884 m.routing() == Routing::OpenBootstrap,
885 open_bootstrap,
886 "{} routing mismatch",
887 m.name()
888 );
889 }
890 }
891
892 #[test]
893 fn pairing_admin_methods_are_exactly_three() {
894 let admin: Vec<&str> = ControlMethod::ALL
895 .iter()
896 .filter(|m| m.is_pairing_admin())
897 .map(|m| m.name())
898 .collect();
899 assert_eq!(
900 admin,
901 vec![
902 "control.pairing.list",
903 "control.pairing.approve",
904 "control.pairing.revoke"
905 ]
906 );
907 }
908
909 #[test]
916 fn the_master_token_tier_is_pairing_admin_plus_the_trusted_peer_mutations() {
917 let master: BTreeSet<&str> = ControlMethod::ALL
918 .iter()
919 .filter(|m| m.requires_master_token())
920 .map(|m| m.name())
921 .collect();
922 let expected: BTreeSet<&str> = [
923 "control.pairing.list",
924 "control.pairing.approve",
925 "control.pairing.revoke",
926 "control.chiaPeers.add",
927 "control.chiaPeers.remove",
928 ]
929 .into_iter()
930 .collect();
931 assert_eq!(master, expected);
932
933 for &m in ControlMethod::ALL {
936 assert!(
937 !m.is_pairing_admin() || m.requires_master_token(),
938 "{} is pairing-admin but not master-tier",
939 m.name()
940 );
941 }
942 assert!(
943 master.len()
944 > ControlMethod::ALL
945 .iter()
946 .filter(|m| m.is_pairing_admin())
947 .count(),
948 "the two predicates must not be interchangeable"
949 );
950
951 for &m in ControlMethod::ALL {
953 assert!(
954 !m.requires_master_token() || m.requires_auth(),
955 "{}",
956 m.name()
957 );
958 }
959 }
960
961 #[test]
968 fn the_add_summary_authorises_only_a_node_the_operator_runs() {
969 let summary = ControlMethod::ChiaPeersAdd.summary().to_lowercase();
970 assert!(
971 summary.contains("a node you run"),
972 "add must name the operator-run scope, got: {summary}"
973 );
974 for widened in ["vouch", "otherwise trust", "trust yourself", "recommend"] {
975 assert!(
976 !summary.contains(widened),
977 "add summary widens operator trust past NC-12 with {widened:?}: {summary}"
978 );
979 }
980 }
981
982 #[test]
983 fn delegated_set_matches_the_engine_surface() {
984 let delegated: BTreeSet<&str> = ControlMethod::ALL
985 .iter()
986 .filter(|m| m.routing() == Routing::Delegated)
987 .map(|m| m.name())
988 .collect();
989 let expected: BTreeSet<&str> = [
990 "control.wallet.coins",
991 "control.wallet.coinById",
992 "control.wallet.coinSpend",
993 "control.wallet.coinsByParent",
994 "control.wallet.arrivals",
995 "control.wallet.peak",
996 "control.wallet.syncStatus",
997 "control.wallet.broadcast",
998 "control.wallet.watch",
999 "control.wallet.unwatch",
1000 "control.wallet.watched",
1001 "control.wallet.reservations.held",
1002 "control.wallet.reservations.reserve",
1003 "control.wallet.reservations.release",
1004 "control.profile.putBody",
1005 "control.profile.getBody",
1006 "control.peerStatus",
1007 "control.peerCounts",
1008 "control.peers.connect",
1009 "control.peers.disconnect",
1010 "control.subscribe",
1011 "control.unsubscribe",
1012 "control.listSubscriptions",
1013 "control.wallet.balance",
1014 ]
1015 .into_iter()
1016 .collect();
1017 assert_eq!(delegated, expected);
1018 }
1019
1020 #[test]
1027 fn the_trusted_chia_peer_methods_are_gated_and_disclose_the_corroboration_bypass() {
1028 let declared: BTreeSet<&str> = ControlMethod::ALL.iter().map(|m| m.name()).collect();
1029 for name in [
1030 "control.chiaPeers.add",
1031 "control.chiaPeers.list",
1032 "control.chiaPeers.remove",
1033 ] {
1034 assert!(declared.contains(name), "{name} is not in the catalog");
1035 let m = ControlMethod::from_name(name).expect("from_name round-trips");
1036 assert_eq!(m.category(), Category::Peers, "{name} is a peers method");
1037 assert_eq!(m.routing(), Routing::Owned, "{name} is served by the shell");
1038 assert!(m.requires_auth(), "{name} must require the control token");
1039 assert!(!m.is_open_read(), "{name} is not an open read");
1040 }
1041 assert!(ControlMethod::ChiaPeersAdd.requires_master_token());
1045 assert!(ControlMethod::ChiaPeersRemove.requires_master_token());
1046 assert!(
1047 !ControlMethod::ChiaPeersList.requires_master_token(),
1048 "list grants nothing that outlives the token; gating it would blind a paired client \
1049 to the trust state it is subject to"
1050 );
1051 for name in ["control.chiaPeers.add", "control.chiaPeers.remove"] {
1055 let summary = ControlMethod::from_name(name).unwrap().summary();
1056 assert!(
1057 summary.to_lowercase().contains("corroboration"),
1058 "{name} summary must name the corroboration bypass, got: {summary}"
1059 );
1060 }
1061 }
1062
1063 #[test]
1064 fn every_method_has_a_nonempty_summary() {
1065 for &m in ControlMethod::ALL {
1066 assert!(!m.summary().is_empty(), "{} has no summary", m.name());
1067 }
1068 }
1069}