Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Commit

Permalink
Add interactive stake allow
Browse files Browse the repository at this point in the history
Resolves #98
  • Loading branch information
Neotamandua committed Oct 6, 2023
1 parent b886ff1 commit 067ade7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- Add interactive stake allow [#98]

### Fixed

- Fix staking address display [#204]
Expand Down Expand Up @@ -431,6 +434,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Implementation of `Store` trait from `wallet-core`
- Implementation of `State` and `Prover` traits from `wallet-core`

[#98]: https://github.com/dusk-network/wallet-cli/issues/98
[#179]: https://github.com/dusk-network/wallet-cli/issues/179
[#204]: https://github.com/dusk-network/wallet-cli/issues/204
[#182]: https://github.com/dusk-network/wallet-cli/issues/182
Expand Down
8 changes: 8 additions & 0 deletions src/bin/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ enum CommandMenuItem {
History,
Transfer,
Stake,
StakeAllow,
StakeInfo,
Unstake,
Withdraw,
Expand All @@ -212,6 +213,7 @@ fn menu_op(
.add(CMI::History, "Transaction History")
.add(CMI::Transfer, "Transfer Dusk")
.add(CMI::Stake, "Stake Dusk")
.add(CMI::StakeAllow, "Allow staking key")
.add(CMI::StakeInfo, "Check existing stake")
.add(CMI::Unstake, "Unstake Dusk")
.add(CMI::Withdraw, "Withdraw staking reward")
Expand Down Expand Up @@ -244,6 +246,12 @@ fn menu_op(
gas_limit: prompt::request_gas_limit(DEFAULT_STAKE_GAS_LIMIT)?,
gas_price: prompt::request_gas_price()?,
})),
CMI::StakeAllow => AddrOp::Run(Box::new(Command::StakeAllow {
addr: Some(addr),
key: prompt::request_provisioner_key()?,
gas_limit: prompt::request_gas_limit(DEFAULT_STAKE_GAS_LIMIT)?,
gas_price: prompt::request_gas_price()?,
})),
CMI::StakeInfo => AddrOp::Run(Box::new(Command::StakeInfo {
addr: Some(addr),
reward: false,
Expand Down
23 changes: 23 additions & 0 deletions src/bin/io/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crossterm::{

use anyhow::Result;
use bip39::{ErrorKind, Language, Mnemonic};
use dusk_bytes::DeserializableSlice;
use dusk_wallet::{dat::DatFileVersion, Error};
use requestty::Question;

Expand Down Expand Up @@ -231,6 +232,15 @@ fn check_valid_denom(value: f64, balance: Dusk) -> Result<(), String> {
}
}

fn check_valid_pkey(key: &str) -> Result<(), String> {
let key = bs58::decode(key).into_vec().map_err(|_| {
"Please introduce a valid provisioner key (Base58)".to_string()
})?;
dusk_bls12_381_sign::PublicKey::from_slice(&key)
.map_err(|_| "Invalid provisioner key value".to_string())?;
Ok(())
}

/// Request amount of tokens
pub(crate) fn request_token_amt(
action: &str,
Expand Down Expand Up @@ -280,6 +290,19 @@ pub(crate) fn request_gas_price() -> anyhow::Result<Lux> {
Ok(*price)
}

/// Request provisioner key
pub(crate) fn request_provisioner_key() -> anyhow::Result<String> {
// let the user input the provisioner key
let q = Question::input("key")
.message("Please enter the provisioner key:")
.validate_on_key(|pkey, _| check_valid_pkey(pkey).is_ok())
.validate(|pkey, _| check_valid_pkey(pkey))
.build();

let a = requestty::prompt_one(q)?;
Ok(a.as_string().expect("answer to be a string").to_owned())
}

/// Request Dusk block explorer to be opened
pub(crate) fn launch_explorer(url: String) -> Result<()> {
let q = requestty::Question::confirm("launch")
Expand Down

0 comments on commit 067ade7

Please sign in to comment.