Mailbox
When the program sends a message to the user (e.g., using the msg::send
function), this message is placed in the user's mailbox. Actually, the mailbox is a dedicated storage that keeps a message received from a program.
The user can detect a message received by subscribing to the UserMessageSent
event. It's important to note that the reply (sent using the msg::reply
function) doesn't go to the mailbox, it just generates an event.
Messages in the Mainlbox are shown in the Gear Idea application: https://idea.gear-tech.io/mailbox
A message is charged for being in the mailbox. Therefore, a message can be in the mailbox for a limited time.
Let's explore possible user reactions to the mailbox's message.
User sends a reply to the message
WhenTthe program sends a message to the user and waits for their reply, user can respond using a send_reply
extrinsic. The value linked to the message gets transferred to the user's account, removing the message from the mailbox. Simultaneously, the new reply message gets added to the message queue.
User claims value from a message in the mailbox
If a message in the mailbox has an associated value, the user can claim it using a claim_value
extrinsic. Value is transferred to the user's account and the message is removed from the mailbox.
User ignores a message in the mailbox
A message is charged for every block in the mailbox within its gas limit. If the message hasn't an explicit gas limit, gas is borrowed from the origin's limit (e.g. an actor that has initiated the execution).
When the message's gas runs out, the message is removed from the mailbox, and the associated value transferred back to the message sender.