Merge #629: check if embedded daemon is stopped before request
caa9d385b963e985dd665c0269534c2c28603100 check if embedded daemon is stopped before request (edouard)
Pull request description:
ACKs for top commit:
edouardparis:
Self-ACK caa9d385b963e985dd665c0269534c2c28603100
Tree-SHA512: e15fc9be90c48c5cfa549e7e8caf42502af07446ecc78579fda645494c3e4b482f4e756d3b76e862f50d7417e4efabdb40db9510a5ce961988df1d40cefdea3f
This commit is contained in:
commit
557c775912
@ -25,6 +25,7 @@ impl std::fmt::Display for Error {
|
|||||||
Self::Daemon(e) => match e {
|
Self::Daemon(e) => match e {
|
||||||
DaemonError::Unexpected(e) => write!(f, "{}", e),
|
DaemonError::Unexpected(e) => write!(f, "{}", e),
|
||||||
DaemonError::NoAnswer => write!(f, "Daemon did not answer"),
|
DaemonError::NoAnswer => write!(f, "Daemon did not answer"),
|
||||||
|
DaemonError::DaemonStopped => write!(f, "Daemon stopped"),
|
||||||
DaemonError::Transport(Some(ErrorKind::ConnectionRefused), _) => {
|
DaemonError::Transport(Some(ErrorKind::ConnectionRefused), _) => {
|
||||||
write!(f, "Failed to connect to daemon")
|
write!(f, "Failed to connect to daemon")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,6 +33,7 @@ impl From<&Error> for WarningMessage {
|
|||||||
DaemonError::NoAnswer | DaemonError::Transport(..) => {
|
DaemonError::NoAnswer | DaemonError::Transport(..) => {
|
||||||
WarningMessage("Communication with Daemon failed".to_string())
|
WarningMessage("Communication with Daemon failed".to_string())
|
||||||
}
|
}
|
||||||
|
DaemonError::DaemonStopped => WarningMessage("Daemon stopped".to_string()),
|
||||||
},
|
},
|
||||||
Error::Unexpected(_) => WarningMessage("Unknown error".to_string()),
|
Error::Unexpected(_) => WarningMessage("Unknown error".to_string()),
|
||||||
Error::HardwareWallet(_) => WarningMessage("Hardware wallet error".to_string()),
|
Error::HardwareWallet(_) => WarningMessage("Hardware wallet error".to_string()),
|
||||||
|
|||||||
@ -4,7 +4,7 @@ use super::{model::*, Daemon, DaemonError};
|
|||||||
use liana::{
|
use liana::{
|
||||||
config::Config,
|
config::Config,
|
||||||
miniscript::bitcoin::{address, psbt::Psbt, Address, OutPoint, Txid},
|
miniscript::bitcoin::{address, psbt::Psbt, Address, OutPoint, Txid},
|
||||||
DaemonHandle,
|
DaemonControl, DaemonHandle,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct EmbeddedDaemon {
|
pub struct EmbeddedDaemon {
|
||||||
@ -17,6 +17,14 @@ impl EmbeddedDaemon {
|
|||||||
let handle = DaemonHandle::start_default(config.clone()).map_err(DaemonError::Start)?;
|
let handle = DaemonHandle::start_default(config.clone()).map_err(DaemonError::Start)?;
|
||||||
Ok(Self { handle, config })
|
Ok(Self { handle, config })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn control(&self) -> Result<&DaemonControl, DaemonError> {
|
||||||
|
if self.handle.shutdown_complete() {
|
||||||
|
Err(DaemonError::DaemonStopped)
|
||||||
|
} else {
|
||||||
|
Ok(&self.handle.control)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Debug for EmbeddedDaemon {
|
impl std::fmt::Debug for EmbeddedDaemon {
|
||||||
@ -43,19 +51,19 @@ impl Daemon for EmbeddedDaemon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_info(&self) -> Result<GetInfoResult, DaemonError> {
|
fn get_info(&self) -> Result<GetInfoResult, DaemonError> {
|
||||||
Ok(self.handle.control.get_info())
|
Ok(self.control()?.get_info())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_new_address(&self) -> Result<GetAddressResult, DaemonError> {
|
fn get_new_address(&self) -> Result<GetAddressResult, DaemonError> {
|
||||||
Ok(self.handle.control.get_new_address())
|
Ok(self.control()?.get_new_address())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn list_coins(&self) -> Result<ListCoinsResult, DaemonError> {
|
fn list_coins(&self) -> Result<ListCoinsResult, DaemonError> {
|
||||||
Ok(self.handle.control.list_coins())
|
Ok(self.control()?.list_coins())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn list_spend_txs(&self) -> Result<ListSpendResult, DaemonError> {
|
fn list_spend_txs(&self) -> Result<ListSpendResult, DaemonError> {
|
||||||
Ok(self.handle.control.list_spend())
|
Ok(self.control()?.list_spend())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn list_confirmed_txs(
|
fn list_confirmed_txs(
|
||||||
@ -65,13 +73,12 @@ impl Daemon for EmbeddedDaemon {
|
|||||||
limit: u64,
|
limit: u64,
|
||||||
) -> Result<ListTransactionsResult, DaemonError> {
|
) -> Result<ListTransactionsResult, DaemonError> {
|
||||||
Ok(self
|
Ok(self
|
||||||
.handle
|
.control()?
|
||||||
.control
|
|
||||||
.list_confirmed_transactions(start, end, limit))
|
.list_confirmed_transactions(start, end, limit))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn list_txs(&self, txids: &[Txid]) -> Result<ListTransactionsResult, DaemonError> {
|
fn list_txs(&self, txids: &[Txid]) -> Result<ListTransactionsResult, DaemonError> {
|
||||||
Ok(self.handle.control.list_transactions(txids))
|
Ok(self.control()?.list_transactions(txids))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_spend_tx(
|
fn create_spend_tx(
|
||||||
@ -80,34 +87,30 @@ impl Daemon for EmbeddedDaemon {
|
|||||||
destinations: &HashMap<Address<address::NetworkUnchecked>, u64>,
|
destinations: &HashMap<Address<address::NetworkUnchecked>, u64>,
|
||||||
feerate_vb: u64,
|
feerate_vb: u64,
|
||||||
) -> Result<CreateSpendResult, DaemonError> {
|
) -> Result<CreateSpendResult, DaemonError> {
|
||||||
self.handle
|
self.control()?
|
||||||
.control
|
|
||||||
.create_spend(destinations, coins_outpoints, feerate_vb)
|
.create_spend(destinations, coins_outpoints, feerate_vb)
|
||||||
.map_err(|e| DaemonError::Unexpected(e.to_string()))
|
.map_err(|e| DaemonError::Unexpected(e.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_spend_tx(&self, psbt: &Psbt) -> Result<(), DaemonError> {
|
fn update_spend_tx(&self, psbt: &Psbt) -> Result<(), DaemonError> {
|
||||||
self.handle
|
self.control()?
|
||||||
.control
|
|
||||||
.update_spend(psbt.clone())
|
.update_spend(psbt.clone())
|
||||||
.map_err(|e| DaemonError::Unexpected(e.to_string()))
|
.map_err(|e| DaemonError::Unexpected(e.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn delete_spend_tx(&self, txid: &Txid) -> Result<(), DaemonError> {
|
fn delete_spend_tx(&self, txid: &Txid) -> Result<(), DaemonError> {
|
||||||
self.handle.control.delete_spend(txid);
|
self.control()?.delete_spend(txid);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn broadcast_spend_tx(&self, txid: &Txid) -> Result<(), DaemonError> {
|
fn broadcast_spend_tx(&self, txid: &Txid) -> Result<(), DaemonError> {
|
||||||
self.handle
|
self.control()?
|
||||||
.control
|
|
||||||
.broadcast_spend(txid)
|
.broadcast_spend(txid)
|
||||||
.map_err(|e| DaemonError::Unexpected(e.to_string()))
|
.map_err(|e| DaemonError::Unexpected(e.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_rescan(&self, t: u32) -> Result<(), DaemonError> {
|
fn start_rescan(&self, t: u32) -> Result<(), DaemonError> {
|
||||||
self.handle
|
self.control()?
|
||||||
.control
|
|
||||||
.start_rescan(t)
|
.start_rescan(t)
|
||||||
.map_err(|e| DaemonError::Unexpected(e.to_string()))
|
.map_err(|e| DaemonError::Unexpected(e.to_string()))
|
||||||
}
|
}
|
||||||
@ -118,8 +121,7 @@ impl Daemon for EmbeddedDaemon {
|
|||||||
feerate_vb: u64,
|
feerate_vb: u64,
|
||||||
sequence: Option<u16>,
|
sequence: Option<u16>,
|
||||||
) -> Result<Psbt, DaemonError> {
|
) -> Result<Psbt, DaemonError> {
|
||||||
self.handle
|
self.control()?
|
||||||
.control
|
|
||||||
.create_recovery(address, feerate_vb, sequence)
|
.create_recovery(address, feerate_vb, sequence)
|
||||||
.map_err(|e| DaemonError::Unexpected(e.to_string()))
|
.map_err(|e| DaemonError::Unexpected(e.to_string()))
|
||||||
.map(|res| res.psbt)
|
.map(|res| res.psbt)
|
||||||
|
|||||||
@ -22,6 +22,8 @@ pub enum DaemonError {
|
|||||||
Unexpected(String),
|
Unexpected(String),
|
||||||
/// No response.
|
/// No response.
|
||||||
NoAnswer,
|
NoAnswer,
|
||||||
|
/// Daemon stopped
|
||||||
|
DaemonStopped,
|
||||||
// Error at start up.
|
// Error at start up.
|
||||||
Start(StartupError),
|
Start(StartupError),
|
||||||
// Error if the client is not supported.
|
// Error if the client is not supported.
|
||||||
@ -33,6 +35,7 @@ impl std::fmt::Display for DaemonError {
|
|||||||
match self {
|
match self {
|
||||||
Self::Rpc(code, e) => write!(f, "Daemon error rpc call: [{:?}] {}", code, e),
|
Self::Rpc(code, e) => write!(f, "Daemon error rpc call: [{:?}] {}", code, e),
|
||||||
Self::NoAnswer => write!(f, "Daemon returned no answer"),
|
Self::NoAnswer => write!(f, "Daemon returned no answer"),
|
||||||
|
Self::DaemonStopped => write!(f, "Daemon stopped"),
|
||||||
Self::Transport(kind, e) => write!(f, "Daemon transport error: [{:?}] {}", kind, e),
|
Self::Transport(kind, e) => write!(f, "Daemon transport error: [{:?}] {}", kind, e),
|
||||||
Self::Unexpected(e) => write!(f, "Daemon unexpected error: {}", e),
|
Self::Unexpected(e) => write!(f, "Daemon unexpected error: {}", e),
|
||||||
Self::Start(e) => write!(f, "Daemon did not start: {}", e),
|
Self::Start(e) => write!(f, "Daemon did not start: {}", e),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user