Merge pull request #9 from comit-network/re-order-send-recv

Re-order send/receive
This commit is contained in:
Philipp Hoenisch 2020-10-12 13:07:35 +11:00 committed by GitHub
commit 1ee060b535
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -17,6 +17,9 @@ use std::convert::{TryFrom, TryInto};
pub mod message;
pub use message::{Message, Message0, Message1, Message2};
// There are no guarantees that send_message and receive_massage do not block
// the flow of execution. Therefore they must be paired between Alice/Bob, one
// send to one receive in the correct order.
pub async fn next_state<
R: RngCore + CryptoRng,
B: WatchForRawTransaction + BroadcastSignedTransaction,
@ -31,11 +34,11 @@ pub async fn next_state<
) -> Result<State> {
match state {
State::State0(state0) => {
transport
.send_message(state0.next_message(rng).into())
.await?;
let alice_message0 = state0.next_message(rng).into();
let bob_message0 = transport.receive_message().await?.try_into()?;
transport.send_message(alice_message0).await?;
let state1 = state0.receive(bob_message0)?;
Ok(state1.into())
}

View File

@ -21,6 +21,9 @@ use std::convert::{TryFrom, TryInto};
pub mod message;
pub use message::{Message, Message0, Message1, Message2, Message3};
// There are no guarantees that send_message and receive_massage do not block
// the flow of execution. Therefore they must be paired between Alice/Bob, one
// send to one receive in the correct order.
pub async fn next_state<
R: RngCore + CryptoRng,
B: WatchForRawTransaction + SignTxLock + BuildTxLockPsbt + BroadcastSignedTransaction,