|
| 1 | +// Copyright (C) Parity Technologies (UK) Ltd. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +// you may not use this file except in compliance with the License. |
| 6 | +// You may obtain a copy of the License at |
| 7 | +// |
| 8 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +// |
| 10 | +// Unless required by applicable law or agreed to in writing, software |
| 11 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +// See the License for the specific language governing permissions and |
| 14 | +// limitations under the License. |
| 15 | + |
| 16 | +#![cfg_attr(not(feature = "std"), no_std)] |
| 17 | + |
| 18 | +use codec::{Decode, Encode}; |
| 19 | +use polkadot_sdk_frame::prelude::{ |
| 20 | + fungible::{Dust, Inspect, InspectHold, MutateHold, Unbalanced, UnbalancedHold}, |
| 21 | + DepositConsequence, DispatchError, DispatchResult, Fortitude, Preservation, Provenance, |
| 22 | + WithdrawConsequence, Zero, |
| 23 | +}; |
| 24 | +use scale_info::TypeInfo; |
| 25 | + |
| 26 | +/// Fungible currency implementation that does not support any balance operations. |
| 27 | +/// Works only with zero balances. |
| 28 | +/// |
| 29 | +/// Note: This is a workaround to satisfy the `pallet-session::Config::Currency` trait requirements. |
| 30 | +pub struct NoCurrency<AccountId, HoldReason>(core::marker::PhantomData<(AccountId, HoldReason)>); |
| 31 | + |
| 32 | +impl<AccountId, HoldReason: Encode + Decode + TypeInfo + 'static> Inspect<AccountId> |
| 33 | + for NoCurrency<AccountId, HoldReason> |
| 34 | +{ |
| 35 | + type Balance = u128; |
| 36 | + |
| 37 | + fn total_issuance() -> Self::Balance { |
| 38 | + Zero::zero() |
| 39 | + } |
| 40 | + |
| 41 | + fn minimum_balance() -> Self::Balance { |
| 42 | + Zero::zero() |
| 43 | + } |
| 44 | + |
| 45 | + fn total_balance(_who: &AccountId) -> Self::Balance { |
| 46 | + Zero::zero() |
| 47 | + } |
| 48 | + |
| 49 | + fn balance(_who: &AccountId) -> Self::Balance { |
| 50 | + Zero::zero() |
| 51 | + } |
| 52 | + |
| 53 | + fn reducible_balance( |
| 54 | + _who: &AccountId, |
| 55 | + _preservation: Preservation, |
| 56 | + _force: Fortitude, |
| 57 | + ) -> Self::Balance { |
| 58 | + Zero::zero() |
| 59 | + } |
| 60 | + |
| 61 | + fn can_deposit( |
| 62 | + _who: &AccountId, |
| 63 | + _amount: Self::Balance, |
| 64 | + _provenance: Provenance, |
| 65 | + ) -> DepositConsequence { |
| 66 | + DepositConsequence::Success |
| 67 | + } |
| 68 | + |
| 69 | + fn can_withdraw( |
| 70 | + _who: &AccountId, |
| 71 | + _amount: Self::Balance, |
| 72 | + ) -> WithdrawConsequence<Self::Balance> { |
| 73 | + WithdrawConsequence::Success |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +impl<AccountId, HoldReason: Encode + Decode + TypeInfo + 'static> Unbalanced<AccountId> |
| 78 | + for NoCurrency<AccountId, HoldReason> |
| 79 | +{ |
| 80 | + fn handle_dust(_dust: Dust<AccountId, Self>) {} |
| 81 | + |
| 82 | + fn write_balance( |
| 83 | + _who: &AccountId, |
| 84 | + _amount: Self::Balance, |
| 85 | + ) -> Result<Option<Self::Balance>, DispatchError> { |
| 86 | + Ok(None) |
| 87 | + } |
| 88 | + |
| 89 | + fn set_total_issuance(_amount: Self::Balance) {} |
| 90 | +} |
| 91 | + |
| 92 | +impl<AccountId, HoldReason: Encode + Decode + TypeInfo + 'static> InspectHold<AccountId> |
| 93 | + for NoCurrency<AccountId, HoldReason> |
| 94 | +{ |
| 95 | + type Reason = HoldReason; |
| 96 | + |
| 97 | + fn total_balance_on_hold(_who: &AccountId) -> Self::Balance { |
| 98 | + Zero::zero() |
| 99 | + } |
| 100 | + |
| 101 | + fn balance_on_hold(_reason: &Self::Reason, _who: &AccountId) -> Self::Balance { |
| 102 | + Zero::zero() |
| 103 | + } |
| 104 | +} |
| 105 | + |
| 106 | +impl<AccountId, HoldReason: Encode + Decode + TypeInfo + 'static> UnbalancedHold<AccountId> |
| 107 | + for NoCurrency<AccountId, HoldReason> |
| 108 | +{ |
| 109 | + fn set_balance_on_hold( |
| 110 | + _reason: &Self::Reason, |
| 111 | + _who: &AccountId, |
| 112 | + _amount: Self::Balance, |
| 113 | + ) -> DispatchResult { |
| 114 | + Ok(()) |
| 115 | + } |
| 116 | +} |
| 117 | + |
| 118 | +impl<AccountId, HoldReason: Encode + Decode + TypeInfo + 'static> MutateHold<AccountId> |
| 119 | + for NoCurrency<AccountId, HoldReason> |
| 120 | +{ |
| 121 | +} |
0 commit comments