diff --git a/core/resources/i18n/i18n.json b/core/resources/i18n/i18n.json index 47538bb..b6e0530 100644 --- a/core/resources/i18n/i18n.json +++ b/core/resources/i18n/i18n.json @@ -3189,6 +3189,7 @@ "ECDSA": "ECDSA", "Economic": "Economic", "Enable Market Monitor": "Enable Market Monitor", + "Enable Public wRPC Borsh": "Enable Public wRPC Borsh", "Enable UPnP": "Enable UPnP", "Enable custom daemon arguments": "Enable custom daemon arguments", "Enable experimental features": "Enable experimental features", diff --git a/core/src/core.rs b/core/src/core.rs index 166474d..a947d97 100644 --- a/core/src/core.rs +++ b/core/src/core.rs @@ -60,7 +60,7 @@ pub struct Core { notifications: Notifications, pub storage: Storage, // pub feerate : Option>, - pub feerate : Option, + pub feerate: Option, } impl Core { @@ -222,7 +222,7 @@ impl Core { network_pressure: NetworkPressure::default(), notifications: Notifications::default(), storage, - feerate : None, + feerate: None, // daemon_storage_root: Mutex::new(daemon_storage_root), }; diff --git a/core/src/egui/selection_panels.rs b/core/src/egui/selection_panels.rs index ca45399..a9ec00f 100644 --- a/core/src/egui/selection_panels.rs +++ b/core/src/egui/selection_panels.rs @@ -37,7 +37,8 @@ impl UILayoutExt for Ui { let mut child_rect = self.available_rect_before_wrap(); child_rect.min.x += indent; - let mut child_ui = self.child_ui_with_id_source(child_rect, *self.layout(), id_source, None); + let mut child_ui = + self.child_ui_with_id_source(child_rect, *self.layout(), id_source, None); let ret = add_contents(&mut child_ui); // let left_vline = self.visuals().indent_has_left_vline; @@ -149,10 +150,7 @@ impl SelectionPanel { let _res = add_contents(&mut prepared.content_ui); *min_height = min_height.max(prepared.content_ui.min_rect().height()); prepared.content_ui.set_min_height(*min_height); - let rect = prepared - .frame - .inner_margin - .expand_rect(prepared.content_ui.min_rect()); + let rect = prepared.content_ui.min_rect() + prepared.frame.inner_margin; if !selected && ui.allocate_rect(rect, Sense::hover()).hovered() { //prepared.frame = prepared.frame.stroke(hover_stroke); prepared.frame = prepared.frame.fill(selected_bg).stroke(hover_stroke); @@ -269,9 +267,12 @@ impl SelectionPanels { //ui.visuals_mut().override_text_color = Some(Color32::WHITE); { let available_width = ui.available_width() - indent; - let title = - self.title - .into_galley(ui, Some(TextWrapMode::Wrap), available_width, TextStyle::Heading); + let title = self.title.into_galley( + ui, + Some(TextWrapMode::Wrap), + available_width, + TextStyle::Heading, + ); let text_indent = (available_width - title.size().x) / 2.0; let rect = ui.cursor().translate(Vec2::new(text_indent, 10.0)); ui.allocate_exact_size( diff --git a/core/src/imports.rs b/core/src/imports.rs index c3e7329..81f65b4 100644 --- a/core/src/imports.rs +++ b/core/src/imports.rs @@ -5,7 +5,7 @@ pub use kaspa_consensus_core::network::{NetworkId, NetworkType}; pub use kaspa_consensus_core::Hash as KaspaHash; pub use kaspa_metrics_core::MetricsSnapshot; pub use kaspa_rpc_core::api::rpc::RpcApi; -pub use kaspa_rpc_core::{RpcFeeEstimate,RpcFeerateBucket}; +pub use kaspa_rpc_core::{RpcFeeEstimate, RpcFeerateBucket}; pub use kaspa_utils::hex::{FromHex, ToHex}; pub use kaspa_utils::{hashmap::GroupExtension, networking::ContextualNetAddress}; pub use kaspa_wallet_core::prelude::{ diff --git a/core/src/runtime/services/feerate_monitor.rs b/core/src/runtime/services/feerate_monitor.rs index d6ff345..56dcf23 100644 --- a/core/src/runtime/services/feerate_monitor.rs +++ b/core/src/runtime/services/feerate_monitor.rs @@ -56,12 +56,13 @@ impl FeerateMonitorService { async fn fetch(self: &Arc) -> Result<()> { if let Some(rpc_api) = self.rpc_api() { if let Ok(resp) = rpc_api.get_fee_estimate().await { - // println!("{}",resp.priority_bucket.feerate); // let feerate = Arc::new(resp); // self.feerate.lock().unwrap().replace(feerate.clone()); self.application_events - .send(Events::Feerate { feerate : Some(Arc::new(resp)) }) + .send(Events::Feerate { + feerate: Some(Arc::new(resp)), + }) .await .unwrap(); } @@ -76,7 +77,6 @@ impl FeerateMonitorService { .await .unwrap(); } - } #[async_trait] @@ -97,7 +97,6 @@ impl Service for FeerateMonitorService { Ok(()) } - async fn spawn(self: Arc) -> Result<()> { // let this = self.clone(); // let application_events_sender = self.application_events.sender.clone(); diff --git a/core/src/utils/average.rs b/core/src/utils/average.rs index c35bdef..f460b8e 100644 --- a/core/src/utils/average.rs +++ b/core/src/utils/average.rs @@ -5,9 +5,9 @@ const AVERAGE_ALPHA_HIGH: f64 = 0.8; const AVERAGE_ALPHA_LOW: f64 = 0.5; pub struct FeerateEstimate { - pub low : FeerateBucketAverage, - pub economic : FeerateBucketAverage, - pub priority : FeerateBucketAverage, + pub low: FeerateBucketAverage, + pub economic: FeerateBucketAverage, + pub priority: FeerateBucketAverage, } impl Default for FeerateEstimate { @@ -21,7 +21,7 @@ impl Default for FeerateEstimate { } impl FeerateEstimate { - pub fn new(estimate : &RpcFeeEstimate) -> Self { + pub fn new(estimate: &RpcFeeEstimate) -> Self { let mut feerate = Self { low: FeerateBucketAverage::default(), economic: FeerateBucketAverage::default(), @@ -32,25 +32,33 @@ impl FeerateEstimate { } pub fn insert(&mut self, estimate: &RpcFeeEstimate) { - self.low.insert(estimate.low_buckets.first().map(FeerateBucket::from).unwrap_or_default()); - self.economic.insert(estimate.normal_buckets.first().map(FeerateBucket::from).unwrap_or_default()); + self.low.insert( + estimate + .low_buckets + .first() + .map(FeerateBucket::from) + .unwrap_or_default(), + ); + self.economic.insert( + estimate + .normal_buckets + .first() + .map(FeerateBucket::from) + .unwrap_or_default(), + ); self.priority.insert(estimate.priority_bucket.into()); } - } #[derive(Debug, Clone, Copy)] pub struct FeerateBucket { - pub feerate : f64, - pub seconds : f64, + pub feerate: f64, + pub seconds: f64, } impl FeerateBucket { pub fn new(feerate: f64, seconds: f64) -> Self { - Self { - feerate, - seconds, - } + Self { feerate, seconds } } } @@ -107,14 +115,12 @@ impl From for FeerateBucket { pub type FeerateBucketAverage = FeerateBucketAverageN; #[derive(Default, Debug, Clone)] -pub struct FeerateBucketAverageN -{ +pub struct FeerateBucketAverageN { pub samples: VecDeque, pub average: FeerateBucket, } -impl FeerateBucketAverageN -{ +impl FeerateBucketAverageN { pub fn clear(&mut self) { self.samples.clear(); self.average = FeerateBucket::default(); @@ -127,12 +133,16 @@ impl FeerateBucketAverageN let delta = self.average; if value > self.value() { - let feerate = AVERAGE_ALPHA_HIGH * value.feerate + (1.0 - AVERAGE_ALPHA_HIGH) * delta.feerate; - let seconds = AVERAGE_ALPHA_HIGH * value.seconds + (1.0 - AVERAGE_ALPHA_HIGH) * delta.seconds; + let feerate = + AVERAGE_ALPHA_HIGH * value.feerate + (1.0 - AVERAGE_ALPHA_HIGH) * delta.feerate; + let seconds = + AVERAGE_ALPHA_HIGH * value.seconds + (1.0 - AVERAGE_ALPHA_HIGH) * delta.seconds; self.samples.push_back(FeerateBucket::new(feerate, seconds)); } else { - let feerate = AVERAGE_ALPHA_LOW * value.feerate + (1.0 - AVERAGE_ALPHA_LOW) * delta.feerate; - let seconds = AVERAGE_ALPHA_LOW * value.seconds + (1.0 - AVERAGE_ALPHA_LOW) * delta.seconds; + let feerate = + AVERAGE_ALPHA_LOW * value.feerate + (1.0 - AVERAGE_ALPHA_LOW) * delta.feerate; + let seconds = + AVERAGE_ALPHA_LOW * value.seconds + (1.0 - AVERAGE_ALPHA_LOW) * delta.seconds; self.samples.push_back(FeerateBucket::new(feerate, seconds)); } } @@ -141,15 +151,17 @@ impl FeerateBucketAverageN self.samples.pop_front(); } self.update(); - } pub fn update(&mut self) { let len = self.samples.len() as f64; - let sum = self.samples.iter().fold(FeerateBucket::default(), |a, b| a + *b); + let sum = self + .samples + .iter() + .fold(FeerateBucket::default(), |a, b| a + *b); self.average = FeerateBucket { - feerate : sum.feerate / len, - seconds : sum.seconds / len, + feerate: sum.feerate / len, + seconds: sum.seconds / len, }; } @@ -160,7 +172,6 @@ impl FeerateBucketAverageN FeerateBucket::default() } } - } #[cfg(test)] @@ -169,8 +180,6 @@ mod test { #[test] fn test_average() { - - let values = [ 248155.3514557079, 215263.2471686213, @@ -491,8 +500,8 @@ mod test { let mut average = FeerateBucketAverageN::<6>::default(); for value in values.iter() { - average.insert(FeerateBucket::new(*value,1.0)); + average.insert(FeerateBucket::new(*value, 1.0)); println!("{} -> {:?}", value, average.value()); } } -} \ No newline at end of file +} diff --git a/core/src/utils/format.rs b/core/src/utils/format.rs index 12b8b04..5bc324a 100644 --- a/core/src/utils/format.rs +++ b/core/src/utils/format.rs @@ -201,7 +201,6 @@ pub fn precision_from_symbol(symbol: &str) -> usize { } } - // /// Format supplied value as a float with 2 decimal places. // fn format_as_float(f: f64, short: bool) -> String { // if short {