transaction

package
v0.0.0-...-886a677 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2024 License: MIT Imports: 16 Imported by: 14

Documentation

Overview

Package transaction contains Neo transaction definition.

This is one of the core structures of Neo blockchain.

Index

Constants

View Source
const (
	// ReservedLowerBound is the lower bound of reserved attribute types.
	ReservedLowerBound = 0xe0
	// ReservedUpperBound is the upper bound of reserved attribute types.
	ReservedUpperBound = 0xff
)
View Source
const (
	// MaxScriptLength is the limit for transaction's script length.
	MaxScriptLength = math.MaxUint16
	// MaxTransactionSize is the upper limit size in bytes that a transaction can reach. It is
	// set to be 102400.
	MaxTransactionSize = 102400
	// MaxAttributes is maximum number of attributes including signers that can be contained
	// within a transaction. It is set to be 16.
	MaxAttributes = 16
)
View Source
const (
	// MaxInvocationScript is the maximum length of allowed invocation
	// script. It should fit 11/21 multisignature for the committee.
	MaxInvocationScript = 1024

	// MaxVerificationScript is the maximum allowed length of verification
	// script. It should be appropriate for 11/21 multisignature committee.
	MaxVerificationScript = 1024
)
View Source
const MaxOracleResultSize = math.MaxUint16

MaxOracleResultSize is the maximum allowed oracle answer size.

Variables

View Source
var (
	ErrInvalidResponseCode = errors.New("invalid oracle response code")
	ErrInvalidResult       = errors.New("oracle response != success, but result is not empty")
)

Various validation errors.

View Source
var (
	ErrInvalidVersion     = errors.New("only version 0 is supported")
	ErrNegativeSystemFee  = errors.New("negative system fee")
	ErrNegativeNetworkFee = errors.New("negative network fee")
	ErrTooBigFees         = errors.New("too big fees: int64 overflow")
	ErrEmptySigners       = errors.New("signers array should contain sender")
	ErrNonUniqueSigners   = errors.New("transaction signers should be unique")
	ErrInvalidAttribute   = errors.New("invalid attribute")
	ErrEmptyScript        = errors.New("no script")
)

Various errors for transaction validation.

View Source
var ErrInvalidWitnessNum = errors.New("number of signers doesn't match witnesses")

ErrInvalidWitnessNum returns when the number of witnesses does not match signers.

Functions

func IsValidAttrType

func IsValidAttrType(reservedAttributesEnabled bool, attrType AttrType) bool

IsValidAttrType returns whether the provided attribute type is valid.

func SignersToStackItem

func SignersToStackItem(signers []Signer) stackitem.Item

SignersToStackItem converts transaction.Signers to stackitem.Item.

Types

type AttrType

type AttrType uint8

AttrType represents the purpose of the attribute.

const (
	HighPriority    AttrType = 1
	OracleResponseT AttrType = 0x11 // OracleResponse
	NotValidBeforeT AttrType = 0x20 // NotValidBefore
	ConflictsT      AttrType = 0x21 // Conflicts
	NotaryAssistedT AttrType = 0x22 // NotaryAssisted
)

List of valid attribute types.

func (AttrType) String

func (i AttrType) String() string

type AttrValue

type AttrValue interface {
	io.Serializable

	// Copy returns a deep copy of the attribute value.
	Copy() AttrValue
	// contains filtered or unexported methods
}

AttrValue represents a Transaction Attribute value.

type Attribute

type Attribute struct {
	Type  AttrType
	Value AttrValue
}

Attribute represents a Transaction attribute.

func (*Attribute) Copy

func (attr *Attribute) Copy() *Attribute

Copy creates a deep copy of the Attribute.

func (*Attribute) DecodeBinary

func (attr *Attribute) DecodeBinary(br *io.BinReader)

DecodeBinary implements the Serializable interface.

func (*Attribute) EncodeBinary

func (attr *Attribute) EncodeBinary(bw *io.BinWriter)

EncodeBinary implements the Serializable interface.

func (*Attribute) MarshalJSON

func (attr *Attribute) MarshalJSON() ([]byte, error)

MarshalJSON implements the json Marshaller interface.

func (*Attribute) UnmarshalJSON

func (attr *Attribute) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaller interface.

type ConditionAnd

type ConditionAnd []WitnessCondition

ConditionAnd is a set of conditions required to match.

func (*ConditionAnd) Copy

func (c *ConditionAnd) Copy() WitnessCondition

Copy implements the WitnessCondition interface and returns a deep copy of the condition.

func (*ConditionAnd) DecodeBinarySpecific

func (c *ConditionAnd) DecodeBinarySpecific(r *io.BinReader, maxDepth int)

DecodeBinarySpecific implements the WitnessCondition interface allowing to deserialize condition-specific data.

func (*ConditionAnd) EncodeBinary

func (c *ConditionAnd) EncodeBinary(w *io.BinWriter)

EncodeBinary implements the WitnessCondition interface allowing to serialize condition.

func (*ConditionAnd) MarshalJSON

func (c *ConditionAnd) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*ConditionAnd) Match

func (c *ConditionAnd) Match(ctx MatchContext) (bool, error)

Match implements the WitnessCondition interface checking whether this condition matches given context.

func (*ConditionAnd) ToStackItem

func (c *ConditionAnd) ToStackItem() stackitem.Item

ToStackItem implements the WitnessCondition interface allowing to convert to stackitem.Item.

func (*ConditionAnd) Type

Type implements the WitnessCondition interface and returns condition type.

type ConditionBoolean

type ConditionBoolean bool

ConditionBoolean is a boolean condition type.

func (*ConditionBoolean) Copy

Copy returns a deep copy of the condition.

func (*ConditionBoolean) DecodeBinarySpecific

func (c *ConditionBoolean) DecodeBinarySpecific(r *io.BinReader, maxDepth int)

DecodeBinarySpecific implements the WitnessCondition interface allowing to deserialize condition-specific data.

func (*ConditionBoolean) EncodeBinary

func (c *ConditionBoolean) EncodeBinary(w *io.BinWriter)

EncodeBinary implements the WitnessCondition interface allowing to serialize condition.

func (*ConditionBoolean) MarshalJSON

func (c *ConditionBoolean) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*ConditionBoolean) Match

func (c *ConditionBoolean) Match(_ MatchContext) (bool, error)

Match implements the WitnessCondition interface checking whether this condition matches given context.

func (*ConditionBoolean) ToStackItem

func (c *ConditionBoolean) ToStackItem() stackitem.Item

ToStackItem implements WitnessCondition interface allowing to convert to stackitem.Item.

func (*ConditionBoolean) Type

Type implements the WitnessCondition interface and returns condition type.

type ConditionCalledByContract

type ConditionCalledByContract util.Uint160

ConditionCalledByContract is a condition matching calling script hash.

func (*ConditionCalledByContract) Copy

Copy implements the WitnessCondition interface and returns a deep copy of the condition.

func (*ConditionCalledByContract) DecodeBinarySpecific

func (c *ConditionCalledByContract) DecodeBinarySpecific(r *io.BinReader, _ int)

DecodeBinarySpecific implements the WitnessCondition interface allowing to deserialize condition-specific data.

func (*ConditionCalledByContract) EncodeBinary

func (c *ConditionCalledByContract) EncodeBinary(w *io.BinWriter)

EncodeBinary implements the WitnessCondition interface allowing to serialize condition.

func (*ConditionCalledByContract) MarshalJSON

func (c *ConditionCalledByContract) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*ConditionCalledByContract) Match

Match implements the WitnessCondition interface checking whether this condition matches given context.

func (*ConditionCalledByContract) ToStackItem

func (c *ConditionCalledByContract) ToStackItem() stackitem.Item

ToStackItem implements the WitnessCondition interface allowing to convert to stackitem.Item.

func (*ConditionCalledByContract) Type

Type implements the WitnessCondition interface and returns condition type.

type ConditionCalledByEntry

type ConditionCalledByEntry struct{}

ConditionCalledByEntry is a condition matching entry script or one directly called by it.

func (ConditionCalledByEntry) Copy

Copy implements the WitnessCondition interface and returns a deep copy of the condition.

func (ConditionCalledByEntry) DecodeBinarySpecific

func (c ConditionCalledByEntry) DecodeBinarySpecific(_ *io.BinReader, _ int)

DecodeBinarySpecific implements the WitnessCondition interface allowing to deserialize condition-specific data.

func (ConditionCalledByEntry) EncodeBinary

func (c ConditionCalledByEntry) EncodeBinary(w *io.BinWriter)

EncodeBinary implements the WitnessCondition interface allowing to serialize condition.

func (ConditionCalledByEntry) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface.

func (ConditionCalledByEntry) Match

Match implements the WitnessCondition interface checking whether this condition matches given context.

func (ConditionCalledByEntry) ToStackItem

func (c ConditionCalledByEntry) ToStackItem() stackitem.Item

ToStackItem implements the WitnessCondition interface allowing to convert to stackitem.Item.

func (ConditionCalledByEntry) Type

Type implements the WitnessCondition interface and returns condition type.

type ConditionCalledByGroup

type ConditionCalledByGroup keys.PublicKey

ConditionCalledByGroup is a condition matching calling script group.

func (*ConditionCalledByGroup) Copy

Copy implements the WitnessCondition interface and returns a deep copy of the condition.

func (*ConditionCalledByGroup) DecodeBinarySpecific

func (c *ConditionCalledByGroup) DecodeBinarySpecific(r *io.BinReader, _ int)

DecodeBinarySpecific implements the WitnessCondition interface allowing to deserialize condition-specific data.

func (*ConditionCalledByGroup) EncodeBinary

func (c *ConditionCalledByGroup) EncodeBinary(w *io.BinWriter)

EncodeBinary implements the WitnessCondition interface allowing to serialize condition.

func (*ConditionCalledByGroup) MarshalJSON

func (c *ConditionCalledByGroup) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*ConditionCalledByGroup) Match

func (c *ConditionCalledByGroup) Match(ctx MatchContext) (bool, error)

Match implements the WitnessCondition interface checking whether this condition matches given context.

func (*ConditionCalledByGroup) ToStackItem

func (c *ConditionCalledByGroup) ToStackItem() stackitem.Item

ToStackItem implements WitnessCondition interface allowing to convert to stackitem.Item.

func (*ConditionCalledByGroup) Type

Type implements the WitnessCondition interface and returns condition type.

type ConditionGroup

type ConditionGroup keys.PublicKey

ConditionGroup is a condition matching executing script group.

func (*ConditionGroup) Copy

func (c *ConditionGroup) Copy() WitnessCondition

Copy implements the WitnessCondition interface and returns a deep copy of the condition.

func (*ConditionGroup) DecodeBinarySpecific

func (c *ConditionGroup) DecodeBinarySpecific(r *io.BinReader, _ int)

DecodeBinarySpecific implements the WitnessCondition interface allowing to deserialize condition-specific data.

func (*ConditionGroup) EncodeBinary

func (c *ConditionGroup) EncodeBinary(w *io.BinWriter)

EncodeBinary implements the WitnessCondition interface allowing to serialize condition.

func (*ConditionGroup) MarshalJSON

func (c *ConditionGroup) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*ConditionGroup) Match

func (c *ConditionGroup) Match(ctx MatchContext) (bool, error)

Match implements the WitnessCondition interface checking whether this condition matches given context.

func (*ConditionGroup) ToStackItem

func (c *ConditionGroup) ToStackItem() stackitem.Item

ToStackItem implements the WitnessCondition interface allowing to convert to stackitem.Item.

func (*ConditionGroup) Type

Type implements the WitnessCondition interface and returns condition type.

type ConditionNot

type ConditionNot struct {
	Condition WitnessCondition
}

ConditionNot inverses the meaning of contained condition.

func (*ConditionNot) Copy

func (c *ConditionNot) Copy() WitnessCondition

Copy implements the WitnessCondition interface and returns a deep copy of the condition.

func (*ConditionNot) DecodeBinarySpecific

func (c *ConditionNot) DecodeBinarySpecific(r *io.BinReader, maxDepth int)

DecodeBinarySpecific implements the WitnessCondition interface allowing to deserialize condition-specific data.

func (*ConditionNot) EncodeBinary

func (c *ConditionNot) EncodeBinary(w *io.BinWriter)

EncodeBinary implements the WitnessCondition interface allowing to serialize condition.

func (*ConditionNot) MarshalJSON

func (c *ConditionNot) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*ConditionNot) Match

func (c *ConditionNot) Match(ctx MatchContext) (bool, error)

Match implements the WitnessCondition interface checking whether this condition matches given context.

func (*ConditionNot) ToStackItem

func (c *ConditionNot) ToStackItem() stackitem.Item

ToStackItem implements the WitnessCondition interface allowing to convert to stackitem.Item.

func (*ConditionNot) Type

Type implements the WitnessCondition interface and returns condition type.

type ConditionOr

type ConditionOr []WitnessCondition

ConditionOr is a set of conditions one of which is required to match.

func (*ConditionOr) Copy

func (c *ConditionOr) Copy() WitnessCondition

Copy implements the WitnessCondition interface and returns a deep copy of the condition.

func (*ConditionOr) DecodeBinarySpecific

func (c *ConditionOr) DecodeBinarySpecific(r *io.BinReader, maxDepth int)

DecodeBinarySpecific implements the WitnessCondition interface allowing to deserialize condition-specific data.

func (*ConditionOr) EncodeBinary

func (c *ConditionOr) EncodeBinary(w *io.BinWriter)

EncodeBinary implements the WitnessCondition interface allowing to serialize condition.

func (*ConditionOr) MarshalJSON

func (c *ConditionOr) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*ConditionOr) Match

func (c *ConditionOr) Match(ctx MatchContext) (bool, error)

Match implements the WitnessCondition interface checking whether this condition matches given context.

func (*ConditionOr) ToStackItem

func (c *ConditionOr) ToStackItem() stackitem.Item

ToStackItem implements the WitnessCondition interface allowing to convert to stackitem.Item.

func (*ConditionOr) Type

Type implements the WitnessCondition interface and returns condition type.

type ConditionScriptHash

type ConditionScriptHash util.Uint160

ConditionScriptHash is a condition matching executing script hash.

func (*ConditionScriptHash) Copy

Copy implements the WitnessCondition interface and returns a deep copy of the condition.

func (*ConditionScriptHash) DecodeBinarySpecific

func (c *ConditionScriptHash) DecodeBinarySpecific(r *io.BinReader, _ int)

DecodeBinarySpecific implements the WitnessCondition interface allowing to deserialize condition-specific data.

func (*ConditionScriptHash) EncodeBinary

func (c *ConditionScriptHash) EncodeBinary(w *io.BinWriter)

EncodeBinary implements the WitnessCondition interface allowing to serialize condition.

func (*ConditionScriptHash) MarshalJSON

func (c *ConditionScriptHash) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*ConditionScriptHash) Match

func (c *ConditionScriptHash) Match(ctx MatchContext) (bool, error)

Match implements the WitnessCondition interface checking whether this condition matches given context.

func (*ConditionScriptHash) ToStackItem

func (c *ConditionScriptHash) ToStackItem() stackitem.Item

ToStackItem implements the WitnessCondition interface allowing to convert to stackitem.Item.

func (*ConditionScriptHash) Type

Type implements the WitnessCondition interface and returns condition type.

type Conflicts

type Conflicts struct {
	Hash util.Uint256 `json:"hash"`
}

Conflicts represents attribute for conflicting transactions.

func (*Conflicts) Copy

func (c *Conflicts) Copy() AttrValue

Copy implements the AttrValue interface.

func (*Conflicts) DecodeBinary

func (c *Conflicts) DecodeBinary(br *io.BinReader)

DecodeBinary implements the io.Serializable interface.

func (*Conflicts) EncodeBinary

func (c *Conflicts) EncodeBinary(w *io.BinWriter)

EncodeBinary implements the io.Serializable interface.

type MatchContext

type MatchContext interface {
	GetCallingScriptHash() util.Uint160
	GetCurrentScriptHash() util.Uint160
	CallingScriptHasGroup(*keys.PublicKey) (bool, error)
	CurrentScriptHasGroup(*keys.PublicKey) (bool, error)
	IsCalledByEntry() bool
}

MatchContext is a set of methods from execution engine needed to perform the witness check.

type NotValidBefore

type NotValidBefore struct {
	Height uint32 `json:"height"`
}

NotValidBefore represents attribute with the height transaction is not valid before.

func (*NotValidBefore) Copy

func (n *NotValidBefore) Copy() AttrValue

Copy implements the AttrValue interface.

func (*NotValidBefore) DecodeBinary

func (n *NotValidBefore) DecodeBinary(br *io.BinReader)

DecodeBinary implements the io.Serializable interface.

func (*NotValidBefore) EncodeBinary

func (n *NotValidBefore) EncodeBinary(w *io.BinWriter)

EncodeBinary implements the io.Serializable interface.

type NotaryAssisted

type NotaryAssisted struct {
	NKeys uint8 `json:"nkeys"`
}

NotaryAssisted represents attribute for notary service transactions.

func (*NotaryAssisted) Copy

func (n *NotaryAssisted) Copy() AttrValue

Copy implements the AttrValue interface.

func (*NotaryAssisted) DecodeBinary

func (n *NotaryAssisted) DecodeBinary(br *io.BinReader)

DecodeBinary implements the io.Serializable interface.

func (*NotaryAssisted) EncodeBinary

func (n *NotaryAssisted) EncodeBinary(w *io.BinWriter)

EncodeBinary implements the io.Serializable interface.

type OracleResponse

type OracleResponse struct {
	ID     uint64             `json:"id"`
	Code   OracleResponseCode `json:"code"`
	Result []byte             `json:"result"`
}

OracleResponse represents oracle response.

func (*OracleResponse) Copy

func (r *OracleResponse) Copy() AttrValue

Copy implements the AttrValue interface.

func (*OracleResponse) DecodeBinary

func (r *OracleResponse) DecodeBinary(br *io.BinReader)

DecodeBinary implements the io.Serializable interface.

func (*OracleResponse) EncodeBinary

func (r *OracleResponse) EncodeBinary(w *io.BinWriter)

EncodeBinary implements the io.Serializable interface.

type OracleResponseCode

type OracleResponseCode byte

OracleResponseCode represents result code of oracle response.

const (
	Success                 OracleResponseCode = 0x00
	ProtocolNotSupported    OracleResponseCode = 0x10
	ConsensusUnreachable    OracleResponseCode = 0x12
	NotFound                OracleResponseCode = 0x14
	Timeout                 OracleResponseCode = 0x16
	Forbidden               OracleResponseCode = 0x18
	ResponseTooLarge        OracleResponseCode = 0x1a
	InsufficientFunds       OracleResponseCode = 0x1c
	ContentTypeNotSupported OracleResponseCode = 0x1f
	Error                   OracleResponseCode = 0xff
)

Enumeration of possible oracle response types.

func (OracleResponseCode) IsValid

func (c OracleResponseCode) IsValid() bool

IsValid checks if c is valid response code.

func (OracleResponseCode) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface.

func (OracleResponseCode) String

func (i OracleResponseCode) String() string

func (*OracleResponseCode) UnmarshalJSON

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

UnmarshalJSON implements the json.Unmarshaler interface.

type Reserved

type Reserved struct {
	Value []byte
}

Reserved represents an attribute for experimental or private usage.

func (*Reserved) Copy

func (e *Reserved) Copy() AttrValue

Copy implements the AttrValue interface.

func (*Reserved) DecodeBinary

func (e *Reserved) DecodeBinary(br *io.BinReader)

DecodeBinary implements the io.Serializable interface.

func (*Reserved) EncodeBinary

func (e *Reserved) EncodeBinary(w *io.BinWriter)

EncodeBinary implements the io.Serializable interface.

type Signer

type Signer struct {
	Account          util.Uint160      `json:"account"`
	Scopes           WitnessScope      `json:"scopes"`
	AllowedContracts []util.Uint160    `json:"allowedcontracts,omitempty"`
	AllowedGroups    []*keys.PublicKey `json:"allowedgroups,omitempty"`
	Rules            []WitnessRule     `json:"rules,omitempty"`
}

Signer implements a Transaction signer.

func (*Signer) Copy

func (c *Signer) Copy() *Signer

Copy creates a deep copy of the Signer.

func (*Signer) DecodeBinary

func (c *Signer) DecodeBinary(br *io.BinReader)

DecodeBinary implements the Serializable interface.

func (*Signer) EncodeBinary

func (c *Signer) EncodeBinary(bw *io.BinWriter)

EncodeBinary implements the Serializable interface.

type Transaction

type Transaction struct {
	// The trading version which is currently 0.
	Version uint8

	// Random number to avoid hash collision.
	Nonce uint32

	// Fee to be burned.
	SystemFee int64

	// Fee to be distributed to consensus nodes.
	NetworkFee int64

	// Maximum blockchain height exceeding which
	// transaction should fail verification. E.g. if VUB=N, then transaction
	// can be accepted to block with index N, but not to block with index N+1.
	ValidUntilBlock uint32

	// Code to run in NeoVM for this transaction.
	Script []byte

	// Transaction attributes.
	Attributes []Attribute

	// Transaction signers list (starts with Sender).
	Signers []Signer

	// The scripts that comes with this transaction.
	// Scripts exist out of the verification script
	// and invocation script.
	Scripts []Witness

	// Trimmed indicates this is a transaction from trimmed
	// data.
	Trimmed bool
	// contains filtered or unexported fields
}

Transaction is a process recorded in the Neo blockchain.

func New

func New(script []byte, gas int64) *Transaction

New returns a new transaction to execute given script and pay given system fee.

func NewTransactionFromBytes

func NewTransactionFromBytes(b []byte) (*Transaction, error)

NewTransactionFromBytes decodes byte array into *Transaction.

func NewTrimmedTX

func NewTrimmedTX(hash util.Uint256) *Transaction

NewTrimmedTX returns a trimmed transaction with only its hash and Trimmed to true.

func (*Transaction) Bytes

func (t *Transaction) Bytes() []byte

Bytes converts the transaction to []byte.

func (*Transaction) Copy

func (t *Transaction) Copy() *Transaction

Copy creates a deep copy of the Transaction, including all slice fields. Cached values like 'hashed' and 'size' are reset to ensure the copy can be modified independently of the original.

func (*Transaction) DecodeBinary

func (t *Transaction) DecodeBinary(br *io.BinReader)

DecodeBinary implements the Serializable interface.

func (*Transaction) DecodeHashableFields

func (t *Transaction) DecodeHashableFields(buf []byte) error

DecodeHashableFields decodes a part of transaction which should be hashed.

func (*Transaction) EncodeBinary

func (t *Transaction) EncodeBinary(bw *io.BinWriter)

EncodeBinary implements the Serializable interface.

func (*Transaction) EncodeHashableFields

func (t *Transaction) EncodeHashableFields() ([]byte, error)

EncodeHashableFields returns serialized transaction's fields which are hashed.

func (*Transaction) FeePerByte

func (t *Transaction) FeePerByte() int64

FeePerByte returns NetworkFee of the transaction divided by its size.

func (*Transaction) GetAttributes

func (t *Transaction) GetAttributes(typ AttrType) []Attribute

GetAttributes returns the list of transaction's attributes of the given type. Returns nil in case if attributes not found.

func (*Transaction) HasAttribute

func (t *Transaction) HasAttribute(typ AttrType) bool

HasAttribute returns true iff t has an attribute of type typ.

func (*Transaction) HasSigner

func (t *Transaction) HasSigner(hash util.Uint160) bool

HasSigner returns true in case if hash is present in the list of signers.

func (*Transaction) Hash

func (t *Transaction) Hash() util.Uint256

Hash returns the hash of the transaction.

func (*Transaction) MarshalJSON

func (t *Transaction) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*Transaction) Sender

func (t *Transaction) Sender() util.Uint160

Sender returns the sender of the transaction which is always on the first place in the transaction's signers list.

func (*Transaction) Size

func (t *Transaction) Size() int

Size returns size of the serialized transaction.

func (*Transaction) ToStackItem

func (t *Transaction) ToStackItem() stackitem.Item

ToStackItem converts Transaction to stackitem.Item.

func (*Transaction) UnmarshalJSON

func (t *Transaction) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type Witness

type Witness struct {
	InvocationScript   []byte `json:"invocation"`
	VerificationScript []byte `json:"verification"`
}

Witness contains 2 scripts.

func (Witness) Copy

func (w Witness) Copy() Witness

Copy creates a deep copy of the Witness.

func (*Witness) DecodeBinary

func (w *Witness) DecodeBinary(br *io.BinReader)

DecodeBinary implements the Serializable interface.

func (*Witness) EncodeBinary

func (w *Witness) EncodeBinary(bw *io.BinWriter)

EncodeBinary implements the Serializable interface.

func (Witness) ScriptHash

func (w Witness) ScriptHash() util.Uint160

ScriptHash returns the hash of the VerificationScript.

type WitnessAction

type WitnessAction byte

WitnessAction represents an action to perform in WitnessRule if WitnessCondition matches.

const (
	// WitnessDeny rejects current witness if condition is met.
	WitnessDeny WitnessAction = 0 // Deny
	// WitnessAllow approves current witness if condition is met.
	WitnessAllow WitnessAction = 1 // Allow
)

func (WitnessAction) String

func (i WitnessAction) String() string

type WitnessCondition

type WitnessCondition interface {
	// Type returns a type of this condition.
	Type() WitnessConditionType
	// Match checks whether this condition matches current context.
	Match(MatchContext) (bool, error)
	// EncodeBinary allows to serialize condition to its binary
	// representation (including type data).
	EncodeBinary(*io.BinWriter)
	// DecodeBinarySpecific decodes type-specific binary data from the given
	// reader (not including type data).
	DecodeBinarySpecific(*io.BinReader, int)
	// ToStackItem converts WitnessCondition to stackitem.Item.
	ToStackItem() stackitem.Item
	// Copy returns a deep copy of the condition.
	Copy() WitnessCondition

	json.Marshaler
}

WitnessCondition is a condition of WitnessRule.

func DecodeBinaryCondition

func DecodeBinaryCondition(r *io.BinReader) WitnessCondition

DecodeBinaryCondition decodes and returns condition from the given binary stream.

func UnmarshalConditionJSON

func UnmarshalConditionJSON(data []byte) (WitnessCondition, error)

UnmarshalConditionJSON unmarshalls condition from the given JSON data.

type WitnessConditionType

type WitnessConditionType byte

WitnessConditionType encodes a type of witness condition.

const (
	// WitnessBoolean is a generic boolean condition.
	WitnessBoolean WitnessConditionType = 0x00 // Boolean
	// WitnessNot reverses another condition.
	WitnessNot WitnessConditionType = 0x01 // Not
	// WitnessAnd means that all conditions must be met.
	WitnessAnd WitnessConditionType = 0x02 // And
	// WitnessOr means that any of conditions must be met.
	WitnessOr WitnessConditionType = 0x03 // Or
	// WitnessScriptHash matches executing contract's script hash.
	WitnessScriptHash WitnessConditionType = 0x18 // ScriptHash
	// WitnessGroup matches executing contract's group key.
	WitnessGroup WitnessConditionType = 0x19 // Group
	// WitnessCalledByEntry matches when current script is an entry script or is called by an entry script.
	WitnessCalledByEntry WitnessConditionType = 0x20 // CalledByEntry
	// WitnessCalledByContract matches when current script is called by the specified contract.
	WitnessCalledByContract WitnessConditionType = 0x28 // CalledByContract
	// WitnessCalledByGroup matches when current script is called by contract belonging to the specified group.
	WitnessCalledByGroup WitnessConditionType = 0x29 // CalledByGroup

	// MaxConditionNesting limits the maximum allowed level of condition nesting.
	MaxConditionNesting = 2
)

func (WitnessConditionType) String

func (i WitnessConditionType) String() string

type WitnessRule

type WitnessRule struct {
	Action    WitnessAction    `json:"action"`
	Condition WitnessCondition `json:"condition"`
}

WitnessRule represents a single rule for Rules witness scope.

func (*WitnessRule) Copy

func (w *WitnessRule) Copy() *WitnessRule

Copy creates a deep copy of the WitnessRule.

func (*WitnessRule) DecodeBinary

func (w *WitnessRule) DecodeBinary(br *io.BinReader)

DecodeBinary implements the Serializable interface.

func (*WitnessRule) EncodeBinary

func (w *WitnessRule) EncodeBinary(bw *io.BinWriter)

EncodeBinary implements the Serializable interface.

func (*WitnessRule) MarshalJSON

func (w *WitnessRule) MarshalJSON() ([]byte, error)

UnmarshalJSON implements the json.Unmarshaler interface.

func (*WitnessRule) ToStackItem

func (w *WitnessRule) ToStackItem() stackitem.Item

ToStackItem implements Convertible interface.

func (*WitnessRule) UnmarshalJSON

func (w *WitnessRule) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type WitnessScope

type WitnessScope byte

WitnessScope represents set of witness flags for Transaction signer.

const (
	// None specifies that no contract was witnessed. Only sign the transaction.
	None WitnessScope = 0
	// CalledByEntry witness is only valid in entry script and ones directly called by it.
	// No params is needed, as the witness/permission/signature given on first invocation will
	// automatically expire if entering deeper internal invokes. This can be default safe
	// choice for native NEO/GAS (previously used on Neo 2 as "attach" mode).
	CalledByEntry WitnessScope = 0x01
	// CustomContracts define custom hash for contract-specific.
	CustomContracts WitnessScope = 0x10
	// CustomGroups define custom pubkey for group members.
	CustomGroups WitnessScope = 0x20
	// Rules is a set of conditions with boolean operators.
	Rules WitnessScope = 0x40 // WitnessRules
	// Global allows this witness in all contexts (default Neo2 behavior).
	// This cannot be combined with other flags.
	Global WitnessScope = 0x80
)

func ScopesFromByte

func ScopesFromByte(b byte) (WitnessScope, error)

ScopesFromByte converts byte to a set of WitnessScopes and performs validity check.

func ScopesFromString

func ScopesFromString(s string) (WitnessScope, error)

ScopesFromString converts string of comma-separated scopes to a set of scopes (case-sensitive). String can combine several scopes, e.g. be any of: 'Global', 'CalledByEntry,CustomGroups' etc. In case of an empty string an error will be returned.

func (WitnessScope) MarshalJSON

func (s WitnessScope) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (WitnessScope) String

func (i WitnessScope) String() string

func (*WitnessScope) UnmarshalJSON

func (s *WitnessScope) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

Jump to

Keyboard shortcuts

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