Function gstd::msg::reply

source ·
pub fn reply<E: Encode>(payload: E, value: u128) -> Result<MessageId>
Expand description

Send a new message as a reply to the message being processed.

Some programs can reply to other programs, e.g., check another program’s state and use it as a parameter for its business logic.

This function allows sending such replies, which are similar to standard messages in terms of payload and different only in how the message processing is handled by a dedicated program function called handle_reply.

The first argument is the encodable payload. The second argument is the value to be transferred from the current program account to the reply message target account.

Reply message transactions will be posted after processing is finished, similar to the standard message-sending function (e.g. send).

§Examples

use gstd::{msg, prelude::*};

#[derive(Encode)]
#[codec(crate = gstd::codec)]
struct Reply {
    a: i32,
    b: Option<bool>,
}

#[no_mangle]
extern "C" fn handle() {
    let payload = Reply {
        a: 42,
        b: Some(true),
    };

    msg::reply(payload, 0).expect("Unable to reply");
}

§See also

  • reply_bytes function sends a reply with an encoded payload.
  • reply_push, reply_commit functions allow forming a reply message in parts.
  • send function sends a new message to the program or user.