// if written successfully, take and return `self.stage`
.map(|_| Some(core::mem::take(&mut self.stage)))
}
+
+ /// Stages a new changeset and commits it (along with any other previously staged changes) to
+ /// the persistence backend
+ ///
+ /// Convience method for calling [`stage`] and then [`commit`].
+ ///
+ /// [`stage`]: Self::stage
+ /// [`commit`]: Self::commit
+ pub fn stage_and_commit(&mut self, changeset: C) -> Result<Option<C>, B::WriteError> {
+ self.stage(changeset);
+ self.commit()
+ }
}
/// A persistence backend for [`Persist`].
let rpc_cmd = match args.command {
example_cli::Commands::ChainSpecific(rpc_cmd) => rpc_cmd,
general_cmd => {
- let res = example_cli::handle_commands(
+ return example_cli::handle_commands(
&graph,
&db,
&chain,
},
general_cmd,
);
- db.lock().unwrap().commit()?;
- return res;
}
};
let ((spk_i, spk), index_changeset) = spk_chooser(index, &Keychain::External);
let db = &mut *db.lock().unwrap();
- db.stage(C::from((
+ db.stage_and_commit(C::from((
local_chain::ChangeSet::default(),
indexed_tx_graph::ChangeSet::from(index_changeset),
- )));
- db.commit()?;
+ )))?;
let addr =
Address::from_script(spk, network).context("failed to derive address")?;
println!("[address @ {}] {}", spk_i, addr);
// If we're unable to persist this, then we don't want to broadcast.
{
let db = &mut *db.lock().unwrap();
- db.stage(C::from((
+ db.stage_and_commit(C::from((
local_chain::ChangeSet::default(),
indexed_tx_graph::ChangeSet::from(index_changeset),
- )));
- db.commit()?;
+ )))?;
}
// We don't want other callers/threads to use this address while we're using it
// We know the tx is at least unconfirmed now. Note if persisting here fails,
// it's not a big deal since we can always find it again form
// blockchain.
- db.lock().unwrap().stage(C::from((
+ db.lock().unwrap().stage_and_commit(C::from((
local_chain::ChangeSet::default(),
keychain_changeset,
- )));
+ )))?;
Ok(())
}
Err(e) => {
let electrum_cmd = match &args.command {
example_cli::Commands::ChainSpecific(electrum_cmd) => electrum_cmd,
general_cmd => {
- let res = example_cli::handle_commands(
+ return example_cli::handle_commands(
&graph,
&db,
&chain,
},
general_cmd.clone(),
);
-
- db.lock().unwrap().commit()?;
- return res;
}
};
example_cli::Commands::ChainSpecific(esplora_cmd) => esplora_cmd,
// These are general commands handled by example_cli. Execute the cmd and return.
general_cmd => {
- let res = example_cli::handle_commands(
+ return example_cli::handle_commands(
&graph,
&db,
&chain,
},
general_cmd.clone(),
);
-
- db.lock().unwrap().commit()?;
- return res;
}
};