@@ -4,40 +4,52 @@ use super::{
4
4
EmptyMemo , Hop , MemoSource , WithCallbacks , WithDstCallback , WithMemo , WithSrcCallback ,
5
5
} ;
6
6
7
- impl < M : MemoSource > TransferMsgBuilderV2 < M > {
7
+ impl < M : MemoSource , F : Into < Vec < Hop > > > TransferMsgBuilderV2 < M , F > {
8
8
pub fn build ( self ) -> IbcMsg {
9
9
IbcMsg :: TransferV2 {
10
10
channel_id : self . channel_id ,
11
11
to_address : self . to_address ,
12
12
tokens : self . tokens ,
13
13
timeout : self . timeout ,
14
14
memo : self . memo . into_memo ( ) ,
15
- forwarding : self . forwarding ,
15
+ forwarding : self . forwarding . into ( ) ,
16
16
}
17
17
}
18
18
}
19
19
20
20
#[ derive( Clone , Debug , PartialEq , Eq ) ]
21
- pub struct TransferMsgBuilderV2 < MemoData > {
21
+ pub struct TransferMsgBuilderV2 < MemoData , ForwardingData > {
22
22
channel_id : String ,
23
23
to_address : String ,
24
24
tokens : Vec < Coin > ,
25
25
timeout : IbcTimeout ,
26
26
memo : MemoData ,
27
- forwarding : Vec < Hop > ,
27
+ forwarding : ForwardingData ,
28
28
}
29
29
30
30
#[ derive( Clone , Debug , PartialEq , Eq ) ]
31
31
#[ non_exhaustive]
32
- pub struct WithForwarding ;
32
+ pub struct WithoutForwarding ;
33
+
34
+ #[ derive( Clone , Debug , PartialEq , Eq ) ]
35
+ #[ non_exhaustive]
36
+ pub struct WithForwarding {
37
+ pub ( crate ) forwarding : Vec < Hop > ,
38
+ }
33
39
34
- impl MemoSource for WithForwarding {
35
- fn into_memo ( self ) -> Option < String > {
36
- None
40
+ impl From < WithoutForwarding > for Vec < Hop > {
41
+ fn from ( _val : WithoutForwarding ) -> Self {
42
+ vec ! [ ]
37
43
}
38
44
}
39
45
40
- impl TransferMsgBuilderV2 < EmptyMemo > {
46
+ impl From < WithForwarding > for Vec < Hop > {
47
+ fn from ( val : WithForwarding ) -> Self {
48
+ val. forwarding
49
+ }
50
+ }
51
+
52
+ impl TransferMsgBuilderV2 < EmptyMemo , WithoutForwarding > {
41
53
/// Creates a new transfer message with the given parameters and no memo.
42
54
pub fn new (
43
55
channel_id : impl Into < String > ,
@@ -51,12 +63,15 @@ impl TransferMsgBuilderV2<EmptyMemo> {
51
63
tokens,
52
64
timeout : timeout. into ( ) ,
53
65
memo : EmptyMemo ,
54
- forwarding : vec ! [ ] ,
66
+ forwarding : WithoutForwarding ,
55
67
}
56
68
}
57
69
58
70
/// Adds a memo text to the transfer message.
59
- pub fn with_memo ( self , memo : impl Into < String > ) -> TransferMsgBuilderV2 < WithMemo > {
71
+ pub fn with_memo (
72
+ self ,
73
+ memo : impl Into < String > ,
74
+ ) -> TransferMsgBuilderV2 < WithMemo , WithoutForwarding > {
60
75
TransferMsgBuilderV2 {
61
76
channel_id : self . channel_id ,
62
77
to_address : self . to_address ,
@@ -74,7 +89,7 @@ impl TransferMsgBuilderV2<EmptyMemo> {
74
89
pub fn with_src_callback (
75
90
self ,
76
91
src_callback : IbcSrcCallback ,
77
- ) -> TransferMsgBuilderV2 < WithSrcCallback > {
92
+ ) -> TransferMsgBuilderV2 < WithSrcCallback , WithoutForwarding > {
78
93
TransferMsgBuilderV2 {
79
94
channel_id : self . channel_id ,
80
95
to_address : self . to_address ,
@@ -92,7 +107,7 @@ impl TransferMsgBuilderV2<EmptyMemo> {
92
107
pub fn with_dst_callback (
93
108
self ,
94
109
dst_callback : IbcDstCallback ,
95
- ) -> TransferMsgBuilderV2 < WithDstCallback > {
110
+ ) -> TransferMsgBuilderV2 < WithDstCallback , WithoutForwarding > {
96
111
TransferMsgBuilderV2 {
97
112
channel_id : self . channel_id ,
98
113
to_address : self . to_address ,
@@ -105,29 +120,32 @@ impl TransferMsgBuilderV2<EmptyMemo> {
105
120
106
121
/// Adds forwarding data.
107
122
/// It is worth to notice that the builder does not allow to add forwarding data along with
108
- /// callbacks. It is discouraged in the IBC docs:
109
- /// https://github.com/cosmos/ibc-go/blob/main/docs/docs/04-middleware/02-callbacks/01-overview.md#known-limitations
110
- pub fn with_forwarding ( self , forwarding : Vec < Hop > ) -> TransferMsgBuilderV2 < WithForwarding > {
123
+ /// source callback. It is discouraged in the IBC docs:
124
+ /// https://ibc.cosmos.network/v9/middleware/callbacks/overview/#known-limitations
125
+ pub fn with_forwarding (
126
+ self ,
127
+ forwarding : Vec < Hop > ,
128
+ ) -> TransferMsgBuilderV2 < EmptyMemo , WithForwarding > {
111
129
TransferMsgBuilderV2 {
112
130
channel_id : self . channel_id ,
113
131
to_address : self . to_address ,
114
132
tokens : self . tokens ,
115
133
timeout : self . timeout ,
116
- memo : WithForwarding ,
117
- forwarding,
134
+ memo : self . memo ,
135
+ forwarding : WithForwarding { forwarding } ,
118
136
}
119
137
}
120
138
}
121
139
122
- impl TransferMsgBuilderV2 < WithSrcCallback > {
140
+ impl TransferMsgBuilderV2 < WithSrcCallback , WithoutForwarding > {
123
141
/// Adds an IBC destination callback entry to the memo field.
124
142
/// Use this if you want to receive IBC callbacks on the destination chain.
125
143
///
126
144
/// For more info check out [`crate::IbcDestinationCallbackMsg`].
127
145
pub fn with_dst_callback (
128
146
self ,
129
147
dst_callback : IbcDstCallback ,
130
- ) -> TransferMsgBuilderV2 < WithCallbacks > {
148
+ ) -> TransferMsgBuilderV2 < WithCallbacks , WithoutForwarding > {
131
149
TransferMsgBuilderV2 {
132
150
channel_id : self . channel_id ,
133
151
to_address : self . to_address ,
@@ -142,15 +160,15 @@ impl TransferMsgBuilderV2<WithSrcCallback> {
142
160
}
143
161
}
144
162
145
- impl TransferMsgBuilderV2 < WithDstCallback > {
163
+ impl TransferMsgBuilderV2 < WithDstCallback , WithoutForwarding > {
146
164
/// Adds an IBC source callback entry to the memo field.
147
165
/// Use this if you want to receive IBC callbacks on the source chain.
148
166
///
149
167
/// For more info check out [`crate::IbcSourceCallbackMsg`].
150
168
pub fn with_src_callback (
151
169
self ,
152
170
src_callback : IbcSrcCallback ,
153
- ) -> TransferMsgBuilderV2 < WithCallbacks > {
171
+ ) -> TransferMsgBuilderV2 < WithCallbacks , WithoutForwarding > {
154
172
TransferMsgBuilderV2 {
155
173
channel_id : self . channel_id ,
156
174
to_address : self . to_address ,
@@ -163,6 +181,24 @@ impl TransferMsgBuilderV2<WithDstCallback> {
163
181
forwarding : self . forwarding ,
164
182
}
165
183
}
184
+
185
+ /// Adds forwarding data.
186
+ /// It is worth to notice that the builder does not allow to add forwarding data along with
187
+ /// source callback. It is discouraged in the IBC docs:
188
+ /// https://ibc.cosmos.network/v9/middleware/callbacks/overview/#known-limitations
189
+ pub fn with_forwarding (
190
+ self ,
191
+ forwarding : Vec < Hop > ,
192
+ ) -> TransferMsgBuilderV2 < WithDstCallback , WithForwarding > {
193
+ TransferMsgBuilderV2 {
194
+ channel_id : self . channel_id ,
195
+ to_address : self . to_address ,
196
+ tokens : self . tokens ,
197
+ timeout : self . timeout ,
198
+ memo : self . memo ,
199
+ forwarding : WithForwarding { forwarding } ,
200
+ }
201
+ }
166
202
}
167
203
168
204
#[ cfg( test) ]
0 commit comments