common

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: MIT Imports: 9 Imported by: 8

Documentation

Index

Constants

View Source
const (
	// CrossChainAddressMaxLength defines the maximum length for cross-chain addresses.
	CrossChainAddressMaxLength = 64 // in bytes
	// MaxArrayLength defines the maximum length for arrays packed with reference chaining to prevent excessive resource consumption.
	MaxArrayLength = 1000
	// MaxCellChainDepth is the maximum depth for c4/c5 registers in TON (512 cells).
	// General execution depth limit is <1024, but c4/c5 specifically limited to 512.
	MaxCellChainDepth = 512
	// MaxCellDataBytes is the maximum data per cell in TON (127 bytes, ~1023 bits).
	// This limit is enforced during cell creation by Builder operations (StoreSlice, etc).
	MaxCellDataBytes = 127
	// MaxCellChainBytes is the maximum total bytes in a cell chain (MaxCellChainDepth * MaxCellDataBytes = ~65KB).
	// Represents the practical limit for c4/c5 register data.
	MaxCellChainBytes = MaxCellChainDepth * MaxCellDataBytes // 65,024 bytes
)

TVM limits for cell chains, enforced at different stages: - Per-cell limits (MaxCellDataBytes): Enforced by Builder during cell creation - Chain depth limits (MaxCellChainDepth): Enforced during TVM execution (not during creation)

The 512-depth limit specifically applies to c4 (persistent storage) and c5 (output actions) registers during smart contract execution. Cell chains exceeding this depth can be created locally but will fail when used in contract state or validated during blockchain processing.

Variables

View Source
var GetTypeAndVersion = tvm.NewNoArgsGetter(tvm.NoArgsOpts[TypeAndVersion]{
	Name: versionGetter,
	Decoder: tvm.NewResultDecoder(func(r *ton.ExecutionResult) (TypeAndVersion, error) {
		var t TypeAndVersion
		typ, err := r.Slice(0)
		if err != nil {
			return t, err
		}
		tStr, err := typ.LoadStringSnake()
		if err != nil {
			return t, err
		}

		version, err := r.Slice(1)
		if err != nil {
			return t, err
		}

		vStr, err := version.LoadStringSnake()
		if err != nil {
			return t, err
		}

		return TypeAndVersion{
			Type:    tStr,
			Version: vStr,
		}, nil
	}),
})

GetTypeAndVersion gets the type and version of the contract

Functions

func NewDummyCell

func NewDummyCell() (*cell.Cell, error)

NewDummyCell returns a cell containing the string "placeholder" in its data.

Types

type AddressWrap

type AddressWrap struct {
	Val *address.Address `tlb:"addr"`
}

AddressWrap is a simple wrapper around address.Address for TLB serialization. Needed for common.SnakedCell[] of addresses.

func WrapAddresses

func WrapAddresses(addrs []*address.Address) []AddressWrap

func (AddressWrap) BitsLen

func (a AddressWrap) BitsLen() uint

type CrossChainAddress

type CrossChainAddress []byte

CrossChainAddress is a type that represents a cross-chain address.

func LoadCrossChainAddressWithoutPrefix

func LoadCrossChainAddressWithoutPrefix(s *cell.Slice) (CrossChainAddress, error)

LoadCrossChainAddressWithoutPrefix parses a CrossChainAddress from raw data if lacks a length prefix as the first byte.

func (*CrossChainAddress) LoadFromCell

func (c *CrossChainAddress) LoadFromCell(s *cell.Slice) error

func (CrossChainAddress) ToCell

func (c CrossChainAddress) ToCell() (*cell.Cell, error)

ToCell converts the CrossChainAddress to a cell structure.

type Proof

type Proof struct {
	Value *big.Int `tlb:"## 256"` // The value of the struct
}

Proof represents a 32-byte (256 bits) proof used in merkle proofs. This wrapper type allows [32]byte to be used with SnakedCell by implementing ToCell/LoadFromCell that directly store/load 256 bits inline, avoiding the infinite loop issue that occurs with SnakeBytes (which uses c.ToCell() in LoadFromCell).

type Signature

type Signature struct {
	Sig []byte `tlb:"bits 256"`
}

Signature is a type that represents a cryptographic signature used in MerkleProofs

type SnakeBytes

type SnakeBytes []byte

SnakeBytes is a byte array type for packing and unpacking into a cell structure.

func (*SnakeBytes) LoadFromCell

func (s *SnakeBytes) LoadFromCell(c *cell.Slice) error

LoadFromCell loads the SnakeBytes from a cell slice. It uses unloadCellToByteArray to deserialize the data.

func (SnakeBytes) ToCell

func (s SnakeBytes) ToCell() (*cell.Cell, error)

ToCell packs the SnakeBytes into a cell. It uses packByteArrayToCell to serialize the data.

type SnakeRef

type SnakeRef[T any] []T

SnakeRef is a generic type for packing and unpacking slices of any type T into a cell structure with references chaining.

func (*SnakeRef[T]) LoadFromCell

func (s *SnakeRef[T]) LoadFromCell(c *cell.Slice) error

LoadFromCell loads the SnakeRef from a cell slice. It uses unpackArrayWithRefChaining to deserialize the data.

func (SnakeRef[T]) ToCell

func (s SnakeRef[T]) ToCell() (*cell.Cell, error)

ToCell packs the SnakeRef into a cell. It uses packArrayWithRefChaining to serialize the data.

type SnakedCell

type SnakedCell[T any] []T

SnakedCell is a generic type for packing and unpacking slices of any type T into a cell structure.

func (*SnakedCell[T]) LoadFromCell

func (s *SnakedCell[T]) LoadFromCell(c *cell.Slice) error

LoadFromCell loads the SnakedCell from a cell slice. It uses UnpackArray to deserialize the data.

func (SnakedCell[T]) ToCell

func (s SnakedCell[T]) ToCell() (*cell.Cell, error)

ToCell packs the SnakedCell into a cell. It uses PackArray to serialize the data. currently this function is not using pointer receiver, lack of support from tonutils-go library https://github.com/xssnick/tonutils-go/issues/340

type TypeAndVersion

type TypeAndVersion struct {
	Type    string `tlb:"str"`
	Version string `tlb:"str"`
}

TypeAndVersion holds the type and version of the onramp contract.

func (*TypeAndVersion) GetterMethodName deprecated

func (t *TypeAndVersion) GetterMethodName() string

Deprecated: Use GetTypeAndVersion getter instead.

func (*TypeAndVersion) UnmarshalResult deprecated

func (t *TypeAndVersion) UnmarshalResult(result *ton.ExecutionResult) error

Deprecated: Use GetTypeAndVersion getter instead.

Jump to

Keyboard shortcuts

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