Skip to content

Commit adc1098

Browse files
committed
chore: update api for testnet 65
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
1 parent f5185d2 commit adc1098

File tree

5 files changed

+52
-31
lines changed

5 files changed

+52
-31
lines changed

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ parallel = ["penumbra-wallet/parallel"]
1313

1414
[dependencies]
1515
# Penumbra dependencies
16-
penumbra-proto = { path = "../penumbra/crates/proto" }
16+
penumbra-proto = { path = "../penumbra/crates/proto", features = ["rpc", "box-grpc"] }
1717
penumbra-asset = { path = "../penumbra/crates/core/asset" }
1818
penumbra-keys = { path = "../penumbra/crates/core/keys" }
1919
penumbra-custody = { path = "../penumbra/crates/custody" }
@@ -22,6 +22,7 @@ penumbra-view = { path = "../penumbra/crates/view" }
2222
penumbra-transaction = { path = "../penumbra/crates/core/transaction", features = [
2323
"download-proving-keys",
2424
] }
25+
penumbra-txhash = { path = "../penumbra/crates/core/txhash" }
2526

2627
# External dependencies
2728
tower = { version = "0.4", features = ["balance"] }

src/opt/serve.rs

+8-13
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,12 @@ use num_traits::identities::Zero;
77
use penumbra_asset::Value;
88
use penumbra_custody::soft_kms::SoftKms;
99
use penumbra_proto::{
10-
custody::v1alpha1::{
11-
custody_protocol_service_client::CustodyProtocolServiceClient,
12-
custody_protocol_service_server::CustodyProtocolServiceServer,
13-
},
14-
view::v1alpha1::{
15-
view_protocol_service_client::ViewProtocolServiceClient,
16-
view_protocol_service_server::ViewProtocolServiceServer,
10+
custody::v1::{
11+
custody_service_client::CustodyServiceClient, custody_service_server::CustodyServiceServer,
1712
},
13+
view::v1::{view_service_client::ViewServiceClient, view_service_server::ViewServiceServer},
1814
};
19-
use penumbra_view::{ViewClient, ViewService};
15+
use penumbra_view::{ViewClient, ViewServer};
2016
use serenity::prelude::GatewayIntents;
2117
use std::{env, path::PathBuf, time::Duration};
2218
use tokio::sync::mpsc;
@@ -91,8 +87,7 @@ impl Serve {
9187
let wallet = Wallet::load(pcli_config_file)
9288
.context("failed to load wallet from local custody file")?;
9389
let soft_kms = SoftKms::new(wallet.spend_key.clone().into());
94-
let custody =
95-
CustodyProtocolServiceClient::new(CustodyProtocolServiceServer::new(soft_kms));
90+
let custody = CustodyServiceClient::new(CustodyServiceServer::new(soft_kms));
9691
let fvk = wallet.spend_key.full_viewing_key().clone();
9792

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

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

115110
// Wait to synchronize the chain before doing anything else.
116111
tracing::info!(
117112
"starting initial sync: please wait for sync to complete before requesting tokens"
118113
);
119-
ViewClient::status_stream(&mut view, fvk.wallet_id())
114+
ViewClient::status_stream(&mut view)
120115
.await?
121116
.try_collect::<Vec<_>>()
122117
.await?;

src/responder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use futures_util::StreamExt as _;
44
use penumbra_asset::Value;
55
use penumbra_custody::CustodyClient;
66
use penumbra_keys::Address;
7-
use penumbra_transaction::Id;
7+
use penumbra_txhash::TransactionId;
88
use penumbra_view::ViewClient;
99
use serenity::prelude::TypeMapKey;
1010
use tokio::sync::mpsc;
@@ -136,7 +136,7 @@ where
136136
C: CustodyClient + Clone + Send + 'static,
137137
{
138138
// Track addresses to which we successfully dispensed tokens
139-
let mut succeeded = Vec::<(Address, Id)>::new();
139+
let mut succeeded = Vec::<(Address, TransactionId)>::new();
140140

141141
// Track addresses (and associated errors) which we tried to send tokens to, but failed
142142
let mut failed = Vec::<(Address, String)>::new();

src/responder/response.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use std::fmt::Write;
22

33
use penumbra_keys::Address;
4-
use penumbra_transaction::Id;
4+
use penumbra_txhash::TransactionId;
55
use serenity::{client::Cache, model::id::GuildId};
66

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

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

@@ -64,7 +64,7 @@ impl Response {
6464
for (addr, id) in self.succeeded.iter() {
6565
write!(
6666
response,
67-
"\n`{}`\ntry `pcli v tx {}`\nor visit https://app.testnet.penumbra.zone/tx/{}",
67+
"\n`{}`\ntry `pcli v tx {}`\nor visit https://app.testnet.penumbra.zone/#/tx/{}",
6868
addr.display_short_form(),
6969
id,
7070
id,

src/sender.rs

+36-11
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ use std::{
55

66
use futures::{Future, FutureExt};
77
use futures_util::Stream;
8+
use futures_util::TryStreamExt;
9+
10+
use penumbra_proto::view::v1::broadcast_transaction_response::Status as BroadcastStatus;
11+
812
use penumbra_asset::Value;
913
use penumbra_custody::{AuthorizeRequest, CustodyClient};
1014
use penumbra_keys::{Address, FullViewingKey};
1115
use penumbra_transaction::memo::MemoPlaintext;
16+
use penumbra_txhash::TransactionId;
1217
use penumbra_view::ViewClient;
1318
use penumbra_wallet::plan::Planner;
1419
use pin_project_lite::pin_project;
@@ -51,7 +56,7 @@ where
5156
V: ViewClient + Clone + Send + 'static,
5257
C: CustodyClient + Clone + Send + 'static,
5358
{
54-
type Response = penumbra_transaction::Id;
59+
type Response = TransactionId;
5560
type Error = anyhow::Error;
5661
type Future =
5762
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>;
@@ -71,13 +76,15 @@ where
7176
planner.output(value, address);
7277
}
7378
planner
74-
.memo(MemoPlaintext {
75-
text: "Hello from Galileo, the Penumbra faucet bot".to_string(),
76-
return_address: self2.fvk.payment_address(0.into()).0,
77-
})
79+
.memo(
80+
MemoPlaintext::new(
81+
self2.fvk.payment_address(0.into()).0,
82+
"Hello from Galileo, the Penumbra faucet bot".to_string(),
83+
)
84+
.expect("can create memo"),
85+
)
7886
.unwrap();
79-
let plan = planner.plan(&mut self2.view, self2.fvk.wallet_id(), self2.account.into());
80-
let plan = plan.await?;
87+
let plan = planner.plan(&mut self2.view, self2.account.into()).await?;
8188

8289
// 2. Authorize and build the transaction.
8390
let auth_data = self2
@@ -90,14 +97,32 @@ where
9097
.data
9198
.ok_or_else(|| anyhow::anyhow!("no auth data"))?
9299
.try_into()?;
93-
let witness_data = self2.view.witness(self2.fvk.wallet_id(), &plan).await?;
100+
let witness_data = self2.view.witness(&plan).await?;
94101
let tx = plan
95102
.build_concurrent(&self2.fvk, &witness_data, &auth_data)
96103
.await?;
97104

98105
// 3. Broadcast the transaction and wait for confirmation.
99-
let (tx_id, _detection_height) = self2.view.broadcast_transaction(tx, true).await?;
100-
Ok(tx_id)
106+
let id = tx.id();
107+
let mut rsp = self2.view.broadcast_transaction(tx, true).await?;
108+
while let Some(rsp) = rsp.try_next().await? {
109+
match rsp.status {
110+
Some(BroadcastStatus::BroadcastSuccess(_)) => {
111+
println!("transaction broadcast successfully: {}", id);
112+
}
113+
Some(BroadcastStatus::Confirmed(c)) => {
114+
println!(
115+
"transaction confirmed and detected: {} @ height {}",
116+
id, c.detection_height
117+
);
118+
return Ok(id);
119+
}
120+
_ => {}
121+
}
122+
}
123+
Err(anyhow::anyhow!(
124+
"view server closed stream without reporting transaction confirmation"
125+
))
101126
}
102127
.boxed()
103128
}
@@ -128,7 +153,7 @@ impl<S> SenderSet<S> {
128153

129154
impl<S> Stream for SenderSet<S>
130155
where
131-
S: Service<(Address, Vec<Value>), Response = penumbra_transaction::Id, Error = anyhow::Error>,
156+
S: Service<(Address, Vec<Value>), Response = TransactionId, Error = anyhow::Error>,
132157
{
133158
type Item = Result<Change<Key, S>, anyhow::Error>;
134159

0 commit comments

Comments
 (0)