transaction

package
v0.0.0-...-2cf7c70 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2018 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxCollectableEntityNum = 20480
)
View Source
const (
	TransactionNonceLength = 32
)

Variables

This section is empty.

Functions

func CheckAssetPrecision

func CheckAssetPrecision(Tx *Transaction) error

func CheckAttributeProgram

func CheckAttributeProgram(Tx *Transaction) error

func CheckDuplicateInput

func CheckDuplicateInput(tx *Transaction) error

validate the transaction of duplicate UTXO input

func CheckDuplicateUtxoInBlock

func CheckDuplicateUtxoInBlock(tx *Transaction, txPoolInputs []string) error

func CheckTransactionBalance

func CheckTransactionBalance(txn *Transaction) error

func CheckTransactionContracts

func CheckTransactionContracts(Tx *Transaction) error

func CheckTransactionPayload

func CheckTransactionPayload(txn *Transaction) error

func IsDoubleSpend

func IsDoubleSpend(tx *Transaction) bool

func IsValidAttributeType

func IsValidAttributeType(usage TransactionAttributeUsage) bool

func VerifyTransaction

func VerifyTransaction(Tx *Transaction) ErrCode

VerifyTransaction verifys received single transaction

func VerifyTransactionWithBlock

func VerifyTransactionWithBlock(TxPool []*Transaction) error

VerifyTransactionWithBlock verifys a transaction with current transaction pool in memory

func VerifyTransactionWithLedger

func VerifyTransactionWithLedger(Tx *Transaction) ErrCode

VerifyTransactionWithLedger verifys a transaction with history transaction in ledger

Types

type Payload

type Payload interface {
	//  Get payload data
	Data(version byte) []byte

	//Serialize payload data
	Serialize(w io.Writer, version byte) error

	Deserialize(r io.Reader, version byte) error

	MarshalJson() ([]byte, error)

	UnmarshalJson(data []byte) error
}

Payload define the func for loading the payload data base on payload type which have different struture

type Transaction

type Transaction struct {
	TxType         TransactionType
	PayloadVersion byte
	Payload        Payload
	Attributes     []*TxnAttribute
	Inputs         []*TxnInput
	Outputs        []*TxnOutput
	Programs       []*program.Program
	// contains filtered or unexported fields
}

func NewBookKeeperTransaction

func NewBookKeeperTransaction(pubKey *crypto.PubKey, isAdd bool, cert []byte, issuer *crypto.PubKey) (*Transaction, error)

initial a new transaction with asset registration payload

func NewCommitTransaction

func NewCommitTransaction(sigChain []byte, submitter Uint160) (*Transaction, error)

func NewIssueAssetTransaction

func NewIssueAssetTransaction(outputs []*TxnOutput) (*Transaction, error)

func NewPrepaidTransaction

func NewPrepaidTransaction(inputs []*TxnInput, changes *TxnOutput, assetID Uint256, amount, rates string) (*Transaction, error)

func NewRegisterAssetTransaction

func NewRegisterAssetTransaction(asset *asset.Asset, amount Fixed64, issuer *crypto.PubKey, conroller Uint160) (*Transaction, error)

initial a new transaction with asset registration payload

func NewTransferAssetTransaction

func NewTransferAssetTransaction(inputs []*TxnInput, outputs []*TxnOutput) (*Transaction, error)

func NewWithdrawTransaction

func NewWithdrawTransaction(output *TxnOutput) (*Transaction, error)

func (*Transaction) Deserialize

func (tx *Transaction) Deserialize(r io.Reader) error

deserialize the Transaction

func (*Transaction) DeserializeUnsigned

func (tx *Transaction) DeserializeUnsigned(r io.Reader) error

func (*Transaction) DeserializeUnsignedWithoutType

func (tx *Transaction) DeserializeUnsignedWithoutType(r io.Reader) error

func (*Transaction) GenerateAssetMaps

func (tx *Transaction) GenerateAssetMaps()

func (*Transaction) GetMergedAssetIDValueFromOutputs

func (tx *Transaction) GetMergedAssetIDValueFromOutputs() TransactionResult

func (*Transaction) GetMergedAssetIDValueFromReference

func (tx *Transaction) GetMergedAssetIDValueFromReference() (TransactionResult, error)

func (*Transaction) GetMessage

func (tx *Transaction) GetMessage() []byte

func (*Transaction) GetOutputHashes

func (tx *Transaction) GetOutputHashes() ([]Uint160, error)

func (*Transaction) GetProgramHashes

func (tx *Transaction) GetProgramHashes() ([]Uint160, error)

func (*Transaction) GetPrograms

func (tx *Transaction) GetPrograms() []*program.Program

func (*Transaction) GetReference

func (tx *Transaction) GetReference() (map[*TxnInput]*TxnOutput, error)

func (*Transaction) GetTransactionResults

func (tx *Transaction) GetTransactionResults() (TransactionResult, error)

func (*Transaction) Hash

func (tx *Transaction) Hash() Uint256

func (*Transaction) MarshalJson

func (tx *Transaction) MarshalJson() ([]byte, error)

func (*Transaction) Serialize

func (tx *Transaction) Serialize(w io.Writer) error

Serialize the Transaction

func (*Transaction) SerializeUnsigned

func (tx *Transaction) SerializeUnsigned(w io.Writer) error

Serialize the Transaction data without contracts

func (*Transaction) SetHash

func (tx *Transaction) SetHash(hash Uint256)

func (*Transaction) SetPrograms

func (tx *Transaction) SetPrograms(programs []*program.Program)

func (*Transaction) ToArray

func (tx *Transaction) ToArray() []byte

func (*Transaction) Type

func (tx *Transaction) Type() InventoryType

func (*Transaction) UnmarshalJson

func (tx *Transaction) UnmarshalJson(data []byte) error

func (*Transaction) Verify

func (tx *Transaction) Verify() error

type TransactionAttributeUsage

type TransactionAttributeUsage byte
const (
	Nonce       TransactionAttributeUsage = 0x00
	Script      TransactionAttributeUsage = 0x20
	Description TransactionAttributeUsage = 0x90
)

type TransactionInfo

type TransactionInfo struct {
	TxType         TransactionType       `json:"txType"`
	PayloadVersion byte                  `json:"payloadVersion"`
	Payload        interface{}           `json:"payload"`
	Attributes     []TxnAttributeInfo    `json:"attributes"`
	Inputs         []TxnInputInfo        `json:"inputs"`
	Outputs        []TxnOutputInfo       `json:"outputs"`
	Programs       []program.ProgramInfo `json:"programs"`
	Hash           string                `json:"hash"`
}

type TransactionResult

type TransactionResult map[Uint256]Fixed64

type TransactionType

type TransactionType byte

for different transaction types with different payload format and transaction process methods

const (
	Coinbase      TransactionType = 0x00
	TransferAsset TransactionType = 0x10
	RegisterAsset TransactionType = 0x11
	IssueAsset    TransactionType = 0x12
	BookKeeper    TransactionType = 0x20
	Prepaid       TransactionType = 0x40
	Withdraw      TransactionType = 0x41
	Commit        TransactionType = 0x42
)

type TxnAttribute

type TxnAttribute struct {
	Usage TransactionAttributeUsage
	Data  []byte
	Size  uint32
}

func NewTxAttribute

func NewTxAttribute(u TransactionAttributeUsage, d []byte) TxnAttribute

func (*TxnAttribute) Deserialize

func (attr *TxnAttribute) Deserialize(r io.Reader) error

func (*TxnAttribute) Equal

func (attr *TxnAttribute) Equal(tx2 *TxnAttribute) bool

func (*TxnAttribute) GetSize

func (attr *TxnAttribute) GetSize() uint32

func (*TxnAttribute) MarshalJson

func (attr *TxnAttribute) MarshalJson() ([]byte, error)

func (*TxnAttribute) Serialize

func (attr *TxnAttribute) Serialize(w io.Writer) error

func (*TxnAttribute) ToArray

func (attr *TxnAttribute) ToArray() []byte

func (*TxnAttribute) UnmarshalJson

func (attr *TxnAttribute) UnmarshalJson(data []byte) error

type TxnAttributeInfo

type TxnAttributeInfo struct {
	Usage TransactionAttributeUsage `json:"usage"`
	Data  string                    `json:"data"`
}

type TxnCollector

type TxnCollector struct {
	TxnNum    int
	TxnSource TxnSource
}

TxnCollector collects transactions from transaction pool

func NewTxnCollector

func NewTxnCollector(source TxnSource, num int) *TxnCollector

func (*TxnCollector) Append

func (tc *TxnCollector) Append(txn *Transaction) errors.ErrCode

func (*TxnCollector) Cleanup

func (tc *TxnCollector) Cleanup(txns []*Transaction) error

func (*TxnCollector) Collect

func (tc *TxnCollector) Collect(winningHash Uint256) (map[Uint256]*Transaction, error)

func (*TxnCollector) GetTransaction

func (tc *TxnCollector) GetTransaction(hash Uint256) *Transaction

type TxnInput

type TxnInput struct {

	//Indicate the previous Tx which include the UTXO output for usage
	ReferTxID common.Uint256

	//The index of output in the referTx output list
	ReferTxOutputIndex uint16
}

func (*TxnInput) Deserialize

func (input *TxnInput) Deserialize(r io.Reader) error

func (*TxnInput) Equal

func (input *TxnInput) Equal(ui2 *TxnInput) bool

func (*TxnInput) Equals

func (input *TxnInput) Equals(other *TxnInput) bool

func (*TxnInput) MarshalJson

func (input *TxnInput) MarshalJson() ([]byte, error)

func (*TxnInput) Serialize

func (input *TxnInput) Serialize(w io.Writer) error

func (*TxnInput) ToArray

func (input *TxnInput) ToArray() []byte

func (*TxnInput) ToString

func (input *TxnInput) ToString() string

func (*TxnInput) UnmarshalJson

func (input *TxnInput) UnmarshalJson(data []byte) error

type TxnInputInfo

type TxnInputInfo struct {
	ReferTxID          string `json:"referTxID"`
	ReferTxOutputIndex uint16 `json:"referTxOutputIndex"`
}

type TxnOutput

type TxnOutput struct {
	AssetID     common.Uint256
	Value       common.Fixed64
	ProgramHash common.Uint160
}

func (*TxnOutput) Deserialize

func (output *TxnOutput) Deserialize(r io.Reader) error

func (*TxnOutput) Equal

func (output *TxnOutput) Equal(o2 *TxnOutput) bool

func (*TxnOutput) MarshalJson

func (output *TxnOutput) MarshalJson() ([]byte, error)

func (*TxnOutput) Serialize

func (output *TxnOutput) Serialize(w io.Writer) error

func (*TxnOutput) ToArray

func (output *TxnOutput) ToArray() []byte

func (*TxnOutput) UnmarshalJson

func (output *TxnOutput) UnmarshalJson(data []byte) error

type TxnOutputInfo

type TxnOutputInfo struct {
	AssetID string `json:"assetID"`
	Value   string `json:"value"`
	Address string `json:"address"`
}

type TxnSource

type TxnSource interface {
	GetTxnByCount(num int, hash Uint256) (map[Uint256]*Transaction, error)
	GetTransaction(hash Uint256) *Transaction
	AppendTxnPool(txn *Transaction) errors.ErrCode
	CleanSubmittedTransactions(txns []*Transaction) error
}

Transaction pool should be a concrete entity of this interface

type TxnStore

type TxnStore interface {
	GetTransaction(hash Uint256) (*Transaction, error)
	GetQuantityIssued(AssetId Uint256) (Fixed64, error)
	IsDoubleSpend(tx *Transaction) bool
	GetAsset(hash Uint256) (*asset.Asset, error)
	GetBookKeeperList() ([]*crypto.PubKey, []*crypto.PubKey, error)
	GetPrepaidInfo(programHash Uint160) (*Fixed64, *Fixed64, error)
	IsTxHashDuplicate(txhash Uint256) bool
}
var Store TxnStore

type UTXOUnspent

type UTXOUnspent struct {
	Txid  common.Uint256
	Index uint32
	Value common.Fixed64
}

func (*UTXOUnspent) Deserialize

func (uu *UTXOUnspent) Deserialize(r io.Reader) error

func (*UTXOUnspent) Serialize

func (uu *UTXOUnspent) Serialize(w io.Writer) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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