Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inject genesis balances from json into chainspec #3197

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading