Rename bob::Message2 to Message4

As per sequence diagram.
This commit is contained in:
Franck Royer 2021-02-04 11:43:07 +11:00
parent 081237bb6f
commit e74efd38b5
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
6 changed files with 31 additions and 15 deletions

View File

@ -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<bob::SwapRequest>),
Message0(Box<bob::Message0>),
Message1(Box<bob::Message1>),
Message2(Box<bob::Message2>),
Message4(Box<Message4>),
}
/// Messages Alice sends to Bob.

View File

@ -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::<bob::Message2>(
let message4 = serde_cbor::from_slice::<Message4>(
&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)

View File

@ -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<State3> {
pub fn receive(self, msg: Message4) -> Result<State3> {
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)

View File

@ -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;

View File

@ -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?;
}

View File

@ -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,
}