Browse Source

Merge pull request #3192 from mnaamani/olympia-member-migration-memo-lock-export

Olympia member migration memo lock export
shamil-gadelshin 3 years ago
parent
commit
4f96bbaee8

+ 2 - 15
Cargo.lock

@@ -2365,7 +2365,6 @@ dependencies = [
  "pallet-grandpa",
  "pallet-im-online",
  "pallet-membership",
- "pallet-memo",
  "pallet-offences",
  "pallet-offences-benchmarking",
  "pallet-proposals-codex",
@@ -2383,7 +2382,7 @@ dependencies = [
  "pallet-timestamp",
  "pallet-transaction-payment",
  "pallet-transaction-payment-rpc-runtime-api",
- "pallet-utility 1.0.0",
+ "pallet-utility 1.1.0",
  "pallet-utility 2.0.1",
  "pallet-working-group",
  "parity-scale-codec",
@@ -3958,18 +3957,6 @@ dependencies = [
  "sp-std",
 ]
 
-[[package]]
-name = "pallet-memo"
-version = "5.0.0"
-dependencies = [
- "frame-support",
- "frame-system",
- "pallet-balances",
- "parity-scale-codec",
- "sp-arithmetic",
- "sp-std",
-]
-
 [[package]]
 name = "pallet-offences"
 version = "2.0.1"
@@ -4309,7 +4296,7 @@ dependencies = [
 
 [[package]]
 name = "pallet-utility"
-version = "1.0.0"
+version = "1.1.0"
 dependencies = [
  "frame-benchmarking",
  "frame-support",

+ 0 - 1
Cargo.toml

@@ -8,7 +8,6 @@ members = [
 	"runtime-modules/council",
 	"runtime-modules/forum",
 	"runtime-modules/membership",
-	"runtime-modules/memo",
 	"runtime-modules/referendum",
 	"runtime-modules/storage",
 	"runtime-modules/working-group",

File diff suppressed because it is too large
+ 0 - 0
chain-metadata.json


+ 1 - 1
query-node/mappings/src/bootstrap-data/index.ts

@@ -1,4 +1,4 @@
-import { MemberJson, StorageSystemJson, WorkingGroupJson, MembershipSystemJson } from './types'
+import { StorageSystemJson, WorkingGroupJson, MembershipSystemJson, MemberJson } from './types'
 import storageSystemJson from './data/storageSystem.json'
 import membersJson from './data/members.json'
 import workingGroupsJson from './data/workingGroups.json'

+ 5 - 7
query-node/mappings/src/bootstrap-data/types.ts

@@ -1,12 +1,10 @@
 export type MemberJson = {
-  memberId: string
-  rootAccount: string
-  controllerAccount: string
+  member_id: number
+  root_account: string
+  controller_account: string
   handle: string
-  about?: string
-  avatarUri?: string
-  registeredAtTime: number
-  registeredAtBlock: number
+  about: string
+  avatar_uri: string
 }
 
 export type StorageSystemJson = {

+ 24 - 1
query-node/mappings/src/bootstrap.ts

@@ -6,13 +6,17 @@ import {
   WorkingGroup,
   ElectedCouncil,
   ElectionRound,
+  MembershipEntryGenesis,
 } from 'query-node/dist/model'
-import { storageSystemData, membershipSystemData, workingGroupsData } from './bootstrap-data'
+import { storageSystemData, membershipSystemData, workingGroupsData, membersData } from './bootstrap-data'
+import { createNewMember } from './membership'
 
 import { CURRENT_NETWORK } from './common'
+import { MembershipMetadata } from '@joystream/metadata-protobuf'
 
 export async function bootstrapData({ store }: StoreContext): Promise<void> {
   await initMembershipSystem(store)
+  await initMembers(store)
   await initStorageSystem(store)
   await initWorkingGroups(store)
   await initFirstElectionRound(store)
@@ -81,3 +85,22 @@ async function initFirstElectionRound(store: DatabaseManager): Promise<void> {
   })
   await store.save<ElectionRound>(initialElectionRound)
 }
+
+async function initMembers(store: DatabaseManager) {
+  for (const member of membersData) {
+    await createNewMember(
+      store,
+      new Date(0),
+      member.member_id.toString(),
+      new MembershipEntryGenesis(),
+      member.root_account,
+      member.controller_account,
+      member.handle,
+      0,
+      new MembershipMetadata({
+        about: member.about,
+        avatarUri: member.avatar_uri,
+      })
+    )
+  }
+}

+ 50 - 0
query-node/mappings/src/membership.ts

@@ -120,6 +120,56 @@ async function createNewMemberFromParams(
   return member
 }
 
+export async function createNewMember(
+  store: DatabaseManager,
+  eventTime: Date,
+  memberId: string,
+  entryMethod: typeof MembershipEntryMethod,
+  rootAccount: string,
+  controllerAccount: string,
+  handle: string,
+  defaultInviteCount: number,
+  metadata: MembershipMetadata
+): Promise<Membership> {
+  const avatar = new AvatarUri()
+  avatar.avatarUri = metadata?.avatarUri ?? ''
+
+  const metadataEntity = new MemberMetadata({
+    createdAt: eventTime,
+    updatedAt: eventTime,
+    name: metadata?.name || undefined,
+    about: metadata?.about || undefined,
+    avatar,
+  })
+
+  const member = new Membership({
+    createdAt: eventTime,
+    updatedAt: eventTime,
+    id: memberId,
+    rootAccount: rootAccount.toString(),
+    controllerAccount: controllerAccount.toString(),
+    handle: handle.toString(),
+    metadata: metadataEntity,
+    entry: entryMethod,
+    referredBy: undefined,
+    isVerified: false,
+    inviteCount: defaultInviteCount,
+    boundAccounts: [],
+    invitees: [],
+    referredMembers: [],
+    invitedBy: undefined,
+    isFoundingMember: false,
+    isCouncilMember: false,
+    councilCandidacies: [],
+    councilMembers: [],
+  })
+
+  await store.save<MemberMetadata>(member.metadata)
+  await store.save<Membership>(member)
+
+  return member
+}
+
 export async function members_MembershipBought({ store, event }: EventContext & StoreContext): Promise<void> {
   const [memberId, buyMembershipParameters] = new Members.MembershipBoughtEvent(event).params
 

+ 8 - 0
runtime-modules/common/src/lib.rs

@@ -12,10 +12,12 @@ use codec::{Codec, Decode, Encode};
 #[cfg(feature = "std")]
 use serde::{Deserialize, Serialize};
 
+use frame_support::traits::LockIdentifier;
 use frame_support::Parameter;
 pub use membership::{ActorId, MemberId, MembershipTypes, StakingAccountValidator};
 use sp_arithmetic::traits::BaseArithmetic;
 use sp_runtime::traits::{MaybeSerialize, Member};
+use sp_std::collections::btree_set::BTreeSet;
 use sp_std::vec::Vec;
 
 /// HTTP Url string
@@ -92,3 +94,9 @@ pub fn current_block_time<T: frame_system::Trait + pallet_timestamp::Trait>(
         time: <pallet_timestamp::Module<T>>::now(),
     }
 }
+
+/// Provides allowed locks combination for the accounts.
+pub trait AllowedLockCombinationProvider {
+    /// Return allowed locks combination set.
+    fn get_allowed_lock_combinations() -> BTreeSet<(LockIdentifier, LockIdentifier)>;
+}

+ 0 - 2
runtime-modules/membership/src/genesis.rs

@@ -13,7 +13,6 @@ pub struct Member<MemberId, AccountId> {
     pub handle: String,
     pub avatar_uri: String,
     pub about: String,
-    pub name: String,
 }
 
 /// Builder fo membership module genesis configuration.
@@ -47,7 +46,6 @@ impl<T: Trait> GenesisConfigBuilder<T> {
                 handle: (10000 + ix).to_string(),
                 avatar_uri: "".into(),
                 about: "".into(),
-                name: "".into(),
             })
             .collect()
     }

+ 0 - 24
runtime-modules/memo/Cargo.toml

@@ -1,24 +0,0 @@
-[package]
-name = 'pallet-memo'
-version = '5.0.0'
-authors = ['Joystream contributors']
-edition = '2018'
-
-[dependencies]
-codec = { package = 'parity-scale-codec', version = '1.3.4', default-features = false, features = ['derive'] }
-sp-arithmetic = { package = 'sp-arithmetic', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '2cd20966cc09b059817c3ebe12fc130cdd850d62'}
-sp-std = { package = 'sp-std', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '2cd20966cc09b059817c3ebe12fc130cdd850d62'}
-frame-support = { package = 'frame-support', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '2cd20966cc09b059817c3ebe12fc130cdd850d62'}
-frame-system = { package = 'frame-system', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '2cd20966cc09b059817c3ebe12fc130cdd850d62'}
-balances = { package = 'pallet-balances', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '2cd20966cc09b059817c3ebe12fc130cdd850d62'}
-
-[features]
-default = ['std']
-std = [
-	'codec/std',
-	'sp-arithmetic/std',
-	'sp-std/std',
-	'frame-support/std',
-	'frame-system/std',
-	'balances/std',
-]

+ 0 - 46
runtime-modules/memo/src/lib.rs

@@ -1,46 +0,0 @@
-// Ensure we're `no_std` when compiling for Wasm.
-#![cfg_attr(not(feature = "std"), no_std)]
-// Internal Substrate warning (decl_event).
-#![allow(clippy::unused_unit)]
-
-use frame_support::traits::Currency;
-use frame_support::{decl_event, decl_module, decl_storage, ensure};
-use frame_system::ensure_signed;
-use sp_arithmetic::traits::Zero;
-use sp_std::vec::Vec;
-
-pub trait Trait: frame_system::Trait + balances::Trait {
-    type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
-}
-
-pub type MemoText = Vec<u8>;
-
-decl_storage! {
-    trait Store for Module<T: Trait> as Memo {
-        Memo get(fn memo) : map hasher(blake2_128_concat) T::AccountId => MemoText;
-        MaxMemoLength get(fn max_memo_length) : u32 = 4096;
-    }
-}
-
-decl_event! {
-    pub enum Event<T> where <T as frame_system::Trait>::AccountId {
-        MemoUpdated(AccountId, MemoText),
-    }
-}
-
-decl_module! {
-    pub struct Module<T: Trait> for enum Call where origin: T::Origin {
-        fn deposit_event() = default;
-
-        #[weight = 10_000_000] // TODO: adjust weight
-        fn update_memo(origin, memo: MemoText) {
-            let sender = ensure_signed(origin)?;
-
-            ensure!(!<balances::Module<T>>::total_balance(&sender).is_zero(), "account must have a balance");
-            ensure!(memo.len() as u32 <= Self::max_memo_length(), "memo too long");
-
-            <Memo<T>>::insert(&sender, memo.clone());
-            Self::deposit_event(RawEvent::MemoUpdated(sender, memo));
-        }
-    }
-}

+ 1 - 1
runtime-modules/utility/Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = 'pallet-utility'
-version = '1.0.0'
+version = '1.1.0'
 authors = ['Joystream contributors']
 edition = '2018'
 

+ 10 - 3
runtime-modules/utility/src/lib.rs

@@ -24,16 +24,16 @@ pub(crate) mod tests;
 
 mod benchmarking;
 
-use common::{working_group::WorkingGroup, BalanceKind};
+use common::{working_group::WorkingGroup, AllowedLockCombinationProvider, BalanceKind};
 use council::Module as Council;
-use frame_support::traits::Currency;
-use frame_support::traits::Get;
+use frame_support::traits::{Currency, Get, LockIdentifier};
 use frame_support::weights::{DispatchClass, Weight};
 use frame_support::{decl_error, decl_event, decl_module, ensure, print};
 use frame_system::{ensure_root, ensure_signed};
 use sp_arithmetic::traits::Zero;
 use sp_runtime::traits::Saturating;
 use sp_runtime::SaturatedConversion;
+use sp_std::collections::btree_set::BTreeSet;
 use sp_std::vec::Vec;
 
 type BalanceOf<T> = <T as balances::Trait>::Balance;
@@ -50,6 +50,9 @@ pub trait Trait: frame_system::Trait + balances::Trait + council::Trait {
 
     /// Weight information for extrinsics in this pallet.
     type WeightInfo: WeightInfo;
+
+    /// Exposes allowed lock combinations from the runtime level.
+    type AllowedLockCombinationProvider: AllowedLockCombinationProvider;
 }
 
 /// Utility WeightInfo.
@@ -116,6 +119,10 @@ decl_module! {
         /// Predefined errors
         type Error = Error<T>;
 
+        /// Exposes allowed lock combinations from the runtime level.
+        const AllowedLockCombinations: BTreeSet<(LockIdentifier, LockIdentifier)> =
+            T::AllowedLockCombinationProvider::get_allowed_lock_combinations();
+
         /// Signal proposal extrinsic. Should be used as callable object to pass to the `engine` module.
         ///
         /// <weight>

+ 9 - 0
runtime-modules/utility/src/tests/mocks.rs

@@ -206,6 +206,15 @@ impl Trait for Test {
     fn set_working_group_budget(working_group: WorkingGroup, budget: BalanceOf<Test>) {
         call_wg!(working_group<Test>, set_budget, budget)
     }
+
+    type AllowedLockCombinationProvider = AllowedLockCombinationProvider;
+}
+
+pub struct AllowedLockCombinationProvider;
+impl common::AllowedLockCombinationProvider for AllowedLockCombinationProvider {
+    fn get_allowed_lock_combinations() -> BTreeSet<(LockIdentifier, LockIdentifier)> {
+        Default::default()
+    }
 }
 
 impl WeightInfo for () {

+ 0 - 2
runtime/Cargo.toml

@@ -64,7 +64,6 @@ hex-literal = { optional = true, version = '0.3.1' }
 
 # Joystream
 common = { package = 'pallet-common', default-features = false, path = '../runtime-modules/common'}
-memo = { package = 'pallet-memo', default-features = false, path = '../runtime-modules/memo'}
 forum = { package = 'pallet-forum', default-features = false, path = '../runtime-modules/forum'}
 membership = { package = 'pallet-membership', default-features = false, path = '../runtime-modules/membership'}
 referendum = { package = 'pallet-referendum', default-features = false, path = '../runtime-modules/referendum'}
@@ -139,7 +138,6 @@ std = [
 
     # Joystream
     'common/std',
-    'memo/std',
     'forum/std',
     'membership/std',
     'council/std',

+ 11 - 5
runtime/src/lib.rs

@@ -58,6 +58,7 @@ use sp_runtime::curve::PiecewiseLinear;
 use sp_runtime::traits::{BlakeTwo256, Block as BlockT, IdentityLookup, OpaqueKeys, Saturating};
 use sp_runtime::{create_runtime_str, generic, impl_opaque_keys, ModuleId, Perbill};
 use sp_std::boxed::Box;
+use sp_std::collections::btree_set::BTreeSet;
 use sp_std::vec::Vec;
 #[cfg(feature = "std")]
 use sp_version::NativeVersion;
@@ -71,6 +72,7 @@ pub use runtime_api::*;
 use integration::proposals::{CouncilManager, ExtrinsicProposalEncoder};
 
 use common::working_group::{WorkingGroup, WorkingGroupAuthenticator, WorkingGroupBudgetHandler};
+use common::AllowedLockCombinationProvider;
 use council::ReferendumConnection;
 use referendum::{CastVote, OptionResult};
 use staking_handler::{LockComparator, StakingManager};
@@ -575,10 +577,6 @@ impl common::StorageOwnership for Runtime {
     type DataObjectTypeId = DataObjectTypeId;
 }
 
-impl memo::Trait for Runtime {
-    type Event = Event;
-}
-
 parameter_types! {
     pub const MaxDistributionBucketFamilyNumber: u64 = 200;
     pub const DataObjectDeletionPrize: Balance = 0; //TODO: Change during Olympia release
@@ -983,9 +981,18 @@ impl proposals_discussion::Trait for Runtime {
     type PostLifeTime = ForumPostLifeTime;
 }
 
+pub struct LockCombinationProvider;
+impl AllowedLockCombinationProvider for LockCombinationProvider {
+    fn get_allowed_lock_combinations() -> BTreeSet<(LockIdentifier, LockIdentifier)> {
+        ALLOWED_LOCK_COMBINATIONS.clone()
+    }
+}
+
 impl joystream_utility::Trait for Runtime {
     type Event = Event;
 
+    type AllowedLockCombinationProvider = LockCombinationProvider;
+
     type WeightInfo = weights::joystream_utility::WeightInfo;
 
     fn get_working_group_budget(working_group: WorkingGroup) -> Balance {
@@ -1133,7 +1140,6 @@ construct_runtime!(
         // Joystream
         Council: council::{Module, Call, Storage, Event<T>, Config<T>},
         Referendum: referendum::<Instance1>::{Module, Call, Storage, Event<T>, Config<T>},
-        Memo: memo::{Module, Call, Storage, Event<T>},
         Members: membership::{Module, Call, Storage, Event<T>, Config<T>},
         Forum: forum::{Module, Call, Storage, Event<T>, Config<T>},
         Constitution: pallet_constitution::{Module, Call, Storage, Event},

+ 0 - 1
types/augment/all/defs.json

@@ -24,7 +24,6 @@
             "Membership"
         ]
     },
-    "MemoText": "Text",
     "BalanceKind": {
         "_enum": [
             "Positive",

+ 0 - 3
types/augment/all/types.ts

@@ -579,9 +579,6 @@ export interface Membership extends Struct {
   readonly invites: u32;
 }
 
-/** @name MemoText */
-export interface MemoText extends Text {}
-
 /** @name ModeratorId */
 export interface ModeratorId extends u64 {}
 

+ 0 - 3
types/src/common.ts

@@ -93,8 +93,6 @@ export const WorkingGroupDef = {
 export type WorkingGroupKey = keyof typeof WorkingGroupDef
 export class WorkingGroup extends JoyEnum(WorkingGroupDef) {}
 
-export class MemoText extends Text {}
-
 export class BalanceKind extends JoyEnum({
   Positive: Null,
   Negative: Null,
@@ -115,7 +113,6 @@ export const commonTypes: RegistryTypes = {
   PostId,
   InputValidationLengthConstraint,
   WorkingGroup,
-  MemoText,
   BalanceKind,
   // Customize Address type for joystream chain
   Address,

Some files were not shown because too many files changed in this diff