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

Remove stake_allow command #229

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Removed

- Remove `stake_allow` command

## [0.21.0] - 2023-12-30

### Added
Expand Down
1 change: 0 additions & 1 deletion src/bin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ SUBCOMMANDS:
transfer Send DUSK through the network
stake Start staking DUSK
stake-info Check your stake information
stake-allow Allow a provisioner key to stake
unstake Unstake a key's stake
withdraw Withdraw accumulated reward for a stake key
export Export BLS provisioner key pair
Expand Down
42 changes: 0 additions & 42 deletions src/bin/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
mod history;

use clap::Subcommand;
use dusk_bls12_381_sign::PublicKey;
use dusk_bytes::DeserializableSlice;
use dusk_plonk::prelude::BlsScalar;
use rusk_abi::hash::Hasher;
use std::{fmt, path::PathBuf};
Expand Down Expand Up @@ -126,25 +124,6 @@ pub(crate) enum Command {
reward: bool,
},

/// Allow a provisioner key to stake
StakeAllow {
/// Address used to perform the operation [default: first address]
#[clap(short, long)]
addr: Option<Address>,

/// Provisioner key to allow
#[clap(short, long)]
key: String,

/// Max amt of gas for this transaction
#[clap(short = 'l', long, default_value_t= DEFAULT_STAKE_GAS_LIMIT)]
gas_limit: u64,

/// Price you're going to pay for each gas unit (in LUX)
#[clap(short = 'p', long, default_value_t= DEFAULT_PRICE)]
gas_price: Lux,
},

/// Unstake a key's stake
Unstake {
/// Address from which your DUSK was staked [default: first address]
Expand Down Expand Up @@ -269,27 +248,6 @@ impl Command {
let tx = wallet.stake(addr, amt, gas).await?;
Ok(RunResult::Tx(Hasher::digest(tx.to_hash_input_bytes())))
}
Command::StakeAllow {
addr,
key,
gas_limit,
gas_price,
} => {
wallet.sync().await?;
let addr = match addr {
Some(addr) => wallet.claim_as_address(addr)?,
None => wallet.default_address(),
};

let gas = Gas::new(gas_limit).with_price(gas_price);

let key_data = bs58::decode(key).into_vec()?;
let key = PublicKey::from_slice(&key_data[..])
.map_err(dusk_wallet::Error::from)?;

let tx = wallet.stake_allow(addr, &key, gas).await?;
Ok(RunResult::Tx(Hasher::digest(tx.to_hash_input_bytes())))
}
Command::StakeInfo { addr, reward } => {
let addr = match addr {
Some(addr) => wallet.claim_as_address(addr)?,
Expand Down
8 changes: 0 additions & 8 deletions src/bin/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ enum CommandMenuItem {
History,
Transfer,
Stake,
StakeAllow,
StakeInfo,
Unstake,
Withdraw,
Expand All @@ -213,7 +212,6 @@ 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 @@ -246,12 +244,6 @@ 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: 0 additions & 23 deletions src/bin/io/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ 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 @@ -232,15 +231,6 @@ 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 @@ -290,19 +280,6 @@ 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
4 changes: 0 additions & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ pub enum Error {
/// Not enough gas to perform this transaction
#[error("Not enough gas to perform this transaction")]
NotEnoughGas,
/// Staking is only allowed when you're running your own local Rusk
/// instance (Tip: Point `rusk_addr` to "localhost" or "127.0.0.1")
#[error("Staking is only allowed when you're running your own local Rusk instance")]
StakingNotAllowed,
/// A stake already exists for this key
#[error("A stake already exists for this key")]
AlreadyStaked,
Expand Down
34 changes: 0 additions & 34 deletions src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,40 +545,6 @@ impl<F: SecureWalletFile + Debug> Wallet<F> {
Ok(tx)
}

/// Allow a `staker` BLS key to stake
pub async fn stake_allow(
&self,
addr: &Address,
staker: &PublicKey,
gas: Gas,
) -> Result<Transaction, Error> {
let wallet = self.connected_wallet().await?;
// make sure we own the staking address
if !addr.is_owned() {
return Err(Error::Unauthorized);
}

// check if the gas is enough
// TODO: This should be tuned with the right usage for this tx
if !gas.is_enough() {
return Err(Error::NotEnoughGas);
}

let mut rng = StdRng::from_entropy();
let index = addr.index()? as u64;

let tx = wallet.allow(
&mut rng,
index,
index,
addr.psk(),
staker,
gas.limit,
gas.price,
)?;
Ok(tx)
}

/// Obtains stake information for a given address
pub async fn stake_info(&self, addr: &Address) -> Result<StakeInfo, Error> {
let wallet = self.connected_wallet().await?;
Expand Down