Skip to content

Commit d76fd10

Browse files
authored
Merge pull request #58 from paritytech/node-template-archive
Bumps Version to 0.3.1, Introduce Node-Template-Archive
2 parents c3a5442 + bd6a244 commit d76fd10

File tree

16 files changed

+1334
-726
lines changed

16 files changed

+1334
-726
lines changed

Cargo.lock

Lines changed: 669 additions & 707 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
members = [
33
"archive",
44
"kusama-archive",
5+
"node-template-archive",
56
]

archive/Cargo.toml

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "substrate-archive"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
authors = ["Andrew Plaza <andrew.plaza@parity.io>"]
55
edition = "2018"
66

@@ -38,22 +38,22 @@ kvdb-rocksdb = "0.8"
3838
parity-util-mem = "0.6.1"
3939
codec = { package = "parity-scale-codec", version = "1.2.0", default-features = false, features = ["derive", "full"] }
4040

41+
4142
# Substrate
42-
sp-database = { git = "https://github.com/paritytech/substrate", branch = "master", package="sp-database" }
43-
sc-service = { git = "https://github.com/paritytech/substrate", branch = "master", package = "sc-service" }
44-
sc-client-db = { git = "https://github.com/paritytech/substrate", branch = "master", package = "sc-client-db" }
45-
sp-storage = { git = "https://github.com/paritytech/substrate", branch = "master", package = "sp-storage" }
46-
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", package = "sp-runtime" }
47-
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "master", package = "sc-client-api" }
48-
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "master", package = "sp-blockchain" }
49-
substrate-rpc-primitives = { git = "https://github.com/paritytech/substrate", branch = "master", package = "sp-rpc" }
50-
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", package = "sp-core" }
51-
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", package = "sp-api" }
52-
runtime-version = { git = "https://github.com/paritytech/substrate", branch = "master", package = "sp-version" }
53-
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "master", package = "sc-executor" }
54-
sc-transaction-graph = { git = "https://github.com/paritytech/substrate", branch = "master", package = "sc-transaction-graph" }
55-
sc-chain-spec = { git = "https://github.com/paritytech/substrate", branch = "master", package = "sc-chain-spec" }
56-
frame-system = { git = "https://github.com/paritytech/substrate", branch = "master", package = "frame-system" }
43+
sp-database = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master", version = "2.0.0-rc2", package = "sp-database" }
44+
sc-service = { git = "https://github.com/paritytech/substrate", branch = "master", version = "0.8.0-rc2", package = "sc-service" }
45+
sc-client-db = { git = "https://github.com/paritytech/substrate", branch = "master", version = "0.8.0-rc2", package = "sc-client-db" }
46+
sp-storage = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master", version = "2.0.0-rc2", package = "sp-storage" }
47+
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master", version = "2.0.0-rc2", package = "sp-runtime" }
48+
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "master", version = "2.0.0-rc2", package = "sc-client-api" }
49+
sp-blockchain = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master", version = "2.0.0-rc2", package = "sp-blockchain" }
50+
51+
substrate-rpc-primitives = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, version = "2.0.0-rc2", package = "sp-rpc" }
52+
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, version = "2.0.0-rc2", package = "sp-core" }
53+
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, version = "2.0.0-rc2", package = "sp-api" }
54+
runtime-version = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, version = "2.0.0-rc2", package = "sp-version" }
55+
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, version = "0.8.0-rc2", package = "sc-executor" }
56+
frame-system = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, version = "2.0.0-rc2", package = "frame-system" }
5757

5858
[dev-dependencies]
5959
# desub-extras = { path = "../desub/extras/", package="desub-extras", features = ["polkadot"] }
@@ -62,4 +62,14 @@ pretty_env_logger = "0.4.0"
6262

6363

6464
[features]
65+
default = ["std"]
66+
std = [
67+
"sp-storage/std",
68+
"sp-runtime/std",
69+
"sp-core/std",
70+
"sp-api/std",
71+
"runtime-version/std",
72+
"sc-executor/std",
73+
"frame-system/std"
74+
]
6575
logging = ["chrono", "fern"]

archive/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ pub use self::actors::Archive;
3939
pub use sp_storage::StorageKey;
4040
pub use sp_core::twox_128;
4141
pub use sp_blockchain::Error as BlockchainError;
42+
pub use sp_runtime::MultiSignature;
4243
pub mod chain_traits {
4344
//! Traits defining functions on the client needed for indexing
4445
pub use sc_client_api::{backend::StorageProvider, client::BlockBackend, UsageProvider};
4546
pub use sp_blockchain::{HeaderBackend, HeaderMetadata};
46-
pub use sp_runtime::traits::{BlakeTwo256, Block};
47+
pub use sp_runtime::traits::{BlakeTwo256, Block, Verify, IdentifyAccount};
4748
}

kusama-archive/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pretty_env_logger = "0.4.0"
1717
anyhow = "1.0.31"
1818
serde = "1.0.110"
1919
sqlx = { version = "0.3.5", features = ["postgres"] }
20-
async-std = "1.6.0"
20+
async-std = "1.5.0"
2121
async-ctrlc = "1.1.0"
2222
indicatif = "0.14.0"
2323

kusama-archive/src/cli_opts.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ impl CliOpts {
3636
};
3737
let file = matches.value_of("config").expect("Config is a required value");
3838

39+
3940
CliOpts {
4041
file: PathBuf::from(file), log_level
4142
}
4243
}
43-
}
44+
}

node-template-archive/Cargo.toml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
[package]
2+
name = "node-template-archive"
3+
version = "0.1.0"
4+
authors = ["Andrew Plaza <aplaza@liquidthink.net>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
10+
substrate-archive = { version = "0.3.1", path = "../archive", default-features = false, features = ["logging"] }
11+
node-template-runtime = { git = "https://github.com/paritytech/substrate", branch="master", default-features = false, package = "node-template-runtime" }
12+
clap = { version = "2.33.1", features = ["yaml", "suggestions", "color"] }
13+
toml = "0.5"
14+
futures = "0.3.5"
15+
log = "0.4.8"
16+
pretty_env_logger = "0.4.0"
17+
anyhow = "1.0.31"
18+
serde = "1.0.110"
19+
sqlx = { version = "0.3.5", features = ["postgres"] }
20+
async-std = "1.5.0"
21+
async-ctrlc = "1.1.0"
22+
indicatif = "0.14.0"
23+
24+
sp-consensus-aura = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, version = "0.8.0-rc2", package = "sp-consensus-aura" }
25+
sp-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, version = "2.0.0-rc2", package = "sp-finality-grandpa" }
26+
# sc-finality-grandpa = { version = "0.8.0-rc2" }
27+
28+
sc-service = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, version = "0.8.0-rc2", package = "sc-service" }
29+
# sp-runtime = { version = "2.0.0-rc2", package = "sp-runtime" }
30+
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, version = "2.0.0-rc2", package = "sp-core" }
31+
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, version = "0.8.0-rc2", package = "sc-executor" }
32+
33+
34+
[features]
35+
default = ["std"]
36+
std = [
37+
"substrate-archive/std",
38+
"node-template-runtime/std",
39+
"sp-consensus-aura/std",
40+
"sp-finality-grandpa/std",
41+
"sp-core/std",
42+
"sc-executor/std"
43+
]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Must be an absolute path to db (no ~/)
2+
db_path = "/home/insipx/.local/share/node-template/chains/dev/db"
3+
4+
# Can be set by exporting environment variable "DATABASE_URL" too
5+
psql_url = "postgres://archive:default@localhost/archive"
6+
7+
[[modules]]
8+
name = "System"
9+
keys = [
10+
"Events",
11+
"Account"
12+
]
13+
14+
[[modules]]
15+
name = "Democracy"
16+
keys = [
17+
"PublicPropCount",
18+
"PublicProps"
19+
]
20+

node-template-archive/src/archive.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright 2018-2019 Parity Technologies (UK) Ltd.
2+
// This file is part of substrate-archive.
3+
4+
// substrate-archive is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
9+
// substrate-archive is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
14+
// You should have received a copy of the GNU General Public License
15+
// along with substrate-archive. If not, see <http://www.gnu.org/licenses/>.
16+
17+
use node_template_runtime::{self as runtime, opaque::Block};
18+
use sc_executor::native_executor_instance;
19+
use substrate_archive::{Archive, backend::{self, ChainAccess}, chain_traits::HeaderBackend as _};
20+
use std::sync::Arc;
21+
use anyhow::Result;
22+
23+
native_executor_instance!(
24+
pub Executor,
25+
node_template_runtime::api::dispatch,
26+
node_template_runtime::native_version
27+
);
28+
29+
pub fn run_archive(config: super::config::Config) -> Result<(Arc<impl ChainAccess<Block>>, Archive)>
30+
{
31+
let db = backend::open_database::<Block>(config.db_path(), 8192).unwrap();
32+
33+
// let spec = polkadot_service::chain_spec::kusama_config().unwrap();
34+
let spec = config.cli().chain_spec.clone();
35+
let client =
36+
backend::client::<Block, runtime::RuntimeApi, Executor, _>(
37+
db, spec,
38+
)
39+
.unwrap();
40+
41+
let info = client.info();
42+
println!("{:?}", info);
43+
44+
45+
// TODO: use a better error-handling (this-error) crate with substrate-archive
46+
// (failure is deprecated)
47+
// run until we want to exit (Ctrl-C)
48+
let archive = Archive::init::<runtime::Runtime, _>(
49+
client.clone(),
50+
"ws://127.0.0.1:9944".to_string(),
51+
config.keys(),
52+
config.psql_url()
53+
).expect("Init Failed");
54+
55+
56+
Ok((
57+
client, archive
58+
))
59+
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
use sp_core::{Pair, Public, sr25519};
2+
use node_template_runtime::{
3+
AuraConfig, BalancesConfig, GenesisConfig, GrandpaConfig,
4+
SudoConfig, SystemConfig, WASM_BINARY
5+
};
6+
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
7+
use sp_finality_grandpa::AuthorityId as GrandpaId;
8+
// use sp_runtime::traits::{Verify, IdentifyAccount};
9+
use substrate_archive::{MultiSignature, chain_traits::{Verify, IdentifyAccount}};
10+
use sc_service::ChainType;
11+
12+
// Note this is the URL for the telemetry server
13+
//const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";
14+
15+
/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.
16+
pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig>;
17+
18+
/// Helper function to generate a crypto pair from seed
19+
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
20+
TPublic::Pair::from_string(&format!("//{}", seed), None)
21+
.expect("static values are valid; qed")
22+
.public()
23+
}
24+
25+
/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.
26+
pub type Signature = MultiSignature;
27+
28+
/// Some way of identifying an account on the chain. We intentionally make it equivalent
29+
/// to the public key of our transaction signing scheme.
30+
pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
31+
32+
type AccountPublic = <Signature as Verify>::Signer;
33+
34+
/// Helper function to generate an account ID from seed
35+
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId where
36+
AccountPublic: From<<TPublic::Pair as Pair>::Public>
37+
{
38+
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
39+
}
40+
41+
/// Helper function to generate an authority key for Aura
42+
pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) {
43+
(
44+
get_from_seed::<AuraId>(s),
45+
get_from_seed::<GrandpaId>(s),
46+
)
47+
}
48+
49+
pub fn development_config() -> ChainSpec {
50+
ChainSpec::from_genesis(
51+
"Development",
52+
"dev",
53+
ChainType::Development,
54+
|| testnet_genesis(
55+
vec![
56+
authority_keys_from_seed("Alice"),
57+
],
58+
get_account_id_from_seed::<sr25519::Public>("Alice"),
59+
vec![
60+
get_account_id_from_seed::<sr25519::Public>("Alice"),
61+
get_account_id_from_seed::<sr25519::Public>("Bob"),
62+
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
63+
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
64+
],
65+
true,
66+
),
67+
vec![],
68+
None,
69+
None,
70+
None,
71+
None,
72+
)
73+
}
74+
75+
pub fn local_testnet_config() -> ChainSpec {
76+
ChainSpec::from_genesis(
77+
"Local Testnet",
78+
"local_testnet",
79+
ChainType::Local,
80+
|| testnet_genesis(
81+
vec![
82+
authority_keys_from_seed("Alice"),
83+
authority_keys_from_seed("Bob"),
84+
],
85+
get_account_id_from_seed::<sr25519::Public>("Alice"),
86+
vec![
87+
get_account_id_from_seed::<sr25519::Public>("Alice"),
88+
get_account_id_from_seed::<sr25519::Public>("Bob"),
89+
get_account_id_from_seed::<sr25519::Public>("Charlie"),
90+
get_account_id_from_seed::<sr25519::Public>("Dave"),
91+
get_account_id_from_seed::<sr25519::Public>("Eve"),
92+
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
93+
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
94+
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
95+
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
96+
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
97+
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
98+
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
99+
],
100+
true,
101+
),
102+
vec![],
103+
None,
104+
None,
105+
None,
106+
None,
107+
)
108+
}
109+
110+
fn testnet_genesis(initial_authorities: Vec<(AuraId, GrandpaId)>,
111+
root_key: AccountId,
112+
endowed_accounts: Vec<AccountId>,
113+
_enable_println: bool) -> GenesisConfig {
114+
GenesisConfig {
115+
system: Some(SystemConfig {
116+
code: WASM_BINARY.to_vec(),
117+
changes_trie_config: Default::default(),
118+
}),
119+
balances: Some(BalancesConfig {
120+
balances: endowed_accounts.iter().cloned().map(|k|(k, 1 << 60)).collect(),
121+
}),
122+
aura: Some(AuraConfig {
123+
authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(),
124+
}),
125+
grandpa: Some(GrandpaConfig {
126+
authorities: initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect(),
127+
}),
128+
sudo: Some(SudoConfig {
129+
key: root_key,
130+
}),
131+
}
132+
}

0 commit comments

Comments
 (0)