-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.rs
87 lines (73 loc) · 2.38 KB
/
lib.rs
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#![cfg_attr(not(feature = "std"), no_std)]
use polkadot_sdk::polkadot_sdk_frame::{self as frame, prelude::*};
#[frame::pallet(dev_mode)]
pub mod demonstrative_pallet {
#[pallet::pallet]
pub struct Pallet<T>(_);
#[docify::export(DemonstrationConfig)]
#[pallet::config]
#[pallet::disable_frame_system_supertrait_check]
pub trait Config: flite::flite_system::Config {}
}
#[frame::pallet(dev_mode)]
pub mod pallet {
use super::*;
#[pallet::pallet]
pub struct Pallet<T>(_);
#[docify::export]
#[pallet::config]
#[pallet::disable_frame_system_supertrait_check]
pub trait Config: flite::flite_system::Config {
type AdvanceCurrency: flite::native_currency::Advance;
}
#[pallet::call]
impl<T: Config> Pallet<T> {
#[docify::export]
pub fn dispatching(origin: OriginFor<T>) -> DispatchResult {
// Yes, the account id type is no longer generic, because `flite` uses constrained
// associated types.
let _sender: flite::types::AccountId = ensure_signed(origin)?;
Ok(())
}
#[docify::export]
/// simple-pallet can use the very very basic flite currency primitives.
pub fn simple_currency_usage(
origin: OriginFor<T>,
to: flite::types::AccountId,
amount: u128, // aka. flite::types::Balance
) -> DispatchResult {
let who: flite::types::AccountId = ensure_signed(origin)?;
// read. Yes, the balance types is just `u128`
let _: u128 = flite::native_currency::Simple::<T>::balance_of(&who);
// transfer
flite::native_currency::Simple::<T>::transfer(&who, &to, amount)?;
// 'lock', which is an abstraction over holding with more opinions
flite::native_currency::Simple::<T>::lock(&who, amount)?;
Ok(())
}
/// Or it can tap into the default FRAME currency, although as constrained by flite. For
/// example, `Balance` is still `u128`, `RuntimeHoldReason` is still `&static str` adn so
/// on.
#[docify::export]
pub fn advance_currency_usage(
origin: OriginFor<T>,
to: flite::types::AccountId,
amount: flite::types::Balance,
) -> DispatchResult {
use frame::traits::fungible::*;
let who: flite::types::AccountId = ensure_signed(origin)?;
// read
let _: flite::types::Balance = T::AdvanceCurrency::balance(&who);
// transfer
T::AdvanceCurrency::transfer(
&who,
&to,
amount,
frame::traits::tokens::Preservation::Expendable,
)?;
// 'hold'.
T::AdvanceCurrency::hold(&0u8, &who, amount)?;
Ok(())
}
}
}