-
Notifications
You must be signed in to change notification settings - Fork 11
/
msg.rs
140 lines (124 loc) · 4.98 KB
/
msg.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use cosmwasm_std::{Binary, Coin, CosmosMsg, CustomMsg, Uint128};
use crate::gov::GovProposal;
use crate::hooks::PrivilegeMsg;
#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
/// A number of Custom messages that can be returned by 'privileged' contracts.
/// Returning them from any other contract will return an error and abort the transaction.
pub enum TgradeMsg {
/// request or release some privileges, such as BeginBlocker or TokenMinter
Privilege(PrivilegeMsg),
/// privileged contracts can mint arbitrary native tokens (extends BankMsg)
MintTokens {
denom: String,
amount: Uint128,
recipient: String,
},
/// as well as adjust tendermint consensus params
ConsensusParams(ConsensusParams),
/// Run another contract in "sudo" mode (extends WasmMsg)
WasmSudo {
contract_addr: String,
/// msg is the json-encoded SudoMsg struct (as raw Binary).
/// Note the contract may support different variants than the base TgradeSudoMsg,
/// which defines the base chain->contract interface
msg: Binary,
},
/// This will execute an approved proposal in the Cosmos SDK "Gov Router".
/// That allows access to many of the system internals, like sdk params or x/upgrade,
/// as well as privileged access to the wasm module (eg. mark module privileged)
ExecuteGovProposal {
title: String,
description: String,
proposal: GovProposal,
},
/// This will stake funds from the sender's vesting account. Requires `Delegator` privilege.
Delegate { funds: Coin, staker: String },
/// This will unstake funds to the recipient's vesting account. Requires `Delegator` privilege.
Undelegate { funds: Coin, recipient: String },
}
/// See https://github.com/tendermint/tendermint/blob/v0.34.8/proto/tendermint/abci/types.proto#L282-L289
/// These are various Tendermint Consensus Params that can be adjusted by EndBlockers
/// If any of them are set to Some, then the blockchain will set those as new parameter for tendermint consensus.
///
/// Note: we are not including ValidatorParams, which is used to change the allowed pubkey types for validators
#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug, Default)]
pub struct ConsensusParams {
pub block: Option<BlockParams>,
pub evidence: Option<EvidenceParams>,
}
#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug, Default)]
pub struct BlockParams {
/// Maximum number of bytes (over all tx) to be included in a block
pub max_bytes: Option<i64>,
/// Maximum gas (over all tx) to be executed in one block.
/// If set, more txs may be included in a block, but when executing, all tx after this is limit
/// are consumed will immediately error
pub max_gas: Option<i64>,
}
#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug, Default)]
pub struct EvidenceParams {
/// Max age of evidence, in blocks.
pub max_age_num_blocks: Option<i64>,
/// Max age of evidence, in seconds.
/// It should correspond with an app's "unbonding period"
pub max_age_duration: Option<i64>,
/// Maximum number of bytes of evidence to be included in a block
pub max_bytes: Option<i64>,
}
// we provide some constructor helpers for some common parameter changes
impl ConsensusParams {
/// set -1 for unlimited, positive number for a gas limit over all txs in a block
pub fn max_block_gas(gas: i64) -> Self {
ConsensusParams {
block: Some(BlockParams {
max_bytes: None,
max_gas: Some(gas),
}),
evidence: None,
}
}
/// set -1 for unlimited, positive number for a gas limit over all txs in a block
pub fn max_block_size(bytes: i64) -> Self {
ConsensusParams {
block: Some(BlockParams {
max_bytes: Some(bytes),
max_gas: None,
}),
evidence: None,
}
}
pub fn max_evidence_age(seconds: i64) -> Self {
ConsensusParams {
block: None,
evidence: Some(EvidenceParams {
max_age_num_blocks: None,
max_age_duration: Some(seconds),
max_bytes: None,
}),
}
}
}
impl From<TgradeMsg> for CosmosMsg<TgradeMsg> {
fn from(msg: TgradeMsg) -> CosmosMsg<TgradeMsg> {
CosmosMsg::Custom(msg)
}
}
impl From<PrivilegeMsg> for TgradeMsg {
fn from(msg: PrivilegeMsg) -> TgradeMsg {
TgradeMsg::Privilege(msg)
}
}
impl From<PrivilegeMsg> for CosmosMsg<TgradeMsg> {
fn from(msg: PrivilegeMsg) -> CosmosMsg<TgradeMsg> {
CosmosMsg::Custom(TgradeMsg::from(msg))
}
}
impl From<ConsensusParams> for CosmosMsg<TgradeMsg> {
fn from(params: ConsensusParams) -> CosmosMsg<TgradeMsg> {
CosmosMsg::Custom(TgradeMsg::ConsensusParams(params))
}
}
impl CustomMsg for TgradeMsg {}