From e74efd38b54b08cc8327ca8651b194692846d3f9 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Thu, 4 Feb 2021 11:43:07 +1100 Subject: [PATCH] Rename bob::Message2 to Message4 As per sequence diagram. --- swap/src/network/request_response.rs | 9 +++++++-- swap/src/protocol/alice/execution_setup.rs | 7 ++++--- swap/src/protocol/alice/state.rs | 10 ++++++++-- swap/src/protocol/bob.rs | 2 +- swap/src/protocol/bob/execution_setup.rs | 8 ++++---- swap/src/protocol/bob/state.rs | 10 +++++++--- 6 files changed, 31 insertions(+), 15 deletions(-) diff --git a/swap/src/network/request_response.rs b/swap/src/network/request_response.rs index f35ac3e0..d4b5ffc9 100644 --- a/swap/src/network/request_response.rs +++ b/swap/src/network/request_response.rs @@ -1,4 +1,9 @@ -use crate::protocol::{alice, alice::TransferProof, bob, bob::EncryptedSignature}; +use crate::protocol::{ + alice, + alice::TransferProof, + bob, + bob::{EncryptedSignature, Message4}, +}; use async_trait::async_trait; use futures::prelude::*; use libp2p::{ @@ -23,7 +28,7 @@ pub enum BobToAlice { SwapRequest(Box), Message0(Box), Message1(Box), - Message2(Box), + Message4(Box), } /// Messages Alice sends to Bob. diff --git a/swap/src/protocol/alice/execution_setup.rs b/swap/src/protocol/alice/execution_setup.rs index d8673448..de6ee9c7 100644 --- a/swap/src/protocol/alice/execution_setup.rs +++ b/swap/src/protocol/alice/execution_setup.rs @@ -6,6 +6,7 @@ use crate::{ protocol::{ alice::{State0, State3}, bob, + bob::Message4, }, }; use anyhow::{Context, Error, Result}; @@ -99,11 +100,11 @@ impl Behaviour { } let state3 = { - let bob_message2 = serde_cbor::from_slice::( + let message4 = serde_cbor::from_slice::( &substream.read_message(BUF_SIZE).await?, ) - .context("failed to deserialize message2")?; - state2.receive(bob_message2)? + .context("failed to deserialize message4")?; + state2.receive(message4)? }; Ok(state3) diff --git a/swap/src/protocol/alice/state.rs b/swap/src/protocol/alice/state.rs index 394493a5..80e08744 100644 --- a/swap/src/protocol/alice/state.rs +++ b/swap/src/protocol/alice/state.rs @@ -7,7 +7,13 @@ use crate::{ TxRefund, WatchForRawTransaction, }, monero, - protocol::{alice, alice::TransferProof, bob, bob::EncryptedSignature, SwapAmounts}, + protocol::{ + alice, + alice::TransferProof, + bob, + bob::{EncryptedSignature, Message4}, + SwapAmounts, + }, }; use anyhow::{anyhow, Context, Result}; use ecdsa_fun::{adaptor::Adaptor, nonce::Deterministic}; @@ -250,7 +256,7 @@ impl State2 { } } - pub fn receive(self, msg: bob::Message2) -> Result { + pub fn receive(self, msg: Message4) -> Result { let tx_cancel = bitcoin::TxCancel::new(&self.tx_lock, self.cancel_timelock, self.a.public(), self.B); bitcoin::verify_sig(&self.B, &tx_cancel.digest(), &msg.tx_cancel_sig) diff --git a/swap/src/protocol/bob.rs b/swap/src/protocol/bob.rs index 8e0ebd36..cb151d8d 100644 --- a/swap/src/protocol/bob.rs +++ b/swap/src/protocol/bob.rs @@ -26,7 +26,7 @@ pub use self::{ swap::{run, run_until}, swap_request::*, }; -pub use execution_setup::{Message0, Message1, Message2}; +pub use execution_setup::{Message0, Message1, Message4}; mod encrypted_signature; pub mod event_loop; diff --git a/swap/src/protocol/bob/execution_setup.rs b/swap/src/protocol/bob/execution_setup.rs index d3eacac0..e518796f 100644 --- a/swap/src/protocol/bob/execution_setup.rs +++ b/swap/src/protocol/bob/execution_setup.rs @@ -28,7 +28,7 @@ pub struct Message1 { } #[derive(Clone, Debug, Serialize, Deserialize)] -pub struct Message2 { +pub struct Message4 { pub(crate) tx_punish_sig: Signature, pub(crate) tx_cancel_sig: Signature, } @@ -105,11 +105,11 @@ impl Behaviour { let state2 = state1.receive(alice_message1)?; { - let bob_message2 = state2.next_message(); + let message4 = state2.next_message(); substream .write_message( - &serde_cbor::to_vec(&bob_message2) - .context("failed to serialize Message2")?, + &serde_cbor::to_vec(&message4) + .context("failed to serialize message4")?, ) .await?; } diff --git a/swap/src/protocol/bob/state.rs b/swap/src/protocol/bob/state.rs index a5902956..b0ac3c83 100644 --- a/swap/src/protocol/bob/state.rs +++ b/swap/src/protocol/bob/state.rs @@ -9,7 +9,11 @@ use crate::{ execution_params::ExecutionParams, monero, monero::{monero_private_key, TransferProof}, - protocol::{alice, bob, bob::EncryptedSignature, SwapAmounts}, + protocol::{ + alice, bob, + bob::{EncryptedSignature, Message4}, + SwapAmounts, + }, }; use anyhow::{anyhow, Result}; use ecdsa_fun::{adaptor::Adaptor, nonce::Deterministic, Signature}; @@ -246,14 +250,14 @@ pub struct State2 { } impl State2 { - pub fn next_message(&self) -> bob::Message2 { + pub fn next_message(&self) -> Message4 { let tx_cancel = TxCancel::new(&self.tx_lock, self.cancel_timelock, self.A, self.b.public()); let tx_cancel_sig = self.b.sign(tx_cancel.digest()); let tx_punish = bitcoin::TxPunish::new(&tx_cancel, &self.punish_address, self.punish_timelock); let tx_punish_sig = self.b.sign(tx_punish.digest()); - bob::Message2 { + Message4 { tx_punish_sig, tx_cancel_sig, }