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

          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

              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

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

                        UnmarshalJSON implements the json.Unmarshaller interface.

                        type Conflicts

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

                          Conflicts represents attribute for conflicting transactions.

                          func (*Conflicts) DecodeBinary

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

                            DecodeBinary implements io.Serializable interface.

                            func (*Conflicts) EncodeBinary

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

                              EncodeBinary implements io.Serializable interface.

                              type NotValidBefore

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

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

                                func (*NotValidBefore) DecodeBinary

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

                                  DecodeBinary implements io.Serializable interface.

                                  func (*NotValidBefore) EncodeBinary

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

                                    EncodeBinary implements io.Serializable interface.

                                    type NotaryAssisted

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

                                      NotaryAssisted represents attribute for notary service transactions.

                                      func (*NotaryAssisted) DecodeBinary

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

                                        DecodeBinary implements io.Serializable interface.

                                        func (*NotaryAssisted) EncodeBinary

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

                                          EncodeBinary implements 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) DecodeBinary

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

                                              DecodeBinary implements io.Serializable interface.

                                              func (*OracleResponse) EncodeBinary

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

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

                                                      type Reserved

                                                      type Reserved struct {
                                                      	Value []byte
                                                      }

                                                        Reserved represents an attribute for experimental or private usage.

                                                        func (*Reserved) DecodeBinary

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

                                                          DecodeBinary implements io.Serializable interface.

                                                          func (*Reserved) EncodeBinary

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

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

                                                              Signer implements a Transaction signer.

                                                              func (*Signer) DecodeBinary

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

                                                                DecodeBinary implements Serializable interface.

                                                                func (*Signer) EncodeBinary

                                                                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

                                                                    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

                                                                      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

                                                                              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

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

                                                                                      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

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

                                                                                                      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

                                                                                                                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

                                                                                                                  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 json.Marshaler interface.

                                                                                                                      func (WitnessScope) String

                                                                                                                      func (i WitnessScope) String() string

                                                                                                                      func (*WitnessScope) UnmarshalJSON

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

                                                                                                                        UnmarshalJSON implements json.Unmarshaler interface.