Skip to content

Commit e2ae160

Browse files
author
Joshua Mir
committed
πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰
1 parent e3cc748 commit e2ae160

File tree

19 files changed

+3276
-0
lines changed

19 files changed

+3276
-0
lines changed

β€Ždatdot-node/LICENSEβ€Ž

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
This is free and unencumbered software released into the public domain.
2+
3+
Anyone is free to copy, modify, publish, use, compile, sell, or
4+
distribute this software, either in source code form or as a compiled
5+
binary, for any purpose, commercial or non-commercial, and by any
6+
means.
7+
8+
In jurisdictions that recognize copyright laws, the author or authors
9+
of this software dedicate any and all copyright interest in the
10+
software to the public domain. We make this dedication for the benefit
11+
of the public at large and to the detriment of our heirs and
12+
successors. We intend this dedication to be an overt act of
13+
relinquishment in perpetuity of all present and future rights to this
14+
software under copyright law.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.
23+
24+
For more information, please refer to <http://unlicense.org>

β€Ždatdot-node/README.mdβ€Ž

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Substrate Node Template
2+
3+
A new FRAME-based Substrate node, ready for hacking.
4+
5+
## Build
6+
7+
Install Rust:
8+
9+
```bash
10+
curl https://sh.rustup.rs -sSf | sh
11+
```
12+
13+
Initialize your Wasm Build environment:
14+
15+
```bash
16+
./scripts/init.sh
17+
```
18+
19+
Build Wasm and native code:
20+
21+
```bash
22+
cargo build --release
23+
```
24+
25+
## Run
26+
27+
### Single node development chain
28+
29+
Purge any existing developer chain state:
30+
31+
```bash
32+
./target/release/node-template purge-chain --dev
33+
```
34+
35+
Start a development chain with:
36+
37+
```bash
38+
./target/release/node-template --dev
39+
```
40+
41+
Detailed logs may be shown by running the node with the following environment variables set: `RUST_LOG=debug RUST_BACKTRACE=1 cargo run -- --dev`.
42+
43+
### Multi-node local testnet
44+
45+
If you want to see the multi-node consensus algorithm in action locally, then you can create a local testnet with two validator nodes for Alice and Bob, who are the initial authorities of the genesis chain that have been endowed with testnet units.
46+
47+
Optionally, give each node a name and expose them so they are listed on the Polkadot [telemetry site](https://telemetry.polkadot.io/#/Local%20Testnet).
48+
49+
You'll need two terminal windows open.
50+
51+
We'll start Alice's substrate node first on default TCP port 30333 with her chain database stored locally at `/tmp/alice`. The bootnode ID of her node is `QmRpheLN4JWdAnY7HGJfWFNbfkQCb6tFf4vvA6hgjMZKrR`, which is generated from the `--node-key` value that we specify below:
52+
53+
```bash
54+
cargo run -- \
55+
--base-path /tmp/alice \
56+
--chain=local \
57+
--alice \
58+
--node-key 0000000000000000000000000000000000000000000000000000000000000001 \
59+
--telemetry-url 'ws://telemetry.polkadot.io:1024 0' \
60+
--validator
61+
```
62+
63+
In the second terminal, we'll start Bob's substrate node on a different TCP port of 30334, and with his chain database stored locally at `/tmp/bob`. We'll specify a value for the `--bootnodes` option that will connect his node to Alice's bootnode ID on TCP port 30333:
64+
65+
```bash
66+
cargo run -- \
67+
--base-path /tmp/bob \
68+
--bootnodes /ip4/127.0.0.1/tcp/30333/p2p/QmRpheLN4JWdAnY7HGJfWFNbfkQCb6tFf4vvA6hgjMZKrR \
69+
--chain=local \
70+
--bob \
71+
--port 30334 \
72+
--telemetry-url 'ws://telemetry.polkadot.io:1024 0' \
73+
--validator
74+
```
75+
76+
Additional CLI usage options are available and may be shown by running `cargo run -- --help`.

β€Ždatdot-node/node/Cargo.tomlβ€Ž

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
[package]
2+
name = "datdot-node"
3+
version = "0.0.1"
4+
authors = ["Datdot Authors"]
5+
description = "Datdot Demo Node"
6+
edition = "2018"
7+
license = "Unlicense"
8+
build = "build.rs"
9+
homepage = "https://playproject.io"
10+
repository = "https://github.com/playproject-io/datdot-substrate"
11+
12+
[package.metadata.docs.rs]
13+
targets = ["x86_64-unknown-linux-gnu"]
14+
15+
[[bin]]
16+
name = "datdot-node"
17+
18+
[dependencies]
19+
futures = "0.3.4"
20+
log = "0.4.8"
21+
structopt = "0.3.8"
22+
23+
sc-cli = { version = "0.8.0-alpha.7" }
24+
sc-rpc = { version = "2.0.0-alpha.7" }
25+
sp-core = { version = "2.0.0-alpha.7" }
26+
sc-executor = { version = "0.8.0-alpha.7" }
27+
sc-service = { version = "0.8.0-alpha.7" }
28+
sp-inherents = { version = "2.0.0-alpha.7" }
29+
sc-transaction-pool = { version = "2.0.0-alpha.7" }
30+
sp-transaction-pool = { version = "2.0.0-alpha.7" }
31+
sc-network = { version = "0.8.0-alpha.7" }
32+
sc-consensus-babe = { version = "0.8.0-alpha.7" }
33+
sp-consensus-babe = { version = "0.8.0-alpha.7" }
34+
sp-authority-discovery = { version = "2.0.0-alpha.7" }
35+
sp-consensus = { version = "0.8.0-alpha.7" }
36+
sc-consensus = { version = "0.8.0-alpha.7" }
37+
sc-finality-grandpa = { version = "0.8.0-alpha.7" }
38+
sp-finality-grandpa = { version = "2.0.0-alpha.7" }
39+
sc-client-api = { version = "2.0.0-alpha.7" }
40+
sp-runtime = { version = "2.0.0-alpha.7" }
41+
sc-basic-authorship = { version = "0.8.0-alpha.7" }
42+
sc-authority-discovery = { version = "0.8.0-alpha.7" }
43+
pallet-im-online = { version = "2.0.0-alpha.7" }
44+
45+
datdot-runtime = { version = "2.0.0-alpha.7", path = "../runtime" }
46+
47+
[build-dependencies]
48+
substrate-build-script-utils = { version = "2.0.0-alpha.7" }

β€Ždatdot-node/node/build.rsβ€Ž

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use substrate_build_script_utils::{generate_cargo_keys, rerun_if_git_head_changed};
2+
3+
fn main() {
4+
generate_cargo_keys();
5+
6+
rerun_if_git_head_changed();
7+
}
Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
use sp_core::{Pair, Public, sr25519};
2+
use datdot_runtime::{
3+
primitives::AccountId, primitives::Signature, primitives::Balance,
4+
BabeConfig, BalancesConfig, GenesisConfig, GrandpaConfig, ElectionsConfig,
5+
SudoConfig, SystemConfig, WASM_BINARY, IndicesConfig, ImOnlineConfig,
6+
AuthorityDiscoveryConfig, CouncilConfig, TechnicalCommitteeConfig,
7+
DemocracyConfig, SessionConfig, SessionKeys,
8+
constants::currency::*
9+
};
10+
use sp_consensus_babe::AuthorityId as BabeId;
11+
use sp_finality_grandpa::AuthorityId as GrandpaId;
12+
use pallet_im_online::sr25519::{AuthorityId as ImOnlineId};
13+
use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
14+
use sp_runtime::traits::{Verify, IdentifyAccount};
15+
use sc_service::ChainType;
16+
17+
// Note this is the URL for the telemetry server
18+
//const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";
19+
20+
/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.
21+
pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig>;
22+
23+
/// Helper function to generate a crypto pair from seed
24+
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
25+
TPublic::Pair::from_string(&format!("//{}", seed), None)
26+
.expect("static values are valid; qed")
27+
.public()
28+
}
29+
30+
type AccountPublic = <Signature as Verify>::Signer;
31+
32+
/// Helper function to generate an account ID from seed
33+
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId where
34+
AccountPublic: From<<TPublic::Pair as Pair>::Public>
35+
{
36+
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
37+
}
38+
39+
/// Helper function to generate stash, controller and session key from seed
40+
pub fn authority_keys_from_seed(seed: &str) -> (
41+
AccountId,
42+
AccountId,
43+
GrandpaId,
44+
BabeId,
45+
ImOnlineId,
46+
AuthorityDiscoveryId,
47+
) {
48+
(
49+
get_account_id_from_seed::<sr25519::Public>(&format!("{}//stash", seed)),
50+
get_account_id_from_seed::<sr25519::Public>(seed),
51+
get_from_seed::<GrandpaId>(seed),
52+
get_from_seed::<BabeId>(seed),
53+
get_from_seed::<ImOnlineId>(seed),
54+
get_from_seed::<AuthorityDiscoveryId>(seed),
55+
)
56+
}
57+
58+
pub fn development_config() -> ChainSpec {
59+
ChainSpec::from_genesis(
60+
"Development",
61+
"dev",
62+
ChainType::Development,
63+
|| testnet_genesis(
64+
vec![
65+
authority_keys_from_seed("Alice"),
66+
],
67+
get_account_id_from_seed::<sr25519::Public>("Alice"),
68+
Some(vec![
69+
get_account_id_from_seed::<sr25519::Public>("Alice"),
70+
get_account_id_from_seed::<sr25519::Public>("Bob"),
71+
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
72+
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
73+
]),
74+
true,
75+
),
76+
vec![],
77+
None,
78+
None,
79+
None,
80+
None,
81+
)
82+
}
83+
84+
pub fn local_testnet_config() -> ChainSpec {
85+
ChainSpec::from_genesis(
86+
"Local Testnet",
87+
"local_testnet",
88+
ChainType::Local,
89+
|| testnet_genesis(
90+
vec![
91+
authority_keys_from_seed("Alice"),
92+
authority_keys_from_seed("Bob"),
93+
],
94+
get_account_id_from_seed::<sr25519::Public>("Alice"),
95+
Some(vec![
96+
get_account_id_from_seed::<sr25519::Public>("Alice"),
97+
get_account_id_from_seed::<sr25519::Public>("Bob"),
98+
get_account_id_from_seed::<sr25519::Public>("Charlie"),
99+
get_account_id_from_seed::<sr25519::Public>("Dave"),
100+
get_account_id_from_seed::<sr25519::Public>("Eve"),
101+
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
102+
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
103+
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
104+
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
105+
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
106+
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
107+
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
108+
]),
109+
true,
110+
),
111+
vec![],
112+
None,
113+
None,
114+
None,
115+
None,
116+
)
117+
}
118+
119+
fn session_keys(
120+
grandpa: GrandpaId,
121+
babe: BabeId,
122+
im_online: ImOnlineId,
123+
authority_discovery: AuthorityDiscoveryId,
124+
) -> SessionKeys {
125+
SessionKeys { grandpa, babe, im_online, authority_discovery }
126+
}
127+
128+
fn testnet_genesis(
129+
initial_authorities: Vec<(
130+
AccountId,
131+
AccountId,
132+
GrandpaId,
133+
BabeId,
134+
ImOnlineId,
135+
AuthorityDiscoveryId,
136+
)>,
137+
root_key: AccountId,
138+
endowed_accounts: Option<Vec<AccountId>>,
139+
enable_println: bool,
140+
) -> GenesisConfig {
141+
let endowed_accounts: Vec<AccountId> = endowed_accounts.unwrap_or_else(|| {
142+
vec![
143+
get_account_id_from_seed::<sr25519::Public>("Alice"),
144+
get_account_id_from_seed::<sr25519::Public>("Bob"),
145+
get_account_id_from_seed::<sr25519::Public>("Charlie"),
146+
get_account_id_from_seed::<sr25519::Public>("Dave"),
147+
get_account_id_from_seed::<sr25519::Public>("Eve"),
148+
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
149+
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
150+
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
151+
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
152+
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
153+
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
154+
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
155+
]
156+
});
157+
let num_endowed_accounts = endowed_accounts.len();
158+
159+
const ENDOWMENT: Balance = 10_000_000 * DOLLARS;
160+
const STASH: Balance = 100 * DOLLARS;
161+
162+
GenesisConfig {
163+
frame_system: Some(SystemConfig {
164+
code: WASM_BINARY.to_vec(),
165+
changes_trie_config: Default::default(),
166+
}),
167+
pallet_balances: Some(BalancesConfig {
168+
balances: endowed_accounts.iter().cloned()
169+
.map(|k| (k, ENDOWMENT))
170+
.chain(initial_authorities.iter().map(|x| (x.0.clone(), STASH)))
171+
.collect(),
172+
}),
173+
pallet_indices: Some(IndicesConfig {
174+
indices: vec![],
175+
}),
176+
pallet_session: Some(SessionConfig {
177+
keys: initial_authorities.iter().map(|x| {
178+
(x.0.clone(), x.0.clone(), session_keys(
179+
x.2.clone(),
180+
x.3.clone(),
181+
x.4.clone(),
182+
x.5.clone(),
183+
))
184+
}).collect::<Vec<_>>(),
185+
}),
186+
pallet_democracy: Some(DemocracyConfig::default()),
187+
pallet_elections_phragmen: Some(ElectionsConfig {
188+
members: endowed_accounts.iter()
189+
.take((num_endowed_accounts + 1) / 2)
190+
.cloned()
191+
.map(|member| (member, STASH))
192+
.collect(),
193+
}),
194+
pallet_collective_Instance1: Some(CouncilConfig::default()),
195+
pallet_collective_Instance2: Some(TechnicalCommitteeConfig {
196+
members: endowed_accounts.iter()
197+
.take((num_endowed_accounts + 1) / 2)
198+
.cloned()
199+
.collect(),
200+
phantom: Default::default(),
201+
}),
202+
pallet_sudo: Some(SudoConfig {
203+
key: root_key,
204+
}),
205+
pallet_babe: Some(BabeConfig {
206+
authorities: vec![],
207+
}),
208+
pallet_im_online: Some(ImOnlineConfig {
209+
keys: vec![],
210+
}),
211+
pallet_authority_discovery: Some(AuthorityDiscoveryConfig {
212+
keys: vec![],
213+
}),
214+
pallet_grandpa: Some(GrandpaConfig {
215+
authorities: vec![],
216+
}),
217+
pallet_membership_Instance1: Some(Default::default()),
218+
}
219+
}

β€Ždatdot-node/node/src/cli.rsβ€Ž

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use sc_cli::{RunCmd, Subcommand};
2+
use structopt::StructOpt;
3+
4+
#[derive(Debug, StructOpt)]
5+
pub struct Cli {
6+
#[structopt(subcommand)]
7+
pub subcommand: Option<Subcommand>,
8+
9+
#[structopt(flatten)]
10+
pub run: RunCmd,
11+
}

0 commit comments

Comments
Β (0)