@@ -74,69 +74,63 @@ pub type HashedProof = [u8; 32];
74
74
/// succeeds with best efforts.
75
75
/// - **Claim**: claim any resources reserved in the first phrase.
76
76
/// - **Cancel**: cancel any resources reserved in the first phrase.
77
- pub trait SwapAction < T : Trait > {
77
+ pub trait SwapAction < AccountId , T : Trait > {
78
78
/// Reserve the resources needed for the swap, from the given `source`. The reservation is
79
79
/// allowed to fail. If that is the case, the the full swap creation operation is cancelled.
80
- fn reserve ( & self , source : & T :: AccountId ) -> DispatchResult ;
80
+ fn reserve ( & self , source : & AccountId ) -> DispatchResult ;
81
81
/// Claim the reserved resources, with `source` and `target`. Returns whether the claim
82
82
/// succeeds.
83
- fn claim ( & self , source : & T :: AccountId , target : & T :: AccountId ) -> bool ;
83
+ fn claim ( & self , source : & AccountId , target : & AccountId ) -> bool ;
84
84
/// Weight for executing the operation.
85
85
fn weight ( & self ) -> Weight ;
86
86
/// Cancel the resources reserved in `source`.
87
- fn cancel ( & self , source : & T :: AccountId ) ;
87
+ fn cancel ( & self , source : & AccountId ) ;
88
88
}
89
89
90
90
/// A swap action that only allows transferring balances.
91
91
#[ derive( Clone , RuntimeDebug , Eq , PartialEq , Encode , Decode ) ]
92
- pub struct BalanceSwapAction < T : Trait , C : ReservableCurrency < T :: AccountId > > {
93
- value : <C as Currency < < T as frame_system :: Trait > :: AccountId > >:: Balance ,
92
+ pub struct BalanceSwapAction < AccountId , C : ReservableCurrency < AccountId > > {
93
+ value : <C as Currency < AccountId > >:: Balance ,
94
94
_marker : PhantomData < C > ,
95
95
}
96
96
97
- impl < T : Trait , C > BalanceSwapAction < T , C > where
98
- C : ReservableCurrency < T :: AccountId > ,
99
- {
97
+ impl < AccountId , C > BalanceSwapAction < AccountId , C > where C : ReservableCurrency < AccountId > {
100
98
/// Create a new swap action value of balance.
101
- pub fn new ( value : <C as Currency < < T as frame_system :: Trait > :: AccountId > >:: Balance ) -> Self {
99
+ pub fn new ( value : <C as Currency < AccountId > >:: Balance ) -> Self {
102
100
Self { value, _marker : PhantomData }
103
101
}
104
102
}
105
103
106
- impl < T : Trait , C > Deref for BalanceSwapAction < T , C > where
107
- C : ReservableCurrency < T :: AccountId > ,
108
- {
109
- type Target = <C as Currency < <T as frame_system:: Trait >:: AccountId > >:: Balance ;
104
+ impl < AccountId , C > Deref for BalanceSwapAction < AccountId , C > where C : ReservableCurrency < AccountId > {
105
+ type Target = <C as Currency < AccountId > >:: Balance ;
110
106
111
107
fn deref ( & self ) -> & Self :: Target {
112
108
& self . value
113
109
}
114
110
}
115
111
116
- impl < T : Trait , C > DerefMut for BalanceSwapAction < T , C > where
117
- C : ReservableCurrency < T :: AccountId > ,
118
- {
112
+ impl < AccountId , C > DerefMut for BalanceSwapAction < AccountId , C > where C : ReservableCurrency < AccountId > {
119
113
fn deref_mut ( & mut self ) -> & mut Self :: Target {
120
114
& mut self . value
121
115
}
122
116
}
123
117
124
- impl < T : Trait , C > SwapAction < T > for BalanceSwapAction < T , C > where
125
- C : ReservableCurrency < T :: AccountId > ,
118
+ impl < T : Trait , AccountId , C > SwapAction < AccountId , T > for BalanceSwapAction < AccountId , C >
119
+ where C : ReservableCurrency < AccountId >
126
120
{
127
- fn reserve ( & self , source : & T :: AccountId ) -> DispatchResult {
121
+ fn reserve ( & self , source : & AccountId ) -> DispatchResult {
128
122
C :: reserve ( & source, self . value )
129
123
}
130
124
131
- fn claim ( & self , source : & T :: AccountId , target : & T :: AccountId ) -> bool {
125
+ fn claim ( & self , source : & AccountId , target : & AccountId ) -> bool {
132
126
C :: repatriate_reserved ( source, target, self . value , BalanceStatus :: Free ) . is_ok ( )
133
127
}
134
128
135
129
fn weight ( & self ) -> Weight {
136
130
T :: DbWeight :: get ( ) . reads_writes ( 1 , 1 )
137
131
}
138
132
139
- fn cancel ( & self , source : & T :: AccountId ) {
133
+ fn cancel ( & self , source : & AccountId ) {
140
134
C :: unreserve ( source, self . value ) ;
141
135
}
142
136
}
@@ -146,7 +140,7 @@ pub trait Trait: frame_system::Trait {
146
140
/// The overarching event type.
147
141
type Event : From < Event < Self > > + Into < <Self as frame_system:: Trait >:: Event > ;
148
142
/// Swap action.
149
- type SwapAction : SwapAction < Self > + Parameter ;
143
+ type SwapAction : SwapAction < Self :: AccountId , Self > + Parameter ;
150
144
/// Limit of proof size.
151
145
///
152
146
/// Atomic swap is only atomic if once the proof is revealed, both parties can submit the proofs
0 commit comments