trx

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TxInputFixedSize defines the fixed size of transaction input
	TxInputFixedSize = 44

	// ValueSizeInBytes defines the size of value in byte units
	ValueSizeInBytes = 8
	// LockScriptSizeInBytes defines the size of lock script in byte units
	LockScriptSizeInBytes = 4

	// VersionSizeInBytes defines the size of version in byte units
	VersionSizeInBytes = 4
	// LockTimeSizeInBytes defines the size of lock time in byte units
	LockTimeSizeInBytes = 4
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Tx

type Tx struct {
	Version  uint32
	LockTime uint32 // transaction to be locked until this time

	// used by utxo-based model
	TxIn  []*TxInput
	TxOut []*TxOutput
}

Tx defines the struct of utxo-based transaction make sure the variable type and order of this struct is same as "type Tx" in blockchain.pb.go

func NewCoinbaseTx

func NewCoinbaseTx(toaddr string, amount uint64, data string) *Tx

NewCoinbaseTx creates the coinbase transaction - a special type of transaction that does not require previously outputs.

func NewTx

func NewTx(in []*TxInput, out []*TxOutput, lockTime uint32) *Tx

NewTx returns a Tx instance

func (*Tx) ByteStream

func (tx *Tx) ByteStream() []byte

ByteStream returns a raw byte stream of this transaction

func (*Tx) ConvertFromTxPb

func (tx *Tx) ConvertFromTxPb(pbTx *iproto.TxPb)

ConvertFromTxPb converts protobuf's TxPb to Tx

func (*Tx) ConvertToTxPb

func (tx *Tx) ConvertToTxPb() *iproto.TxPb

ConvertToTxPb converts Tx to protobuf's TxPb

func (*Tx) ConvertToUtxoPb

func (tx *Tx) ConvertToUtxoPb() *iproto.UtxoMapPb

ConvertToUtxoPb creates a protobuf's UTXO

func (*Tx) Deserialize

func (tx *Tx) Deserialize(buf []byte) error

Deserialize parse the byte stream into Tx

func (*Tx) Hash

func (tx *Tx) Hash() common.Hash32B

Hash returns the hash of the Tx

func (*Tx) IsCoinbase

func (tx *Tx) IsCoinbase() bool

IsCoinbase checks if it is a coinbase transaction by checking if Vin is empty

func (*Tx) Serialize

func (tx *Tx) Serialize() ([]byte, error)

Serialize returns a serialized byte stream for the Tx

func (*Tx) TotalSize

func (tx *Tx) TotalSize() uint32

TotalSize returns the total size of this transaction

type TxInSorter

type TxInSorter []*TxInput

TxInSorter is TxInput sorter that implements Sort interface

func (TxInSorter) Len

func (sorter TxInSorter) Len() int

Sort Interface implementation for *TxInput slice

func (TxInSorter) Less

func (sorter TxInSorter) Less(i, j int) bool

func (TxInSorter) Swap

func (sorter TxInSorter) Swap(i, j int)

type TxInput

type TxInput struct {
	*iproto.TxInputPb
}

TxInput defines the transaction input protocol buffer

func NewTxInput

func NewTxInput(hash common.Hash32B, index int32, unlock []byte, seq uint32) *TxInput

NewTxInput returns a TxInput instance

func (*TxInput) ByteStream

func (in *TxInput) ByteStream() []byte

ByteStream returns a raw byte stream of transaction input

func (*TxInput) TotalSize

func (in *TxInput) TotalSize() uint32

TotalSize returns the total size (in bytes) of transaction input

func (*TxInput) UnlockSuccess

func (in *TxInput) UnlockSuccess(lockScript []byte) bool

UnlockSuccess checks whether the TxInput can unlock the provided script

type TxOutSorter

type TxOutSorter []*TxOutput

TxOutSorter is TxOutput sorter that implements Sort interface

func (TxOutSorter) Len

func (sorter TxOutSorter) Len() int

Sort Interface implementation for *TxOuput slice

func (TxOutSorter) Less

func (sorter TxOutSorter) Less(i, j int) bool

func (TxOutSorter) Swap

func (sorter TxOutSorter) Swap(i, j int)

type TxOutput

type TxOutput struct {
	*iproto.TxOutputPb // embedded

	// below fields only used internally, not part of serialize/deserialize
	OutIndex int32 // outIndex is needed when spending UTXO
}

TxOutput defines the transaction output protocol buffer

func CreateTxOutput

func CreateTxOutput(toaddr string, value uint64) *TxOutput

CreateTxOutput creates a new transaction output

func NewTxOutput

func NewTxOutput(amount uint64, index int32) *TxOutput

NewTxOutput returns a TxOutput instance

func (*TxOutput) ByteStream

func (out *TxOutput) ByteStream() []byte

ByteStream returns a raw byte stream of transaction output

func (*TxOutput) IsLockedWithKey

func (out *TxOutput) IsLockedWithKey(lockScript []byte) bool

IsLockedWithKey checks if the UTXO in output is locked with script

func (*TxOutput) TotalSize

func (out *TxOutput) TotalSize() uint32

TotalSize returns the total size of transaction output

Jump to

Keyboard shortcuts

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