Skip to content

Commit

Permalink
fix: add burn funds command to console wallet (see issue #4547) (#4655)
Browse files Browse the repository at this point in the history
Description
---
Adds command to burn funds on Tari console wallet.

Motivation and Context
---
Tackle issue #4547.

How Has This Been Tested?
---
Proper unit tests.
  • Loading branch information
jorgeantonio21 committed Sep 14, 2022
1 parent 0a396c2 commit 0242b1d
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 1 deletion.
28 changes: 28 additions & 0 deletions applications/tari_console_wallet/src/automation/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@ pub async fn send_tari(
.map_err(CommandError::TransactionServiceError)
}

pub async fn burn_tari(
mut wallet_transaction_service: TransactionServiceHandle,
fee_per_gram: u64,
amount: MicroTari,
message: String,
) -> Result<TxId, CommandError> {
wallet_transaction_service
.burn_tari(amount, UtxoSelectionCriteria::default(), fee_per_gram * uT, message)
.await
.map_err(CommandError::TransactionServiceError)
}

/// publishes a tari-SHA atomic swap HTLC transaction
pub async fn init_sha_atomic_swap(
mut wallet_transaction_service: TransactionServiceHandle,
Expand Down Expand Up @@ -609,6 +621,22 @@ pub async fn command_runner(
eprintln!("DiscoverPeer error! {}", e);
}
},
BurnTari(args) => {
match burn_tari(
transaction_service.clone(),
config.fee_per_gram,
args.amount,
args.message,
)
.await
{
Ok(tx_id) => {
debug!(target: LOG_TARGET, "burn tari concluded with tx_id {}", tx_id);
tx_ids.push(tx_id);
},
Err(e) => eprintln!("BurnTari error! {}", e),
}
},
SendTari(args) => {
match send_tari(
transaction_service.clone(),
Expand Down
8 changes: 8 additions & 0 deletions applications/tari_console_wallet/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ impl ConfigOverrideProvider for Cli {
pub enum CliCommands {
GetBalance,
SendTari(SendTariArgs),
BurnTari(BurnTariArgs),
SendOneSided(SendTariArgs),
SendOneSidedToStealthAddress(SendTariArgs),
MakeItRain(MakeItRainArgs),
Expand Down Expand Up @@ -147,6 +148,13 @@ pub struct SendTariArgs {
pub message: String,
}

#[derive(Debug, Args, Clone)]
pub struct BurnTariArgs {
pub amount: MicroTari,
#[clap(short, long, default_value = "Burn funds")]
pub message: String,
}

#[derive(Debug, Args, Clone)]
pub struct MakeItRainArgs {
pub destination: UniPublicKey,
Expand Down
6 changes: 5 additions & 1 deletion applications/tari_console_wallet/src/wallet_modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ mod test {
discover-peer f6b2ca781342a3ebe30ee1643655c96f1d7c14f4d49f077695395de98ae73665
send-tari --message Our_secret! 125T 5c4f2a4b3f3f84e047333218a84fd24f581a9d7e4f23b78e3714e9d174427d61
burn-tari --message Ups_these_funds_will_be_burned! 100T
coin-split --message Make_many_dust_UTXOs! --fee-per-gram 2 0.001T 499
Expand All @@ -441,6 +443,7 @@ mod test {

let mut get_balance = false;
let mut send_tari = false;
let mut burn_tari = false;
let mut make_it_rain = false;
let mut coin_split = false;
let mut discover_peer = false;
Expand All @@ -449,6 +452,7 @@ mod test {
match command {
CliCommands::GetBalance => get_balance = true,
CliCommands::SendTari(_) => send_tari = true,
CliCommands::BurnTari(_) => burn_tari = true,
CliCommands::SendOneSided(_) => {},
CliCommands::SendOneSidedToStealthAddress(_) => {},
CliCommands::MakeItRain(_) => make_it_rain = true,
Expand All @@ -468,6 +472,6 @@ mod test {
CliCommands::HashGrpcPassword(_) => {},
}
}
assert!(get_balance && send_tari && make_it_rain && coin_split && discover_peer && whois);
assert!(get_balance && send_tari && burn_tari && make_it_rain && coin_split && discover_peer && whois);
}
}
15 changes: 15 additions & 0 deletions integration_tests/features/WalletCli.feature
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ Feature: Wallet CLI
And mining node MINE mines 5 blocks
Then I wait for wallet RECEIVER to have at least 1000000 uT


Scenario: As a user I want to burn tari via command line
Given I have a seed node SEED
And I have a base node BASE connected to seed SEED
And I have wallet WALLET_A connected to base node BASE
And I have wallet WALLET_B connected to base node BASE
And I have mining node MINER_A connected to base node BASE and wallet WALLET_A
And I have mining node MINER_B connected to base node BASE and wallet WALLET_B
And mining node MINER_A mines 15 blocks
Then all nodes are at height 15
When I wait for wallet WALLET_A to have at least 55000000000 uT
When I create a burn transaction of 45000000000 uT from WALLET_A via command line
Then I have mining node MINER_B mines 10 blocks
Then I get balance of wallet WALLET_A is at least 10000000000 uT via command line

@long-running
Scenario: As a user I want to send one-sided via command line
Given I have a seed node SEED
Expand Down
9 changes: 9 additions & 0 deletions integration_tests/features/support/wallet_cli_steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ When(
}
);

When(
"I create a burn transaction of {int} uT from {word} via command line",
{ timeout: 180 * 1000 },
async function (amount, name) {
let wallet = this.getWallet(name);
await wallet_run_command(wallet, `burn-tari ${amount}`, 180);
}
);

When(
"I send one-sided {int} uT from {word} to {word} via command line",
{ timeout: 180 * 1000 },
Expand Down

0 comments on commit 0242b1d

Please sign in to comment.