transaction

package
v0.73.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxTransactionSize is the upper limit size in bytes that a transaction can reach. It is
	// set to be 102400.
	MaxTransactionSize = 102400
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AssetType

type AssetType uint8

AssetType represents a NEO asset type.

const (
	CreditFlag     AssetType = 0x40
	DutyFlag       AssetType = 0x80
	GoverningToken AssetType = 0x00
	UtilityToken   AssetType = 0x01
	Currency       AssetType = 0x08
	Share          AssetType = DutyFlag | 0x10
	Invoice        AssetType = DutyFlag | 0x18
	Token          AssetType = CreditFlag | 0x20
)

Valid asset types.

type AttrUsage

type AttrUsage uint8

AttrUsage represents the purpose of the attribute.

const (
	ContractHash   AttrUsage = 0x00
	ECDH02         AttrUsage = 0x02
	ECDH03         AttrUsage = 0x03
	Script         AttrUsage = 0x20
	Vote           AttrUsage = 0x30
	CertURL        AttrUsage = 0x80
	DescriptionURL AttrUsage = 0x81
	Description    AttrUsage = 0x90

	Hash1  AttrUsage = 0xa1
	Hash2  AttrUsage = 0xa2
	Hash3  AttrUsage = 0xa3
	Hash4  AttrUsage = 0xa4
	Hash5  AttrUsage = 0xa5
	Hash6  AttrUsage = 0xa6
	Hash7  AttrUsage = 0xa7
	Hash8  AttrUsage = 0xa8
	Hash9  AttrUsage = 0xa9
	Hash10 AttrUsage = 0xaa
	Hash11 AttrUsage = 0xab
	Hash12 AttrUsage = 0xac
	Hash13 AttrUsage = 0xad
	Hash14 AttrUsage = 0xae
	Hash15 AttrUsage = 0xaf

	Remark   AttrUsage = 0xf0
	Remark1  AttrUsage = 0xf1
	Remark2  AttrUsage = 0xf2
	Remark3  AttrUsage = 0xf3
	Remark4  AttrUsage = 0xf4
	Remark5  AttrUsage = 0xf5
	Remark6  AttrUsage = 0xf6
	Remark7  AttrUsage = 0xf7
	Remark8  AttrUsage = 0xf8
	Remark9  AttrUsage = 0xf9
	Remark10 AttrUsage = 0xfa
	Remark11 AttrUsage = 0xfb
	Remark12 AttrUsage = 0xfc
	Remark13 AttrUsage = 0xfd
	Remark14 AttrUsage = 0xfe
	Remark15 AttrUsage = 0xff
)

List of valid attribute usages.

func (AttrUsage) String

func (i AttrUsage) String() string

type Attribute

type Attribute struct {
	Usage AttrUsage `json:"usage"`
	Data  []byte    `json:"data"`
}

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.

type ClaimTX

type ClaimTX struct {
	Claims []*Input
}

ClaimTX represents a claim transaction.

func (*ClaimTX) DecodeBinary

func (tx *ClaimTX) DecodeBinary(br *io.BinReader)

DecodeBinary implements Serializable interface.

func (*ClaimTX) EncodeBinary

func (tx *ClaimTX) EncodeBinary(bw *io.BinWriter)

EncodeBinary implements Serializable interface.

type ContractTX

type ContractTX struct{}

ContractTX represents a contract transaction. This TX has not special attributes.

func (*ContractTX) DecodeBinary

func (tx *ContractTX) DecodeBinary(r *io.BinReader)

DecodeBinary implements Serializable interface.

func (*ContractTX) EncodeBinary

func (tx *ContractTX) EncodeBinary(w *io.BinWriter)

EncodeBinary implements Serializable interface.

type DescStateType

type DescStateType uint8

DescStateType represents the type of StateDescriptor.

const (
	Account   DescStateType = 0x40
	Validator DescStateType = 0x48
)

Valid DescStateType constants.

type EnrollmentTX

type EnrollmentTX struct {
	// PublicKey of the validator.
	PublicKey keys.PublicKey
}

EnrollmentTX transaction represents an enrollment form, which indicates that the sponsor of the transaction would like to sign up as a validator. The way to sign up is: To construct an EnrollmentTransaction type of transaction, and send a deposit to the address of the PublicKey. The way to cancel the registration is: Spend the deposit on the address of the PublicKey.

func (*EnrollmentTX) DecodeBinary

func (tx *EnrollmentTX) DecodeBinary(r *io.BinReader)

DecodeBinary implements Serializable interface.

func (*EnrollmentTX) EncodeBinary

func (tx *EnrollmentTX) EncodeBinary(w *io.BinWriter)

EncodeBinary implements Serializable interface.

type Input

type Input struct {
	// The hash of the previous transaction.
	PrevHash util.Uint256 `json:"txid"`

	// The index of the previous transaction.
	PrevIndex uint16 `json:"vout"`
}

Input represents a Transaction input (CoinReference).

func (*Input) DecodeBinary

func (in *Input) DecodeBinary(br *io.BinReader)

DecodeBinary implements Serializable interface.

func (*Input) EncodeBinary

func (in *Input) EncodeBinary(bw *io.BinWriter)

EncodeBinary implements Serializable interface.

type InvocationTX

type InvocationTX struct {
	// Script output of the smart contract.
	Script []byte

	// Gas cost of the smart contract.
	Gas     util.Fixed8
	Version uint8
}

InvocationTX represents a invocation transaction and is used to deploy smart contract to the NEO blockchain.

func (*InvocationTX) DecodeBinary

func (tx *InvocationTX) DecodeBinary(br *io.BinReader)

DecodeBinary implements Serializable interface.

func (*InvocationTX) EncodeBinary

func (tx *InvocationTX) EncodeBinary(bw *io.BinWriter)

EncodeBinary implements Serializable interface.

type IssueTX

type IssueTX struct{}

IssueTX represents a issue transaction. This TX has not special attributes.

func (*IssueTX) DecodeBinary

func (tx *IssueTX) DecodeBinary(r *io.BinReader)

DecodeBinary implements Serializable interface.

func (*IssueTX) EncodeBinary

func (tx *IssueTX) EncodeBinary(w *io.BinWriter)

EncodeBinary implements Serializable interface.

type MinerTX

type MinerTX struct {
	// Random number to avoid hash collision.
	Nonce uint32
}

MinerTX represents a miner transaction.

func (*MinerTX) DecodeBinary

func (tx *MinerTX) DecodeBinary(r *io.BinReader)

DecodeBinary implements Serializable interface.

func (*MinerTX) EncodeBinary

func (tx *MinerTX) EncodeBinary(w *io.BinWriter)

EncodeBinary implements Serializable interface.

type Output

type Output struct {
	// The NEO asset id used in the transaction.
	AssetID util.Uint256 `json:"asset"`

	// Amount of AssetType send or received.
	Amount util.Fixed8 `json:"value"`

	// The address of the recipient.
	ScriptHash util.Uint160 `json:"address"`

	// The position of the Output in slice []Output. This is actually set in NewTransactionOutputRaw
	// and used for displaying purposes.
	Position int `json:"n"`
}

Output represents a Transaction output.

func NewOutput

func NewOutput(assetID util.Uint256, amount util.Fixed8, scriptHash util.Uint160) *Output

NewOutput returns a new transaction output.

func (*Output) DecodeBinary

func (out *Output) DecodeBinary(br *io.BinReader)

DecodeBinary implements Serializable interface.

func (*Output) EncodeBinary

func (out *Output) EncodeBinary(bw *io.BinWriter)

EncodeBinary implements Serializable interface.

func (*Output) MarshalJSON

func (out *Output) MarshalJSON() ([]byte, error)

MarshalJSON implements the Marshaler interface.

type PublishTX

type PublishTX struct {
	Script      []byte
	ParamList   []smartcontract.ParamType
	ReturnType  smartcontract.ParamType
	NeedStorage bool
	Name        string
	CodeVersion string
	Author      string
	Email       string
	Description string
	Version     uint8 // Version of the parent struct Transaction. Used in reading NeedStorage flag.
}

PublishTX represents a publish transaction. NOTE: This is deprecated and should no longer be used.

func (*PublishTX) DecodeBinary

func (tx *PublishTX) DecodeBinary(br *io.BinReader)

DecodeBinary implements Serializable interface.

func (*PublishTX) EncodeBinary

func (tx *PublishTX) EncodeBinary(bw *io.BinWriter)

EncodeBinary implements Serializable interface.

type RegisterTX

type RegisterTX struct {
	// The type of the asset being registered.
	AssetType AssetType

	// Name of the asset being registered.
	Name string

	// Amount registered.
	// Unlimited mode -0.00000001.
	Amount util.Fixed8

	// Decimals.
	Precision uint8

	// Public key of the owner.
	Owner keys.PublicKey

	Admin util.Uint160
}

RegisterTX represents a register transaction. NOTE: This is deprecated.

func (*RegisterTX) DecodeBinary

func (tx *RegisterTX) DecodeBinary(br *io.BinReader)

DecodeBinary implements Serializable interface.

func (*RegisterTX) EncodeBinary

func (tx *RegisterTX) EncodeBinary(bw *io.BinWriter)

EncodeBinary implements Serializable interface.

type Result

type Result struct {
	AssetID util.Uint256
	Amount  util.Fixed8
}

Result represents the Result of a transaction.

type StateDescriptor

type StateDescriptor struct {
	Type  DescStateType
	Key   []byte
	Value []byte
	Field string
}

StateDescriptor ..

func (*StateDescriptor) DecodeBinary

func (s *StateDescriptor) DecodeBinary(r *io.BinReader)

DecodeBinary implements Serializable interface.

func (*StateDescriptor) EncodeBinary

func (s *StateDescriptor) EncodeBinary(w *io.BinWriter)

EncodeBinary implements Serializable interface.

type StateTX

type StateTX struct {
	Descriptors []*StateDescriptor
}

StateTX represents a state transaction.

func (*StateTX) DecodeBinary

func (tx *StateTX) DecodeBinary(r *io.BinReader)

DecodeBinary implements Serializable interface.

func (*StateTX) EncodeBinary

func (tx *StateTX) EncodeBinary(w *io.BinWriter)

EncodeBinary implements Serializable interface.

type TXType

type TXType uint8

TXType is the type of a transaction.

const (
	MinerType      TXType = 0x00
	IssueType      TXType = 0x01
	ClaimType      TXType = 0x02
	EnrollmentType TXType = 0x20
	VotingType     TXType = 0x24
	RegisterType   TXType = 0x40
	ContractType   TXType = 0x80
	StateType      TXType = 0x90
	AgencyType     TXType = 0xb0
	PublishType    TXType = 0xd0
	InvocationType TXType = 0xd1
)

Constants for all valid transaction types.

func TXTypeFromString added in v0.71.0

func TXTypeFromString(jsonString string) (TXType, error)

TXTypeFromString searches for TXType by string name.

func (TXType) MarshalJSON

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

MarshalJSON implements the json marshaller interface.

func (TXType) String

func (t TXType) String() string

String implements the stringer interface.

func (*TXType) UnmarshalJSON added in v0.71.0

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

UnmarshalJSON implements the json.Unmarshaler interface.

type TXer

type TXer interface {
	io.Serializable
}

TXer is interface that can act as the underlying data of a transaction.

type Transaction

type Transaction struct {
	// The type of the transaction.
	Type TXType `json:"type"`

	// The trading version which is currently 0.
	Version uint8 `json:"version"`

	// Data specific to the type of the transaction.
	// This is always a pointer to a <Type>Transaction.
	Data TXer `json:"-"`

	// Transaction attributes.
	Attributes []Attribute `json:"attributes"`

	// The inputs of the transaction.
	Inputs []Input `json:"vin"`

	// The outputs of the transaction.
	Outputs []Output `json:"vout"`

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

	// Trimmed indicates this is a transaction from trimmed
	// data.
	Trimmed bool `json:"-"`
	// contains filtered or unexported fields
}

Transaction is a process recorded in the NEO blockchain.

func NewContractTX

func NewContractTX() *Transaction

NewContractTX creates Transaction of ContractType type.

func NewInvocationTX

func NewInvocationTX(script []byte, gas util.Fixed8) *Transaction

NewInvocationTX returns a new invocation transaction.

func NewTrimmedTX

func NewTrimmedTX(hash util.Uint256) *Transaction

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

func (*Transaction) AddInput

func (t *Transaction) AddInput(in *Input)

AddInput adds the given input to the transaction inputs.

func (*Transaction) AddOutput

func (t *Transaction) AddOutput(out *Output)

AddOutput adds the given output to the transaction outputs.

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

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

EncodeBinary implements Serializable interface.

func (*Transaction) GroupInputsByPrevHash

func (t *Transaction) GroupInputsByPrevHash() map[util.Uint256][]*Input

GroupInputsByPrevHash groups all TX inputs by their previous hash.

func (Transaction) GroupOutputByAssetID

func (t Transaction) GroupOutputByAssetID() map[util.Uint256][]*Output

GroupOutputByAssetID groups all TX outputs by their assetID.

func (*Transaction) Hash

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

Hash returns the hash of the transaction.

func (*Transaction) VerificationHash added in v0.51.0

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

VerificationHash returns the hash of the transaction used to verify it.

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

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

MarshalJSON implements the json marshaller interface.

func (Witness) ScriptHash

func (w Witness) ScriptHash() util.Uint160

ScriptHash returns the hash of the VerificationScript.

Jump to

Keyboard shortcuts

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