Skip to content

Commit

Permalink
rusk-wallet: Update CHANGELOG.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Daksh14 committed Jan 31, 2025
1 parent 88d8a38 commit a46c867
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 31 deletions.
6 changes: 6 additions & 0 deletions rusk-wallet/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Change dependency declaration to not require strict equal [#3405]

### Fix

- Fix wrong lower limit for stake operation when performing topup [#3394]

## [0.1.0] - 2025-01-20

### Add
Expand Down Expand Up @@ -42,6 +46,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix stake info for inactive stakes with rewards [#2766]
- Fix Moonlight stake reward withdrawal [#2523]


<!-- Issues -->
[#3405]: https://github.com/dusk-network/rusk/issues/3405
[#3263]: https://github.com/dusk-network/rusk/issues/3263
Expand All @@ -63,6 +68,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#2396]: https://github.com/dusk-network/rusk/issues/2396
[#2340]: https://github.com/dusk-network/rusk/issues/2340
[#2288]: https://github.com/dusk-network/rusk/issues/2288
[#3394]: https://github.com/dusk-network/rusk/issues/3394

<!-- Releases -->
[Unreleased]: https://github.com/dusk-network/rusk/compare/rusk-wallet-0.1.0...HEAD
Expand Down
20 changes: 16 additions & 4 deletions rusk-wallet/src/bin/interactive/command_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use std::fmt::Display;

use dusk_core::stake::DEFAULT_MINIMUM_STAKE;
use dusk_core::transfer::data::MAX_MEMO_SIZE;
use inquire::{InquireError, Select};
use rusk_wallet::currency::Dusk;
Expand All @@ -15,6 +16,7 @@ use rusk_wallet::gas::{
};
use rusk_wallet::{
Address, Error, Wallet, MAX_CONTRACT_INIT_ARG_SIZE, MAX_FUNCTION_NAME_SIZE,
MIN_CONVERTIBLE,
};

use super::ProfileOp;
Expand Down Expand Up @@ -169,9 +171,19 @@ pub(crate) async fn online(
.public_key(stake_idx)
.expect("public key to exists in interactive mode");

let mut has_stake = match wallet.check_stake_exists(stake_pk) {
Ok(x) => x,
Err(_) => false,
let min_val: u64 = {
let has_stake = wallet
.stake_info(stake_idx)
.await?
.map(|s| s.amount.is_some())
.unwrap_or_default();

// if the user has stake then they are performing a topup
if has_stake {
MIN_CONVERTIBLE
} else {
DEFAULT_MINIMUM_STAKE
}
};

let owner = match wallet.find_stake_owner_account(stake_pk).await {
Expand All @@ -191,7 +203,7 @@ pub(crate) async fn online(
ProfileOp::Run(Box::new(Command::Stake {
address: Some(addr),
owner: Some(owner),
amt: prompt::request_stake_token_amt(balance, has_stake)?,
amt: prompt::request_stake_token_amt(balance, min_val)?,
gas_limit: prompt::request_gas_limit(gas::DEFAULT_LIMIT_CALL)?,
gas_price: prompt::request_gas_price(
DEFAULT_PRICE,
Expand Down
14 changes: 4 additions & 10 deletions rusk-wallet/src/bin/io/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use crossterm::{

use anyhow::Result;
use bip39::{ErrorKind, Language, Mnemonic};
use dusk_core::stake::DEFAULT_MINIMUM_STAKE;

use inquire::ui::RenderConfig;
use inquire::validator::Validation;
Expand Down Expand Up @@ -265,18 +264,13 @@ pub(crate) fn request_optional_token_amt(
request_token(action, min, balance, None).map_err(Error::from)
}

/// Request amount of tokens that can't be lower than MINIMUM_STAKE
/// Request amount of tokens that can't be lower than the `min` argument and
/// higher than `balance`
pub(crate) fn request_stake_token_amt(
balance: Dusk,
has_stake: bool,
min: u64,
) -> Result<Dusk, Error> {
let min: Dusk = {
let min_stake = if has_stake { 1 } else { DEFAULT_MINIMUM_STAKE };

min_stake.into()
};

request_token("stake", min, balance, None).map_err(Error::from)
request_token("stake", min.into(), balance, None).map_err(Error::from)
}

/// Request gas limit
Expand Down
17 changes: 0 additions & 17 deletions rusk-wallet/src/wallet/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,21 +734,4 @@ impl<F: SecureWalletFile + Debug> Wallet<F> {
StakeFundOwner::Contract(_) => Err(Error::Unauthorized),
}
}

/// Return true if the stake amount currently exists
/// or if the user has staked some amount
pub async fn check_stake_exists(
&self,
stake_pk: &BlsPublicKey,
) -> Result<bool, Error> {
let stake = self.state()?.fetch_stake(pk).await?;

let exists = if let Some(stake) = stake {
stake.amount.is_some()
} else {
false
};

Ok(exists)
}
}

0 comments on commit a46c867

Please sign in to comment.