Unverified Commit 0eed4b01 authored by Sergey Pepyakin's avatar Sergey Pepyakin Committed by GitHub
Browse files

Register ReadRuntimeVersionExt (#3045)

* Register ReadRuntimeVersionExt

* Update Substrate

This includes the fix of compilation for macOS platforms.
parent bb2ac8a7
Pipeline #138657 passed with stages
in 33 minutes and 8 seconds
......@@ -64,6 +64,7 @@ pub fn execute(
let mut extensions = sp_externalities::Extensions::new();
extensions.register(sp_core::traits::TaskExecutorExt::new(spawner));
extensions.register(sp_core::traits::ReadRuntimeVersionExt::new(ReadRuntimeVersion));
let mut ext = ValidationExternalities(extensions);
......@@ -244,3 +245,26 @@ impl sp_core::traits::SpawnNamed for TaskExecutor {
self.0.spawn_ok(future);
}
}
struct ReadRuntimeVersion;
impl sp_core::traits::ReadRuntimeVersion for ReadRuntimeVersion {
fn read_runtime_version(
&self,
wasm_code: &[u8],
_ext: &mut dyn sp_externalities::Externalities,
) -> Result<Vec<u8>, String> {
let blob = RuntimeBlob::uncompress_if_needed(wasm_code)
.map_err(|e| format!("Failed to read the PVF runtime blob: {:?}", e))?;
match sc_executor::read_embedded_version(&blob)
.map_err(|e| format!("Failed to read the static section from the PVF blob: {:?}", e))?
{
Some(version) => {
use parity_scale_codec::Encode;
Ok(version.encode())
},
None => Err(format!("runtime version section is not found")),
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment