-
Notifications
You must be signed in to change notification settings - Fork 288
Expand file tree
/
Copy pathlocalnet.rs
More file actions
138 lines (129 loc) · 4.46 KB
/
localnet.rs
File metadata and controls
138 lines (129 loc) · 4.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// Allowed since it's actually better to panic during chain setup when there is an error
#![allow(clippy::unwrap_used)]
use super::*;
pub fn localnet_config(single_authority: bool) -> Result<ChainSpec, String> {
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;
// Give front-ends necessary data to present to users
let mut properties = sc_service::Properties::new();
properties.insert("tokenSymbol".into(), "TAO".into());
properties.insert("tokenDecimals".into(), 9.into());
properties.insert("ss58Format".into(), 42.into());
Ok(ChainSpec::builder(
wasm_binary,
Extensions {
bad_blocks: Some(HashSet::from_iter(vec![
// Example bad block
H256::from_str(
"0xc174d485de4bc3813ac249fe078af605c74ff91d07b0a396cf75fa04f81fa312",
)
.unwrap(),
])),
..Default::default()
},
)
.with_name("Bittensor")
.with_protocol_id("bittensor")
.with_id("bittensor")
.with_chain_type(ChainType::Local)
.with_genesis_config_patch(localnet_genesis(
// Initial PoA authorities (Validators)
// aura | grandpa
if single_authority {
// single authority allows you to run the network using a single node
vec![authority_keys_from_seed("Alice")]
} else {
vec![
authority_keys_from_seed("Alice"),
authority_keys_from_seed("Bob"),
]
},
// Pre-funded accounts
true,
))
.with_properties(properties)
.build())
}
fn localnet_genesis(
initial_authorities: Vec<(AuraId, GrandpaId)>,
_enable_println: bool,
) -> serde_json::Value {
let mut balances = vec![
(
get_account_id_from_seed::<sr25519::Public>("Alice"),
1000000000000000u128,
),
(
get_account_id_from_seed::<sr25519::Public>("Bob"),
1000000000000000u128,
),
(
get_account_id_from_seed::<sr25519::Public>("Charlie"),
1000000000000000u128,
),
(
get_account_id_from_seed::<sr25519::Public>("Dave"),
2000000000000u128,
),
(
get_account_id_from_seed::<sr25519::Public>("Eve"),
2000000000000u128,
),
(
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
2000000000000u128,
),
// ETH
(
// Alith - 0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac
AccountId::from_str("5Fghzk1AJt88PeFEzuRfXzbPchiBbsVGTTXcdx599VdZzkTA").unwrap(),
2000000000000u128,
),
(
// Baltathar - 0x3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0
AccountId::from_str("5GeqNhKWj1KG78VHzbmo3ZjZgUTrCuWeamdgiA114XHGdaEr").unwrap(),
2000000000000u128,
),
];
// Check if the environment variable is set
if let Ok(bt_wallet) = env::var("BT_DEFAULT_TOKEN_WALLET") {
if let Ok(decoded_wallet) = Ss58Codec::from_ss58check(&bt_wallet) {
balances.push((decoded_wallet, 1_000_000_000_000_000u128));
} else {
eprintln!("Invalid format for BT_DEFAULT_TOKEN_WALLET.");
}
}
let trimvirate_members: Vec<AccountId> = bounded_vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Charlie"),
];
let senate_members: Vec<AccountId> = bounded_vec![
get_account_id_from_seed::<sr25519::Public>("Dave"),
get_account_id_from_seed::<sr25519::Public>("Eve"),
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
];
serde_json::json!({
"balances": { "balances": balances },
"aura": {
"authorities": initial_authorities.iter().map(|x| (x.0.clone())).collect::<Vec<_>>()
},
"grandpa": {
"authorities": initial_authorities
.iter()
.map(|x| (x.1.clone(), 1))
.collect::<Vec<_>>()
},
"sudo": {
"key": Some(get_account_id_from_seed::<sr25519::Public>("Alice"))
},
"triumvirateMembers": {
"members": trimvirate_members
},
"senateMembers": {
"members": senate_members,
},
"evmChainId": {
"chainId": 42,
},
})
}