Rename alice::Message1 to Message3

As per sequence diagram.
This commit is contained in:
Franck Royer 2021-02-04 11:45:54 +11:00
parent e74efd38b5
commit 0d1be52966
No known key found for this signature in database
GPG key ID: A82ED75A8DFC50A4
6 changed files with 19 additions and 17 deletions

View file

@ -1,6 +1,6 @@
use crate::protocol::{ use crate::protocol::{
alice, alice,
alice::TransferProof, alice::{Message3, TransferProof},
bob, bob,
bob::{EncryptedSignature, Message4}, bob::{EncryptedSignature, Message4},
}; };
@ -36,7 +36,7 @@ pub enum BobToAlice {
pub enum AliceToBob { pub enum AliceToBob {
SwapResponse(Box<alice::SwapResponse>), SwapResponse(Box<alice::SwapResponse>),
Message0(Box<alice::Message0>), Message0(Box<alice::Message0>),
Message1(Box<alice::Message1>), Message3(Box<Message3>),
Message2, Message2,
} }

View file

@ -31,7 +31,7 @@ pub use self::{
swap_response::*, swap_response::*,
transfer_proof::TransferProof, transfer_proof::TransferProof,
}; };
pub use execution_setup::Message1; pub use execution_setup::Message3;
mod encrypted_signature; mod encrypted_signature;
pub mod event_loop; pub mod event_loop;

View file

@ -26,7 +26,7 @@ pub struct Message0 {
} }
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Message1 { pub struct Message3 {
pub(crate) tx_cancel_sig: Signature, pub(crate) tx_cancel_sig: Signature,
pub(crate) tx_refund_encsig: EncryptedSignature, pub(crate) tx_refund_encsig: EncryptedSignature,
} }
@ -90,11 +90,11 @@ impl Behaviour {
}; };
{ {
let alice_message2 = state2.next_message(); let message3 = state2.next_message();
substream substream
.write_message( .write_message(
&serde_cbor::to_vec(&alice_message2) &serde_cbor::to_vec(&message3)
.context("failed to serialize Message2")?, .context("failed to serialize message3")?,
) )
.await?; .await?;
} }

View file

@ -9,7 +9,7 @@ use crate::{
monero, monero,
protocol::{ protocol::{
alice, alice,
alice::TransferProof, alice::{Message3, TransferProof},
bob, bob,
bob::{EncryptedSignature, Message4}, bob::{EncryptedSignature, Message4},
SwapAmounts, SwapAmounts,
@ -237,7 +237,7 @@ pub struct State2 {
} }
impl State2 { impl State2 {
pub fn next_message(&self) -> alice::Message1 { pub fn next_message(&self) -> Message3 {
let tx_cancel = let tx_cancel =
bitcoin::TxCancel::new(&self.tx_lock, self.cancel_timelock, self.a.public(), self.B); bitcoin::TxCancel::new(&self.tx_lock, self.cancel_timelock, self.a.public(), self.B);
@ -250,7 +250,7 @@ impl State2 {
let tx_refund_encsig = self.a.encsign(self.S_b_bitcoin, tx_refund.digest()); let tx_refund_encsig = self.a.encsign(self.S_b_bitcoin, tx_refund.digest());
let tx_cancel_sig = self.a.sign(tx_cancel.digest()); let tx_cancel_sig = self.a.sign(tx_cancel.digest());
alice::Message1 { Message3 {
tx_refund_encsig, tx_refund_encsig,
tx_cancel_sig, tx_cancel_sig,
} }

View file

@ -3,6 +3,7 @@ use crate::{
network::request_response::BUF_SIZE, network::request_response::BUF_SIZE,
protocol::{ protocol::{
alice, alice,
alice::Message3,
bob::{State0, State2}, bob::{State0, State2},
}, },
}; };
@ -98,11 +99,10 @@ impl Behaviour {
.await?; .await?;
} }
let alice_message1 = serde_cbor::from_slice::<alice::Message1>( let message3 =
&substream.read_message(BUF_SIZE).await?, serde_cbor::from_slice::<Message3>(&substream.read_message(BUF_SIZE).await?)
) .context("failed to deserialize message3")?;
.context("failed to deserialize message1")?; let state2 = state1.receive(message3)?;
let state2 = state1.receive(alice_message1)?;
{ {
let message4 = state2.next_message(); let message4 = state2.next_message();

View file

@ -10,7 +10,9 @@ use crate::{
monero, monero,
monero::{monero_private_key, TransferProof}, monero::{monero_private_key, TransferProof},
protocol::{ protocol::{
alice, bob, alice,
alice::Message3,
bob,
bob::{EncryptedSignature, Message4}, bob::{EncryptedSignature, Message4},
SwapAmounts, SwapAmounts,
}, },
@ -193,7 +195,7 @@ impl State1 {
} }
} }
pub fn receive(self, msg: alice::Message1) -> Result<State2> { pub fn receive(self, msg: Message3) -> Result<State2> {
let tx_cancel = TxCancel::new(&self.tx_lock, self.cancel_timelock, self.A, self.b.public()); let tx_cancel = TxCancel::new(&self.tx_lock, self.cancel_timelock, self.A, self.b.public());
let tx_refund = bitcoin::TxRefund::new(&tx_cancel, &self.refund_address); let tx_refund = bitcoin::TxRefund::new(&tx_cancel, &self.refund_address);