fn create_custom_deployer(payload: &[u8]) -> Result<Module, ModuleError> {
    // The standard deployer code, which expects a 32 bit little endian as the trailing content
    // immediately following the payload, placed in a custom section.
    let code = deployer_code();

    // This is the pre-written deployer code.
    let mut module: Module = parity_wasm::deserialize_buffer(&code)?;

    // Re-write memory to pre-allocate enough for code size
    let memory_initial = (payload.len() as u32 / 65536) + 1;
    let mem_type = parity_wasm::elements::MemoryType::new(memory_initial, None, false);
    module
        .memory_section_mut()
        // This would be an internal error (.e.g the the deployer code above has no memory section)
        .expect("failed to get memory section")
        .entries_mut()[0] = mem_type;

    // Prepare payload (append length).
    let mut custom_payload = payload.to_vec();
    custom_payload.write_i32::<LittleEndian>(payload.len() as i32)?;

    // Prepare and append custom section.
    let custom = CustomSection::new("deployer".to_string(), custom_payload);

    module
        .sections_mut()
        .push(parity_wasm::elements::Section::Custom(custom));

    Ok(module)
}
/// Returns a module which contains the deployable bytecode as a custom section.
Returns a module which contains the deployable bytecode as a custom section.
Returns a module which contains the deployable bytecode as a custom section .
fn create_custom_deployer(payload: &[u8]) -> Result<Module, ModuleError> {
    // The standard deployer code, which expects a 32 bit little endian as the trailing content
    // immediately following the payload, placed in a custom section.
    let code = deployer_code();
    // This is the pre-written deployer code.
    let mut module: Module = parity_wasm::deserialize_buffer(&code)?;
    // Re-write memory to pre-allocate enough for code size
    let memory_initial = (payload.len() as u32 / 65536) + 1;
    let mem_type = parity_wasm::elements::MemoryType::new(memory_initial, None, false);
    module
        .memory_section_mut()
        // This would be an internal error (.e.g the the deployer code above has no memory section)
        .expect("failed to get memory section")
        .entries_mut()[0] = mem_type;
    // Prepare payload (append length).
    let mut custom_payload = payload.to_vec();
    custom_payload.write_i32::<LittleEndian>(payload.len() as i32)?;
    // Prepare and append custom section.
    let custom = CustomSection::new("deployer".to_string(), custom_payload);
    module
        .sections_mut()
        .push(parity_wasm::elements::Section::Custom(custom));
    Ok(module)
}
fn create_custom_deployer ( payload : & [ u8 ] ) -> Result < Module , ModuleError > { // The standard deployer code, which expects a 32 bit little endian as the trailing content // immediately following the payload, placed in a custom section. let code = deployer_code ( ) ; // This is the pre-written deployer code. let mut module : Module = parity_wasm :: deserialize_buffer ( & code ) ? ; // Re-write memory to pre-allocate enough for code size let memory_initial = ( payload . len ( ) as u32 / 65536 ) + 1 ; let mem_type = parity_wasm :: elements :: MemoryType :: new ( memory_initial , None , false ) ; module . memory_section_mut ( ) // This would be an internal error (.e.g the the deployer code above has no memory section) . expect ( " " ) . entries_mut ( ) [ 0 ] = mem_type ; // Prepare payload (append length). let mut custom_payload = payload . to_vec ( ) ; custom_payload . write_i32 :: < LittleEndian > ( payload . len ( ) as i32 ) ? ; // Prepare and append custom section. let custom = CustomSection :: new ( " " . to_string ( ) , custom_payload ) ; module . sections_mut ( ) . push ( parity_wasm :: elements :: Section :: Custom ( custom ) ) ; Ok ( module ) }
Returns a module which contains the deployable bytecode as a custom section.
Returns a module which contains the deployable bytecode as a custom section .
payload
&[u8]