Skip to content

Commit

Permalink
Merge pull request #2528 from dusk-network/fix-rewards
Browse files Browse the repository at this point in the history
  • Loading branch information
Daksh14 authored Sep 30, 2024
2 parents a4fbe69 + 71e7bb0 commit f52e13f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
21 changes: 8 additions & 13 deletions rusk-wallet/src/bin/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,12 @@ pub(crate) enum Command {
contract_id: Vec<u8>,

/// Function name to call
#[clap(short, long)]
#[clap(short = 'n', long)]
fn_name: String,

/// Function arguments for this call
#[clap(short, long)]
#[clap(short = 'f', long)]
fn_args: Vec<u8>,

/// Max amount of gas for this transaction
Expand Down Expand Up @@ -337,10 +338,6 @@ pub(crate) enum Command {
#[clap(short, long)]
addr: Option<Address>,

/// 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,
Expand Down Expand Up @@ -385,11 +382,11 @@ pub(crate) enum Command {
contract_id: Vec<u8>,

/// Function name to call
#[clap(short, long)]
#[clap(short = 'n', long)]
fn_name: String,

/// Function arguments for this call
#[clap(short, long)]
#[clap(short = 'f', long)]
fn_args: Vec<u8>,

/// Max amount of gas for this transaction
Expand All @@ -405,7 +402,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<Address>,

/// Amount of DUSK to transfer to your Moonlight account
Expand All @@ -424,7 +421,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<Address>,

/// Amount of DUSK to transfer to your phoenix account
Expand Down Expand Up @@ -746,7 +743,6 @@ impl Command {
}
Command::MoonlightWithdraw {
addr,
amt,
gas_limit,
gas_price,
} => {
Expand All @@ -757,8 +753,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()))
}
Expand Down
1 change: 0 additions & 1 deletion rusk-wallet/src/bin/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,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()?,
})),
Expand Down
10 changes: 6 additions & 4 deletions rusk-wallet/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -993,20 +993,22 @@ impl<F: SecureWalletFile + Debug> Wallet<F> {
pub async fn moonlight_stake_withdraw(
&self,
sender: &Address,
amt: Dusk,
gas: Gas,
) -> Result<Transaction, Error> {
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,
)?;

Expand Down

0 comments on commit f52e13f

Please sign in to comment.