Skip to content

Commit

Permalink
Fix warnings from rustc, rustfmt, and clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash-L2L committed Jan 11, 2024
1 parent d635dc8 commit 1efb463
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 51 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"

members = [
"lib",
Expand Down
2 changes: 1 addition & 1 deletion app/src/gui/deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Deposit {
.add_enabled(amount.is_ok() && fee.is_ok(), egui::Button::new("deposit"))
.clicked()
{
app.deposit(
let _ = app.deposit(
amount.expect("should not happen"),
fee.expect("should not happen"),
);
Expand Down
17 changes: 6 additions & 11 deletions app/src/gui/mempool_explorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,14 @@ use lib::{
types::{GetValue, OutPoint},
};

#[derive(Default)]
pub struct MemPoolExplorer {
current: usize,
}

impl Default for MemPoolExplorer {
fn default() -> Self {
Self { current: 0 }
}
}

impl MemPoolExplorer {
pub fn show(&mut self, app: &mut App, ui: &mut egui::Ui) {
let transactions = app.node.get_all_transactions().unwrap_or(vec![]);
let transactions = app.node.get_all_transactions().unwrap_or_default();
let utxos = app.wallet.get_utxos().unwrap_or_default();
egui::SidePanel::left("transaction_picker")
.resizable(false)
Expand Down Expand Up @@ -50,7 +45,7 @@ impl MemPoolExplorer {
let txid = &format!("{}", transaction.transaction.txid())[0..8];
if value_in >= value_out {
let fee = value_in - value_out;
ui.selectable_value(&mut self.current, index, format!("{txid}"));
ui.selectable_value(&mut self.current, index, txid.to_string());
ui.with_layout(
egui::Layout::right_to_left(egui::Align::Max),
|ui| {
Expand All @@ -67,7 +62,7 @@ impl MemPoolExplorer {
);
ui.end_row();
} else {
ui.selectable_value(&mut self.current, index, format!("{txid}"));
ui.selectable_value(&mut self.current, index, txid.to_string());
ui.monospace("invalid");
ui.end_row();
}
Expand Down Expand Up @@ -100,7 +95,7 @@ impl MemPoolExplorer {
let output = &utxos[input];
let hash = &hash[0..8];
let value = bitcoin::Amount::from_sat(output.get_value());
ui.monospace(format!("{kind}",));
ui.monospace(kind.to_string());
ui.monospace(format!("{hash}:{vout}",));
ui.monospace(format!("{value}",));
ui.end_row();
Expand All @@ -121,7 +116,7 @@ impl MemPoolExplorer {
let address = &format!("{}", output.address)[0..8];
let value = bitcoin::Amount::from_sat(output.get_value());
ui.monospace(format!("{vout}"));
ui.monospace(format!("{address}"));
ui.monospace(address.to_string());
ui.monospace(format!("{value}"));
ui.end_row();
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/gui/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl Miner {
let best_hash = &format!("{best_hash}")[0..8];
ui.monospace(format!("{best_hash}..."));
if ui.button("mine").clicked() {
app.mine();
let _ = app.mine();
}
}
}
10 changes: 5 additions & 5 deletions app/src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ impl EguiApp {
Self {
app,
set_seed: SetSeed::default(),
miner: Miner::default(),
miner: Miner,
deposit: Deposit::default(),
utxo_selector: UtxoSelector::default(),
utxo_selector: UtxoSelector,
utxo_creator: UtxoCreator::default(),
mempool_explorer: MemPoolExplorer::default(),
block_explorer: BlockExplorer::new(height),
Expand Down Expand Up @@ -136,7 +136,7 @@ impl eframe::App for EguiApp {
self.app.transaction.inputs.iter().enumerate()
{
let output = &self.app.utxos[&outpoint];
show_utxo(ui, &outpoint, output);
show_utxo(ui, outpoint, output);
if ui.button("remove").clicked() {
remove = Some(vout);
}
Expand Down Expand Up @@ -170,7 +170,7 @@ impl eframe::App for EguiApp {
let address = &format!("{}", output.address)[0..8];
let value = bitcoin::Amount::from_sat(output.get_value());
ui.monospace(format!("{vout}"));
ui.monospace(format!("{address}"));
ui.monospace(address.to_string());
ui.with_layout(
egui::Layout::right_to_left(egui::Align::Max),
|ui| {
Expand Down Expand Up @@ -222,7 +222,7 @@ impl eframe::App for EguiApp {
} else {
egui::CentralPanel::default().show(ctx, |_ui| {
egui::Window::new("Set Seed").show(ctx, |ui| {
self.set_seed.show(&mut self.app, ui);
self.set_seed.show(&self.app, ui);
});
});
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/gui/utxo_selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl UtxoSelector {
.filter(|(outpoint, _)| !selected.contains(outpoint))
.map(|(_, output)| output.get_value())
.sum();
let mut utxos: Vec<_> = utxos.into_iter().collect();
let mut utxos: Vec<_> = utxos.iter().collect();
utxos.sort_by_key(|(outpoint, _)| format!("{outpoint}"));
ui.separator();
ui.monospace(format!("Total: {}", bitcoin::Amount::from_sat(total)));
Expand Down Expand Up @@ -57,7 +57,7 @@ pub fn show_utxo(ui: &mut egui::Ui, outpoint: &OutPoint, output: &Output) {
};
let hash = &hash[0..8];
let value = bitcoin::Amount::from_sat(output.get_value());
ui.monospace(format!("{kind}",));
ui.monospace(kind.to_string());
ui.monospace(format!("{hash}:{vout}",));
ui.with_layout(egui::Layout::right_to_left(egui::Align::Max), |ui| {
ui.monospace(format!("{value}"));
Expand Down
7 changes: 1 addition & 6 deletions app/src/gui/withdrawals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@ use eframe::egui;
use lib::bip300301::bitcoin;
use lib::types::GetValue;

#[derive(Default)]
pub struct Withdrawals {}

impl Default for Withdrawals {
fn default() -> Self {
Self {}
}
}

impl Withdrawals {
pub fn show(&mut self, app: &mut App, ui: &mut egui::Ui) {
ui.heading("Pending withdrawals");
Expand Down
2 changes: 1 addition & 1 deletion lib/src/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl MemPool {
self.spent_utxos.put(txn, input, &())?;
}
self.transactions
.put(txn, &transaction.transaction.txid().into(), &transaction)?;
.put(txn, &transaction.transaction.txid().into(), transaction)?;
Ok(())
}

Expand Down
8 changes: 1 addition & 7 deletions lib/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,11 @@ pub enum Response {
TransactionRejected,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
pub struct PeerState {
pub block_height: u32,
}

impl Default for PeerState {
fn default() -> Self {
Self { block_height: 0 }
}
}

impl Net {
pub fn new(bind_addr: SocketAddr) -> Result<Self, Error> {
let (server, _) = make_server_endpoint(bind_addr)?;
Expand Down
14 changes: 7 additions & 7 deletions lib/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ impl Node {
) -> Result<(), Error> {
{
let mut txn = self.env.write_txn()?;
self.validate_transaction(&txn, &transaction)?;
self.mempool.put(&mut txn, &transaction)?;
self.validate_transaction(&txn, transaction)?;
self.mempool.put(&mut txn, transaction)?;
txn.commit()?;
}
for peer in self.net.peers.read().await.values() {
Expand Down Expand Up @@ -206,13 +206,13 @@ impl Node {
.await?;
let mut txn = self.env.write_txn()?;
let height = self.archive.get_height(&txn)?;
self.state.validate_body(&txn, &body, height)?;
self.state.connect_body(&mut txn, &body)?;
self.state.validate_body(&txn, body, height)?;
self.state.connect_body(&mut txn, body)?;
self.state
.connect_two_way_peg_data(&mut txn, &two_way_peg_data, height)?;
let bundle = self.state.get_pending_withdrawal_bundle(&txn)?;
self.archive.append_header(&mut txn, &header)?;
self.archive.put_body(&mut txn, &header, &body)?;
self.archive.append_header(&mut txn, header)?;
self.archive.put_body(&mut txn, header, body)?;
for transaction in &body.transactions {
self.mempool.delete(&mut txn, &transaction.txid())?;
}
Expand Down Expand Up @@ -320,7 +320,7 @@ impl Node {
send.write_all(&response)
.await
.map_err(crate::net::Error::from)?;
return Err(err.into());
return Err(err);
}
Ok(_) => {
{
Expand Down
4 changes: 2 additions & 2 deletions lib/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl State {
let commitment = hash(&inputs);
let script = script::Builder::new()
.push_opcode(opcodes::all::OP_RETURN)
.push_slice(&commitment)
.push_slice(commitment)
.into_script();
let inputs_commitment_txout = bitcoin::TxOut {
value: 0,
Expand Down Expand Up @@ -321,7 +321,7 @@ impl State {
&self,
txn: &RoTxn,
) -> Result<Option<bitcoin::BlockHash>, Error> {
Ok(self.last_deposit_block.get(&txn, &0)?)
Ok(self.last_deposit_block.get(txn, &0)?)
}

pub fn connect_two_way_peg_data(
Expand Down
12 changes: 6 additions & 6 deletions lib/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ use std::{cmp::Ordering, collections::HashMap};

mod address;
mod hashes;
mod types;
mod transaction;

pub use blake3;
pub use bs58;
pub use serde;
pub use types::*;
pub use transaction::*;

/*
// Replace () with a type (usually an enum) for output data specific for your sidechain.
Expand All @@ -29,7 +29,7 @@ pub struct Header {

impl Header {
pub fn hash(&self) -> BlockHash {
types::hash(self).into()
transaction::hash(self).into()
}
}

Expand All @@ -41,13 +41,13 @@ pub enum WithdrawalBundleStatus {

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct WithdrawalBundle {
pub spent_utxos: HashMap<types::OutPoint, types::Output>,
pub spent_utxos: HashMap<transaction::OutPoint, transaction::Output>,
pub transaction: bitcoin::Transaction,
}

#[derive(Default, Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct TwoWayPegData {
pub deposits: HashMap<types::OutPoint, types::Output>,
pub deposits: HashMap<transaction::OutPoint, transaction::Output>,
pub deposit_block_hash: Option<bitcoin::BlockHash>,
pub bundle_statuses: HashMap<bitcoin::Txid, WithdrawalBundleStatus>,
}
Expand All @@ -66,7 +66,7 @@ pub struct DisconnectData {

#[derive(Eq, PartialEq, Clone, Debug)]
pub struct AggregatedWithdrawal {
pub spent_utxos: HashMap<OutPoint, types::Output>,
pub spent_utxos: HashMap<OutPoint, transaction::Output>,
pub main_address: bitcoin::Address<bitcoin::address::NetworkUnchecked>,
pub value: u64,
pub main_fee: u64,
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions lib/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl Wallet {

pub fn set_seed(&self, seed: &[u8; 64]) -> Result<(), Error> {
let mut txn = self.env.write_txn()?;
self.seed.put(&mut txn, &0, &seed)?;
self.seed.put(&mut txn, &0, seed)?;
self.address_to_index.clear(&mut txn)?;
self.index_to_address.clear(&mut txn)?;
self.utxos.clear(&mut txn)?;
Expand Down Expand Up @@ -129,7 +129,7 @@ impl Wallet {
if total < value {
return Err(Error::NotEnoughFunds);
}
return Ok((total, selected));
Ok((total, selected))
}

pub fn delete_utxos(&self, outpoints: &[OutPoint]) -> Result<(), Error> {
Expand Down

0 comments on commit 1efb463

Please sign in to comment.