Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
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 core/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jsonrpc-pubsub = { git="https://github.com/paritytech/jsonrpc.git" }
log = "0.4"
parking_lot = "0.4"
parity-codec = "2.1"
serde_json = "1.0"
substrate-client = { path = "../client" }
substrate-executor = { path = "../executor" }
substrate-transaction-pool = { path = "../transaction-pool" }
Expand Down
4 changes: 4 additions & 0 deletions core/rpc/src/system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,9 @@ build_rpc_trait! {
/// Get the chain's type. Given as a string identifier.
#[rpc(name = "system_chain")]
fn system_chain(&self) -> Result<String>;

/// Get a custom set of properties as a JSON object, defined in the chain spec.
#[rpc(name = "system_properties")]
fn system_properties(&self) -> Result<serde_json::map::Map<String, serde_json::Value>>;
}
}
11 changes: 11 additions & 0 deletions core/rpc/src/system/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ impl SystemApi for () {
fn system_chain(&self) -> Result<String> {
Ok("testchain".into())
}
fn system_properties(&self) -> Result<serde_json::map::Map<String, serde_json::Value>> {
Ok(serde_json::map::Map::new())
}
}

#[test]
Expand All @@ -52,3 +55,11 @@ fn system_chain_works() {
"testchain".to_owned()
);
}

#[test]
fn system_properties_works() {
assert_eq!(
SystemApi::system_properties(&()).unwrap(),
serde_json::map::Map::new()
);
}
11 changes: 11 additions & 0 deletions core/service/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,12 @@ struct ChainSpecFile {
pub telemetry_url: Option<String>,
pub protocol_id: Option<String>,
pub consensus_engine: Option<String>,
pub properties: Option<Properties>,
}

/// Arbitrary properties defined in chain spec as a JSON object
pub type Properties = json::map::Map<String, json::Value>;

/// A configuration of a chain. Can be used to build a genesis block.
pub struct ChainSpec<G: RuntimeGenesis> {
spec: ChainSpecFile,
Expand Down Expand Up @@ -130,6 +134,11 @@ impl<G: RuntimeGenesis> ChainSpec<G> {
self.spec.consensus_engine.as_ref().map(String::as_str)
}

pub fn properties(&self) -> Properties {
// Return an empty JSON object if 'properties' not defined in config
self.spec.properties.as_ref().unwrap_or(&json::map::Map::new()).clone()
}

/// Parse json content into a `ChainSpec`
pub fn from_embedded(json: &'static [u8]) -> Result<Self, String> {
let spec = json::from_slice(json).map_err(|e| format!("Error parsing spec file: {}", e))?;
Expand Down Expand Up @@ -158,6 +167,7 @@ impl<G: RuntimeGenesis> ChainSpec<G> {
telemetry_url: Option<&str>,
protocol_id: Option<&str>,
consensus_engine: Option<&str>,
properties: Option<Properties>,
) -> Self
{
let spec = ChainSpecFile {
Expand All @@ -167,6 +177,7 @@ impl<G: RuntimeGenesis> ChainSpec<G> {
telemetry_url: telemetry_url.map(str::to_owned),
protocol_id: protocol_id.map(str::to_owned),
consensus_engine: consensus_engine.map(str::to_owned),
properties,
};
ChainSpec {
spec,
Expand Down
8 changes: 7 additions & 1 deletion core/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ use codec::{Encode, Decode};

pub use self::error::{ErrorKind, Error};
pub use config::{Configuration, Roles, PruningMode};
pub use chain_spec::ChainSpec;
pub use chain_spec::{ChainSpec, Properties};
pub use transaction_pool::txpool::{self, Pool as TransactionPool, Options as TransactionPoolOptions, ChainApi, IntoPoolError};
pub use client::ExecutionStrategy;

Expand Down Expand Up @@ -236,6 +236,7 @@ impl<Components> Service<Components>
// RPC
let rpc_config = RpcConfig {
chain_name: config.chain_spec.name().to_string(),
properties: config.chain_spec.properties().clone(),
impl_name: config.impl_name,
impl_version: config.impl_version,
};
Expand Down Expand Up @@ -379,6 +380,7 @@ fn maybe_start_server<T, F>(address: Option<SocketAddr>, start: F) -> Result<Opt
#[derive(Clone)]
struct RpcConfig {
chain_name: String,
properties: Properties,
impl_name: &'static str,
impl_version: &'static str,
}
Expand All @@ -395,6 +397,10 @@ impl substrate_rpc::system::SystemApi for RpcConfig {
fn system_chain(&self) -> substrate_rpc::system::error::Result<String> {
Ok(self.chain_name.clone())
}

fn system_properties(&self) -> substrate_rpc::system::error::Result<Properties> {
Ok(self.properties.clone())
}
}

/// Transaction pool adapter.
Expand Down
3 changes: 3 additions & 0 deletions node/cli/res/bbq-birch.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"name": "BBQ Birch",
"id": "bbq-birch",
"properties": {
"tokenSymbol": "BBQ"
},
"telemetryUrl": "wss://telemetry.polkadot.io/submit/",
"protocolId": null,
"bootNodes": [
Expand Down
7 changes: 4 additions & 3 deletions node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ pub fn staging_testnet_config() -> ChainSpec {
Some(STAGING_TELEMETRY_URL.into()),
None,
None,
None,
)
}

Expand Down Expand Up @@ -240,7 +241,7 @@ fn development_config_genesis() -> GenesisConfig {

/// Development config (single validator Alice)
pub fn development_config() -> ChainSpec {
ChainSpec::from_genesis("Development", "development", development_config_genesis, vec![], None, None, None)
ChainSpec::from_genesis("Development", "development", development_config_genesis, vec![], None, None, None, None)
}

fn local_testnet_genesis() -> GenesisConfig {
Expand All @@ -254,7 +255,7 @@ fn local_testnet_genesis() -> GenesisConfig {

/// Local testnet config (multivalidator Alice + Bob)
pub fn local_testnet_config() -> ChainSpec {
ChainSpec::from_genesis("Local Testnet", "local_testnet", local_testnet_genesis, vec![], None, None, None)
ChainSpec::from_genesis("Local Testnet", "local_testnet", local_testnet_genesis, vec![], None, None, None, None)
}

#[cfg(test)]
Expand All @@ -271,7 +272,7 @@ mod tests {

/// Local testnet config (multivalidator Alice + Bob)
pub fn integration_test_config() -> ChainSpec {
ChainSpec::from_genesis("Integration Test", "test", local_testnet_genesis_instant, vec![], None, None, None)
ChainSpec::from_genesis("Integration Test", "test", local_testnet_genesis_instant, vec![], None, None, None, None)
}

#[test]
Expand Down