diff --git a/rusk-wallet/src/bin/command.rs b/rusk-wallet/src/bin/command.rs
index fa50c3756c..ef1aec0ded 100644
--- a/rusk-wallet/src/bin/command.rs
+++ b/rusk-wallet/src/bin/command.rs
@@ -51,9 +51,9 @@ pub(crate) enum Command {
/// Check your current Phoenix balance
PhoenixBalance {
- /// Address
+ /// Address index
#[clap(short, long)]
- addr: Option
,
+ addr_idx: Option,
/// Check maximum spendable balance
#[clap(long)]
@@ -62,9 +62,9 @@ pub(crate) enum Command {
/// Check your current Moonlight balance
MoonlightBalance {
- /// Address
+ /// Address index
#[clap(short, long)]
- addr: Option,
+ addr_idx: Option,
},
/// List your existing addresses and generate new ones
@@ -77,16 +77,16 @@ pub(crate) enum Command {
// Phoenix transaction commands
/// Show address transaction history
PhoenixHistory {
- /// Address for which you want to see the history
+ /// Address index for which you want to see the history
#[clap(short, long)]
- addr: Option,
+ addr_idx: Option,
},
/// Send DUSK privately through the network using Phoenix
PhoenixTransfer {
/// Phoenix address from which to send DUSK [default: first address]
#[clap(short, long)]
- sndr: Option,
+ sndr_idx: Option,
/// Phoenix receiver address
#[clap(short, long)]
@@ -109,7 +109,7 @@ pub(crate) enum Command {
PhoenixMemo {
/// Phoenix address from which to send DUSK [default: first address]
#[clap(short, long)]
- sndr: Option,
+ sndr_idx: Option,
/// Optional memo to attach to the transaction
#[clap(short, long)]
@@ -136,7 +136,7 @@ pub(crate) enum Command {
PhoenixStake {
/// Phoenix address from which to stake DUSK [default: first address]
#[clap(short = 's', long)]
- addr: Option,
+ addr_idx: Option,
/// Amount of DUSK to stake
#[clap(short, long)]
@@ -156,7 +156,7 @@ pub(crate) enum Command {
/// Phoenix address from which to make the unstake request [default:
/// first address]
#[clap(short, long)]
- addr: Option,
+ addr_idx: Option,
/// Max amount of gas for this transaction
#[clap(short = 'l', long, default_value_t = DEFAULT_STAKE_GAS_LIMIT)]
@@ -172,7 +172,7 @@ pub(crate) enum Command {
/// Phoenix address from which to make the withdraw request [default:
/// first address]
#[clap(short, long)]
- addr: Option,
+ addr_idx: Option,
/// Max amount of gas for this transaction
#[clap(short = 'l', long, default_value_t = DEFAULT_STAKE_GAS_LIMIT)]
@@ -187,7 +187,7 @@ pub(crate) enum Command {
PhoenixContractDeploy {
/// Phoenix address from which to deploy the contract [default: first]
#[clap(short, long)]
- addr: Option,
+ addr_idx: Option,
/// Path to the WASM contract code
#[clap(short, long)]
@@ -210,7 +210,7 @@ pub(crate) enum Command {
PhoenixContractCall {
/// Phoenix address from which to call the contract [default: first]
#[clap(short, long)]
- addr: Option,
+ addr_idx: Option,
/// Contract id of the contract to call
#[clap(short, long)]
@@ -238,7 +238,7 @@ pub(crate) enum Command {
StakeInfo {
/// Address used to stake [default: first address]
#[clap(short, long)]
- addr: Option,
+ addr_idx: Option,
/// Check accumulated reward
#[clap(long, action)]
@@ -250,7 +250,7 @@ pub(crate) enum Command {
MoonlightTransfer {
/// Moonlight Address from which to send DUSK [default: first address]
#[clap(short, long)]
- sndr: Option,
+ sndr_idx: Option,
/// Moonlight receiver address
#[clap(short, long)]
@@ -273,7 +273,7 @@ pub(crate) enum Command {
MoonlightMemo {
/// Moonlight Address from which to send DUSK [default: first address]
#[clap(short, long)]
- sndr: Option,
+ sndr_idx: Option,
/// Optional memo to attach to the transaction
#[clap(short, long)]
@@ -300,7 +300,7 @@ pub(crate) enum Command {
MoonlightStake {
/// Moonlight address from which to stake DUSK [default: first address]
#[clap(short = 's', long)]
- addr: Option,
+ addr_idx: Option,
/// Amount of DUSK to stake
#[clap(short, long)]
@@ -320,7 +320,7 @@ pub(crate) enum Command {
/// Moonlight address from which to make the unstake request [default:
/// first address]
#[clap(short, long)]
- addr: Option,
+ addr_idx: Option,
/// Max amount of gas for this transaction
#[clap(short = 'l', long, default_value_t = DEFAULT_STAKE_GAS_LIMIT)]
@@ -336,7 +336,7 @@ pub(crate) enum Command {
/// Moonlight address from which to make the withdraw request [default:
/// first address]
#[clap(short, long)]
- addr: Option,
+ addr_idx: Option,
/// Max amount of gas for this transaction
#[clap(short = 'l', long, default_value_t = DEFAULT_STAKE_GAS_LIMIT)]
@@ -352,7 +352,7 @@ pub(crate) enum Command {
/// Moonlight address from which to deploy the contract [default:
/// first]
#[clap(short, long)]
- addr: Option,
+ addr_idx: Option,
/// Path to the WASM contract code
#[clap(short, long)]
@@ -373,9 +373,9 @@ pub(crate) enum Command {
/// Call a contract using Moonlight
MoonlightContractCall {
- /// ContractId to call
+ /// address index of the moonlight account that will pay for the gas
#[clap(short, long)]
- addr: Option,
+ addr_idx: Option,
/// contract id of the contract to call
#[clap(short, long)]
@@ -403,7 +403,7 @@ pub(crate) enum Command {
PhoenixToMoonlight {
/// Moonlight or Phoenix address from which to convert DUSK to
#[clap(short = 's', long)]
- addr: Option,
+ addr_idx: Option,
/// Amount of DUSK to transfer to your Moonlight account
#[clap(short, long)]
@@ -422,7 +422,7 @@ pub(crate) enum Command {
MoonlightToPhoenix {
/// Moonlight or Phoenix Address from which to convert DUSK to
#[clap(short = 's', long)]
- addr: Option,
+ addr_idx: Option,
/// Amount of DUSK to transfer to your phoenix account
#[clap(short, long)]
@@ -442,7 +442,7 @@ pub(crate) enum Command {
/// Address for which you want the exported keys [default: first
/// address]
#[clap(short, long)]
- addr: Option,
+ addr_idx: Option,
/// Output directory for the exported keys
#[clap(short, long)]
@@ -465,7 +465,10 @@ impl Command {
settings: &Settings,
) -> anyhow::Result {
match self {
- Command::PhoenixBalance { addr, spendable } => {
+ Command::PhoenixBalance {
+ addr_idx,
+ spendable,
+ } => {
let sync_result = wallet.sync().await;
if let Err(e) = sync_result {
// Sync error should be reported only if wallet is online
@@ -473,23 +476,15 @@ impl Command {
tracing::error!("Unable to update the balance {e:?}")
}
}
+ let addr_idx = addr_idx.unwrap_or_default();
- let addr = match addr {
- Some(addr) => wallet.claim_as_address(addr)?,
- None => wallet.default_address(),
- };
-
- let balance = wallet.get_phoenix_balance(addr).await?;
+ let balance = wallet.get_phoenix_balance(addr_idx).await?;
Ok(RunResult::PhoenixBalance(balance, spendable))
}
- Command::MoonlightBalance { addr } => {
- let addr = match addr {
- Some(addr) => wallet.claim_as_address(addr)?,
- None => wallet.default_address(),
- };
-
+ Command::MoonlightBalance { addr_idx } => {
+ let addr_idx = addr_idx.unwrap_or_default();
Ok(RunResult::MoonlightBalance(
- wallet.get_moonlight_balance(addr).await?,
+ wallet.get_moonlight_balance(addr_idx).await?,
))
}
Command::Addresses { new } => {
@@ -501,34 +496,47 @@ impl Command {
std::process::exit(0);
}
- let addr = wallet.new_address().clone();
+ let new_addr_idx = wallet.add_address();
wallet.save()?;
- Ok(RunResult::Address(Box::new(addr)))
+
+ // leave this hack here until `RunResult` gets an overhaul
+ let phoenix_addr = Address::Phoenix {
+ pk: *wallet.phoenix_pk(new_addr_idx)?,
+ };
+ Ok(RunResult::Address(Box::new(phoenix_addr)))
} else {
- Ok(RunResult::Addresses(wallet.addresses().clone()))
+ let phoenix_addresses = wallet
+ .addresses()
+ .iter()
+ .enumerate()
+ .map(|(_index, (phoenix_pk, _bls_pk))| {
+ Address::Phoenix { pk: *phoenix_pk }
+ })
+ .collect();
+
+ Ok(RunResult::Addresses(phoenix_addresses))
}
}
Command::PhoenixTransfer {
- sndr,
+ sndr_idx,
rcvr,
amt,
gas_limit,
gas_price,
} => {
wallet.sync().await?;
- let sender = match sndr {
- Some(addr) => wallet.claim_as_address(addr)?,
- None => wallet.default_address(),
- };
let gas = Gas::new(gas_limit).with_price(gas_price);
+ let sender_idx = sndr_idx.unwrap_or_default();
+
+ let receiver = rcvr.try_phoenix_pk()?;
let tx = wallet
- .phoenix_transfer(sender, &rcvr, None, amt, gas)
+ .phoenix_transfer(sender_idx, receiver, None, amt, gas)
.await?;
Ok(RunResult::Tx(tx.hash()))
}
Command::PhoenixMemo {
- sndr,
+ sndr_idx,
memo,
rcvr,
amt,
@@ -536,38 +544,42 @@ impl Command {
gas_price,
} => {
wallet.sync().await?;
- let sender = match sndr {
- Some(addr) => wallet.claim_as_address(addr)?,
- None => wallet.default_address(),
- };
let gas = Gas::new(gas_limit).with_price(gas_price);
+ let sender_idx = sndr_idx.unwrap_or_default();
+
+ let receiver = rcvr.try_phoenix_pk()?;
let tx = wallet
- .phoenix_transfer(sender, &rcvr, Some(memo), amt, gas)
+ .phoenix_transfer(
+ sender_idx,
+ receiver,
+ Some(memo),
+ amt,
+ gas,
+ )
.await?;
Ok(RunResult::Tx(tx.hash()))
}
Command::MoonlightTransfer {
- sndr,
+ sndr_idx,
rcvr,
amt,
gas_limit,
gas_price,
} => {
let gas = Gas::new(gas_limit).with_price(gas_price);
- let sender = match sndr {
- Some(addr) => wallet.claim_as_address(addr)?,
- None => wallet.default_address(),
- };
+ let sender_idx = sndr_idx.unwrap_or_default();
+
+ let receiver = rcvr.try_bls_pk()?;
let tx = wallet
- .moonlight_transfer(sender, &rcvr, None, amt, gas)
+ .moonlight_transfer(sender_idx, receiver, None, amt, gas)
.await?;
Ok(RunResult::Tx(tx.hash()))
}
Command::MoonlightMemo {
- sndr,
+ sndr_idx,
memo,
rcvr,
amt,
@@ -575,101 +587,91 @@ impl Command {
gas_price,
} => {
let gas = Gas::new(gas_limit).with_price(gas_price);
- let sender = match sndr {
- Some(addr) => wallet.claim_as_address(addr)?,
- None => wallet.default_address(),
- };
+ let sender_idx = sndr_idx.unwrap_or_default();
+
+ let receiver = rcvr.try_bls_pk()?;
let tx = wallet
- .moonlight_transfer(sender, &rcvr, Some(memo), amt, gas)
+ .moonlight_transfer(
+ sender_idx,
+ receiver,
+ Some(memo),
+ amt,
+ gas,
+ )
.await?;
Ok(RunResult::Tx(tx.hash()))
}
Command::PhoenixStake {
- addr,
+ addr_idx,
amt,
gas_limit,
gas_price,
} => {
wallet.sync().await?;
let gas = Gas::new(gas_limit).with_price(gas_price);
- let addr = match addr {
- Some(addr) => wallet.claim_as_address(addr)?,
- None => wallet.default_address(),
- };
+ let addr_idx = addr_idx.unwrap_or_default();
- let tx = wallet.phoenix_stake(addr, amt, gas).await?;
+ let tx = wallet.phoenix_stake(addr_idx, amt, gas).await?;
Ok(RunResult::Tx(tx.hash()))
}
- Command::StakeInfo { addr, reward } => {
- let addr = match addr {
- Some(addr) => wallet.claim_as_address(addr)?,
- None => wallet.default_address(),
- };
- let si = wallet
- .stake_info(addr.index()?)
+ Command::StakeInfo { addr_idx, reward } => {
+ let addr_idx = addr_idx.unwrap_or_default();
+ let stake_info = wallet
+ .stake_info(addr_idx)
.await?
.ok_or(Error::NotStaked)?;
- Ok(RunResult::StakeInfo(si, reward))
+ Ok(RunResult::StakeInfo(stake_info, reward))
}
Command::PhoenixUnstake {
- addr,
+ addr_idx,
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 addr_idx = addr_idx.unwrap_or_default();
- let tx = wallet.phoenix_unstake(addr, gas).await?;
+ let tx = wallet.phoenix_unstake(addr_idx, gas).await?;
Ok(RunResult::Tx(tx.hash()))
}
Command::PhoenixWithdraw {
- addr,
+ addr_idx,
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 addr_idx = addr_idx.unwrap_or_default();
- let tx = wallet.phoenix_stake_withdraw(addr, gas).await?;
+ let tx = wallet.phoenix_stake_withdraw(addr_idx, gas).await?;
Ok(RunResult::Tx(tx.hash()))
}
- Command::Export { addr, dir, name } => {
- let addr = match addr {
- Some(addr) => wallet.claim_as_address(addr)?,
- None => wallet.default_address(),
- };
-
+ Command::Export {
+ addr_idx,
+ dir,
+ name,
+ } => {
let pwd = prompt::request_auth(
"Provide a password for your provisioner keys",
&settings.password,
wallet.get_file_version()?,
)?;
+ let addr_idx = addr_idx.unwrap_or_default();
- let (pub_key, key_pair) =
- wallet.export_provisioner_keys(addr, &dir, name, &pwd)?;
+ let (pub_key, key_pair) = wallet
+ .export_provisioner_keys(addr_idx, &dir, name, &pwd)?;
Ok(RunResult::ExportedKeys(pub_key, key_pair))
}
- Command::PhoenixHistory { addr } => {
+ Command::PhoenixHistory { addr_idx } => {
wallet.sync().await?;
- let addr = match addr {
- Some(addr) => wallet.claim_as_address(addr)?,
- None => wallet.default_address(),
- };
- let notes = wallet.get_all_notes(addr).await?;
+ let addr_idx = addr_idx.unwrap_or_default();
+ let notes = wallet.get_all_notes(addr_idx).await?;
let transactions =
history::transaction_from_notes(settings, notes).await?;
@@ -677,100 +679,80 @@ impl Command {
Ok(RunResult::PhoenixHistory(transactions))
}
Command::PhoenixToMoonlight {
- addr,
+ addr_idx,
gas_limit,
gas_price,
amt,
} => {
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 addr_idx = addr_idx.unwrap_or_default();
- let tx = wallet.phoenix_to_moonlight(addr, amt, gas).await?;
+ let tx =
+ wallet.phoenix_to_moonlight(addr_idx, amt, gas).await?;
Ok(RunResult::Tx(tx.hash()))
}
Command::MoonlightToPhoenix {
- addr,
+ addr_idx,
amt,
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 addr_idx = addr_idx.unwrap_or_default();
- let tx = wallet.moonlight_to_phoenix(addr, amt, gas).await?;
+ let tx =
+ wallet.moonlight_to_phoenix(addr_idx, amt, gas).await?;
Ok(RunResult::Tx(tx.hash()))
}
Command::MoonlightStake {
- addr,
+ addr_idx,
amt,
gas_limit,
gas_price,
} => {
- 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 addr_idx = addr_idx.unwrap_or_default();
- let tx = wallet.moonlight_stake(addr, amt, gas).await?;
+ let tx = wallet.moonlight_stake(addr_idx, amt, gas).await?;
Ok(RunResult::Tx(tx.hash()))
}
Command::MoonlightUnstake {
- addr,
+ addr_idx,
gas_limit,
gas_price,
} => {
- 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 addr_idx = addr_idx.unwrap_or_default();
- let tx = wallet.moonlight_unstake(addr, gas).await?;
+ let tx = wallet.moonlight_unstake(addr_idx, gas).await?;
Ok(RunResult::Tx(tx.hash()))
}
Command::MoonlightWithdraw {
- addr,
+ addr_idx,
gas_limit,
gas_price,
} => {
- 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 addr_idx = addr_idx.unwrap_or_default();
- let tx = wallet.moonlight_stake_withdraw(addr, gas).await?;
+ let tx = wallet.moonlight_stake_withdraw(addr_idx, gas).await?;
Ok(RunResult::Tx(tx.hash()))
}
Command::PhoenixContractCall {
- addr,
+ addr_idx,
contract_id,
fn_name,
fn_args,
gas_limit,
gas_price,
} => {
- 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 addr_idx = addr_idx.unwrap_or_default();
let contract_id: [u8; 32] = contract_id
.try_into()
@@ -780,25 +762,21 @@ impl Command {
.map_err(|_| Error::Rkyv)?;
let tx = wallet
- .phoenix_execute(addr, Dusk::from(0), gas, call.into())
+ .phoenix_execute(addr_idx, Dusk::from(0), gas, call.into())
.await?;
Ok(RunResult::Tx(tx.hash()))
}
Command::MoonlightContractCall {
- addr,
+ addr_idx,
contract_id,
fn_name,
fn_args,
gas_limit,
gas_price,
} => {
- 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 addr_idx = addr_idx.unwrap_or_default();
let contract_id: [u8; 32] = contract_id
.try_into()
@@ -809,8 +787,7 @@ impl Command {
let tx = wallet
.moonlight_execute(
- addr,
- None,
+ addr_idx,
Dusk::from(0),
Dusk::from(0),
gas,
@@ -821,18 +798,14 @@ impl Command {
Ok(RunResult::Tx(tx.hash()))
}
Self::PhoenixContractDeploy {
- addr,
+ addr_idx,
code,
init_args,
gas_limit,
gas_price,
} => {
- 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 addr_idx = addr_idx.unwrap_or_default();
if code.extension().unwrap_or_default() != "wasm" {
return Err(Error::InvalidWasmContractPath.into());
@@ -841,24 +814,21 @@ impl Command {
let code = std::fs::read(code)
.map_err(|_| Error::InvalidWasmContractPath)?;
- let tx =
- wallet.phoenix_deploy(addr, code, init_args, gas).await?;
+ let tx = wallet
+ .phoenix_deploy(addr_idx, code, init_args, gas)
+ .await?;
Ok(RunResult::Tx(tx.hash()))
}
Self::MoonlightContractDeploy {
- addr,
+ addr_idx,
code,
init_args,
gas_limit,
gas_price,
} => {
- 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 addr_idx = addr_idx.unwrap_or_default();
if code.extension().unwrap_or_default() != "wasm" {
return Err(Error::InvalidWasmContractPath.into());
@@ -867,8 +837,9 @@ impl Command {
let code = std::fs::read(code)
.map_err(|_| Error::InvalidWasmContractPath)?;
- let tx =
- wallet.moonlight_deploy(addr, code, init_args, gas).await?;
+ let tx = wallet
+ .moonlight_deploy(addr_idx, code, init_args, gas)
+ .await?;
Ok(RunResult::Tx(tx.hash()))
}
diff --git a/rusk-wallet/src/bin/interactive.rs b/rusk-wallet/src/bin/interactive.rs
index c3d0e8e529..db284371f2 100644
--- a/rusk-wallet/src/bin/interactive.rs
+++ b/rusk-wallet/src/bin/interactive.rs
@@ -29,8 +29,8 @@ pub(crate) async fn run_loop(
) -> anyhow::Result<()> {
loop {
// let the user choose (or create) an address
- let addr = match menu_addr(wallet)? {
- AddrSelect::Address(addr) => *addr,
+ let addr_idx = match menu_addr(wallet)? {
+ AddrSelect::AddressIndex(addr_idx) => addr_idx,
AddrSelect::NewAddress => {
if wallet.addresses().len() >= MAX_ADDRESSES {
println!(
@@ -39,7 +39,7 @@ pub(crate) async fn run_loop(
std::process::exit(0);
}
- let addr = wallet.new_address().clone();
+ let addr_idx = wallet.add_address();
let file_version = wallet.get_file_version()?;
let password = &settings.password;
@@ -61,26 +61,18 @@ pub(crate) async fn run_loop(
wallet.save()?;
}
- addr
+ addr_idx
}
AddrSelect::Exit => std::process::exit(0),
};
- let index = addr.index()?;
-
- let moonlight = Address::Bls {
- index: Some(index),
- addr: wallet.bls_public_key(addr.index()?),
- };
-
let is_synced = wallet.is_synced().await?;
loop {
// get balance for this address
prompt::hide_cursor()?;
- let moonlight_bal =
- wallet.get_moonlight_balance(&moonlight).await?;
- let phoenix_bal = wallet.get_phoenix_balance(&addr).await?;
+ let moonlight_bal = wallet.get_moonlight_balance(addr_idx).await?;
+ let phoenix_bal = wallet.get_phoenix_balance(addr_idx).await?;
let phoenix_spendable = phoenix_bal.spendable.into();
let phoenix_total: Dusk = phoenix_bal.value.into();
@@ -89,35 +81,41 @@ pub(crate) async fn run_loop(
// display address information
println!();
println!();
+ // display phoenix balance and keys information
if is_synced {
println!(
- "{0: <20} - Total: {moonlight_bal}",
- "Moonlight Balance",
+ "{0: <23} - Spendable: {phoenix_spendable}",
+ "Phoenix Balance",
);
+ println!("{0: <23} - Total: {phoenix_total}", "",);
}
- println!("{0: <20} {moonlight}", "Moonlight Address");
+ let phoenix_addr = Address::Phoenix {
+ pk: *wallet.phoenix_pk(addr_idx)?,
+ };
+ println!("{phoenix_addr}\n");
- println!();
+ // display moonlight balance and keys information
if is_synced {
println!(
- "{0: <20} - Spendable: {phoenix_spendable}",
- "Phoenix Balance",
+ "{0: <23} - Total: {moonlight_bal}",
+ "Moonlight Balance",
);
- println!("{0: <20} - Total: {phoenix_total}", "",);
}
- println!("{0: <20} {addr}", "Phoenix Address");
- println!();
+ let moonlight_addr = Address::Bls {
+ pk: *wallet.bls_pk(addr_idx)?,
+ };
+ println!("{moonlight_addr}\n");
// request operation to perform
let op = match wallet.is_online().await {
true => menu_op(
- addr.clone(),
+ addr_idx,
phoenix_spendable,
moonlight_bal,
settings,
is_synced,
),
- false => menu_op_offline(addr.clone(), settings),
+ false => menu_op_offline(addr_idx, settings),
};
// perform operations with this address
@@ -164,35 +162,42 @@ pub(crate) async fn run_loop(
#[derive(PartialEq, Eq, Hash, Debug, Clone)]
enum AddrSelect {
- Address(Box),
+ AddressIndex(u8),
NewAddress,
Exit,
}
+fn address_idx_string(addr_idx: u8) -> String {
+ if addr_idx == 0 {
+ "Default Address".to_string()
+ } else {
+ format!("Address no {:4}", addr_idx)
+ }
+}
+
/// Allows the user to choose an address from the selected wallet
/// to start performing operations.
fn menu_addr(wallet: &Wallet) -> anyhow::Result {
let mut address_menu = Menu::title("Addresses");
- for addr in wallet.addresses() {
- let preview = addr.preview();
- address_menu = address_menu
- .add(AddrSelect::Address(Box::new(addr.clone())), preview);
+ let total_addresses = wallet.addresses().len() as u8;
+ for addr_idx in 0..total_addresses {
+ address_menu = address_menu.add(
+ AddrSelect::AddressIndex(addr_idx),
+ address_idx_string(addr_idx),
+ );
}
let remaining_addresses =
- MAX_ADDRESSES.saturating_sub(wallet.addresses().len());
- let mut action_menu = Menu::new()
- .separator()
- .add(AddrSelect::NewAddress, "New address");
-
- // show warning if less than
- if remaining_addresses < 5 {
- action_menu = action_menu.separator().separator_msg(format!(
- "\x1b[93m{}\x1b[0m This wallet only supports up to {MAX_ADDRESSES} addresses, you have {} addresses ",
- "Warning:",
- wallet.addresses().len()
- ));
- }
+ MAX_ADDRESSES.saturating_sub(total_addresses as usize);
+
+ let mut action_menu = Menu::new();
+ // only show the option to create a new address if we don't already have
+ // `MAX_ADDRESSES`
+ if remaining_addresses > 0 {
+ action_menu = action_menu
+ .separator()
+ .add(AddrSelect::NewAddress, "New address")
+ };
if let Some(rx) = &wallet.state()?.sync_rx {
if let Ok(status) = rx.try_recv() {
@@ -221,7 +226,7 @@ fn menu_addr(wallet: &Wallet) -> anyhow::Result {
/// Allows the user to choose an operation to perform with the selected
/// transaction type
fn transaction_op_menu_moonlight(
- addr: Address,
+ addr_idx: u8,
moonlight_bal: Dusk,
) -> anyhow::Result {
use TransactionOp::*;
@@ -248,14 +253,14 @@ fn transaction_op_menu_moonlight(
let x = match val {
Transfer => AddrOp::Run(Box::new(Command::MoonlightTransfer {
- sndr: Some(addr),
+ sndr_idx: Some(addr_idx),
rcvr: prompt::request_rcvr_addr("recipient")?,
amt: prompt::request_token_amt("transfer", moonlight_bal)?,
gas_limit: prompt::request_gas_limit(gas::DEFAULT_LIMIT)?,
gas_price: prompt::request_gas_price()?,
})),
Memo => AddrOp::Run(Box::new(Command::MoonlightMemo {
- sndr: Some(addr),
+ sndr_idx: Some(addr_idx),
memo: prompt::request_str("memo")?,
rcvr: prompt::request_rcvr_addr("recipient")?,
amt: prompt::request_optional_token_amt("transfer", moonlight_bal)?,
@@ -263,24 +268,24 @@ fn transaction_op_menu_moonlight(
gas_price: prompt::request_gas_price()?,
})),
Stake => AddrOp::Run(Box::new(Command::MoonlightStake {
- addr: Some(addr),
+ addr_idx: Some(addr_idx),
amt: prompt::request_stake_token_amt(moonlight_bal)?,
gas_limit: prompt::request_gas_limit(DEFAULT_STAKE_GAS_LIMIT)?,
gas_price: prompt::request_gas_price()?,
})),
Unstake => AddrOp::Run(Box::new(Command::MoonlightUnstake {
- addr: Some(addr),
+ addr_idx: Some(addr_idx),
gas_limit: prompt::request_gas_limit(DEFAULT_STAKE_GAS_LIMIT)?,
gas_price: prompt::request_gas_price()?,
})),
Withdraw => AddrOp::Run(Box::new(Command::MoonlightWithdraw {
- addr: Some(addr),
+ addr_idx: Some(addr_idx),
gas_limit: prompt::request_gas_limit(DEFAULT_STAKE_GAS_LIMIT)?,
gas_price: prompt::request_gas_price()?,
})),
ContractDeploy => {
AddrOp::Run(Box::new(Command::MoonlightContractDeploy {
- addr: Some(addr),
+ addr_idx: Some(addr_idx),
code: prompt::request_contract_code()?,
init_args: prompt::request_bytes("init arguments")?,
gas_limit: prompt::request_gas_limit(gas::DEFAULT_LIMIT)?,
@@ -288,7 +293,7 @@ fn transaction_op_menu_moonlight(
}))
}
ContractCall => AddrOp::Run(Box::new(Command::MoonlightContractCall {
- addr: Some(addr),
+ addr_idx: Some(addr_idx),
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")?,
@@ -305,7 +310,7 @@ fn transaction_op_menu_moonlight(
/// Allows the user to choose an operation to perform with the selected
/// transaction type
fn transaction_op_menu_phoenix(
- addr: Address,
+ addr_idx: u8,
phoenix_balance: Dusk,
) -> anyhow::Result {
use TransactionOp::*;
@@ -332,14 +337,14 @@ fn transaction_op_menu_phoenix(
let x = match val {
Transfer => AddrOp::Run(Box::new(Command::PhoenixTransfer {
- sndr: Some(addr),
+ sndr_idx: Some(addr_idx),
rcvr: prompt::request_rcvr_addr("recipient")?,
amt: prompt::request_token_amt("transfer", phoenix_balance)?,
gas_limit: prompt::request_gas_limit(gas::DEFAULT_LIMIT)?,
gas_price: prompt::request_gas_price()?,
})),
Memo => AddrOp::Run(Box::new(Command::PhoenixMemo {
- sndr: Some(addr),
+ sndr_idx: Some(addr_idx),
memo: prompt::request_str("memo")?,
rcvr: prompt::request_rcvr_addr("recipient")?,
amt: prompt::request_optional_token_amt(
@@ -350,24 +355,24 @@ fn transaction_op_menu_phoenix(
gas_price: prompt::request_gas_price()?,
})),
Stake => AddrOp::Run(Box::new(Command::PhoenixStake {
- addr: Some(addr),
+ addr_idx: Some(addr_idx),
amt: prompt::request_stake_token_amt(phoenix_balance)?,
gas_limit: prompt::request_gas_limit(DEFAULT_STAKE_GAS_LIMIT)?,
gas_price: prompt::request_gas_price()?,
})),
Unstake => AddrOp::Run(Box::new(Command::PhoenixUnstake {
- addr: Some(addr),
+ addr_idx: Some(addr_idx),
gas_limit: prompt::request_gas_limit(DEFAULT_STAKE_GAS_LIMIT)?,
gas_price: prompt::request_gas_price()?,
})),
Withdraw => AddrOp::Run(Box::new(Command::PhoenixWithdraw {
- addr: Some(addr),
+ addr_idx: Some(addr_idx),
gas_limit: prompt::request_gas_limit(DEFAULT_STAKE_GAS_LIMIT)?,
gas_price: prompt::request_gas_price()?,
})),
ContractDeploy => {
AddrOp::Run(Box::new(Command::PhoenixContractDeploy {
- addr: Some(addr),
+ addr_idx: Some(addr_idx),
code: prompt::request_contract_code()?,
init_args: prompt::request_bytes("init arguments")?,
gas_limit: prompt::request_gas_limit(gas::DEFAULT_LIMIT)?,
@@ -375,16 +380,16 @@ fn transaction_op_menu_phoenix(
}))
}
ContractCall => AddrOp::Run(Box::new(Command::PhoenixContractCall {
- addr: Some(addr),
+ addr_idx: Some(addr_idx),
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")?,
gas_limit: prompt::request_gas_limit(gas::DEFAULT_LIMIT)?,
gas_price: prompt::request_gas_price()?,
})),
- History => {
- AddrOp::Run(Box::new(Command::PhoenixHistory { addr: Some(addr) }))
- }
+ History => AddrOp::Run(Box::new(Command::PhoenixHistory {
+ addr_idx: Some(addr_idx),
+ })),
Back => AddrOp::Back,
};
@@ -429,7 +434,7 @@ enum TransactionOp {
/// Allows the user to choose the operation to perform for the
/// selected address
fn menu_op(
- addr: Address,
+ addr_idx: u8,
phoenix_balance: Dusk,
moonlight_balance: Dusk,
settings: &Settings,
@@ -471,18 +476,18 @@ fn menu_op(
let res = match cmd {
CMI::PhoenixTransactions => {
- transaction_op_menu_phoenix(addr, phoenix_balance)?
+ transaction_op_menu_phoenix(addr_idx, phoenix_balance)?
}
CMI::MoonlightTransactions => {
- transaction_op_menu_moonlight(addr, moonlight_balance)?
+ transaction_op_menu_moonlight(addr_idx, moonlight_balance)?
}
CMI::StakeInfo => AddrOp::Run(Box::new(Command::StakeInfo {
- addr: Some(addr),
+ addr_idx: Some(addr_idx),
reward: false,
})),
CMI::MoonlightToPhoenix => {
AddrOp::Run(Box::new(Command::MoonlightToPhoenix {
- addr: Some(addr),
+ addr_idx: Some(addr_idx),
amt: prompt::request_token_amt("convert", moonlight_balance)?,
gas_limit: prompt::request_gas_limit(gas::DEFAULT_LIMIT)?,
gas_price: prompt::request_gas_price()?,
@@ -490,14 +495,14 @@ fn menu_op(
}
CMI::PhoenixToMoonlight => {
AddrOp::Run(Box::new(Command::PhoenixToMoonlight {
- addr: Some(addr),
+ addr_idx: Some(addr_idx),
amt: prompt::request_token_amt("convert", phoenix_balance)?,
gas_limit: prompt::request_gas_limit(gas::DEFAULT_LIMIT)?,
gas_price: prompt::request_gas_price()?,
}))
}
CMI::Export => AddrOp::Run(Box::new(Command::Export {
- addr: Some(addr),
+ addr_idx: Some(addr_idx),
name: None,
dir: prompt::request_dir("export keys", settings.profile.clone())?,
})),
@@ -509,7 +514,7 @@ fn menu_op(
/// Allows the user to choose the operation to perform for the
/// selected address while in offline mode
fn menu_op_offline(
- addr: Address,
+ addr_idx: u8,
settings: &Settings,
) -> anyhow::Result {
use CommandMenuItem as CMI;
@@ -530,7 +535,7 @@ fn menu_op_offline(
let res = match cmd {
CMI::Export => AddrOp::Run(Box::new(Command::Export {
- addr: Some(addr),
+ addr_idx: Some(addr_idx),
name: None,
dir: prompt::request_dir("export keys", settings.profile.clone())?,
})),
@@ -664,30 +669,34 @@ fn menu_wallet(wallet_found: Option) -> anyhow::Result {
fn confirm(cmd: &Command) -> anyhow::Result {
match cmd {
Command::PhoenixTransfer {
- sndr,
+ sndr_idx,
rcvr,
amt,
gas_limit,
gas_price,
} => {
- let sndr = sndr.as_ref().expect("sender to be a valid address");
let max_fee = gas_limit * gas_price;
- println!(" > Send from = {}", sndr.preview());
+ println!(
+ " > Send from {}",
+ address_idx_string(sndr_idx.unwrap_or_default())
+ );
println!(" > Recipient = {}", rcvr.preview());
println!(" > Amount to transfer = {} DUSK", amt);
println!(" > Max fee = {} DUSK", Dusk::from(max_fee));
prompt::ask_confirm()
}
Command::MoonlightTransfer {
- sndr,
+ sndr_idx,
rcvr,
amt,
gas_limit,
gas_price,
} => {
- let sndr = sndr.as_ref().expect("sender to be a valid address");
let max_fee = gas_limit * gas_price;
- println!(" > Send from = {}", sndr.preview());
+ println!(
+ " > Send from {}",
+ address_idx_string(sndr_idx.unwrap_or_default())
+ );
println!(" > Recipient = {}", rcvr.preview());
println!(" > Amount to transfer = {} DUSK", amt);
println!(" > Max fee = {} DUSK", Dusk::from(max_fee));
@@ -695,37 +704,43 @@ fn confirm(cmd: &Command) -> anyhow::Result {
prompt::ask_confirm()
}
Command::PhoenixStake {
- addr,
+ addr_idx,
amt,
gas_limit,
gas_price,
} => {
- let addr = addr.as_ref().expect("address to be valid");
let max_fee = gas_limit * gas_price;
- println!(" > Stake from {}", addr.preview());
+ println!(
+ " > Send from {}",
+ address_idx_string(addr_idx.unwrap_or_default())
+ );
println!(" > Amount to stake = {} DUSK", amt);
println!(" > Max fee = {} DUSK", Dusk::from(max_fee));
prompt::ask_confirm()
}
Command::PhoenixUnstake {
- addr,
+ addr_idx,
gas_limit,
gas_price,
} => {
- let addr = addr.as_ref().expect("address to be valid");
let max_fee = gas_limit * gas_price;
- println!(" > Unstake from {}", addr.preview());
+ println!(
+ " > Send from {}",
+ address_idx_string(addr_idx.unwrap_or_default())
+ );
println!(" > Max fee = {} DUSK", Dusk::from(max_fee));
prompt::ask_confirm()
}
Command::PhoenixWithdraw {
- addr,
+ addr_idx,
gas_limit,
gas_price,
} => {
- let addr = addr.as_ref().expect("address to be valid");
let max_fee = gas_limit * gas_price;
- println!(" > Reward from {}", addr.preview());
+ println!(
+ " > Send from {}",
+ address_idx_string(addr_idx.unwrap_or_default())
+ );
println!(" > Max fee = {} DUSK", Dusk::from(max_fee));
prompt::ask_confirm()
}
diff --git a/rusk-wallet/src/clients.rs b/rusk-wallet/src/clients.rs
index ab3faa2319..df9b560529 100644
--- a/rusk-wallet/src/clients.rs
+++ b/rusk-wallet/src/clients.rs
@@ -8,7 +8,7 @@ mod sync;
use dusk_bytes::Serializable;
use execution_core::{
- signatures::bls::PublicKey as AccountPublicKey,
+ signatures::bls::PublicKey as BlsPublicKey,
transfer::{
moonlight::AccountData,
phoenix::{Note, NoteLeaf, Prove},
@@ -246,7 +246,7 @@ impl State {
pub(crate) async fn fetch_account(
&self,
- pk: &AccountPublicKey,
+ pk: &BlsPublicKey,
) -> Result {
let status = self.status;
status("Fetching account-data...");
@@ -285,7 +285,7 @@ impl State {
/// Queries the node for the amount staked by a key.
pub(crate) async fn fetch_stake(
&self,
- pk: &AccountPublicKey,
+ pk: &BlsPublicKey,
) -> Result