blockchain

package
v0.0.0-...-509fca3 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2019 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const FT byte = 0x00

Variables

View Source
var GenesisBlock = genesisBlock
View Source
var MaxTarget = new(big.Int).Lsh(big.NewInt(1), 256)

Functions

func CheckProofOfWork

func CheckProofOfWork(header *network.BlockHeader) bool

func ComputeMerkleRoot

func ComputeMerkleRoot(hashes []*utils.Hash) *utils.Hash

func DoubleHash

func DoubleHash(a, b *utils.Hash) *utils.Hash

func WriteUtxoEntry

func WriteUtxoEntry(writer io.Writer, entry *UtxoEntry) error

Types

type Block

type Block struct {
	Msg *network.BlockMessage
	Txs []*Tx
}

func NewBlock

func NewBlock() *Block

func NewBlockFromBlockMessage

func NewBlockFromBlockMessage(msg *network.BlockMessage) *Block

func (*Block) CalcBlockSubsidy

func (block *Block) CalcBlockSubsidy() uint64

func (*Block) GetWork

func (block *Block) GetWork() *big.Int

func (*Block) Hash

func (block *Block) Hash() *utils.Hash

func (*Block) IsSane

func (block *Block) IsSane() error

func (*Block) MarshalBinary

func (block *Block) MarshalBinary() ([]byte, error)

func (*Block) UnmarshalBinary

func (block *Block) UnmarshalBinary(data []byte) error

type Blockchain

type Blockchain struct {
	GenesisBlock *Block
	// contains filtered or unexported fields
}

func NewBlockchain

func NewBlockchain(config *Config) *Blockchain

func (*Blockchain) CalcNextBlockDifficulty

func (blockchain *Blockchain) CalcNextBlockDifficulty(timestamp time.Time, ancestorTimestamp time.Time, ancestorTarget *big.Int) (*big.Int, error)

func (*Blockchain) FetchAllUtxos

func (blockchain *Blockchain) FetchAllUtxos() (*Utxos, error)

func (*Blockchain) FetchStxojEntry

func (blockchain *Blockchain) FetchStxojEntry(blockHash *utils.Hash) ([]*UtxoEntry, error)

func (*Blockchain) FetchUtxos

func (blockchain *Blockchain) FetchUtxos(tx *Tx) (*Utxos, []*network.Outpoint, error)

func (*Blockchain) FindBestBlock

func (blockchain *Blockchain) FindBestBlock() (*Block, error)

func (*Blockchain) FindBlockByHash

func (blockchain *Blockchain) FindBlockByHash(hash *utils.Hash) (*Block, error)

func (*Blockchain) FindBlockHashesStartingAt

func (blockchain *Blockchain) FindBlockHashesStartingAt(hash *utils.Hash, limit int) ([]*utils.Hash, error)

func (*Blockchain) FindOrphan

func (blockchain *Blockchain) FindOrphan(hash *utils.Hash) (*Block, error)

func (*Blockchain) GenerateBlockLocator

func (blockchain *Blockchain) GenerateBlockLocator() ([]*utils.Hash, error)

func (*Blockchain) GetAncestor

func (blockchain *Blockchain) GetAncestor(blockHash *utils.Hash) (*utils.Hash, error)

func (*Blockchain) GetBlockHashAtHeight

func (blockchain *Blockchain) GetBlockHashAtHeight(height uint32) (*utils.Hash, error)

func (*Blockchain) GetFollowing

func (blockchain *Blockchain) GetFollowing(blockHash *utils.Hash) (*utils.Hash, error)

func (*Blockchain) HaveBlock

func (blockchain *Blockchain) HaveBlock(hash *utils.Hash) (bool, error)

func (*Blockchain) Load

func (blockchain *Blockchain) Load() error

func (*Blockchain) ProcessBlock

func (blockchain *Blockchain) ProcessBlock(block *Block) (error, error)

func (*Blockchain) Stop

func (blockchain *Blockchain) Stop() error

func (*Blockchain) ValidateBlock

func (blockchain *Blockchain) ValidateBlock(block *Block) (error, error)

func (*Blockchain) Validatetx

func (blockchain *Blockchain) Validatetx(tx *Tx, block *Block, utxos *Utxos) (bool, uint64, error)

type BlockchainStats

type BlockchainStats struct {
	BestBlockHash   utils.Hash
	BestBlockHeight uint32
}

type Config

type Config struct {
	DataDir       string
	OnPushedBlock func(*Block) error
	OnPoppedBlock func(*Block) error
}

type Tx

type Tx struct {
	Msg *network.TxMessage
}

func NewTxFromTxMessage

func NewTxFromTxMessage(msg *network.TxMessage) *Tx

func (*Tx) Hash

func (tx *Tx) Hash() *utils.Hash

func (*Tx) IsCoinBase

func (tx *Tx) IsCoinBase() bool

IsCoinBase returns true if the transaction is a coinbase.

func (*Tx) IsSane

func (tx *Tx) IsSane() bool

IsSane applies the validation tests of a transaction and returns true if they pass, false if they fail.

func (*Tx) SHash

func (tx *Tx) SHash(input *network.TxIn, value uint64) *utils.Hash

type UtxoEntry

type UtxoEntry struct {
	// contains filtered or unexported fields
}

func ReadUtxoEntry

func ReadUtxoEntry(reader io.Reader) (*UtxoEntry, error)

func (*UtxoEntry) Amount

func (entry *UtxoEntry) Amount() uint64

func (*UtxoEntry) BlockHeight

func (entry *UtxoEntry) BlockHeight() uint32

func (*UtxoEntry) IsCoinBase

func (entry *UtxoEntry) IsCoinBase() bool

func (*UtxoEntry) MarshalBinary

func (entry *UtxoEntry) MarshalBinary() ([]byte, error)

func (*UtxoEntry) Script

func (entry *UtxoEntry) Script() []byte

func (*UtxoEntry) UnmarshalBinary

func (entry *UtxoEntry) UnmarshalBinary(data []byte) error

type Utxos

type Utxos struct {
	// contains filtered or unexported fields
}

func (*Utxos) AddEntry

func (utxos *Utxos) AddEntry(outpoint *network.Outpoint, entry *UtxoEntry)

func (*Utxos) AddEntryWithTx

func (utxos *Utxos) AddEntryWithTx(outpoint *network.Outpoint, tx *Tx, blockHeight uint32)

func (*Utxos) FindEntry

func (utxos *Utxos) FindEntry(outpoint *network.Outpoint) *UtxoEntry

func (*Utxos) RemoveEntry

func (utxos *Utxos) RemoveEntry(outpoint *network.Outpoint) *UtxoEntry

type ValidationError

type ValidationError struct {
	Reason string
}

func (*ValidationError) Error

func (err *ValidationError) Error() string

Jump to

Keyboard shortcuts

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