I have a CLI tool that gets a WebAssembly runtime file:
let validation_code_content = fs::read_to_string(path_validation_code)
.expect("Should have been able to read the validation code file");
If I print validation_code_content
I can see the content is correct. Now I want to send this file into an extrinsic (e.g: register), which needs to be converted into the [ValidationCode][3]
struct:
/// Parachain validation code.
#[derive(
PartialEq,
Eq,
Clone,
Encode,
Decode,
RuntimeDebug,
derive_more::From,
TypeInfo,
Serialize,
Deserialize,
)]
#[cfg_attr(feature = "std", derive(Hash))]
pub struct ValidationCode(#[serde(with = "bytes")] pub Vec<u8>);
I can see in the tests on the pallet that I need a vector of bytes:
fn test_validation_code(size: usize) -> ValidationCode {
let validation_code = vec![0u8; size as usize];
ValidationCode(validation_code)
}
So my approach is convert the String in the vector of bytes and cast it to ValidationCode:
let validation_code = validation_code_content.into_bytes()
let call = Call::Registrar(RegistrarCall::register {
id: RococoId(para_id),
genesis_head: HeadData(genesis_head),
validation_code: ValidationCode(validation_code),
});
The code compiles but the extrinsic fails because something is wrong with the validation code. Did I lose data when I am doing the conversion?
fs::read
to directly read it as binary data.