bind

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: May 10, 2023 License: MIT Imports: 13 Imported by: 1

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 added in v0.2.2

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

MarshalParams marshals the provided params into a folded Prim.

func MarshalPrim added in v0.2.2

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 added in v0.2.2

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 added in v0.2.2

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 added in v0.2.2

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

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

Types

type Bigmap added in v0.2.3

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 added in v0.2.3

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 added in v0.2.3

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 added in v0.2.3

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

ID returns the id of the bigmap.

func (*Bigmap[K, B]) SetKeyType added in v0.2.3

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 added in v0.2.3

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 added in v0.2.3

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

func (*Bigmap[K, V]) UnmarshalPrim added in v0.2.3

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

type Contract added in v0.1.2

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 added in v0.2.3

type ErrKeyNotFound struct {
	Key string
}

func (*ErrKeyNotFound) Error added in v0.2.3

func (e *ErrKeyNotFound) Error() string

func (*ErrKeyNotFound) Is added in v0.2.3

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

type Lambda added in v0.4.0

type Lambda struct {
	micheline.Prim
}

Lambda is raw Michelson code represented as a Prim tree.

func (*Lambda) MarshalPrim added in v0.4.0

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

func (*Lambda) UnmarshalPrim added in v0.4.0

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

type Map added in v0.2.3

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 added in v0.2.3

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

func (*Map[K, V]) Entries added in v0.2.3

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

func (Map[K, V]) Format added in v0.2.3

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

func (*Map[K, V]) Get added in v0.2.3

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

func (Map[K, V]) MarshalPrim added in v0.2.3

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

func (*Map[K, V]) Set added in v0.2.3

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

func (*Map[K, V]) UnmarshalPrim added in v0.2.3

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

type MapEntry added in v0.2.3

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

type Option added in v0.2.2

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 added in v0.2.2

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

None returns a None option for type T.

func Some added in v0.2.2

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

Some returns a Some option with v as a value.

func (Option[T]) Get added in v0.2.2

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 added in v0.3.4

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 added in v0.2.2

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

func (Option[T]) IsSome added in v0.2.2

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

func (Option[T]) MarshalPrim added in v0.2.2

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

func (*Option[T]) SetNone added in v0.3.2

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

SetNone replaces o's value with None.

func (*Option[T]) SetSome added in v0.3.2

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

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

func (*Option[T]) SetUntyped added in v0.3.4

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 added in v0.4.2

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

func (*Option[T]) UnmarshalPrim added in v0.2.2

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

func (Option[T]) Unwrap added in v0.2.2

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 added in v0.2.2

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 added in v0.2.2

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 added in v0.2.2

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 added in v0.2.2

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 added in v0.2.2

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

func (Or[L, R]) IsRight added in v0.2.2

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

func (Or[L, R]) Left added in v0.2.2

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 added in v0.2.2

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

func (Or[L, R]) Right added in v0.2.2

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 added in v0.2.2

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

type PrimMarshaler added in v0.2.3

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

type RPC added in v0.2.3

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