Skip to content

Commit

Permalink
remove unused
Browse files Browse the repository at this point in the history
  • Loading branch information
borngraced committed Nov 6, 2024
1 parent a43dc60 commit eea1532
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 71 deletions.
2 changes: 2 additions & 0 deletions mm2src/coins/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2694,6 +2694,8 @@ async fn sign_raw_eth_tx(coin: &EthCoin, args: &SignEthTransactionParams) -> Raw
.map_to_mm(|err| RawTransactionError::TransactionError(err.get_plain_text_format()))
},
EthPrivKeyPolicy::WalletConnect { .. } => {
//NOTE: doesn't work with wallets that doesn't support `eth_signTransaction` e.g
//Metamask
let wc = {
let ctx = MmArc::from_weak(&coin.ctx).expect("No context");
WalletConnectCtx::from_ctx(&ctx).expect("WalletConnectCtx should be initialized by now!")
Expand Down
7 changes: 0 additions & 7 deletions mm2src/kdf_walletconnect/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ pub struct WalletConnectCtx {

relay: Relay,
metadata: Metadata,
subscriptions: Arc<Mutex<Vec<Topic>>>,
inbound_message_rx: Arc<Mutex<UnboundedReceiver<PublishedMessage>>>,
connection_live_rx: Arc<Mutex<UnboundedReceiver<()>>>,
message_tx: UnboundedSender<SessionMessageType>,
Expand Down Expand Up @@ -112,7 +111,6 @@ impl WalletConnectCtx {
metadata: generate_metadata(),
key_pair: SymKeyPair::new(),
session: SessionManager::new(),
subscriptions: Default::default(),

inbound_message_rx: Arc::new(inbound_message_rx.into()),
connection_live_rx: Arc::new(conn_live_receiver.into()),
Expand Down Expand Up @@ -166,11 +164,6 @@ impl WalletConnectCtx {

send_proposal_request(self, &topic, namespaces).await?;

{
let mut subs = self.subscriptions.lock().await;
subs.push(topic);
};

Ok(url)
}

Expand Down
4 changes: 0 additions & 4 deletions mm2src/kdf_walletconnect/src/session/rpc/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ async fn session_delete_cleanup(ctx: &WalletConnectCtx, topic: &Topic) -> MmResu
ctx.client.unsubscribe(session.pairing_topic.clone()).await?;
// Attempt to disconnect the pairing
ctx.pairing.delete(session.pairing_topic.as_ref()).await;
// Remove subscriptions
let mut subs = ctx.subscriptions.lock().await;
subs.retain(|s| s != &session.topic);
subs.retain(|s| s != &session.pairing_topic);

// delete session from storage as well.
ctx.storage
Expand Down
115 changes: 56 additions & 59 deletions mm2src/kdf_walletconnect/src/session/rpc/propose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use relay_rpc::{domain::{MessageId, Topic},
rpc::params::{session_propose::{Proposer, SessionProposeRequest, SessionProposeResponse},
RequestParams, ResponseParamsSuccess}};

/// Creates a new session proposal form topic and metadata.
/// Creates a new session proposal from topic and metadata.
pub(crate) async fn send_proposal_request(
ctx: &WalletConnectCtx,
topic: &Topic,
Expand Down Expand Up @@ -43,28 +43,29 @@ pub async fn reply_session_proposal_request(
topic: &Topic,
message_id: &MessageId,
) -> MmResult<(), WalletConnectError> {
let sender_public_key = const_hex::decode(&proposal.proposer.public_key)?
.as_slice()
.try_into()
.map_to_mm(|_| WalletConnectError::InternalError("Invalid sender_public_key".to_owned()))?;

let session_key = SessionKey::from_osrng(&sender_public_key)?;
let session_topic: Topic = session_key.generate_topic().into();
let subscription_id = ctx
.client
.subscribe(session_topic.clone())
.await
.map_to_mm(|err| WalletConnectError::SubscriptionError(err.to_string()))?;

let session = Session::new(
ctx,
session_topic.clone(),
subscription_id,
session_key,
topic.clone(),
proposal.proposer.metadata,
SessionType::Controller,
);
let session = {
let sender_public_key = const_hex::decode(&proposal.proposer.public_key)?
.as_slice()
.try_into()
.map_to_mm(|_| WalletConnectError::InternalError("Invalid sender_public_key".to_owned()))?;
let session_key = SessionKey::from_osrng(&sender_public_key)?;
let session_topic: Topic = session_key.generate_topic().into();
let subscription_id = ctx
.client
.subscribe(session_topic.clone())
.await
.map_to_mm(|err| WalletConnectError::SubscriptionError(err.to_string()))?;

Session::new(
ctx,
session_topic.clone(),
subscription_id,
session_key,
topic.clone(),
proposal.proposer.metadata,
SessionType::Controller,
)
};
session
.propose_namespaces
.supported(&proposal.required_namespaces)
Expand All @@ -79,14 +80,9 @@ pub async fn reply_session_proposal_request(

// Add session to session lists
ctx.session.add_session(session.clone()).await;
// Add topic to subscription list
let mut subs = ctx.subscriptions.lock().await;
subs.push(session_topic);
}

{
send_session_settle_request(ctx, &session).await?;
};
send_session_settle_request(ctx, &session).await?;

// Respond to incoming session propose.
let param = ResponseParamsSuccess::SessionPropose(SessionProposeResponse {
Expand All @@ -105,34 +101,38 @@ pub(crate) async fn process_session_propose_response(
pairing_topic: &Topic,
response: &SessionProposeResponse,
) -> MmResult<(), WalletConnectError> {
let other_public_key = const_hex::decode(&response.responder_public_key)?
.as_slice()
.try_into()
.unwrap();

let mut session_key = SessionKey::new(ctx.key_pair.public_key);
session_key.generate_symmetric_key(&ctx.key_pair.secret, &other_public_key)?;

let session_topic: Topic = session_key.generate_topic().into();
let subscription_id = ctx
.client
.subscribe(session_topic.clone())
.await
.map_to_mm(|err| WalletConnectError::SubscriptionError(err.to_string()))?;

let mut session = Session::new(
ctx,
session_topic.clone(),
subscription_id,
session_key,
pairing_topic.clone(),
generate_metadata(),
SessionType::Proposer,
);
session.relay = response.relay.clone();
session.expiry = Utc::now().timestamp() as u64 + THIRTY_DAYS;
session.controller.public_key = response.responder_public_key.clone();
let session_key = {
let other_public_key = const_hex::decode(&response.responder_public_key)?
.as_slice()
.try_into()
.unwrap();
let mut session_key = SessionKey::new(ctx.key_pair.public_key);
session_key.generate_symmetric_key(&ctx.key_pair.secret, &other_public_key)?;
session_key
};

let session = {
let session_topic: Topic = session_key.generate_topic().into();
let subscription_id = ctx
.client
.subscribe(session_topic.clone())
.await
.map_to_mm(|err| WalletConnectError::SubscriptionError(err.to_string()))?;

let mut session = Session::new(
ctx,
session_topic.clone(),
subscription_id,
session_key,
pairing_topic.clone(),
generate_metadata(),
SessionType::Proposer,
);
session.relay = response.relay.clone();
session.expiry = Utc::now().timestamp() as u64 + THIRTY_DAYS;
session.controller.public_key = response.responder_public_key.clone();
session
};
{
// save session to storage
ctx.storage
Expand All @@ -142,9 +142,6 @@ pub(crate) async fn process_session_propose_response(

// Add session to session lists
ctx.session.add_session(session.clone()).await;
// Add topic to subscription list
let mut subs = ctx.subscriptions.lock().await;
subs.push(session_topic.clone());
};

// Activate pairing_topic
Expand Down
3 changes: 2 additions & 1 deletion mm2src/kdf_walletconnect/src/session/rpc/settle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub(crate) async fn reply_session_settle_request(
{
let session = ctx.session.get_session_mut(topic);
if let Some(mut session) = session {
session.namespaces = settle.namespaces.0.clone();
session.namespaces = settle.namespaces.0;
session.controller = settle.controller.clone();
session.relay = settle.relay;
session.expiry = settle.expiry;
Expand All @@ -66,6 +66,7 @@ pub(crate) async fn reply_session_settle_request(
ctx.publish_response_ok(topic, param, message_id).await?;

// Delete other sessions with same controller
// TODO: we might not want to do this!
let all_sessions = ctx.session.get_sessions_full();
for session in all_sessions {
if session.controller == settle.controller && session.topic.as_ref() != topic.as_ref() {
Expand Down

0 comments on commit eea1532

Please sign in to comment.