transaction

package
v0.93.0-pre Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2020 License: MIT Imports: 15 Imported by: 43

Documentation

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
	// MaxValidUntilBlockIncrement is the upper increment size of blockhain height in blocks
	// exceeding that a transaction should fail validation. It is set to estimated daily number
	// of blocks with 15s interval.
	MaxValidUntilBlockIncrement = 5760
	// MaxAttributes is maximum number of attributes including signers that can be contained
	// within a transaction. It is set to be 16.
	MaxAttributes = 16
	// DummyVersion represents reserved transaction version for trimmed transactions.
	DummyVersion = 255
)
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.

View Source
const NotaryServiceFeePerKey = 1000_0000 // 0.1 GAS

NotaryServiceFeePerKey is a reward per key for notary nodes.

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.

Functions

This section is empty.

Types

type AttrType added in v0.91.0

type AttrType uint8

AttrType represents the purpose of the attribute.

const (
	HighPriority    AttrType = 1
	OracleResponseT AttrType = 0x11                   // OracleResponse
	NotValidBeforeT AttrType = ReservedLowerBound     // NotValidBefore
	ConflictsT      AttrType = ReservedLowerBound + 1 // Conflicts
	NotaryAssistedT AttrType = ReservedLowerBound + 2 // NotaryAssisted
)

List of valid attribute types.

func (AttrType) String added in v0.92.0

func (i AttrType) String() string

type Attribute

type Attribute struct {
	Type  AttrType
	Value interface {
		io.Serializable
		// contains filtered or unexported methods
	}
}

Attribute represents a Transaction attribute.

func (*Attribute) DecodeBinary

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

DecodeBinary implements Serializable interface.

func (*Attribute) EncodeBinary

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

EncodeBinary implements Serializable interface.

func (*Attribute) MarshalJSON

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

MarshalJSON implements the json Marshaller interface.

func (*Attribute) UnmarshalJSON added in v0.75.0

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

UnmarshalJSON implements the json.Unmarshaller interface.

type Conflicts added in v0.92.0

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

Conflicts represents attribute for conflicting transactions.

func (*Conflicts) DecodeBinary added in v0.92.0

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

DecodeBinary implements io.Serializable interface.

func (*Conflicts) EncodeBinary added in v0.92.0

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

EncodeBinary implements io.Serializable interface.

type NotValidBefore added in v0.92.0

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

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

func (*NotValidBefore) DecodeBinary added in v0.92.0

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

DecodeBinary implements io.Serializable interface.

func (*NotValidBefore) EncodeBinary added in v0.92.0

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

EncodeBinary implements io.Serializable interface.

type NotaryAssisted added in v0.92.0

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

NotaryAssisted represents attribute for notary service transactions.

func (*NotaryAssisted) DecodeBinary added in v0.92.0

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

DecodeBinary implements io.Serializable interface.

func (*NotaryAssisted) EncodeBinary added in v0.92.0

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

EncodeBinary implements io.Serializable interface.

type OracleResponse added in v0.92.0

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

OracleResponse represents oracle response.

func (*OracleResponse) DecodeBinary added in v0.92.0

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

DecodeBinary implements io.Serializable interface.

func (*OracleResponse) EncodeBinary added in v0.92.0

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

EncodeBinary implements io.Serializable interface.

type OracleResponseCode added in v0.92.0

type OracleResponseCode byte

OracleResponseCode represents result code of oracle response.

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

Enumeration of possible oracle response types.

func (OracleResponseCode) IsValid added in v0.92.0

func (c OracleResponseCode) IsValid() bool

IsValid checks if c is valid response code.

type Reserved added in v0.92.0

type Reserved struct {
	Value []byte
}

Reserved represents an attribute for experimental or private usage.

func (*Reserved) DecodeBinary added in v0.92.0

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

DecodeBinary implements io.Serializable interface.

func (*Reserved) EncodeBinary added in v0.92.0

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

EncodeBinary implements io.Serializable interface.

type Signer added in v0.91.0

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

Signer implements a Transaction signer.

func (*Signer) DecodeBinary added in v0.91.0

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

DecodeBinary implements Serializable interface.

func (*Signer) EncodeBinary added in v0.91.0

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

EncodeBinary implements 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.
	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

	// Network magic number. This one actually is not a part of the
	// wire-representation of Transaction, but it's absolutely necessary
	// for correct signing/verification.
	Network netmode.Magic

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

func New(network netmode.Magic, script []byte, gas int64) *Transaction

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

func NewTransactionFromBytes added in v0.90.0

func NewTransactionFromBytes(network netmode.Magic, 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) DecodeBinary

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

DecodeBinary implements Serializable interface.

func (*Transaction) DecodeSignedPart added in v0.90.0

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

DecodeSignedPart decodes a part of transaction from GetSignedPart data.

func (*Transaction) EncodeBinary

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

EncodeBinary implements Serializable interface.

func (*Transaction) FeePerByte added in v0.90.0

func (t *Transaction) FeePerByte() int64

FeePerByte returns NetworkFee of the transaction divided by its size

func (*Transaction) GetAttributes added in v0.92.0

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) GetSignedHash added in v0.92.0

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

GetSignedHash returns a hash of the transaction used to verify it.

func (*Transaction) GetSignedPart

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

GetSignedPart returns a part of the transaction which must be signed.

func (*Transaction) HasAttribute added in v0.92.0

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

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

func (*Transaction) HasSigner added in v0.92.0

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

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

MarshalJSON implements json.Marshaler interface.

func (*Transaction) Sender added in v0.90.0

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

func (t *Transaction) Size() int

Size returns size of the serialized transaction.

func (*Transaction) UnmarshalJSON added in v0.75.0

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

UnmarshalJSON implements json.Unmarshaler interface.

type Witness

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

Witness contains 2 scripts.

func (*Witness) DecodeBinary

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

DecodeBinary implements Serializable interface.

func (*Witness) EncodeBinary

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

EncodeBinary implements Serializable interface.

func (Witness) ScriptHash

func (w Witness) ScriptHash() util.Uint160

ScriptHash returns the hash of the VerificationScript.

type WitnessScope added in v0.90.0

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 means that this condition must hold: EntryScriptHash == CallingScriptHash.
	// 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
	// Global allows this witness in all contexts (default Neo2 behavior).
	// This cannot be combined with other flags.
	Global WitnessScope = 0x80
)

func ScopesFromString added in v0.90.0

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

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

MarshalJSON implements json.Marshaler interface.

func (WitnessScope) String added in v0.90.0

func (i WitnessScope) String() string

func (*WitnessScope) UnmarshalJSON added in v0.90.0

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

UnmarshalJSON implements json.Unmarshaler interface.

Jump to

Keyboard shortcuts

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