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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
pub use super::*;
use codec::{Decode, Encode, HasCompact, MaxEncodedLen};
pub use frame_support::{
assert_ok,
dispatch::{DispatchResult, DispatchResultWithPostInfo, EncodeLike},
fail,
inherent::Vec,
pallet_prelude::*,
require_transactional,
sp_runtime::{
traits::{AccountIdConversion, Hash, One, Saturating, StaticLookup, Zero},
FixedU128, PerThing, Percent,
},
storage::{bounded_btree_map::BoundedBTreeMap, child},
traits::{
tokens::{
BalanceStatus,
ExistenceRequirement::{AllowDeath, KeepAlive},
},
Contains, Currency, ExistenceRequirement, Get, LockableCurrency, ReservableCurrency,
UnfilteredDispatchable, WithdrawReasons,
},
weights::GetDispatchInfo,
PalletId,
};
pub use frame_system::{ensure_signed, pallet_prelude::*, RawOrigin};
pub use scale_info::{prelude::vec, TypeInfo};
pub use sp_runtime::traits::{BadOrigin, BlakeTwo256, CheckedAdd, IdentityLookup};
pub use sp_std::boxed::Box;
pub type BalanceOf<T> =
<<T as pallet::Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
pub type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
pub type BlockNumberOf<T> = <T as frame_system::Config>::BlockNumber;
pub type HashOf<T> = <T as frame_system::Config>::Hash;
pub type BoundedDataOf<T> = BoundedVec<u8, <T as Config>::MaxRemarkLength>;
pub type ScheduledTaskOf<T> = ScheduledTask<<T as frame_system::Config>::BlockNumber>;
pub type ScheduledTaskList<T> = BoundedBTreeMap<
(<T as frame_system::Config>::AccountId, <T as frame_system::Config>::AccountId),
ScheduledTaskOf<T>,
<T as Config>::MaxRemarkLength,
>;
#[derive(Encode, Decode, Debug, Clone, PartialEq, Eq, MaxEncodedLen, TypeInfo)]
#[scale_info(skip_type_params(T))]
#[codec(mel_bound(T: pallet::Config))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PaymentDetail<T: pallet::Config> {
#[codec(compact)]
pub amount: BalanceOf<T>,
#[codec(compact)]
pub incentive_amount: BalanceOf<T>,
pub state: PaymentState<T>,
pub resolver_account: T::AccountId,
pub fee_detail: Option<(T::AccountId, BalanceOf<T>)>,
}
#[derive(Encode, Decode, Debug, Clone, PartialEq, Eq, MaxEncodedLen, TypeInfo)]
#[scale_info(skip_type_params(T))]
#[codec(mel_bound(T: pallet::Config))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum PaymentState<T: pallet::Config> {
Created,
NeedsReview,
RefundRequested { cancel_block: T::BlockNumber },
PaymentRequested,
PaymentCompleted,
}
pub trait PaymentHandler<T: pallet::Config> {
fn create_payment(
from: &T::AccountId,
to: &T::AccountId,
amount: BalanceOf<T>,
payment_state: PaymentState<T>,
incentive_percentage: Percent,
remark: Option<&[u8]>,
) -> Result<PaymentDetail<T>, sp_runtime::DispatchError>;
fn reserve_payment_amount(
from: &T::AccountId,
to: &T::AccountId,
payment: PaymentDetail<T>,
) -> DispatchResult;
fn settle_payment(
from: &T::AccountId,
to: &T::AccountId,
recipient_share: Percent,
) -> DispatchResult;
fn get_payment_details(from: &T::AccountId, to: &T::AccountId) -> Option<PaymentDetail<T>>;
}
pub trait DisputeResolver<Account> {
fn get_resolver_account() -> Account;
}
pub trait FeeHandler<T: pallet::Config> {
fn apply_fees(
from: &T::AccountId,
to: &T::AccountId,
detail: &PaymentDetail<T>,
remark: Option<&[u8]>,
) -> (T::AccountId, Percent);
}
#[derive(PartialEq, Eq, Clone, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
pub enum Task {
Cancel,
}
#[derive(PartialEq, Eq, Clone, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
pub struct ScheduledTask<Time: HasCompact> {
pub task: Task,
pub when: Time,
}