@@ -71,7 +71,7 @@ use frame_support::{
7171 traits:: {
7272 Currency , Get , OnUnbalanced , WithdrawReason , ExistenceRequirement :: AllowDeath
7373 } ,
74- weights:: { MINIMUM_WEIGHT , SimpleDispatchInfo } ,
74+ weights:: MINIMUM_WEIGHT ,
7575} ;
7676use system:: ensure_signed;
7777use sp_runtime:: { ModuleId ,
@@ -80,7 +80,6 @@ use sp_runtime::{ModuleId,
8080use crate :: slots;
8181use codec:: { Encode , Decode } ;
8282use sp_std:: vec:: Vec ;
83- use sp_core:: storage:: well_known_keys:: CHILD_STORAGE_KEY_PREFIX ;
8483use primitives:: parachain:: { Id as ParaId , HeadData } ;
8584
8685const MODULE_ID : ModuleId = ModuleId ( * b"py/cfund" ) ;
@@ -251,7 +250,7 @@ decl_module! {
251250 fn deposit_event( ) = default ;
252251
253252 /// Create a new crowdfunding campaign for a parachain slot deposit for the current auction.
254- #[ weight = SimpleDispatchInfo :: FixedNormal ( 100_000_000 ) ]
253+ #[ weight = 100_000_000 ]
255254 fn create( origin,
256255 #[ compact] cap: BalanceOf <T >,
257256 #[ compact] first_slot: T :: BlockNumber ,
@@ -295,7 +294,7 @@ decl_module! {
295294 /// Contribute to a crowd sale. This will transfer some balance over to fund a parachain
296295 /// slot. It will be withdrawable in two instances: the parachain becomes retired; or the
297296 /// slot is unable to be purchased and the timeout expires.
298- #[ weight = SimpleDispatchInfo :: FixedNormal ( MINIMUM_WEIGHT ) ]
297+ #[ weight = MINIMUM_WEIGHT ]
299298 fn contribute( origin, #[ compact] index: FundIndex , #[ compact] value: BalanceOf <T >) {
300299 let who = ensure_signed( origin) ?;
301300
@@ -354,7 +353,7 @@ decl_module! {
354353 /// - `index` is the fund index that `origin` owns and whose deploy data will be set.
355354 /// - `code_hash` is the hash of the parachain's Wasm validation function.
356355 /// - `initial_head_data` is the parachain's initial head data.
357- #[ weight = SimpleDispatchInfo :: FixedNormal ( MINIMUM_WEIGHT ) ]
356+ #[ weight = MINIMUM_WEIGHT ]
358357 fn fix_deploy_data( origin,
359358 #[ compact] index: FundIndex ,
360359 code_hash: T :: Hash ,
@@ -380,7 +379,7 @@ decl_module! {
380379 ///
381380 /// - `index` is the fund index that `origin` owns and whose deploy data will be set.
382381 /// - `para_id` is the parachain index that this fund won.
383- #[ weight = SimpleDispatchInfo :: FixedNormal ( MINIMUM_WEIGHT ) ]
382+ #[ weight = MINIMUM_WEIGHT ]
384383 fn onboard( origin,
385384 #[ compact] index: FundIndex ,
386385 #[ compact] para_id: ParaId
@@ -409,7 +408,7 @@ decl_module! {
409408 }
410409
411410 /// Note that a successful fund has lost its parachain slot, and place it into retirement.
412- #[ weight = SimpleDispatchInfo :: FixedNormal ( MINIMUM_WEIGHT ) ]
411+ #[ weight = MINIMUM_WEIGHT ]
413412 fn begin_retirement( origin, #[ compact] index: FundIndex ) {
414413 let _ = ensure_signed( origin) ?;
415414
@@ -431,7 +430,7 @@ decl_module! {
431430 }
432431
433432 /// Withdraw full balance of a contributor to an unsuccessful or off-boarded fund.
434- #[ weight = SimpleDispatchInfo :: FixedNormal ( MINIMUM_WEIGHT ) ]
433+ #[ weight = MINIMUM_WEIGHT ]
435434 fn withdraw( origin, #[ compact] index: FundIndex ) {
436435 let who = ensure_signed( origin) ?;
437436
@@ -462,7 +461,7 @@ decl_module! {
462461 /// Remove a fund after either: it was unsuccessful and it timed out; or it was successful
463462 /// but it has been retired from its parachain slot. This places any deposits that were not
464463 /// withdrawn into the treasury.
465- #[ weight = SimpleDispatchInfo :: FixedNormal ( MINIMUM_WEIGHT ) ]
464+ #[ weight = MINIMUM_WEIGHT ]
466465 fn dissolve( origin, #[ compact] index: FundIndex ) {
467466 let _ = ensure_signed( origin) ?;
468467
@@ -529,46 +528,30 @@ impl<T: Trait> Module<T> {
529528 MODULE_ID . into_sub_account ( index)
530529 }
531530
532- pub fn id_from_index ( index : FundIndex ) -> Vec < u8 > {
531+ pub fn id_from_index ( index : FundIndex ) -> child :: ChildInfo {
533532 let mut buf = Vec :: new ( ) ;
534533 buf. extend_from_slice ( b"crowdfund" ) ;
535534 buf. extend_from_slice ( & index. to_le_bytes ( ) [ ..] ) ;
536-
537- CHILD_STORAGE_KEY_PREFIX . into_iter ( )
538- . chain ( b"default:" )
539- . chain ( T :: Hashing :: hash ( & buf[ ..] ) . as_ref ( ) . into_iter ( ) )
540- . cloned ( )
541- . collect ( )
542- }
543-
544- /// Child trie unique id for a crowdfund is built from the hash part of the fund id.
545- pub fn trie_unique_id ( fund_id : & [ u8 ] ) -> child:: ChildInfo {
546- let start = CHILD_STORAGE_KEY_PREFIX . len ( ) + b"default:" . len ( ) ;
547- child:: ChildInfo :: new_default ( & fund_id[ start..] )
535+ child:: ChildInfo :: new_default ( T :: Hashing :: hash ( & buf[ ..] ) . as_ref ( ) )
548536 }
549537
550538 pub fn contribution_put ( index : FundIndex , who : & T :: AccountId , balance : & BalanceOf < T > ) {
551- let id = Self :: id_from_index ( index) ;
552- who. using_encoded ( |b| child:: put ( id. as_ref ( ) , Self :: trie_unique_id ( id. as_ref ( ) ) , b, balance) ) ;
539+ who. using_encoded ( |b| child:: put ( & Self :: id_from_index ( index) , b, balance) ) ;
553540 }
554541
555542 pub fn contribution_get ( index : FundIndex , who : & T :: AccountId ) -> BalanceOf < T > {
556- let id = Self :: id_from_index ( index) ;
557543 who. using_encoded ( |b| child:: get_or_default :: < BalanceOf < T > > (
558- id. as_ref ( ) ,
559- Self :: trie_unique_id ( id. as_ref ( ) ) ,
544+ & Self :: id_from_index ( index) ,
560545 b,
561546 ) )
562547 }
563548
564549 pub fn contribution_kill ( index : FundIndex , who : & T :: AccountId ) {
565- let id = Self :: id_from_index ( index) ;
566- who. using_encoded ( |b| child:: kill ( id. as_ref ( ) , Self :: trie_unique_id ( id. as_ref ( ) ) , b) ) ;
550+ who. using_encoded ( |b| child:: kill ( & Self :: id_from_index ( index) , b) ) ;
567551 }
568552
569553 pub fn crowdfund_kill ( index : FundIndex ) {
570- let id = Self :: id_from_index ( index) ;
571- child:: kill_storage ( id. as_ref ( ) , Self :: trie_unique_id ( id. as_ref ( ) ) ) ;
554+ child:: kill_storage ( & Self :: id_from_index ( index) ) ;
572555 }
573556}
574557
0 commit comments