From 4e0c47bca1f607dca679f111ee144823c517b101 Mon Sep 17 00:00:00 2001 From: Daksh <41485688+Daksh14@users.noreply.github.com> Date: Sun, 29 Sep 2024 20:17:25 -0400 Subject: [PATCH 1/3] rusk-wallet: Fix moonlight withdraw function by not asking for amount --- rusk-wallet/src/bin/command.rs | 8 +------- rusk-wallet/src/bin/interactive.rs | 1 - rusk-wallet/src/wallet.rs | 10 ++++++---- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/rusk-wallet/src/bin/command.rs b/rusk-wallet/src/bin/command.rs index 73de8be757..f161b049a3 100644 --- a/rusk-wallet/src/bin/command.rs +++ b/rusk-wallet/src/bin/command.rs @@ -302,10 +302,6 @@ pub(crate) enum Command { #[clap(short, long)] addr: Option
, - /// Amount of DUSK to withdraw - #[clap(short, long)] - amt: Dusk, - /// Max amount of gas for this transaction #[clap(short = 'l', long, default_value_t= DEFAULT_STAKE_GAS_LIMIT)] gas_limit: u64, @@ -687,7 +683,6 @@ impl Command { } Command::MoonlightWithdraw { addr, - amt, gas_limit, gas_price, } => { @@ -698,8 +693,7 @@ impl Command { let gas = Gas::new(gas_limit).with_price(gas_price); - let tx = - wallet.moonlight_stake_withdraw(addr, amt, gas).await?; + let tx = wallet.moonlight_stake_withdraw(addr, gas).await?; Ok(RunResult::Tx(tx.hash())) } diff --git a/rusk-wallet/src/bin/interactive.rs b/rusk-wallet/src/bin/interactive.rs index 2cabefe777..6aefc42c40 100644 --- a/rusk-wallet/src/bin/interactive.rs +++ b/rusk-wallet/src/bin/interactive.rs @@ -251,7 +251,6 @@ fn transaction_op_menu_moonlight( })), Withdraw => AddrOp::Run(Box::new(Command::MoonlightWithdraw { addr: Some(addr), - amt: prompt::request_token_amt("withdraw", moonlight_bal)?, gas_limit: prompt::request_gas_limit(DEFAULT_STAKE_GAS_LIMIT)?, gas_price: prompt::request_gas_price()?, })), diff --git a/rusk-wallet/src/wallet.rs b/rusk-wallet/src/wallet.rs index 7adc474abf..adac9532eb 100644 --- a/rusk-wallet/src/wallet.rs +++ b/rusk-wallet/src/wallet.rs @@ -1000,20 +1000,22 @@ impl Wallet { pub async fn moonlight_stake_withdraw( &self, sender: &Address, - amt: Dusk, gas: Gas, ) -> Result { let mut rng = StdRng::from_entropy(); let state = self.state()?; let sender_index = sender.index()?; - let pk = sender.apk()?; - let nonce = state.fetch_account(pk).await?.nonce + 1; + let pk = self.bls_public_key(sender_index); + let nonce = state.fetch_account(&pk).await?.nonce + 1; let chain_id = state.fetch_chain_id().await?; + let stake_info = state.fetch_stake(&pk).await?; + let reward = stake_info.map(|s| s.reward).ok_or(Error::NoReward)?; + let reward = Dusk::from(reward); let mut sender_sk = self.bls_secret_key(sender_index); let withdraw = moonlight_stake_reward( - &mut rng, &sender_sk, &sender_sk, *amt, gas.limit, gas.price, + &mut rng, &sender_sk, &sender_sk, *reward, gas.limit, gas.price, nonce, chain_id, )?; From 690814658e6b4fe2709957003bc3a53c6659a808 Mon Sep 17 00:00:00 2001 From: Daksh <41485688+Daksh14@users.noreply.github.com> Date: Sun, 29 Sep 2024 22:34:28 -0400 Subject: [PATCH 2/3] rusk-wallet: reword `ContractCall` command argument to prevent conflict --- rusk-wallet/src/bin/command.rs | 28 ++++++++++++++-------------- rusk-wallet/src/bin/interactive.rs | 8 ++++---- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/rusk-wallet/src/bin/command.rs b/rusk-wallet/src/bin/command.rs index f161b049a3..9471de0687 100644 --- a/rusk-wallet/src/bin/command.rs +++ b/rusk-wallet/src/bin/command.rs @@ -191,11 +191,11 @@ pub(crate) enum Command { /// Function name to call #[clap(short, long)] - fn_name: String, + name: String, /// Function arguments for this call - #[clap(short, long)] - fn_args: Vec, + #[clap(short = 'f', long)] + param: Vec, /// Max amount of gas for this transaction #[clap(short = 'l', long, default_value_t= DEFAULT_STAKE_GAS_LIMIT)] @@ -347,11 +347,11 @@ pub(crate) enum Command { /// Function name to call #[clap(short, long)] - fn_name: String, + name: String, /// Function arguments for this call - #[clap(short, long)] - fn_args: Vec, + #[clap(short = 'f', long)] + param: Vec, /// Max amount of gas for this transaction #[clap(short = 'l', long, default_value_t= DEFAULT_LIMIT)] @@ -384,7 +384,7 @@ pub(crate) enum Command { /// Convert Phoenix DUSK to Moonlight for the same owned address PhoenixToMoonlight { /// Moonlight or Phoenix address from which to convert DUSK to - #[clap(short, long)] + #[clap(short = 's', long)] addr: Option
, /// Amount of DUSK to transfer to your Moonlight account @@ -403,7 +403,7 @@ pub(crate) enum Command { /// Convert Moonlight DUSK to Phoenix for the same owned address MoonlightToPhoenix { /// Moonlight or Phoenix Address from which to convert DUSK to - #[clap(short, long)] + #[clap(short = 's', long)] addr: Option
, /// Amount of DUSK to transfer to your phoenix account @@ -700,8 +700,8 @@ impl Command { Command::PhoenixContractCall { addr, contract_id, - fn_name, - fn_args, + name, + param, gas_limit, gas_price, } => { @@ -716,7 +716,7 @@ impl Command { .try_into() .map_err(|_| Error::InvalidContractId)?; - let call = ContractCall::new(contract_id, fn_name, &fn_args) + let call = ContractCall::new(contract_id, name, ¶m) .map_err(|_| Error::Rkyv)?; let tx = wallet @@ -728,8 +728,8 @@ impl Command { Command::MoonlightContractCall { addr, contract_id, - fn_name, - fn_args, + name, + param, gas_limit, gas_price, } => { @@ -744,7 +744,7 @@ impl Command { .try_into() .map_err(|_| Error::InvalidContractId)?; - let call = ContractCall::new(contract_id, fn_name, &fn_args) + let call = ContractCall::new(contract_id, name, ¶m) .map_err(|_| Error::Rkyv)?; let tx = wallet diff --git a/rusk-wallet/src/bin/interactive.rs b/rusk-wallet/src/bin/interactive.rs index 6aefc42c40..987c3c961c 100644 --- a/rusk-wallet/src/bin/interactive.rs +++ b/rusk-wallet/src/bin/interactive.rs @@ -266,8 +266,8 @@ fn transaction_op_menu_moonlight( ContractCall => AddrOp::Run(Box::new(Command::MoonlightContractCall { addr: Some(addr), contract_id: prompt::request_bytes("contract id")?, - fn_name: prompt::request_str("function name to call")?, - fn_args: prompt::request_bytes("arguments of calling function")?, + name: prompt::request_str("function name to call")?, + param: prompt::request_bytes("arguments of calling function")?, gas_limit: prompt::request_gas_limit(gas::DEFAULT_LIMIT)?, gas_price: prompt::request_gas_price()?, })), @@ -348,8 +348,8 @@ fn transaction_op_menu_phoenix( ContractCall => AddrOp::Run(Box::new(Command::PhoenixContractCall { addr: Some(addr), contract_id: prompt::request_bytes("contract id")?, - fn_name: prompt::request_str("function name to cal")?, - fn_args: prompt::request_bytes("arguments of calling function")?, + name: prompt::request_str("function name to cal")?, + param: prompt::request_bytes("arguments of calling function")?, gas_limit: prompt::request_gas_limit(gas::DEFAULT_LIMIT)?, gas_price: prompt::request_gas_price()?, })), From 71e7bb0e231dd7ba9ef248174728874375c7901f Mon Sep 17 00:00:00 2001 From: Daksh <41485688+Daksh14@users.noreply.github.com> Date: Mon, 30 Sep 2024 07:58:13 -0400 Subject: [PATCH 3/3] rusk-wallet: rename fields --- rusk-wallet/src/bin/command.rs | 25 +++++++++++++------------ rusk-wallet/src/bin/interactive.rs | 8 ++++---- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/rusk-wallet/src/bin/command.rs b/rusk-wallet/src/bin/command.rs index 9471de0687..1eb2ff9955 100644 --- a/rusk-wallet/src/bin/command.rs +++ b/rusk-wallet/src/bin/command.rs @@ -190,12 +190,13 @@ pub(crate) enum Command { contract_id: Vec, /// Function name to call - #[clap(short, long)] - name: String, + + #[clap(short = 'n', long)] + fn_name: String, /// Function arguments for this call #[clap(short = 'f', long)] - param: Vec, + fn_args: Vec, /// Max amount of gas for this transaction #[clap(short = 'l', long, default_value_t= DEFAULT_STAKE_GAS_LIMIT)] @@ -346,12 +347,12 @@ pub(crate) enum Command { contract_id: Vec, /// Function name to call - #[clap(short, long)] - name: String, + #[clap(short = 'n', long)] + fn_name: String, /// Function arguments for this call #[clap(short = 'f', long)] - param: Vec, + fn_args: Vec, /// Max amount of gas for this transaction #[clap(short = 'l', long, default_value_t= DEFAULT_LIMIT)] @@ -700,8 +701,8 @@ impl Command { Command::PhoenixContractCall { addr, contract_id, - name, - param, + fn_name, + fn_args, gas_limit, gas_price, } => { @@ -716,7 +717,7 @@ impl Command { .try_into() .map_err(|_| Error::InvalidContractId)?; - let call = ContractCall::new(contract_id, name, ¶m) + let call = ContractCall::new(contract_id, fn_name, &fn_args) .map_err(|_| Error::Rkyv)?; let tx = wallet @@ -728,8 +729,8 @@ impl Command { Command::MoonlightContractCall { addr, contract_id, - name, - param, + fn_name, + fn_args, gas_limit, gas_price, } => { @@ -744,7 +745,7 @@ impl Command { .try_into() .map_err(|_| Error::InvalidContractId)?; - let call = ContractCall::new(contract_id, name, ¶m) + let call = ContractCall::new(contract_id, fn_name, &fn_args) .map_err(|_| Error::Rkyv)?; let tx = wallet diff --git a/rusk-wallet/src/bin/interactive.rs b/rusk-wallet/src/bin/interactive.rs index 987c3c961c..6aefc42c40 100644 --- a/rusk-wallet/src/bin/interactive.rs +++ b/rusk-wallet/src/bin/interactive.rs @@ -266,8 +266,8 @@ fn transaction_op_menu_moonlight( ContractCall => AddrOp::Run(Box::new(Command::MoonlightContractCall { addr: Some(addr), contract_id: prompt::request_bytes("contract id")?, - name: prompt::request_str("function name to call")?, - param: prompt::request_bytes("arguments of calling function")?, + fn_name: prompt::request_str("function name to call")?, + fn_args: prompt::request_bytes("arguments of calling function")?, gas_limit: prompt::request_gas_limit(gas::DEFAULT_LIMIT)?, gas_price: prompt::request_gas_price()?, })), @@ -348,8 +348,8 @@ fn transaction_op_menu_phoenix( ContractCall => AddrOp::Run(Box::new(Command::PhoenixContractCall { addr: Some(addr), contract_id: prompt::request_bytes("contract id")?, - name: prompt::request_str("function name to cal")?, - param: prompt::request_bytes("arguments of calling function")?, + fn_name: prompt::request_str("function name to cal")?, + fn_args: prompt::request_bytes("arguments of calling function")?, gas_limit: prompt::request_gas_limit(gas::DEFAULT_LIMIT)?, gas_price: prompt::request_gas_price()?, })),