Skip to content

Commit

Permalink
rough implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
borngraced committed Sep 11, 2024
1 parent c3dc6c6 commit 0eea639
Show file tree
Hide file tree
Showing 13 changed files with 564 additions and 104 deletions.
Empty file.
1 change: 1 addition & 0 deletions mm2src/kdf_walletconnect/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"

[dependencies]
# chacha20poly1305 = "0.10"
chrono = { version = "0.4.23", "features" = ["serde"] }
common = { path = "../common" }
derive_more = "0.99"
futures = { version = "0.3", package = "futures", features = [
Expand Down
28 changes: 20 additions & 8 deletions mm2src/kdf_walletconnect/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
use derive_more::Display;
use pairing_api::PairingClientError;
use relay_client::error::{ClientError, Error};
use relay_rpc::rpc::PublishError;
use relay_rpc::rpc::{PublishError, SubscriptionError};
use serde::{Deserialize, Serialize};

#[derive(Debug, Display, Serialize, Deserialize)]
pub enum WalletConnectClientError {
pub enum WalletConnectCtxError {
PairingError(String),
EncodeError(String),
PublishError(String),
ClientError(String),
PairingNotFound(String),
SubscriptionError(String),
InternalError(String),
SerdeError(String),
UnsuccessfulResponse(String)
}

impl From<PairingClientError> for WalletConnectClientError {
fn from(error: PairingClientError) -> Self { WalletConnectClientError::PairingError(error.to_string()) }
impl From<PairingClientError> for WalletConnectCtxError {
fn from(error: PairingClientError) -> Self { WalletConnectCtxError::PairingError(error.to_string()) }
}

impl From<ClientError> for WalletConnectClientError {
fn from(error: ClientError) -> Self { WalletConnectClientError::ClientError(error.to_string()) }
impl From<ClientError> for WalletConnectCtxError {
fn from(error: ClientError) -> Self { WalletConnectCtxError::ClientError(error.to_string()) }
}

impl From<Error<PublishError>> for WalletConnectClientError {
fn from(error: Error<PublishError>) -> Self { WalletConnectClientError::PublishError(format!("{error:?}")) }
impl From<Error<PublishError>> for WalletConnectCtxError {
fn from(error: Error<PublishError>) -> Self { WalletConnectCtxError::PublishError(format!("{error:?}")) }
}

impl From<Error<SubscriptionError>> for WalletConnectCtxError {
fn from(error: Error<SubscriptionError>) -> Self { WalletConnectCtxError::SubscriptionError(format!("{error:?}")) }
}

impl From<serde_json::Error> for WalletConnectCtxError {
fn from(value: serde_json::Error) -> Self { WalletConnectCtxError::SerdeError(value.to_string()) }
}
18 changes: 1 addition & 17 deletions mm2src/kdf_walletconnect/src/handler.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
use std::time::Duration;

use common::log::info;
use futures::channel::mpsc::UnboundedSender;
use relay_client::{error::ClientError,
websocket::{CloseFrame, ConnectionHandler, PublishedMessage},
ConnectionOptions};
use relay_rpc::auth::{ed25519_dalek::SigningKey, AuthToken};
websocket::{CloseFrame, ConnectionHandler, PublishedMessage}};

pub struct Handler {
name: &'static str,
Expand Down Expand Up @@ -44,15 +40,3 @@ impl ConnectionHandler for Handler {
info!("\n[{}] outbound error: {error}", self.name);
}
}

fn create_conn_opts(relay_address: &str, project_id: &str) -> ConnectionOptions {
let key = SigningKey::generate(&mut rand::thread_rng());

let auth = AuthToken::new("https://komodefi.com")
.aud(relay_address)
.ttl(Duration::from_secs(60 * 60))
.as_jwt(&key)
.unwrap();

ConnectionOptions::new(project_id, auth).with_address(relay_address)
}
Loading

0 comments on commit 0eea639

Please sign in to comment.