forked from jl777/SuperNET
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
save dev state - implement wc rpc commands
- Loading branch information
1 parent
6135665
commit 5457d80
Showing
19 changed files
with
202 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
mm2src/kdf_walletconnect/src/rpc_commands/delete_connection.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use mm2_core::mm_ctx::MmArc; | ||
use mm2_err_handle::prelude::MmResult; | ||
use relay_rpc::domain::Topic; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::{error::WalletConnectCtxError, session::delete::send_session_delete_request, WalletConnectCtx}; | ||
|
||
#[derive(Debug, PartialEq, Serialize)] | ||
pub struct DeleteConnectionResponse { | ||
pub successful: bool, | ||
} | ||
|
||
#[derive(Deserialize)] | ||
pub struct DeleteConnectionRequest { | ||
topic: Topic, | ||
} | ||
|
||
/// `delete connection` RPC command implementation. | ||
pub async fn delete_connection( | ||
ctx: MmArc, | ||
req: DeleteConnectionRequest, | ||
) -> MmResult<DeleteConnectionResponse, WalletConnectCtxError> { | ||
let ctx = WalletConnectCtx::try_from_ctx_or_initialize(&ctx)?; | ||
send_session_delete_request(&ctx, &req.topic).await?; | ||
|
||
Ok(DeleteConnectionResponse { successful: true }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use mm2_core::mm_ctx::MmArc; | ||
use mm2_err_handle::prelude::MmResult; | ||
use serde::Serialize; | ||
|
||
use crate::{error::WalletConnectCtxError, WalletConnectCtx}; | ||
|
||
use super::EmptyRpcRequst; | ||
|
||
#[derive(Debug, PartialEq, Serialize)] | ||
pub struct GetChainIdResponse { | ||
pub chain_id: String, | ||
} | ||
|
||
/// `delete connection` RPC command implementation. | ||
pub async fn get_chain_id(ctx: MmArc, _req: EmptyRpcRequst) -> MmResult<GetChainIdResponse, WalletConnectCtxError> { | ||
let ctx = WalletConnectCtx::try_from_ctx_or_initialize(&ctx)?; | ||
let chain_id = ctx.get_active_chain_id().await; | ||
|
||
Ok(GetChainIdResponse { chain_id }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use mm2_core::mm_ctx::MmArc; | ||
use mm2_err_handle::prelude::MmResult; | ||
use serde::Serialize; | ||
|
||
use super::EmptyRpcRequst; | ||
use crate::{error::WalletConnectCtxError, session::Session, WalletConnectCtx}; | ||
|
||
#[derive(Debug, PartialEq, Serialize)] | ||
pub struct GetSessionResponse { | ||
pub session: Option<Session>, | ||
} | ||
|
||
/// `delete connection` RPC command implementation. | ||
pub async fn get_session(ctx: MmArc, _req: EmptyRpcRequst) -> MmResult<GetSessionResponse, WalletConnectCtxError> { | ||
let ctx = WalletConnectCtx::try_from_ctx_or_initialize(&ctx)?; | ||
let session = ctx.get_session().await; | ||
|
||
Ok(GetSessionResponse { session }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
mod delete_connection; | ||
mod get_chain_id; | ||
mod get_session; | ||
mod new_connection; | ||
mod ping; | ||
|
||
pub use delete_connection::delete_connection; | ||
pub use get_chain_id::get_chain_id; | ||
pub use get_session::get_session; | ||
pub use new_connection::new_connection; | ||
pub use ping::ping_session; | ||
use serde::Deserialize; | ||
|
||
#[derive(Deserialize)] | ||
pub struct EmptyRpcRequst {} |
22 changes: 22 additions & 0 deletions
22
mm2src/kdf_walletconnect/src/rpc_commands/new_connection.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use mm2_core::mm_ctx::MmArc; | ||
use mm2_err_handle::prelude::MmResult; | ||
use serde::Serialize; | ||
|
||
use super::EmptyRpcRequst; | ||
use crate::{error::WalletConnectCtxError, WalletConnectCtx}; | ||
|
||
#[derive(Debug, PartialEq, Serialize)] | ||
pub struct CreateConnectionResponse { | ||
pub url: String, | ||
} | ||
|
||
/// `new_connection` RPC command implementation. | ||
pub async fn new_connection( | ||
ctx: MmArc, | ||
_req: EmptyRpcRequst, | ||
) -> MmResult<CreateConnectionResponse, WalletConnectCtxError> { | ||
let ctx = WalletConnectCtx::try_from_ctx_or_initialize(&ctx)?; | ||
let url = ctx.new_connection(None).await?; | ||
|
||
Ok(CreateConnectionResponse { url }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use mm2_core::mm_ctx::MmArc; | ||
use mm2_err_handle::prelude::MmResult; | ||
use relay_rpc::domain::Topic; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::{error::WalletConnectCtxError, session::ping::send_session_ping_request, WalletConnectCtx}; | ||
|
||
#[derive(Debug, PartialEq, Serialize)] | ||
pub struct SessionPingResponse { | ||
pub successful: bool, | ||
} | ||
|
||
#[derive(Deserialize)] | ||
pub struct SessionPingRequest { | ||
topic: Topic, | ||
} | ||
|
||
/// `ping session` RPC command implementation. | ||
pub async fn ping_session(ctx: MmArc, req: SessionPingRequest) -> MmResult<SessionPingResponse, WalletConnectCtxError> { | ||
let ctx = WalletConnectCtx::try_from_ctx_or_initialize(&ctx)?; | ||
send_session_ping_request(&ctx, &req.topic).await?; | ||
|
||
Ok(SessionPingResponse { successful: true }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.