Browse Source

substrate v2: additional fixes

Mokhtar Naamani 5 years ago
parent
commit
83fc6f09d1

+ 3 - 3
src/governance/election.rs

@@ -837,13 +837,13 @@ decl_module! {
             ensure!(!Self::is_election_running(), "cannot change params during election");
             ensure!(council_size > 0, "council size cannot be zero");
             ensure!(council_size <= Self::candidacy_limit(), "council size cannot greater than candidacy limit");
-            <CouncilSize<T>>::put(council_size);
+            CouncilSize::put(council_size);
         }
         fn set_param_candidacy_limit(origin, limit: u32) {
             ensure_root(origin)?;
             ensure!(!Self::is_election_running(), "cannot change params during election");
             ensure!(limit >= Self::council_size(), "candidacy limit cannot be less than council size");
-            <CandidacyLimit<T>>::put(limit);
+            CandidacyLimit::put(limit);
         }
         fn set_param_min_voting_stake(origin, amount: BalanceOf<T>) {
             ensure_root(origin)?;
@@ -877,7 +877,7 @@ decl_module! {
 
         fn set_auto_start (origin, flag: bool) {
             ensure_root(origin)?;
-            <AutoStart<T>>::put(flag);
+            AutoStart::put(flag);
         }
 
     }

+ 5 - 5
src/governance/proposals.rs

@@ -249,7 +249,7 @@ decl_module! {
                 .map_err(|_| MSG_STAKE_IS_GREATER_THAN_BALANCE)?;
 
             let proposal_id = Self::proposal_count() + 1;
-            <ProposalCount<T>>::put(proposal_id);
+            ProposalCount::put(proposal_id);
 
             // See in substrate repo @ srml/contract/src/wasm/code_cache.rs:73
             let wasm_hash = T::Hashing::hash(&wasm_code);
@@ -269,7 +269,7 @@ decl_module! {
               <WasmCodeByHash<T>>::insert(wasm_hash, wasm_code);
             }
             <Proposals<T>>::insert(proposal_id, new_proposal);
-            <ActiveProposalIds<T>>::mutate(|ids| ids.push(proposal_id));
+            ActiveProposalIds::mutate(|ids| ids.push(proposal_id));
             Self::deposit_event(RawEvent::ProposalCreated(proposer.clone(), proposal_id));
 
             // Auto-vote with Approve if proposer is a councilor:
@@ -347,7 +347,7 @@ decl_module! {
         fn set_approval_quorum(origin, new_value: u32) {
             ensure_root(origin)?;
             ensure!(new_value > 0, "approval quorom must be greater than zero");
-            <ApprovalQuorum<T>>::put(new_value);
+            ApprovalQuorum::put(new_value);
         }
     }
 }
@@ -501,7 +501,7 @@ impl<T: Trait> Module<T> {
                 Approved => Self::_approve_proposal(pid)?,
                 Active | Cancelled => { /* nothing */ }
             }
-            <ActiveProposalIds<T>>::put(other_active_ids);
+            ActiveProposalIds::put(other_active_ids);
             <Proposals<T>>::mutate(proposal_id, |p| p.status = new_status.clone());
             Self::deposit_event(RawEvent::ProposalStatusUpdated(proposal_id, new_status));
             Ok(())
@@ -543,7 +543,7 @@ impl<T: Trait> Module<T> {
         let _ = T::Currency::unreserve(&proposal.proposer, proposal.stake);
 
         // Update wasm code of node's runtime:
-        <system::Module<T>>::set_code(wasm_code)?;
+        <system::Module<T>>::set_code(system::RawOrigin::Root.into(), wasm_code)?;
 
         Self::deposit_event(RawEvent::RuntimeUpdated(proposal_id, proposal.wasm_hash));
 

+ 11 - 11
src/membership/members.rs

@@ -43,12 +43,12 @@ pub trait Trait: system::Trait + GovernanceCurrency + timestamp::Trait {
     type Roles: Roles<Self>;
 }
 
-const DEFAULT_FIRST_MEMBER_ID: u64 = 1;
-const FIRST_PAID_TERMS_ID: u64 = 1;
+const DEFAULT_FIRST_MEMBER_ID: u32 = 1;
+const FIRST_PAID_TERMS_ID: u32 = 1;
 
 // Default paid membership terms
-const DEFAULT_PAID_TERM_ID: u64 = 0;
-const DEFAULT_PAID_TERM_FEE: u64 = 100; // Can be overidden in genesis config
+const DEFAULT_PAID_TERM_ID: u32 = 0;
+const DEFAULT_PAID_TERM_FEE: u32 = 100; // Can be overidden in genesis config
 const DEFAULT_PAID_TERM_TEXT: &str = "Default Paid Term TOS...";
 
 // Default user info constraints
@@ -107,8 +107,8 @@ pub struct PaidMembershipTerms<T: Trait> {
 impl<T: Trait> Default for PaidMembershipTerms<T> {
     fn default() -> Self {
         PaidMembershipTerms {
-            id: T::PaidTermId::sa(DEFAULT_PAID_TERM_ID),
-            fee: BalanceOf::<T>::sa(DEFAULT_PAID_TERM_FEE),
+            id: T::PaidTermId::from(DEFAULT_PAID_TERM_ID),
+            fee: BalanceOf::<T>::from(DEFAULT_PAID_TERM_FEE),
             text: DEFAULT_PAID_TERM_TEXT.as_bytes().to_vec(),
         }
     }
@@ -117,10 +117,10 @@ impl<T: Trait> Default for PaidMembershipTerms<T> {
 decl_storage! {
     trait Store for Module<T: Trait> as Membership {
         /// MemberId's start at this value
-        pub FirstMemberId get(first_member_id) config(first_member_id): T::MemberId = T::MemberId::sa(DEFAULT_FIRST_MEMBER_ID);
+        pub FirstMemberId get(first_member_id) config(first_member_id): T::MemberId = T::MemberId::from(DEFAULT_FIRST_MEMBER_ID);
 
         /// MemberId to assign to next member that is added to the registry
-        pub NextMemberId get(next_member_id) build(|config: &GenesisConfig<T>| config.first_member_id): T::MemberId = T::MemberId::sa(DEFAULT_FIRST_MEMBER_ID);
+        pub NextMemberId get(next_member_id) build(|config: &GenesisConfig<T>| config.first_member_id): T::MemberId = T::MemberId::from(DEFAULT_FIRST_MEMBER_ID);
 
         /// Mapping of member ids to their corresponding primary accountid
         pub AccountIdByMemberId get(account_id_by_member_id) : map T::MemberId => T::AccountId;
@@ -136,7 +136,7 @@ decl_storage! {
         pub Handles get(handles) : map Vec<u8> => Option<T::MemberId>;
 
         /// Next paid membership terms id
-        pub NextPaidMembershipTermsId get(next_paid_membership_terms_id) : T::PaidTermId = T::PaidTermId::sa(FIRST_PAID_TERMS_ID);
+        pub NextPaidMembershipTermsId get(next_paid_membership_terms_id) : T::PaidTermId = T::PaidTermId::from(FIRST_PAID_TERMS_ID);
 
         /// Paid membership terms record
         // Remember to add _genesis_phantom_data: std::marker::PhantomData{} to membership
@@ -152,7 +152,7 @@ decl_storage! {
         }) : map T::PaidTermId => Option<PaidMembershipTerms<T>>;
 
         /// Active Paid membership terms
-        pub ActivePaidMembershipTerms get(active_paid_membership_terms) : Vec<T::PaidTermId> = vec![T::PaidTermId::sa(DEFAULT_PAID_TERM_ID)];
+        pub ActivePaidMembershipTerms get(active_paid_membership_terms) : Vec<T::PaidTermId> = vec![T::PaidTermId::from(DEFAULT_PAID_TERM_ID)];
 
         /// Is the platform is accepting new members or not
         pub NewMembershipsAllowed get(new_memberships_allowed) : bool = true;
@@ -450,7 +450,7 @@ impl<T: Trait> Module<T> {
         <MemberProfile<T>>::insert(new_member_id, profile);
         <Handles<T>>::insert(user_info.handle.clone(), new_member_id);
         <NextMemberId<T>>::mutate(|n| {
-            *n += T::MemberId::sa(1);
+            *n += T::MemberId::from(1);
         });
 
         new_member_id

+ 1 - 1
src/migration.rs

@@ -63,7 +63,7 @@ decl_module! {
         fn on_initialize(_now: T::BlockNumber) {
             if Self::spec_version().map_or(true, |spec_version| VERSION.spec_version > spec_version) {
                 // mark store version with current version of the runtime
-                <SpecVersion<T>>::put(VERSION.spec_version);
+                SpecVersion::put(VERSION.spec_version);
 
                 // run migrations and store initializers
                 Self::runtime_initialization();

+ 6 - 6
src/roles/actors.rs

@@ -104,8 +104,8 @@ pub type Request<T> = (
 );
 pub type Requests<T> = Vec<Request<T>>;
 
-pub const DEFAULT_REQUEST_LIFETIME: u64 = 300;
-pub const REQUEST_CLEARING_INTERVAL: u64 = 100;
+pub const DEFAULT_REQUEST_LIFETIME: u32 = 300;
+pub const REQUEST_CLEARING_INTERVAL: u32 = 100;
 
 decl_storage! {
     trait Store for Module<T: Trait> as Actors {
@@ -149,7 +149,7 @@ decl_storage! {
         pub RoleEntryRequests get(role_entry_requests) : Requests<T>;
 
         /// Entry request expires after this number of blocks
-        pub RequestLifeTime get(request_life_time) config(request_life_time) : u64 = DEFAULT_REQUEST_LIFETIME;
+        pub RequestLifeTime get(request_life_time) config(request_life_time) : u32 = DEFAULT_REQUEST_LIFETIME;
     }
     add_extra_genesis {
         config(enable_storage_role): bool;
@@ -397,13 +397,13 @@ decl_module! {
 
         pub fn set_available_roles(origin, roles: Vec<Role>) {
             ensure_root(origin)?;
-            <AvailableRoles<T>>::put(roles);
+            AvailableRoles::put(roles);
         }
 
         pub fn add_to_available_roles(origin, role: Role) {
             ensure_root(origin)?;
             if !Self::available_roles().into_iter().any(|r| r == role) {
-                <AvailableRoles<T>>::mutate(|roles| roles.push(role));
+                AvailableRoles::mutate(|roles| roles.push(role));
             }
         }
 
@@ -411,7 +411,7 @@ decl_module! {
             ensure_root(origin)?;
             // Should we eject actors in the role being removed?
             let roles: Vec<Role> = Self::available_roles().into_iter().filter(|r| role != *r).collect();
-            <AvailableRoles<T>>::put(roles);
+            AvailableRoles::put(roles);
         }
 
         pub fn remove_actor(origin, actor_account: T::AccountId) {

+ 4 - 4
src/service_discovery/discovery.rs

@@ -25,8 +25,8 @@ pub type IPNSIdentity = Vec<u8>;
 /// HTTP Url string to a discovery service endpoint
 pub type Url = Vec<u8>;
 
-pub const MINIMUM_LIFETIME: u64 = 600; // 1hr assuming 6s block times
-pub const DEFAULT_LIFETIME: u64 = MINIMUM_LIFETIME * 24; // 24hr
+pub const MINIMUM_LIFETIME: u32 = 600; // 1hr assuming 6s block times
+pub const DEFAULT_LIFETIME: u32 = MINIMUM_LIFETIME * 24; // 24hr
 
 #[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
 #[derive(Encode, Decode, Default, Clone, PartialEq, Eq)]
@@ -80,7 +80,7 @@ decl_module! {
     pub struct Module<T: Trait> for enum Call where origin: T::Origin {
         fn deposit_event<T>() = default;
 
-        pub fn set_ipns_id(origin, id: Vec<u8>, lifetime: Option<u64>) {
+        pub fn set_ipns_id(origin, id: Vec<u8>, lifetime: Option<u32>) {
             let sender = ensure_signed(origin)?;
             ensure!(T::Roles::is_role_account(&sender), "only role accounts can set ipns id");
 
@@ -121,7 +121,7 @@ decl_module! {
 
         pub fn set_bootstrap_endpoints(origin, endpoints: Vec<Vec<u8>>) {
             ensure_root(origin)?;
-            <BootstrapEndpoints<T>>::put(endpoints);
+            BootstrapEndpoints::put(endpoints);
         }
     }
 }

+ 1 - 1
src/storage/data_object_storage_registry.rs

@@ -35,7 +35,7 @@ static MSG_ONLY_STORAGE_PROVIDER_MAY_CLAIM_READY: &str =
     "Only the storage provider in a DOSR can decide whether they're ready.";
 
 // TODO deprecated
-const DEFAULT_FIRST_RELATIONSHIP_ID: u64 = 1;
+const DEFAULT_FIRST_RELATIONSHIP_ID: u32 = 1;
 
 // TODO deprecated
 #[derive(Clone, Encode, Decode, PartialEq)]

+ 1 - 1
src/storage/data_object_type_registry.rs

@@ -24,7 +24,7 @@ const DEFAULT_TYPE_DESCRIPTION: &str = "Default data object type for audio and v
 const DEFAULT_TYPE_ACTIVE: bool = true;
 const CREATE_DETAULT_TYPE: bool = true;
 
-const DEFAULT_FIRST_DATA_OBJECT_TYPE_ID: u64 = 1;
+const DEFAULT_FIRST_DATA_OBJECT_TYPE_ID: u32 = 1;
 
 #[derive(Clone, Encode, Decode, PartialEq)]
 #[cfg_attr(feature = "std", derive(Debug))]

+ 1 - 1
src/storage/downloads.rs

@@ -38,7 +38,7 @@ static MSG_INVALID_TRANSMITTED_VALUE: &str = "Invalid update to transmitted byte
 static MSG_NEED_STORAGE_PROVIDER: &str =
     "Cannnot download without at least one active storage relationship.";
 
-const DEFAULT_FIRST_DOWNLOAD_SESSION_ID: u64 = 1;
+const DEFAULT_FIRST_DOWNLOAD_SESSION_ID: u32 = 1;
 
 #[derive(Clone, Encode, Decode, PartialEq)]
 #[cfg_attr(feature = "std", derive(Debug))]