2
2
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
3
3
// see LICENSE for license details.
4
4
5
- use super :: signed_extensions:: CheckNonceParams ;
6
- use super :: { signed_extensions, ExtrinsicParams } ;
7
- use super :: { Config , Header } ;
5
+ use super :: Config ;
6
+ use super :: { transaction_extensions, ExtrinsicParams } ;
8
7
9
8
/// The default [`super::ExtrinsicParams`] implementation understands common signed extensions
10
9
/// and how to apply them to a given chain.
11
- pub type DefaultExtrinsicParams < T > = signed_extensions :: AnyOf <
10
+ pub type DefaultExtrinsicParams < T > = transaction_extensions :: AnyOf <
12
11
T ,
13
12
(
14
- signed_extensions:: CheckSpecVersion ,
15
- signed_extensions:: CheckTxVersion ,
16
- signed_extensions:: CheckNonce ,
17
- signed_extensions:: CheckGenesis < T > ,
18
- signed_extensions:: CheckMortality < T > ,
19
- signed_extensions:: ChargeAssetTxPayment < T > ,
20
- signed_extensions:: ChargeTransactionPayment ,
21
- signed_extensions:: CheckMetadataHash ,
13
+ transaction_extensions:: VerifySignature < T > ,
14
+ transaction_extensions:: CheckSpecVersion ,
15
+ transaction_extensions:: CheckTxVersion ,
16
+ transaction_extensions:: CheckNonce ,
17
+ transaction_extensions:: CheckGenesis < T > ,
18
+ transaction_extensions:: CheckMortality < T > ,
19
+ transaction_extensions:: ChargeAssetTxPayment < T > ,
20
+ transaction_extensions:: ChargeTransactionPayment ,
21
+ transaction_extensions:: CheckMetadataHash ,
22
22
) ,
23
23
> ;
24
24
25
25
/// A builder that outputs the set of [`super::ExtrinsicParams::Params`] required for
26
26
/// [`DefaultExtrinsicParams`]. This may expose methods that aren't applicable to the current
27
27
/// chain; such values will simply be ignored if so.
28
28
pub struct DefaultExtrinsicParamsBuilder < T : Config > {
29
- /// `None` means the tx will be immortal.
30
- mortality : Option < Mortality < T :: Hash > > ,
29
+ /// `None` means the tx will be immortal, else it's mortal for N blocks (if possible) .
30
+ mortality : Option < u64 > ,
31
31
/// `None` means the nonce will be automatically set.
32
32
nonce : Option < u64 > ,
33
33
/// `None` means we'll use the native token.
@@ -36,16 +36,6 @@ pub struct DefaultExtrinsicParamsBuilder<T: Config> {
36
36
tip_of : u128 ,
37
37
}
38
38
39
- struct Mortality < Hash > {
40
- /// Block hash that mortality starts from
41
- checkpoint_hash : Hash ,
42
- /// Block number that mortality starts from (must
43
- // point to the same block as the hash above)
44
- checkpoint_number : u64 ,
45
- /// How many blocks the tx is mortal for
46
- period : u64 ,
47
- }
48
-
49
39
impl < T : Config > Default for DefaultExtrinsicParamsBuilder < T > {
50
40
fn default ( ) -> Self {
51
41
Self {
@@ -65,15 +55,10 @@ impl<T: Config> DefaultExtrinsicParamsBuilder<T> {
65
55
Default :: default ( )
66
56
}
67
57
68
- /// Make the transaction mortal, given a block header that it should be mortal from,
69
- /// and the number of blocks (roughly; it'll be rounded to a power of two) that it will
70
- /// be mortal for.
71
- pub fn mortal ( mut self , from_block : & T :: Header , for_n_blocks : u64 ) -> Self {
72
- self . mortality = Some ( Mortality {
73
- checkpoint_hash : from_block. hash ( ) ,
74
- checkpoint_number : from_block. number ( ) . into ( ) ,
75
- period : for_n_blocks,
76
- } ) ;
58
+ /// Make the transaction mortal, given a number of blocks it will be mortal for from
59
+ /// the current block at the time of submission.
60
+ pub fn mortal ( mut self , for_n_blocks : u64 ) -> Self {
61
+ self . mortality = Some ( for_n_blocks) ;
77
62
self
78
63
}
79
64
@@ -83,26 +68,6 @@ impl<T: Config> DefaultExtrinsicParamsBuilder<T> {
83
68
self
84
69
}
85
70
86
- /// Make the transaction mortal, given a block number and block hash (which must both point to
87
- /// the same block) that it should be mortal from, and the number of blocks (roughly; it'll be
88
- /// rounded to a power of two) that it will be mortal for.
89
- ///
90
- /// Prefer to use [`DefaultExtrinsicParamsBuilder::mortal()`], which ensures that the block hash
91
- /// and number align.
92
- pub fn mortal_unchecked (
93
- mut self ,
94
- from_block_number : u64 ,
95
- from_block_hash : T :: Hash ,
96
- for_n_blocks : u64 ,
97
- ) -> Self {
98
- self . mortality = Some ( Mortality {
99
- checkpoint_hash : from_block_hash,
100
- checkpoint_number : from_block_number,
101
- period : for_n_blocks,
102
- } ) ;
103
- self
104
- }
105
-
106
71
/// Provide a tip to the block author in the chain's native token.
107
72
pub fn tip ( mut self , tip : u128 ) -> Self {
108
73
self . tip = tip;
@@ -123,28 +88,29 @@ impl<T: Config> DefaultExtrinsicParamsBuilder<T> {
123
88
124
89
/// Build the extrinsic parameters.
125
90
pub fn build ( self ) -> <DefaultExtrinsicParams < T > as ExtrinsicParams < T > >:: Params {
126
- let check_mortality_params = if let Some ( mortality) = self . mortality {
127
- signed_extensions:: CheckMortalityParams :: mortal (
128
- mortality. period ,
129
- mortality. checkpoint_number ,
130
- mortality. checkpoint_hash ,
131
- )
91
+ let check_mortality_params = if let Some ( for_n_blocks) = self . mortality {
92
+ transaction_extensions:: CheckMortalityParams :: mortal ( for_n_blocks)
132
93
} else {
133
- signed_extensions :: CheckMortalityParams :: immortal ( )
94
+ transaction_extensions :: CheckMortalityParams :: immortal ( )
134
95
} ;
135
96
136
97
let charge_asset_tx_params = if let Some ( asset_id) = self . tip_of_asset_id {
137
- signed_extensions :: ChargeAssetTxPaymentParams :: tip_of ( self . tip , asset_id)
98
+ transaction_extensions :: ChargeAssetTxPaymentParams :: tip_of ( self . tip , asset_id)
138
99
} else {
139
- signed_extensions :: ChargeAssetTxPaymentParams :: tip ( self . tip )
100
+ transaction_extensions :: ChargeAssetTxPaymentParams :: tip ( self . tip )
140
101
} ;
141
102
142
103
let charge_transaction_params =
143
- signed_extensions :: ChargeTransactionPaymentParams :: tip ( self . tip ) ;
104
+ transaction_extensions :: ChargeTransactionPaymentParams :: tip ( self . tip ) ;
144
105
145
- let check_nonce_params = CheckNonceParams ( self . nonce ) ;
106
+ let check_nonce_params = if let Some ( nonce) = self . nonce {
107
+ transaction_extensions:: CheckNonceParams :: with_nonce ( nonce)
108
+ } else {
109
+ transaction_extensions:: CheckNonceParams :: from_chain ( )
110
+ } ;
146
111
147
112
(
113
+ ( ) ,
148
114
( ) ,
149
115
( ) ,
150
116
check_nonce_params,
@@ -156,3 +122,16 @@ impl<T: Config> DefaultExtrinsicParamsBuilder<T> {
156
122
)
157
123
}
158
124
}
125
+
126
+ #[ cfg( test) ]
127
+ mod test {
128
+ use super :: * ;
129
+
130
+ fn assert_default < T : Default > ( _t : T ) { }
131
+
132
+ #[ test]
133
+ fn params_are_default ( ) {
134
+ let params = DefaultExtrinsicParamsBuilder :: < crate :: config:: PolkadotConfig > :: new ( ) . build ( ) ;
135
+ assert_default ( params)
136
+ }
137
+ }
0 commit comments