memo

package
v0.0.0-...-1329066 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 9, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LenBytesShort = 1
	LenBytesLong  = 2
)

Enum for length of bytes used to encode compact data

View Source
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
)
View Source
const (
	// MaskFlagsReserved is the mask for reserved data flags
	MaskFlagsReserved = 0b11100000
)

Variables

This section is empty.

Functions

func DecodeLegacyMemoHex

func DecodeLegacyMemoHex(message string) (common.Address, []byte, error)

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 ArgType

type ArgType string

ArgType is the enum for types supported by the codec

const (
	ArgTypeBytes   ArgType = "bytes"
	ArgTypeString  ArgType = "string"
	ArgTypeAddress ArgType = "address"
)

Define all the types supported by the codec

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 NewCodecABI

func NewCodecABI() *CodecABI

NewCodecABI creates a new ABI codec

func (*CodecABI) AddArguments

func (c *CodecABI) AddArguments(args ...CodecArg)

AddArguments adds a list of arguments to the codec

func (*CodecABI) PackArguments

func (c *CodecABI) PackArguments() ([]byte, error)

PackArguments packs the arguments into the ABI encoded data

func (*CodecABI) UnpackArguments

func (c *CodecABI) UnpackArguments(data []byte) error

UnpackArguments unpacks the ABI encoded data into the output arguments

type CodecArg

type CodecArg struct {
	Name string
	Type ArgType
	Arg  interface{}
}

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

func NewArg

func NewArg(name string, argType ArgType, arg interface{}) CodecArg

NewArg create a new codec argument

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

func (*FieldsV0) DataFlags

func (f *FieldsV0) DataFlags() uint8

DataFlags build the data flags from actual fields

func (*FieldsV0) Pack

func (f *FieldsV0) Pack(opCode OpCode, encodingFmt EncodingFormat, dataFlags uint8) ([]byte, error)

Pack encodes the memo fields

func (*FieldsV0) Unpack

func (f *FieldsV0) Unpack(encodingFmt EncodingFormat, dataFlags uint8, data []byte) error

Unpack decodes the memo fields

func (*FieldsV0) Validate

func (f *FieldsV0) Validate(opCode OpCode, dataFlags uint8) error

Validate checks if the fields are valid

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

func (h *Header) DecodeFromBytes(data []byte) error

DecodeFromBytes decodes the memo header from the given data

func (*Header) EncodeToBytes

func (h *Header) EncodeToBytes() ([]byte, error)

EncodeToBytes encodes the memo header to raw bytes

func (*Header) Validate

func (h *Header) Validate() error

Validate checks if the memo header is valid

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.

type OpCode

type OpCode uint8
const (
	OpCodeDeposit        OpCode = 0b0000 // operation 'deposit'
	OpCodeDepositAndCall OpCode = 0b0001 // operation 'deposit_and_call'
	OpCodeCall           OpCode = 0b0010 // operation 'call'
	OpCodeInvalid        OpCode = 0b0011 // invalid operation code
)

Enum for non-EVM chain inbound operation code (4 bits)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL