Skip to content

Commit df42043

Browse files
committed
fix added change
1 parent db130b4 commit df42043

9 files changed

Lines changed: 436 additions & 311 deletions

File tree

wallet/src/account/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ impl<K: AccountKeyChains> Account<K> {
444444
selection_result = selection_result.add_change(
445445
(total_fees_not_paid - new_total_fees_not_paid).unwrap_or(Amount::ZERO),
446446
)?;
447+
let change_amount = selection_result.get_change();
447448
let change_output = match pay_fee_with_currency {
448449
Currency::Coin => make_address_output(change_address.clone(), change_amount),
449450
Currency::Token(token_id) => {

wallet/types/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ pub use currency::Currency;
3737
pub use keys::{KeyPurpose, KeychainUsageState, RootKeys};
3838
pub use wallet_tx::{BlockInfo, WalletTx};
3939

40+
use std::collections::BTreeMap;
41+
4042
use common::{
4143
chain::{SignedTransaction, Transaction},
4244
primitives::Amount,
4345
};
44-
use std::collections::BTreeMap;
4546

4647
#[derive(Debug, Clone, PartialEq, Eq)]
4748
pub struct SignedTxWithFees {

wallet/wallet-cli-commands/src/command_handler/mod.rs

Lines changed: 63 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,7 @@ where
139139
id_to_hex_string(*new_tx.tx_id.as_hash())
140140
)
141141
} else {
142-
let hex = new_tx.tx.to_string();
143-
let mut summary = new_tx.tx.take().transaction().text_summary(chain_config);
144-
format_fees(&mut summary, &new_tx.fees);
145-
146-
format!("{summary}\nThe transaction was created and is ready to be submitted:\n{hex}",)
142+
format_tx_to_be_broadcasted(new_tx.tx, &new_tx.fees, chain_config)
147143
};
148144

149145
ConsoleCommand::Print(status_text)
@@ -1157,11 +1153,17 @@ where
11571153
)
11581154
.await?;
11591155

1160-
Ok(ConsoleCommand::Print(format!(
1161-
"A new token has been issued with ID: {} in tx: {}",
1162-
new_token.token_id,
1163-
id_to_hex_string(*new_token.tx_id.as_hash())
1164-
)))
1156+
let result = if new_token.broadcasted {
1157+
format!(
1158+
"A new token has been issued with ID: {} in tx: {}",
1159+
new_token.token_id,
1160+
id_to_hex_string(*new_token.tx_id.as_hash())
1161+
)
1162+
} else {
1163+
format_tx_to_be_broadcasted(new_token.tx, &new_token.fees, chain_config)
1164+
};
1165+
1166+
Ok(ConsoleCommand::Print(result))
11651167
}
11661168

11671169
WalletCommand::IssueNewNft {
@@ -1191,11 +1193,17 @@ where
11911193
.issue_new_nft(selected_account, destination_address, metadata, self.config)
11921194
.await?;
11931195

1194-
Ok(ConsoleCommand::Print(format!(
1195-
"A new NFT has been issued with ID: {} in tx: {}",
1196-
new_token.token_id,
1197-
id_to_hex_string(*new_token.tx_id.as_hash())
1198-
)))
1196+
let result = if new_token.broadcasted {
1197+
format!(
1198+
"A new NFT has been issued with ID: {} in tx: {}",
1199+
new_token.token_id,
1200+
id_to_hex_string(*new_token.tx_id.as_hash())
1201+
)
1202+
} else {
1203+
format_tx_to_be_broadcasted(new_token.tx, &new_token.fees, chain_config)
1204+
};
1205+
1206+
Ok(ConsoleCommand::Print(result))
11991207
}
12001208

12011209
WalletCommand::MintTokens {
@@ -1670,30 +1678,43 @@ where
16701678

16711679
WalletCommand::CreateDelegation { owner, pool_id } => {
16721680
let (wallet, selected_account) = wallet_and_selected_acc(&mut self.wallet).await?;
1673-
let delegation_id = wallet
1674-
.create_delegation(selected_account, owner, pool_id, self.config)
1675-
.await?
1676-
.delegation_id;
1681+
let new_delegation =
1682+
wallet.create_delegation(selected_account, owner, pool_id, self.config).await?;
16771683

1678-
Ok(ConsoleCommand::Print(format!(
1679-
"Success, the creation of delegation transaction was broadcast to the network. Delegation id: {}",
1680-
delegation_id
1681-
)))
1684+
let result = if new_delegation.broadcasted {
1685+
format!(
1686+
"Success, the creation of delegation transaction was broadcast to the network. Delegation id: {} in tx: {}",
1687+
new_delegation.delegation_id,
1688+
id_to_hex_string(*new_delegation.tx_id.as_hash())
1689+
)
1690+
} else {
1691+
format_tx_to_be_broadcasted(
1692+
new_delegation.tx,
1693+
&new_delegation.fees,
1694+
chain_config,
1695+
)
1696+
};
1697+
1698+
Ok(ConsoleCommand::Print(result))
16821699
}
16831700

16841701
WalletCommand::DelegateStaking {
16851702
amount,
16861703
delegation_id,
16871704
} => {
16881705
let (wallet, selected_account) = wallet_and_selected_acc(&mut self.wallet).await?;
1689-
wallet
1706+
let new_tx = wallet
16901707
.delegate_staking(selected_account, amount, delegation_id, self.config)
16911708
.await?;
16921709

1693-
Ok(ConsoleCommand::Print(
1710+
let result = if new_tx.broadcasted {
16941711
"Success, the delegation staking transaction was broadcast to the network"
1695-
.to_owned(),
1696-
))
1712+
.to_owned()
1713+
} else {
1714+
format_tx_to_be_broadcasted(new_tx.tx, &new_tx.fees, chain_config)
1715+
};
1716+
1717+
Ok(ConsoleCommand::Print(result))
16971718
}
16981719

16991720
WalletCommand::WithdrawFromDelegation {
@@ -1702,7 +1723,7 @@ where
17021723
delegation_id,
17031724
} => {
17041725
let (wallet, selected_account) = wallet_and_selected_acc(&mut self.wallet).await?;
1705-
wallet
1726+
let new_tx = wallet
17061727
.withdraw_from_delegation(
17071728
selected_account,
17081729
address,
@@ -1711,9 +1732,8 @@ where
17111732
self.config,
17121733
)
17131734
.await?;
1714-
Ok(ConsoleCommand::Print(
1715-
"Success. The transaction was broadcast to the network".to_owned(),
1716-
))
1735+
1736+
Ok(Self::new_tx_command(new_tx, chain_config))
17171737
}
17181738

17191739
WalletCommand::CreateStakePool {
@@ -1953,6 +1973,18 @@ where
19531973
}
19541974
}
19551975

1976+
fn format_tx_to_be_broadcasted(
1977+
tx: HexEncoded<SignedTransaction>,
1978+
fees: &Balances,
1979+
chain_config: &ChainConfig,
1980+
) -> String {
1981+
let hex = tx.to_string();
1982+
let mut summary = tx.take().transaction().text_summary(chain_config);
1983+
format_fees(&mut summary, fees);
1984+
1985+
format!("{summary}\nThe transaction was created and is ready to be submitted:\n{hex}")
1986+
}
1987+
19561988
fn format_signature_status((idx, status): (usize, &RpcSignatureStatus)) -> String {
19571989
let status = match status {
19581990
RpcSignatureStatus::FullySigned => "FullySigned".to_owned(),

wallet/wallet-cli-commands/src/lib.rs

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,9 @@ pub enum WalletCommand {
302302
#[command(flatten)]
303303
ColdCommands(ColdWalletCommand),
304304

305-
/// Configure broadcasting to Mempool to true or false.
305+
/// Configure broadcasting to Mempool to yes or no.
306306
///
307-
/// If set to false, any command that creates a transaction will return it to the user and not submit it automatically.
307+
/// If set to no, any command that creates a transaction will return it to the user and not submit it automatically.
308308
/// The transaction will need to be submitted manually with the command `node-submit-transaction`.
309309
///
310310
/// The effect of this is not preserved when the CLI wallet is closed.
@@ -559,6 +559,13 @@ pub enum WalletCommand {
559559
},
560560

561561
#[clap(name = "address-sweep-spendable")]
562+
/// Sweep all spendable coins or tokens from an address or addresses specified in `addresses`
563+
/// or all addresses from this account if all is set to true, to the given destination address.
564+
/// Either 1 or more addresses need to be specified in `addresses` without `all` being set, or
565+
/// `addresses` needs to be empty and --all being set.
566+
///
567+
/// Spendable coins are any coins that are not locked, and tokens that are not frozen or locked.
568+
/// The wallet will automatically calculate the required fees
562569
SweepFromAddress {
563570
/// The receiving address of the coins or tokens
564571
destination_address: String,
@@ -1100,20 +1107,23 @@ pub fn get_repl_command(cold_wallet: bool, mutable_wallet: bool) -> Command {
11001107

11011108
// Customize the help template for all commands to make it more REPL friendly
11021109
for subcommand in repl_command.get_subcommands_mut() {
1103-
if let Some(desc) =
1104-
COLD_WALLET_DESC.methods.iter().chain(WALLET_DESC.methods).find_map(|method| {
1105-
method
1106-
.name
1107-
.split('_')
1108-
.zip(subcommand.get_name().split('-'))
1109-
.all(|(x, y)| x == y)
1110-
.then_some(method.description)
1111-
})
1112-
{
1113-
*subcommand = subcommand.clone().help_template(COMMAND_HELP_TEMPLATE).about(desc);
1114-
} else {
1115-
*subcommand = subcommand.clone().help_template(COMMAND_HELP_TEMPLATE);
1110+
let mut new_subcommand = subcommand.clone().help_template(COMMAND_HELP_TEMPLATE);
1111+
if new_subcommand.get_about().is_none() {
1112+
if let Some(desc) =
1113+
COLD_WALLET_DESC.methods.iter().chain(WALLET_DESC.methods).find_map(|method| {
1114+
method
1115+
.name
1116+
.split('_')
1117+
.zip(subcommand.get_name().split('-'))
1118+
.all(|(x, y)| x == y)
1119+
.then_some(method.description)
1120+
})
1121+
{
1122+
new_subcommand = new_subcommand.about(desc);
1123+
}
11161124
}
1125+
1126+
*subcommand = new_subcommand;
11171127
}
11181128

11191129
repl_command

0 commit comments

Comments
 (0)