Documentation ¶
Index ¶
Constants ¶
const ( LenBytesShort = 1 LenBytesLong = 2 )
Enum for length of bytes used to encode compact data
const ( // Identifier is the ASCII code of 'Z' (0x5A) Identifier byte = 0x5A // HeaderSize is the size of the memo header: [identifier + ctrlByte1+ ctrlByte2 + dataFlags] HeaderSize = 4 )
const (
// MaskFlagsReserved is the mask for reserved data flags
MaskFlagsReserved = 0b11100000
)
Variables ¶
This section is empty.
Functions ¶
func DecodeLegacyMemoHex ¶
DecodeLegacyMemoHex decodes hex encoded memo message into address and calldata
The layout of legacy memo is: [20-byte address, variable calldata]
func GetLenBytes ¶
func GetLenBytes(encodingFmt EncodingFormat) (int, error)
GetLenBytes returns the number of bytes used to encode the length of the data
Types ¶
type Codec ¶
type Codec interface { // AddArguments adds a list of arguments to the codec AddArguments(args ...CodecArg) // PackArguments packs the arguments into the encoded data PackArguments() ([]byte, error) // UnpackArguments unpacks the encoded data into the arguments UnpackArguments(data []byte) error }
Codec is the interface for a codec
func GetCodec ¶
func GetCodec(encodingFmt EncodingFormat) (Codec, error)
GetCodec returns the codec based on the encoding format
type CodecABI ¶
type CodecABI struct {
// contains filtered or unexported fields
}
CodecABI is a coder/decoder for ABI encoded memo fields
func (*CodecABI) AddArguments ¶
AddArguments adds a list of arguments to the codec
func (*CodecABI) PackArguments ¶
PackArguments packs the arguments into the ABI encoded data
func (*CodecABI) UnpackArguments ¶
UnpackArguments unpacks the ABI encoded data into the output arguments
type CodecArg ¶
CodecArg represents a codec argument
func ArgAbortAddress ¶
func ArgAbortAddress(arg interface{}) CodecArg
ArgAbortAddress wraps the abort address in a CodecArg
func ArgPayload ¶
func ArgPayload(arg interface{}) CodecArg
ArgPayload wraps the payload in a CodecArg
func ArgReceiver ¶
func ArgReceiver(arg interface{}) CodecArg
ArgReceiver wraps the receiver address in a CodecArg
func ArgRevertAddress ¶
func ArgRevertAddress(arg interface{}) CodecArg
ArgRevertAddress wraps the revert address in a CodecArg
func ArgRevertMessage ¶
func ArgRevertMessage(arg interface{}) CodecArg
ArgRevertMessage wraps the revert message in a CodecArg
type CodecCompact ¶
type CodecCompact struct {
// contains filtered or unexported fields
}
CodecCompact is a coder/decoder for compact encoded memo fields
This encoding format concatenates the memo fields into a single byte array with zero padding to minimize the total size of the memo.
func NewCodecCompact ¶
func NewCodecCompact(encodingFmt EncodingFormat) (*CodecCompact, error)
NewCodecCompact creates a new compact codec
func (*CodecCompact) AddArguments ¶
func (c *CodecCompact) AddArguments(args ...CodecArg)
AddArguments adds a list of arguments to the codec
func (*CodecCompact) PackArguments ¶
func (c *CodecCompact) PackArguments() ([]byte, error)
PackArguments packs the arguments into the compact encoded data
func (*CodecCompact) UnpackArguments ¶
func (c *CodecCompact) UnpackArguments(data []byte) error
UnpackArguments unpacks the compact encoded data into the output arguments
type EncodingFormat ¶
type EncodingFormat uint8
const ( // EncodingFmtABI represents ABI encoding format EncodingFmtABI EncodingFormat = 0b0000 // EncodingFmtCompactShort represents 'compact short' encoding format EncodingFmtCompactShort EncodingFormat = 0b0001 // EncodingFmtCompactLong represents 'compact long' encoding format EncodingFmtCompactLong EncodingFormat = 0b0010 // EncodingFmtInvalid represents invalid encoding format EncodingFmtInvalid EncodingFormat = 0b0011 )
Enum for non-EVM chain memo encoding format (2 bits)
type Fields ¶
type Fields interface { // Pack encodes the memo fields Pack(opCode OpCode, encodingFmt EncodingFormat, dataFlags uint8) ([]byte, error) // Unpack decodes the memo fields Unpack(encodingFmt EncodingFormat, dataFlags uint8, data []byte) error // Validate checks if the fields are valid Validate(opCode OpCode, dataFlags uint8) error // DataFlags build the data flags for the fields DataFlags() uint8 }
Fields is the interface for memo fields
type FieldsV0 ¶
type FieldsV0 struct { // Receiver is the ZEVM receiver address Receiver common.Address // Payload is the calldata passed to ZEVM contract call Payload []byte // RevertOptions is the options for cctx revert handling RevertOptions crosschaintypes.RevertOptions }
FieldsV0 contains the data fields of the inbound memo V0
type Header ¶
type Header struct { // Version is the memo Version Version uint8 // EncodingFmt is the memo encoding format EncodingFmt EncodingFormat // OpCode is the inbound operation code OpCode OpCode // Reserved is the reserved control bits Reserved uint8 // DataFlags is the data flags DataFlags uint8 }
Header represent the memo header
func (*Header) DecodeFromBytes ¶
DecodeFromBytes decodes the memo header from the given data
func (*Header) EncodeToBytes ¶
EncodeToBytes encodes the memo header to raw bytes
type InboundMemo ¶
type InboundMemo struct { // Header contains the memo header Header // FieldsV0 contains the memo fields V0 // Note: add a FieldsV1 if breaking change is needed in the future FieldsV0 }
InboundMemo represents the inbound memo structure for non-EVM chains
func DecodeFromBytes ¶
func DecodeFromBytes(data []byte) (*InboundMemo, bool, error)
DecodeFromBytes decodes a InboundMemo struct from raw bytes
Returns:
- [memo, true, nil] if given data is successfully decoded as a memo.
- [nil, true, err] if given data is successfully decoded as a memo but contains improper field values.
- [nil, false, err] if given data can't be decoded as a memo.
Note: we won't have to differentiate between the two 'true' cases if legacy memo phase out is completed.
func (*InboundMemo) EncodeToBytes ¶
func (m *InboundMemo) EncodeToBytes() ([]byte, error)
EncodeToBytes encodes a InboundMemo struct to raw bytes
Note:
- Any provided 'DataFlags' is ignored as they are calculated based on the fields set in the memo.
- The 'RevertGasLimit' is not used for now for non-EVM chains.