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, Default)]
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    /// The required LQT vote authorization signatures, returned in the same order as the
19    /// actions in the original request
20    pub lqt_vote_auths: Vec<Signature<SpendAuth>>,
21}
22
23impl DomainType for AuthorizationData {
24    type Proto = pb::AuthorizationData;
25}
26
27impl From<AuthorizationData> for pb::AuthorizationData {
28    fn from(msg: AuthorizationData) -> Self {
29        Self {
30            effect_hash: msg.effect_hash.map(Into::into),
31            spend_auths: msg.spend_auths.into_iter().map(Into::into).collect(),
32            delegator_vote_auths: msg
33                .delegator_vote_auths
34                .into_iter()
35                .map(Into::into)
36                .collect(),
37            lqt_vote_auths: msg.lqt_vote_auths.into_iter().map(Into::into).collect(),
38        }
39    }
40}
41
42impl TryFrom<pb::AuthorizationData> for AuthorizationData {
43    type Error = anyhow::Error;
44    fn try_from(value: pb::AuthorizationData) -> Result<Self, Self::Error> {
45        Ok(Self {
46            effect_hash: value.effect_hash.map(TryInto::try_into).transpose()?,
47            spend_auths: value
48                .spend_auths
49                .into_iter()
50                .map(TryInto::try_into)
51                .collect::<Result<_, _>>()?,
52            delegator_vote_auths: value
53                .delegator_vote_auths
54                .into_iter()
55                .map(TryInto::try_into)
56                .collect::<Result<_, _>>()?,
57            lqt_vote_auths: value
58                .lqt_vote_auths
59                .into_iter()
60                .map(TryInto::try_into)
61                .collect::<Result<_, _>>()?,
62        })
63    }
64}