1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#[frame_support::pallet(dev_mode)]
pub mod pallet {
	use cfg_traits::fees::{Fee, Fees};
	use frame_support::{pallet_prelude::*, traits::tokens::Balance};
	use mock_builder::{execute_call, register_call};

	#[pallet::config]
	pub trait Config: frame_system::Config {
		type Balance: Balance;
		type FeeKey;
	}

	#[pallet::pallet]
	pub struct Pallet<T>(_);

	#[pallet::storage]
	type CallIds<T: Config> = StorageMap<_, _, String, mock_builder::CallId>;

	impl<T: Config> Pallet<T> {
		pub fn mock_fee_value(f: impl Fn(T::FeeKey) -> T::Balance + 'static) {
			register_call!(f);
		}

		pub fn mock_fee_to_author(
			f: impl Fn(&T::AccountId, Fee<T::Balance, T::FeeKey>) -> DispatchResult + 'static,
		) {
			register_call!(move |(a, b)| f(a, b));
		}

		pub fn mock_fee_to_burn(
			f: impl Fn(&T::AccountId, Fee<T::Balance, T::FeeKey>) -> DispatchResult + 'static,
		) {
			register_call!(move |(a, b)| f(a, b));
		}

		pub fn mock_fee_to_treasury(
			f: impl Fn(&T::AccountId, Fee<T::Balance, T::FeeKey>) -> DispatchResult + 'static,
		) {
			register_call!(move |(a, b)| f(a, b));
		}
	}

	impl<T: Config> Fees for Pallet<T> {
		type AccountId = T::AccountId;
		type Balance = T::Balance;
		type FeeKey = T::FeeKey;

		fn fee_value(a: Self::FeeKey) -> Self::Balance {
			execute_call!(a)
		}

		fn fee_to_author(
			a: &Self::AccountId,
			b: Fee<Self::Balance, Self::FeeKey>,
		) -> DispatchResult {
			execute_call!((a, b))
		}

		fn fee_to_burn(a: &Self::AccountId, b: Fee<Self::Balance, Self::FeeKey>) -> DispatchResult {
			execute_call!((a, b))
		}

		fn fee_to_treasury(
			a: &Self::AccountId,
			b: Fee<Self::Balance, Self::FeeKey>,
		) -> DispatchResult {
			execute_call!((a, b))
		}
	}
}