Register ReadRuntimeVersionExt (#3045)

* Register ReadRuntimeVersionExt

* Update Substrate

This includes the fix of compilation for macOS platforms.
This commit is contained in:
Sergei Shulepov
2021-05-19 12:33:33 +02:00
committed by GitHub
parent fe97c3a3a2
commit 46e5316a77
@@ -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")),
}
}
}