Skip to content

Commit 918b8c5

Browse files
authored
feat: add tag field to subscription data struct (#6)
1 parent 87c2a08 commit 918b8c5

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

relay_rpc/src/rpc.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ impl Publish {
438438
topic: self.topic.clone(),
439439
message: self.message.clone(),
440440
published_at,
441+
tag: self.tag,
441442
},
442443
}),
443444
}
@@ -530,6 +531,10 @@ pub struct SubscriptionData {
530531

531532
/// Message publish timestamp in UTC milliseconds.
532533
pub published_at: i64,
534+
535+
/// A label that identifies what type of message is sent based on the RPC
536+
/// method used.
537+
pub tag: u32,
533538
}
534539

535540
/// Enum representing parameters of all possible RPC requests.

relay_rpc/src/rpc/tests.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ fn subscription() {
9292
topic: "test_topic".into(),
9393
message: "test_message".into(),
9494
published_at: 123,
95+
tag: 1000,
9596
};
9697
let params = Subscription {
9798
id: "test_id".into(),
@@ -103,7 +104,7 @@ fn subscription() {
103104

104105
assert_eq!(
105106
&serialized,
106-
r#"{"id":1,"jsonrpc":"2.0","method":"irn_subscription","params":{"id":"test_id","data":{"topic":"test_topic","message":"test_message","publishedAt":123}}}"#
107+
r#"{"id":1,"jsonrpc":"2.0","method":"irn_subscription","params":{"id":"test_id","data":{"topic":"test_topic","message":"test_message","publishedAt":123,"tag":1000}}}"#
107108
);
108109

109110
let deserialized: Payload = serde_json::from_str(&serialized).unwrap();
@@ -113,7 +114,7 @@ fn subscription() {
113114

114115
#[test]
115116
fn deserialize_iridium_method() {
116-
let serialized = r#"{"id":1,"jsonrpc":"2.0","method":"iridium_subscription","params":{"id":"test_id","data":{"topic":"test_topic","message":"test_message","publishedAt":123}}}"#;
117+
let serialized = r#"{"id":1,"jsonrpc":"2.0","method":"iridium_subscription","params":{"id":"test_id","data":{"topic":"test_topic","message":"test_message","publishedAt":123,"tag":1000}}}"#;
117118
assert!(serde_json::from_str::<'_, Payload>(serialized).is_ok());
118119
}
119120

@@ -303,6 +304,7 @@ fn validation() {
303304
topic: topic.clone(),
304305
message: message.clone(),
305306
published_at: 123,
307+
tag: 1000,
306308
},
307309
}),
308310
};
@@ -318,6 +320,7 @@ fn validation() {
318320
topic: topic.clone(),
319321
message: message.clone(),
320322
published_at: 123,
323+
tag: 1000,
321324
},
322325
}),
323326
};
@@ -338,6 +341,7 @@ fn validation() {
338341
topic: Topic::from("invalid"),
339342
message,
340343
published_at: 123,
344+
tag: 1000,
341345
},
342346
}),
343347
};

0 commit comments

Comments
 (0)