Skip to content

Commit 0009cea

Browse files
committed
feat: message timestamp in subscription payload
2 parents 64ba9c3 + 0ed6b74 commit 0009cea

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

.github/pull_request_template.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Description
2+
3+
<!--
4+
Please include:
5+
* summary of the changes and the related issue
6+
* relevant motivation and context
7+
-->
8+
9+
Resolves # (issue)
10+
11+
## How Has This Been Tested?
12+
13+
<!--
14+
Please:
15+
* describe the tests that you ran to verify your changes.
16+
* provide instructions so we can reproduce.
17+
-->
18+
19+
<!-- If valid for smoke test on feature add screenshots -->
20+
21+
## Due Diligence
22+
23+
* [ ] Breaking change
24+
* [ ] Requires a documentation update
25+
* [ ] Requires a e2e/integration test update

relay_rpc/src/rpc.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ impl Publish {
443443
&self,
444444
message_id: MessageId,
445445
subscription_id: SubscriptionId,
446+
published_at: i64,
446447
) -> Request {
447448
Request {
448449
id: message_id,
@@ -452,6 +453,7 @@ impl Publish {
452453
data: SubscriptionData {
453454
topic: self.topic.clone(),
454455
message: self.message.clone(),
456+
published_at,
455457
},
456458
}),
457459
}
@@ -542,12 +544,16 @@ impl RequestPayload for Subscription {
542544

543545
/// Data structure representing subscription message params.
544546
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
547+
#[serde(rename_all = "camelCase")]
545548
pub struct SubscriptionData {
546549
/// The topic of the subscription.
547550
pub topic: Topic,
548551

549552
/// The message for the subscription.
550553
pub message: Arc<str>,
554+
555+
/// Message publish timestamp in UTC milliseconds.
556+
pub published_at: i64,
551557
}
552558

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

relay_rpc/src/rpc/tests.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ fn subscription() {
9191
let data = SubscriptionData {
9292
topic: "test_topic".into(),
9393
message: "test_message".into(),
94+
published_at: 123,
9495
};
9596
let params = Subscription {
9697
id: "test_id".into(),
@@ -102,7 +103,7 @@ fn subscription() {
102103

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

108109
let deserialized: Payload = serde_json::from_str(&serialized).unwrap();
@@ -112,7 +113,7 @@ fn subscription() {
112113

113114
#[test]
114115
fn deserialize_iridium_method() {
115-
let serialized = r#"{"id":1,"jsonrpc":"2.0","method":"iridium_subscription","params":{"id":"test_id","data":{"topic":"test_topic","message":"test_message"}}}"#;
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}}}"#;
116117
assert!(serde_json::from_str::<'_, Payload>(serialized).is_ok());
117118
}
118119

@@ -315,6 +316,7 @@ fn validation() {
315316
data: SubscriptionData {
316317
topic: topic.clone(),
317318
message: message.clone(),
319+
published_at: 123,
318320
},
319321
}),
320322
};
@@ -329,6 +331,7 @@ fn validation() {
329331
data: SubscriptionData {
330332
topic: topic.clone(),
331333
message: message.clone(),
334+
published_at: 123,
332335
},
333336
}),
334337
};
@@ -348,6 +351,7 @@ fn validation() {
348351
data: SubscriptionData {
349352
topic: Topic::from("invalid"),
350353
message,
354+
published_at: 123,
351355
},
352356
}),
353357
};
@@ -365,6 +369,7 @@ fn validation() {
365369
data: SubscriptionData {
366370
topic: topic.clone(),
367371
message: "0".repeat(MAX_MESSAGE_LENGTH + 1).into(),
372+
published_at: 123,
368373
},
369374
}),
370375
};

0 commit comments

Comments
 (0)