Skip to content

Commit

Permalink
rpc: add rpc v2 chainSpec to polkadot (paritytech#2859)
Browse files Browse the repository at this point in the history
The [chainSpec RPC API from the v2
spec](https://paritytech.github.io/json-rpc-interface-spec/api/chainSpec.html)
was only added to substrate-node and should be added to polkadot as well

/cc @lexnv
  • Loading branch information
niklasad1 committed Jan 8, 2024
1 parent fd377af commit f282059
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 12 deletions.
7 changes: 7 additions & 0 deletions substrate/bin/node-template/node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,12 @@ where
// to call into the runtime.
// `module.merge(YourRpcTrait::into_rpc(YourRpcStruct::new(ReferenceToClient, ...)))?;`

// You probably want to enable the `rpc v2 chainSpec` API as well
//
// let chain_name = chain_spec.name().to_string();
// let genesis_hash = client.block_hash(0).ok().flatten().expect("Genesis block exists; qed");
// let properties = chain_spec.properties();
// module.merge(ChainSpec::new(chain_name, genesis_hash, properties).into_rpc())?;

Ok(module)
}
2 changes: 1 addition & 1 deletion substrate/client/consensus/beefy/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ where
// The block is imported as part of some chain sync.
// The voter doesn't need to process it now.
// It will be detected and processed as part of the voter state init.
return Ok(inner_import_result);
return Ok(inner_import_result)
},
}

Expand Down
2 changes: 1 addition & 1 deletion substrate/client/consensus/beefy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ where
header =
wait_for_parent_header(backend.blockchain(), header, HEADER_SYNC_DELAY).await?;
}
return Ok(state);
return Ok(state)
}

// No valid voter-state persisted, re-initialize from pallet genesis.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ impl Notifications {
peerset_rejected,
incoming_index,
};
return self.report_reject(index).map_or((), |_| ());
return self.report_reject(index).map_or((), |_| ())
}

trace!(
Expand Down
6 changes: 3 additions & 3 deletions substrate/frame/contracts/fixtures/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fn collect_entries(contracts_dir: &Path, out_dir: &Path) -> Vec<Entry> {
.filter_map(|file| {
let path = file.expect("file exists; qed").path();
if path.extension().map_or(true, |ext| ext != "rs") {
return None;
return None
}

let entry = Entry::new(path);
Expand Down Expand Up @@ -307,7 +307,7 @@ fn find_workspace_root(current_dir: &Path) -> Option<PathBuf> {
let cargo_toml_contents =
std::fs::read_to_string(current_dir.join("Cargo.toml")).ok()?;
if cargo_toml_contents.contains("[workspace]") {
return Some(current_dir);
return Some(current_dir)
}
}

Expand All @@ -325,7 +325,7 @@ fn main() -> Result<()> {

let entries = collect_entries(&contracts_dir, &out_dir);
if entries.is_empty() {
return Ok(());
return Ok(())
}

let tmp_dir = tempfile::tempdir()?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn expand_outer_task(
let mut task_paths = Vec::new();
for decl in pallet_decls {
if decl.find_part("Task").is_none() {
continue;
continue
}

let variant_name = &decl.name;
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/system/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ fn last_runtime_upgrade_spec_version_usage() {
// a runtime upgrade in the pipeline of being applied, you should use the spec version
// of this upgrade.
if System::last_runtime_upgrade_spec_version() > 1337 {
return Weight::zero();
return Weight::zero()
}

// Do the migration.
Expand Down
2 changes: 1 addition & 1 deletion substrate/primitives/core/src/address_uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl<'a> AddressUri<'a> {
Error::in_pass(initial_input, initial_input_len - input.len())
} else {
Error::in_phrase(initial_input, initial_input_len - input.len())
});
})
}
}

Expand Down
4 changes: 2 additions & 2 deletions substrate/primitives/core/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ impl<T: Sized + AsMut<[u8]> + AsRef<[u8]> + Public + Derive> Ss58Codec for T {
fn from_string(s: &str) -> Result<Self, PublicError> {
let cap = AddressUri::parse(s)?;
if cap.pass.is_some() {
return Err(PublicError::PasswordNotAllowed);
return Err(PublicError::PasswordNotAllowed)
}
let s = cap.phrase.unwrap_or(DEV_ADDRESS);
let addr = if let Some(stripped) = s.strip_prefix("0x") {
Expand All @@ -454,7 +454,7 @@ impl<T: Sized + AsMut<[u8]> + AsRef<[u8]> + Public + Derive> Ss58Codec for T {
fn from_string_with_version(s: &str) -> Result<(Self, Ss58AddressFormat), PublicError> {
let cap = AddressUri::parse(s)?;
if cap.pass.is_some() {
return Err(PublicError::PasswordNotAllowed);
return Err(PublicError::PasswordNotAllowed)
}
let (addr, v) = Self::from_ss58check_with_version(cap.phrase.unwrap_or(DEV_ADDRESS))?;
if cap.paths.is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion substrate/utils/wasm-builder/src/wasm_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ fn generate_rerun_if_changed_instructions(
while let Some(dependency) = dependencies.pop() {
// Ignore all dev dependencies
if dependency.kind == DependencyKind::Development {
continue;
continue
}

let path_or_git_dep =
Expand Down

0 comments on commit f282059

Please sign in to comment.