Documentation ¶
Index ¶
- Constants
- Variables
- func DetectBigmapTypes(typ Prim) map[string]Type
- func DetectBigmaps(typ Prim, storage Prim) map[string]int64
- func DisableLog()
- func IsEqualPrim(p1, p2 Prim, withAnno bool) bool
- func IsManagerTz(buf []byte) bool
- func KeyHash(buf []byte) tezos.ExprHash
- func Trace(fn func(log LogFn))
- func UnmarshalScriptType(data []byte) (param Type, storage Type, err error)
- func UseLogger(logger logpkg.Logger)
- type BigmapEvent
- type BigmapEvents
- type Ciphertext
- type Code
- type ConstantDict
- type DiffAction
- type Entrypoint
- type Entrypoints
- type Features
- type GenericEvent
- type Interface
- func (m Interface) Contains(e Entrypoint) bool
- func (m Interface) ContainsStrict(e Entrypoint) bool
- func (m Interface) Matches(e Entrypoints) bool
- func (m Interface) MatchesStrict(e Entrypoints) bool
- func (m Interface) PrimOf(name string) Prim
- func (m Interface) String() string
- func (m Interface) TypeOf(name string) Type
- type Interfaces
- type Key
- func (k Key) Bytes() []byte
- func (k Key) Hash() tezos.ExprHash
- func (k Key) IsPacked() bool
- func (k Key) MarshalBinary() ([]byte, error)
- func (k Key) MarshalJSON() ([]byte, error)
- func (k Key) Prim() Prim
- func (k Key) PrimPtr() *Prim
- func (k Key) String() string
- func (k Key) Unpack() (Key, error)
- func (k Key) UnpackPrim() (p Prim, err error)
- type LazyBigmapEvent
- type LazyEvent
- type LazyEvents
- type LazyKind
- type LazySaplingEvent
- type LogFn
- type OpCode
- type Parameters
- func (p Parameters) Branch(prefix string, eps Entrypoints) string
- func (p *Parameters) DecodeBuffer(buf *bytes.Buffer) error
- func (p Parameters) EncodeBuffer(buf *bytes.Buffer) error
- func (p Parameters) MapEntrypoint(typ Type) (Entrypoint, Prim, error)
- func (p Parameters) MarshalBinary() ([]byte, error)
- func (p Parameters) MarshalJSON() ([]byte, error)
- func (p *Parameters) UnmarshalBinary(data []byte) error
- func (p *Parameters) UnmarshalJSON(data []byte) error
- func (p Parameters) Unwrap(branch string) Prim
- type Prim
- func ASSERT_CMPEQ() Prim
- func DELEGATE_ENTRY() Prim
- func DO_ENTRY() Prim
- func DUUP() Prim
- func IFCMPNEQ(left, right Prim) Prim
- func NewAddress(a tezos.Address) Prim
- func NewBig(i *big.Int) Prim
- func NewBigmapRef(id int64) Prim
- func NewBigmapRefType(anno string) Prim
- func NewBytes(b []byte) Prim
- func NewCode(c OpCode, args ...Prim) Prim
- func NewCodeAnno(c OpCode, anno string, args ...Prim) Prim
- func NewCombPair(contents ...Prim) Prim
- func NewCombPairType(contents ...Prim) Prim
- func NewInt64(i int64) Prim
- func NewKeyHash(a tezos.Address) Prim
- func NewMap(elts ...Prim) Prim
- func NewMapElem(k, v Prim) Prim
- func NewMapType(k, v Prim, anno ...string) Prim
- func NewMutez(n tezos.N) Prim
- func NewNat(i *big.Int) Prim
- func NewOptType(e Prim, anno ...string) Prim
- func NewOption(p ...Prim) Prim
- func NewPair(l, r Prim) Prim
- func NewPairType(l, r Prim, anno ...string) Prim
- func NewPrim(c OpCode, anno ...string) Prim
- func NewSeq(args ...Prim) Prim
- func NewSetType(e Prim, anno ...string) Prim
- func NewString(s string) Prim
- func NewUnion(path []int, prim Prim) Prim
- func NewZ(z tezos.Z) Prim
- func ParsePrim(typ Typedef, val string, optimized bool) (p Prim, err error)
- func TicketValue(v Prim, ticketer tezos.Address, amount tezos.Z) Prim
- func UNPAIR() Prim
- func (p Prim) BuildType() Type
- func (p Prim) CanUnfold(typ Type) bool
- func (p Prim) CanUnfoldType() bool
- func (p Prim) Clone() Prim
- func (p Prim) CloneNoAnnots() Prim
- func (p Prim) Compare(p2 Prim) int
- func (p Prim) Constants() []tezos.ExprHash
- func (p Prim) ContainsOpCode(typ OpCode) bool
- func (p Prim) Decode(v interface{}) error
- func (p *Prim) DecodeBuffer(buf *bytes.Buffer) error
- func (p Prim) Dump() string
- func (p Prim) DumpLimit(n int) string
- func (p Prim) EncodeBuffer(buf *bytes.Buffer) error
- func (p Prim) EncodeJSON(buf *bytes.Buffer)
- func (p Prim) Features() Features
- func (p Prim) FindBigmapByName(name string) (Prim, bool)
- func (p Prim) FindLabel(label string) (Prim, bool)
- func (p Prim) FindLabels(label string) ([]Prim, bool)
- func (p Prim) FindOpCodes(typ OpCode) ([]Prim, bool)
- func (p Prim) FoldPair() Prim
- func (p Prim) GetFieldAnno() string
- func (p Prim) GetFieldAnnoAny() string
- func (p Prim) GetIndex(index []int) (Prim, error)
- func (p Prim) GetIndexExt(index []int, typ OpCode) (Prim, error)
- func (p Prim) GetPath(path string) (Prim, error)
- func (p Prim) GetPathExt(path string, typ OpCode) (Prim, error)
- func (p Prim) GetTypeAnno() string
- func (p Prim) GetTypeAnnoAny() string
- func (p Prim) GetVarAnno() string
- func (p Prim) GetVarAnnoAny() string
- func (p Prim) GetVarOrFieldAnno() string
- func (p Prim) HasAnno() bool
- func (p Prim) HasFieldAnno() bool
- func (p Prim) HasIndex(index []int) bool
- func (p Prim) HasSimilarChildTypes() bool
- func (p Prim) HasTypeAnno() bool
- func (p Prim) HasVarAnno() bool
- func (p Prim) HasVarOrFieldAnno() bool
- func (p Prim) Hash64() uint64
- func (p Prim) Implements(t Type) bool
- func (p Prim) ImplementsType(t Typedef) bool
- func (p *Prim) Insert(src Prim, path []int)
- func (p Prim) IsConstant() bool
- func (p Prim) IsContainerType() bool
- func (p Prim) IsConvertedComb() bool
- func (p Prim) IsElt() bool
- func (p Prim) IsEmpty() bool
- func (p Prim) IsEmptyBigmap() bool
- func (p Prim) IsEqual(p2 Prim) bool
- func (p Prim) IsEqualWithAnno(p2 Prim) bool
- func (p Prim) IsInstruction() bool
- func (p Prim) IsLambda() bool
- func (p Prim) IsList() bool
- func (p Prim) IsMap() bool
- func (p Prim) IsNil() bool
- func (p Prim) IsPacked() bool
- func (p Prim) IsPackedAny() bool
- func (p Prim) IsPair() bool
- func (p Prim) IsScalar() bool
- func (p Prim) IsScalarType() bool
- func (p Prim) IsSequence() bool
- func (p Prim) IsSet() bool
- func (p Prim) IsTicket() bool
- func (p Prim) IsValid() bool
- func (p Prim) LabelIndex(label string) ([]int, bool)
- func (p Prim) LooksLikeCode() bool
- func (p Prim) LooksLikeContainer() bool
- func (p Prim) LooksLikeMap() bool
- func (p Prim) LooksLikeSet() bool
- func (p Prim) MarshalBinary() ([]byte, error)
- func (p Prim) MarshalJSON() ([]byte, error)
- func (p Prim) MarshalYAML() (any, error)
- func (p Prim) MatchesAnno(anno string) bool
- func (p Prim) MigrateToBabylonStorage(managerHash []byte) Prim
- func (p Prim) Pack() []byte
- func (p *Prim) SetIndex(index []int, dst Prim) error
- func (p *Prim) SetIndexExt(index []int, typ PrimType, dst Prim) error
- func (p *Prim) SetPath(path string, dst Prim) error
- func (p *Prim) SetPathExt(path string, typ PrimType, dst Prim) error
- func (p Prim) Size() int
- func (p *Prim) StripAnno(name string)
- func (p Prim) ToBytes() []byte
- func (p Prim) UnfoldPair(typ Type) []Prim
- func (p Prim) UnfoldPairRecursive(typ Type) []Prim
- func (p Prim) UnfoldTypeRecursive(path []int) []Prim
- func (p *Prim) UnmarshalBinary(data []byte) error
- func (p *Prim) UnmarshalJSON(data []byte) error
- func (p Prim) Unpack() (pp Prim, err error)
- func (p Prim) UnpackAll() (Prim, error)
- func (p Prim) UnpackAllAsciiStrings() Prim
- func (p Prim) UnpackAsciiString() Prim
- func (p *Prim) UnpackJSON(val any) error
- func (p *Prim) UnpackPrimitive(val map[string]any) error
- func (p *Prim) UnpackSequence(val []any) error
- func (p Prim) Value(as OpCode) interface{}
- func (p *Prim) Visit(f PrimVisitorFunc) error
- func (p Prim) Walk(f PrimWalkerFunc) error
- func (p Prim) WithAnno(anno string) Prim
- type PrimList
- type PrimMarshaler
- type PrimType
- type PrimUnmarshaler
- type PrimVisitorFunc
- type PrimWalkerFunc
- type SaplingDiffElem
- type SaplingUpdate
- type Script
- func (s Script) BigmapTypes() map[string]Type
- func (s Script) Bigmaps() map[string]int64
- func (s Script) CodeHash() uint64
- func (s Script) Constants() []tezos.ExprHash
- func (p *Script) DecodeBuffer(buf *bytes.Buffer) error
- func (p Script) EncodeBuffer(buf *bytes.Buffer) error
- func (s Script) Entrypoints(withPrim bool) (Entrypoints, error)
- func (s *Script) ExpandConstants(dict ConstantDict)
- func (s *Script) Features() Features
- func (s *Script) Implements(i Interface) bool
- func (s *Script) ImplementsStrict(i Interface) bool
- func (s Script) InterfaceHash() uint64
- func (s *Script) Interfaces() Interfaces
- func (s *Script) InterfacesStrict() Interfaces
- func (s Script) IsValid() bool
- func (p Script) MarshalBinary() ([]byte, error)
- func (p Script) MarshalJSON() ([]byte, error)
- func (s *Script) MigrateToBabylonAddDo(managerHash []byte)
- func (s *Script) MigrateToBabylonSetDelegate(managerHash []byte)
- func (s Script) ParamType() Type
- func (s Script) ResolveEntrypointPath(name string) string
- func (s Script) StorageHash() uint64
- func (s Script) StorageType() Type
- func (p *Script) UnmarshalBinary(data []byte) error
- func (s Script) Views(withPrim, withCode bool) (Views, error)
- type Stack
- type Type
- func (t Type) Clone() Type
- func (t Type) Entrypoints(withPrim bool) (Entrypoints, error)
- func (t Type) HasLabel() bool
- func (t Type) IsEqual(t2 Type) bool
- func (t Type) IsEqualWithAnno(t2 Type) bool
- func (t Type) IsSimilar(t2 Type) bool
- func (t Type) Label() string
- func (t Type) Left() Type
- func (t Type) MarshalJSON() ([]byte, error)
- func (t Type) ResolveEntrypointPath(name string) string
- func (t Type) Right() Type
- func (t Type) Typedef(name string) Typedef
- func (t Type) TypedefPtr(name string) *Typedef
- func (t *Type) UnmarshalBinary(buf []byte) error
- func (t *Type) UnmarshalJSON(buf []byte) error
- type Typedef
- func (a Typedef) Equal(b Typedef) bool
- func (a Typedef) IsValid() bool
- func (t Typedef) Left() Typedef
- func (t Typedef) Marshal(v any, optimized bool) (Prim, error)
- func (t Typedef) OpCode() OpCode
- func (t Typedef) Right() Typedef
- func (a Typedef) Similar(b Typedef) bool
- func (t Typedef) StrictEqual(v Typedef) bool
- func (t Typedef) String() string
- func (t Typedef) Unfold() Typedef
- type Value
- func (v *Value) Decode(buf []byte) error
- func (e Value) Dump() string
- func (e Value) DumpLimit(n int) string
- func (e Value) DumpTo(w io.Writer)
- func (e *Value) FixType()
- func (v *Value) GetAddress(label string) (tezos.Address, bool)
- func (v *Value) GetBig(label string) (*big.Int, bool)
- func (v *Value) GetBool(label string) (bool, bool)
- func (v *Value) GetBytes(label string) ([]byte, bool)
- func (v *Value) GetInt64(label string) (int64, bool)
- func (v *Value) GetKey(label string) (tezos.Key, bool)
- func (v *Value) GetSignature(label string) (tezos.Signature, bool)
- func (v *Value) GetString(label string) (string, bool)
- func (v *Value) GetTime(label string) (time.Time, bool)
- func (v *Value) GetValue(label string) (interface{}, bool)
- func (v *Value) GetZ(label string) (*tezos.Z, bool)
- func (v Value) IsPacked() bool
- func (v Value) IsPackedAny() bool
- func (e *Value) Map() (interface{}, error)
- func (e Value) MarshalJSON() ([]byte, error)
- func (v *Value) Unmarshal(val interface{}) error
- func (v Value) Unpack() (Value, error)
- func (v Value) UnpackAll() (Value, error)
- func (v Value) UnpackAllAsciiStrings() Value
- func (v *Value) Walk(label string, fn ValueWalkerFunc) error
- type ValueWalkerFunc
- type View
- func (v View) Clone() View
- func (v View) IsEqual(v2 View) bool
- func (v View) IsEqualWithAnno(v2 View) bool
- func (v View) IsEqualWithCode(v2 View) bool
- func (v View) IsValid() bool
- func (v View) MarshalJSON() ([]byte, error)
- func (v View) Typedef() Typedef
- func (v View) TypedefPtr(name string) *Typedef
- type Views
Constants ¶
const ( TypeAnnoPrefix = ":" VarAnnoPrefix = "%" FieldAnnoPrefix = "@" )
const ( TypeStruct = "struct" TypeUnion = "union" )
Extra Types
const ( CONST_ENTRYPOINT = "@entrypoint" CONST_KEY = "@key" CONST_VALUE = "@value" CONST_ITEM = "@item" CONST_PARAM = "@param" CONST_RETURN = "@return" CONST_UNION_LEFT = "@or_0" CONST_UNION_RIGHT = "@or_1" )
Default names
const ( PATH_SEPARATOR = "." DEFAULT = "default" PRIM = "prim" INT = "int" BYTES = "bytes" STRING = "string" ROOT = "root" ANNOTS = "annots" ARGS = "args" DO = "do" SET_DELEGATE = "set_delegate" REMOVE_DELEGATE = "remove_delegate" DEPOSIT = "deposit" STAKE = "stake" UNSTAKE = "unstake" FINALIZE_UNSTAKE = "finalize_unstake" SET_DELEGATE_PARAMETERS = "set_delegate_parameters" )
const ( EMPTY_LABEL = `@%%@` // illegal Michelson annotation value RENDER_TYPE_PRIM = 0 // silently output primitive tree instead if human-readable RENDER_TYPE_FAIL = 1 // return error if human-readable formatting fails RENDER_TYPE_PANIC = 2 // panic with error if human-readable formatting fails RENDER_TYPE_DEBUG = 3 // return error and primitives )
Variables ¶
var ( IManager = Interface("MANAGER") ISetDelegate = Interface("SET_DELEGATE") ITzip5 = Interface("TZIP-005") ITzip7 = Interface("TZIP-007") ITzip12 = Interface("TZIP-012") WellKnownInterfaces = []Interface{ IManager, ISetDelegate, ITzip5, ITzip7, ITzip12, } )
var ( InvalidPrim = Prim{} EmptyPrim = Prim{Type: PrimNullary, OpCode: 255} PrimSkip = errors.New("skip branch") ErrTypeMismatch = errors.New("type mismatch") )
var BigmapRefType = Prim{ Type: PrimNullary, OpCode: T_INT, }
var InterfaceSpecs = map[Interface][]Prim{ IManager: { NewCodeAnno(T_LAMBDA, "%do", NewCode(T_UNIT), NewCode(T_LIST, NewCode(T_OPERATION))), NewCodeAnno(T_UNIT, "%default"), }, ISetDelegate: { NewCodeAnno(T_OPTION, "%setDelegate", NewCode(T_KEY_HASH)), }, ITzip5: { NewPairType( NewCodeAnno(T_ADDRESS, ":from"), NewPairType( NewCodeAnno(T_ADDRESS, ":to"), NewCodeAnno(T_NAT, ":value"), ), "%transfer", ), NewPairType( NewCodeAnno(T_ADDRESS, ":owner"), NewCode(T_CONTRACT, NewCode(T_NAT)), "%getBalance", ), NewPairType( NewCode(T_UNIT), NewCode(T_CONTRACT, NewCode(T_NAT)), "%getTotalSupply", ), }, ITzip7: { NewPairType( NewCodeAnno(T_ADDRESS, ":from"), NewPairType( NewCodeAnno(T_ADDRESS, ":to"), NewCodeAnno(T_NAT, ":value"), ), "%transfer", ), NewPairType( NewCodeAnno(T_ADDRESS, ":spender"), NewCodeAnno(T_NAT, ":value"), "%approve", ), NewPairType( NewPairType( NewCodeAnno(T_ADDRESS, ":owner"), NewCodeAnno(T_ADDRESS, ":spender"), ), NewCode(T_CONTRACT, NewCode(T_NAT)), "%getAllowance", ), NewPairType( NewCodeAnno(T_ADDRESS, ":owner"), NewCode(T_CONTRACT, NewCode(T_NAT)), "%getBalance", ), NewPairType( NewCode(T_UNIT), NewCode(T_CONTRACT, NewCode(T_NAT)), "%getTotalSupply", ), }, ITzip12: { NewCodeAnno(T_LIST, "%transfer", NewPairType( NewCodeAnno(T_ADDRESS, "%from_"), NewCodeAnno(T_LIST, "%txs", NewPairType( NewCodeAnno(T_ADDRESS, "%to_"), NewPairType( NewCodeAnno(T_NAT, "%token_id"), NewCodeAnno(T_NAT, "%amount"), ), ), ), ), ), NewCodeAnno(T_LIST, "%update_operators", NewCode(T_OR, NewPairType( NewCodeAnno(T_ADDRESS, "%owner"), NewPairType( NewCodeAnno(T_ADDRESS, "%operator"), NewCodeAnno(T_NAT, "%token_id"), ), "%add_operator", ), NewPairType( NewCodeAnno(T_ADDRESS, "%owner"), NewPairType( NewCodeAnno(T_ADDRESS, "%operator"), NewCodeAnno(T_NAT, "%token_id"), ), "%remove_operator", ), ), ), }, }
WellKnownInterfaces contains entrypoint types for standard call interfaces and other known contracts.
var (
Unit = NewCode(D_UNIT)
)
Functions ¶
func DetectBigmapTypes ¶
Returns a map of all known bigmap type definitions inside a given prim. Keys are derived from type annotations. Unlabeled bigmaps are prefixed `bigmap_` followed by a unique sequence number. Duplicate names are prevented by adding by a unique sequence number as well.
func DetectBigmaps ¶
Returns a map of named bigmap ids obtained from a storage type and a storage value. In the edge case where a T_OR branch hides an exsting bigmap behind a None value, the hidden bigmap is not detected.
func DisableLog ¶
func DisableLog()
DisableLog disables all library log output. Logging output is disabled by default until either UseLogger or SetLogWriter are called.
func IsEqualPrim ¶
func IsManagerTz ¶
func Trace ¶
func Trace(fn func(log LogFn))
Trace is a function closure wrapper that forwards trace calls to an output function if set. Call UseTrace() to set a function of type LogFn
func UnmarshalScriptType ¶
UnmarshalScriptType is an optimized binary unmarshaller which decodes type trees only. Use this to access smart contract types when script and storage are not required.
Types ¶
type BigmapEvent ¶
type BigmapEvent struct { Action DiffAction `json:"action"` Id int64 `json:"big_map,string"` KeyHash tezos.ExprHash `json:"key_hash"` // update/remove Key Prim `json:"key"` // update/remove Value Prim `json:"value"` // update KeyType Prim `json:"key_type"` // alloc ValueType Prim `json:"value_type"` // alloc SourceId int64 `json:"source_big_map,string"` // copy DestId int64 `json:"destination_big_map,string"` // copy }
func (BigmapEvent) Encoding ¶
func (e BigmapEvent) Encoding() PrimType
func (BigmapEvent) GetKey ¶
func (e BigmapEvent) GetKey(typ Type) Key
func (BigmapEvent) GetKeyPtr ¶
func (e BigmapEvent) GetKeyPtr(typ Type) *Key
func (BigmapEvent) MarshalJSON ¶
func (e BigmapEvent) MarshalJSON() ([]byte, error)
func (*BigmapEvent) UnmarshalJSON ¶
func (e *BigmapEvent) UnmarshalJSON(data []byte) error
type BigmapEvents ¶
type BigmapEvents []BigmapEvent
func (BigmapEvents) Filter ¶
func (l BigmapEvents) Filter(id int64) BigmapEvents
func (BigmapEvents) MarshalBinary ¶
func (b BigmapEvents) MarshalBinary() ([]byte, error)
func (*BigmapEvents) UnmarshalBinary ¶
func (b *BigmapEvents) UnmarshalBinary(data []byte) error
type Ciphertext ¶
type Ciphertext struct { Cv []byte Epk []byte PayloadEnc []byte NonceEnc []byte PayloadOut []byte NonceOut []byte }
func (*Ciphertext) UnmarshalJSON ¶
func (c *Ciphertext) UnmarshalJSON(data []byte) error
type Code ¶
type Code struct { Param Prim // call types Storage Prim // storage types Code Prim // program code View Prim // view code (i.e. list of views, may be empty) BadCode Prim // catch-all for ill-formed contracts }
func (Code) MarshalBinary ¶
func (Code) MarshalJSON ¶
func (*Code) UnmarshalBinary ¶
func (*Code) UnmarshalJSON ¶
type ConstantDict ¶
type DiffAction ¶
type DiffAction byte
const ( DiffActionUpdate DiffAction = iota DiffActionRemove DiffActionCopy DiffActionAlloc )
func ParseDiffAction ¶
func ParseDiffAction(data string) (DiffAction, error)
func (DiffAction) MarshalText ¶
func (a DiffAction) MarshalText() ([]byte, error)
func (DiffAction) String ¶
func (a DiffAction) String() string
func (*DiffAction) UnmarshalText ¶
func (a *DiffAction) UnmarshalText(data []byte) error
type Entrypoint ¶
type Entrypoint struct { Id int `json:"id"` Name string `json:"name"` Branch string `json:"branch"` Typedef []Typedef `json:"type"` Prim *Prim `json:"prim,omitempty"` }
func (Entrypoint) IsCallback ¶
func (e Entrypoint) IsCallback() bool
func (Entrypoint) Type ¶
func (e Entrypoint) Type() Type
type Entrypoints ¶
type Entrypoints map[string]Entrypoint
func (Entrypoints) FindBranch ¶
func (e Entrypoints) FindBranch(branch string) (Entrypoint, bool)
func (Entrypoints) FindId ¶
func (e Entrypoints) FindId(id int) (Entrypoint, bool)
type GenericEvent ¶
func (*GenericEvent) Id ¶
func (d *GenericEvent) Id() int64
func (*GenericEvent) Kind ¶
func (d *GenericEvent) Kind() LazyKind
type Interface ¶
type Interface string
func (Interface) Contains ¶
func (m Interface) Contains(e Entrypoint) bool
func (Interface) ContainsStrict ¶
func (m Interface) ContainsStrict(e Entrypoint) bool
func (Interface) Matches ¶
func (m Interface) Matches(e Entrypoints) bool
Checks if a contract implements all entrypoints required by a standard interface without requiring argument labels to match. This is a looser definition of interface compliance, but in line with the Michelson type system which ignores annotation labels for type equality.
This check uses extracted Typedefs to avoid issues when the Micheline primitive structure diverges from the defined interface (e.g. due to comb type unfolding).
func (Interface) MatchesStrict ¶
func (m Interface) MatchesStrict(e Entrypoints) bool
Checks if a contract strictly implements all standard interface entrypoints including argument types and argument names (annotations).
This check uses extracted Typedefs to avoid issues when the Micheline primitive structure diverges from the defined interface (e.g. due to comb type unfolding).
type Interfaces ¶
type Interfaces []Interface
func (Interfaces) Contains ¶
func (i Interfaces) Contains(x Interface) bool
func (Interfaces) MarshalJSON ¶
func (i Interfaces) MarshalJSON() ([]byte, error)
func (Interfaces) MarshalText ¶
func (i Interfaces) MarshalText() ([]byte, error)
func (*Interfaces) Parse ¶
func (i *Interfaces) Parse(s string) error
func (Interfaces) String ¶
func (i Interfaces) String() string
func (*Interfaces) UnmarshalText ¶
func (i *Interfaces) UnmarshalText(b []byte) error
type Key ¶
type Key struct { Type Type // TODO: refactor into simple Prim IntKey *big.Int StringKey string BytesKey []byte BoolKey bool AddrKey tezos.Address KeyKey tezos.Key SignatureKey tezos.Signature TimeKey time.Time PrimKey Prim }
Comparable key as used in bigmaps and maps
func (Key) MarshalBinary ¶
func (Key) MarshalJSON ¶
func (Key) UnpackPrim ¶
type LazyBigmapEvent ¶
type LazyBigmapEvent struct { BigmapId int64 `json:"id,string"` Diff struct { Action DiffAction `json:"action"` Updates []struct { KeyHash tezos.ExprHash `json:"key_hash"` // update/remove Key Prim `json:"key"` // update/remove Value Prim `json:"value"` // update } `json:"updates"` // update KeyType Prim `json:"key_type"` // alloc ValueType Prim `json:"value_type"` // alloc SourceId int64 `json:"source,string"` // copy } `json:"diff"` }
func (*LazyBigmapEvent) Id ¶
func (d *LazyBigmapEvent) Id() int64
func (*LazyBigmapEvent) Kind ¶
func (d *LazyBigmapEvent) Kind() LazyKind
type LazyEvents ¶
type LazyEvents []LazyEvent
func (LazyEvents) BigmapEvents ¶
func (d LazyEvents) BigmapEvents() BigmapEvents
func (*LazyEvents) UnmarshalJSON ¶
func (d *LazyEvents) UnmarshalJSON(data []byte) error
type LazyKind ¶
type LazyKind string
func ParseLazyKind ¶
func (LazyKind) MarshalText ¶
func (*LazyKind) UnmarshalText ¶
type LazySaplingEvent ¶
type LazySaplingEvent struct { PoolId int64 `json:"id,string"` Diff SaplingDiffElem `json:"diff"` }
func (*LazySaplingEvent) Id ¶
func (d *LazySaplingEvent) Id() int64
func (*LazySaplingEvent) Kind ¶
func (d *LazySaplingEvent) Kind() LazyKind
type OpCode ¶
type OpCode byte
const ( // Keys K_PARAMETER OpCode = iota // 00 K_STORAGE // 01 K_CODE // 02 // Data D_FALSE // 03 D_ELT // 04 D_LEFT // 05 D_NONE // 06 D_PAIR // 07 D_RIGHT // 08 D_SOME // 09 D_TRUE // 0A D_UNIT // 0B // instructions I_PACK // 0C I_UNPACK // 0D I_BLAKE2B // 0E I_SHA256 // 0F I_SHA512 // 10 I_ABS // 11 I_ADD // 12 I_AMOUNT // 13 I_AND // 14 I_BALANCE // 15 I_CAR // 16 I_CDR // 17 I_CHECK_SIGNATURE // 18 I_COMPARE // 19 I_CONCAT // 1A I_CONS // 1B I_CREATE_ACCOUNT // 1C I_CREATE_CONTRACT // 1D I_IMPLICIT_ACCOUNT // 1E I_DIP // 1F I_DROP // 20 I_DUP // 21 I_EDIV // 22 I_EMPTY_MAP // 23 I_EMPTY_SET // 24 I_EQ // 25 I_EXEC // 26 I_FAILWITH // 27 I_GE // 28 I_GET // 29 I_GT // 2A I_HASH_KEY // 2B I_IF // 2C I_IF_CONS // 2D I_IF_LEFT // 2E I_IF_NONE // 2F I_INT // 30 I_LAMBDA // 31 I_LE // 32 I_LEFT // 33 I_LOOP // 34 I_LSL // 35 I_LSR // 36 I_LT // 37 I_MAP // 38 I_MEM // 39 I_MUL // 3A I_NEG // 3B I_NEQ // 3C I_NIL // 3D I_NONE // 3E I_NOT // 3F I_NOW // 40 I_OR // 41 I_PAIR // 42 I_PUSH // 43 I_RIGHT // 44 I_SIZE // 45 I_SOME // 46 I_SOURCE // 47 I_SENDER // 48 I_SELF // 49 I_STEPS_TO_QUOTA // 4A I_SUB // 4B I_SWAP // 4C I_TRANSFER_TOKENS // 4D I_SET_DELEGATE // 4E I_UNIT // 4F I_UPDATE // 50 I_XOR // 51 I_ITER // 52 I_LOOP_LEFT // 53 I_ADDRESS // 54 I_CONTRACT // 55 I_ISNAT // 56 I_CAST // 57 I_RENAME // 58 // Types T_BOOL // 59 T_CONTRACT // 5A T_INT // 5B T_KEY // 5C T_KEY_HASH // 5D T_LAMBDA // 5E T_LIST // 5F T_MAP // 60 T_BIG_MAP // 61 T_NAT // 62 T_OPTION // 63 T_OR // 64 T_PAIR // 65 T_SET // 66 T_SIGNATURE // 67 T_STRING // 68 T_BYTES // 69 T_MUTEZ // 6A T_TIMESTAMP // 6B T_UNIT // 6C T_OPERATION // 6D T_ADDRESS // 6E // v002 addition I_SLICE // 6F // v005 addition // https://blog.nomadic-labs.com/michelson-updates-in-005.html I_DIG // 70 I_DUG // 71 I_EMPTY_BIG_MAP // 72 I_APPLY // 73 T_CHAIN_ID // 74 I_CHAIN_ID // 75 // v008 additions I_LEVEL // 76 I_SELF_ADDRESS // 77 T_NEVER // 78 I_NEVER // 79 I_UNPAIR // 7A I_VOTING_POWER // 7B I_TOTAL_VOTING_POWER // 7C I_KECCAK // 7D I_SHA3 // 7E I_PAIRING_CHECK // 7F T_BLS12_381_G1 // 80 T_BLS12_381_G2 // 81 T_BLS12_381_FR // 82 T_SAPLING_STATE // 83 I_SAPLING_EMPTY_STATE // 85 I_SAPLING_VERIFY_UPDATE // 86 T_TICKET // 87 I_READ_TICKET // 89 I_SPLIT_TICKET // 8A I_JOIN_TICKETS // 8B I_GET_AND_UPDATE // 8C // v011 additions T_CHEST // 8D T_CHEST_KEY // 8E I_OPEN_CHEST // 8F I_VIEW // 90 K_VIEW // 91 H_CONSTANT // 92 // v012 additions I_SUB_MUTEZ // 93 // v013 additions T_TX_ROLLUP_L2_ADDRESS // 94 I_MIN_BLOCK_TIME // 95 T_SAPLING_TRANSACTION // 96 // v014 additions I_EMIT // 97 // v015 additions D_LAMBDA_REC // 98 I_LAMBDA_REC // 99 I_TICKET // 9A // v016 additions I_BYTES // 9B I_NAT // 9C // v19 additions D_TICKET )
Michelson V1 Primitives
func InferKeyType ¶
func ParseKeyType ¶
func ParseOpCode ¶
func (OpCode) IsTypeCode ¶
func (OpCode) MarshalText ¶
type Parameters ¶
func (Parameters) Branch ¶
func (p Parameters) Branch(prefix string, eps Entrypoints) string
func (*Parameters) DecodeBuffer ¶
func (p *Parameters) DecodeBuffer(buf *bytes.Buffer) error
func (Parameters) EncodeBuffer ¶
func (p Parameters) EncodeBuffer(buf *bytes.Buffer) error
func (Parameters) MapEntrypoint ¶
func (p Parameters) MapEntrypoint(typ Type) (Entrypoint, Prim, error)
func (Parameters) MarshalBinary ¶
func (p Parameters) MarshalBinary() ([]byte, error)
func (Parameters) MarshalJSON ¶
func (p Parameters) MarshalJSON() ([]byte, error)
func (*Parameters) UnmarshalBinary ¶
func (p *Parameters) UnmarshalBinary(data []byte) error
func (*Parameters) UnmarshalJSON ¶
func (p *Parameters) UnmarshalJSON(data []byte) error
func (Parameters) Unwrap ¶
func (p Parameters) Unwrap(branch string) Prim
type Prim ¶
type Prim struct { Type PrimType // primitive type OpCode OpCode // primitive opcode (invalid on sequences, strings, bytes, int) Args PrimList // optional arguments Anno []string // optional type annotations Int *big.Int // optional data String string // optional data Bytes []byte // optional data WasPacked bool // true when content was unpacked (and no type info is available) Path []int // optional path to this prim (use to track type structure) }
func NewAddress ¶
func NewBigmapRef ¶
func NewBigmapRefType ¶
func NewCombPair ¶
func NewCombPairType ¶
func NewKeyHash ¶
func NewMapElem ¶
func NewMapType ¶
func NewOptType ¶
func NewPairType ¶
func NewSetType ¶
func TicketValue ¶
Wraps ticket content into structure that is compatible with ticket type. This is necessary for transfer_ticket calls which use explicit fields for value, amount and ticketer.
func (Prim) CanUnfold ¶
Detects whether a primitive contains a regular pair or any form of container type. Pairs can be unfolded into flat sequences.
func (Prim) CanUnfoldType ¶
func (Prim) CloneNoAnnots ¶
func (Prim) ContainsOpCode ¶
func (Prim) Decode ¶
Decode unmarshals a prim tree into a Go struct. The mapping uses Go struct tags to define primitive paths that are mapped to each struct member. Types are converted between Micheline and Go when possible.
Examples of struct field tags and their meanings:
// maps Micheline path 0/0/0 to string field and fails on type mismatch Field string `prim:",path=0/0/1"` // ignore type errors and do not update struct field Field string `prim:",path=0/0/1,nofail"` // ignore struct field Field string `prim:"-"`
func (Prim) EncodeJSON ¶
func (Prim) FindLabel ¶
FindLabel searches a nested type annotation path. Must be used on a type prim. Path segments are separated by dot (.)
func (Prim) GetFieldAnno ¶
func (Prim) GetFieldAnnoAny ¶
prefers FieldAnno, first anno otherwise
func (Prim) GetIndexExt ¶
GetIndex returns a nested primitive at path index if the primitive matches the expected opcode. This only works on type trees. Value trees lack opcode info.
func (Prim) GetPath ¶
GetPath returns a nested primitive at path. Path segments are separated by slash (/). Works on both type and value primitive trees.
func (Prim) GetPathExt ¶
GetPathExt returns a nested primitive at path if the primitive matches the expected opcode. Path segments are separated by slash (/). Works on both type and value primitive trees.
func (Prim) GetTypeAnno ¶
func (Prim) GetTypeAnnoAny ¶
prefers TypeAnno, first anno otherwise
func (Prim) GetVarAnno ¶
func (Prim) GetVarAnnoAny ¶
prefers VarAnno, first anno otherwise
func (Prim) GetVarOrFieldAnno ¶
func (Prim) HasFieldAnno ¶
func (Prim) HasIndex ¶
HasIndex returns true when a nested primitive exists at path defined by index.
func (Prim) HasSimilarChildTypes ¶
Checks if all children have the same type by generating a type tree from values. Can be used to identfy containers based on the existence of similar records.
Works for simple and nested primitives but may mis-detect ambiguous simple types like PrimInt (used for int, nat, timestamp, mutez), or PrimString resp. PrimBytes. May also misdetect when optional types like T_OR, T_OPTION are used and their values are nil since we cannot detect embedded type here.
func (Prim) HasTypeAnno ¶
func (Prim) HasVarAnno ¶
func (Prim) HasVarOrFieldAnno ¶
func (Prim) Implements ¶
func (Prim) ImplementsType ¶
func (Prim) IsConstant ¶
func (Prim) IsContainerType ¶
func (Prim) IsConvertedComb ¶
Checks if a Prim looks like an optimized (i.e. flat) comb sequence.
func (Prim) IsEmptyBigmap ¶
func (Prim) IsEqualWithAnno ¶
func (Prim) IsInstruction ¶
func (Prim) IsPacked ¶
Checks if a primitve contains a packed value such as a byte sequence generated with PACK (starting with 0x05), an address or ascii/utf string.
func (Prim) IsPackedAny ¶
func (Prim) IsScalar ¶
returns true when the prim can be expressed as a single value key/value pairs (ie. prims with annots) do not fit into this category used when mapping complex big map values to JSON objects
func (Prim) IsScalarType ¶
func (Prim) IsSequence ¶
func (Prim) LabelIndex ¶
LabelIndex returns the indexed path to a type annotation label and true if path exists. Path segments are separated by dot (.)
func (Prim) LooksLikeCode ¶
Checks if a Prim looks like a lambda type.
func (Prim) LooksLikeContainer ¶
Checks if a Prim looks like a container type. This is necessary to distinguish optimized comb pairs from other container types.
func (Prim) LooksLikeMap ¶
func (Prim) LooksLikeSet ¶
func (Prim) MarshalBinary ¶
func (Prim) MarshalJSON ¶
func (Prim) MarshalYAML ¶
func (Prim) MatchesAnno ¶
func (Prim) MigrateToBabylonStorage ¶
func (Prim) Pack ¶
Packs produces a packed serialization for of a primitive's contents that is prefixed with a 0x5 byte.
func (*Prim) SetIndexExt ¶
SetIndexExt replaces a nested primitive at path index if the primitive matches the expected primitive type. This function works best with value trees which lack opcode info. Use as extra cross-check when replacing prims.
func (*Prim) SetPath ¶
SetPath replaces a nested primitive at path with dst. Path segments are separated by slash (/). Works on both type and value primitive trees.
func (*Prim) SetPathExt ¶
SetPathExt replaces a nested primitive at path with dst if the primitive matches the expected type. Path segments are separated by slash (/). Works on best on value primitive trees.
func (Prim) UnfoldPair ¶
Converts a pair tree into a flat sequence. While Michelson optimized comb pairs are only used for right-side combs, this function applies to all pairs. It makes use of the type definition to identify which contained type is a regular pair, an already unfolded pair sequence or anther container type.
- Works both on value trees and type trees. - When called on already converted comb sequences this function is a noop.
func (Prim) UnfoldPairRecursive ¶
func (Prim) UnfoldTypeRecursive ¶
func (*Prim) UnmarshalBinary ¶
func (*Prim) UnmarshalJSON ¶
func (Prim) Unpack ¶
Unpacks all primitive contents that looks like packed and returns a new primitive tree.
func (Prim) UnpackAllAsciiStrings ¶
UnpackAllAsciiStrings recursively converts all ASCII strings inside byte prims.
func (Prim) UnpackAsciiString ¶
UnpackAsciiString converts ASCII strings inside byte prims.
func (*Prim) UnpackJSON ¶
func (*Prim) UnpackSequence ¶
func (*Prim) Visit ¶
func (p *Prim) Visit(f PrimVisitorFunc) error
Visit traverses the prim tree in pre-order and allows the callback to alter the contents of a visited node.
func (Prim) Walk ¶
func (p Prim) Walk(f PrimWalkerFunc) error
Walk traverses the prim tree in pre-order in read-only mode, forwarding value copies to the callback.
type PrimMarshaler ¶
type PrimType ¶
type PrimType byte
const ( PrimInt PrimType = iota // 00 {name: 'int'} PrimString // 01 {name: 'string'} PrimSequence // 02 [] PrimNullary // 03 {name: 'prim', len: 0, annots: false}, PrimNullaryAnno // 04 {name: 'prim', len: 0, annots: true}, PrimUnary // 05 {name: 'prim', len: 1, annots: false}, PrimUnaryAnno // 06 {name: 'prim', len: 1, annots: true}, PrimBinary // 07 {name: 'prim', len: 2, annots: false}, PrimBinaryAnno // 08 {name: 'prim', len: 2, annots: true}, PrimVariadicAnno // 09 {name: 'prim', len: n, annots: true}, PrimBytes // 0A {name: 'bytes' } )
func ParsePrimType ¶
func (PrimType) MarshalText ¶
type PrimUnmarshaler ¶
type PrimVisitorFunc ¶
PrimWalkerFunc is the callback function signature used while traversing a prim tree. The callback may change the contents of the visited node, including altering nested child nodes and annotations.
type PrimWalkerFunc ¶
PrimWalkerFunc is the callback function signature used while traversing a prim tree in read-only mode.
type SaplingDiffElem ¶
type SaplingDiffElem struct { Action DiffAction `json:"action"` Updates SaplingUpdate `json:"updates"` MemoSize int `json:"memo_size"` }
type SaplingUpdate ¶
type SaplingUpdate struct { Commitments [][]byte `json:"commitments"` Ciphertexts []Ciphertext `json:"ciphertexts"` Nullifiers [][]byte `json:"nullifiers"` }
type Script ¶
type Script struct { Code Code `json:"code"` // code section, i.e. parameter & storage types, code Storage Prim `json:"storage"` // data section, i.e. initial contract storage }
func MakeManagerScript ¶
func (Script) BigmapTypes ¶
Returns a map of all known bigmap type definitions inside the scripts storage type. Unlabeled bigmaps are prefixed `bigmap_` followed by a unique sequence number. Duplicate names are prevented by adding by a unique sequence number as well.
func (Script) CodeHash ¶
Returns the first 4 bytes of the SHA256 hash from a binary encoded code section of a contract.
func (Script) Entrypoints ¶
func (s Script) Entrypoints(withPrim bool) (Entrypoints, error)
func (*Script) ExpandConstants ¶
func (s *Script) ExpandConstants(dict ConstantDict)
func (*Script) Implements ¶
func (*Script) ImplementsStrict ¶
func (Script) InterfaceHash ¶
Returns the first 4 bytes of the SHA256 hash from a binary encoded parameter type definition. This value is sufficiently unique to identify contracts with exactly the same entrypoints including annotations.
To identify syntactically equal entrypoints with or without annotations use `IsEqual()`, `IsEqualWithAnno()` or `IsEqualPrim()`.
func (*Script) Interfaces ¶
func (s *Script) Interfaces() Interfaces
func (*Script) InterfacesStrict ¶
func (s *Script) InterfacesStrict() Interfaces
func (Script) MarshalBinary ¶
func (Script) MarshalJSON ¶
func (*Script) MigrateToBabylonAddDo ¶
Patch params, storage and code
func (*Script) MigrateToBabylonSetDelegate ¶
func (Script) ResolveEntrypointPath ¶
func (Script) StorageHash ¶
Returns the first 4 bytes of the SHA256 hash from a binary encoded storage type definition. This value is sufficiently unique to identify contracts with exactly the same entrypoints including annotations.
func (Script) StorageType ¶
func (*Script) UnmarshalBinary ¶
type Type ¶
type Type struct {
Prim
}
func MustParseType ¶
func NewTypePtr ¶
func TicketType ¶
Wraps ticket value type into type structure that is compatible with ticket values. This is necessary because T_TICKET uses an implicit structure (extra fields amount, ticketer) in addition to the defined value.
func (Type) Entrypoints ¶
func (t Type) Entrypoints(withPrim bool) (Entrypoints, error)
func (Type) IsEqualWithAnno ¶
func (Type) MarshalJSON ¶
func (Type) ResolveEntrypointPath ¶
returns path to named entrypoint
func (Type) TypedefPtr ¶
func (*Type) UnmarshalBinary ¶
func (*Type) UnmarshalJSON ¶
type Typedef ¶
type Typedef struct { Name string `json:"name"` // annotation label | @key | @value | @item | @params | @return Type string `json:"type"` // opcode or struct | union Optional bool `json:"optional,omitempty"` // Union only Args []Typedef `json:"args,omitempty"` Path []int `json:"path"` // type tree original path to this element }
func (Typedef) Marshal ¶
Marshal takes a scalar or nested Go type and populates a Micheline primitive tree compatible with type t. This method is compatible with most contract entrypoints, contract storage, bigmap values, etc. Use optimized to control whether the target prims contain values in optimized form (binary addresses, numeric timestamps) or string form.
Note: This is work in progress. Several data types are still unsupported and entrypoint mapping requires some extra boilerplate:
// Entrypoint example (without error handling for brevity) eps, _ := script.Entrypoints(true) ep, _ := eps["name"] // marshal to prim tree // Note: be mindful of the way entrypoint typedefs are structured: // - 1 arg: use scalar value in ep.Typedef[0] // - >1 arg: use entire list in ep.Typedef but wrap into struct typ := ep.Typedef[0] if len(ep.Typedef) > 1 { typ = micheline.Typedef{ Name: micheline.CONST_ENTRYPOINT, Type: micheline.TypeStruct, Args: ep.Typedef, } } // then use the type to marshal into primitives prim, err := typ.Marshal(args, true)