Skip to content

Commit 1a52612

Browse files
committed
joinstr: move state updates to Joinstr::start_coinjoin_blocking()
1 parent e0befd7 commit 1a52612

File tree

1 file changed

+7
-5
lines changed
  • rust/joinstr/src/joinstr

1 file changed

+7
-5
lines changed

rust/joinstr/src/joinstr/mod.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,6 @@ impl Joinstr<'_> {
443443
fn join_pool(&mut self) -> Result<(), Error> {
444444
let mut inner = self.inner.lock().expect("poisoned");
445445
inner.pool_exists()?;
446-
inner.step = Step::Connecting;
447446
let pool_npub = inner.pool_as_ref()?.public_key;
448447
// TODO: receive the response on a derived npub;
449448
let my_npub = inner.client.get_keys()?.public_key();
@@ -477,7 +476,6 @@ impl Joinstr<'_> {
477476
new_client.connect_nostr()?;
478477
inner.client = new_client;
479478
connected = true;
480-
inner.step = Step::OutputRegistration;
481479
break;
482480
} else {
483481
log::error!(
@@ -875,18 +873,21 @@ impl Joinstr<'_> {
875873
log::debug!("Joinstr::start_coinjoin_blocking({name}) try to join pool...");
876874
inner.pool_not_exists()?;
877875
inner.pool = Some(pool);
876+
inner.step = Step::Connecting;
878877
drop(inner);
879878
self.join_pool()?;
880879
log::debug!("Joinstr::start_coinjoin_blocking({name}) pool joined");
881880
} else {
882881
// broadcast the pool event
883882
log::debug!("Joinstr::start_coinjoin_blocking({name}) try to broadcast pool...");
883+
inner.step = Step::Posting;
884884
inner.post()?;
885885
log::debug!("Joinstr::start_coinjoin_blocking({name}) pool broadcast!");
886886
drop(inner);
887887
}
888888
notif();
889889

890+
self.inner.lock().expect("poisoned").step = Step::OutputRegistration;
890891
log::debug!("Joinstr::start_coinjoin_blocking({name}) start register outputs..");
891892
// register peers & outputs
892893
self.register_outputs(&notif)?;
@@ -918,12 +919,16 @@ impl Joinstr<'_> {
918919
log::debug!(
919920
"Joinstr::start_coinjoin_blocking({name}) start registering external inputs..."
920921
);
922+
self.inner.lock().expect("poisoned").step = Step::InputRegistration;
921923
self.register_inputs(&notif)?;
922924

923925
log::debug!("Joinstr::start_coinjoin_blocking({name}) inputs registerd!");
924926

925927
log::debug!("Joinstr::start_coinjoin_blocking({name}) try broadcast tx...");
928+
self.inner.lock().expect("poisoned").step = Step::Broadcast;
926929
self.inner.lock().expect("poisoned").broadcast_tx()?;
930+
// FIXME: wait the tx mined to change the step
931+
self.inner.lock().expect("poisoned").step = Step::Mined;
927932
log::debug!("Joinstr::start_coinjoin_blocking({name}) tx broadcast!");
928933
notif();
929934

@@ -1229,7 +1234,6 @@ impl<'a> JoinstrInner<'a> {
12291234
self.is_ready()?;
12301235
self.pool_not_exists()?;
12311236

1232-
self.step = Step::Posting;
12331237
let public_key = self.client.get_keys()?.public_key();
12341238
let transport = crate::nostr::Transport {
12351239
vpn: Some(Vpn {
@@ -1270,7 +1274,6 @@ impl<'a> JoinstrInner<'a> {
12701274
};
12711275
self.client.post_event(pool.clone().try_into()?)?;
12721276
self.pool = Some(pool);
1273-
self.step = Step::OutputRegistration;
12741277
Ok(())
12751278
}
12761279

@@ -1528,7 +1531,6 @@ impl<'a> JoinstrInner<'a> {
15281531
client.broadcast(&tx)?;
15291532
}
15301533
self.final_tx = Some(tx);
1531-
self.step = Step::Broadcast;
15321534
Ok(())
15331535
}
15341536

0 commit comments

Comments
 (0)