block

package
v0.74.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2020 License: MIT Imports: 7 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Base

type Base struct {
	// Version of the block.
	Version uint32 `json:"version"`

	// hash of the previous block.
	PrevHash util.Uint256 `json:"previousblockhash"`

	// Root hash of a transaction list.
	MerkleRoot util.Uint256 `json:"merkleroot"`

	// The time stamp of each block must be later than previous block's time stamp.
	// Generally the difference of two block's time stamp is about 15 seconds and imprecision is allowed.
	// The height of the block must be exactly equal to the height of the previous block plus 1.
	Timestamp uint32 `json:"time"`

	// index/height of the block
	Index uint32 `json:"height"`

	// Random number also called nonce
	ConsensusData uint64 `json:"nonce"`

	// Contract address of the next miner
	NextConsensus util.Uint160 `json:"next_consensus"`

	// Script used to validate the block
	Script transaction.Witness `json:"script"`
	// contains filtered or unexported fields
}

Base holds the base info of a block

func (*Base) DecodeBinary

func (b *Base) DecodeBinary(br *io.BinReader)

DecodeBinary implements Serializable interface.

func (*Base) EncodeBinary

func (b *Base) EncodeBinary(bw *io.BinWriter)

EncodeBinary implements Serializable interface

func (*Base) GetHashableData

func (b *Base) GetHashableData() []byte

GetHashableData returns serialized hashable data of the block.

func (*Base) Hash

func (b *Base) Hash() util.Uint256

Hash returns the hash of the block.

func (*Base) VerificationHash

func (b *Base) VerificationHash() util.Uint256

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

func (*Base) Verify

func (b *Base) Verify() bool

Verify verifies the integrity of the Base.

type Block

type Block struct {
	// The base of the block.
	Base

	// Transaction list.
	Transactions []*transaction.Transaction `json:"tx"`

	// True if this block is created from trimmed data.
	Trimmed bool `json:"-"`
}

Block represents one block in the chain.

func NewBlockFromTrimmedBytes

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

NewBlockFromTrimmedBytes returns a new block from trimmed data. This is commonly used to create a block from stored data. Blocks created from trimmed data will have their Trimmed field set to true.

func (*Block) Compare

func (b *Block) Compare(item queue.Item) int

Compare implements the queue Item interface.

func (*Block) DecodeBinary

func (b *Block) DecodeBinary(br *io.BinReader)

DecodeBinary decodes the block from the given BinReader, implementing Serializable interface.

func (*Block) EncodeBinary

func (b *Block) EncodeBinary(bw *io.BinWriter)

EncodeBinary encodes the block to the given BinWriter, implementing Serializable interface.

func (*Block) Header

func (b *Block) Header() *Header

Header returns the Header of the Block.

func (*Block) RebuildMerkleRoot

func (b *Block) RebuildMerkleRoot() error

RebuildMerkleRoot rebuilds the merkleroot of the block.

func (*Block) Trim

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

Trim returns a subset of the block data to save up space in storage. Notice that only the hashes of the transactions are stored.

func (*Block) Verify

func (b *Block) Verify() error

Verify verifies the integrity of the block.

type Header struct {
	// Base of the block.
	Base
	// contains filtered or unexported fields
}

Header holds the head info of a block.

func (*Header) DecodeBinary

func (h *Header) DecodeBinary(r *io.BinReader)

DecodeBinary implements Serializable interface.

func (*Header) EncodeBinary

func (h *Header) EncodeBinary(w *io.BinWriter)

EncodeBinary implements Serializable interface.

Jump to

Keyboard shortcuts

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