@@ -121,46 +121,64 @@ where
121
121
}
122
122
123
123
pub trait ConvertBalance < A , B > {
124
- fn convert_balance ( amount : A ) -> B ;
125
- fn convert_balance_back ( amount : B ) -> A ;
124
+ type AssetId ;
125
+ fn convert_balance ( amount : A , asset_id : Self :: AssetId ) -> B ;
126
+ fn convert_balance_back ( amount : B , asset_id : Self :: AssetId ) -> A ;
126
127
}
127
128
128
129
pub struct Mapper < AccountId , T , C , B , GetCurrencyId > ( sp_std:: marker:: PhantomData < ( AccountId , T , C , B , GetCurrencyId ) > ) ;
129
130
impl < AccountId , T , C , B , GetCurrencyId > fungible:: Inspect < AccountId > for Mapper < AccountId , T , C , B , GetCurrencyId >
130
131
where
131
132
T : fungibles:: Inspect < AccountId > ,
132
- C : ConvertBalance < <T as fungibles:: Inspect < AccountId > >:: Balance , B > ,
133
+ C : ConvertBalance <
134
+ <T as fungibles:: Inspect < AccountId > >:: Balance ,
135
+ B ,
136
+ AssetId = <T as fungibles:: Inspect < AccountId > >:: AssetId ,
137
+ > ,
133
138
// TOOD: use trait Balance after https://github.com/paritytech/substrate/pull/9863 is available
134
139
B : AtLeast32BitUnsigned + FullCodec + Copy + Default + Debug ,
135
140
GetCurrencyId : Get < <T as fungibles:: Inspect < AccountId > >:: AssetId > ,
136
141
{
137
142
type Balance = B ;
138
143
139
144
fn total_issuance ( ) -> Self :: Balance {
140
- C :: convert_balance ( T :: total_issuance ( GetCurrencyId :: get ( ) ) )
145
+ C :: convert_balance ( T :: total_issuance ( GetCurrencyId :: get ( ) ) , GetCurrencyId :: get ( ) )
141
146
}
142
147
143
148
fn minimum_balance ( ) -> Self :: Balance {
144
- C :: convert_balance ( T :: minimum_balance ( GetCurrencyId :: get ( ) ) )
149
+ C :: convert_balance ( T :: minimum_balance ( GetCurrencyId :: get ( ) ) , GetCurrencyId :: get ( ) )
145
150
}
146
151
147
152
fn balance ( who : & AccountId ) -> Self :: Balance {
148
- C :: convert_balance ( T :: balance ( GetCurrencyId :: get ( ) , who) )
153
+ C :: convert_balance ( T :: balance ( GetCurrencyId :: get ( ) , who) , GetCurrencyId :: get ( ) )
149
154
}
150
155
151
156
fn reducible_balance ( who : & AccountId , keep_alive : bool ) -> Self :: Balance {
152
- C :: convert_balance ( T :: reducible_balance ( GetCurrencyId :: get ( ) , who, keep_alive) )
157
+ C :: convert_balance (
158
+ T :: reducible_balance ( GetCurrencyId :: get ( ) , who, keep_alive) ,
159
+ GetCurrencyId :: get ( ) ,
160
+ )
153
161
}
154
162
155
163
fn can_deposit ( who : & AccountId , amount : Self :: Balance ) -> DepositConsequence {
156
- T :: can_deposit ( GetCurrencyId :: get ( ) , who, C :: convert_balance_back ( amount) )
164
+ T :: can_deposit (
165
+ GetCurrencyId :: get ( ) ,
166
+ who,
167
+ C :: convert_balance_back ( amount, GetCurrencyId :: get ( ) ) ,
168
+ )
157
169
}
158
170
159
171
fn can_withdraw ( who : & AccountId , amount : Self :: Balance ) -> WithdrawConsequence < Self :: Balance > {
160
172
use WithdrawConsequence :: * ;
161
- let res = T :: can_withdraw ( GetCurrencyId :: get ( ) , who, C :: convert_balance_back ( amount) ) ;
173
+ let res = T :: can_withdraw (
174
+ GetCurrencyId :: get ( ) ,
175
+ who,
176
+ C :: convert_balance_back ( amount, GetCurrencyId :: get ( ) ) ,
177
+ ) ;
162
178
match res {
163
- WithdrawConsequence :: ReducedToZero ( b) => WithdrawConsequence :: ReducedToZero ( C :: convert_balance ( b) ) ,
179
+ WithdrawConsequence :: ReducedToZero ( b) => {
180
+ WithdrawConsequence :: ReducedToZero ( C :: convert_balance ( b, GetCurrencyId :: get ( ) ) )
181
+ }
164
182
NoFunds => NoFunds ,
165
183
WouldDie => WouldDie ,
166
184
UnknownAsset => UnknownAsset ,
@@ -175,7 +193,11 @@ where
175
193
impl < AccountId , T , C , B , GetCurrencyId > fungible:: Transfer < AccountId > for Mapper < AccountId , T , C , B , GetCurrencyId >
176
194
where
177
195
T : fungibles:: Transfer < AccountId , Balance = B > ,
178
- C : ConvertBalance < <T as fungibles:: Inspect < AccountId > >:: Balance , B > ,
196
+ C : ConvertBalance <
197
+ <T as fungibles:: Inspect < AccountId > >:: Balance ,
198
+ B ,
199
+ AssetId = <T as fungibles:: Inspect < AccountId > >:: AssetId ,
200
+ > ,
179
201
// TOOD: use trait Balance after https://github.com/paritytech/substrate/pull/9863 is available
180
202
B : AtLeast32BitUnsigned + FullCodec + Copy + Default + Debug ,
181
203
GetCurrencyId : Get < <T as fungibles:: Inspect < AccountId > >:: AssetId > ,
@@ -185,7 +207,7 @@ where
185
207
GetCurrencyId :: get ( ) ,
186
208
source,
187
209
dest,
188
- C :: convert_balance_back ( amount) ,
210
+ C :: convert_balance_back ( amount, GetCurrencyId :: get ( ) ) ,
189
211
keep_alive,
190
212
)
191
213
}
@@ -194,16 +216,28 @@ where
194
216
impl < AccountId , T , C , B , GetCurrencyId > fungible:: Mutate < AccountId > for Mapper < AccountId , T , C , B , GetCurrencyId >
195
217
where
196
218
T : fungibles:: Mutate < AccountId , Balance = B > ,
197
- C : ConvertBalance < <T as fungibles:: Inspect < AccountId > >:: Balance , B > ,
219
+ C : ConvertBalance <
220
+ <T as fungibles:: Inspect < AccountId > >:: Balance ,
221
+ B ,
222
+ AssetId = <T as fungibles:: Inspect < AccountId > >:: AssetId ,
223
+ > ,
198
224
// TOOD: use trait Balance after https://github.com/paritytech/substrate/pull/9863 is available
199
225
B : AtLeast32BitUnsigned + FullCodec + Copy + Default + Debug ,
200
226
GetCurrencyId : Get < <T as fungibles:: Inspect < AccountId > >:: AssetId > ,
201
227
{
202
228
fn mint_into ( dest : & AccountId , amount : Self :: Balance ) -> DispatchResult {
203
- T :: mint_into ( GetCurrencyId :: get ( ) , dest, C :: convert_balance_back ( amount) )
229
+ T :: mint_into (
230
+ GetCurrencyId :: get ( ) ,
231
+ dest,
232
+ C :: convert_balance_back ( amount, GetCurrencyId :: get ( ) ) ,
233
+ )
204
234
}
205
235
206
236
fn burn_from ( dest : & AccountId , amount : Self :: Balance ) -> Result < Self :: Balance , DispatchError > {
207
- T :: burn_from ( GetCurrencyId :: get ( ) , dest, C :: convert_balance_back ( amount) )
237
+ T :: burn_from (
238
+ GetCurrencyId :: get ( ) ,
239
+ dest,
240
+ C :: convert_balance_back ( amount, GetCurrencyId :: get ( ) ) ,
241
+ )
208
242
}
209
243
}
0 commit comments