Skip to content

Commit

Permalink
Remove wallet id filter from view service
Browse files Browse the repository at this point in the history
  • Loading branch information
grod220 authored and hdevalence committed Jan 3, 2024
1 parent 303fc03 commit ac766cf
Show file tree
Hide file tree
Showing 20 changed files with 964 additions and 1,512 deletions.
21 changes: 10 additions & 11 deletions crates/bin/pcli/src/command.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
mod ceremony;
mod debug;
mod init;
mod query;
mod threshold;
mod tx;
mod utils;
mod validator;
mod view;

pub use debug::DebugCmd;
pub use init::InitCmd;
pub use query::QueryCmd;
pub use threshold::ThresholdCmd;
pub use tx::TxCmd;
pub use validator::ValidatorCmd;
pub use view::transaction_hashes::TransactionHashesCmd;
pub use view::ViewCmd;

use self::ceremony::CeremonyCmd;

mod ceremony;
mod debug;
mod init;
mod query;
mod threshold;
mod tx;
mod utils;
mod validator;
mod view;

// Note on display_order:
//
// The value is between 0 and 999 (the default). Sorting of subcommands is done
Expand Down
15 changes: 8 additions & 7 deletions crates/bin/pcli/src/command/ceremony.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use crate::App;
use anyhow::{anyhow, Context, Result};
use rand_core::OsRng;
use tokio::sync::mpsc;
use tokio_stream::wrappers::ReceiverStream;
use url::Url;

use penumbra_asset::Value;
use penumbra_keys::{keys::AddressIndex, Address};
use penumbra_num::Amount;
Expand All @@ -18,11 +22,9 @@ use penumbra_proto::{
view::v1alpha1::GasPricesRequest,
};
use penumbra_transaction::memo::MemoPlaintext;
use penumbra_view::Planner;
use rand_core::OsRng;
use tokio::sync::mpsc;
use tokio_stream::wrappers::ReceiverStream;
use url::Url;
use penumbra_view::{Planner, ViewClient};

use crate::App;

fn max_message_size(phase: u8) -> usize {
match phase {
Expand Down Expand Up @@ -66,7 +68,6 @@ async fn handle_bid(app: &mut App, to: Address, from: AddressIndex, bid: &str) -
app.view
.as_mut()
.context("view service must be initialized")?,
app.config.full_viewing_key.wallet_id(),
from,
)
.await
Expand Down
33 changes: 6 additions & 27 deletions crates/bin/pcli/src/command/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ impl TxCmd {
app.view
.as_mut()
.context("view service must be initialized")?,
app.config.full_viewing_key.wallet_id(),
AddressIndex::new(*from),
)
.await
Expand All @@ -319,15 +318,13 @@ impl TxCmd {
app.view
.as_mut()
.context("view service must be initialized")?,
app.config.full_viewing_key.wallet_id(),
AddressIndex::new(*source),
)
.await?;
app.build_and_submit_transaction(plan).await?;
}
TxCmd::Sweep => loop {
let plans = plan::sweep(
app.config.full_viewing_key.wallet_id(),
app.view
.as_mut()
.context("view service must be initialized")?,
Expand Down Expand Up @@ -381,9 +378,8 @@ impl TxCmd {
);
planner.swap(input, into.id(), estimated_claim_fee, claim_address)?;

let wallet_id = app.config.full_viewing_key.wallet_id();
let plan = planner
.plan(app.view(), wallet_id, AddressIndex::new(*source))
.plan(app.view(), AddressIndex::new(*source))
.await
.context("can't plan swap transaction")?;

Expand All @@ -402,7 +398,7 @@ impl TxCmd {
// Fetch the SwapRecord with the claimable swap.
let swap_record = app
.view()
.swap_by_commitment(wallet_id, swap_plaintext.swap_commitment())
.swap_by_commitment(swap_plaintext.swap_commitment())
.await?;

let asset_cache = app.view().assets().await?;
Expand All @@ -425,8 +421,6 @@ impl TxCmd {
.format(&asset_cache),
);

let wallet_id = app.config.full_viewing_key.wallet_id();

let params = app
.view
.as_mut()
Expand All @@ -445,7 +439,7 @@ impl TxCmd {
proof_blinding_r: Fq::rand(&mut OsRng),
proof_blinding_s: Fq::rand(&mut OsRng),
})
.plan(app.view(), wallet_id, AddressIndex::new(*source))
.plan(app.view(), AddressIndex::new(*source))
.await
.context("can't plan swap claim")?;

Expand Down Expand Up @@ -474,10 +468,9 @@ impl TxCmd {

let mut planner = Planner::new(OsRng);
planner.set_gas_prices(gas_prices);
let wallet_id = app.config.full_viewing_key.wallet_id().clone();
let plan = planner
.delegate(unbonded_amount.value(), rate_data)
.plan(app.view(), wallet_id, AddressIndex::new(*source))
.plan(app.view(), AddressIndex::new(*source))
.await
.context("can't plan delegation")?;

Expand Down Expand Up @@ -518,7 +511,6 @@ impl TxCmd {
app.view
.as_mut()
.context("view service must be initialized")?,
app.config.full_viewing_key.wallet_id(),
AddressIndex::new(*source),
)
.await
Expand All @@ -527,15 +519,13 @@ impl TxCmd {
app.build_and_submit_transaction(plan).await?;
}
TxCmd::UndelegateClaim {} => {
let wallet_id = app.config.full_viewing_key.wallet_id(); // this should be optional? or saved in the client statefully?

let channel = app.pd_channel().await?;
let view: &mut dyn ViewClient = app
.view
.as_mut()
.context("view service must be initialized")?;

let current_height = view.status(wallet_id).await?.full_sync_height;
let current_height = view.status().await?.full_sync_height;
let mut client = ChainQueryServiceClient::new(channel.clone());
let current_epoch = client
.epoch_by_height(EpochByHeightRequest {
Expand All @@ -549,7 +539,7 @@ impl TxCmd {

// Query the view client for the list of undelegations that are ready to be claimed.
// We want to claim them into the same address index that currently holds the tokens.
let notes = view.unspent_notes_by_address_and_asset(wallet_id).await?;
let notes = view.unspent_notes_by_address_and_asset().await?;

for (address_index, notes_by_asset) in notes.into_iter() {
for (token, notes) in
Expand Down Expand Up @@ -617,7 +607,6 @@ impl TxCmd {
app.view
.as_mut()
.context("view service must be initialized")?,
app.config.full_viewing_key.wallet_id(),
address_index,
)
.await?;
Expand Down Expand Up @@ -649,7 +638,6 @@ impl TxCmd {
app.view
.as_mut()
.context("view service must be initialized")?,
app.config.full_viewing_key.wallet_id(),
AddressIndex::new(*source),
)
.await?;
Expand All @@ -668,7 +656,6 @@ impl TxCmd {
app.view
.as_mut()
.context("view service must be initialized")?,
app.config.full_viewing_key.wallet_id(),
AddressIndex::new(*source),
)
.await?;
Expand Down Expand Up @@ -748,7 +735,6 @@ impl TxCmd {
app.view
.as_mut()
.context("view service must be initialized")?,
app.config.full_viewing_key.wallet_id(),
AddressIndex::new(*source),
)
.await?;
Expand Down Expand Up @@ -813,7 +799,6 @@ impl TxCmd {
app.view
.as_mut()
.context("view service must be initialized")?,
app.config.full_viewing_key.wallet_id(),
AddressIndex::new(*source),
)
.await?;
Expand All @@ -836,7 +821,6 @@ impl TxCmd {
app.view
.as_mut()
.context("view service must be initialized")?,
app.config.full_viewing_key.wallet_id(),
source,
)
.await?;
Expand Down Expand Up @@ -909,7 +893,6 @@ impl TxCmd {
app.view
.as_mut()
.context("view service must be initialized")?,
app.config.full_viewing_key.wallet_id(),
AddressIndex::new(*source),
)
.await?;
Expand All @@ -929,7 +912,6 @@ impl TxCmd {
app.view
.as_mut()
.context("view service must be initialized")?,
app.config.full_viewing_key.wallet_id(),
AddressIndex::new(*source),
)
.await?;
Expand Down Expand Up @@ -970,7 +952,6 @@ impl TxCmd {
app.view
.as_mut()
.context("view service must be initialized")?,
app.config.full_viewing_key.wallet_id(),
AddressIndex::new(*source),
)
.await?;
Expand Down Expand Up @@ -1047,7 +1028,6 @@ impl TxCmd {
app.view
.as_mut()
.context("view service must be initialized")?,
app.config.full_viewing_key.wallet_id(),
AddressIndex::new(*source),
)
.await?;
Expand Down Expand Up @@ -1100,7 +1080,6 @@ impl TxCmd {
app.view
.as_mut()
.context("view service must be initialized")?,
app.config.full_viewing_key.wallet_id(),
AddressIndex::new(*source),
)
.await?;
Expand Down
13 changes: 7 additions & 6 deletions crates/bin/pcli/src/command/tx/replicate.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::{warning, App};
use std::io::Write;
use std::path::PathBuf;

use crate::dex_utils;
use crate::dex_utils::replicate::debug;
use anyhow::{anyhow, bail, Context, Result};
use dialoguer::Confirm;
use rand_core::OsRng;

use penumbra_asset::Value;
use penumbra_dex::{lp::position::Position, DirectedUnitPair};
use penumbra_keys::keys::AddressIndex;
Expand All @@ -16,8 +16,10 @@ use penumbra_proto::{
view::v1alpha1::GasPricesRequest,
};
use penumbra_view::{Planner, ViewClient};
use rand_core::OsRng;
use std::io::Write;

use crate::dex_utils;
use crate::dex_utils::replicate::debug;
use crate::{warning, App};

/// Queries the chain for a transaction by hash.
#[derive(Debug, clap::Subcommand)]
Expand Down Expand Up @@ -168,7 +170,6 @@ impl ConstantProduct {
app.view
.as_mut()
.context("view service must be initialized")?,
app.config.full_viewing_key.wallet_id(),
AddressIndex::new(self.source),
)
.await?;
Expand Down
5 changes: 0 additions & 5 deletions crates/bin/pcli/src/command/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,7 @@ impl ValidatorCmd {
};
// Construct a new transaction and include the validator definition.

let wallet_id = app.config.full_viewing_key.wallet_id();
let plan = plan::validator_definition(
wallet_id,
app.view
.as_mut()
.context("view service must be initialized")?,
Expand Down Expand Up @@ -212,10 +210,7 @@ impl ValidatorCmd {
// Construct a new transaction and include the validator definition.
let fee = Fee::from_staking_token_amount((*fee).into());

let wallet_id = app.config.full_viewing_key.wallet_id();

let plan = plan::validator_vote(
wallet_id,
app.view
.as_mut()
.context("view service must be initialized")?,
Expand Down
6 changes: 3 additions & 3 deletions crates/bin/pcli/src/command/view/balance.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use anyhow::Result;
use comfy_table::{presets, Table};

use penumbra_keys::FullViewingKey;
use penumbra_sct::CommitmentSource;
use penumbra_view::ViewClient;

#[derive(Debug, clap::Args)]
pub struct BalanceCmd {
#[clap(long)]
Expand All @@ -22,9 +24,7 @@ impl BalanceCmd {
let mut table = Table::new();
table.load_preset(presets::NOTHING);

let notes = view
.unspent_notes_by_account_and_asset(fvk.wallet_id())
.await?;
let notes = view.unspent_notes_by_account_and_asset().await?;

if self.by_note {
table.set_header(vec!["Account", "Value", "Source"]);
Expand Down
8 changes: 3 additions & 5 deletions crates/bin/pcli/src/command/view/staked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ use std::collections::BTreeMap;
use anyhow::Result;
use comfy_table::{presets, Table};
use futures::TryStreamExt;
use tonic::transport::Channel;

use penumbra_asset::{Value, STAKING_TOKEN_ASSET_ID};
use penumbra_keys::FullViewingKey;
use penumbra_proto::core::component::stake::v1alpha1::{
query_service_client::QueryServiceClient as StakeQueryServiceClient, ValidatorInfoRequest,
};
use penumbra_stake::{validator, DelegationToken};
use penumbra_view::ViewClient;
use tonic::transport::Channel;

#[derive(Debug, clap::Parser)]
pub struct StakedCmd {}
Expand Down Expand Up @@ -43,10 +44,7 @@ impl StakedCmd {
.map(TryInto::try_into)
.collect::<Result<Vec<validator::Info>, _>>()?;

let wallet_id = full_viewing_key.wallet_id();
let notes = view_client
.unspent_notes_by_asset_and_address(wallet_id)
.await?;
let notes = view_client.unspent_notes_by_asset_and_address().await?;
let mut total = 0u128;

let mut table = Table::new();
Expand Down
Loading

0 comments on commit ac766cf

Please sign in to comment.