Skip to content

Commit

Permalink
rename branch and fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
borngraced committed Aug 28, 2024
1 parent 4e42f2a commit 23bb925
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 89 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ authors = ["WalletConnect Team"]
license = "Apache-2.0"

[workspace]
members = ["blockchain_api", "sign_api", "relay_client", "relay_rpc"]
members = ["blockchain_api", "relay_client", "relay_rpc", "sign_api"]

[features]
default = ["full"]
full = ["client", "rpc", "http"]
full = ["client", "rpc", "http", "sign_api"]
client = ["dep:relay_client"]
http = ["relay_client/http"]
rpc = ["dep:relay_rpc"]
Expand Down
9 changes: 8 additions & 1 deletion relay_rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
use {
crate::domain::{DidKey, MessageId, SubscriptionId, Topic},
params::session::{
delete::SessionDeleteRequest, event::SessionEventRequest, extend::SessionExtendRequest, ping::SessionPingRequest, propose::SessionProposeRequest, request::SessionRequestRequest, settle::SessionSettleRequest, update::SessionUpdateRequest, RequestParams
delete::SessionDeleteRequest,
event::SessionEventRequest,
extend::SessionExtendRequest,
propose::SessionProposeRequest,
request::SessionRequestRequest,
settle::SessionSettleRequest,
update::SessionUpdateRequest,
RequestParams,
},
serde::{de::DeserializeOwned, Deserialize, Serialize},
std::{fmt::Debug, sync::Arc},
Expand Down
25 changes: 18 additions & 7 deletions relay_rpc/src/rpc/params/session.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
pub mod delete;
pub mod event;
pub mod extend;
pub mod ping;
pub mod propose;
pub mod settle;
pub mod request;
pub mod ping;
pub mod delete;
pub mod settle;
pub mod update;
pub mod extend;
pub mod event;

use {
delete::SessionDeleteRequest, event::SessionEventRequest, extend::SessionExtendRequest, paste::paste, propose::{SessionProposeRequest, SessionProposeResponse}, regex::Regex, request::SessionRequestRequest, serde::{Deserialize, Serialize}, serde_json::Value, settle::SessionSettleRequest, std::{
delete::SessionDeleteRequest,
event::SessionEventRequest,
extend::SessionExtendRequest,
paste::paste,
propose::{SessionProposeRequest, SessionProposeResponse},
regex::Regex,
request::SessionRequestRequest,
serde::{Deserialize, Serialize},
serde_json::Value,
settle::SessionSettleRequest,
std::{
collections::{BTreeMap, BTreeSet},
ops::Deref,
sync::OnceLock,
}, update::SessionUpdateRequest
},
update::SessionUpdateRequest,
};

/// https://specs.walletconnect.com/2.0/specs/clients/sign/namespaces
Expand Down
14 changes: 8 additions & 6 deletions relay_rpc/src/rpc/params/session/delete.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//! https://specs.walletconnect.com/2.0/specs/clients/sign/rpc-methods
//! #wc_sessiondelete

use super::IrnMetadata;
use serde::{Deserialize, Serialize};
use {
super::IrnMetadata,
serde::{Deserialize, Serialize},
};

pub(super) const IRN_REQUEST_METADATA: IrnMetadata = IrnMetadata {

Check failure on line 9 in relay_rpc/src/rpc/params/session/delete.rs

View workflow job for this annotation

GitHub Actions / Clippy

constant `IRN_REQUEST_METADATA` is never used

Check warning on line 9 in relay_rpc/src/rpc/params/session/delete.rs

View workflow job for this annotation

GitHub Actions / Tests

constant `IRN_REQUEST_METADATA` is never used

Check warning on line 9 in relay_rpc/src/rpc/params/session/delete.rs

View workflow job for this annotation

GitHub Actions / Documentation Tests

constant `IRN_REQUEST_METADATA` is never used
tag: 1112,
Expand All @@ -25,10 +27,10 @@ pub struct SessionDeleteRequest {

#[cfg(test)]
mod tests {
use super::*;

use super::super::tests::param_serde_test;
use anyhow::Result;
use {
super::{super::tests::param_serde_test, *},
anyhow::Result,

Check failure on line 32 in relay_rpc/src/rpc/params/session/delete.rs

View workflow job for this annotation

GitHub Actions / Clippy

unresolved import `anyhow`
};

#[test]
fn test_serde_session_delete_request() -> Result<()> {
Expand Down
15 changes: 8 additions & 7 deletions relay_rpc/src/rpc/params/session/event.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! https://specs.walletconnect.com/2.0/specs/clients/sign/rpc-methods
//! #wc_sessionevent

use serde::{Deserialize, Serialize};

use super::IrnMetadata;
use {
super::IrnMetadata,
serde::{Deserialize, Serialize},
};

pub(super) const IRN_REQUEST_METADATA: IrnMetadata = IrnMetadata {

Check failure on line 9 in relay_rpc/src/rpc/params/session/event.rs

View workflow job for this annotation

GitHub Actions / Clippy

constant `IRN_REQUEST_METADATA` is never used

Check warning on line 9 in relay_rpc/src/rpc/params/session/event.rs

View workflow job for this annotation

GitHub Actions / Tests

constant `IRN_REQUEST_METADATA` is never used

Check warning on line 9 in relay_rpc/src/rpc/params/session/event.rs

View workflow job for this annotation

GitHub Actions / Documentation Tests

constant `IRN_REQUEST_METADATA` is never used
tag: 1110,
Expand Down Expand Up @@ -36,10 +37,10 @@ pub struct SessionEventRequest {

#[cfg(test)]
mod tests {
use super::*;

use super::super::tests::param_serde_test;
use anyhow::Result;
use {
super::{super::tests::param_serde_test, *},
anyhow::Result,

Check failure on line 42 in relay_rpc/src/rpc/params/session/event.rs

View workflow job for this annotation

GitHub Actions / Clippy

unresolved import `anyhow`
};

#[test]
fn test_serde_accounts_changed_event() -> Result<()> {
Expand Down
15 changes: 8 additions & 7 deletions relay_rpc/src/rpc/params/session/extend.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! https://specs.walletconnect.com/2.0/specs/clients/sign/rpc-methods
//! #wc_sessionextend

use serde::{Deserialize, Serialize};

use super::IrnMetadata;
use {
super::IrnMetadata,
serde::{Deserialize, Serialize},
};

pub(super) const IRN_REQUEST_METADATA: IrnMetadata = IrnMetadata {

Check warning on line 9 in relay_rpc/src/rpc/params/session/extend.rs

View workflow job for this annotation

GitHub Actions / Tests

constant `IRN_REQUEST_METADATA` is never used

Check warning on line 9 in relay_rpc/src/rpc/params/session/extend.rs

View workflow job for this annotation

GitHub Actions / Documentation Tests

constant `IRN_REQUEST_METADATA` is never used
tag: 1106,
Expand All @@ -25,10 +26,10 @@ pub struct SessionExtendRequest {

#[cfg(test)]
mod tests {
use super::*;

use super::super::tests::param_serde_test;
use anyhow::Result;
use {
super::{super::tests::param_serde_test, *},
anyhow::Result,

Check failure on line 31 in relay_rpc/src/rpc/params/session/extend.rs

View workflow job for this annotation

GitHub Actions / Clippy

unresolved import `anyhow`
};

#[test]
fn test_serde_session_extend_request() -> Result<()> {
Expand Down
15 changes: 8 additions & 7 deletions relay_rpc/src/rpc/params/session/ping.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! https://specs.walletconnect.com/2.0/specs/clients/sign/rpc-methods
//! #wc_sessionping
//!
use super::IrnMetadata;
use serde::{Deserialize, Serialize};
use {
super::IrnMetadata,
serde::{Deserialize, Serialize},
};

pub(super) const IRN_REQUEST_METADATA: IrnMetadata = IrnMetadata {

Check warning on line 8 in relay_rpc/src/rpc/params/session/ping.rs

View workflow job for this annotation

GitHub Actions / Tests

constant `IRN_REQUEST_METADATA` is never used

Check warning on line 8 in relay_rpc/src/rpc/params/session/ping.rs

View workflow job for this annotation

GitHub Actions / Documentation Tests

constant `IRN_REQUEST_METADATA` is never used
tag: 1114,
Expand All @@ -22,10 +23,10 @@ pub struct SessionPingRequest {}

#[cfg(test)]
mod tests {
use super::*;

use super::super::tests::param_serde_test;
use anyhow::Result;
use {
super::{super::tests::param_serde_test, *},
anyhow::Result,

Check failure on line 28 in relay_rpc/src/rpc/params/session/ping.rs

View workflow job for this annotation

GitHub Actions / Clippy

unresolved import `anyhow`
};

#[test]
fn test_serde_session_ping_request() -> Result<()> {
Expand Down
20 changes: 11 additions & 9 deletions relay_rpc/src/rpc/params/session/request.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//! https://specs.walletconnect.com/2.0/specs/clients/sign/rpc-methods
//! #wc_sessionrequest

use super::IrnMetadata;
use serde::{Deserialize, Serialize};
use {
super::IrnMetadata,
serde::{Deserialize, Serialize},
};

pub(super) const IRN_REQUEST_METADATA: IrnMetadata = IrnMetadata {

Check warning on line 9 in relay_rpc/src/rpc/params/session/request.rs

View workflow job for this annotation

GitHub Actions / Tests

constant `IRN_REQUEST_METADATA` is never used

Check warning on line 9 in relay_rpc/src/rpc/params/session/request.rs

View workflow job for this annotation

GitHub Actions / Documentation Tests

constant `IRN_REQUEST_METADATA` is never used
tag: 1108,
Expand All @@ -19,13 +21,13 @@ pub(super) const IRN_RESPONSE_METADATA: IrnMetadata = IrnMetadata {
#[derive(Debug, Serialize, PartialEq, Eq, Hash, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Request {
pub method: String,
pub method: String,
/// Opaque blockchain RPC parameters.
///
/// Parsing is deferred to a higher level, blockchain RPC aware code.
pub params: serde_json::Value,
pub params: serde_json::Value,
#[serde(skip_serializing_if = "Option::is_none")]
pub expiry: Option<u64>,
pub expiry: Option<u64>,
}

#[derive(Debug, Serialize, PartialEq, Eq, Hash, Deserialize, Clone)]
Expand All @@ -37,10 +39,10 @@ pub struct SessionRequestRequest {

#[cfg(test)]
mod tests {
use super::*;

use super::super::tests::param_serde_test;
use anyhow::Result;
use {
super::{super::tests::param_serde_test, *},
anyhow::Result,

Check failure on line 44 in relay_rpc/src/rpc/params/session/request.rs

View workflow job for this annotation

GitHub Actions / Clippy

unresolved import `anyhow`
};

#[test]
fn test_serde_eth_sign_transaction() -> Result<()> {
Expand Down
14 changes: 8 additions & 6 deletions relay_rpc/src/rpc/params/session/update.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//! https://specs.walletconnect.com/2.0/specs/clients/sign/rpc-methods
//! #wc_sessionupdate

use super::{IrnMetadata, SettleNamespaces};
use serde::{Deserialize, Serialize};
use {
super::{IrnMetadata, SettleNamespaces},
serde::{Deserialize, Serialize},
};

pub(super) const IRN_REQUEST_METADATA: IrnMetadata = IrnMetadata {

Check warning on line 9 in relay_rpc/src/rpc/params/session/update.rs

View workflow job for this annotation

GitHub Actions / Tests

constant `IRN_REQUEST_METADATA` is never used

Check warning on line 9 in relay_rpc/src/rpc/params/session/update.rs

View workflow job for this annotation

GitHub Actions / Documentation Tests

constant `IRN_REQUEST_METADATA` is never used
tag: 1104,
Expand All @@ -24,10 +26,10 @@ pub struct SessionUpdateRequest {

#[cfg(test)]
mod tests {
use super::*;

use super::super::tests::param_serde_test;
use anyhow::Result;
use {
super::{super::tests::param_serde_test, *},
anyhow::Result,

Check failure on line 31 in relay_rpc/src/rpc/params/session/update.rs

View workflow job for this annotation

GitHub Actions / Clippy

unresolved import `anyhow`
};

#[test]
fn test_serde_session_update_request() -> Result<()> {
Expand Down
76 changes: 40 additions & 36 deletions sign_api/examples/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,17 @@ use {
rpc::{
params::{
session::{
delete::SessionDeleteRequest, propose::{SessionProposeRequest, SessionProposeResponse}, settle::{Controller, SessionSettleRequest}, IrnMetadata, ProposeNamespace, ProposeNamespaces, RelayProtocolMetadata, RequestParams, ResponseParamsSuccess, SettleNamespace, SettleNamespaces
delete::SessionDeleteRequest,
propose::{SessionProposeRequest, SessionProposeResponse},
settle::{Controller, SessionSettleRequest},
IrnMetadata,
ProposeNamespace,
ProposeNamespaces,
RelayProtocolMetadata,
RequestParams,
ResponseParamsSuccess,
SettleNamespace,
SettleNamespaces,
},
Metadata,
Relay,
Expand Down Expand Up @@ -213,8 +223,8 @@ async fn process_proposal_request(
Ok(create_proposal_response(responder_public_key))
}

fn process_session_delete_request(delete_params: SessionDeleteRequest) ->
ResponseParamsSuccess { println!(
fn process_session_delete_request(delete_params: SessionDeleteRequest) -> ResponseParamsSuccess {
println!(
"\nSession is being terminated reason={}, code={}",
delete_params.message, delete_params.code,
);
Expand Down Expand Up @@ -439,39 +449,33 @@ impl Context {
}

/// Deletes session identified by the `topic`.
///
/// When session count reaches zero, unsubscribes from topic and sends
/// termination signal to end the application execution.
///
/// TODO: should really delete pairing as well:
/// https://specs.walletconnect.com/2.0/specs/clients/core/pairing/
/// rpc-methods#wc_pairingdelete
async fn session_delete_cleanup(&mut self, topic: Topic) -> Result<()> {
let _session = self
.sessions
.remove(&topic)
.ok_or_else(|| anyhow::anyhow!("Attempt to remove non-existing session"))?;

self.client
.unsubscribe(topic)
.await?;

// Un-pair when there are no more session subscriptions.
// TODO: Delete pairing, not just unsubscribe.
if self.sessions.is_empty() {
println!("\nNo active sessions left, terminating the pairing");

self.client
.unsubscribe(
self.pairing.topic.clone(),
)
.await?;

self.pairing.terminator.send(()).await?;
}

Ok(())
}
///
/// When session count reaches zero, unsubscribes from topic and sends
/// termination signal to end the application execution.
///
/// TODO: should really delete pairing as well:
/// https://specs.walletconnect.com/2.0/specs/clients/core/pairing/
/// rpc-methods#wc_pairingdelete
async fn session_delete_cleanup(&mut self, topic: Topic) -> Result<()> {
let _session = self
.sessions
.remove(&topic)
.ok_or_else(|| anyhow::anyhow!("Attempt to remove non-existing session"))?;

self.client.unsubscribe(topic).await?;

// Un-pair when there are no more session subscriptions.
// TODO: Delete pairing, not just unsubscribe.
if self.sessions.is_empty() {
println!("\nNo active sessions left, terminating the pairing");

self.client.unsubscribe(self.pairing.topic.clone()).await?;

self.pairing.terminator.send(()).await?;
}

Ok(())
}
}

#[tokio::main]
Expand Down
6 changes: 5 additions & 1 deletion sign_api/src/pairing_uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
// pairing is considered expired, should be generated 5 minutes in the future

use {
lazy_static::lazy_static, regex::Regex, relay_rpc::domain::Topic, std::{collections::HashMap, str::FromStr}, thiserror::Error, url::Url
lazy_static::lazy_static,
regex::Regex,
std::{collections::HashMap, str::FromStr},
thiserror::Error,
url::Url,
};

lazy_static! {
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
pub use relay_client as client;
#[cfg(feature = "rpc")]
pub use relay_rpc as rpc;
#[cfg(feature = "sign_api")]
pub use sign_api;

0 comments on commit 23bb925

Please sign in to comment.