@@ -113,7 +113,7 @@ pub mod pallet {
113
113
use parity_scale_codec:: Codec ;
114
114
use solana_sdk:: {
115
115
account:: Account ,
116
- clock,
116
+ bpf_loader , clock,
117
117
feature_set:: FeatureSet ,
118
118
fee_calculator:: FeeCalculator ,
119
119
hash:: Hash ,
@@ -218,6 +218,12 @@ pub mod pallet {
218
218
#[ pallet:: origin]
219
219
pub type Origin = RawOrigin ;
220
220
221
+ #[ pallet:: error]
222
+ pub enum Error < T > {
223
+ /// Failed to reallocate account data of this length
224
+ InvalidRealloc ,
225
+ }
226
+
221
227
#[ pallet:: storage]
222
228
#[ pallet:: getter( fn slot) ]
223
229
pub type Slot < T : Config > = StorageValue < _ , clock:: Slot , ValueQuery > ;
@@ -328,6 +334,32 @@ pub mod pallet {
328
334
}
329
335
330
336
impl < T : Config > Pallet < T > {
337
+ pub fn create_account ( pubkey : Pubkey , owner : Pubkey , executable : bool ) {
338
+ let who = T :: AccountIdConversion :: convert ( pubkey) ;
339
+ <frame_system:: Pallet < T > >:: inc_sufficients ( & who) ;
340
+ <AccountMeta < T > >:: insert (
341
+ who,
342
+ AccountMetadata { owner, executable, rent_epoch : u64:: MAX } ,
343
+ ) ;
344
+ }
345
+
346
+ pub fn deploy_program (
347
+ pubkey : Pubkey ,
348
+ data : Vec < u8 > ,
349
+ owner : Option < Pubkey > ,
350
+ ) -> Result < ( ) , Error < T > > {
351
+ let program_id = T :: AccountIdConversion :: convert ( pubkey) ;
352
+ let owner = owner. unwrap_or ( bpf_loader:: id ( ) ) ;
353
+ Self :: create_account ( pubkey, owner, true ) ;
354
+ if !data. is_empty ( ) {
355
+ <AccountData < T > >:: insert (
356
+ program_id,
357
+ BoundedVec :: try_from ( data. to_vec ( ) ) . map_err ( |_| Error :: InvalidRealloc ) ?,
358
+ ) ;
359
+ }
360
+ Ok ( ( ) )
361
+ }
362
+
331
363
pub fn get_hash_info_if_valid (
332
364
hash : & T :: Hash ,
333
365
max_age : BlockNumberFor < T > ,
0 commit comments