@@ -5,8 +5,8 @@ use pallet_evm::{
5
5
AddressMapping , ExitError , HashedAddressMapping , PrecompileFailure , PrecompileHandle ,
6
6
PrecompileResult ,
7
7
} ;
8
- use sp_runtime:: traits:: BlakeTwo256 ;
9
8
use sp_runtime:: AccountId32 ;
9
+ use sp_runtime:: { traits:: BlakeTwo256 , Vec } ;
10
10
use sp_std:: vec;
11
11
pub const SUBNET_PRECOMPILE_INDEX : u64 = 2051 ;
12
12
// bytes with max lenght 1K
@@ -62,14 +62,26 @@ impl SubnetPrecompile {
62
62
)
63
63
}
64
64
33 .. => {
65
- let ( hotkey, subnet_name, github_repo, subnet_contact) =
66
- Self :: parse_register_network_parameters ( data) ?;
65
+ let (
66
+ hotkey,
67
+ subnet_name,
68
+ github_repo,
69
+ subnet_contact,
70
+ subnet_url,
71
+ discord,
72
+ description,
73
+ additional,
74
+ ) = Self :: parse_register_network_parameters ( data) ?;
67
75
68
- let identity: pallet_subtensor:: SubnetIdentityOf =
69
- pallet_subtensor:: SubnetIdentityOf {
76
+ let identity: pallet_subtensor:: SubnetIdentityOfV2 =
77
+ pallet_subtensor:: SubnetIdentityOfV2 {
70
78
subnet_name,
71
79
github_repo,
72
80
subnet_contact,
81
+ subnet_url,
82
+ discord,
83
+ description,
84
+ additional,
73
85
} ;
74
86
75
87
// Create the register_network callcle
@@ -98,12 +110,24 @@ impl SubnetPrecompile {
98
110
99
111
fn parse_register_network_parameters (
100
112
data : & [ u8 ] ,
101
- ) -> Result < ( AccountId32 , vec:: Vec < u8 > , vec:: Vec < u8 > , vec:: Vec < u8 > ) , PrecompileFailure > {
113
+ ) -> Result <
114
+ (
115
+ AccountId32 ,
116
+ Vec < u8 > ,
117
+ Vec < u8 > ,
118
+ Vec < u8 > ,
119
+ Vec < u8 > ,
120
+ Vec < u8 > ,
121
+ Vec < u8 > ,
122
+ Vec < u8 > ,
123
+ ) ,
124
+ PrecompileFailure ,
125
+ > {
102
126
let ( pubkey, dynamic_params) = get_pubkey ( data) ?;
103
127
let dynamic_data_len = dynamic_params. len ( ) ;
104
128
105
129
let mut buf = [ 0_u8 ; 4 ] ;
106
- // get all start point for three data items: name, repo and contact
130
+ // get all start points for the data items: name, repo, contact, url, discord, description, additional
107
131
buf. copy_from_slice ( get_slice ( data, 60 , 64 ) ?) ;
108
132
let subnet_name_start: usize = u32:: from_be_bytes ( buf) as usize ;
109
133
if subnet_name_start > dynamic_data_len {
@@ -140,6 +164,54 @@ impl SubnetPrecompile {
140
164
} ) ;
141
165
}
142
166
167
+ buf. copy_from_slice ( get_slice ( data, 156 , 160 ) ?) ;
168
+ let subnet_url_start: usize = u32:: from_be_bytes ( buf) as usize ;
169
+ if subnet_url_start > dynamic_data_len {
170
+ log:: error!(
171
+ "the start position of subnet_url as {} is too big " ,
172
+ subnet_url_start
173
+ ) ;
174
+ return Err ( PrecompileFailure :: Error {
175
+ exit_status : ExitError :: InvalidRange ,
176
+ } ) ;
177
+ }
178
+
179
+ buf. copy_from_slice ( get_slice ( data, 188 , 192 ) ?) ;
180
+ let discord_start: usize = u32:: from_be_bytes ( buf) as usize ;
181
+ if discord_start > dynamic_data_len {
182
+ log:: error!(
183
+ "the start position of discord as {} is too big " ,
184
+ discord_start
185
+ ) ;
186
+ return Err ( PrecompileFailure :: Error {
187
+ exit_status : ExitError :: InvalidRange ,
188
+ } ) ;
189
+ }
190
+
191
+ buf. copy_from_slice ( get_slice ( data, 220 , 224 ) ?) ;
192
+ let description_start: usize = u32:: from_be_bytes ( buf) as usize ;
193
+ if description_start > dynamic_data_len {
194
+ log:: error!(
195
+ "the start position of description as {} is too big " ,
196
+ description_start
197
+ ) ;
198
+ return Err ( PrecompileFailure :: Error {
199
+ exit_status : ExitError :: InvalidRange ,
200
+ } ) ;
201
+ }
202
+
203
+ buf. copy_from_slice ( get_slice ( data, 252 , 256 ) ?) ;
204
+ let additional_start: usize = u32:: from_be_bytes ( buf) as usize ;
205
+ if additional_start > dynamic_data_len {
206
+ log:: error!(
207
+ "the start position of additional as {} is too big " ,
208
+ additional_start
209
+ ) ;
210
+ return Err ( PrecompileFailure :: Error {
211
+ exit_status : ExitError :: InvalidRange ,
212
+ } ) ;
213
+ }
214
+
143
215
// get name
144
216
buf. copy_from_slice ( get_slice (
145
217
data,
@@ -149,7 +221,10 @@ impl SubnetPrecompile {
149
221
let subnet_name_len: usize = u32:: from_be_bytes ( buf) as usize ;
150
222
151
223
if subnet_name_len > MAX_SINGLE_PARAMETER_SIZE {
152
- log:: error!( "the length of subnet nae as {} is too big" , subnet_name_len) ;
224
+ log:: error!(
225
+ "the length of subnet name as {} is too big" ,
226
+ subnet_name_len
227
+ ) ;
153
228
return Err ( PrecompileFailure :: Error {
154
229
exit_status : ExitError :: InvalidRange ,
155
230
} ) ;
@@ -210,6 +285,94 @@ impl SubnetPrecompile {
210
285
subnet_contact_start + subnet_contact_len + 32 ,
211
286
) ?) ;
212
287
213
- Ok ( ( pubkey, name_vec, repo_vec, contact_vec) )
288
+ // get subnet_url
289
+ buf. copy_from_slice ( get_slice (
290
+ data,
291
+ subnet_url_start + 28 ,
292
+ subnet_url_start + 32 ,
293
+ ) ?) ;
294
+ let subnet_url_len: usize = u32:: from_be_bytes ( buf) as usize ;
295
+ if subnet_url_len > MAX_SINGLE_PARAMETER_SIZE {
296
+ log:: error!( "the length of subnet_url as {} is too big" , subnet_url_len) ;
297
+ return Err ( PrecompileFailure :: Error {
298
+ exit_status : ExitError :: InvalidRange ,
299
+ } ) ;
300
+ }
301
+ let mut url_vec = vec ! [ 0 ; subnet_url_len] ;
302
+ url_vec. copy_from_slice ( get_slice (
303
+ data,
304
+ subnet_url_start + 32 ,
305
+ subnet_url_start + subnet_url_len + 32 ,
306
+ ) ?) ;
307
+
308
+ // get discord
309
+ buf. copy_from_slice ( get_slice ( data, discord_start + 28 , discord_start + 32 ) ?) ;
310
+ let discord_len: usize = u32:: from_be_bytes ( buf) as usize ;
311
+ if discord_len > MAX_SINGLE_PARAMETER_SIZE {
312
+ log:: error!( "the length of discord as {} is too big" , discord_len) ;
313
+ return Err ( PrecompileFailure :: Error {
314
+ exit_status : ExitError :: InvalidRange ,
315
+ } ) ;
316
+ }
317
+ let mut discord_vec = vec ! [ 0 ; discord_len] ;
318
+ discord_vec. copy_from_slice ( get_slice (
319
+ data,
320
+ discord_start + 32 ,
321
+ discord_start + discord_len + 32 ,
322
+ ) ?) ;
323
+
324
+ // get description
325
+ buf. copy_from_slice ( get_slice (
326
+ data,
327
+ description_start + 28 ,
328
+ description_start + 32 ,
329
+ ) ?) ;
330
+ let description_len: usize = u32:: from_be_bytes ( buf) as usize ;
331
+ if description_len > MAX_SINGLE_PARAMETER_SIZE {
332
+ log:: error!(
333
+ "the length of description as {} is too big" ,
334
+ description_len
335
+ ) ;
336
+ return Err ( PrecompileFailure :: Error {
337
+ exit_status : ExitError :: InvalidRange ,
338
+ } ) ;
339
+ }
340
+ let mut description_vec = vec ! [ 0 ; description_len] ;
341
+ description_vec. copy_from_slice ( get_slice (
342
+ data,
343
+ description_start + 32 ,
344
+ description_start + description_len + 32 ,
345
+ ) ?) ;
346
+
347
+ // get additional
348
+ buf. copy_from_slice ( get_slice (
349
+ data,
350
+ additional_start + 28 ,
351
+ additional_start + 32 ,
352
+ ) ?) ;
353
+ let additional_len: usize = u32:: from_be_bytes ( buf) as usize ;
354
+ if additional_len > MAX_SINGLE_PARAMETER_SIZE {
355
+ log:: error!( "the length of additional as {} is too big" , additional_len) ;
356
+ return Err ( PrecompileFailure :: Error {
357
+ exit_status : ExitError :: InvalidRange ,
358
+ } ) ;
359
+ }
360
+ let mut additional_vec = vec ! [ 0 ; additional_len] ;
361
+ additional_vec. copy_from_slice ( get_slice (
362
+ data,
363
+ additional_start + 32 ,
364
+ additional_start + additional_len + 32 ,
365
+ ) ?) ;
366
+
367
+ Ok ( (
368
+ pubkey,
369
+ name_vec,
370
+ repo_vec,
371
+ contact_vec,
372
+ url_vec,
373
+ discord_vec,
374
+ description_vec,
375
+ additional_vec,
376
+ ) )
214
377
}
215
378
}
0 commit comments