Skip to content

Commit

Permalink
Merge pull request #3197 from autonomys/genesis-allocations
Browse files Browse the repository at this point in the history
inject genesis balances from json into chainspec
  • Loading branch information
nazar-pc authored Oct 31, 2024
2 parents a003e8e + 96f585b commit 3650f91
Show file tree
Hide file tree
Showing 4 changed files with 108,450 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/subspace-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ sc-telemetry = { git = "https://github.com/subspace/polkadot-sdk", rev = "587181
sc-transaction-pool-api = { git = "https://github.com/subspace/polkadot-sdk", rev = "5871818e1d736f1843eb9078f886290695165c42" }
sc-network-sync = { git = "https://github.com/subspace/polkadot-sdk", rev = "5871818e1d736f1843eb9078f886290695165c42" }
sc-utils = { git = "https://github.com/subspace/polkadot-sdk", rev = "5871818e1d736f1843eb9078f886290695165c42" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.128"
sp-api = { git = "https://github.com/subspace/polkadot-sdk", rev = "5871818e1d736f1843eb9078f886290695165c42" }
sp-blockchain = { git = "https://github.com/subspace/polkadot-sdk", rev = "5871818e1d736f1843eb9078f886290695165c42" }
Expand Down
25 changes: 20 additions & 5 deletions crates/subspace-node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ use sc_chain_spec::GenericChainSpec;
use sc_service::ChainType;
use sc_subspace_chain_specs::{DEVNET_CHAIN_SPEC, TAURUS_CHAIN_SPEC};
use sc_telemetry::TelemetryEndpoints;
use serde::Deserialize;
use sp_core::crypto::Ss58Codec;
use sp_domains::PermissionedActionAllowedBy;
use sp_runtime::{BoundedVec, Percent};
use std::marker::PhantomData;
use std::num::NonZeroU32;
use std::num::{NonZeroU128, NonZeroU32};
use subspace_core_primitives::pot::PotKey;
use subspace_runtime::{
AllowAuthoringBy, BalancesConfig, CouncilConfig, DemocracyConfig, DomainsConfig,
Expand Down Expand Up @@ -58,6 +59,22 @@ struct GenesisDomainParams {
genesis_domains: Vec<GenesisDomain>,
}

/// Genesis token balances allocations
const GENESIS_ALLOCATIONS: &str = include_str!("genesis_allocations.json");

#[derive(Deserialize)]
struct GenesisAllocation(AccountId, NonZeroU128);

fn get_genesis_allocations(contents: &str) -> Vec<(AccountId, Balance)> {
let allocations: Vec<GenesisAllocation> =
serde_json::from_str(contents).expect("Failed to parse genesis allocations JSON");

allocations
.into_iter()
.map(|GenesisAllocation(account, balance)| (account, balance.get() * SSC))
.collect()
}

pub fn taurus_compiled() -> Result<GenericChainSpec, String> {
Ok(GenericChainSpec::builder(
WASM_BINARY.ok_or_else(|| "Wasm binary must be built for Taurus".to_string())?,
Expand Down Expand Up @@ -105,10 +122,8 @@ pub fn taurus_compiled() -> Result<GenericChainSpec, String> {
phantom: PhantomData,
members: council_members,
};
let balances = vec![
(sudo_account.clone(), 1_000 * SSC),
(history_seeder.clone(), SSC),
];
let balances = get_genesis_allocations(GENESIS_ALLOCATIONS);

serde_json::to_value(subspace_genesis_config(
sudo_account.clone(),
balances,
Expand Down
Loading

0 comments on commit 3650f91

Please sign in to comment.