bind

package
v1.18.4 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package bind contains utility functions and types that are used by generated contract code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalParams

func MarshalParams(optimized bool, params ...any) (micheline.Prim, error)

MarshalParams marshals the provided params into a folded Prim.

func MarshalParamsPath

func MarshalParamsPath(optimized bool, paths [][]int, params ...any) (micheline.Prim, error)

MarshalParamsPath marshals the provided params into a Prim tree at specified paths. This function is useful to render any kind of structs (records) into a type-conform prim tree. It requires a list of tree positions in the form of paths. Both paths and params must have the same length.

func MarshalPrim

func MarshalPrim(v any, optimized bool) (micheline.Prim, error)

MarshalPrim marshals v into a Prim by using reflection.

If true, timestamps ,addresses, keys and signatures will be marshaled in their optimized format. See https://tezos.gitlab.io/active/michelson.html#differences-with-the-formal-notation.

func UnmarshalPrim

func UnmarshalPrim(prim micheline.Prim, v any) error

UnmarshalPrim unmarshals a prim into v.

v must be a non-nil pointer to the expected result.

func UnmarshalPrimPath

func UnmarshalPrimPath(root micheline.Prim, path string, v any) error

UnmarshalPrimPath unmarshals a nested prim contained in root, obtained using the given path, into v.

v must be a non-nil pointer to the expected result.

func UnmarshalPrimPaths

func UnmarshalPrimPaths(root micheline.Prim, dst map[string]any) error

UnmarshalPrimPaths unmarshals a Prim into a map of (path => destination).

Types

type Bigmap

type Bigmap[K, V any] struct {
	// contains filtered or unexported fields
}

Bigmap is a handle to a Tezos bigmap.

It has two type parameters, K and V, which are determined when a contract script is parsed.

Before using a Bigmap to Get a value, its RPC client must be set with SetRPC.

func NewBigmap

func NewBigmap[K, V any](id int64) Bigmap[K, V]

NewBigmap returns a new Bigmap that points to the given bigmap id.

The type parameters must match the key and value type of the corresponding bigmap.

func (*Bigmap[K, V]) Get

func (b *Bigmap[K, V]) Get(ctx context.Context, key K) (v V, err error)

Get the value corresponding to the given key.

This makes a rpc call, so SetRPC must have been called before calling this.

If the key doesn't exist in the bigmap, an ErrKeyNotFound is returned.

func (*Bigmap[K, B]) ID

func (b *Bigmap[K, B]) ID() int64

ID returns the id of the bigmap.

func (Bigmap[K, V]) MarshalPrim

func (b Bigmap[K, V]) MarshalPrim(optimized bool) (micheline.Prim, error)

func (*Bigmap[K, V]) SetContent

func (b *Bigmap[K, V]) SetContent(elt ...MapEntry[K, V])

func (*Bigmap[K, B]) SetKeyType

func (b *Bigmap[K, B]) SetKeyType(keyType micheline.Type) *Bigmap[K, B]

SetKeyType forces the key micheline type to use, when marshaling a key into an expression hash.

func (*Bigmap[K, B]) SetRPC

func (b *Bigmap[K, B]) SetRPC(client RPC) *Bigmap[K, B]

SetRPC defines the client to use when getting a value from the bigmap.

func (Bigmap[K, V]) String

func (b Bigmap[K, V]) String() string

func (*Bigmap[K, V]) UnmarshalPrim

func (b *Bigmap[K, V]) UnmarshalPrim(prim micheline.Prim) error

type Contract

type Contract interface {
	Address() tezos.Address
	Call(ctx context.Context, args contract.CallArguments, opts *rpc.CallOptions) (*rpc.Receipt, error)
	RunView(ctx context.Context, name string, args micheline.Prim) (micheline.Prim, error)
}

type ErrKeyNotFound

type ErrKeyNotFound struct {
	Key string
}

func (*ErrKeyNotFound) Error

func (e *ErrKeyNotFound) Error() string

func (*ErrKeyNotFound) Is

func (e *ErrKeyNotFound) Is(target error) bool

type Lambda

type Lambda struct {
	micheline.Prim
}

Lambda is raw Michelson code represented as a Prim tree.

func (Lambda) MarshalPrim

func (l Lambda) MarshalPrim(_ bool) (micheline.Prim, error)

func (*Lambda) UnmarshalPrim

func (l *Lambda) UnmarshalPrim(prim micheline.Prim) error

type Map

type Map[K, V any] struct {
	// contains filtered or unexported fields
}

Map is a map type used to interact with Tezos smart contracts.

Go's map type cannot be used in this context, because the "comparable" types are different in Go and in Tezos specification.

func MakeMap

func MakeMap[K, V any](size ...int) Map[K, V]

func (*Map[K, V]) Entries

func (m *Map[K, V]) Entries() []MapEntry[K, V]

func (Map[K, V]) Format

func (m Map[K, V]) Format(f fmt.State, verb rune)

func (*Map[K, V]) Get

func (m *Map[K, V]) Get(key K) (V, bool)

func (Map[K, V]) MarshalPrim

func (m Map[K, V]) MarshalPrim(optimized bool) (micheline.Prim, error)

func (*Map[K, V]) Set

func (m *Map[K, V]) Set(key K, value V)

func (*Map[K, V]) UnmarshalPrim

func (m *Map[K, V]) UnmarshalPrim(prim micheline.Prim) error

type MapEntry

type MapEntry[K, V any] struct {
	Key   K
	Value V
}

type Option

type Option[T any] struct {
	// contains filtered or unexported fields
}

Option is a type that can either contain a value T, or be None.

func None

func None[T any]() Option[T]

None returns a None option for type T.

func Some

func Some[T any](v T) Option[T]

Some returns a Some option with v as a value.

func (Option[T]) Get

func (o Option[T]) Get() (v T, isSome bool)

Get returns the inner value of the Option and a boolean indicating if the Option is Some.

If it is none, the returned value is the default value for T.

func (Option[T]) GetUntyped

func (o Option[T]) GetUntyped() (v any, isSome bool)

GetUntyped is the equivalent of Get, but it returns v as an empty interface instead of T.

This method is useful when generic parameters cannot be used, for example with reflection.

func (Option[T]) IsNone

func (o Option[T]) IsNone() bool

func (Option[T]) IsSome

func (o Option[T]) IsSome() bool

func (Option[T]) MarshalPrim

func (o Option[T]) MarshalPrim(optimized bool) (micheline.Prim, error)

func (*Option[T]) SetNone

func (o *Option[T]) SetNone()

SetNone replaces o's value with None.

func (*Option[T]) SetSome

func (o *Option[T]) SetSome(v T)

SetSome replaces o's value with Some(v).

func (*Option[T]) SetUntyped

func (o *Option[T]) SetUntyped(v any) error

SetUntyped is the equivalent of SetSome or SetNone, but uses v as an empty interface instead of T.

If v is nil, then the Option will be set to None. Else, it will cast v to T and set the Option to Some.

Returns an error if the cast failed.

This method is useful when generic parameters cannot be used, for example with reflection.

func (Option[T]) String

func (o Option[T]) String() string

func (*Option[T]) UnmarshalPrim

func (o *Option[T]) UnmarshalPrim(prim micheline.Prim) error

func (Option[T]) Unwrap

func (o Option[T]) Unwrap() T

Unwrap returns the inner value of the Option, expecting that it is Some.

Panics if the option is None.

func (Option[T]) UnwrapOr

func (o Option[T]) UnwrapOr(defaultValue T) T

UnwrapOr returns the inner value of the Option if it is Some, or the provided default value if it is None.

func (Option[T]) UnwrapOrZero

func (o Option[T]) UnwrapOrZero() T

UnwrapOrZero returns the inner value of the Option if it is Some, or T's zero value if it is None.

type Or

type Or[L, R any] struct {
	// contains filtered or unexported fields
}

Or is a type that can be either L or R.

It maps to michelson's `or` type.

func Left

func Left[L, R any](l L) Or[L, R]

Left returns a new Or[L, R] filled with the left value.

func Right[L, R any](r R) Or[L, R]

Right returns a new Or[L, R] filled with the right value.

func (Or[L, R]) IsLeft

func (o Or[L, R]) IsLeft() bool

func (Or[L, R]) IsRight

func (o Or[L, R]) IsRight() bool

func (Or[L, R]) Left

func (o Or[L, R]) Left() (L, bool)

Left returns the left value and true, if the Or is Left.

func (Or[L, R]) MarshalPrim

func (o Or[L, R]) MarshalPrim(optimized bool) (micheline.Prim, error)

func (Or[L, R]) Right

func (o Or[L, R]) Right() (R, bool)

Right returns the right value and true, if the Or is Right.

func (*Or[L, R]) UnmarshalPrim

func (o *Or[L, R]) UnmarshalPrim(prim micheline.Prim) error

type PrimMarshaler

type PrimMarshaler interface {
	MarshalPrim(optimized bool) (micheline.Prim, error)
}

type RPC

type RPC interface {
	GetContractStorage(ctx context.Context, addr tezos.Address, id rpc.BlockID) (micheline.Prim, error)
	GetBigmapValue(ctx context.Context, bigmap int64, hash tezos.ExprHash, id rpc.BlockID) (micheline.Prim, error)
}

Jump to

Keyboard shortcuts

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