From 88bf080dc0d79e9740f8f910ecd08bfce10fa21e Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Thu, 4 Feb 2021 11:56:58 +1100 Subject: [PATCH] rename alice::Message0 to Message1 --- swap/src/network/request_response.rs | 4 ++-- swap/src/protocol/alice.rs | 2 +- swap/src/protocol/alice/execution_setup.rs | 7 +++---- swap/src/protocol/alice/state.rs | 7 +++---- swap/src/protocol/bob/execution_setup.rs | 14 +++++--------- swap/src/protocol/bob/state.rs | 5 ++--- 6 files changed, 16 insertions(+), 23 deletions(-) diff --git a/swap/src/network/request_response.rs b/swap/src/network/request_response.rs index 64775e74..e7641e22 100644 --- a/swap/src/network/request_response.rs +++ b/swap/src/network/request_response.rs @@ -1,6 +1,6 @@ use crate::protocol::{ alice, - alice::{Message3, TransferProof}, + alice::{Message1, Message3, TransferProof}, bob, bob::{EncryptedSignature, Message2, Message4}, }; @@ -35,7 +35,7 @@ pub enum BobToAlice { #[derive(Clone, Debug, Serialize, Deserialize)] pub enum AliceToBob { SwapResponse(Box), - Message0(Box), + Message1(Box), Message3(Box), Message2, } diff --git a/swap/src/protocol/alice.rs b/swap/src/protocol/alice.rs index 5b14a868..27d71c12 100644 --- a/swap/src/protocol/alice.rs +++ b/swap/src/protocol/alice.rs @@ -25,7 +25,7 @@ use uuid::Uuid; pub use self::{ event_loop::{EventLoop, EventLoopHandle}, - execution_setup::Message0, + execution_setup::Message1, state::*, swap::{run, run_until}, swap_response::*, diff --git a/swap/src/protocol/alice/execution_setup.rs b/swap/src/protocol/alice/execution_setup.rs index 8e698058..cfdfce68 100644 --- a/swap/src/protocol/alice/execution_setup.rs +++ b/swap/src/protocol/alice/execution_setup.rs @@ -15,7 +15,7 @@ use libp2p_async_await::BehaviourOutEvent; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Serialize, Deserialize)] -pub struct Message0 { +pub struct Message1 { pub(crate) A: bitcoin::PublicKey, pub(crate) S_a_monero: monero::PublicKey, pub(crate) S_a_bitcoin: bitcoin::PublicKey, @@ -64,7 +64,7 @@ impl Behaviour { pub fn run(&mut self, bob: PeerId, state0: State0) { self.inner .do_protocol_listener(bob, move |mut substream| async move { - let alice_message0 = state0.next_message(); + let message1 = state0.next_message(); let state1 = { let bob_message0 = serde_cbor::from_slice::( @@ -76,8 +76,7 @@ impl Behaviour { substream .write_message( - &serde_cbor::to_vec(&alice_message0) - .context("failed to serialize Message0")?, + &serde_cbor::to_vec(&message1).context("failed to serialize message1")?, ) .await?; diff --git a/swap/src/protocol/alice/state.rs b/swap/src/protocol/alice/state.rs index 2f439cc4..f64703e9 100644 --- a/swap/src/protocol/alice/state.rs +++ b/swap/src/protocol/alice/state.rs @@ -8,8 +8,7 @@ use crate::{ }, monero, protocol::{ - alice, - alice::{Message3, TransferProof}, + alice::{Message1, Message3, TransferProof}, bob, bob::{EncryptedSignature, Message2, Message4}, SwapAmounts, @@ -135,8 +134,8 @@ impl State0 { } } - pub fn next_message(&self) -> alice::Message0 { - alice::Message0 { + pub fn next_message(&self) -> Message1 { + Message1 { A: self.a.public(), S_a_monero: monero::PublicKey::from_private_key(&monero::PrivateKey { scalar: self.s_a.into_ed25519(), diff --git a/swap/src/protocol/bob/execution_setup.rs b/swap/src/protocol/bob/execution_setup.rs index 9f90c862..cff6a3fd 100644 --- a/swap/src/protocol/bob/execution_setup.rs +++ b/swap/src/protocol/bob/execution_setup.rs @@ -2,8 +2,7 @@ use crate::{ bitcoin::Signature, network::request_response::BUF_SIZE, protocol::{ - alice, - alice::Message3, + alice::{Message1, Message3}, bob::{State0, State2}, }, }; @@ -81,14 +80,11 @@ impl Behaviour { ) .await?; - let alice_message0 = serde_cbor::from_slice::( - &substream.read_message(BUF_SIZE).await?, - ) - .context("failed to deserialize message0")?; + let message1 = + serde_cbor::from_slice::(&substream.read_message(BUF_SIZE).await?) + .context("failed to deserialize message1")?; - let state1 = state0 - .receive(bitcoin_wallet.as_ref(), alice_message0) - .await?; + let state1 = state0.receive(bitcoin_wallet.as_ref(), message1).await?; { let message2 = state1.next_message(); substream diff --git a/swap/src/protocol/bob/state.rs b/swap/src/protocol/bob/state.rs index 7ccc4452..b8144fe6 100644 --- a/swap/src/protocol/bob/state.rs +++ b/swap/src/protocol/bob/state.rs @@ -10,8 +10,7 @@ use crate::{ monero, monero::{monero_private_key, TransferProof}, protocol::{ - alice, - alice::Message3, + alice::{Message1, Message3}, bob, bob::{EncryptedSignature, Message2, Message4}, SwapAmounts, @@ -133,7 +132,7 @@ impl State0 { } } - pub async fn receive(self, wallet: &W, msg: alice::Message0) -> anyhow::Result + pub async fn receive(self, wallet: &W, msg: Message1) -> anyhow::Result where W: BuildTxLockPsbt + GetNetwork, {