tg_bindings/
hooks.rs

1use crate::TgradeMsg;
2use cosmwasm_std::SubMsg;
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug, Copy)]
7#[serde(rename_all = "snake_case")]
8pub enum Privilege {
9    /// contracts registered here are called the beginning of each block with possible double-sign evidence
10    BeginBlocker,
11    /// contracts registered here are called the end of every block
12    EndBlocker,
13    /// only max 1 contract can be registered here, this is called in EndBlock (after everything else) and can change the validator set.
14    ValidatorSetUpdater,
15    /// contracts registered here are allowed to call ExecuteGovProposal{}
16    /// (Any privileged contract *can* register, but this means you must explicitly request permission before sending such a message)
17    GovProposalExecutor,
18    /// contracts registered here are allowed to use WasmSudo msg to call other contracts
19    Sudoer,
20    /// contracts registered here are allowed to use MintTokens msg
21    TokenMinter,
22    /// contracts registered here are allowed to use ConsensusParams msg to adjust tendermint
23    ConsensusParamChanger,
24    /// contracts registered here are allowed to use Delegate / Undelegate to stake funds using the
25    /// Cosmos SDK
26    Delegator,
27    /// contracts registered here are allowed to use Export / Import to export / import their state
28    StateExporterImporter,
29}
30
31#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)]
32#[serde(rename_all = "snake_case")]
33pub enum PrivilegeMsg {
34    Request(Privilege),
35    Release(Privilege),
36}
37
38pub fn request_privileges(privileges: &[Privilege]) -> Vec<SubMsg<TgradeMsg>> {
39    privileges
40        .iter()
41        .map(|x| SubMsg::new(PrivilegeMsg::Request(*x)))
42        .collect()
43}