pub enum Message<P = Box<RawMessage>> {
Transfer {
amount: Amount,
token_address: Address,
token_chain: Chain,
recipient: Address,
recipient_chain: Chain,
fee: Amount,
},
AssetMeta {
token_address: Address,
token_chain: Chain,
decimals: u8,
symbol: BString,
name: BString,
},
TransferWithPayload {
amount: Amount,
token_address: Address,
token_chain: Chain,
recipient: Address,
recipient_chain: Chain,
sender_address: Address,
payload: P,
},
}Expand description
Represents a non-governance action targeted at the token bridge.
The generic parameter P indicates the type of the payload for the TransferWithPayload
variant. This defaults to Box<RawMessage> as that provides the most flexibility when
deserializing the payload and avoids leaking lifetime parameters higher up the stack. However,
users who are serializing to or deserializing from the serde_wormhole data format may want to
use a &RawMessage to avoid unnecessary memory allocations. When the type of the payload is
known and is serialized in the same data format as the rest of the message, that type can be
used as the generic parameter to deserialize the message and the payload together.
Variants§
Transfer
The Transfer message contains specifics detailing a token lock up on a sending chain. Chains that are attempting to initiate a transfer must lock up tokens in some manner, such as in a custody account or via burning, before emitting this message.
Fields
AssetMeta
Contains information about a token and its origin chain.
Fields
TransferWithPayload
Similar to Transfer but also includes an arbitrary payload.
§Examples
Deserialize a TransferWithPayload message using the serde_wormhole crate:
use serde_wormhole::RawMessage;
use wormhole_sdk::{token::Message, Vaa};
let msg = serde_wormhole::from_slice::<Vaa<Message<&RawMessage>>>(&data)?;
match msg.payload {
Message::TransferWithPayload { payload, .. } => {
// Handle the payload.
}
_ => {
// Handle other message types.
}
}Deserialize a TransferWithPayload message using serde_json:
use anyhow::anyhow;
use wormhole_sdk::{token::Message, Vaa};
let msg = serde_json::from_slice::<Vaa<Message>>(&data)?;
match msg.payload {
Message::TransferWithPayload { payload, .. } => {
// Handle the payload.
}
_ => {
// Handle other message types.
}
}Fields
payload: PThe payload to be included with the transfer.