micheline

package
v1.12.2 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2022 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeAnnoPrefix  = ":"
	VarAnnoPrefix   = "%"
	FieldAnnoPrefix = "@"
)
View Source
const (
	TypeStruct = "struct"
	TypeUnion  = "union"
)

Extra Types

View Source
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

View Source
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
)
View Source
const PATH_SEPARATOR = "."

Variables

View Source
var (
	IManager     = Interface("MANAGER")
	ISetDelegate = Interface("SET_DELEGATE")
	ITzip5       = Interface("TZIP-005")
	ITzip7       = Interface("TZIP-007")
	ITzip12      = Interface("TZIP-012")
	IDexter      = Interface("DEXTER")

	WellKnownInterfaces = []Interface{
		IManager,
		ISetDelegate,
		ITzip5,
		ITzip7,
		ITzip12,

		IDexter,
	}
)
View Source
var (
	InvalidPrim = Prim{}
	EmptyPrim   = Prim{Type: PrimNullary, OpCode: 255}
)
View Source
var BigmapRefType = Prim{
	Type:   PrimNullary,
	OpCode: T_INT,
}
View Source
var InterfaceSpecs = map[Interface][]Prim{

	IManager: []Prim{

		NewCodeAnno(T_LAMBDA, "%do", NewCode(T_UNIT), NewCode(T_LIST, NewCode(T_OPERATION))),

		NewCodeAnno(T_UNIT, "%default"),
	},

	ISetDelegate: []Prim{

		NewCodeAnno(T_OPTION, "%setDelegate", NewCode(T_KEY_HASH)),
	},

	ITzip5: []Prim{

		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: []Prim{

		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: []Prim{

		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"),
						),
					),
				),
			),
		),

		NewPairType(
			NewCodeAnno(T_LIST, "%requests",
				NewPairType(
					NewCodeAnno(T_ADDRESS, "%owner"),
					NewCodeAnno(T_NAT, "%token_id"),
				),
			),
			NewCodeAnno(T_CONTRACT, "%callback",
				NewCode(T_LIST,
					NewPairType(
						NewPairType(
							NewCodeAnno(T_ADDRESS, "%owner"),
							NewCodeAnno(T_NAT, "%token_id"),
							"%request",
						),
						NewCodeAnno(T_NAT, "%balance"),
					),
				),
			),
			"%balance_of",
		),

		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",
				),
			),
		),
	},
	IDexter: []Prim{

		NewPairType(
			NewCodeAnno(T_ADDRESS, ":spender"),
			NewPairType(
				NewCodeAnno(T_NAT, ":allowance"),
				NewCodeAnno(T_NAT, ":currentAllowance"),
			),
			"%approve",
		),

		NewPairType(
			NewPairType(
				NewCodeAnno(T_ADDRESS, ":owner"),
				NewCodeAnno(T_NAT, ":minLqtMinted"),
			),
			NewPairType(
				NewCodeAnno(T_NAT, ":maxTokensDeposited"),
				NewCodeAnno(T_TIMESTAMP, ":deadline"),
			),
			"%addLiquidity",
		),

		NewPairType(
			NewPairType(
				NewCodeAnno(T_ADDRESS, ":owner"),
				NewPairType(
					NewCodeAnno(T_ADDRESS, ":to"),
					NewCodeAnno(T_NAT, ":lqtBurned"),
				),
			),
			NewPairType(
				NewCodeAnno(T_MUTEZ, ":minXtzWithdrawn"),
				NewPairType(
					NewCodeAnno(T_NAT, ":minTokensWithdrawn"),
					NewCodeAnno(T_TIMESTAMP, ":deadline"),
				),
			),
			"%removeLiquidity",
		),

		NewPairType(
			NewCodeAnno(T_ADDRESS, ":to"),
			NewPairType(
				NewCodeAnno(T_NAT, ":minTokensBought"),
				NewCodeAnno(T_TIMESTAMP, ":deadline"),
			),
			"%xtzToToken",
		),

		NewPairType(
			NewPairType(
				NewCodeAnno(T_ADDRESS, ":owner"),
				NewCodeAnno(T_ADDRESS, ":to"),
			),
			NewPairType(
				NewCodeAnno(T_NAT, ":tokensSold"),
				NewPairType(
					NewCodeAnno(T_MUTEZ, ":minXtzBought"),
					NewCodeAnno(T_TIMESTAMP, ":deadline"),
				),
			),
			"%tokenToXtz",
		),

		NewPairType(
			NewPairType(
				NewCodeAnno(T_ADDRESS, ":outputDexterContract"),
				NewPairType(
					NewCodeAnno(T_NAT, ":minTokensBought"),
					NewCodeAnno(T_ADDRESS, ":owner"),
				),
			),
			NewPairType(
				NewCodeAnno(T_ADDRESS, ":to"),
				NewPairType(
					NewCodeAnno(T_NAT, ":tokensSold"),
					NewCodeAnno(T_TIMESTAMP, ":deadline"),
				),
			),
			"%tokenToToken",
		),

		NewCodeAnno(T_KEY_HASH, "%updateTokenPool"),

		NewCodeAnno(T_NAT, "%updateTokenPoolInternal"),

		NewPairType(
			NewCode(T_OPTION, NewCode(T_KEY_HASH)),
			NewCode(T_BOOL),
			"%setBaker",
		),

		NewCodeAnno(T_ADDRESS, "%setManager"),
	},
}

WellKnownInterfaces contains entrypoint types for standard call interfaces and other known contracts.

View Source
var PrimSkip = errors.New("skip branch")

Functions

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 IsEqualPrim(p1, p2 Prim, withAnno bool) bool

func IsManagerTz

func IsManagerTz(buf []byte) bool

func KeyHash

func KeyHash(buf []byte) tezos.ExprHash

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 UseLogger

func UseLogger(logger logpkg.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using logpkg.

func UseTrace

func UseTrace(fn LogFn)

UseTrace sets fn to be used as trace function

Types

type BigmapDiff

type BigmapDiff []BigmapDiffElem

func (BigmapDiff) MarshalBinary

func (b BigmapDiff) MarshalBinary() ([]byte, error)

func (*BigmapDiff) UnmarshalBinary

func (b *BigmapDiff) UnmarshalBinary(data []byte) error

type BigmapDiffElem

type BigmapDiffElem struct {
	Action    DiffAction
	Id        int64
	SourceId  int64 // used on copy
	DestId    int64 // used on copy
	KeyHash   tezos.ExprHash
	Key       Prim // works with any type
	Value     Prim
	KeyType   Prim // used on alloc/copy, uses Prim for native marshalling
	ValueType Prim // used on alloc/copy, uses Prim for native marshalling
}

func (BigmapDiffElem) Encoding

func (e BigmapDiffElem) Encoding() PrimType

func (BigmapDiffElem) GetKey

func (e BigmapDiffElem) GetKey(typ Type) Key

func (BigmapDiffElem) GetKeyPtr

func (e BigmapDiffElem) GetKeyPtr(typ Type) *Key

func (BigmapDiffElem) MarshalJSON

func (e BigmapDiffElem) MarshalJSON() ([]byte, error)

func (*BigmapDiffElem) UnmarshalJSON

func (e *BigmapDiffElem) UnmarshalJSON(data []byte) error

TODO: lazy_storage_diff updates

type Ciphertext

type Ciphertext struct {
	Cv         []byte
	Epk        []byte
	PayloadEnc []byte
	NonceEnc   []byte
	PayloadOut []byte
	NonceOut   []byte
}

func (Ciphertext) MarshalJSON

func (c Ciphertext) MarshalJSON() ([]byte, error)

TODO

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) DecodeBuffer

func (c *Code) DecodeBuffer(buf *bytes.Buffer) error

func (Code) MarshalBinary

func (c Code) MarshalBinary() ([]byte, error)

func (Code) MarshalJSON

func (c Code) MarshalJSON() ([]byte, error)

func (*Code) UnmarshalBinary

func (c *Code) UnmarshalBinary(data []byte) error

func (*Code) UnmarshalJSON

func (c *Code) UnmarshalJSON(data []byte) error

type ConstantDict

type ConstantDict map[string]Prim

func (*ConstantDict) Add

func (d *ConstantDict) Add(address tezos.ExprHash, value Prim)

func (ConstantDict) Get

func (d ConstantDict) Get(address tezos.ExprHash) (Prim, bool)

func (ConstantDict) GetString

func (d ConstantDict) GetString(address string) (Prim, bool)

func (ConstantDict) Has

func (d ConstantDict) Has(address tezos.ExprHash) bool

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 Features

type Features uint16
const (
	FeatureSpendable Features = 1 << iota
	FeatureDelegatable
	FeatureAccountFactory
	FeatureContractFactory
	FeatureSetDelegate
	FeatureLambda
	FeatureTransferTokens
	FeatureChainId
	FeatureTicket
	FeatureSapling
	FeatureView
	FeatureGlobalConstant
	FeatureTimelock
)

func (Features) Array

func (f Features) Array() []string

func (Features) Contains

func (f Features) Contains(x Features) bool

func (Features) MarshalJSON

func (f Features) MarshalJSON() ([]byte, error)

func (Features) String

func (f Features) String() string

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) FuncPrim

func (m Interface) FuncPrim(name string) Prim

func (Interface) FuncType

func (m Interface) FuncType(name string) Type

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).

func (Interface) String

func (m Interface) String() string

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 DecodeKey

func DecodeKey(typ Type, b []byte) (Key, error)

func NewKey

func NewKey(typ Type, key Prim) (Key, error)

func NewKeyPtr

func NewKeyPtr(typ Type, key Prim) (*Key, error)

func ParseKey

func ParseKey(typ OpCode, val string) (Key, error)

query string parsing used for lookup

func (Key) Bytes

func (k Key) Bytes() []byte

func (Key) Hash

func (k Key) Hash() tezos.ExprHash

func (Key) IsPacked

func (k Key) IsPacked() bool

func (Key) MarshalBinary

func (k Key) MarshalBinary() ([]byte, error)

func (Key) MarshalJSON

func (k Key) MarshalJSON() ([]byte, error)

func (Key) Prim

func (k Key) Prim() Prim

func (Key) PrimPtr

func (k Key) PrimPtr() *Prim

func (Key) String

func (k Key) String() string

func (Key) Unpack

func (k Key) Unpack() (Key, error)

func (Key) UnpackPrim

func (k Key) UnpackPrim() (p Prim, err error)

type LogFn

type LogFn logpkg.LogfFn

LogFn is a shot alias for a log function of type func(string, interface...)

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
	T_SAPLING_TRANSACTION   // 84
	I_SAPLING_EMPTY_STATE   // 85
	I_SAPLING_VERIFY_UPDATE // 86
	T_TICKET                // 87
	I_TICKET                // 88
	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
)

Michelson V1 Primitives

func InferKeyType

func InferKeyType(val string) OpCode

func ParseKeyType

func ParseKeyType(typ string) (OpCode, error)

func ParseOpCode

func ParseOpCode(str string) (OpCode, error)

func (OpCode) Byte

func (o OpCode) Byte() byte

func (OpCode) IsKeyCode

func (op OpCode) IsKeyCode() bool

func (OpCode) IsTypeCode

func (op OpCode) IsTypeCode() bool

func (OpCode) IsValid

func (op OpCode) IsValid() bool

func (OpCode) MarshalText

func (op OpCode) MarshalText() ([]byte, error)

func (OpCode) PrimType

func (op OpCode) PrimType() PrimType

func (OpCode) String

func (op OpCode) String() string

func (OpCode) TypeCode

func (op OpCode) TypeCode() OpCode

type Parameters

type Parameters struct {
	Entrypoint string `json:"entrypoint"`
	Value      Prim   `json:"value"`
}

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)
}

func ASSERT_CMPEQ

func ASSERT_CMPEQ() Prim

Macros

func DELEGATE_ENTRY

func DELEGATE_ENTRY() Prim

'set_delegate'/'remove_delegate' entrypoints

func DO_ENTRY

func DO_ENTRY() Prim

Macros

func DUUP

func DUUP() Prim

func IFCMPNEQ

func IFCMPNEQ(left, right Prim) Prim

func NewBig

func NewBig(i *big.Int) Prim

func NewBigmapRef

func NewBigmapRef(id int64) Prim

func NewBigmapRefType

func NewBigmapRefType(anno string) Prim

func NewBytes

func NewBytes(b []byte) Prim

func NewCode

func NewCode(c OpCode, args ...Prim) Prim

func NewCodeAnno

func NewCodeAnno(c OpCode, anno string, args ...Prim) Prim

func NewCombPair

func NewCombPair(contents ...Prim) Prim

func NewCombPairType

func NewCombPairType(contents ...Prim) Prim

func NewInt64

func NewInt64(i int64) Prim

func NewNat

func NewNat(i *big.Int) Prim

func NewPair

func NewPair(l, r Prim) Prim

func NewPairType

func NewPairType(l, r Prim, anno ...string) Prim

func NewPrim

func NewPrim(c OpCode, anno ...string) Prim

func NewSeq

func NewSeq(args ...Prim) Prim

func NewString

func NewString(s string) Prim

func UNPAIR

func UNPAIR() Prim

func (Prim) BuildType

func (p Prim) BuildType() Type

build matching type tree for value

func (Prim) CanUnfold

func (p Prim) CanUnfold(typ Type) bool

Detects whether a primitive contains a regular pair or any form of container type. Pairs can be unfolded into flat sequences.

func (Prim) Clone

func (p Prim) Clone() Prim

func (Prim) Constants

func (p Prim) Constants() []tezos.ExprHash

func (Prim) ContainsOpCode

func (p Prim) ContainsOpCode(typ OpCode) bool

func (Prim) Decode

func (p Prim) Decode(v interface{}) error

func (*Prim) DecodeBuffer

func (p *Prim) DecodeBuffer(buf *bytes.Buffer) error

func (Prim) Dump

func (p Prim) Dump() string

func (Prim) DumpLimit

func (p Prim) DumpLimit(n int) string

func (Prim) EncodeBuffer

func (p Prim) EncodeBuffer(buf *bytes.Buffer) error

func (Prim) Features

func (p Prim) Features() Features

func (Prim) FindLabels

func (p Prim) FindLabels(label string) ([]Prim, bool)

func (Prim) FindOpCodes

func (p Prim) FindOpCodes(typ OpCode) ([]Prim, bool)

func (Prim) FoldPair

func (p Prim) FoldPair() Prim

Turns a pair sequence into a right-hand pair tree

func (Prim) GetFieldAnno

func (p Prim) GetFieldAnno() string

func (Prim) GetFieldAnnoAny

func (p Prim) GetFieldAnnoAny() string

prefers FieldAnno, first anno otherwise

func (Prim) GetIndex

func (p Prim) GetIndex(index []int) (Prim, error)

func (Prim) GetIndexExt

func (p Prim) GetIndexExt(index []int, typ OpCode) (Prim, error)

func (Prim) GetPath

func (p Prim) GetPath(path string) (Prim, error)

func (Prim) GetPathExt

func (p Prim) GetPathExt(path string, typ OpCode) (Prim, error)

func (Prim) GetTypeAnno

func (p Prim) GetTypeAnno() string

func (Prim) GetTypeAnnoAny

func (p Prim) GetTypeAnnoAny() string

prefers TypeAnno, first anno otherwise

func (Prim) GetVarAnno

func (p Prim) GetVarAnno() string

func (Prim) GetVarAnnoAny

func (p Prim) GetVarAnnoAny() string

prefers VarAnno, first anno otherwise

func (Prim) GetVarOrFieldAnno

func (p Prim) GetVarOrFieldAnno() string

func (Prim) HasAnno

func (p Prim) HasAnno() bool

func (Prim) HasFieldAnno

func (p Prim) HasFieldAnno() bool

func (Prim) HasSimilarChildTypes

func (p Prim) HasSimilarChildTypes() bool

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 (p Prim) HasTypeAnno() bool

func (Prim) HasVarAnno

func (p Prim) HasVarAnno() bool

func (Prim) HasVarOrFieldAnno

func (p Prim) HasVarOrFieldAnno() bool

func (Prim) Hash64

func (p Prim) Hash64() uint64

func (Prim) Index

func (p Prim) Index(label string) ([]int, bool)

func (Prim) IsConstant

func (p Prim) IsConstant() bool

func (Prim) IsContainerType

func (p Prim) IsContainerType() bool

func (Prim) IsConvertedComb

func (p Prim) IsConvertedComb() bool

Checks if a Prim looks like an optimized (i.e. flat) comb sequence.

func (Prim) IsElt

func (p Prim) IsElt() bool

func (Prim) IsEmpty

func (p Prim) IsEmpty() bool

func (Prim) IsEmptyBigmap

func (p Prim) IsEmptyBigmap() bool

func (Prim) IsEqual

func (p Prim) IsEqual(p2 Prim) bool

func (Prim) IsEqualWithAnno

func (p Prim) IsEqualWithAnno(p2 Prim) bool

func (Prim) IsInstruction

func (p Prim) IsInstruction() bool

func (Prim) IsLambda

func (p Prim) IsLambda() bool

func (Prim) IsList

func (p Prim) IsList() bool

func (Prim) IsMap

func (p Prim) IsMap() bool

func (Prim) IsNil

func (p Prim) IsNil() bool

func (Prim) IsPacked

func (p Prim) IsPacked() bool

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 (p Prim) IsPackedAny() bool

func (Prim) IsPair

func (p Prim) IsPair() bool

func (Prim) IsScalar

func (p Prim) IsScalar() bool

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 (p Prim) IsScalarType() bool

func (Prim) IsSequence

func (p Prim) IsSequence() bool

func (Prim) IsSet

func (p Prim) IsSet() bool

func (Prim) IsTicket

func (p Prim) IsTicket() bool

func (Prim) IsValid

func (p Prim) IsValid() bool

func (Prim) LooksLikeCode

func (p Prim) LooksLikeCode() bool

Checks if a Prim looks like a lambda type.

func (Prim) LooksLikeContainer

func (p Prim) LooksLikeContainer() bool

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 (p Prim) LooksLikeMap() bool

func (Prim) LooksLikeSet

func (p Prim) LooksLikeSet() bool

func (Prim) MarshalBinary

func (p Prim) MarshalBinary() ([]byte, error)

func (Prim) MarshalJSON

func (p Prim) MarshalJSON() ([]byte, error)

func (Prim) MatchesAnno

func (p Prim) MatchesAnno(anno string) bool

func (Prim) MigrateToBabylonStorage

func (p Prim) MigrateToBabylonStorage(managerHash []byte) Prim

func (Prim) Pack

func (p Prim) Pack() []byte

Packs produces a packed serialization for of a primitive's contents that is prefixed with a 0x5 byte.

func (*Prim) StripAnno

func (p *Prim) StripAnno(name string)

func (Prim) UnfoldPair

func (p Prim) UnfoldPair(typ Type) []Prim

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 (p Prim) UnfoldPairRecursive(typ Type) []Prim

func (*Prim) UnmarshalBinary

func (p *Prim) UnmarshalBinary(data []byte) error

func (*Prim) UnmarshalJSON

func (p *Prim) UnmarshalJSON(data []byte) error

func (Prim) Unpack

func (p Prim) Unpack() (pp Prim, err error)

Unpacks all primitive contents that looks like packed and returns a new primitive tree.

func (Prim) UnpackAll

func (p Prim) UnpackAll() (Prim, error)

func (*Prim) UnpackJSON

func (p *Prim) UnpackJSON(val interface{}) error

func (*Prim) UnpackPrimitive

func (p *Prim) UnpackPrimitive(val map[string]interface{}) error

func (*Prim) UnpackScalar

func (p *Prim) UnpackScalar(val interface{}) error

func (*Prim) UnpackSequence

func (p *Prim) UnpackSequence(val []interface{}) error

func (Prim) Value

func (p Prim) Value(as OpCode) interface{}

Returns a typed/decoded value from an encoded primitive.

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 PrimList

type PrimList []Prim

func (PrimList) Last

func (l PrimList) Last() Prim

type PrimMarshaler

type PrimMarshaler interface {
	MarshalPrim() (Prim, error)
}

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 ParsePrimType(val string) (PrimType, error)

func (PrimType) IsValid

func (t PrimType) IsValid() bool

func (PrimType) MarshalText

func (t PrimType) MarshalText() ([]byte, error)

func (PrimType) String

func (t PrimType) String() string

non-normative strings, use for debugging only

func (PrimType) TypeCode

func (t PrimType) TypeCode() OpCode

type PrimUnmarshaler

type PrimUnmarshaler interface {
	UnmarshalPrim(Prim) error
}

type PrimVisitorFunc

type PrimVisitorFunc func(p *Prim) error

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

type PrimWalkerFunc func(p Prim) error

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 MakeManagerScript(managerHash []byte) (*Script, error)

func NewScript

func NewScript() *Script

func (*Script) BigmapTypesByName

func (s *Script) BigmapTypesByName() map[string]Type

Returns a named map containing all bigmaps defined in contracts storgae spec. Names are derived from Michelson type annotations and if missing, a sequence number. Optionally appends a sequence number to prevent duplicate names.

func (*Script) BigmapsById

func (s *Script) BigmapsById() []int64

Returns a list of bigmaps referenced by a contracts current storage. Note that in rare cases when storage type uses a T_OR branch above its bigmap type definitions and the relevant branch is inactive/hidden the storage value lacks bigmap references and this function will return an empty list, even though bigmaps exist.

func (*Script) BigmapsByName

func (s *Script) BigmapsByName() map[string]int64

Returns a named map containing all bigmaps currently referenced by a contracts storage value. Names are derived from Michelson type annotations and if missing, a sequence number. Optionally appends a sequence number to prevent duplicate names.

func (*Script) CodeHash

func (s *Script) CodeHash() uint64

Returns the first 4 bytes of the SHA256 hash from a binary encoded code section of a contract.

func (*Script) Constants

func (s *Script) Constants() []tezos.ExprHash

func (*Script) DecodeBuffer

func (p *Script) DecodeBuffer(buf *bytes.Buffer) error

func (Script) EncodeBuffer

func (p Script) EncodeBuffer(buf *bytes.Buffer) error

func (*Script) Entrypoints

func (s *Script) Entrypoints(withPrim bool) (Entrypoints, error)

func (*Script) ExpandConstants

func (s *Script) ExpandConstants(dict ConstantDict)

func (*Script) Features

func (s *Script) Features() Features

func (*Script) Implements

func (s *Script) Implements(i Interface) bool

func (*Script) ImplementsStrict

func (s *Script) ImplementsStrict(i Interface) bool

func (*Script) InterfaceHash

func (s *Script) InterfaceHash() uint64

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 (p Script) MarshalBinary() ([]byte, error)

func (*Script) MigrateToBabylonAddDo

func (s *Script) MigrateToBabylonAddDo(managerHash []byte)

Patch params, storage and code

func (*Script) MigrateToBabylonSetDelegate

func (s *Script) MigrateToBabylonSetDelegate(managerHash []byte)

func (*Script) ParamType

func (s *Script) ParamType() Type

func (*Script) ResolveEntrypointPath

func (s *Script) ResolveEntrypointPath(name string) string

func (*Script) StorageHash

func (s *Script) StorageHash() uint64

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 (s *Script) StorageType() Type

func (*Script) UnmarshalBinary

func (p *Script) UnmarshalBinary(data []byte) error

func (*Script) Views

func (s *Script) Views(withPrim, withCode bool) (Views, error)

type Stack

type Stack []Prim

func NewStack

func NewStack(args ...Prim) *Stack

func (Stack) Dump

func (s Stack) Dump() string

func (Stack) DumpIdent

func (s Stack) DumpIdent(indent int) string

func (*Stack) Empty

func (s *Stack) Empty() bool

func (*Stack) Len

func (s *Stack) Len() int

func (*Stack) Peek

func (s *Stack) Peek() Prim

func (*Stack) Pop

func (s *Stack) Pop() Prim

func (*Stack) Push

func (s *Stack) Push(args ...Prim)

type Type

type Type struct {
	Prim
}

func NewType

func NewType(p Prim) Type

func NewTypePtr

func NewTypePtr(p Prim) *Type

func TicketType

func TicketType(t Prim) Type

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) Clone

func (t Type) Clone() Type

func (Type) Entrypoints

func (t Type) Entrypoints(withPrim bool) (Entrypoints, error)

func (Type) HasLabel

func (t Type) HasLabel() bool

func (Type) IsEqual

func (t Type) IsEqual(t2 Type) bool

func (Type) IsEqualWithAnno

func (t Type) IsEqualWithAnno(t2 Type) bool

func (Type) Label

func (t Type) Label() string

func (Type) Left

func (t Type) Left() Type

func (Type) MarshalJSON

func (t Type) MarshalJSON() ([]byte, error)

func (Type) ResolveEntrypointPath

func (t Type) ResolveEntrypointPath(name string) string

returns path to named entrypoint

func (Type) Right

func (t Type) Right() Type

func (Type) Typedef

func (t Type) Typedef(name string) Typedef

func (Type) TypedefPtr

func (t Type) TypedefPtr(name string) *Typedef

func (*Type) UnmarshalBinary

func (t *Type) UnmarshalBinary(buf []byte) error

func (*Type) UnmarshalJSON

func (t *Type) UnmarshalJSON(buf []byte) error

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"`
}

func (Typedef) Equal

func (a Typedef) Equal(b Typedef) bool

func (Typedef) StrictEqual

func (a Typedef) StrictEqual(b Typedef) bool

func (Typedef) String

func (t Typedef) String() string

type Value

type Value struct {
	Type   Type
	Value  Prim
	Render int
	// contains filtered or unexported fields
}

func NewValue

func NewValue(typ Type, val Prim) Value

func NewValuePtr

func NewValuePtr(typ Type, val Prim) *Value

func (*Value) Decode

func (v *Value) Decode(buf []byte) error

func (Value) Dump

func (e Value) Dump() string

func (Value) DumpLimit

func (e Value) DumpLimit(n int) string

func (Value) DumpTo

func (e Value) DumpTo(w io.Writer)

func (*Value) FixType

func (e *Value) FixType()

func (*Value) GetAddress

func (v *Value) GetAddress(label string) (tezos.Address, bool)

func (*Value) GetBig

func (v *Value) GetBig(label string) (*big.Int, bool)

func (*Value) GetBool

func (v *Value) GetBool(label string) (bool, bool)

func (*Value) GetBytes

func (v *Value) GetBytes(label string) ([]byte, bool)

func (*Value) GetInt64

func (v *Value) GetInt64(label string) (int64, bool)

func (*Value) GetKey

func (v *Value) GetKey(label string) (tezos.Key, bool)

func (*Value) GetSignature

func (v *Value) GetSignature(label string) (tezos.Signature, bool)

func (*Value) GetString

func (v *Value) GetString(label string) (string, bool)

func (*Value) GetTime

func (v *Value) GetTime(label string) (time.Time, bool)

func (*Value) GetValue

func (v *Value) GetValue(label string) (interface{}, bool)

func (Value) IsPacked

func (v Value) IsPacked() bool

func (Value) IsPackedAny

func (v Value) IsPackedAny() bool

func (*Value) Map

func (e *Value) Map() (interface{}, error)

func (Value) MarshalJSON

func (e Value) MarshalJSON() ([]byte, error)

func (*Value) Unmarshal

func (v *Value) Unmarshal(val interface{}) error

func (Value) Unpack

func (v Value) Unpack() (Value, error)

func (Value) UnpackAll

func (v Value) UnpackAll() (Value, error)

func (*Value) Walk

func (v *Value) Walk(label string, fn ValueWalkerFunc) error

type ValueWalkerFunc

type ValueWalkerFunc func(label string, value interface{}) error

type View

type View struct {
	Name   string
	Param  Type
	Retval Type
	Code   Prim
	Prim   Prim
}

func NewView

func NewView(p Prim) View

func NewViewPtr

func NewViewPtr(p Prim) *View

func (View) Clone

func (v View) Clone() View

func (View) IsEqual

func (v View) IsEqual(v2 View) bool

func (View) IsEqualWithAnno

func (v View) IsEqualWithAnno(v2 View) bool

func (View) IsEqualWithCode

func (v View) IsEqualWithCode(v2 View) bool

func (View) IsValid

func (v View) IsValid() bool

func (View) MarshalJSON

func (v View) MarshalJSON() ([]byte, error)

func (View) Typedef

func (v View) Typedef() Typedef

func (View) TypedefPtr

func (v View) TypedefPtr(name string) *Typedef

type Views

type Views map[string]View

Jump to

Keyboard shortcuts

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