Skip to content

Commit ad4a145

Browse files
authored
feat: watch register behalf (#41)
1 parent 5f4dd3c commit ad4a145

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fmt:
6666

6767
if command -v cargo-fmt >/dev/null; then
6868
echo '==> Running rustfmt'
69-
cargo +nightly fmt --all -- --check
69+
cargo +nightly fmt --all
7070
else
7171
echo '==> rustfmt not found in PATH, skipping'
7272
echo ' ^^^^^^ To install `rustup component add rustfmt`, see https://github.com/rust-lang/rustfmt for details'

relay_client/src/http.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ pub enum HttpClientError {
3636
#[error("Invalid response")]
3737
InvalidResponse,
3838

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

4242
#[error("JWT error: {0}")]
4343
Jwt(#[from] JwtError),
@@ -187,6 +187,14 @@ impl Client {
187187
self.request(payload).await
188188
}
189189

190+
/// Registers a webhook to watch messages on behalf of another client.
191+
pub async fn watch_register_behalf(
192+
&self,
193+
register_auth: String,
194+
) -> Response<rpc::WatchRegister> {
195+
self.request(rpc::WatchRegister { register_auth }).await
196+
}
197+
190198
/// Unregisters a webhook to watch messages.
191199
pub async fn watch_unregister(
192200
&self,
@@ -280,7 +288,8 @@ impl Client {
280288
let status = result.status();
281289

282290
if !status.is_success() {
283-
return Err(HttpClientError::InvalidHttpCode(status).into());
291+
let body = result.text().await;
292+
return Err(HttpClientError::InvalidHttpCode(status, body).into());
284293
}
285294

286295
let response = result

relay_rpc/src/rpc/msg_id.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,17 @@ pub trait MsgId {
99

1010
impl MsgId for rpc::Publish {
1111
fn msg_id(&self) -> String {
12-
let msg_id = Sha256::new()
13-
.chain_update(self.message.as_ref().as_bytes())
14-
.finalize();
15-
format!("{msg_id:x}")
12+
get_message_id(&self.message)
1613
}
1714
}
1815

1916
impl MsgId for rpc::Subscription {
2017
fn msg_id(&self) -> String {
21-
let msg_id = Sha256::new()
22-
.chain_update(self.data.message.as_ref().as_bytes())
23-
.finalize();
24-
format!("{msg_id:x}")
18+
get_message_id(&self.data.message)
2519
}
2620
}
21+
22+
pub fn get_message_id(message: &str) -> String {
23+
let msg_id = Sha256::new().chain_update(message.as_bytes()).finalize();
24+
format!("{msg_id:x}")
25+
}

0 commit comments

Comments
 (0)