[blockchain] add Error::OfflineClient

This commit is contained in:
Alekos Filini 2020-05-06 16:50:03 +02:00
parent 75a9c30c9a
commit 45aa001e10
No known key found for this signature in database
GPG Key ID: 5E8AFC3034FDFA4F
2 changed files with 11 additions and 6 deletions

View File

@ -84,7 +84,7 @@ impl<T: Read + Write> OnlineBlockchain for ElectrumBlockchain<T> {
let call_result = self let call_result = self
.0 .0
.as_mut() .as_mut()
.unwrap() .ok_or(Error::OfflineClient)?
.batch_script_get_history(chunk.iter())?; .batch_script_get_history(chunk.iter())?;
for (script, history) in chunk.into_iter().zip(call_result.into_iter()) { for (script, history) in chunk.into_iter().zip(call_result.into_iter()) {
@ -127,7 +127,7 @@ impl<T: Read + Write> OnlineBlockchain for ElectrumBlockchain<T> {
let call_result = self let call_result = self
.0 .0
.as_mut() .as_mut()
.unwrap() .ok_or(Error::OfflineClient)?
.batch_script_list_unspent(scripts)?; .batch_script_list_unspent(scripts)?;
// check which utxos are actually still unspent // check which utxos are actually still unspent
@ -175,7 +175,7 @@ impl<T: Read + Write> OnlineBlockchain for ElectrumBlockchain<T> {
Ok(self Ok(self
.0 .0
.as_mut() .as_mut()
.unwrap() .ok_or(Error::OfflineClient)?
.transaction_get(txid) .transaction_get(txid)
.map(Option::Some)?) .map(Option::Some)?)
} }
@ -184,7 +184,7 @@ impl<T: Read + Write> OnlineBlockchain for ElectrumBlockchain<T> {
Ok(self Ok(self
.0 .0
.as_mut() .as_mut()
.unwrap() .ok_or(Error::OfflineClient)?
.transaction_broadcast(tx) .transaction_broadcast(tx)
.map(|_| ())?) .map(|_| ())?)
} }
@ -193,7 +193,7 @@ impl<T: Read + Write> OnlineBlockchain for ElectrumBlockchain<T> {
Ok(self Ok(self
.0 .0
.as_mut() .as_mut()
.unwrap() .ok_or(Error::OfflineClient)?
.block_headers_subscribe() .block_headers_subscribe()
.map(|data| data.height)?) .map(|data| data.height)?)
} }
@ -232,7 +232,11 @@ impl<T: Read + Write> ElectrumBlockchain<T> {
// went wrong // went wrong
saved_tx.transaction.unwrap() saved_tx.transaction.unwrap()
} }
None => self.0.as_mut().unwrap().transaction_get(&txid)?, None => self
.0
.as_mut()
.ok_or(Error::OfflineClient)?
.transaction_get(&txid)?,
}; };
let mut incoming: u64 = 0; let mut incoming: u64 = 0;

View File

@ -29,6 +29,7 @@ pub enum Error {
// Blockchain interface errors // Blockchain interface errors
Uncapable(crate::blockchain::Capability), Uncapable(crate::blockchain::Capability),
OfflineClient,
InvalidProgressValue(f32), InvalidProgressValue(f32),
ProgressUpdateError, ProgressUpdateError,
MissingCachedAddresses, MissingCachedAddresses,