chain_spec.rs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. use primitives::{Ed25519AuthorityId, ed25519};
  2. use joystream_node_runtime::{
  3. AccountId, GenesisConfig, ConsensusConfig, TimestampConfig, BalancesConfig,
  4. SudoConfig, IndicesConfig
  5. };
  6. use substrate_service;
  7. // Note this is the URL for the telemetry server
  8. //const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";
  9. /// Specialised `ChainSpec`. This is a specialisation of the general Substrate ChainSpec type.
  10. pub type ChainSpec = substrate_service::ChainSpec<GenesisConfig>;
  11. /// The chain specification option. This is expected to come in from the CLI and
  12. /// is little more than one of a number of alternatives which can easily be converted
  13. /// from a string (`--chain=...`) into a `ChainSpec`.
  14. #[derive(Clone, Debug)]
  15. pub enum Alternative {
  16. /// Whatever the current runtime is, with just Alice as an auth.
  17. Development,
  18. /// Whatever the current runtime is, with simple Alice/Bob auths.
  19. LocalTestnet,
  20. }
  21. impl Alternative {
  22. /// Get an actual chain config from one of the alternatives.
  23. pub(crate) fn load(self) -> Result<ChainSpec, String> {
  24. Ok(match self {
  25. Alternative::Development => ChainSpec::from_genesis(
  26. "Development",
  27. "dev",
  28. || testnet_genesis(vec![
  29. ed25519::Pair::from_seed(b"Alice ").public().into(),
  30. ], vec![
  31. ed25519::Pair::from_seed(b"Alice ").public().0.into(),
  32. ],
  33. ed25519::Pair::from_seed(b"Alice ").public().0.into()
  34. ),
  35. vec![],
  36. None,
  37. None,
  38. None,
  39. None
  40. ),
  41. Alternative::LocalTestnet => ChainSpec::from_genesis(
  42. "Local Testnet",
  43. "local_testnet",
  44. || testnet_genesis(vec![
  45. ed25519::Pair::from_seed(b"Alice ").public().into(),
  46. ed25519::Pair::from_seed(b"Bob ").public().into(),
  47. ], vec![
  48. ed25519::Pair::from_seed(b"Alice ").public().0.into(),
  49. ed25519::Pair::from_seed(b"Bob ").public().0.into(),
  50. ed25519::Pair::from_seed(b"Charlie ").public().0.into(),
  51. ed25519::Pair::from_seed(b"Dave ").public().0.into(),
  52. ed25519::Pair::from_seed(b"Eve ").public().0.into(),
  53. ed25519::Pair::from_seed(b"Ferdie ").public().0.into(),
  54. ],
  55. ed25519::Pair::from_seed(b"Alice ").public().0.into()
  56. ),
  57. vec![],
  58. None,
  59. None,
  60. None,
  61. None
  62. ),
  63. })
  64. }
  65. pub(crate) fn from(s: &str) -> Option<Self> {
  66. match s {
  67. "dev" => Some(Alternative::Development),
  68. "local" => Some(Alternative::LocalTestnet),
  69. _ => None,
  70. }
  71. }
  72. }
  73. fn testnet_genesis(initial_authorities: Vec<Ed25519AuthorityId>, endowed_accounts: Vec<AccountId>, root_key: AccountId) -> GenesisConfig {
  74. GenesisConfig {
  75. consensus: Some(ConsensusConfig {
  76. code: include_bytes!("../runtime/wasm/target/wasm32-unknown-unknown/release/joystream_node_runtime.compact.wasm").to_vec(),
  77. authorities: initial_authorities.clone(),
  78. }),
  79. system: None,
  80. timestamp: Some(TimestampConfig {
  81. period: 5, // 5 second block time.
  82. }),
  83. indices: Some(IndicesConfig {
  84. ids: endowed_accounts.clone(),
  85. }),
  86. balances: Some(BalancesConfig {
  87. transaction_base_fee: 1,
  88. transaction_byte_fee: 0,
  89. existential_deposit: 500,
  90. transfer_fee: 0,
  91. creation_fee: 0,
  92. balances: endowed_accounts.iter().map(|&k|(k, (1 << 60))).collect(),
  93. }),
  94. sudo: Some(SudoConfig {
  95. key: root_key,
  96. }),
  97. }
  98. }