1515// along with Encointer. If not, see <http://www.gnu.org/licenses/>.
1616
1717use super :: * ;
18- use encointer_primitives:: { balances:: EncointerBalanceConverter , common:: UnboundedPalletString } ;
19- use frame_support:: {
20- inherent:: Vec ,
21- traits:: tokens:: { DepositConsequence , WithdrawConsequence } ,
18+ use encointer_primitives:: balances:: EncointerBalanceConverter ;
19+ use frame_support:: traits:: tokens:: {
20+ DepositConsequence , Fortitude , Preservation , Provenance , WithdrawConsequence ,
2221} ;
2322use sp_runtime:: traits:: { Convert , Zero } ;
2423
25- // Implementation of this trait is just to satisfy the trait bounds of the
26- // `pallet-asset-tx-payment`. It is not used in our case.
27- impl < T : Config > fungibles:: InspectMetadata < T :: AccountId > for Pallet < T > {
28- fn name ( _asset : & Self :: AssetId ) -> Vec < u8 > {
29- UnboundedPalletString :: from ( "Encointer" ) . into ( )
30- }
31-
32- fn symbol ( _asset : & Self :: AssetId ) -> Vec < u8 > {
33- UnboundedPalletString :: from ( "ETR" ) . into ( )
34- }
35-
36- fn decimals ( _asset : & Self :: AssetId ) -> u8 {
37- // Our BalanceType is I64F64 which is base2 fixpoint and therefore doesn't use decimals (which would be base10 fixpoint)
38- // but in order to comply with this trait we need to define decimals nevertheless.
39- // the smallest possible number is 2^-64 = 5.42101086242752217003726400434970855712890625 × 10^-20
40- // and an upper bound is 2^63 + 1 = 9.223372036854775809 × 10^18
41- // so we chose 18 decimals and lose some precision but can prevent overflows that way.
42- // due to demurrage, that lost precision is meaningless anyway
43- 18u8
44- }
45- }
46-
4724pub ( crate ) fn fungible ( balance : BalanceType ) -> u128 {
4825 EncointerBalanceConverter :: convert ( balance)
4926}
@@ -72,10 +49,15 @@ impl<T: Config> fungibles::Inspect<T::AccountId> for Pallet<T> {
7249 fungible ( Pallet :: < T > :: balance ( asset, who) )
7350 }
7451
52+ fn total_balance ( asset : Self :: AssetId , who : & T :: AccountId ) -> Self :: Balance {
53+ fungible ( Pallet :: < T > :: balance ( asset, who) )
54+ }
55+
7556 fn reducible_balance (
7657 asset : Self :: AssetId ,
7758 who : & T :: AccountId ,
78- _keep_alive : bool ,
59+ _preservation : Preservation ,
60+ _force : Fortitude ,
7961 ) -> Self :: Balance {
8062 fungible ( Pallet :: < T > :: balance ( asset, who) )
8163 }
@@ -84,7 +66,7 @@ impl<T: Config> fungibles::Inspect<T::AccountId> for Pallet<T> {
8466 asset : Self :: AssetId ,
8567 who : & T :: AccountId ,
8668 amount : Self :: Balance ,
87- _mint : bool ,
69+ _mint : Provenance ,
8870 ) -> DepositConsequence {
8971 if !<TotalIssuance < T > >:: contains_key ( asset) {
9072 return DepositConsequence :: UnknownAsset
@@ -129,25 +111,25 @@ impl<T: Config> fungibles::Inspect<T::AccountId> for Pallet<T> {
129111 let balance = fungible ( Pallet :: < T > :: balance ( asset, who) ) ;
130112
131113 if balance. checked_sub ( amount) . is_none ( ) {
132- return NoFunds
114+ return WithdrawConsequence :: BalanceLow
133115 }
134- Success
116+ WithdrawConsequence :: Success
135117 }
136118}
137119
138120impl < T : Config > fungibles:: Unbalanced < T :: AccountId > for Pallet < T > {
139- fn set_balance (
121+ fn write_balance (
140122 asset : Self :: AssetId ,
141123 who : & T :: AccountId ,
142124 amount : Self :: Balance ,
143- ) -> DispatchResult {
125+ ) -> Result < Option < Self :: Balance > , sp_runtime :: DispatchError > {
144126 let current_block = frame_system:: Pallet :: < T > :: block_number ( ) ;
145127 <Balance < T > >:: insert (
146128 asset,
147129 who,
148130 BalanceEntry { principal : balance_type ( amount) , last_update : current_block } ,
149131 ) ;
150- Ok ( ( ) )
132+ Ok ( None )
151133 }
152134
153135 fn set_total_issuance ( asset : Self :: AssetId , amount : Self :: Balance ) {
@@ -157,4 +139,5 @@ impl<T: Config> fungibles::Unbalanced<T::AccountId> for Pallet<T> {
157139 BalanceEntry { principal : balance_type ( amount) , last_update : current_block } ,
158140 ) ;
159141 }
142+ fn handle_dust ( _: fungibles:: Dust < T :: AccountId , Self > ) { }
160143}
0 commit comments