Skip to content

Commit

Permalink
Cumulative PR for Wallet & Metrics Refactoring (#360)
Browse files Browse the repository at this point in the history
* external access to kaspad core rpc services API

* rename wallet event members for serde serialization
misc wallet functionality update

* wip - event renaming

* wip - event serialization tuneup

* remove default wrpc listening ports on kaspad Args + fix port mapping bug for automatic JSON RPC port mapping.

* Box wallet events

* introduce RpcCtl + isolate wRPC from DynRpcApi

* debug trait for secret

* de-couple wRPC from the runtiem wallet making RPC bindings generic

* convert wallet_list to return Vec<WalletDescriptor>

* user-friendly error message on decryption error

* UtxoProcessor - ignore task shutdown if not running

* wallet storage data versioning

* wallet - propagate wallet title

* sort traits on WalletDescriptor

* wallet - use precise decimal conversion when parsing strings to sompi

* display kaspa on get-balance-by-address-rpc

* wallet - rename settings fns to have try_ prefixes

* rename library names "kaspad" and "kaspa_cli" to "kaspad_lib" and "kaspa_cli_lib" to prevent build collisions

* no-unsafe-eval feature

* allow for chrome-extension schema in the RPC url

* wallet - expose bip32 wordlist for external access

* wallet - delegate rpc ownership to utxo_processor; reorder rpc disconnect to occur before utxo_processor shutdown;

* wallet - migrate wallet settings loading to cli

* rename RpcCtlOp (Open, Close) to RpcState (Opened, Closed)

* remove automatic RPC disconnect from wallet stop() to allow retention of the RPC channel after closing the wallet

* allow UtxoProcessor to bind to an already existing/connected RPC channel, allow retention of a connected RPC channel past UtxoProcessor shutdown. (API centric defensive functionality)

* code formatting

* fix clippy warnings

* migrate chrome-extension to use ws:// schema by default

* wallet list formatting

* staging for WRS 0.7.0

* add bip32 word list iterator

* update WRS to 0.7.0

* fix rustdoc errors

* wip - initial WalletApi trait implementation

* wallet - macros and account descriptors

* wallet - ping_call

* cleanup

* wip - wallet api cleanup & testing

* kaspa-metrics as a separate crate

* wip - metrics cleanup

* cargo.lock update

* async/sync api  changes for storage

* merge

* master merge

* wip

* wip

* wip

* wallet - (wip) changes to AccountDescriptor and Wallet API

* metrics - make sink future return as optional

* wip - refactor wallet open; improve wallet event ordering; cleanup

* wip (debugging UtxoChanged notifications) - fix issuance during failed tx

* adding workflow-rs as github dependency (allows CI)

* revert github deps for WRS

* metrics

* refactor metrics to include bdi counts and peer counts

* wallet api updates
refactoring transaction access interface
misc updates to wallet APIs
refactor wallet open sequence
refactor legacy accounts

* wallet framework - fix a but resulting in the early issuane of UTXO maturity events.
Refactor handling of outgoing transaction UTXOs (sending outgoing tx ACKs on UtxoChange removal), minor fixes in the Transaction file-system storage.  Add "outgoing" property to account balances (to track in-flight transactions being submitted until acceptance). Introduce new Events::Change that gets fired specifically when receiving change of the currently outgoing transaction. Initial steps toward Daa property wrapper.

* npm 0.13.0

* metrics - cleanup after RPC refactoring

* rename rust-side of wasm bindings as naming conventions interfere with rust use (make fns more explicitly named)

* make metrics data formatting fns as pub

* expose log levels in kaspa-core::log

* rename metrics & improve metrics fetch task

* add API calls to pre-configure wallet framework stroage folders

* cumulative updates for Cargo.lock

* Improve address error messages for human readability

* PrvKeyData enumeration, initial account transfer support (wip), wallet descriptor handling

* wallet - change error to retain PrvKeyDataId instead of a String

* propagate bip39 flag to runtime account and it's descriptor

* wip - keydata refactoring

* metrics refactoring (bandwidth)

* wip (cleanup)

* misc improvements to metrics

* code formatting

* wRPC bandwidth monitoring + scaffolding for global bandwidth metrics

* bump WRS to 0.9.0

* metrics - add mempool_size and convert some items to u32/f32

* metrics cleanup

* wallet and account rename, remove "title" from accounts

* add missing mempool size metric

* UTXO "stasis" mode for new coinbase transactions

* remove useless Option from the rpc url parser

* fix daa score in maturity state check

* add name_or_id to PrvKeyDataInfo

* wallet RPC Connect/Disconnect and GetStatus API calls

* cleanup

* support for 12-word bip39 mnemonics

* add a hidden --daemon flag to kaspad

* refactor get_daa_score_timestamp helper to return Vec<u64> instead of Response struct

* Add Scan event

* implement support for unixtime in transactions

* kaspa value formatting functions

* fix a deadlock due to re-entrant mutex lock when loading multiple accounts from storage

* introduce utxo stasis mode + make balance carry utxo counts as well as the totals

* refactor wallet events, replace reset() with close() where appropriate

* manual debug impl for tx components (display script as hex, address as address etc)

* fix incorrect gas assignment in WASM bindings

* updates for wallet event handling

* refactor sign_with_multiple to return Err(tx) when partially signed

* refactor Storage and Wallet descriptors

* fix account derivation index handling in DerivationCapable

* track acceptance DAA stamp in outgoing transaction record

* temporary harness for embedding script engine directly into tx generator (used for debugging)

* convert PendingTransaction Utxo entries into HashSet

* rename pending tx fns

* outgoing tx wrapper around pending tx

* refactor notification events during wallet ops

* as_ref() for PrvKeyData

* wip - initial RpcCoreMocks for wallet framework tests

* wallet api messages update for StorageDescriptor usage

* update AddressDerivationMeta to track addresses from index 0

* add AHash and async_channel to wallet_core crate

* allow Args to be used externally for daemon argument pre-validation

* impl Hash for UtxoEntryReference and rename "fake()" to "simulated()"

* update wallet events

* expose tx validator check_scripts() as pub

* update wallet wasm fns for wallet and storage descriptors

* rename kaspa-metrics to kaspa-metrics-core

* code formatting

* code formatting

* migrate transaction console formatting to cli/extensions

* refactor wallet events

* use ahash for faster processing in wallet hash maps (utxo context)

* wallet - add SendError handling for error::Error

* wallet event refactoring, scan/discovery process refactoring, wallet change secret api handling

* refactoring: transfer and deep derivation scan

* transaction record refactoring

* wallet - support for cross-account transfers in generator

* wallet - outgoing transaction impl

* wallet - refactor maturity handling

* wallet/utxo - initial tests scaffolding

* minor optimization of the discovery/scan process

* wallet - utxo processor outgoing tx and discovery timestamp unixtime handling

* refactor utxo context to use output transactions, refactor transfers, compound and change notifications

* code formatting + Cargo.lock update

* Signed enum to represent Fully or Partially signed tx

* bind p2p and grpc bandwidth metrics

* misc clippy fixes

* cleanup

* remove --daemon as Args::parse() offers external mutations

* remove previously implemented mnemonic variant in favor of client-side mnemonic creation

* remove AccessContextT, convert to wallet_secret, wip WalletApi traits, refactor account args

* code formatting

* separate runtime wallet into multiple modules

* wallet - revert create_accounts to process a single account at a time

* cleanup

* wallet - JSON import and export + preliminary docs

* address - AddressList - fix TryFrom deadlock caused by recursive trait invocation

* wallet - api rustdoc + cleanup, transaction calls

* wallet docs

* change address debug formatting

* adding cli rpc addpeer

* wip - wallet restructuring

* wip - restructure wallet modules

* wip - wallet restructuring - cleanup

* wip - AccountKind refactoring

* wallet - refactoring storage serialization & encryption

* fold in PR #349

* wallet framework - misc helper fns and cleanup

* storage unit tests + prv key data module restructuring

* wallet - account factory registrations

* Remove panics caused by sudden loss of connection while submitting transactions.

* cleanup

* cleanup

* cleanup + docs

* docs

* adjust metrics formatting

* cleanup

* bump workflow-rs to 0.10.1

* fix wallet storage unit tests

* fix generator unit tests

* convert missing listener_id panic to error

* docs

* code formatting

* lints

* misc updates following github reviews

* refactor AccountKind to use fixedstr and implement Copy

* refactor AccountKind to use fixedstr (str64) and re-implement Copy, removing clone() where necessary

* change js-bound fn names from *as* to *to* to follow Rust conventions

* replace AssocPrvKeyDataIds iter().any() to contains()

* remove vec![] in MetricsGroup iterator fn; add TODO comment on Metric::group()

* scope magic numbers within their associated structs

* add try_fully_signed() and try_partially_signed() fns to Signed that allow recovery of the tx

* refactor local storage cache to use RwLock instead of a Mutex

* refactor serialization as per github feedback (partial trait impl)

* Optimize AssocPrvKeyDataIds to use Either in the IntoIter impl, removing allocations.

* Refactor to bypass aux buffer creation when storing wallet on native platforms.

* impl custom Debug for storage structs to display data in hex

* adding misc SAFETY comments on unsafe ops

* TODO comments for later SignerT+multisig refactoring

* Change panic!() to unreachable!() to make it clearer that a state should not be reached.

* rename TransactionRecord::unixtime to unixtime_msec

* fix wrong references in comments

* Fix min_cosigner_index handling in multisig fns

* add comments to UtxoContext::insert() error handling

* bind AccountStorable:Storable for AccountStorage, migrate Storable into a separate module, add comments to MAGIC values in some locations

* make framework init functions unsafe

* update workflow-rs to 0.10.2

* fix comments

* fix data cloning when getting collection counts

* adding TODO notes to wasm macros and KAS value decimal parsing

---------

Co-authored-by: Surinder Singh Matoo <[email protected]>
  • Loading branch information
aspect and surinder83singh authored Dec 26, 2023
1 parent 10d0ebf commit b6f7e09
Show file tree
Hide file tree
Showing 221 changed files with 12,941 additions and 5,285 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]
# kaspa-testing-integration = { version = "0.13.1", path = "testing/integration" }
kaspa-os = { version = "0.13.1", path = "kaspa-os" }
kaspa-daemon = { version = "0.13.1", path = "daemon" }
kaspa-addresses = { version = "0.13.1", path = "crypto/addresses" }
kaspa-addressmanager = { version = "0.13.1", path = "components/addressmanager" }
kaspa-bip32 = { version = "0.13.1", path = "wallet/bip32" }
kaspa-cli = { version = "0.13.1", path = "cli" }
kaspa-connectionmanager = { version = "0.13.1", path = "components/connectionmanager" }
kaspa-consensus = { version = "0.13.1", path = "consensus" }
kaspa-consensus-core = { version = "0.13.1", path = "consensus/core" }
kaspa-consensus-notify = { version = "0.13.1", path = "consensus/notify" }
kaspa-consensus-wasm = { version = "0.13.1", path = "consensus/wasm" }
kaspa-consensusmanager = { version = "0.13.1", path = "components/consensusmanager" }
kaspa-core = { version = "0.13.1", path = "core" }
kaspa-daemon = { version = "0.13.1", path = "daemon" }
kaspa-database = { version = "0.13.1", path = "database" }
kaspa-grpc-client = { version = "0.13.1", path = "rpc/grpc/client" }
kaspa-grpc-core = { version = "0.13.1", path = "rpc/grpc/core" }
Expand All @@ -94,12 +95,15 @@ kaspa-index-core = { version = "0.13.1", path = "indexes/core" }
kaspa-index-processor = { version = "0.13.1", path = "indexes/processor" }
kaspa-math = { version = "0.13.1", path = "math" }
kaspa-merkle = { version = "0.13.1", path = "crypto/merkle" }
kaspa-metrics-core = { version = "0.13.0", path = "metrics/core" }
kaspa-mining = { version = "0.13.1", path = "mining" }
kaspa-mining-errors = { version = "0.13.1", path = "mining/errors" }
kaspa-muhash = { version = "0.13.1", path = "crypto/muhash" }
kaspa-notify = { version = "0.13.1", path = "notify" }
kaspa-os = { version = "0.13.1", path = "kaspa-os" }
kaspa-p2p-flows = { version = "0.13.1", path = "protocol/flows" }
kaspa-p2p-lib = { version = "0.13.1", path = "protocol/p2p" }
kaspa-perf-monitor = { version = "0.13.1", path = "metrics/perf_monitor" }
kaspa-pow = { version = "0.13.1", path = "consensus/pow" }
kaspa-rpc-core = { version = "0.13.1", path = "rpc/core" }
kaspa-rpc-macros = { version = "0.13.1", path = "rpc/macros" }
Expand All @@ -110,20 +114,20 @@ kaspa-utils = { version = "0.13.1", path = "utils" }
kaspa-utils-tower = { version = "0.13.1", path = "utils/tower" }
kaspa-utxoindex = { version = "0.13.1", path = "indexes/utxoindex" }
kaspa-wallet = { version = "0.13.1", path = "wallet/native" }
kaspa-cli = { version = "0.13.1", path = "cli" }
kaspa-wallet-cli-wasm = { version = "0.13.1", path = "wallet/wasm" }
kaspa-wallet-core = { version = "0.13.1", path = "wallet/core" }
kaspa-wallet-macros = { version = "0.13.0", path = "wallet/macros" }
kaspa-wasm = { version = "0.13.1", path = "wasm" }
kaspa-wrpc-core = { version = "0.13.1", path = "rpc/wrpc/core" }
kaspa-wrpc-client = { version = "0.13.1", path = "rpc/wrpc/client" }
kaspa-wrpc-core = { version = "0.13.1", path = "rpc/wrpc/core" }
kaspa-wrpc-proxy = { version = "0.13.1", path = "rpc/wrpc/proxy" }
kaspa-wrpc-server = { version = "0.13.1", path = "rpc/wrpc/server" }
kaspa-wrpc-wasm = { version = "0.13.1", path = "rpc/wrpc/wasm" }
kaspad = { version = "0.13.1", path = "kaspad" }
kaspa-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 @@ kaspa-bip32.workspace = true
kaspa-consensus-core.workspace = true
kaspa-core.workspace = true
kaspa-daemon.workspace = true
kaspa-metrics-core.workspace = true
kaspa-rpc-core.workspace = true
kaspa-utils.workspace = true
kaspa-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 kaspa_daemon::{DaemonEvent, DaemonKind, Daemons};
use kaspa_wallet_core::rpc::DynRpcApi;
use kaspa_wallet_core::runtime::{Account, BalanceStrings};
use kaspa_wallet_core::storage::{IdT, PrvKeyDataInfo};
use kaspa_wallet_core::{runtime::Wallet, Events};
use kaspa_wrpc_client::KaspaRpcClient;
use workflow_core::channel::*;
use workflow_core::time::Instant;
Expand Down Expand Up @@ -192,6 +189,7 @@ impl KaspaCli {
}

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 KaspaCli {

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 KaspaCli {

},
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 KaspaCli {
}
}

if let Some(name) = self.wallet.name() {
if name != "kaspa" {
prompt.push(name);
if let Some(descriptor) = self.wallet.descriptor() {
let title = descriptor.title.unwrap_or(descriptor.filename);
if title.to_lowercase().as_str() != "kaspa" {
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(kaspa_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 b6f7e09

Please sign in to comment.