Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: improve error handling with anyhow #259

Merged
merged 2 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ default: fmt

fmt:
$(CC) fmt --all
$(CC) clippy --workspace

check:
$(CC) test --all -- --show-output
Expand Down
20 changes: 10 additions & 10 deletions lampo-bitcoind/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl BitcoinCore {
.lock()
.unwrap()
.borrow_mut()
.push((txid.clone(), script.clone()));
.push((*txid, script.clone()));
Ok(())
}

Expand Down Expand Up @@ -132,10 +132,10 @@ impl BitcoinCore {
tx.clone(),
idx as u32,
block.header,
Height::from_consensus(self.best_height.borrow().clone() as u32)?,
Height::from_consensus(*self.best_height.borrow() as u32)?,
))));
} else {
still_unconfirmed.push((utxo.clone(), script.clone()));
still_unconfirmed.push((*utxo, script.clone()));
}
}
utxos.clear();
Expand Down Expand Up @@ -226,7 +226,7 @@ impl Backend for BitcoinCore {
let fee: MinimumMempoolFee = self.inner.call("getmempoolinfo", &[])?;
// FIXME: adds the trait for conversion from and to BTC
let fee = fee.mempoolminfee;
Ok((fee * 10000 as f32) as u32)
Ok((fee * 10000_f32) as u32)
}

fn get_best_block(&self) -> error::Result<(lampo_common::backend::BlockHash, Option<u32>)> {
Expand Down Expand Up @@ -393,9 +393,9 @@ impl Backend for BitcoinCore {
tx.txid(),
)));
}
TxResult::Discarded => handler.emit(Event::OnChain(
OnChainEvent::UnconfirmedTransaction(txid.clone()),
)),
TxResult::Discarded => {
handler.emit(Event::OnChain(OnChainEvent::UnconfirmedTransaction(*txid)))
}
}
}
txs.clear();
Expand Down Expand Up @@ -437,7 +437,7 @@ impl Backend for BitcoinCore {
};

if !self.others_txs.lock().unwrap().borrow().is_empty() {
let start: u64 = self.best_height.borrow().clone().into();
let start: u64 = *self.best_height.borrow();
let end: u64 = height.into();
log::trace!(target: "bitcoind", "Scan blocks in range [{start}..{end}]");
for height in start..end + 1 {
Expand All @@ -449,8 +449,8 @@ impl Backend for BitcoinCore {
log::warn!(target: "bitcoind", "Impossible retrieval the block information with hash `{block_hash}`");
continue;
};
if self.best_height.borrow().lt(&height.into()) {
*self.best_height.borrow_mut() = height.into();
if self.best_height.borrow().lt(&height) {
*self.best_height.borrow_mut() = height;
*self.last_bloch_hash.borrow_mut() = Some(block_hash);
log::trace!(target: "bitcoind", "new best block with hash `{block_hash}` at height `{height}`");
handler.emit(Event::OnChain(OnChainEvent::NewBestBlock((
Expand Down
2 changes: 1 addition & 1 deletion lampo-cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub fn parse_args() -> Result<LampoCliArgs, lexopt::Error> {
let data_dir = data_dir
.or_else(|| {
#[allow(deprecated)]
std::env::home_dir().and_then(|path| Some(path.to_string_lossy().to_string()))
std::env::home_dir().map(|path| path.to_string_lossy().to_string())
})
.unwrap();
let data_dir = format!("{data_dir}/.lampo");
Expand Down
Loading
Loading