Skip to content

Commit

Permalink
feat: add summary to TransactionInfo (#5102)
Browse files Browse the repository at this point in the history
Adds a `summary` field of type `TransactionSummary` to `TransactionInfo`
proto.

Mostly needed for Web because Rust ecosystem can simply do
`tx_info.view.summary()` but Web would have to re-implement this feature
in TypeScript
  • Loading branch information
VanishMax authored Feb 21, 2025
1 parent f0b0db5 commit 9e1c21d
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 2 deletions.
2 changes: 2 additions & 0 deletions crates/bin/pcli/src/command/view/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ impl TxCmd {
let tx = Transaction::decode(rsp.tx.as_slice())?;
let txp = Default::default();
let txv = tx.view_from_perspective(&txp);
let summary = txv.summary();

TransactionInfo {
height: rsp.height,
id: hash,
transaction: tx,
perspective: txp,
view: txv,
summary: summary,
}
};

Expand Down
2 changes: 1 addition & 1 deletion crates/core/transaction/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub use is_action::IsAction;
pub use parameters::TransactionParameters;
pub use penumbra_sdk_txhash as txhash;
pub use plan::{ActionPlan, TransactionPlan};
pub use transaction::{Transaction, TransactionBody};
pub use transaction::{Transaction, TransactionBody, TransactionSummary};
pub use view::{ActionView, MemoPlaintextView, MemoView, TransactionPerspective, TransactionView};
pub use witness_data::WitnessData;

Expand Down
5 changes: 5 additions & 0 deletions crates/proto/src/gen/penumbra.view.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,11 @@ pub struct TransactionInfo {
pub view: ::core::option::Option<
super::super::core::transaction::v1::TransactionView,
>,
/// A short view of balances leaving and entering accounts, computed from transaction actions.
#[prost(message, optional, tag = "6")]
pub summary: ::core::option::Option<
super::super::core::transaction::v1::TransactionSummary,
>,
}
impl ::prost::Name for TransactionInfo {
const NAME: &'static str = "TransactionInfo";
Expand Down
17 changes: 17 additions & 0 deletions crates/proto/src/gen/penumbra.view.v1.serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5870,6 +5870,9 @@ impl serde::Serialize for TransactionInfo {
if self.view.is_some() {
len += 1;
}
if self.summary.is_some() {
len += 1;
}
let mut struct_ser = serializer.serialize_struct("penumbra.view.v1.TransactionInfo", len)?;
if self.height != 0 {
#[allow(clippy::needless_borrow)]
Expand All @@ -5888,6 +5891,9 @@ impl serde::Serialize for TransactionInfo {
if let Some(v) = self.view.as_ref() {
struct_ser.serialize_field("view", v)?;
}
if let Some(v) = self.summary.as_ref() {
struct_ser.serialize_field("summary", v)?;
}
struct_ser.end()
}
}
Expand All @@ -5903,6 +5909,7 @@ impl<'de> serde::Deserialize<'de> for TransactionInfo {
"transaction",
"perspective",
"view",
"summary",
];

#[allow(clippy::enum_variant_names)]
Expand All @@ -5912,6 +5919,7 @@ impl<'de> serde::Deserialize<'de> for TransactionInfo {
Transaction,
Perspective,
View,
Summary,
__SkipField__,
}
impl<'de> serde::Deserialize<'de> for GeneratedField {
Expand Down Expand Up @@ -5939,6 +5947,7 @@ impl<'de> serde::Deserialize<'de> for TransactionInfo {
"transaction" => Ok(GeneratedField::Transaction),
"perspective" => Ok(GeneratedField::Perspective),
"view" => Ok(GeneratedField::View),
"summary" => Ok(GeneratedField::Summary),
_ => Ok(GeneratedField::__SkipField__),
}
}
Expand All @@ -5963,6 +5972,7 @@ impl<'de> serde::Deserialize<'de> for TransactionInfo {
let mut transaction__ = None;
let mut perspective__ = None;
let mut view__ = None;
let mut summary__ = None;
while let Some(k) = map_.next_key()? {
match k {
GeneratedField::Height => {
Expand Down Expand Up @@ -5997,6 +6007,12 @@ impl<'de> serde::Deserialize<'de> for TransactionInfo {
}
view__ = map_.next_value()?;
}
GeneratedField::Summary => {
if summary__.is_some() {
return Err(serde::de::Error::duplicate_field("summary"));
}
summary__ = map_.next_value()?;
}
GeneratedField::__SkipField__ => {
let _ = map_.next_value::<serde::de::IgnoredAny>()?;
}
Expand All @@ -6008,6 +6024,7 @@ impl<'de> serde::Deserialize<'de> for TransactionInfo {
transaction: transaction__,
perspective: perspective__,
view: view__,
summary: summary__,
})
}
}
Expand Down
Binary file modified crates/proto/src/gen/proto_descriptor.bin.no_lfs
Binary file not shown.
8 changes: 8 additions & 0 deletions crates/view/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,10 @@ where
.view
.ok_or_else(|| anyhow::anyhow!("missing view"))?
.try_into()?,
summary: rsp
.summary
.ok_or_else(|| anyhow::anyhow!("missing summary"))?
.try_into()?,
};

Ok(tx_info)
Expand Down Expand Up @@ -826,6 +830,10 @@ where
.view
.ok_or_else(|| anyhow::anyhow!("missing view"))?
.try_into()?,
summary: tx_rsp
.summary
.ok_or_else(|| anyhow::anyhow!("missing summary"))?
.try_into()?,
};

Ok(tx_info)
Expand Down
2 changes: 2 additions & 0 deletions crates/view/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,7 @@ impl ViewService for ViewServer {

// Finally, compute the full TxV from the full TxP:
let txv = tx.view_from_perspective(&txp);
let summary = txv.summary();

let response = pb::TransactionInfoByHashResponse {
tx_info: Some(pb::TransactionInfo {
Expand All @@ -1067,6 +1068,7 @@ impl ViewService for ViewServer {
perspective: Some(txp.into()),
transaction: Some(tx.into()),
view: Some(txv.into()),
summary: Some(summary.into()),
}),
};

Expand Down
4 changes: 3 additions & 1 deletion crates/view/src/transaction_info.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use penumbra_sdk_transaction::{
txhash::TransactionId, Transaction, TransactionPerspective, TransactionView,
txhash::TransactionId, Transaction, TransactionPerspective, TransactionSummary, TransactionView,
};

#[derive(Debug, Clone)]
Expand All @@ -14,4 +14,6 @@ pub struct TransactionInfo {
pub perspective: TransactionPerspective,
// A precomputed transaction view of `transaction` from `perspective`, included for convenience of clients that don't have support for viewing transactions on their own.
pub view: TransactionView,
// A short view of balances leaving and entering accounts, computed from transaction actions.
pub summary: TransactionSummary,
}
2 changes: 2 additions & 0 deletions proto/penumbra/penumbra/view/v1/view.proto
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,8 @@ message TransactionInfo {
core.transaction.v1.TransactionPerspective perspective = 4;
// A precomputed transaction view of `transaction` from `perspective`, included for convenience of clients that don't have support for viewing transactions on their own.
core.transaction.v1.TransactionView view = 5;
// A short view of balances leaving and entering accounts, computed from transaction actions.
core.transaction.v1.TransactionSummary summary = 6;
}

message TransactionInfoResponse {
Expand Down

0 comments on commit 9e1c21d

Please sign in to comment.