Skip to content

Commit

Permalink
View service: wallet id rpc (#3186)
Browse files Browse the repository at this point in the history
* Rpc request: wallet id

* add pcli command

* Propogate err
  • Loading branch information
grod220 authored Oct 12, 2023
1 parent 1bb5182 commit ac2d3de
Show file tree
Hide file tree
Showing 8 changed files with 1,489 additions and 1,053 deletions.
23 changes: 16 additions & 7 deletions crates/bin/pcli/src/command/view.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
use anyhow::Result;

mod balance;
use balance::BalanceCmd;
mod address;
use address::AddressCmd;
mod staked;

use balance::BalanceCmd;
use staked::StakedCmd;
pub mod transaction_hashes;
use transaction_hashes::TransactionHashesCmd;
mod tx;
use tx::TxCmd;
use wallet_id::WalletIdCmd;

use crate::App;

mod address;
mod balance;
mod staked;
mod wallet_id;

pub mod transaction_hashes;
mod tx;

#[derive(Debug, clap::Subcommand)]
pub enum ViewCmd {
/// View your wallet id
WalletId(WalletIdCmd),
/// View one of your addresses, either by numerical index, or a random ephemeral one.
Address(AddressCmd),
/// View your account balances.
Expand All @@ -39,6 +44,7 @@ pub enum ViewCmd {
impl ViewCmd {
pub fn offline(&self) -> bool {
match self {
ViewCmd::WalletId(wallet_id_cmd) => wallet_id_cmd.offline(),
ViewCmd::Address(address_cmd) => address_cmd.offline(),
ViewCmd::Balance(balance_cmd) => balance_cmd.offline(),
ViewCmd::Staked(staked_cmd) => staked_cmd.offline(),
Expand All @@ -54,6 +60,9 @@ impl ViewCmd {
let full_viewing_key = app.fvk.clone();

match self {
ViewCmd::WalletId(wallet_id_cmd) => {
wallet_id_cmd.exec(&full_viewing_key)?;
}
ViewCmd::Tx(tx_cmd) => {
tx_cmd.exec(app).await?;
}
Expand Down
20 changes: 20 additions & 0 deletions crates/bin/pcli/src/command/view/wallet_id.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use anyhow::Result;

use penumbra_keys::FullViewingKey;

#[derive(Debug, clap::Parser)]
pub struct WalletIdCmd {}

impl WalletIdCmd {
/// Determine if this command requires a network sync before it executes.
pub fn offline(&self) -> bool {
true
}

pub fn exec(&self, fvk: &FullViewingKey) -> Result<()> {
let wallet_id = fvk.wallet_id();
println!("{wallet_id}");

Ok(())
}
}
92 changes: 92 additions & 0 deletions crates/proto/src/gen/penumbra.view.v1alpha1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,15 @@ pub struct AddressByIndexResponse {
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct WalletIdRequest {}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct WalletIdResponse {
#[prost(message, optional, tag = "1")]
pub wallet_id: ::core::option::Option<super::super::core::keys::v1alpha1::WalletId>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct IndexByAddressRequest {
#[prost(message, optional, tag = "1")]
pub address: ::core::option::Option<super::super::core::keys::v1alpha1::Address>,
Expand Down Expand Up @@ -1181,6 +1190,37 @@ pub mod view_protocol_service_client {
);
self.inner.unary(req, path, codec).await
}
/// Query for wallet id
pub async fn wallet_id(
&mut self,
request: impl tonic::IntoRequest<super::WalletIdRequest>,
) -> std::result::Result<
tonic::Response<super::WalletIdResponse>,
tonic::Status,
> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::new(
tonic::Code::Unknown,
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/penumbra.view.v1alpha1.ViewProtocolService/WalletId",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(
GrpcMethod::new(
"penumbra.view.v1alpha1.ViewProtocolService",
"WalletId",
),
);
self.inner.unary(req, path, codec).await
}
/// Query for an address given an address index
pub async fn index_by_address(
&mut self,
Expand Down Expand Up @@ -1818,6 +1858,14 @@ pub mod view_protocol_service_server {
tonic::Response<super::AddressByIndexResponse>,
tonic::Status,
>;
/// Query for wallet id
async fn wallet_id(
&self,
request: tonic::Request<super::WalletIdRequest>,
) -> std::result::Result<
tonic::Response<super::WalletIdResponse>,
tonic::Status,
>;
/// Query for an address given an address index
async fn index_by_address(
&self,
Expand Down Expand Up @@ -2535,6 +2583,50 @@ pub mod view_protocol_service_server {
};
Box::pin(fut)
}
"/penumbra.view.v1alpha1.ViewProtocolService/WalletId" => {
#[allow(non_camel_case_types)]
struct WalletIdSvc<T: ViewProtocolService>(pub Arc<T>);
impl<
T: ViewProtocolService,
> tonic::server::UnaryService<super::WalletIdRequest>
for WalletIdSvc<T> {
type Response = super::WalletIdResponse;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<super::WalletIdRequest>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move { (*inner).wallet_id(request).await };
Box::pin(fut)
}
}
let accept_compression_encodings = self.accept_compression_encodings;
let send_compression_encodings = self.send_compression_encodings;
let max_decoding_message_size = self.max_decoding_message_size;
let max_encoding_message_size = self.max_encoding_message_size;
let inner = self.inner.clone();
let fut = async move {
let inner = inner.0;
let method = WalletIdSvc(inner);
let codec = tonic::codec::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config(
accept_compression_encodings,
send_compression_encodings,
)
.apply_max_message_size_config(
max_decoding_message_size,
max_encoding_message_size,
);
let res = grpc.unary(method, req).await;
Ok(res)
};
Box::pin(fut)
}
"/penumbra.view.v1alpha1.ViewProtocolService/IndexByAddress" => {
#[allow(non_camel_case_types)]
struct IndexByAddressSvc<T: ViewProtocolService>(pub Arc<T>);
Expand Down
163 changes: 163 additions & 0 deletions crates/proto/src/gen/penumbra.view.v1alpha1.serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6495,6 +6495,169 @@ impl<'de> serde::Deserialize<'de> for ViewAuthToken {
deserializer.deserialize_struct("penumbra.view.v1alpha1.ViewAuthToken", FIELDS, GeneratedVisitor)
}
}
impl serde::Serialize for WalletIdRequest {
#[allow(deprecated)]
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
use serde::ser::SerializeStruct;
let len = 0;
let struct_ser = serializer.serialize_struct("penumbra.view.v1alpha1.WalletIdRequest", len)?;
struct_ser.end()
}
}
impl<'de> serde::Deserialize<'de> for WalletIdRequest {
#[allow(deprecated)]
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
const FIELDS: &[&str] = &[
];

#[allow(clippy::enum_variant_names)]
enum GeneratedField {
}
impl<'de> serde::Deserialize<'de> for GeneratedField {
fn deserialize<D>(deserializer: D) -> std::result::Result<GeneratedField, D::Error>
where
D: serde::Deserializer<'de>,
{
struct GeneratedVisitor;

impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
type Value = GeneratedField;

fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(formatter, "expected one of: {:?}", &FIELDS)
}

#[allow(unused_variables)]
fn visit_str<E>(self, value: &str) -> std::result::Result<GeneratedField, E>
where
E: serde::de::Error,
{
Err(serde::de::Error::unknown_field(value, FIELDS))
}
}
deserializer.deserialize_identifier(GeneratedVisitor)
}
}
struct GeneratedVisitor;
impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
type Value = WalletIdRequest;

fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter.write_str("struct penumbra.view.v1alpha1.WalletIdRequest")
}

fn visit_map<V>(self, mut map: V) -> std::result::Result<WalletIdRequest, V::Error>
where
V: serde::de::MapAccess<'de>,
{
while map.next_key::<GeneratedField>()?.is_some() {
let _ = map.next_value::<serde::de::IgnoredAny>()?;
}
Ok(WalletIdRequest {
})
}
}
deserializer.deserialize_struct("penumbra.view.v1alpha1.WalletIdRequest", FIELDS, GeneratedVisitor)
}
}
impl serde::Serialize for WalletIdResponse {
#[allow(deprecated)]
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
use serde::ser::SerializeStruct;
let mut len = 0;
if self.wallet_id.is_some() {
len += 1;
}
let mut struct_ser = serializer.serialize_struct("penumbra.view.v1alpha1.WalletIdResponse", len)?;
if let Some(v) = self.wallet_id.as_ref() {
struct_ser.serialize_field("walletId", v)?;
}
struct_ser.end()
}
}
impl<'de> serde::Deserialize<'de> for WalletIdResponse {
#[allow(deprecated)]
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
const FIELDS: &[&str] = &[
"wallet_id",
"walletId",
];

#[allow(clippy::enum_variant_names)]
enum GeneratedField {
WalletId,
}
impl<'de> serde::Deserialize<'de> for GeneratedField {
fn deserialize<D>(deserializer: D) -> std::result::Result<GeneratedField, D::Error>
where
D: serde::Deserializer<'de>,
{
struct GeneratedVisitor;

impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
type Value = GeneratedField;

fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(formatter, "expected one of: {:?}", &FIELDS)
}

#[allow(unused_variables)]
fn visit_str<E>(self, value: &str) -> std::result::Result<GeneratedField, E>
where
E: serde::de::Error,
{
match value {
"walletId" | "wallet_id" => Ok(GeneratedField::WalletId),
_ => Err(serde::de::Error::unknown_field(value, FIELDS)),
}
}
}
deserializer.deserialize_identifier(GeneratedVisitor)
}
}
struct GeneratedVisitor;
impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
type Value = WalletIdResponse;

fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter.write_str("struct penumbra.view.v1alpha1.WalletIdResponse")
}

fn visit_map<V>(self, mut map: V) -> std::result::Result<WalletIdResponse, V::Error>
where
V: serde::de::MapAccess<'de>,
{
let mut wallet_id__ = None;
while let Some(k) = map.next_key()? {
match k {
GeneratedField::WalletId => {
if wallet_id__.is_some() {
return Err(serde::de::Error::duplicate_field("walletId"));
}
wallet_id__ = map.next_value()?;
}
}
}
Ok(WalletIdResponse {
wallet_id: wallet_id__,
})
}
}
deserializer.deserialize_struct("penumbra.view.v1alpha1.WalletIdResponse", FIELDS, GeneratedVisitor)
}
}
impl serde::Serialize for WitnessAndBuildRequest {
#[allow(deprecated)]
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
Expand Down
Binary file modified crates/proto/src/gen/proto_descriptor.bin.no_lfs
Binary file not shown.
Loading

0 comments on commit ac2d3de

Please sign in to comment.