codec

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2022 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

View Source
const (
	BlockWatermark byte = iota + 1
	EndorsementWatermark
	OperationWatermark
)

Variables

This section is empty.

Functions

func CalculateMinFee

func CalculateMinFee(o Operation, gas int64, withHeader bool) int64

CalculateMinFee returns the minimum fee at/above which bakers will accept this operation under default config settings. Lower fee operations may not pass the fee filter and may time out in the mempool.

Types

type ActivateAccount

type ActivateAccount struct {
	Simple
	PublicKeyHash tezos.Address  `json:"pkh"`
	Secret        tezos.HexBytes `json:"secret"`
}

ActivateAccount represents "activate_account" operation

func (*ActivateAccount) DecodeBuffer

func (o *ActivateAccount) DecodeBuffer(buf *bytes.Buffer, p *tezos.Params) error

func (ActivateAccount) EncodeBuffer

func (o ActivateAccount) EncodeBuffer(buf *bytes.Buffer, p *tezos.Params) error

func (ActivateAccount) Kind

func (o ActivateAccount) Kind() tezos.OpType

func (ActivateAccount) MarshalBinary

func (o ActivateAccount) MarshalBinary() ([]byte, error)

func (ActivateAccount) MarshalJSON

func (o ActivateAccount) MarshalJSON() ([]byte, error)

func (*ActivateAccount) UnmarshalBinary

func (o *ActivateAccount) UnmarshalBinary(data []byte) error

type Ballot

type Ballot struct {
	Simple
	Source   tezos.Address      `json:"source"`
	Period   int32              `json:"period"`
	Proposal tezos.ProtocolHash `json:"proposal"`
	Ballot   tezos.BallotVote   `json:"ballot"`
}

Ballot represents "ballot" operation

func (*Ballot) DecodeBuffer

func (o *Ballot) DecodeBuffer(buf *bytes.Buffer, p *tezos.Params) (err error)

func (Ballot) EncodeBuffer

func (o Ballot) EncodeBuffer(buf *bytes.Buffer, p *tezos.Params) error

func (Ballot) Kind

func (o Ballot) Kind() tezos.OpType

func (Ballot) MarshalBinary

func (o Ballot) MarshalBinary() ([]byte, error)

func (Ballot) MarshalJSON

func (o Ballot) MarshalJSON() ([]byte, error)

func (*Ballot) UnmarshalBinary

func (o *Ballot) UnmarshalBinary(data []byte) error

type BlockHeader

type BlockHeader struct {
	Level            int32                `json:"level"`
	Proto            byte                 `json:"proto"`
	Predecessor      tezos.BlockHash      `json:"predecessor"`
	Timestamp        time.Time            `json:"timestamp"`
	ValidationPass   byte                 `json:"validation_pass"`
	OperationsHash   tezos.OpListListHash `json:"operations_hash"`
	Fitness          []tezos.HexBytes     `json:"fitness"`
	Context          tezos.ContextHash    `json:"context"`
	PayloadHash      tezos.PayloadHash    `json:"payload_hash"`
	PayloadRound     int                  `json:"payload_round"`
	Priority         uint16               `json:"priority"`
	ProofOfWorkNonce tezos.HexBytes       `json:"proof_of_work_nonce"`
	SeedNonceHash    tezos.NonceHash      `json:"seed_nonce_hash"`
	LbEscapeVote     bool                 `json:"liquidity_baking_escape_vote"`
	Signature        tezos.Signature      `json:"signature"`
}

BlockHeader represents block header

func (BlockHeader) Bytes

func (h BlockHeader) Bytes() []byte

Bytes serializes the block header into binary form. When no signature is set, the result can be used as input for signing, if a signature is set the result is ready for broadcast.

func (*BlockHeader) DecodeBuffer

func (h *BlockHeader) DecodeBuffer(buf *bytes.Buffer) (err error)

func (BlockHeader) Digest

func (h BlockHeader) Digest() []byte

Digest returns a 32 byte blake2b hash for signing the block header. The pre-image is binary serialized (without signature) and prefixed with a watermark byte.

func (*BlockHeader) EncodeBuffer

func (h *BlockHeader) EncodeBuffer(buf *bytes.Buffer) error

func (BlockHeader) MarshalBinary

func (h BlockHeader) MarshalBinary() ([]byte, error)

func (BlockHeader) MarshalJSON

func (h BlockHeader) MarshalJSON() ([]byte, error)

func (*BlockHeader) Sign

func (h *BlockHeader) Sign(key tezos.PrivateKey) error

Sign signs the block header using a private key and generates a generic signature. If a valid signature already exists, this function is a noop.

func (*BlockHeader) UnmarshalBinary

func (h *BlockHeader) UnmarshalBinary(data []byte) error

func (BlockHeader) WatermarkedBytes

func (h BlockHeader) WatermarkedBytes() []byte

WatermarkedBytes serializes the block header and prefixes it with a watermark. This format is only used for signing.

func (*BlockHeader) WithSignature

func (h *BlockHeader) WithSignature(sig tezos.Signature) *BlockHeader

WithSignature adds an externally created signature to the block header. Converts any non-generic signature first. No signature validation is performed, it is assumed the signature is correct.

type Delegation

type Delegation struct {
	Manager
	Delegate tezos.Address `json:"delegate"`
}

Delegation represents "delegation" operation

func (*Delegation) DecodeBuffer

func (o *Delegation) DecodeBuffer(buf *bytes.Buffer, p *tezos.Params) (err error)

func (Delegation) EncodeBuffer

func (o Delegation) EncodeBuffer(buf *bytes.Buffer, p *tezos.Params) error

func (Delegation) Kind

func (o Delegation) Kind() tezos.OpType

func (Delegation) MarshalBinary

func (o Delegation) MarshalBinary() ([]byte, error)

func (Delegation) MarshalJSON

func (o Delegation) MarshalJSON() ([]byte, error)

func (*Delegation) UnmarshalBinary

func (o *Delegation) UnmarshalBinary(data []byte) error

type DoubleBakingEvidence

type DoubleBakingEvidence struct {
	Simple
	Bh1 BlockHeader `json:"bh1"`
	Bh2 BlockHeader `json:"bh2"`
}

DoubleBakingEvidence represents "double_baking_evidence" operation

func (*DoubleBakingEvidence) DecodeBuffer

func (o *DoubleBakingEvidence) DecodeBuffer(buf *bytes.Buffer, p *tezos.Params) (err error)

func (DoubleBakingEvidence) EncodeBuffer

func (o DoubleBakingEvidence) EncodeBuffer(buf *bytes.Buffer, p *tezos.Params) error

func (DoubleBakingEvidence) Kind

func (DoubleBakingEvidence) MarshalBinary

func (o DoubleBakingEvidence) MarshalBinary() ([]byte, error)

func (DoubleBakingEvidence) MarshalJSON

func (o DoubleBakingEvidence) MarshalJSON() ([]byte, error)

func (*DoubleBakingEvidence) UnmarshalBinary

func (o *DoubleBakingEvidence) UnmarshalBinary(data []byte) error

type DoubleEndorsementEvidence

type DoubleEndorsementEvidence struct {
	Simple
	Op1  InlinedEndorsement `json:"op1"`
	Op2  InlinedEndorsement `json:"op2"`
	Slot int16              `json:"slot"`
}

DoubleEndorsementEvidence represents "double_endorsement_evidence" operation

func (*DoubleEndorsementEvidence) DecodeBuffer

func (o *DoubleEndorsementEvidence) DecodeBuffer(buf *bytes.Buffer, p *tezos.Params) (err error)

func (DoubleEndorsementEvidence) EncodeBuffer

func (o DoubleEndorsementEvidence) EncodeBuffer(buf *bytes.Buffer, p *tezos.Params) error

func (DoubleEndorsementEvidence) Kind

func (DoubleEndorsementEvidence) MarshalBinary

func (o DoubleEndorsementEvidence) MarshalBinary() ([]byte, error)

func (DoubleEndorsementEvidence) MarshalJSON

func (o DoubleEndorsementEvidence) MarshalJSON() ([]byte, error)

func (*DoubleEndorsementEvidence) UnmarshalBinary

func (o *DoubleEndorsementEvidence) UnmarshalBinary(data []byte) error

type Endorsement

type Endorsement struct {
	Simple
	Level int32 `json:"level"`
}

Endorsement represents "endorsement" operation

func (*Endorsement) DecodeBuffer

func (o *Endorsement) DecodeBuffer(buf *bytes.Buffer, p *tezos.Params) (err error)

func (Endorsement) EncodeBuffer

func (o Endorsement) EncodeBuffer(buf *bytes.Buffer, p *tezos.Params) error

func (Endorsement) Kind

func (o Endorsement) Kind() tezos.OpType

func (Endorsement) MarshalBinary

func (o Endorsement) MarshalBinary() ([]byte, error)

func (Endorsement) MarshalJSON

func (o Endorsement) MarshalJSON() ([]byte, error)

func (*Endorsement) UnmarshalBinary

func (o *Endorsement) UnmarshalBinary(data []byte) error

type EndorsementWithSlot

type EndorsementWithSlot struct {
	Simple
	Endorsement InlinedEndorsement `json:"endorsement"`
	Slot        int16              `json:"slot"`
}

EndorsementWithSlot represents "endorsement_with_slot" operation

func (*EndorsementWithSlot) DecodeBuffer

func (o *EndorsementWithSlot) DecodeBuffer(buf *bytes.Buffer, p *tezos.Params) (err error)

func (EndorsementWithSlot) EncodeBuffer

func (o EndorsementWithSlot) EncodeBuffer(buf *bytes.Buffer, p *tezos.Params) error

func (EndorsementWithSlot) Kind

func (o EndorsementWithSlot) Kind() tezos.OpType

func (EndorsementWithSlot) MarshalBinary

func (o EndorsementWithSlot) MarshalBinary() ([]byte, error)

func (EndorsementWithSlot) MarshalJSON

func (o EndorsementWithSlot) MarshalJSON() ([]byte, error)

func (*EndorsementWithSlot) UnmarshalBinary

func (o *EndorsementWithSlot) UnmarshalBinary(data []byte) error

type FailingNoop

type FailingNoop struct {
	Simple
	Arbitrary string `json:"arbitrary"`
}

FailingNoop represents "failing_noop" operations. Used for signing arbitrary messages and guaranteed to be not included on-chain. This prevents an attack vector where a message is crafted which looks like a regular transaction.

func (*FailingNoop) DecodeBuffer

func (o *FailingNoop) DecodeBuffer(buf *bytes.Buffer, p *tezos.Params) (err error)

func (FailingNoop) EncodeBuffer

func (o FailingNoop) EncodeBuffer(buf *bytes.Buffer, p *tezos.Params) error

func (FailingNoop) Kind

func (o FailingNoop) Kind() tezos.OpType

func (FailingNoop) MarshalBinary

func (o FailingNoop) MarshalBinary() ([]byte, error)

func (FailingNoop) MarshalJSON

func (o FailingNoop) MarshalJSON() ([]byte, error)

func (*FailingNoop) UnmarshalBinary

func (o *FailingNoop) UnmarshalBinary(data []byte) error

type InlinedEndorsement

type InlinedEndorsement struct {
	Branch      tezos.BlockHash `json:"branch"`
	Endorsement Endorsement     `json:"operations"`
	Signature   tezos.Signature `json:"signature"`
}

InlinedEndorsement represents inlined endorsement operation with signature. This type is uses as part of other operations, but is not a stand-alone operation.

func (*InlinedEndorsement) DecodeBuffer

func (o *InlinedEndorsement) DecodeBuffer(buf *bytes.Buffer, p *tezos.Params) (err error)

func (InlinedEndorsement) EncodeBuffer

func (o InlinedEndorsement) EncodeBuffer(buf *bytes.Buffer, p *tezos.Params) error

type Manager

type Manager struct {
	Source       tezos.Address `json:"source"`
	Fee          tezos.N       `json:"fee"`
	Counter      tezos.N       `json:"counter"`
	GasLimit     tezos.N       `json:"gas_limit"`
	StorageLimit tezos.N       `json:"storage_limit"`
}

Manager contains fields common for all manager operations

func (*Manager) DecodeBuffer

func (o *Manager) DecodeBuffer(buf *bytes.Buffer, p *tezos.Params) (err error)

func (Manager) EncodeBuffer

func (o Manager) EncodeBuffer(buf *bytes.Buffer, _ *tezos.Params) error

func (Manager) EncodeJSON

func (o Manager) EncodeJSON(buf *bytes.Buffer) error

func (Manager) GetCounter

func (o Manager) GetCounter() int64

func (Manager) Limits

func (o Manager) Limits() tezos.Limits

func (*Manager) WithCounter

func (o *Manager) WithCounter(c int64)

func (*Manager) WithLimits

func (o *Manager) WithLimits(limits tezos.Limits)

func (*Manager) WithSource

func (o *Manager) WithSource(addr tezos.Address)

type Op

type Op struct {
	Branch    tezos.BlockHash `json:"branch"`
	Contents  []Operation     `json:"contents"`
	Signature tezos.Signature `json:"signature"`
	TTL       int64           `json:"-"`
	Params    *tezos.Params   `json:"-"`
}

Op is a container used to collect, serialize and sign Tezos operations. It serves as a low level building block for constructing and serializing operations, but is agnostic to the order/lifecycle in which data is added or updated.

func DecodeOp

func DecodeOp(data []byte) (*Op, error)

DecodeOp decodes an operation from its binary representation. The encoded data may or may not contain a signature.

func NewOp

func NewOp() *Op

NewOp creates a new empty operation that uses default params and a default operation TTL.

func (*Op) Bytes

func (o *Op) Bytes() []byte

Bytes serializes the operation into binary form. When no signature is set, the result can be used as input for signing, if a signature is set the result is ready to be broadcast. Returns a nil slice when branch or contents are empty.

func (*Op) Digest

func (o *Op) Digest() []byte

Digest returns a 32 byte blake2b hash for signing the operation. The pre-image is the binary serialized operation (without signature) prefixed with a type-dependent watermark byte.

func (Op) Limits

func (o Op) Limits() tezos.Limits

Limits returns the sum of all limits (fee, gas, storage limit) currently set for all contained operations.

func (*Op) MarshalJSON

func (o *Op) MarshalJSON() ([]byte, error)

MarshalJSON conditionally marshals the JSON format of the operation with checks for required fields. Omits signature for unsigned ops so that the encoding is compatible with remote forging.

func (*Op) Sign

func (o *Op) Sign(key tezos.PrivateKey) error

Sign signs the operation using provided private key. If a valid signature already exists this function is a noop. Fails when either branch or contents are empty.

func (*Op) WatermarkedBytes

func (o *Op) WatermarkedBytes() []byte

WatermarkedBytes serializes the operation and prefixes it with a watermark. This format is only used for signing. Watermarked data is not useful anywhere else.

func (*Op) WithBranch

func (o *Op) WithBranch(hash tezos.BlockHash) *Op

WithBranch sets the branch for this operation to hash.

func (*Op) WithContents

func (o *Op) WithContents(op Operation) *Op

WithContents adds a Tezos operation to the end of the contents list.

func (*Op) WithContentsFront

func (o *Op) WithContentsFront(op Operation) *Op

WithContentsFront adds a Tezos operation to the front of the contents list.

func (*Op) WithLimits

func (o *Op) WithLimits(limits []tezos.Limits, margin int64) *Op

WithLimits sets the limits (fee, gas and storage limit) of each contained operation to provided limits. Use this to apply values from simulation with an optional safety margin on gas. This will also calculate the minFee for each operation in the list and add the minFee for header bytes (branch and signature) to the first operation in a list.

Setting a user-defined fee for each individual operation is only honored when its higher than minFee. Note that when sending batch operations all fees must be >= the individual minFee. Otherwise the minFee rule will apply to all zero/lower fee operations and the entire batch may overpay (e.g. if you have the first operation pay all fees for example and set remaining fees to zero).

func (*Op) WithParams

func (o *Op) WithParams(p *tezos.Params) *Op

WithParams defines the protocol and other chain configuration params for which the operation will be encoded. If unset, defaults to tezos.DefaultParams.

func (*Op) WithSignature

func (o *Op) WithSignature(sig tezos.Signature) *Op

WithSignature adds an externally created signature to the operation. No signature validation is performed, it is assumed the signature is correct.

func (*Op) WithSource

func (o *Op) WithSource(addr tezos.Address) *Op

WithSource sets the source for all manager operations to addr.

func (*Op) WithTTL

func (o *Op) WithTTL(n int64) *Op

WithTTL sets a time-to-live for the operation in number of blocks. This may be used as a convenience method instead of setting a branch directly, but requires to use an autocomplete handler, wallet or custom function that fetches the hash of block head~N as branch. Note that serialization will fail until a brach is set.

type Operation

type Operation interface {
	Kind() tezos.OpType
	Limits() tezos.Limits
	GetCounter() int64
	WithSource(tezos.Address)
	WithCounter(int64)
	WithLimits(tezos.Limits)
	encoding.BinaryMarshaler
	encoding.BinaryUnmarshaler
	json.Marshaler
	EncodeBuffer(buf *bytes.Buffer, p *tezos.Params) error
	DecodeBuffer(buf *bytes.Buffer, p *tezos.Params) error
}

Operation is a generic type used to handle different Tezos operation types inside an operation's contents list.

type Origination

type Origination struct {
	Manager
	Balance  tezos.N          `json:"balance"`
	Delegate tezos.Address    `json:"delegate,omitempty"`
	Script   micheline.Script `json:"script"`
}

Origination represents "origination" operation

func (*Origination) DecodeBuffer

func (o *Origination) DecodeBuffer(buf *bytes.Buffer, p *tezos.Params) (err error)

func (Origination) EncodeBuffer

func (o Origination) EncodeBuffer(buf *bytes.Buffer, p *tezos.Params) error

func (Origination) Kind

func (o Origination) Kind() tezos.OpType

func (Origination) MarshalBinary

func (o Origination) MarshalBinary() ([]byte, error)

func (Origination) MarshalJSON

func (o Origination) MarshalJSON() ([]byte, error)

func (*Origination) UnmarshalBinary

func (o *Origination) UnmarshalBinary(data []byte) error

type Proposals

type Proposals struct {
	Simple
	Source    tezos.Address        `json:"source"`
	Period    int32                `json:"period"`
	Proposals []tezos.ProtocolHash `json:"proposals"`
}

Proposals represents "proposals" operation

func (*Proposals) DecodeBuffer

func (o *Proposals) DecodeBuffer(buf *bytes.Buffer, p *tezos.Params) (err error)

func (Proposals) EncodeBuffer

func (o Proposals) EncodeBuffer(buf *bytes.Buffer, p *tezos.Params) error

func (Proposals) Kind

func (o Proposals) Kind() tezos.OpType

func (Proposals) MarshalBinary

func (o Proposals) MarshalBinary() ([]byte, error)

func (Proposals) MarshalJSON

func (o Proposals) MarshalJSON() ([]byte, error)

func (*Proposals) UnmarshalBinary

func (o *Proposals) UnmarshalBinary(data []byte) error

type RegisterGlobalConstant

type RegisterGlobalConstant struct {
	Manager
	Value micheline.Prim `json:"value"`
}

RegisterGlobalConstant represents "register_global_constant" operation

func (*RegisterGlobalConstant) DecodeBuffer

func (o *RegisterGlobalConstant) DecodeBuffer(buf *bytes.Buffer, p *tezos.Params) (err error)

func (RegisterGlobalConstant) EncodeBuffer

func (o RegisterGlobalConstant) EncodeBuffer(buf *bytes.Buffer, p *tezos.Params) error

func (RegisterGlobalConstant) Kind

func (RegisterGlobalConstant) MarshalBinary

func (o RegisterGlobalConstant) MarshalBinary() ([]byte, error)

func (RegisterGlobalConstant) MarshalJSON

func (o RegisterGlobalConstant) MarshalJSON() ([]byte, error)

func (*RegisterGlobalConstant) UnmarshalBinary

func (o *RegisterGlobalConstant) UnmarshalBinary(data []byte) error

type Reveal

type Reveal struct {
	Manager
	PublicKey tezos.Key `json:"public_key"`
}

Reveal represents "reveal" operation

func (*Reveal) DecodeBuffer

func (o *Reveal) DecodeBuffer(buf *bytes.Buffer, p *tezos.Params) (err error)

func (Reveal) EncodeBuffer

func (o Reveal) EncodeBuffer(buf *bytes.Buffer, p *tezos.Params) error

func (Reveal) Kind

func (o Reveal) Kind() tezos.OpType

func (Reveal) MarshalBinary

func (o Reveal) MarshalBinary() ([]byte, error)

func (Reveal) MarshalJSON

func (o Reveal) MarshalJSON() ([]byte, error)

func (*Reveal) UnmarshalBinary

func (o *Reveal) UnmarshalBinary(data []byte) error

type SeedNonceRevelation

type SeedNonceRevelation struct {
	Simple
	Level int32          `json:"level,string"`
	Nonce tezos.HexBytes `json:"nonce"`
}

SeedNonceRevelation represents "seed_nonce_revelation" operation

func (*SeedNonceRevelation) DecodeBuffer

func (o *SeedNonceRevelation) DecodeBuffer(buf *bytes.Buffer, p *tezos.Params) (err error)

func (SeedNonceRevelation) EncodeBuffer

func (o SeedNonceRevelation) EncodeBuffer(buf *bytes.Buffer, p *tezos.Params) error

func (SeedNonceRevelation) Kind

func (o SeedNonceRevelation) Kind() tezos.OpType

func (SeedNonceRevelation) MarshalBinary

func (o SeedNonceRevelation) MarshalBinary() ([]byte, error)

func (SeedNonceRevelation) MarshalJSON

func (o SeedNonceRevelation) MarshalJSON() ([]byte, error)

func (*SeedNonceRevelation) UnmarshalBinary

func (o *SeedNonceRevelation) UnmarshalBinary(data []byte) error

type SetDepositsLimit

type SetDepositsLimit struct {
	Manager
	Limit tezos.N `json:"limit"`
}

SetDepositsLimit represents "set_deposits_limit" operation

func (*SetDepositsLimit) DecodeBuffer

func (o *SetDepositsLimit) DecodeBuffer(buf *bytes.Buffer, p *tezos.Params) (err error)

func (SetDepositsLimit) EncodeBuffer

func (o SetDepositsLimit) EncodeBuffer(buf *bytes.Buffer, p *tezos.Params) error

func (SetDepositsLimit) Kind

func (o SetDepositsLimit) Kind() tezos.OpType

func (SetDepositsLimit) MarshalBinary

func (o SetDepositsLimit) MarshalBinary() ([]byte, error)

func (SetDepositsLimit) MarshalJSON

func (o SetDepositsLimit) MarshalJSON() ([]byte, error)

func (*SetDepositsLimit) UnmarshalBinary

func (o *SetDepositsLimit) UnmarshalBinary(data []byte) error

type Simple

type Simple struct{}

Simple is an empty helper struct that's used to fulfil the Operation interface for anonymous, consensus and voting operations which do not contain fees and counter.

func (Simple) GetCounter

func (o Simple) GetCounter() int64

func (*Simple) Limits

func (o *Simple) Limits() tezos.Limits

func (*Simple) WithCounter

func (o *Simple) WithCounter(int64)

func (*Simple) WithLimits

func (o *Simple) WithLimits(tezos.Limits)

func (*Simple) WithSource

func (o *Simple) WithSource(tezos.Address)

type Transaction

type Transaction struct {
	Manager
	Amount      tezos.N               `json:"amount"`
	Destination tezos.Address         `json:"destination"`
	Parameters  *micheline.Parameters `json:"parameters,omitempty"`
}

Transaction represents "transaction" operation

func (*Transaction) DecodeBuffer

func (o *Transaction) DecodeBuffer(buf *bytes.Buffer, p *tezos.Params) (err error)

func (Transaction) EncodeBuffer

func (o Transaction) EncodeBuffer(buf *bytes.Buffer, p *tezos.Params) error

func (Transaction) Kind

func (o Transaction) Kind() tezos.OpType

func (Transaction) MarshalBinary

func (o Transaction) MarshalBinary() ([]byte, error)

func (Transaction) MarshalJSON

func (o Transaction) MarshalJSON() ([]byte, error)

func (*Transaction) UnmarshalBinary

func (o *Transaction) UnmarshalBinary(data []byte) error

Jump to

Keyboard shortcuts

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