penumbra_sdk_custody/
request.rs

1use penumbra_sdk_governance::ValidatorVoteBody;
2use penumbra_sdk_proto::{custody::v1 as pb, DomainType};
3use penumbra_sdk_stake::validator::Validator;
4use penumbra_sdk_transaction::TransactionPlan;
5
6use crate::PreAuthorization;
7
8/// A transaction authorization request submitted to a custody service for approval.
9#[derive(Debug, Clone)]
10pub struct AuthorizeRequest {
11    /// The transaction plan to authorize.
12    pub plan: TransactionPlan,
13    /// Optionally, pre-authorization data, if required by the custodian.
14    pub pre_authorizations: Vec<PreAuthorization>,
15}
16
17impl DomainType for AuthorizeRequest {
18    type Proto = pb::AuthorizeRequest;
19}
20
21impl TryFrom<pb::AuthorizeRequest> for AuthorizeRequest {
22    type Error = anyhow::Error;
23    fn try_from(value: pb::AuthorizeRequest) -> Result<Self, Self::Error> {
24        Ok(Self {
25            plan: value
26                .plan
27                .ok_or_else(|| anyhow::anyhow!("missing plan"))?
28                .try_into()?,
29            pre_authorizations: value
30                .pre_authorizations
31                .into_iter()
32                .map(TryInto::try_into)
33                .collect::<Result<Vec<_>, _>>()?,
34        })
35    }
36}
37
38impl From<AuthorizeRequest> for pb::AuthorizeRequest {
39    fn from(value: AuthorizeRequest) -> pb::AuthorizeRequest {
40        Self {
41            plan: Some(value.plan.into()),
42            pre_authorizations: value
43                .pre_authorizations
44                .into_iter()
45                .map(Into::into)
46                .collect(),
47        }
48    }
49}
50
51/// A validator definition authorization request submitted to a custody service for approval.
52#[derive(Debug, Clone)]
53pub struct AuthorizeValidatorDefinitionRequest {
54    /// The validator definition to authorize.
55    pub validator_definition: Validator,
56    /// Optionally, pre-authorization data, if required by the custodian.
57    pub pre_authorizations: Vec<PreAuthorization>,
58}
59
60impl DomainType for AuthorizeValidatorDefinitionRequest {
61    type Proto = pb::AuthorizeValidatorDefinitionRequest;
62}
63
64impl TryFrom<pb::AuthorizeValidatorDefinitionRequest> for AuthorizeValidatorDefinitionRequest {
65    type Error = anyhow::Error;
66    fn try_from(value: pb::AuthorizeValidatorDefinitionRequest) -> Result<Self, Self::Error> {
67        Ok(Self {
68            validator_definition: value
69                .validator_definition
70                .ok_or_else(|| anyhow::anyhow!("missing validator definition"))?
71                .try_into()?,
72            pre_authorizations: value
73                .pre_authorizations
74                .into_iter()
75                .map(TryInto::try_into)
76                .collect::<Result<Vec<_>, _>>()?,
77        })
78    }
79}
80
81impl From<AuthorizeValidatorDefinitionRequest> for pb::AuthorizeValidatorDefinitionRequest {
82    fn from(value: AuthorizeValidatorDefinitionRequest) -> pb::AuthorizeValidatorDefinitionRequest {
83        Self {
84            validator_definition: Some(value.validator_definition.into()),
85            pre_authorizations: value
86                .pre_authorizations
87                .into_iter()
88                .map(Into::into)
89                .collect(),
90        }
91    }
92}
93
94/// A validator vote authorization request submitted to a custody service for approval.
95#[derive(Debug, Clone)]
96pub struct AuthorizeValidatorVoteRequest {
97    /// The transaction plan to authorize.
98    pub validator_vote: ValidatorVoteBody,
99    /// Optionally, pre-authorization data, if required by the custodian.
100    pub pre_authorizations: Vec<PreAuthorization>,
101}
102
103impl DomainType for AuthorizeValidatorVoteRequest {
104    type Proto = pb::AuthorizeValidatorVoteRequest;
105}
106
107impl TryFrom<pb::AuthorizeValidatorVoteRequest> for AuthorizeValidatorVoteRequest {
108    type Error = anyhow::Error;
109    fn try_from(value: pb::AuthorizeValidatorVoteRequest) -> Result<Self, Self::Error> {
110        Ok(Self {
111            validator_vote: value
112                .validator_vote
113                .ok_or_else(|| anyhow::anyhow!("missing validator vote"))?
114                .try_into()?,
115            pre_authorizations: value
116                .pre_authorizations
117                .into_iter()
118                .map(TryInto::try_into)
119                .collect::<Result<Vec<_>, _>>()?,
120        })
121    }
122}
123
124impl From<AuthorizeValidatorVoteRequest> for pb::AuthorizeValidatorVoteRequest {
125    fn from(value: AuthorizeValidatorVoteRequest) -> pb::AuthorizeValidatorVoteRequest {
126        Self {
127            validator_vote: Some(value.validator_vote.into()),
128            pre_authorizations: value
129                .pre_authorizations
130                .into_iter()
131                .map(Into::into)
132                .collect(),
133        }
134    }
135}