mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-05-02 14:56:10 -04:00
Init Alice behaviour with state0
Previously state0 had to be set after creating Alice's behaviour. With the event loop we no longer has access to the swarm so set_state0() has to be called indirectly through a channel. This means it is difficult to guarantee state0 is being set due to the asynchronous nature of channels. This was solved by initialising Alice with state0.
This commit is contained in:
parent
3d8866f1a0
commit
27d1334726
6 changed files with 114 additions and 133 deletions
|
@ -145,9 +145,6 @@ pub async fn swap(
|
|||
punish_address,
|
||||
);
|
||||
|
||||
info!("Commencing handshake");
|
||||
swarm.set_state0(state.clone());
|
||||
|
||||
state0 = Some(state)
|
||||
}
|
||||
OutEvent::Message0(msg) => {
|
||||
|
@ -387,6 +384,20 @@ pub struct Behaviour {
|
|||
}
|
||||
|
||||
impl Behaviour {
|
||||
pub fn new(state: State0) -> Self {
|
||||
let identity = Keypair::generate_ed25519();
|
||||
|
||||
Self {
|
||||
pt: PeerTracker::default(),
|
||||
amounts: Amounts::default(),
|
||||
message0: Message0::new(state),
|
||||
message1: Message1::default(),
|
||||
message2: Message2::default(),
|
||||
message3: Message3::default(),
|
||||
identity,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn identity(&self) -> Keypair {
|
||||
self.identity.clone()
|
||||
}
|
||||
|
@ -402,13 +413,6 @@ impl Behaviour {
|
|||
info!("Sent amounts response");
|
||||
}
|
||||
|
||||
// TODO(Franck) remove
|
||||
/// Message0 gets sent within the network layer using this state0.
|
||||
pub fn set_state0(&mut self, state: State0) {
|
||||
debug!("Set state 0");
|
||||
let _ = self.message0.set_state(state);
|
||||
}
|
||||
|
||||
/// Send Message1 to Bob in response to receiving his Message1.
|
||||
pub fn send_message1(
|
||||
&mut self,
|
||||
|
@ -430,22 +434,6 @@ impl Behaviour {
|
|||
}
|
||||
}
|
||||
|
||||
impl Default for Behaviour {
|
||||
fn default() -> Self {
|
||||
let identity = Keypair::generate_ed25519();
|
||||
|
||||
Self {
|
||||
pt: PeerTracker::default(),
|
||||
amounts: Amounts::default(),
|
||||
message0: Message0::default(),
|
||||
message1: Message1::default(),
|
||||
message2: Message2::default(),
|
||||
message3: Message3::default(),
|
||||
identity,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn calculate_amounts(btc: ::bitcoin::Amount) -> SwapAmounts {
|
||||
// TODO (Franck): This should instead verify that the received amounts matches
|
||||
// the command line arguments This value corresponds to 100 XMR per BTC
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue