Skip to content

Commit

Permalink
fix: remove old block param (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
heilhead authored Mar 11, 2024
1 parent 7664418 commit 243ca2d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 42 deletions.
7 changes: 1 addition & 6 deletions relay_client/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,7 @@ impl Client {
/// Subscribes on topic to receive messages. The request is resolved
/// optimistically as soon as the relay receives it.
pub async fn subscribe(&self, topic: Topic) -> Response<rpc::Subscribe> {
self.request(rpc::Subscribe {
topic,
block: false,
})
.await
self.request(rpc::Subscribe { topic }).await
}

/// Subscribes on topic to receive messages. The request is resolved only
Expand Down Expand Up @@ -245,7 +241,6 @@ impl Client {
) -> Response<rpc::BatchSubscribe> {
self.request(rpc::BatchSubscribe {
topics: topics.into(),
block: false,
})
.await
}
Expand Down
15 changes: 4 additions & 11 deletions relay_client/src/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ pub trait ConnectionHandler: Send + 'static {
fn outbound_error(&mut self, _error: ClientError) {}
}

type SubscriptionResult<T> = Result<T, Error<SubscriptionError>>;

/// The Relay WebSocket RPC client.
///
/// This provides the high-level access to all of the available RPC methods. For
Expand Down Expand Up @@ -174,10 +176,7 @@ impl Client {
/// Subscribes on topic to receive messages. The request is resolved
/// optimistically as soon as the relay receives it.
pub fn subscribe(&self, topic: Topic) -> ResponseFuture<Subscribe> {
let (request, response) = create_request(Subscribe {
topic,
block: false,
});
let (request, response) = create_request(Subscribe { topic });

self.request(request);

Expand Down Expand Up @@ -224,7 +223,6 @@ impl Client {
pub fn batch_subscribe(&self, topics: impl Into<Vec<Topic>>) -> ResponseFuture<BatchSubscribe> {
let (request, response) = create_request(BatchSubscribe {
topics: topics.into(),
block: false,
});

self.request(request);
Expand All @@ -239,12 +237,7 @@ impl Client {
pub fn batch_subscribe_blocking(
&self,
topics: impl Into<Vec<Topic>>,
) -> impl Future<
Output = Result<
Vec<Result<SubscriptionId, Error<SubscriptionError>>>,
Error<SubscriptionError>,
>,
> {
) -> impl Future<Output = SubscriptionResult<Vec<SubscriptionResult<SubscriptionId>>>> {
let (request, response) = create_request(BatchSubscribeBlocking {
topics: topics.into(),
});
Expand Down
10 changes: 0 additions & 10 deletions relay_rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,6 @@ pub enum SubscriptionError {
pub struct Subscribe {
/// The topic to subscribe to.
pub topic: Topic,

/// Whether to disable optimistic response. By default optimistic response
/// is enabled.
#[serde(default)]
pub block: bool,
}

impl ServiceRequest for Subscribe {
Expand Down Expand Up @@ -347,11 +342,6 @@ pub struct FetchResponse {
pub struct BatchSubscribe {
/// The topics to subscribe to.
pub topics: Vec<Topic>,

/// Whether to disable optimistic response. By default optimistic response
/// is enabled.
#[serde(default)]
pub block: bool,
}

impl BatchSubscribe {
Expand Down
18 changes: 3 additions & 15 deletions relay_rpc/src/rpc/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@ fn subscribe() {
1659980684711969.into(),
Params::Subscribe(Subscribe {
topic: "c4163cf65859106b3f5435fc296e7765411178ed452d1c30337a6230138c9840".into(),
block: false,
}),
));

let serialized = serde_json::to_string(&payload).unwrap();

assert_eq!(
&serialized,
r#"{"id":1659980684711969,"jsonrpc":"2.0","method":"irn_subscribe","params":{"topic":"c4163cf65859106b3f5435fc296e7765411178ed452d1c30337a6230138c9840","block":false}}"#
r#"{"id":1659980684711969,"jsonrpc":"2.0","method":"irn_subscribe","params":{"topic":"c4163cf65859106b3f5435fc296e7765411178ed452d1c30337a6230138c9840"}}"#
);

let deserialized: Payload = serde_json::from_str(&serialized).unwrap();
Expand Down Expand Up @@ -208,7 +207,6 @@ fn deserialize_batch_methods() {
Topic::from("c4163cf65859106b3f5435fc296e7765411178ed452d1c30337a6230138c9840"),
Topic::from("c4163cf65859106b3f5435fc296e7765411178ed452d1c30337a6230138c9841")
],
block: false
})
})
);
Expand Down Expand Up @@ -346,7 +344,6 @@ fn validation() {
jsonrpc: jsonrpc.clone(),
params: Params::Subscribe(Subscribe {
topic: topic.clone(),
block: false,
}),
};
assert_eq!(request.validate(), Ok(()));
Expand All @@ -357,7 +354,6 @@ fn validation() {
jsonrpc: jsonrpc.clone(),
params: Params::Subscribe(Subscribe {
topic: Topic::from("invalid"),
block: false,
}),
};
assert_eq!(request.validate(), Err(PayloadError::InvalidTopic));
Expand Down Expand Up @@ -456,7 +452,6 @@ fn validation() {
jsonrpc: jsonrpc.clone(),
params: Params::BatchSubscribe(BatchSubscribe {
topics: vec![topic.clone()],
block: false,
}),
};
assert_eq!(request.validate(), Ok(()));
Expand All @@ -465,10 +460,7 @@ fn validation() {
let request = Request {
id,
jsonrpc: jsonrpc.clone(),
params: Params::BatchSubscribe(BatchSubscribe {
topics: vec![],
block: false,
}),
params: Params::BatchSubscribe(BatchSubscribe { topics: vec![] }),
};
assert_eq!(request.validate(), Err(PayloadError::BatchEmpty));

Expand All @@ -479,10 +471,7 @@ fn validation() {
let request = Request {
id,
jsonrpc: jsonrpc.clone(),
params: Params::BatchSubscribe(BatchSubscribe {
topics,
block: false,
}),
params: Params::BatchSubscribe(BatchSubscribe { topics }),
};
assert_eq!(request.validate(), Err(PayloadError::BatchLimitExceeded));

Expand All @@ -494,7 +483,6 @@ fn validation() {
topics: vec![Topic::from(
"c4163cf65859106b3f5435fc296e7765411178ed452d1c30337a6230138c98401",
)],
block: false,
}),
};
assert_eq!(request.validate(), Err(PayloadError::InvalidTopic));
Expand Down

0 comments on commit 243ca2d

Please sign in to comment.