Skip to content

Commit

Permalink
Cherry-picked Cumulative PR for Wallet & Metrics Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
KashProtocol committed Jan 3, 2024
1 parent 962e7a9 commit a9772bf
Show file tree
Hide file tree
Showing 228 changed files with 13,035 additions and 5,329 deletions.
865 changes: 561 additions & 304 deletions Cargo.lock

Large diffs are not rendered by default.

52 changes: 33 additions & 19 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"daemon",
"cli",
"core",
"wallet/macros",
"wallet/core",
"wallet/native",
"wallet/wasm",
Expand Down Expand Up @@ -32,7 +33,6 @@ members = [
"rpc/grpc/core",
"rpc/grpc/client",
"rpc/grpc/server",
"rpc/wrpc/core",
"rpc/wrpc/server",
"rpc/wrpc/client",
"rpc/wrpc/proxy",
Expand All @@ -52,6 +52,7 @@ members = [
"utils/tower",
"rothschild",
"metrics/perf_monitor",
"metrics/core",
]

[workspace.package]
Expand All @@ -73,18 +74,18 @@ include = [

[workspace.dependencies]
# kash-testing-integration = { version = "0.13.1", path = "testing/integration" }
kash-os = { version = "0.13.1", path = "kash-os" }
kash-daemon = { version = "0.13.1", path = "daemon" }
kash-addresses = { version = "0.13.1", path = "crypto/addresses" }
kash-addressmanager = { version = "0.13.1", path = "components/addressmanager" }
kash-bip32 = { version = "0.13.1", path = "wallet/bip32" }
kash-cli = { version = "0.13.1", path = "cli" }
kash-connectionmanager = { version = "0.13.1", path = "components/connectionmanager" }
kash-consensus = { version = "0.13.1", path = "consensus" }
kash-consensus-core = { version = "0.13.1", path = "consensus/core" }
kash-consensus-notify = { version = "0.13.1", path = "consensus/notify" }
kash-consensus-wasm = { version = "0.13.1", path = "consensus/wasm" }
kash-consensusmanager = { version = "0.13.1", path = "components/consensusmanager" }
kash-core = { version = "0.13.1", path = "core" }
kash-daemon = { version = "0.13.1", path = "daemon" }
kash-database = { version = "0.13.1", path = "database" }
kash-grpc-client = { version = "0.13.1", path = "rpc/grpc/client" }
kash-grpc-core = { version = "0.13.1", path = "rpc/grpc/core" }
Expand All @@ -94,12 +95,15 @@ kash-index-core = { version = "0.13.1", path = "indexes/core" }
kash-index-processor = { version = "0.13.1", path = "indexes/processor" }
kash-math = { version = "0.13.1", path = "math" }
kash-merkle = { version = "0.13.1", path = "crypto/merkle" }
kash-metrics-core = { version = "0.13.0", path = "metrics/core" }
kash-mining = { version = "0.13.1", path = "mining" }
kash-mining-errors = { version = "0.13.1", path = "mining/errors" }
kash-muhash = { version = "0.13.1", path = "crypto/muhash" }
kash-notify = { version = "0.13.1", path = "notify" }
kash-os = { version = "0.13.1", path = "kash-os" }
kash-p2p-flows = { version = "0.13.1", path = "protocol/flows" }
kash-p2p-lib = { version = "0.13.1", path = "protocol/p2p" }
kash-perf-monitor = { version = "0.13.1", path = "metrics/perf_monitor" }
kash-pow = { version = "0.13.1", path = "consensus/pow" }
kash-rpc-core = { version = "0.13.1", path = "rpc/core" }
kash-rpc-macros = { version = "0.13.1", path = "rpc/macros" }
Expand All @@ -110,20 +114,20 @@ kash-utils = { version = "0.13.1", path = "utils" }
kash-utils-tower = { version = "0.13.1", path = "utils/tower" }
kash-utxoindex = { version = "0.13.1", path = "indexes/utxoindex" }
kash-wallet = { version = "0.13.1", path = "wallet/native" }
kash-cli = { version = "0.13.1", path = "cli" }
kash-wallet-cli-wasm = { version = "0.13.1", path = "wallet/wasm" }
kash-wallet-core = { version = "0.13.1", path = "wallet/core" }
kash-wallet-macros = { version = "0.13.0", path = "wallet/macros" }
kash-wasm = { version = "0.13.1", path = "wasm" }
kash-wrpc-core = { version = "0.13.1", path = "rpc/wrpc/core" }
kash-wrpc-client = { version = "0.13.1", path = "rpc/wrpc/client" }
kash-wrpc-core = { version = "0.13.1", path = "rpc/wrpc/core" }
kash-wrpc-proxy = { version = "0.13.1", path = "rpc/wrpc/proxy" }
kash-wrpc-server = { version = "0.13.1", path = "rpc/wrpc/server" }
kash-wrpc-wasm = { version = "0.13.1", path = "rpc/wrpc/wasm" }
kashd = { version = "0.13.1", path = "kashd" }
kash-perf-monitor = { version = "0.13.1", path = "metrics/perf_monitor" }

# external
aes = "0.8.3"
ahash = "0.8.6"
argon2 = "0.5.2"
async-channel = "2.0.0"
async-std = { version = "1.12.0", features = ['attributes'] }
Expand Down Expand Up @@ -155,11 +159,10 @@ enum-primitive-derive = "0.2.2"
event-listener = "2.5.3" # TODO "3.0.1"
evpkdf = "0.2.0"
faster-hex = "0.6.1" # TODO "0.8.1" - fails unit tests
fixedstr = { version = "0.5.4", features = ["serde"] }
flate2 = "1.0.28"
futures = { version = "0.3.29" }
futures-util = { version = "0.3.29", default-features = false, features = [
"alloc",
] }
futures-util = { version = "0.3.29", default-features = false, features = [ "alloc", ] }
getrandom = { version = "0.2.10", features = ["js"] }
h2 = "0.3.21"
heapless = "0.7.16"
Expand Down Expand Up @@ -243,16 +246,16 @@ hyper = "0.14.27"
workflow-perf-monitor = { version = "0.0.2" }

# workflow dependencies
workflow-d3 = { version = "0.8.1" }
workflow-nw = { version = "0.8.1" }
workflow-log = { version = "0.8.1" }
workflow-core = { version = "0.8.1" }
workflow-wasm = { version = "0.8.1" }
workflow-dom = { version = "0.8.1" }
workflow-rpc = { version = "0.8.1" }
workflow-node = { version = "0.8.1" }
workflow-store = { version = "0.8.1" }
workflow-terminal = { version = "0.8.1" }
workflow-d3 = { version = "0.10.2" }
workflow-nw = { version = "0.10.2" }
workflow-log = { version = "0.10.2" }
workflow-core = { version = "0.10.2" }
workflow-wasm = { version = "0.10.2" }
workflow-dom = { version = "0.10.2" }
workflow-rpc = { version = "0.10.2" }
workflow-node = { version = "0.10.2" }
workflow-store = { version = "0.10.2" }
workflow-terminal = { version = "0.10.2" }
nw-sys = "0.1.6"

# if below is enabled, this means that there is an ongoing work
Expand All @@ -268,6 +271,17 @@ nw-sys = "0.1.6"
# workflow-node = { path = "../workflow-rs/node" }
# workflow-store = { path = "../workflow-rs/store" }
# workflow-terminal = { path = "../workflow-rs/terminal" }
# ---
# workflow-d3 = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master" }
# workflow-nw = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master" }
# workflow-log = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master" }
# workflow-core = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master" }
# workflow-wasm = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master" }
# workflow-dom = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master" }
# workflow-rpc = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master" }
# workflow-node = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master" }
# workflow-store = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master" }
# workflow-terminal = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master" }
# https://github.com/aspectron/nw-sys
# nw-sys = { path = "../nw-sys" }

Expand Down
1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ kash-bip32.workspace = true
kash-consensus-core.workspace = true
kash-core.workspace = true
kash-daemon.workspace = true
kash-metrics-core.workspace = true
kash-rpc-core.workspace = true
kash-utils.workspace = true
kash-wallet-core.workspace = true
Expand Down
102 changes: 62 additions & 40 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
use crate::error::Error;
use crate::helpers::*;
use crate::imports::*;
pub use crate::metrics;
use crate::modules::miner::Miner;
use crate::modules::node::Node;
use crate::notifier::{Notification, Notifier};
use crate::result::Result;
use kash_daemon::{DaemonEvent, DaemonKind, Daemons};
use kash_wallet_core::rpc::DynRpcApi;
use kash_wallet_core::runtime::{Account, BalanceStrings};
use kash_wallet_core::storage::{IdT, PrvKeyDataInfo};
use kash_wallet_core::{runtime::Wallet, Events};
use kash_wrpc_client::KashRpcClient;
use workflow_core::channel::*;
use workflow_core::time::Instant;
Expand Down Expand Up @@ -192,6 +189,7 @@ impl KashCli {
}

pub fn register_metrics(self: &Arc<Self>) -> Result<()> {
use crate::modules::metrics;
register_handlers!(self, self.handlers(), [metrics]);
Ok(())
}
Expand Down Expand Up @@ -282,6 +280,7 @@ impl KashCli {

if let Ok(msg) = msg {
match *msg {
Events::Error { message } => { terrorln!(this,"{message}"); },
Events::UtxoProcStart => {},
Events::UtxoProcStop => {},
Events::UtxoProcError { message } => {
Expand Down Expand Up @@ -336,95 +335,117 @@ impl KashCli {

},
Events::AccountSelection { .. } => { },
Events::WalletCreate { .. } => { },
Events::WalletError { .. } => { },
Events::WalletOpen |
Events::WalletReload => {

// load all accounts
if let Err(err) = this.wallet().activate_all_stored_accounts().await {
terrorln!(this, "{err}");
}
// Events::WalletReady { .. } => { },

Events::WalletOpen { .. } |
Events::WalletReload { .. } => { },
Events::WalletClose => {
this.term().refresh_prompt();
},
Events::PrvKeyDataCreate { .. } => { },
Events::AccountDeactivation { .. } => { },
Events::AccountActivation { .. } => {
// list all accounts
this.list().await.unwrap_or_else(|err|terrorln!(this, "{err}"));

// load default account if only one account exists
this.wallet().autoselect_default_account_if_single().await.ok();
this.term().refresh_prompt();

},
Events::WalletClose => {
this.term().refresh_prompt();
},
Events::AccountCreate { .. } => { },
Events::AccountUpdate { .. } => { },
Events::DAAScoreChange { current_daa_score } => {
if this.is_mutted() && this.flags.get(Track::Daa) {
tprintln!(this, "{NOTIFY} DAA: {current_daa_score}");
}
},
Events::Discovery { .. } => { }
Events::Reorg {
record
} => {
if !this.is_mutted() || (this.is_mutted() && this.flags.get(Track::Pending)) {
let include_utxos = this.flags.get(Track::Utxo);
let tx = record.format_with_state(&this.wallet,Some("reorg"),include_utxos).await;
let tx = record.format_transaction_with_state(&this.wallet,Some("reorg"),include_utxos).await;
tx.iter().for_each(|line|tprintln!(this,"{NOTIFY} {line}"));
}
},
Events::External {
Events::Stasis {
record
} => {
if !this.is_mutted() || (this.is_mutted() && this.flags.get(Track::Tx)) {
// Pending and coinbase stasis fall under the same `Track` category
if !this.is_mutted() || (this.is_mutted() && this.flags.get(Track::Pending)) {
let include_utxos = this.flags.get(Track::Utxo);
let tx = record.format_with_state(&this.wallet,Some("external"),include_utxos).await;
let tx = record.format_transaction_with_state(&this.wallet,Some("stasis"),include_utxos).await;
tx.iter().for_each(|line|tprintln!(this,"{NOTIFY} {line}"));
}
},
// Events::External {
// record
// } => {
// if !this.is_mutted() || (this.is_mutted() && this.flags.get(Track::Tx)) {
// let include_utxos = this.flags.get(Track::Utxo);
// let tx = record.format_with_state(&this.wallet,Some("external"),include_utxos).await;
// tx.iter().for_each(|line|tprintln!(this,"{NOTIFY} {line}"));
// }
// },
Events::Pending {
record, is_outgoing : _
record
} => {
if !this.is_mutted() || (this.is_mutted() && this.flags.get(Track::Pending)) {
let include_utxos = this.flags.get(Track::Utxo);
let tx = record.format_with_state(&this.wallet,Some("pending"),include_utxos).await;
let tx = record.format_transaction_with_state(&this.wallet,Some("pending"),include_utxos).await;
tx.iter().for_each(|line|tprintln!(this,"{NOTIFY} {line}"));
}
},
Events::Maturity {
record, is_outgoing : _
} => {
if !this.is_mutted() || (this.is_mutted() && this.flags.get(Track::Tx)) {
let include_utxos = this.flags.get(Track::Utxo);
let tx = record.format_with_state(&this.wallet,Some("confirmed"),include_utxos).await;
tx.iter().for_each(|line|tprintln!(this,"{NOTIFY} {line}"));
}
},
Events::Outgoing {
record
} => {
if !this.is_mutted() || (this.is_mutted() && this.flags.get(Track::Tx)) {
let include_utxos = this.flags.get(Track::Utxo);
let tx = record.format_with_state(&this.wallet,Some("confirmed"),include_utxos).await;
let tx = record.format_transaction_with_state(&this.wallet,Some("confirmed"),include_utxos).await;
tx.iter().for_each(|line|tprintln!(this,"{NOTIFY} {line}"));
}
},
// Events::Outgoing {
// record
// } => {
// if !this.is_mutted() || (this.is_mutted() && this.flags.get(Track::Tx)) {
// let include_utxos = this.flags.get(Track::Utxo);
// let tx = record.format_with_state(&this.wallet,Some("confirmed"),include_utxos).await;
// tx.iter().for_each(|line|tprintln!(this,"{NOTIFY} {line}"));
// }
// },
// Events::Change {
// record
// } => {
// if !this.is_mutted() || (this.is_mutted() && this.flags.get(Track::Tx)) {
// let include_utxos = this.flags.get(Track::Utxo);
// let tx = record.format_with_state(&this.wallet,Some("change"),include_utxos).await;
// tx.iter().for_each(|line|tprintln!(this,"{NOTIFY} {line}"));
// }
// },
Events::Balance {
balance,
id,
mature_utxo_size,
pending_utxo_size,
} => {

if !this.is_mutted() || (this.is_mutted() && this.flags.get(Track::Balance)) {
let network_id = this.wallet.network_id().expect("missing network type");
let network_type = NetworkType::from(network_id);
let balance = BalanceStrings::from((&balance,&network_type, None));
let balance_strings = BalanceStrings::from((&balance,&network_type, None));
let id = id.short();

let pending_utxo_info = if pending_utxo_size > 0 {
format!("({pending_utxo_size} pending)")
let mature_utxo_count = balance.as_ref().map(|balance|balance.mature_utxo_count.separated_string()).unwrap_or("N/A".to_string());
let pending_utxo_count = balance.as_ref().map(|balance|balance.pending_utxo_count).unwrap_or(0);

let pending_utxo_info = if pending_utxo_count > 0 {
format!("({} pending)", pending_utxo_count)
} else { "".to_string() };
let utxo_info = style(format!("{} UTXOs {pending_utxo_info}", mature_utxo_size.separated_string())).dim();
let utxo_info = style(format!("{mature_utxo_count} UTXOs {pending_utxo_info}")).dim();

tprintln!(this, "{NOTIFY} {} {id}: {balance} {utxo_info}",style("balance".pad_to_width(8)).blue());
tprintln!(this, "{NOTIFY} {} {id}: {balance_strings} {utxo_info}",style("balance".pad_to_width(8)).blue());
}

this.term().refresh_prompt();
Expand Down Expand Up @@ -757,9 +778,10 @@ impl Cli for KashCli {
}
}

if let Some(name) = self.wallet.name() {
if name != "kash" {
prompt.push(name);
if let Some(descriptor) = self.wallet.descriptor() {
let title = descriptor.title.unwrap_or(descriptor.filename);
if title.to_lowercase().as_str() != "kash" {
prompt.push(title);
}

if let Ok(account) = self.wallet.account() {
Expand Down
3 changes: 3 additions & 0 deletions cli/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ pub enum Error {

#[error("private key {0} already exists")]
PrivateKeyAlreadyExists(String),

#[error(transparent)]
MetricsError(kash_metrics_core::error::Error),
}

impl Error {
Expand Down
2 changes: 2 additions & 0 deletions cli/src/extensions/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod transaction;
pub use transaction::*;
Loading

0 comments on commit a9772bf

Please sign in to comment.