types

package
v1.1.7 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2020 License: AGPL-3.0 Imports: 18 Imported by: 36

Documentation

Index

Constants

View Source
const (
	SerBlockHeader
	SerBlockTransactions
	SerBlockFull
)

serflag variables, start with 1

View Source
const (
	// FlagAssist represent assist node
	FlagAssist = iota
	// FlagTxParent represent the parent of transaction of node
	FlagTxParent
	// FlagTxLeaf represent transaction of node
	FlagTxLeaf
)

merkleFlag represent the type of merkle tree node, it's used to generate the structure of merkle tree Bitcoin has only two flags, which zero means the hash of assist node. And one means the hash of the related transaction node or it's parents, which distinguish them according to the height of the tree. But in the bytom, the height of transaction node is not fixed, so we need three flags to distinguish these nodes.

View Source
const (
	CrossChainInputType uint8 = iota
	SpendInputType
	CoinbaseInputType
	VetoInputType
)

serflag variables for input types.

View Source
const (
	IntraChainOutputType uint8 = iota
	CrossChainOutputType
	VoteOutputType
)

serflag variables for output types.

Variables

This section is empty.

Functions

func ComputeOutputID

func ComputeOutputID(sc *SpendCommitment, inputType uint8, vote []byte) (h bc.Hash, err error)

ComputeOutputID assembles an intra-chain(!) output entry given a spend commitment and computes and returns its corresponding entry ID.

func GetStatusMerkleTreeProof

func GetStatusMerkleTreeProof(statuses []*bc.TxVerifyResult, flags []uint8) []*bc.Hash

GetStatusMerkleTreeProof return a proof of merkle tree, which used to proof the status of transaction is valid

func GetTxMerkleTreeProof

func GetTxMerkleTreeProof(txs []*Tx, relatedTxs []*Tx) ([]*bc.Hash, []uint8)

GetTxMerkleTreeProof return a proof of merkle tree, which used to proof the transaction does exist in the merkle tree

func MapBlock

func MapBlock(old *Block) *bc.Block

MapBlock converts a types block to bc block

func MapTx

func MapTx(oldTx *TxData) *bc.Tx

MapTx converts a types TxData object into its entries-based representation.

func TxMerkleRoot

func TxMerkleRoot(transactions []*bc.Tx) (root bc.Hash, err error)

TxMerkleRoot creates a merkle tree from a slice of transactions and returns the root hash of the tree.

func TxStatusMerkleRoot

func TxStatusMerkleRoot(tvrs []*bc.TxVerifyResult) (root bc.Hash, err error)

TxStatusMerkleRoot creates a merkle tree from a slice of bc.TxVerifyResult

func ValidateStatusMerkleTreeProof

func ValidateStatusMerkleTreeProof(hashes []*bc.Hash, flags []uint8, relatedStatus []*bc.TxVerifyResult, merkleRoot bc.Hash) bool

ValidateStatusMerkleTreeProof validate the merkle tree of transaction status

func ValidateTxMerkleTreeProof

func ValidateTxMerkleTreeProof(hashes []*bc.Hash, flags []uint8, relatedHashes []*bc.Hash, merkleRoot bc.Hash) bool

ValidateTxMerkleTreeProof validate the merkle tree of transactions

Types

type Block

type Block struct {
	BlockHeader
	Transactions []*Tx
}

Block describes a complete block, including its header and the transactions it contains.

func (*Block) MarshalText

func (b *Block) MarshalText() ([]byte, error)

MarshalText fulfills the json.Marshaler interface. This guarantees that blocks will get deserialized correctly when being parsed from HTTP requests.

func (*Block) MarshalTextForBlockHeader

func (b *Block) MarshalTextForBlockHeader() ([]byte, error)

MarshalTextForBlockHeader fulfills the json.Marshaler interface.

func (*Block) MarshalTextForTransactions

func (b *Block) MarshalTextForTransactions() ([]byte, error)

MarshalTextForTransactions fulfills the json.Marshaler interface.

func (*Block) UnmarshalText

func (b *Block) UnmarshalText(text []byte) error

UnmarshalText fulfills the encoding.TextUnmarshaler interface.

func (*Block) WriteTo

func (b *Block) WriteTo(w io.Writer) (int64, error)

WriteTo write block to io.Writer

type BlockCommitment

type BlockCommitment struct {
	// TransactionsMerkleRoot is the root hash of the Merkle binary hash tree
	// formed by the hashes of all transactions included in the block.
	TransactionsMerkleRoot bc.Hash `json:"transaction_merkle_root"`

	// TransactionStatusHash is the root hash of the Merkle binary hash tree
	// formed by the hashes of all transaction verify results
	TransactionStatusHash bc.Hash `json:"transaction_status_hash"`
}

BlockCommitment store the TransactionsMerkleRoot && TransactionStatusHash

type BlockHeader

type BlockHeader struct {
	Version           uint64  // The version of the block.
	Height            uint64  // The height of the block.
	PreviousBlockHash bc.Hash // The hash of the previous block.
	Timestamp         uint64  // The time of the block in milliseconds.
	BlockCommitment
	BlockWitness
}

BlockHeader defines information about a block and is used in the Bytom

func (*BlockHeader) Hash

func (bh *BlockHeader) Hash() bc.Hash

Hash returns complete hash of the block header.

func (*BlockHeader) MarshalText

func (bh *BlockHeader) MarshalText() ([]byte, error)

MarshalText fulfills the json.Marshaler interface. This guarantees that block headers will get deserialized correctly when being parsed from HTTP requests.

func (*BlockHeader) Time

func (bh *BlockHeader) Time() time.Time

Time returns the time represented by the Timestamp in block header.

func (*BlockHeader) UnmarshalText

func (bh *BlockHeader) UnmarshalText(text []byte) error

UnmarshalText fulfills the encoding.TextUnmarshaler interface.

func (*BlockHeader) WriteTo

func (bh *BlockHeader) WriteTo(w io.Writer) (int64, error)

WriteTo writes the block header to the input io.Writer

type BlockWitness

type BlockWitness struct {
	// Witness is a vector of arguments  for validating this block.
	Witness [][]byte
}

BlockWitness save the consensus node sign

func (*BlockWitness) Delete

func (bw *BlockWitness) Delete(index uint64)

Delete remove data from index position

func (*BlockWitness) Get

func (bw *BlockWitness) Get(index uint64) []byte

Get return data from index position

func (*BlockWitness) Set

func (bw *BlockWitness) Set(index uint64, data []byte)

Set save data to index position

type CoinbaseInput

type CoinbaseInput struct {
	Arbitrary []byte
}

CoinbaseInput records the coinbase message

func (*CoinbaseInput) InputType

func (cb *CoinbaseInput) InputType() uint8

InputType is the interface function for return the input type

type CrossChainInput

type CrossChainInput struct {
	SpendCommitmentSuffix []byte   // The unconsumed suffix of the spend commitment
	Arguments             [][]byte // Witness
	SpendCommitment

	AssetDefinition   []byte
	IssuanceVMVersion uint64
	IssuanceProgram   []byte
}

CrossChainInput satisfies the TypedInput interface and represents a cross-chain transaction.

func (*CrossChainInput) InputType

func (si *CrossChainInput) InputType() uint8

InputType is the interface function for return the input type.

type CrossChainOutput

type CrossChainOutput struct {
	OutputCommitment
	// Unconsumed suffixes of the commitment and witness extensible strings.
	CommitmentSuffix []byte
}

CrossChainOutput satisfies the TypedOutput interface and represents a cross-chain transaction.

func (*CrossChainOutput) OutputType

func (it *CrossChainOutput) OutputType() uint8

OutputType implement the txout interface

type IntraChainOutput

type IntraChainOutput struct {
	OutputCommitment
	// Unconsumed suffixes of the commitment and witness extensible strings.
	CommitmentSuffix []byte
}

IntraChainOutput satisfies the TypedOutput interface and represents a intra-chain transaction.

func (*IntraChainOutput) OutputType

func (it *IntraChainOutput) OutputType() uint8

OutputType implement the txout interface

type OutputCommitment

type OutputCommitment struct {
	bc.AssetAmount
	VMVersion      uint64
	ControlProgram []byte
}

OutputCommitment contains the commitment data for a transaction output.

type SpendCommitment

type SpendCommitment struct {
	bc.AssetAmount
	SourceID       bc.Hash
	SourcePosition uint64
	VMVersion      uint64
	ControlProgram []byte
}

SpendCommitment contains the commitment data for a transaction output.

type SpendInput

type SpendInput struct {
	SpendCommitmentSuffix []byte   // The unconsumed suffix of the spend commitment
	Arguments             [][]byte // Witness
	SpendCommitment
}

SpendInput satisfies the TypedInput interface and represents a spend transaction.

func (*SpendInput) InputType

func (si *SpendInput) InputType() uint8

InputType is the interface function for return the input type.

type Tx

type Tx struct {
	TxData
	*bc.Tx `json:"-"`
}

Tx holds a transaction along with its hash.

func NewTx

func NewTx(data TxData) *Tx

NewTx returns a new Tx containing data and its hash. If you have already computed the hash, use struct literal notation to make a Tx object directly.

func (*Tx) OutputID

func (tx *Tx) OutputID(outputIndex int) *bc.Hash

OutputID return the hash of the output position

func (*Tx) SetInputArguments

func (tx *Tx) SetInputArguments(n uint32, args [][]byte)

SetInputArguments sets the Arguments field in input n.

func (*Tx) UnmarshalText

func (tx *Tx) UnmarshalText(p []byte) error

UnmarshalText fulfills the encoding.TextUnmarshaler interface.

type TxData

type TxData struct {
	Version        uint64
	SerializedSize uint64
	TimeRange      uint64
	Inputs         []*TxInput
	Outputs        []*TxOutput
}

TxData encodes a transaction in the blockchain.

func (*TxData) MarshalText

func (tx *TxData) MarshalText() ([]byte, error)

MarshalText fulfills the json.Marshaler interface.

func (*TxData) UnmarshalText

func (tx *TxData) UnmarshalText(p []byte) error

UnmarshalText fulfills the encoding.TextUnmarshaler interface.

func (*TxData) WriteTo

func (tx *TxData) WriteTo(w io.Writer) (int64, error)

WriteTo writes tx to w.

type TxInput

type TxInput struct {
	AssetVersion uint64
	TypedInput
	CommitmentSuffix []byte
	WitnessSuffix    []byte
}

TxInput is the top level struct of tx input.

func NewCoinbaseInput

func NewCoinbaseInput(arbitrary []byte) *TxInput

NewCoinbaseInput creates a new coinbase input struct

func NewCrossChainInput

func NewCrossChainInput(arguments [][]byte, sourceID bc.Hash, assetID bc.AssetID, amount, sourcePos, IssuanceVMVersion uint64, assetDefinition, issuanceProgram []byte) *TxInput

NewCrossChainInput create a new CrossChainInput struct. The source is created/issued by trusted federation and hence there is no need to refer to it.

func NewSpendInput

func NewSpendInput(arguments [][]byte, sourceID bc.Hash, assetID bc.AssetID, amount, sourcePos uint64, controlProgram []byte) *TxInput

NewSpendInput create a new SpendInput struct.

func NewVetoInput

func NewVetoInput(arguments [][]byte, sourceID bc.Hash, assetID bc.AssetID, amount, sourcePos uint64, controlProgram []byte, vote []byte) *TxInput

NewVetoInput create a new VetoInput struct.

func (*TxInput) Amount

func (t *TxInput) Amount() uint64

Amount return the asset amount of the txinput

func (*TxInput) Arguments

func (t *TxInput) Arguments() [][]byte

Arguments get the args for the input

func (*TxInput) AssetAmount

func (t *TxInput) AssetAmount() bc.AssetAmount

AssetAmount return the asset id and amount of the txinput.

func (*TxInput) AssetID

func (t *TxInput) AssetID() bc.AssetID

AssetID return the assetID of the txinput

func (*TxInput) ControlProgram

func (t *TxInput) ControlProgram() []byte

ControlProgram return the control program of the spend input

func (*TxInput) SetArguments

func (t *TxInput) SetArguments(args [][]byte)

SetArguments set the args for the input

func (*TxInput) SpentOutputID

func (t *TxInput) SpentOutputID() (o bc.Hash, err error)

SpentOutputID calculate the hash of spended output

type TxOutput

type TxOutput struct {
	AssetVersion uint64
	TypedOutput
	// Unconsumed suffixes of the commitment and witness extensible strings.
	CommitmentSuffix []byte
}

TxOutput is the top level struct of tx output.

func NewCrossChainOutput

func NewCrossChainOutput(assetID bc.AssetID, amount uint64, controlProgram []byte) *TxOutput

NewCrossChainOutput create a new output struct

func NewIntraChainOutput

func NewIntraChainOutput(assetID bc.AssetID, amount uint64, controlProgram []byte) *TxOutput

NewIntraChainOutput create a new output struct

func NewVoteOutput

func NewVoteOutput(assetID bc.AssetID, amount uint64, controlProgram []byte, vote []byte) *TxOutput

NewVoteOutput create a new output struct

func (*TxOutput) AssetAmount

func (to *TxOutput) AssetAmount() bc.AssetAmount

AssetAmount return the asset id and amount of a txoutput.

func (*TxOutput) ControlProgram

func (to *TxOutput) ControlProgram() []byte

ControlProgram return the control program of the txoutput

func (*TxOutput) OutputCommitment

func (to *TxOutput) OutputCommitment() OutputCommitment

OutputCommitment return the OutputCommitment of a txoutput.

func (*TxOutput) VMVersion

func (to *TxOutput) VMVersion() uint64

VMVersion return the VM version of the txoutput

type TypedInput

type TypedInput interface {
	InputType() uint8
}

TypedInput return the txinput type.

type TypedOutput

type TypedOutput interface {
	OutputType() uint8
}

TypedOutput return the txoutput type.

type VetoInput

type VetoInput struct {
	VetoCommitmentSuffix []byte   // The unconsumed suffix of the output commitment
	Arguments            [][]byte // Witness
	Vote                 []byte   // voter xpub
	SpendCommitment
}

VetoInput satisfies the TypedInput interface and represents a veto transaction.

func (*VetoInput) InputType

func (ui *VetoInput) InputType() uint8

InputType is the interface function for return the input type.

type VoteOutput added in v0.3.0

type VoteOutput struct {
	OutputCommitment
	// Unconsumed suffixes of the commitment and witness extensible strings.
	CommitmentSuffix []byte
	Vote             []byte
}

VoteOutput satisfies the TypedOutput interface and represents a vote transaction.

func (*VoteOutput) OutputType added in v0.3.0

func (it *VoteOutput) OutputType() uint8

OutputType implement the txout interface

Jump to

Keyboard shortcuts

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