Skip to content

Commit

Permalink
chore: update api for testnet 65
Browse files Browse the repository at this point in the history
Includes changes for:

    * txhash refactor
    * new box grpc feature for proto crate
    * proto version bump v1alpha1 -> v1
    * updates to new web URL format

Refs penumbra-zone/penumbra#3554
  • Loading branch information
conorsch committed Feb 7, 2024
1 parent f5185d2 commit 474ada0
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 31 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ parallel = ["penumbra-wallet/parallel"]

[dependencies]
# Penumbra dependencies
penumbra-proto = { path = "../penumbra/crates/proto" }
penumbra-proto = { path = "../penumbra/crates/proto", features = ["rpc", "box-grpc"] }
penumbra-asset = { path = "../penumbra/crates/core/asset" }
penumbra-keys = { path = "../penumbra/crates/core/keys" }
penumbra-custody = { path = "../penumbra/crates/custody" }
Expand All @@ -22,6 +22,7 @@ penumbra-view = { path = "../penumbra/crates/view" }
penumbra-transaction = { path = "../penumbra/crates/core/transaction", features = [
"download-proving-keys",
] }
penumbra-txhash = { path = "../penumbra/crates/core/txhash" }

# External dependencies
tower = { version = "0.4", features = ["balance"] }
Expand Down
21 changes: 8 additions & 13 deletions src/opt/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@ use num_traits::identities::Zero;
use penumbra_asset::Value;
use penumbra_custody::soft_kms::SoftKms;
use penumbra_proto::{
custody::v1alpha1::{
custody_protocol_service_client::CustodyProtocolServiceClient,
custody_protocol_service_server::CustodyProtocolServiceServer,
},
view::v1alpha1::{
view_protocol_service_client::ViewProtocolServiceClient,
view_protocol_service_server::ViewProtocolServiceServer,
custody::v1::{
custody_service_client::CustodyServiceClient, custody_service_server::CustodyServiceServer,
},
view::v1::{view_service_client::ViewServiceClient, view_service_server::ViewServiceServer},
};
use penumbra_view::{ViewClient, ViewService};
use penumbra_view::{ViewClient, ViewServer};
use serenity::prelude::GatewayIntents;
use std::{env, path::PathBuf, time::Duration};
use tokio::sync::mpsc;
Expand Down Expand Up @@ -91,8 +87,7 @@ impl Serve {
let wallet = Wallet::load(pcli_config_file)
.context("failed to load wallet from local custody file")?;
let soft_kms = SoftKms::new(wallet.spend_key.clone().into());
let custody =
CustodyProtocolServiceClient::new(CustodyProtocolServiceServer::new(soft_kms));
let custody = CustodyServiceClient::new(CustodyServiceServer::new(soft_kms));
let fvk = wallet.spend_key.full_viewing_key().clone();

// Initialize view client, to scan Penumbra chain.
Expand All @@ -107,16 +102,16 @@ impl Serve {
let view_storage =
penumbra_view::Storage::load_or_initialize(view_filepath, &fvk, self.node.clone())
.await?;
let view_service = ViewService::new(view_storage, self.node.clone()).await?;
let view_service = ViewServer::new(view_storage, self.node.clone()).await?;

// Now build the view and custody clients, doing gRPC with ourselves
let mut view = ViewProtocolServiceClient::new(ViewProtocolServiceServer::new(view_service));
let mut view = ViewServiceClient::new(ViewServiceServer::new(view_service));

// Wait to synchronize the chain before doing anything else.
tracing::info!(
"starting initial sync: please wait for sync to complete before requesting tokens"
);
ViewClient::status_stream(&mut view, fvk.wallet_id())
ViewClient::status_stream(&mut view)
.await?
.try_collect::<Vec<_>>()
.await?;
Expand Down
4 changes: 2 additions & 2 deletions src/responder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use futures_util::StreamExt as _;
use penumbra_asset::Value;
use penumbra_custody::CustodyClient;
use penumbra_keys::Address;
use penumbra_transaction::Id;
use penumbra_txhash::TransactionId;
use penumbra_view::ViewClient;
use serenity::prelude::TypeMapKey;
use tokio::sync::mpsc;
Expand Down Expand Up @@ -136,7 +136,7 @@ where
C: CustodyClient + Clone + Send + 'static,
{
// Track addresses to which we successfully dispensed tokens
let mut succeeded = Vec::<(Address, Id)>::new();
let mut succeeded = Vec::<(Address, TransactionId)>::new();

// Track addresses (and associated errors) which we tried to send tokens to, but failed
let mut failed = Vec::<(Address, String)>::new();
Expand Down
8 changes: 4 additions & 4 deletions src/responder/response.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use std::fmt::Write;

use penumbra_keys::Address;
use penumbra_transaction::Id;
use penumbra_txhash::TransactionId;
use serenity::{client::Cache, model::id::GuildId};

/// The response from a request to dispense tokens to a set of addresses.
#[derive(Debug, Clone)]
pub struct Response {
/// The addresses that were successfully dispensed tokens.
pub(super) succeeded: Vec<(Address, Id)>,
pub(super) succeeded: Vec<(Address, TransactionId)>,
/// The addresses that failed to be dispensed tokens, accompanied by a string describing the
/// error.
pub(super) failed: Vec<(Address, String)>,
Expand All @@ -21,7 +21,7 @@ pub struct Response {

impl Response {
/// Returns the addresses that were successfully dispensed tokens.
pub fn succeeded(&self) -> &[(Address, Id)] {
pub fn succeeded(&self) -> &[(Address, TransactionId)] {
&self.succeeded
}

Expand Down Expand Up @@ -64,7 +64,7 @@ impl Response {
for (addr, id) in self.succeeded.iter() {
write!(
response,
"\n`{}`\ntry `pcli v tx {}`\nor visit https://app.testnet.penumbra.zone/tx/{}",
"\n`{}`\ntry `pcli v tx {}`\nor visit https://app.testnet.penumbra.zone/#/tx/{}",
addr.display_short_form(),
id,
id,
Expand Down
47 changes: 36 additions & 11 deletions src/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ use std::{

use futures::{Future, FutureExt};
use futures_util::Stream;
use futures_util::TryStreamExt;

use penumbra_proto::view::v1::broadcast_transaction_response::Status as BroadcastStatus;

use penumbra_asset::Value;
use penumbra_custody::{AuthorizeRequest, CustodyClient};
use penumbra_keys::{Address, FullViewingKey};
use penumbra_transaction::memo::MemoPlaintext;
use penumbra_txhash::TransactionId;
use penumbra_view::ViewClient;
use penumbra_wallet::plan::Planner;
use pin_project_lite::pin_project;
Expand Down Expand Up @@ -51,7 +56,7 @@ where
V: ViewClient + Clone + Send + 'static,
C: CustodyClient + Clone + Send + 'static,
{
type Response = penumbra_transaction::Id;
type Response = TransactionId;
type Error = anyhow::Error;
type Future =
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>;
Expand All @@ -71,13 +76,15 @@ where
planner.output(value, address);
}
planner
.memo(MemoPlaintext {
text: "Hello from Galileo, the Penumbra faucet bot".to_string(),
return_address: self2.fvk.payment_address(0.into()).0,
})
.memo(
MemoPlaintext::new(
self2.fvk.payment_address(0.into()).0,
"Hello from Galileo, the Penumbra faucet bot".to_string(),
)
.expect("can create memo"),
)
.unwrap();
let plan = planner.plan(&mut self2.view, self2.fvk.wallet_id(), self2.account.into());
let plan = plan.await?;
let plan = planner.plan(&mut self2.view, self2.account.into()).await?;

// 2. Authorize and build the transaction.
let auth_data = self2
Expand All @@ -90,14 +97,32 @@ where
.data
.ok_or_else(|| anyhow::anyhow!("no auth data"))?
.try_into()?;
let witness_data = self2.view.witness(self2.fvk.wallet_id(), &plan).await?;
let witness_data = self2.view.witness(&plan).await?;
let tx = plan
.build_concurrent(&self2.fvk, &witness_data, &auth_data)
.await?;

// 3. Broadcast the transaction and wait for confirmation.
let (tx_id, _detection_height) = self2.view.broadcast_transaction(tx, true).await?;
Ok(tx_id)
let id = tx.id();
let mut rsp = self2.view.broadcast_transaction(tx, true).await?;
while let Some(rsp) = rsp.try_next().await? {
match rsp.status {
Some(BroadcastStatus::BroadcastSuccess(_)) => {
println!("transaction broadcast successfully: {}", id);
}
Some(BroadcastStatus::Confirmed(c)) => {
println!(
"transaction confirmed and detected: {} @ height {}",
id, c.detection_height
);
return Ok(id);
}
_ => {}
}
}
Err(anyhow::anyhow!(
"view server closed stream without reporting transaction confirmation"
))
}
.boxed()
}
Expand Down Expand Up @@ -128,7 +153,7 @@ impl<S> SenderSet<S> {

impl<S> Stream for SenderSet<S>
where
S: Service<(Address, Vec<Value>), Response = penumbra_transaction::Id, Error = anyhow::Error>,
S: Service<(Address, Vec<Value>), Response = TransactionId, Error = anyhow::Error>,
{
type Item = Result<Change<Key, S>, anyhow::Error>;

Expand Down

0 comments on commit 474ada0

Please sign in to comment.