Skip to content

Commit

Permalink
feat: watch register behalf (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris13524 authored Aug 18, 2023
1 parent 5f4dd3c commit ad4a145
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fmt:

if command -v cargo-fmt >/dev/null; then
echo '==> Running rustfmt'
cargo +nightly fmt --all -- --check
cargo +nightly fmt --all
else
echo '==> rustfmt not found in PATH, skipping'
echo ' ^^^^^^ To install `rustup component add rustfmt`, see https://github.com/rust-lang/rustfmt for details'
Expand Down
15 changes: 12 additions & 3 deletions relay_client/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ pub enum HttpClientError {
#[error("Invalid response")]
InvalidResponse,

#[error("Invalid HTTP status: {0}")]
InvalidHttpCode(StatusCode),
#[error("Invalid HTTP status: {0}, body: {1:?}")]
InvalidHttpCode(StatusCode, reqwest::Result<String>),

#[error("JWT error: {0}")]
Jwt(#[from] JwtError),
Expand Down Expand Up @@ -187,6 +187,14 @@ impl Client {
self.request(payload).await
}

/// Registers a webhook to watch messages on behalf of another client.
pub async fn watch_register_behalf(
&self,
register_auth: String,
) -> Response<rpc::WatchRegister> {
self.request(rpc::WatchRegister { register_auth }).await
}

/// Unregisters a webhook to watch messages.
pub async fn watch_unregister(
&self,
Expand Down Expand Up @@ -280,7 +288,8 @@ impl Client {
let status = result.status();

if !status.is_success() {
return Err(HttpClientError::InvalidHttpCode(status).into());
let body = result.text().await;
return Err(HttpClientError::InvalidHttpCode(status, body).into());
}

let response = result
Expand Down
15 changes: 7 additions & 8 deletions relay_rpc/src/rpc/msg_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@ pub trait MsgId {

impl MsgId for rpc::Publish {
fn msg_id(&self) -> String {
let msg_id = Sha256::new()
.chain_update(self.message.as_ref().as_bytes())
.finalize();
format!("{msg_id:x}")
get_message_id(&self.message)
}
}

impl MsgId for rpc::Subscription {
fn msg_id(&self) -> String {
let msg_id = Sha256::new()
.chain_update(self.data.message.as_ref().as_bytes())
.finalize();
format!("{msg_id:x}")
get_message_id(&self.data.message)
}
}

pub fn get_message_id(message: &str) -> String {
let msg_id = Sha256::new().chain_update(message.as_bytes()).finalize();
format!("{msg_id:x}")
}

0 comments on commit ad4a145

Please sign in to comment.