Function gstd::prog::create_program_bytes_delayed

source ·
pub fn create_program_bytes_delayed(
    code_id: CodeId,
    salt: impl AsRef<[u8]>,
    payload: impl AsRef<[u8]>,
    value: u128,
    delay: u32,
) -> Result<(MessageId, ActorId)>
Expand description

Same as create_program_bytes, but creates a new program after the delay expressed in block count.

§Examples

Create a new program from the provided code identifier after 100 blocks and send a message to it after 200 blocks:

use gstd::{msg, prog, CodeId};

#[no_mangle]
extern "C" fn handle() {
    let code_id: CodeId = msg::load().expect("Unable to load");
    let (init_message_id, new_program_id) =
        prog::create_program_bytes_delayed(code_id, "salt", b"INIT", 0, 100)
            .expect("Unable to create a program");
    msg::send_bytes_delayed(new_program_id, b"PING", 0, 200).expect("Unable to send");
}