Skip to content

Commit

Permalink
Fix gui miner, bump version for release
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash-L2L committed Feb 27, 2024
1 parent e8ec078 commit 87ecae8
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion app/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "plain_bitnames_app"
version = "0.5.1"
version = "0.5.2"
edition = "2021"
authors = [ "Ash Manning <[email protected]>" ]

Expand Down
8 changes: 4 additions & 4 deletions app/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use crate::cli::Config;

#[derive(Clone)]
pub struct App {
pub node: Node,
pub wallet: Wallet,
pub node: Arc<Node>,
pub wallet: Arc<Wallet>,
pub miner: Arc<TokioRwLock<Miner>>,
pub utxos: Arc<RwLock<HashMap<OutPoint, FilledOutput>>>,
pub runtime: Arc<tokio::runtime::Runtime>,
Expand Down Expand Up @@ -88,8 +88,8 @@ impl App {
Arc::new(RwLock::new(utxos))
};
Ok(Self {
node,
wallet,
node: Arc::new(node),
wallet: Arc::new(wallet),
miner: Arc::new(TokioRwLock::new(miner)),
utxos,
runtime: Arc::new(runtime),
Expand Down
37 changes: 31 additions & 6 deletions app/gui/miner.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,50 @@
use std::sync::{
atomic::{self, AtomicBool},
Arc,
};

use eframe::egui::{self, Button};

use crate::app::App;
use eframe::egui;

pub struct Miner;
#[derive(Debug)]
pub struct Miner {
running: Arc<AtomicBool>,
}

impl Default for Miner {
fn default() -> Self {
Self
Self {
running: Arc::new(AtomicBool::new(false)),
}
}
}

impl Miner {
pub fn show(&mut self, app: &mut App, ui: &mut egui::Ui) {
pub fn show(&mut self, app: &App, ui: &mut egui::Ui) {
let block_height = app.node.get_height().unwrap_or(0);
let best_hash = app.node.get_best_hash().unwrap_or([0; 32].into());
ui.label("Block height: ");
ui.monospace(format!("{block_height}"));
ui.label("Best hash: ");
let best_hash = &format!("{best_hash}")[0..8];
ui.monospace(format!("{best_hash}..."));
if ui.button("mine").clicked() {
let _result = app.mine(None);

let running = self.running.load(atomic::Ordering::SeqCst);
if ui.add_enabled(!running, Button::new("Mine")).clicked() {
self.running.store(true, atomic::Ordering::SeqCst);
app.runtime.spawn({
let app = app.clone();
let running = self.running.clone();
async move {
tracing::debug!("Mining...");
let mining_result = app.mine(None).await;
running.store(false, atomic::Ordering::SeqCst);
if let Err(err) = mining_result {
tracing::error!("{:#}", anyhow::Error::new(err))
}
}
});
}
}
}
4 changes: 2 additions & 2 deletions app/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl EguiApp {
Self {
app,
set_seed: SetSeed::default(),
miner: Miner,
miner: Miner::default(),
deposit: Deposit::default(),
bitname_explorer: BitnameExplorer::default(),
tab: Tab::Coins,
Expand Down Expand Up @@ -111,7 +111,7 @@ impl eframe::App for EguiApp {
});
egui::TopBottomPanel::bottom("util").show(ctx, |ui| {
ui.horizontal(|ui| {
self.miner.show(&mut self.app, ui);
self.miner.show(&self.app, ui);
ui.separator();
self.deposit.show(&mut self.app, ui);
});
Expand Down
2 changes: 1 addition & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "plain_bitnames"
version = "0.5.1"
version = "0.5.2"
edition = "2021"
authors = [ "Ash Manning <[email protected]>" ]

Expand Down

0 comments on commit 87ecae8

Please sign in to comment.