Skip to content

Commit 54b172d

Browse files
authored
Update sudo_network_unstable_watch to latest JSON-RPC draft (#1597)
* Update `sudo_network_unstable_watch` to latest JSON-RPC draft * Rustfmt
1 parent 37a2393 commit 54b172d

File tree

3 files changed

+46
-89
lines changed

3 files changed

+46
-89
lines changed

lib/src/json_rpc/methods.rs

+35-74
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,8 @@ define_methods! {
504504
// These functions are a custom addition in smoldot. As of the writing of this comment, there
505505
// is no plan to standardize them. See <https://github.com/paritytech/smoldot/issues/2245> and
506506
// <https://github.com/paritytech/smoldot/issues/2456>.
507-
network_unstable_subscribeEvents() -> Cow<'a, str>,
508-
network_unstable_unsubscribeEvents(subscription: Cow<'a, str>) -> (),
507+
sudo_network_unstable_watch() -> Cow<'a, str>,
508+
sudo_network_unstable_unwatch(subscription: Cow<'a, str>) -> (),
509509
chainHead_unstable_finalizedDatabase(#[rename = "maxSizeBytes"] max_size_bytes: Option<u64>) -> Cow<'a, str>,
510510
}
511511

@@ -525,7 +525,7 @@ define_methods! {
525525

526526
// This function is a custom addition in smoldot. As of the writing of this comment, there is
527527
// no plan to standardize it. See https://github.com/paritytech/smoldot/issues/2245.
528-
network_unstable_event(subscription: Cow<'a, str>, result: NetworkEvent<'a>) -> (),
528+
sudo_networkState_event(subscription: Cow<'a, str>, result: NetworkEvent) -> (),
529529
}
530530

531531
#[derive(Clone, PartialEq, Eq, Hash)]
@@ -849,90 +849,51 @@ pub struct TransactionWatchEventBlock {
849849
/// See <https://github.com/paritytech/smoldot/issues/2245>.
850850
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
851851
#[serde(tag = "event")]
852-
pub enum NetworkEvent<'a> {
853-
#[serde(rename = "startConnect")]
854-
StartConnect {
855-
when: u64,
856-
#[serde(rename = "connectionId")]
857-
connection_id: u32,
858-
multiaddr: Cow<'a, str>,
859-
},
860-
#[serde(rename = "connected")]
861-
Connected {
862-
when: u64,
852+
pub enum NetworkEvent {
853+
#[serde(rename = "connectionState")]
854+
ConnectionState {
863855
#[serde(rename = "connectionId")]
864856
connection_id: u32,
865-
},
866-
#[serde(rename = "handshakeFinished")]
867-
HandshakeFinished {
857+
#[serde(rename = "targetPeerId", skip_serializing_if = "Option::is_none")]
858+
target_peer_id: Option<String>,
859+
#[serde(rename = "targetMultiaddr")]
860+
target_multiaddr: String,
861+
status: NetworkEventStatus,
862+
direction: NetworkEventDirection,
868863
when: u64,
869-
#[serde(rename = "connectionId")]
870-
connection_id: u32,
871-
#[serde(rename = "peerId")]
872-
peer_id: Cow<'a, str>,
873864
},
874-
#[serde(rename = "stop")]
875-
Stop {
876-
when: u64,
877-
#[serde(rename = "connectionId")]
878-
connection_id: u32,
879-
reason: Cow<'a, str>,
880-
},
881-
#[serde(rename = "out-slot-assign")]
882-
OutSlotAssign {
883-
when: u64,
884-
#[serde(rename = "peerId")]
885-
peer_id: Cow<'a, str>,
886-
},
887-
#[serde(rename = "out-slot-unassign")]
888-
OutSlotUnassign {
889-
when: u64,
890-
#[serde(rename = "peerId")]
891-
peer_id: Cow<'a, str>,
892-
},
893-
#[serde(rename = "in-slot-assign")]
894-
InSlotAssign {
895-
when: u64,
896-
#[serde(rename = "peerId")]
897-
peer_id: Cow<'a, str>,
898-
},
899-
#[serde(rename = "in-slot-unassign")]
900-
InSlotUnassign {
901-
when: u64,
902-
#[serde(rename = "peerId")]
903-
peer_id: Cow<'a, str>,
904-
},
905-
#[serde(rename = "in-slot-to-out-slot")]
906-
InSlotToOutSlot {
907-
when: u64,
908-
#[serde(rename = "peerId")]
909-
peer_id: Cow<'a, str>,
910-
},
911-
#[serde(rename = "substream-out-open")]
912-
SubstreamOutOpen {
913-
when: u64,
865+
#[serde(rename = "substreamState")]
866+
SubstreamState {
914867
#[serde(rename = "connectionId")]
915868
connection_id: u32,
916869
#[serde(rename = "substreamId")]
917870
substream_id: u32,
871+
status: NetworkEventStatus,
918872
#[serde(rename = "protocolName")]
919-
protocol_name: Cow<'a, str>,
920-
},
921-
#[serde(rename = "substream-out-accept")]
922-
SubstreamOutAccept {
923-
when: u64,
924-
#[serde(rename = "substreamId")]
925-
substream_id: u32,
926-
},
927-
#[serde(rename = "substream-out-stop")]
928-
SubstreamOutStop {
873+
protocol_name: String,
874+
direction: NetworkEventDirection,
929875
when: u64,
930-
#[serde(rename = "substreamId")]
931-
substream_id: u32,
932-
reason: Cow<'a, str>,
933876
},
934877
}
935878

879+
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
880+
pub enum NetworkEventStatus {
881+
#[serde(rename = "connecting")]
882+
Connecting,
883+
#[serde(rename = "open")]
884+
Open,
885+
#[serde(rename = "closed")]
886+
Close,
887+
}
888+
889+
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
890+
pub enum NetworkEventDirection {
891+
#[serde(rename = "in")]
892+
In,
893+
#[serde(rename = "out")]
894+
Out,
895+
}
896+
936897
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
937898
pub struct Header {
938899
#[serde(rename = "parentHash")]

lib/src/json_rpc/service/client_main_task.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ impl ClientMainTask {
471471
| methods::MethodCall::state_subscribeRuntimeVersion { .. }
472472
| methods::MethodCall::state_subscribeStorage { .. }
473473
| methods::MethodCall::transaction_unstable_submitAndWatch { .. }
474-
| methods::MethodCall::network_unstable_subscribeEvents { .. }
474+
| methods::MethodCall::sudo_network_unstable_watch { .. }
475475
| methods::MethodCall::chainHead_unstable_follow { .. } => {
476476
// Subscription starting requests.
477477

@@ -541,9 +541,7 @@ impl ClientMainTask {
541541
| methods::MethodCall::state_unsubscribeRuntimeVersion { subscription, .. }
542542
| methods::MethodCall::state_unsubscribeStorage { subscription, .. }
543543
| methods::MethodCall::transaction_unstable_unwatch { subscription, .. }
544-
| methods::MethodCall::network_unstable_unsubscribeEvents {
545-
subscription, ..
546-
}
544+
| methods::MethodCall::sudo_network_unstable_unwatch { subscription, .. }
547545
| methods::MethodCall::chainHead_unstable_unfollow {
548546
follow_subscription: subscription,
549547
..
@@ -568,9 +566,9 @@ impl ClientMainTask {
568566
methods::MethodCall::transaction_unstable_unwatch {
569567
..
570568
} => methods::Response::transaction_unstable_unwatch(()),
571-
methods::MethodCall::network_unstable_unsubscribeEvents {
569+
methods::MethodCall::sudo_network_unstable_unwatch {
572570
..
573-
} => methods::Response::network_unstable_unsubscribeEvents(()),
571+
} => methods::Response::sudo_network_unstable_unwatch(()),
574572
methods::MethodCall::chainHead_unstable_unfollow { .. } => {
575573
methods::Response::chainHead_unstable_unfollow(())
576574
}
@@ -1164,10 +1162,8 @@ impl SubscriptionStartProcess {
11641162
&self.subscription_id,
11651163
))
11661164
}
1167-
methods::MethodCall::network_unstable_subscribeEvents { .. } => {
1168-
methods::Response::network_unstable_subscribeEvents(Cow::Borrowed(
1169-
&self.subscription_id,
1170-
))
1165+
methods::MethodCall::sudo_network_unstable_watch { .. } => {
1166+
methods::Response::sudo_network_unstable_watch(Cow::Borrowed(&self.subscription_id))
11711167
}
11721168
methods::MethodCall::chainHead_unstable_follow { .. } => {
11731169
methods::Response::chainHead_unstable_follow(Cow::Borrowed(&self.subscription_id))

light-base/src/json_rpc_service/background.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,8 @@ impl<TPlat: PlatformRef> Background<TPlat> {
358358
| methods::MethodCall::sudo_unstable_version { .. }
359359
| methods::MethodCall::transaction_unstable_submitAndWatch { .. }
360360
| methods::MethodCall::transaction_unstable_unwatch { .. }
361-
| methods::MethodCall::network_unstable_subscribeEvents { .. }
362-
| methods::MethodCall::network_unstable_unsubscribeEvents { .. }
361+
| methods::MethodCall::sudo_network_unstable_watch { .. }
362+
| methods::MethodCall::sudo_network_unstable_unwatch { .. }
363363
| methods::MethodCall::chainHead_unstable_finalizedDatabase { .. } => {}
364364
}
365365

@@ -629,8 +629,8 @@ impl<TPlat: PlatformRef> Background<TPlat> {
629629
| methods::MethodCall::sudo_unstable_version { .. }
630630
| methods::MethodCall::transaction_unstable_submitAndWatch { .. }
631631
| methods::MethodCall::transaction_unstable_unwatch { .. }
632-
| methods::MethodCall::network_unstable_subscribeEvents { .. }
633-
| methods::MethodCall::network_unstable_unsubscribeEvents { .. }
632+
| methods::MethodCall::sudo_network_unstable_watch { .. }
633+
| methods::MethodCall::sudo_network_unstable_unwatch { .. }
634634
| methods::MethodCall::chainHead_unstable_finalizedDatabase { .. } => {}
635635
}
636636

@@ -654,7 +654,7 @@ impl<TPlat: PlatformRef> Background<TPlat> {
654654
self.submit_and_watch_transaction(request).await
655655
}
656656

657-
_method @ methods::MethodCall::network_unstable_subscribeEvents { .. } => {
657+
_method @ methods::MethodCall::sudo_network_unstable_watch { .. } => {
658658
// TODO: implement the ones that make sense to implement ^
659659
log!(
660660
&self.platform,

0 commit comments

Comments
 (0)