penumbra_sdk_transaction/
auth_data.rs

1use decaf377_rdsa::{Signature, SpendAuth};
2
3use penumbra_sdk_proto::{core::transaction::v1 as pb, DomainType};
4use penumbra_sdk_txhash::EffectHash;
5
6/// Authorization data returned in response to a
7/// [`TransactionDescription`](crate::TransactionDescription).
8#[derive(Clone, Debug)]
9pub struct AuthorizationData {
10    /// The computed authorization hash for the approved transaction.
11    pub effect_hash: Option<EffectHash>,
12    /// The required spend authorization signatures, returned in the same order as the Spend actions
13    /// in the original request.
14    pub spend_auths: Vec<Signature<SpendAuth>>,
15    /// The required delegator vote authorization signatures, returned in the same order as the
16    /// DelegatorVote actions in the original request.
17    pub delegator_vote_auths: Vec<Signature<SpendAuth>>,
18}
19
20impl DomainType for AuthorizationData {
21    type Proto = pb::AuthorizationData;
22}
23
24impl From<AuthorizationData> for pb::AuthorizationData {
25    fn from(msg: AuthorizationData) -> Self {
26        Self {
27            effect_hash: msg.effect_hash.map(Into::into),
28            spend_auths: msg.spend_auths.into_iter().map(Into::into).collect(),
29            delegator_vote_auths: msg
30                .delegator_vote_auths
31                .into_iter()
32                .map(Into::into)
33                .collect(),
34        }
35    }
36}
37
38impl TryFrom<pb::AuthorizationData> for AuthorizationData {
39    type Error = anyhow::Error;
40    fn try_from(value: pb::AuthorizationData) -> Result<Self, Self::Error> {
41        Ok(Self {
42            effect_hash: value.effect_hash.map(TryInto::try_into).transpose()?,
43            spend_auths: value
44                .spend_auths
45                .into_iter()
46                .map(TryInto::try_into)
47                .collect::<Result<_, _>>()?,
48            delegator_vote_auths: value
49                .delegator_vote_auths
50                .into_iter()
51                .map(TryInto::try_into)
52                .collect::<Result<_, _>>()?,
53        })
54    }
55}