neutron_std/types/neutron/
harpoon.rs

1use neutron_std_derive::CosmwasmExt;
2/// Specifies how subscribed contract_addresses are stored in the KV store for each hook type.
3#[allow(clippy::derive_partial_eq_without_eq)]
4#[derive(
5    Clone,
6    PartialEq,
7    Eq,
8    ::prost::Message,
9    ::serde::Serialize,
10    ::serde::Deserialize,
11    ::schemars::JsonSchema,
12    CosmwasmExt,
13)]
14#[proto_message(type_url = "/neutron.harpoon.HookSubscriptions")]
15pub struct HookSubscriptions {
16    /// The hook type being subscribed to.
17    #[prost(enumeration = "HookType", tag = "1")]
18    #[serde(
19        serialize_with = "crate::serde::as_str::serialize",
20        deserialize_with = "crate::serde::as_str::deserialize"
21    )]
22    pub hook_type: i32,
23    /// Contract addresses subscribed to this hook type.
24    #[prost(string, repeated, tag = "2")]
25    pub contract_addresses: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
26}
27/// Hook types that can be subscribed to.
28#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
29#[repr(i32)]
30#[derive(::serde::Serialize, ::serde::Deserialize, ::schemars::JsonSchema)]
31pub enum HookType {
32    Unspecified = 0,
33    /// Triggered after validator is created
34    AfterValidatorCreated = 1,
35    /// Triggered before validator is modified
36    BeforeValidatorModified = 2,
37    /// Triggered after validator is removed
38    AfterValidatorRemoved = 3,
39    /// Triggered after validator is bonded
40    AfterValidatorBonded = 4,
41    /// Triggered after validator begins unbonding
42    AfterValidatorBeginUnbonding = 5,
43    /// Triggered before delegation is created
44    BeforeDelegationCreated = 6,
45    /// Triggered before delegation's shares are modified
46    BeforeDelegationSharesModified = 7,
47    /// Triggered before delegation is removed
48    BeforeDelegationRemoved = 8,
49    /// Triggered after delegation is modified
50    AfterDelegationModified = 9,
51    /// Triggered before validator is slashed
52    BeforeValidatorSlashed = 10,
53    /// Triggered after unbonding is initiated
54    AfterUnbondingInitiated = 11,
55}
56impl HookType {
57    /// String value of the enum field names used in the ProtoBuf definition.
58    ///
59    /// The values are not transformed in any way and thus are considered stable
60    /// (if the ProtoBuf definition does not change) and safe for programmatic use.
61    pub fn as_str_name(&self) -> &'static str {
62        match self {
63            HookType::Unspecified => "HOOK_TYPE_UNSPECIFIED",
64            HookType::AfterValidatorCreated => "HOOK_TYPE_AFTER_VALIDATOR_CREATED",
65            HookType::BeforeValidatorModified => "HOOK_TYPE_BEFORE_VALIDATOR_MODIFIED",
66            HookType::AfterValidatorRemoved => "HOOK_TYPE_AFTER_VALIDATOR_REMOVED",
67            HookType::AfterValidatorBonded => "HOOK_TYPE_AFTER_VALIDATOR_BONDED",
68            HookType::AfterValidatorBeginUnbonding => "HOOK_TYPE_AFTER_VALIDATOR_BEGIN_UNBONDING",
69            HookType::BeforeDelegationCreated => "HOOK_TYPE_BEFORE_DELEGATION_CREATED",
70            HookType::BeforeDelegationSharesModified => {
71                "HOOK_TYPE_BEFORE_DELEGATION_SHARES_MODIFIED"
72            }
73            HookType::BeforeDelegationRemoved => "HOOK_TYPE_BEFORE_DELEGATION_REMOVED",
74            HookType::AfterDelegationModified => "HOOK_TYPE_AFTER_DELEGATION_MODIFIED",
75            HookType::BeforeValidatorSlashed => "HOOK_TYPE_BEFORE_VALIDATOR_SLASHED",
76            HookType::AfterUnbondingInitiated => "HOOK_TYPE_AFTER_UNBONDING_INITIATED",
77        }
78    }
79    /// Creates an enum from field names used in the ProtoBuf definition.
80    pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
81        match value {
82            "HOOK_TYPE_UNSPECIFIED" => Some(Self::Unspecified),
83            "HOOK_TYPE_AFTER_VALIDATOR_CREATED" => Some(Self::AfterValidatorCreated),
84            "HOOK_TYPE_BEFORE_VALIDATOR_MODIFIED" => Some(Self::BeforeValidatorModified),
85            "HOOK_TYPE_AFTER_VALIDATOR_REMOVED" => Some(Self::AfterValidatorRemoved),
86            "HOOK_TYPE_AFTER_VALIDATOR_BONDED" => Some(Self::AfterValidatorBonded),
87            "HOOK_TYPE_AFTER_VALIDATOR_BEGIN_UNBONDING" => Some(Self::AfterValidatorBeginUnbonding),
88            "HOOK_TYPE_BEFORE_DELEGATION_CREATED" => Some(Self::BeforeDelegationCreated),
89            "HOOK_TYPE_BEFORE_DELEGATION_SHARES_MODIFIED" => {
90                Some(Self::BeforeDelegationSharesModified)
91            }
92            "HOOK_TYPE_BEFORE_DELEGATION_REMOVED" => Some(Self::BeforeDelegationRemoved),
93            "HOOK_TYPE_AFTER_DELEGATION_MODIFIED" => Some(Self::AfterDelegationModified),
94            "HOOK_TYPE_BEFORE_VALIDATOR_SLASHED" => Some(Self::BeforeValidatorSlashed),
95            "HOOK_TYPE_AFTER_UNBONDING_INITIATED" => Some(Self::AfterUnbondingInitiated),
96            _ => None,
97        }
98    }
99}
100/// Harpoon module genesis state.
101#[allow(clippy::derive_partial_eq_without_eq)]
102#[derive(
103    Clone,
104    PartialEq,
105    Eq,
106    ::prost::Message,
107    ::serde::Serialize,
108    ::serde::Deserialize,
109    ::schemars::JsonSchema,
110    CosmwasmExt,
111)]
112#[proto_message(type_url = "/neutron.harpoon.GenesisState")]
113pub struct GenesisState {
114    /// List of hooks
115    #[prost(message, repeated, tag = "1")]
116    pub hook_subscriptions: ::prost::alloc::vec::Vec<HookSubscriptions>,
117}
118/// Request type for the Query/SubscribedContracts RPC method.
119#[allow(clippy::derive_partial_eq_without_eq)]
120#[derive(
121    Clone,
122    PartialEq,
123    Eq,
124    ::prost::Message,
125    ::serde::Serialize,
126    ::serde::Deserialize,
127    ::schemars::JsonSchema,
128    CosmwasmExt,
129)]
130#[proto_message(type_url = "/neutron.harpoon.QuerySubscribedContractsRequest")]
131#[proto_query(
132    path = "/neutron.harpoon.Query/SubscribedContracts",
133    response_type = QuerySubscribedContractsResponse
134)]
135pub struct QuerySubscribedContractsRequest {
136    /// The response will include only contract addresses for this hook type.
137    #[prost(enumeration = "HookType", tag = "1")]
138    #[serde(
139        serialize_with = "crate::serde::as_str::serialize",
140        deserialize_with = "crate::serde::as_str::deserialize"
141    )]
142    pub hook_type: i32,
143}
144/// Response type for the Query/SubscribedContracts RPC method.
145#[allow(clippy::derive_partial_eq_without_eq)]
146#[derive(
147    Clone,
148    PartialEq,
149    Eq,
150    ::prost::Message,
151    ::serde::Serialize,
152    ::serde::Deserialize,
153    ::schemars::JsonSchema,
154    CosmwasmExt,
155)]
156#[proto_message(type_url = "/neutron.harpoon.QuerySubscribedContractsResponse")]
157pub struct QuerySubscribedContractsResponse {
158    /// List of contract addresses subscribed to a specific hook.
159    #[prost(string, repeated, tag = "1")]
160    pub contract_addresses: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
161}
162/// Defines the Msg/ManageHookSubscription request type.
163#[allow(clippy::derive_partial_eq_without_eq)]
164#[derive(
165    Clone,
166    PartialEq,
167    Eq,
168    ::prost::Message,
169    ::serde::Serialize,
170    ::serde::Deserialize,
171    ::schemars::JsonSchema,
172    CosmwasmExt,
173)]
174#[proto_message(type_url = "/neutron.harpoon.MsgManageHookSubscription")]
175pub struct MsgManageHookSubscription {
176    /// Address of the governance account.
177    #[prost(string, tag = "1")]
178    pub authority: ::prost::alloc::string::String,
179    /// Hook subscription to be updated.
180    #[prost(message, optional, tag = "2")]
181    pub hook_subscription: ::core::option::Option<HookSubscription>,
182}
183/// Defines the response structure for executing a MsgManageHookSubscription message.
184#[allow(clippy::derive_partial_eq_without_eq)]
185#[derive(
186    Clone,
187    PartialEq,
188    Eq,
189    ::prost::Message,
190    ::serde::Serialize,
191    ::serde::Deserialize,
192    ::schemars::JsonSchema,
193    CosmwasmExt,
194)]
195#[proto_message(type_url = "/neutron.harpoon.MsgManageHookSubscriptionResponse")]
196pub struct MsgManageHookSubscriptionResponse {}
197/// Specifies new hook subscriptions for the contract_address.
198#[allow(clippy::derive_partial_eq_without_eq)]
199#[derive(
200    Clone,
201    PartialEq,
202    Eq,
203    ::prost::Message,
204    ::serde::Serialize,
205    ::serde::Deserialize,
206    ::schemars::JsonSchema,
207    CosmwasmExt,
208)]
209#[proto_message(type_url = "/neutron.harpoon.HookSubscription")]
210pub struct HookSubscription {
211    /// Contract address to update subscriptions for.
212    #[prost(string, tag = "2")]
213    pub contract_address: ::prost::alloc::string::String,
214    /// List of hooks to subscribe to. Hooks not listed here will be removed.
215    #[prost(enumeration = "HookType", repeated, tag = "3")]
216    #[serde(
217        serialize_with = "crate::serde::as_str_vec::serialize",
218        deserialize_with = "crate::serde::as_str_vec::deserialize"
219    )]
220    pub hooks: ::prost::alloc::vec::Vec<i32>,
221}
222pub struct HarpoonQuerier<'a, Q: cosmwasm_std::CustomQuery> {
223    querier: &'a cosmwasm_std::QuerierWrapper<'a, Q>,
224}
225impl<'a, Q: cosmwasm_std::CustomQuery> HarpoonQuerier<'a, Q> {
226    pub fn new(querier: &'a cosmwasm_std::QuerierWrapper<'a, Q>) -> Self {
227        Self { querier }
228    }
229    pub fn subscribed_contracts(
230        &self,
231        hook_type: i32,
232    ) -> Result<QuerySubscribedContractsResponse, cosmwasm_std::StdError> {
233        QuerySubscribedContractsRequest { hook_type }.query(self.querier)
234    }
235}