@@ -50,64 +50,48 @@ where
50
50
/// This is used for cases when we use ReplyOn::Never and the id doesn't matter
51
51
pub const UNUSED_MSG_ID : u64 = 123456789 ;
52
52
53
- /// We implement thisas a shortcut so all existing code doesn't break.
54
- /// Up to 0.14, we could do something like:
55
- /// let messages = vec![BankMsg::Send { .. }.into()];
56
- /// In order to construct the response.
57
- ///
58
- /// With 0.15, we move to requiring SubMsg there, but this allows the same
59
- /// `.into()` call to convert the BankMsg into a proper SubMsg with no reply.
60
- impl < M , T > From < M > for SubMsg < T >
61
- where
62
- M : Into < CosmosMsg < T > > ,
63
- T : Clone + fmt:: Debug + PartialEq + JsonSchema ,
64
- {
65
- #[ inline]
66
- fn from ( msg : M ) -> SubMsg < T > {
67
- call ( msg)
68
- }
69
- }
70
-
71
- /// call takes eg. BankMsg::Send{} and wraps it into a SubMsg with normal message sematics (no reply)
72
- pub fn call < M , T > ( msg : M ) -> SubMsg < T >
73
- where
74
- M : Into < CosmosMsg < T > > ,
75
- T : Clone + fmt:: Debug + PartialEq + JsonSchema ,
76
- {
77
- SubMsg {
78
- id : UNUSED_MSG_ID ,
79
- msg : msg. into ( ) ,
80
- reply_on : ReplyOn :: Never ,
81
- gas_limit : None ,
82
- }
83
- }
84
-
85
53
impl < T > SubMsg < T >
86
54
where
87
55
T : Clone + fmt:: Debug + PartialEq + JsonSchema ,
88
56
{
89
- /// new takes eg. BankMsg::Send{} and sets up for a reply. No gas limit is set.
90
- pub fn new < M : Into < CosmosMsg < T > > > ( msg : M , id : u64 , reply_on : ReplyOn ) -> Self {
57
+ /// new creates a "fire and forget" message with the pre-0.14 semantics
58
+ pub fn new < M : Into < CosmosMsg < T > > > ( msg : M ) -> Self {
91
59
SubMsg {
92
- id,
60
+ id : UNUSED_MSG_ID ,
93
61
msg : msg. into ( ) ,
94
- reply_on,
62
+ reply_on : ReplyOn :: Never ,
95
63
gas_limit : None ,
96
64
}
97
65
}
98
66
99
- /// new_with_limit is like new but allows setting a gas limit
100
- pub fn new_with_limit < M : Into < CosmosMsg < T > > > (
101
- msg : M ,
102
- id : u64 ,
103
- reply_on : ReplyOn ,
104
- gas_limit : u64 ,
105
- ) -> Self {
67
+ /// create a `SubMsg` that will provide a `reply` with the given id if the message returns `Ok`
68
+ pub fn reply_on_success < M : Into < CosmosMsg < T > > > ( msg : M , id : u64 ) -> Self {
69
+ Self :: reply_on ( msg. into ( ) , id, ReplyOn :: Success )
70
+ }
71
+
72
+ /// create a `SubMsg` that will provide a `reply` with the given id if the message returns `Err`
73
+ pub fn reply_on_error < M : Into < CosmosMsg < T > > > ( msg : M , id : u64 ) -> Self {
74
+ Self :: reply_on ( msg. into ( ) , id, ReplyOn :: Error )
75
+ }
76
+
77
+ /// create a `SubMsg` that will always provide a `reply` with the given id
78
+ pub fn reply_always < M : Into < CosmosMsg < T > > > ( msg : M , id : u64 ) -> Self {
79
+ Self :: reply_on ( msg. into ( ) , id, ReplyOn :: Always )
80
+ }
81
+
82
+ /// add a gas limit to the message. Usage like:
83
+ /// SubMsg::reply_always(msg, 1234).with_gas_limit(60_000)
84
+ pub fn with_gas_limit ( mut self , limit : u64 ) -> Self {
85
+ self . gas_limit = Some ( limit) ;
86
+ self
87
+ }
88
+
89
+ fn reply_on ( msg : CosmosMsg < T > , id : u64 , reply_on : ReplyOn ) -> Self {
106
90
SubMsg {
107
91
id,
108
- msg : msg . into ( ) ,
92
+ msg,
109
93
reply_on,
110
- gas_limit : Some ( gas_limit ) ,
94
+ gas_limit : None ,
111
95
}
112
96
}
113
97
}
0 commit comments