Skip to content
Snippets Groups Projects
gen_genesis_data.rs 25.81 KiB
// Copyright 2021 Axiom-Team
//
// This file is part of Duniter-v2S.
//
// Duniter-v2S is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// Duniter-v2S is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.

use crate::chain_spec::gdev::{get_authority_keys_from_seed, get_env, session_keys, AuthorityKeys};
use crate::chain_spec::{clique_wot, get_account_id_from_seed, NAMES};
use common_runtime::*;
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use sp_core::crypto::AccountId32;
use sp_core::{blake2_256, sr25519, Decode, Encode, H256};
use std::collections::BTreeMap;

type MembershipData = sp_membership::MembershipData<u32>;

const EXISTENTIAL_DEPOSIT: u64 = 200;

#[derive(Clone)]
pub struct GenesisData<Parameters: DeserializeOwned, SessionKeys: Decode> {
    pub accounts: BTreeMap<AccountId, GenesisAccountData<u64>>,
    pub certs_by_receiver: BTreeMap<u32, BTreeMap<u32, Option<u32>>>,
    pub first_ud: Option<u64>,
    pub first_ud_reeval: Option<u64>,
    pub identities: Vec<(String, AccountId)>,
    pub initial_authorities: BTreeMap<u32, (AccountId, bool)>,
    pub initial_monetary_mass: u64,
    pub memberships: BTreeMap<u32, MembershipData>,
    pub parameters: Parameters,
    pub session_keys_map: BTreeMap<AccountId, SessionKeys>,
    pub smith_certs_by_receiver: BTreeMap<u32, BTreeMap<u32, Option<u32>>>,
    pub smith_memberships: BTreeMap<u32, MembershipData>,
    pub sudo_key: Option<AccountId>,
    pub technical_committee_members: Vec<AccountId>,
    pub ud: u64,
}

#[derive(Default, Deserialize, Serialize)]
pub struct ParamsAppliedAtGenesis {
    pub genesis_certs_min_received: u32,
    pub genesis_memberships_expire_on: u32,
    pub genesis_smith_certs_min_received: u32,
    pub genesis_smith_memberships_expire_on: u32,
}

#[derive(Deserialize, Serialize)]
struct GenesisConfig<Parameters> {
    first_ud: Option<u64>,
    first_ud_reeval: Option<u64>,
    genesis_parameters: ParamsAppliedAtGenesis,
    #[serde(default)]
    parameters: Parameters,
    #[serde(rename = "smiths")]
    smith_identities: Option<BTreeMap<String, SmithData>>,
    clique_smiths: Option<Vec<CliqueSmith>>,
    sudo_key: Option<AccountId>,
    technical_committee: Vec<String>,
    ud: u64,
}