Function gstd::msg::send_bytes_from_reservation
source · pub fn send_bytes_from_reservation<T: AsRef<[u8]>>(
id: ReservationId,
program: ActorId,
payload: T,
value: u128,
) -> Result<MessageId>
Expand description
Same as send_bytes
, but it spends gas from a reservation instead of
borrowing it from the gas limit provided with the incoming message.
The first argument is the reservation identifier ReservationId
obtained
by calling the corresponding API. The second argument is the address of the
target account (ActorId
). The third argument is the payload buffer.
Finally, the last argument is the value to be transferred from the current
program account to the message target account.
§Examples
Send a message with value to the sender’s address:
use gstd::{msg, prelude::*, ReservationId};
#[no_mangle]
extern "C" fn handle() {
// Reserve 5 million of gas for 100 blocks
let reservation_id = ReservationId::reserve(5_000_000, 100).expect("Unable to reserve");
// Receiver id is the message source
let actor_id = msg::source();
msg::send_from_reservation(reservation_id, actor_id, b"HELLO", 42).expect("Unable to send");
}
§See also
reply_bytes_from_reservation
function sends a reply to the program or user by using gas from a reservation.MessageHandle::init
,MessageHandle::push
, andMessageHandle::commit
functions allow forming a message to send in parts.