types

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2018 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SerBlockHeader
	SerBlockTransactions
	SerBlockFull
)

serflag variables, start with 1

View Source
const (
	SerWitness uint8 = 1 << iota
	SerPrevout
	SerMetadata

	// Bit mask for accepted serialization flags.
	// All other flag bits must be 0.
	SerTxHash = 0x0 // this is used only for computing transaction hash - prevout and refdata are replaced with their hashes
	SerValid  = 0x7
)

These flags are part of the wire protocol; they must not change.

View Source
const CurrentTransactionVersion = 1

CurrentTransactionVersion is the current latest supported transaction version.

Variables

This section is empty.

Functions

func ComputeOutputID

func ComputeOutputID(sc *SpendCommitment) (h bc.Hash, err error)

ComputeOutputID assembles an output entry given a spend commitment and computes and returns its corresponding entry ID.

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.

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

func (b *Block) Scan(val interface{}) error

Scan fulfills the sql.Scanner interface.

func (*Block) UnmarshalText

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

UnmarshalText fulfills the encoding.TextUnmarshaler interface.

func (*Block) Value

func (b *Block) Value() (driver.Value, error)

Value fulfills the sql.driver.Valuer interface.

func (*Block) WriteTo

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

WriteTo will write block to input 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 hash of transaction status bitmap
	TransactionStatusHash bc.Hash `json:"transaction_status_hash"`
}

BlockCommitment store the TransactionsMerkleRoot && TransactionStatusHash

type BlockHeader

type BlockHeader struct {
	// Version of the block.
	Version uint64 `json:"version"`

	// Height of the block in the block chain.
	// Initial block has height 1.
	Height uint64 `json:"height"`

	// Hash of the previous block in the block chain.
	PreviousBlockHash bc.Hash `json:"previous_block_hash"`

	// Time of the block in seconds.
	Timestamp uint64 `json:"timestamp"`

	BlockCommitment

	Nonce uint64 `json:"nonce"`
	Bits  uint64 `json:"bits"`
}

BlockHeader describes necessary data of the block.

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

func (bh *BlockHeader) Scan(val interface{}) error

Scan validates the input byte slice is a valid block header

func (*BlockHeader) Time

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

Time returns the time represented by the Timestamp in bh.

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 CoinbaseInput

type CoinbaseInput struct {
	Arbitrary []byte
}

CoinbaseInput is record the coinbase message

func (*CoinbaseInput) IsCoinbase

func (cb *CoinbaseInput) IsCoinbase() bool

IsCoinbase is the interface function for return the struct type

func (*CoinbaseInput) IsIssuance

func (cb *CoinbaseInput) IsIssuance() bool

IsIssuance is the interface function for return the struct type

type IssuanceInput

type IssuanceInput struct {
	// Commitment
	Nonce  []byte
	Amount uint64

	// Witness
	IssuanceWitness
}

func (*IssuanceInput) AssetDefinitionHash

func (ii *IssuanceInput) AssetDefinitionHash() (defhash bc.Hash)

func (*IssuanceInput) AssetID

func (ii *IssuanceInput) AssetID() bc.AssetID

func (*IssuanceInput) IsCoinbase

func (ii *IssuanceInput) IsCoinbase() bool

func (*IssuanceInput) IsIssuance

func (ii *IssuanceInput) IsIssuance() bool

type IssuanceWitness

type IssuanceWitness struct {
	AssetDefinition []byte
	VMVersion       uint64
	IssuanceProgram []byte
	Arguments       [][]byte
}

type OutputCommitment

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

OutputCommitment contains the commitment data for a transaction output (which also appears in the spend input of that output).

func (*OutputCommitment) Hash

func (oc *OutputCommitment) Hash(suffix []byte, assetVersion uint64) (outputhash bc.Hash)

Hash convert suffix && assetVersion to bc.Hash

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 (which also appears in the spend input of that output).

func (*SpendCommitment) Hash

func (sc *SpendCommitment) Hash(suffix []byte, assetVersion uint64) (spendhash bc.Hash)

type SpendInput

type SpendInput struct {
	// Commitment
	SpendCommitment

	// The unconsumed suffix of the output commitment
	SpendCommitmentSuffix []byte

	// Witness
	Arguments [][]byte
}

SpendInput satisfies the TypedInput interface and represents a spend transaction.

func (*SpendInput) IsCoinbase

func (si *SpendInput) IsCoinbase() bool

func (*SpendInput) IsIssuance

func (si *SpendInput) IsIssuance() bool

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

func (tx *Tx) IssuanceHash(n int) bc.Hash

func (*Tx) OutputID

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

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

type TxData

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

	TimeRange uint64

	// The unconsumed suffix of the common fields extensible string
	CommonFieldsSuffix []byte

	// The unconsumed suffix of the common witness extensible string
	CommonWitnessSuffix []byte
}

TxData encodes a transaction in the blockchain. Most users will want to use Tx instead; it includes the hash.

func (*TxData) HasIssuance

func (tx *TxData) HasIssuance() bool

HasIssuance returns true if this transaction has an issuance input.

func (*TxData) MarshalText

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

func (*TxData) UnmarshalText

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

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

	// Unconsumed suffixes of the commitment and witness extensible
	// strings.
	CommitmentSuffix []byte
	WitnessSuffix    []byte
}

func NewCoinbaseInput

func NewCoinbaseInput(arbitrary []byte) *TxInput

NewCoinbaseInput create a new coinbase input struct

func NewIssuanceInput

func NewIssuanceInput(
	nonce []byte,
	amount uint64,
	issuanceProgram []byte,
	arguments [][]byte,
	assetDefinition []byte,
) *TxInput

func NewSpendInput

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

func (*TxInput) Amount

func (t *TxInput) Amount() uint64

func (*TxInput) Arguments

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

func (*TxInput) AssetAmount

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

func (*TxInput) AssetID

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

func (*TxInput) ControlProgram

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

func (*TxInput) IssuanceProgram

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

func (*TxInput) SetArguments

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

func (*TxInput) SpentOutputID

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

func (*TxInput) WriteInputCommitment

func (t *TxInput) WriteInputCommitment(w io.Writer, serflags uint8) (err error)

type TxOutput

type TxOutput struct {
	AssetVersion uint64
	OutputCommitment

	// Unconsumed suffixes of the commitment and witness extensible strings.
	CommitmentSuffix []byte
	WitnessSuffix    []byte
}

func NewTxOutput

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

func (*TxOutput) CommitmentHash

func (to *TxOutput) CommitmentHash() bc.Hash

func (*TxOutput) WriteCommitment

func (to *TxOutput) WriteCommitment(w io.Writer) error

type TypedInput

type TypedInput interface {
	IsIssuance() bool
	IsCoinbase() bool
}

Jump to

Keyboard shortcuts

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