Skip to content

Commit

Permalink
feat: add tag field to subscription data struct (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rakowskiii authored Feb 28, 2023
1 parent 87c2a08 commit 918b8c5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions relay_rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ impl Publish {
topic: self.topic.clone(),
message: self.message.clone(),
published_at,
tag: self.tag,
},
}),
}
Expand Down Expand Up @@ -530,6 +531,10 @@ pub struct SubscriptionData {

/// Message publish timestamp in UTC milliseconds.
pub published_at: i64,

/// A label that identifies what type of message is sent based on the RPC
/// method used.
pub tag: u32,
}

/// Enum representing parameters of all possible RPC requests.
Expand Down
8 changes: 6 additions & 2 deletions relay_rpc/src/rpc/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ fn subscription() {
topic: "test_topic".into(),
message: "test_message".into(),
published_at: 123,
tag: 1000,
};
let params = Subscription {
id: "test_id".into(),
Expand All @@ -103,7 +104,7 @@ fn subscription() {

assert_eq!(
&serialized,
r#"{"id":1,"jsonrpc":"2.0","method":"irn_subscription","params":{"id":"test_id","data":{"topic":"test_topic","message":"test_message","publishedAt":123}}}"#
r#"{"id":1,"jsonrpc":"2.0","method":"irn_subscription","params":{"id":"test_id","data":{"topic":"test_topic","message":"test_message","publishedAt":123,"tag":1000}}}"#
);

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

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

Expand Down Expand Up @@ -303,6 +304,7 @@ fn validation() {
topic: topic.clone(),
message: message.clone(),
published_at: 123,
tag: 1000,
},
}),
};
Expand All @@ -318,6 +320,7 @@ fn validation() {
topic: topic.clone(),
message: message.clone(),
published_at: 123,
tag: 1000,
},
}),
};
Expand All @@ -338,6 +341,7 @@ fn validation() {
topic: Topic::from("invalid"),
message,
published_at: 123,
tag: 1000,
},
}),
};
Expand Down

0 comments on commit 918b8c5

Please sign in to comment.