@@ -50,12 +50,21 @@ mod wasm_api;
50
50
51
51
use rstd:: vec:: Vec ;
52
52
53
- use codec:: { Encode , Decode , CompactAs } ;
54
- use sp_core:: { RuntimeDebug , TypeId } ;
53
+ use codec:: { Encode , Decode } ;
55
54
56
55
#[ cfg( all( not( feature = "std" ) , feature = "wasm-api" ) ) ]
57
56
pub use wasm_api:: * ;
58
57
58
+ #[ deprecated( note="moved to primitives package" ) ]
59
+ pub use polkadot_primitives:: { BlockNumber , parachain:: {
60
+ AccountIdConversion ,
61
+ Id ,
62
+ IncomingMessage ,
63
+ LOWEST_USER_ID ,
64
+ ParachainDispatchOrigin ,
65
+ UpwardMessage ,
66
+ } } ;
67
+
59
68
/// Validation parameters for evaluating the parachain validity function.
60
69
// TODO: balance downloads (https://github.com/paritytech/polkadot/issues/220)
61
70
#[ derive( PartialEq , Eq , Decode ) ]
@@ -65,6 +74,8 @@ pub struct ValidationParams {
65
74
pub block_data : Vec < u8 > ,
66
75
/// Previous head-data.
67
76
pub parent_head : Vec < u8 > ,
77
+ /// Number of the current relay chain block.
78
+ pub current_relay_block : BlockNumber ,
68
79
}
69
80
70
81
/// The result of parachain validation.
@@ -75,152 +86,3 @@ pub struct ValidationResult {
75
86
/// New head data that should be included in the relay chain state.
76
87
pub head_data : Vec < u8 > ,
77
88
}
78
-
79
- /// Unique identifier of a parachain.
80
- #[ derive(
81
- Clone , CompactAs , Copy , Decode , Default , Encode , Eq ,
82
- Hash , Ord , PartialEq , PartialOrd , RuntimeDebug ,
83
- ) ]
84
- #[ cfg_attr( feature = "std" , derive( serde:: Serialize , serde:: Deserialize , derive_more:: Display ) ) ]
85
- pub struct Id ( u32 ) ;
86
-
87
- impl TypeId for Id {
88
- const TYPE_ID : [ u8 ; 4 ] = * b"para" ;
89
- }
90
-
91
- /// Type for determining the active set of parachains.
92
- pub trait ActiveThreads {
93
- /// Return the current ordered set of `Id`s of active parathreads.
94
- fn active_threads ( ) -> Vec < Id > ;
95
- }
96
-
97
- impl From < Id > for u32 {
98
- fn from ( x : Id ) -> Self { x. 0 }
99
- }
100
-
101
- impl From < u32 > for Id {
102
- fn from ( x : u32 ) -> Self { Id ( x) }
103
- }
104
-
105
- const USER_INDEX_START : u32 = 1000 ;
106
-
107
- /// The ID of the first user (non-system) parachain.
108
- pub const LOWEST_USER_ID : Id = Id ( USER_INDEX_START ) ;
109
-
110
- impl Id {
111
- /// Create an `Id`.
112
- pub const fn new ( id : u32 ) -> Self {
113
- Self ( id)
114
- }
115
-
116
- /// Returns `true` if this parachain runs with system-level privileges.
117
- pub fn is_system ( & self ) -> bool { self . 0 < USER_INDEX_START }
118
- }
119
-
120
- impl rstd:: ops:: Add < u32 > for Id {
121
- type Output = Self ;
122
-
123
- fn add ( self , other : u32 ) -> Self {
124
- Self ( self . 0 + other)
125
- }
126
- }
127
-
128
- // TODO: Remove all of this, move sp-runtime::AccountIdConversion to own crate and and use that.
129
- // #360
130
- struct TrailingZeroInput < ' a > ( & ' a [ u8 ] ) ;
131
- impl < ' a > codec:: Input for TrailingZeroInput < ' a > {
132
- fn remaining_len ( & mut self ) -> Result < Option < usize > , codec:: Error > {
133
- Ok ( None )
134
- }
135
-
136
- fn read ( & mut self , into : & mut [ u8 ] ) -> Result < ( ) , codec:: Error > {
137
- let len = into. len ( ) . min ( self . 0 . len ( ) ) ;
138
- into[ ..len] . copy_from_slice ( & self . 0 [ ..len] ) ;
139
- for i in & mut into[ len..] {
140
- * i = 0 ;
141
- }
142
- self . 0 = & self . 0 [ len..] ;
143
- Ok ( ( ) )
144
- }
145
- }
146
-
147
- /// This type can be converted into and possibly from an AccountId (which itself is generic).
148
- pub trait AccountIdConversion < AccountId > : Sized {
149
- /// Convert into an account ID. This is infallible.
150
- fn into_account ( & self ) -> AccountId ;
151
-
152
- /// Try to convert an account ID into this type. Might not succeed.
153
- fn try_from_account ( a : & AccountId ) -> Option < Self > ;
154
- }
155
-
156
- /// Format is b"para" ++ encode(parachain ID) ++ 00.... where 00... is indefinite trailing
157
- /// zeroes to fill AccountId.
158
- impl < T : Encode + Decode + Default > AccountIdConversion < T > for Id {
159
- fn into_account ( & self ) -> T {
160
- ( b"para" , self ) . using_encoded ( |b|
161
- T :: decode ( & mut TrailingZeroInput ( b) )
162
- ) . unwrap_or_default ( )
163
- }
164
-
165
- fn try_from_account ( x : & T ) -> Option < Self > {
166
- x. using_encoded ( |d| {
167
- if & d[ 0 ..4 ] != b"para" { return None }
168
- let mut cursor = & d[ 4 ..] ;
169
- let result = Decode :: decode ( & mut cursor) . ok ( ) ?;
170
- if cursor. iter ( ) . all ( |x| * x == 0 ) {
171
- Some ( result)
172
- } else {
173
- None
174
- }
175
- } )
176
- }
177
- }
178
-
179
- /// Which origin a parachain's message to the relay chain should be dispatched from.
180
- #[ derive( Clone , PartialEq , Eq , Encode , Decode ) ]
181
- #[ cfg_attr( feature = "std" , derive( Debug ) ) ]
182
- #[ repr( u8 ) ]
183
- pub enum ParachainDispatchOrigin {
184
- /// As a simple `Origin::Signed`, using `ParaId::account_id` as its value. This is good when
185
- /// interacting with standard modules such as `balances`.
186
- Signed ,
187
- /// As the special `Origin::Parachain(ParaId)`. This is good when interacting with parachain-
188
- /// aware modules which need to succinctly verify that the origin is a parachain.
189
- Parachain ,
190
- /// As the simple, superuser `Origin::Root`. This can only be done on specially permissioned
191
- /// parachains.
192
- Root ,
193
- }
194
-
195
- impl rstd:: convert:: TryFrom < u8 > for ParachainDispatchOrigin {
196
- type Error = ( ) ;
197
- fn try_from ( x : u8 ) -> core:: result:: Result < ParachainDispatchOrigin , ( ) > {
198
- const SIGNED : u8 = ParachainDispatchOrigin :: Signed as u8 ;
199
- const PARACHAIN : u8 = ParachainDispatchOrigin :: Parachain as u8 ;
200
- Ok ( match x {
201
- SIGNED => ParachainDispatchOrigin :: Signed ,
202
- PARACHAIN => ParachainDispatchOrigin :: Parachain ,
203
- _ => return Err ( ( ) ) ,
204
- } )
205
- }
206
- }
207
-
208
- /// A message from a parachain to its Relay Chain.
209
- #[ derive( Clone , PartialEq , Eq , Encode , Decode , sp_runtime_interface:: pass_by:: PassByCodec ) ]
210
- #[ cfg_attr( feature = "std" , derive( Debug ) ) ]
211
- pub struct UpwardMessage {
212
- /// The origin for the message to be sent from.
213
- pub origin : ParachainDispatchOrigin ,
214
- /// The message data.
215
- pub data : Vec < u8 > ,
216
- }
217
-
218
- /// An incoming message.
219
- #[ derive( PartialEq , Eq , Decode ) ]
220
- #[ cfg_attr( feature = "std" , derive( Debug , Encode ) ) ]
221
- pub struct IncomingMessage {
222
- /// The source parachain.
223
- pub source : Id ,
224
- /// The data of the message.
225
- pub data : Vec < u8 > ,
226
- }
0 commit comments