blockchain

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2019 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MinDepositAmount is the minimum deposit as a producer.
	MinDepositAmount = 5000 * 100000000
	// DepositLockupBlocks indicates how many blocks need to wait when cancel producer was triggered, and can submit return deposit coin request.
	DepositLockupBlocks = 2160
	MaxStringLength     = 100
)
View Source
const BITSPERKEY = 10

used to compute the size of bloom filter bits array . too small will lead to high false positive rate.

View Source
const (
	MaxBlockLocatorsPerMsg = 500
)
View Source
const (
	MaxTimeOffsetSeconds = 2 * 60 * 60
)
View Source
const ProducerConfirmations = 6

Variables

View Source
var (
	OriginIssuanceAmount   = 3300 * 10000 * 100000000
	InflationPerYear       = OriginIssuanceAmount * 4 / 100
	BlockGenerateInterval  = int64(config.Parameters.ChainParam.TargetTimePerBlock / time.Second)
	GeneratedBlocksPerYear = 365 * 24 * 60 * 60 / BlockGenerateInterval
	RewardAmountPerBlock   = common.Fixed64(float64(InflationPerYear) / float64(GeneratedBlocksPerYear))
)
View Source
var FoundationAddress Uint168
View Source
var (
	MinMemoryNodes = config.Parameters.ChainParam.MinMemoryNodes
)

Functions

func AddChildrenWork

func AddChildrenWork(node *BlockNode, work *big.Int)

func BigToCompact

func BigToCompact(n *big.Int) uint32

func CalcCurrentDifficulty

func CalcCurrentDifficulty(currentBits uint32) string

func CalcNextRequiredDifficulty

func CalcNextRequiredDifficulty(prevNode *BlockNode, newBlockTime time.Time) (uint32, error)

func CalcPastMedianTime

func CalcPastMedianTime(node *BlockNode) time.Time

func CalcWork

func CalcWork(bits uint32) *big.Int

(1 << 256) / (difficultyNum + 1)

func CheckAssetPrecision

func CheckAssetPrecision(txn *Transaction) error

func CheckAttributeProgram

func CheckAttributeProgram(blockHeight uint32, tx *Transaction) error

func CheckBlockContext added in v0.2.0

func CheckBlockContext(block *Block) error

func CheckBlockWithConfirmation added in v0.2.2

func CheckBlockWithConfirmation(block *Block, confirm *DPosProposalVoteSlot) error

func CheckCancelProducerTransaction added in v0.2.2

func CheckCancelProducerTransaction(txn *Transaction) error

func CheckConfirm added in v0.2.2

func CheckConfirm(confirm *DPosProposalVoteSlot) error

func CheckDestructionAddress added in v0.2.0

func CheckDestructionAddress(references map[*Input]*Output) error

func CheckDposIllegalBlocks added in v0.2.2

func CheckDposIllegalBlocks(d *DposIllegalBlocks) error

func CheckDuplicateSidechainTx added in v0.1.1

func CheckDuplicateSidechainTx(txn *Transaction) error

validate the transaction of duplicate sidechain transaction

func CheckIllegalBlocksTransaction added in v0.2.2

func CheckIllegalBlocksTransaction(txn *Transaction) error

func CheckIllegalProposalsTransaction added in v0.2.2

func CheckIllegalProposalsTransaction(txn *Transaction) error

func CheckIllegalVotesTransaction added in v0.2.2

func CheckIllegalVotesTransaction(txn *Transaction) error

func CheckProofOfWork

func CheckProofOfWork(header *Header, powLimit *big.Int) error

func CheckRegisterProducerTransaction added in v0.2.2

func CheckRegisterProducerTransaction(txn *Transaction) error

func CheckReturnDepositCoinTransaction added in v0.2.2

func CheckReturnDepositCoinTransaction(txn *Transaction) error

func CheckSideChainPowConsensus added in v0.1.1

func CheckSideChainPowConsensus(txn *Transaction, arbitrator []byte) error

func CheckTransactionCoinbaseOutputLock added in v0.2.0

func CheckTransactionCoinbaseOutputLock(txn *Transaction) error

func CheckTransactionContext

func CheckTransactionContext(blockHeight uint32, txn *Transaction) ErrCode

CheckTransactionContext verifys a transaction with history transaction in ledger

func CheckTransactionDepositUTXO added in v0.2.2

func CheckTransactionDepositUTXO(txn *Transaction, references map[*Input]*Output) error

func CheckTransactionFee added in v0.2.0

func CheckTransactionFee(tx *Transaction, references map[*Input]*Output) error

func CheckTransactionInput

func CheckTransactionInput(txn *Transaction) error

validate the transaction of duplicate UTXO input

func CheckTransactionOutput

func CheckTransactionOutput(blockHeight uint32, txn *Transaction) error

func CheckTransactionPayload

func CheckTransactionPayload(txn *Transaction) error

func CheckTransactionSanity

func CheckTransactionSanity(blockHeight uint32, txn *Transaction) ErrCode

CheckTransactionSanity verifys received single transaction

func CheckTransactionSignature

func CheckTransactionSignature(tx *Transaction, references map[*Input]*Output) error

func CheckTransactionSize

func CheckTransactionSize(txn *Transaction) error

func CheckTransactionUTXOLock

func CheckTransactionUTXOLock(txn *Transaction, references map[*Input]*Output) error

func CheckTransferCrossChainAssetTransaction added in v0.1.1

func CheckTransferCrossChainAssetTransaction(txn *Transaction, references map[*Input]*Output) error

func CheckUpdateProducerTransaction added in v0.2.2

func CheckUpdateProducerTransaction(txn *Transaction) error

func CheckWithdrawFromSideChainTransaction added in v0.1.1

func CheckWithdrawFromSideChainTransaction(txn *Transaction, references map[*Input]*Output) error

func CompactToBig

func CompactToBig(compact uint32) *big.Int

func DumpBlockNode

func DumpBlockNode(node *BlockNode)

func GetGenesisBlock

func GetGenesisBlock() (*Block, error)

func GetTxFee

func GetTxFee(tx *Transaction, assetId Uint256) Fixed64

func GetTxFeeMap

func GetTxFeeMap(tx *Transaction) (map[Uint256]Fixed64, error)

func GetTxProgramHashes

func GetTxProgramHashes(tx *Transaction, references map[*Input]*Output) ([]common.Uint168, error)

func GetUint16Array

func GetUint16Array(source []byte) ([]uint16, error)

func HashToBig

func HashToBig(hash *Uint256) *big.Int

func Init

func Init(store IChainStore, versions interfaces.HeightVersions) error

func IsFinalizedTransaction

func IsFinalizedTransaction(msgTx *Transaction, blockHeight uint32) bool

func IsProposalValid added in v0.2.2

func IsProposalValid(proposal *DPosProposal) bool

func IsVoteValid added in v0.2.2

func IsVoteValid(vote *DPosProposalVote) bool

func NewCoinBaseTransaction

func NewCoinBaseTransaction(coinBasePayload *PayloadCoinBase, currentHeight uint32) *Transaction

func PowCheckBlockContext

func PowCheckBlockContext(block *Block, prevNode *BlockNode, ledger *Ledger) error

func PowCheckBlockSanity

func PowCheckBlockSanity(block *Block, powLimit *big.Int, timeSource MedianTimeSource) error

func RunPrograms

func RunPrograms(data []byte, programHashes []common.Uint168, programs []*Program) error

func SortPrograms added in v0.1.1

func SortPrograms(programs []*Program)

func ToByteArray

func ToByteArray(source []uint16) []byte

Types

type BlockNode

type BlockNode struct {
	Hash        *Uint256
	ParentHash  *Uint256
	Height      uint32
	Version     uint32
	Bits        uint32
	Timestamp   uint32
	WorkSum     *big.Int
	InMainChain bool
	Parent      *BlockNode
	Children    []*BlockNode
}

func NewBlockNode

func NewBlockNode(header *Header, hash *Uint256) *BlockNode

func RemoveChildNode

func RemoveChildNode(children []*BlockNode, node *BlockNode) []*BlockNode

type Blockchain

type Blockchain struct {
	BlockHeight uint32
	GenesisHash Uint256
	BestChain   *BlockNode
	Root        *BlockNode
	IndexLock   sync.RWMutex
	Index       map[Uint256]*BlockNode
	DepNodes    map[Uint256][]*BlockNode

	Orphans            map[Uint256]*OrphanBlock
	PrevOrphans        map[Uint256][]*OrphanBlock
	OldestOrphan       *OrphanBlock
	BlockCache         map[Uint256]*Block
	TimeSource         MedianTimeSource
	MedianTimePast     time.Time
	BCEvents           *events.Event
	AssetID            Uint256
	NewBlocksListeners []interfaces.NewBlocksListener
	// contains filtered or unexported fields
}

func NewBlockchain

func NewBlockchain(height uint32) *Blockchain

func (*Blockchain) AddBlock

func (b *Blockchain) AddBlock(block *Block) (bool, bool, error)

func (*Blockchain) AddConfirm added in v0.2.2

func (b *Blockchain) AddConfirm(confirm *DPosProposalVoteSlot) error

func (*Blockchain) AddNodeToIndex

func (b *Blockchain) AddNodeToIndex(node *BlockNode)

func (*Blockchain) AddOrphanBlock

func (b *Blockchain) AddOrphanBlock(block *Block)

func (*Blockchain) BlockExists

func (b *Blockchain) BlockExists(hash *Uint256) bool

func (*Blockchain) BlockLocatorFromHash

func (b *Blockchain) BlockLocatorFromHash(inhash *Uint256) []*Uint256

func (*Blockchain) ConnectBestChain

func (b *Blockchain) ConnectBestChain(node *BlockNode, block *Block) (bool, error)

func (*Blockchain) ConnectBlock

func (b *Blockchain) ConnectBlock(node *BlockNode, block *Block) error

connectBlock handles connecting the passed node/block to the end of the main (best) chain.

func (*Blockchain) ContainsTransaction

func (b *Blockchain) ContainsTransaction(hash Uint256) bool

func (*Blockchain) CurrentBlockHash

func (b *Blockchain) CurrentBlockHash() Uint256

func (*Blockchain) DisconnectBlock

func (b *Blockchain) DisconnectBlock(node *BlockNode, block *Block) error

// disconnectBlock handles disconnecting the passed node/block from the end of // the main (best) chain.

func (*Blockchain) DumpState

func (b *Blockchain) DumpState()

func (*Blockchain) GetBestHeight

func (b *Blockchain) GetBestHeight() uint32

func (*Blockchain) GetBlock added in v0.2.2

func (b *Blockchain) GetBlock(hash Uint256) (*Block, error)

func (*Blockchain) GetHeader

func (b *Blockchain) GetHeader(hash Uint256) (*Header, error)

func (*Blockchain) GetOrphanRoot

func (b *Blockchain) GetOrphanRoot(hash *Uint256) *Uint256

func (*Blockchain) GetPrevNodeFromBlock

func (b *Blockchain) GetPrevNodeFromBlock(block *Block) (*BlockNode, error)

getPrevNodeFromBlock returns a block node for the block previous to the passed block (the passed block's parent). When it is already in the memory block chain, it simply returns it. Otherwise, it loads the previous block from the block database, creates a new block node from it, and returns it. The returned node will be nil if the genesis block is passed.

func (*Blockchain) GetPrevNodeFromNode

func (b *Blockchain) GetPrevNodeFromNode(node *BlockNode) (*BlockNode, error)

getPrevNodeFromNode returns a block node for the block previous to the passed block node (the passed block node's parent). When the node is already connected to a parent, it simply returns it. Otherwise, it loads the associated block from the database to obtain the previous hash and uses that to dynamically create a new block node and return it. The memory block chain is updated accordingly. The returned node will be nil if the genesis block is passed.

func (*Blockchain) GetReorganizeNodes

func (b *Blockchain) GetReorganizeNodes(node *BlockNode) (*list.List, *list.List)

getReorganizeNodes finds the fork point between the main chain and the passed node and returns a list of block nodes that would need to be detached from the main chain and a list of block nodes that would need to be attached to the fork point (which will be the end of the main chain after detaching the returned list of block nodes) in order to reorganize the chain such that the passed node is the new end of the main chain. The lists will be empty if the passed node is not on a side chain.

func (*Blockchain) IsKnownOrphan

func (b *Blockchain) IsKnownOrphan(hash *Uint256) bool

func (*Blockchain) LatestBlockLocator

func (b *Blockchain) LatestBlockLocator() ([]*Uint256, error)

func (*Blockchain) LatestLocatorHash

func (b *Blockchain) LatestLocatorHash(locator []*Uint256) *Uint256

func (*Blockchain) LoadBlockNode

func (b *Blockchain) LoadBlockNode(blockHeader *Header, hash *Uint256) (*BlockNode, error)

func (*Blockchain) LookupNodeInIndex

func (b *Blockchain) LookupNodeInIndex(hash *Uint256) (*BlockNode, bool)

func (*Blockchain) MedianAdjustedTime

func (b *Blockchain) MedianAdjustedTime() time.Time

func (*Blockchain) ProcessBlock

func (b *Blockchain) ProcessBlock(block *Block) (bool, bool, error)

(bool, bool, error) 1. inMainChain 2. isOphan 3. error

func (*Blockchain) ProcessConfirm added in v0.2.2

func (b *Blockchain) ProcessConfirm(confirm *DPosProposalVoteSlot) error

func (*Blockchain) ProcessOrphans

func (b *Blockchain) ProcessOrphans(hash *Uint256) error

func (*Blockchain) PruneBlockNodes

func (b *Blockchain) PruneBlockNodes() error

func (*Blockchain) RemoveBlockNode

func (b *Blockchain) RemoveBlockNode(node *BlockNode) error

func (*Blockchain) RemoveNodeFromIndex

func (b *Blockchain) RemoveNodeFromIndex(node *BlockNode)

func (*Blockchain) RemoveOrphanBlock

func (b *Blockchain) RemoveOrphanBlock(orphan *OrphanBlock)

func (*Blockchain) ReorganizeChain

func (b *Blockchain) ReorganizeChain(detachNodes, attachNodes *list.List) error

reorganizeChain reorganizes the block chain by disconnecting the nodes in the detachNodes list and connecting the nodes in the attach list. It expects that the lists are already in the correct order and are in sync with the end of the current best chain. Specifically, nodes that are being disconnected must be in reverse order (think of popping them off the end of the chain) and nodes the are being attached must be in forwards order (think pushing them onto the end of the chain).

func (*Blockchain) UpdateBestHeight

func (b *Blockchain) UpdateBestHeight(val uint32)

type ChainStore

type ChainStore struct {
	IStore
	// contains filtered or unexported fields
}

func (*ChainStore) Close

func (c *ChainStore) Close()

func (*ChainStore) ContainsUnspent

func (c *ChainStore) ContainsUnspent(txID Uint256, index uint16) (bool, error)

func (*ChainStore) GetActiveRegisteredProducers added in v0.2.2

func (c *ChainStore) GetActiveRegisteredProducers() []*PayloadRegisterProducer

func (*ChainStore) GetAsset

func (c *ChainStore) GetAsset(hash Uint256) (*Asset, error)

func (*ChainStore) GetAssets

func (c *ChainStore) GetAssets() map[Uint256]*Asset

func (*ChainStore) GetBlock

func (c *ChainStore) GetBlock(hash Uint256) (*Block, error)

func (*ChainStore) GetBlockHash

func (c *ChainStore) GetBlockHash(height uint32) (Uint256, error)

func (*ChainStore) GetCancelProducerHeight added in v0.2.2

func (c *ChainStore) GetCancelProducerHeight(publicKey []byte) (uint32, error)

func (*ChainStore) GetConfirm added in v0.2.2

func (c *ChainStore) GetConfirm(hash Uint256) (*DPosProposalVoteSlot, error)

func (*ChainStore) GetCurrentBlockHash

func (c *ChainStore) GetCurrentBlockHash() Uint256

func (*ChainStore) GetHeader

func (c *ChainStore) GetHeader(hash Uint256) (*Header, error)

func (*ChainStore) GetHeight

func (c *ChainStore) GetHeight() uint32

func (*ChainStore) GetIllegalProducers added in v0.2.2

func (c *ChainStore) GetIllegalProducers() map[string]struct{}

func (*ChainStore) GetProducerStatus added in v0.2.2

func (c *ChainStore) GetProducerStatus(publicKey string) ProducerState

func (*ChainStore) GetProducerVote added in v0.2.2

func (c *ChainStore) GetProducerVote(publicKey []byte) Fixed64

func (*ChainStore) GetRegisteredProducers added in v0.2.2

func (c *ChainStore) GetRegisteredProducers() []*PayloadRegisterProducer

func (*ChainStore) GetRegisteredProducersSorted added in v0.2.2

func (c *ChainStore) GetRegisteredProducersSorted() ([]*PayloadRegisterProducer, error)

func (*ChainStore) GetSidechainTx added in v0.1.1

func (c *ChainStore) GetSidechainTx(sidechainTxHash Uint256) (byte, error)

func (*ChainStore) GetTransaction

func (c *ChainStore) GetTransaction(txID Uint256) (*Transaction, uint32, error)

func (*ChainStore) GetTxReference

func (c *ChainStore) GetTxReference(tx *Transaction) (map[*Input]*Output, error)

func (*ChainStore) GetUnspent

func (c *ChainStore) GetUnspent(txID Uint256, index uint16) (*Output, error)

func (*ChainStore) GetUnspentElementFromProgramHash

func (c *ChainStore) GetUnspentElementFromProgramHash(programHash Uint168, assetid Uint256, height uint32) ([]*UTXO, error)

func (*ChainStore) GetUnspentFromProgramHash

func (c *ChainStore) GetUnspentFromProgramHash(programHash Uint168, assetid Uint256) ([]*UTXO, error)

func (*ChainStore) GetUnspentsFromProgramHash

func (c *ChainStore) GetUnspentsFromProgramHash(programHash Uint168) (map[Uint256][]*UTXO, error)

func (*ChainStore) InitProducerVotes added in v0.2.2

func (c *ChainStore) InitProducerVotes() error

func (*ChainStore) InitWithGenesisBlock

func (c *ChainStore) InitWithGenesisBlock(genesisBlock *Block) (uint32, error)

func (*ChainStore) IsBlockInStore

func (c *ChainStore) IsBlockInStore(hash Uint256) bool

func (*ChainStore) IsDoubleSpend

func (c *ChainStore) IsDoubleSpend(txn *Transaction) bool

func (*ChainStore) IsSidechainTxHashDuplicate added in v0.1.1

func (c *ChainStore) IsSidechainTxHashDuplicate(sidechainTxHash Uint256) bool

func (*ChainStore) IsTxHashDuplicate

func (c *ChainStore) IsTxHashDuplicate(txhash Uint256) bool

func (*ChainStore) OnIllegalBlockTxnReceived added in v0.2.2

func (c *ChainStore) OnIllegalBlockTxnReceived(txn *Transaction)

func (*ChainStore) PersistAsset

func (c *ChainStore) PersistAsset(assetID Uint256, asset Asset) error

func (*ChainStore) PersistConfirm added in v0.2.2

func (c *ChainStore) PersistConfirm(confirm *DPosProposalVoteSlot) error

func (*ChainStore) PersistSidechainTx added in v0.1.1

func (c *ChainStore) PersistSidechainTx(sidechainTxHash Uint256)

func (*ChainStore) PersistTransactions

func (c *ChainStore) PersistTransactions(b *Block) error

func (*ChainStore) PersistUnspentWithProgramHash

func (c *ChainStore) PersistUnspentWithProgramHash(programHash Uint168, assetid Uint256, height uint32, unspents []*UTXO) error

func (*ChainStore) RollbackBlock

func (c *ChainStore) RollbackBlock(blockHash Uint256) error

func (*ChainStore) RollbackBlockHash

func (c *ChainStore) RollbackBlockHash(b *Block) error

func (*ChainStore) RollbackConfirm added in v0.2.2

func (c *ChainStore) RollbackConfirm(b *Block) error

func (*ChainStore) RollbackCurrentBlock

func (c *ChainStore) RollbackCurrentBlock(b *Block) error

func (*ChainStore) RollbackTransactions

func (c *ChainStore) RollbackTransactions(b *Block) error

func (*ChainStore) RollbackTrimmedBlock

func (c *ChainStore) RollbackTrimmedBlock(b *Block) error

func (*ChainStore) RollbackUnspend

func (c *ChainStore) RollbackUnspend(b *Block) error

func (*ChainStore) RollbackUnspendUTXOs

func (c *ChainStore) RollbackUnspendUTXOs(b *Block) error

func (*ChainStore) SaveBlock

func (c *ChainStore) SaveBlock(b *Block) error

func (*ChainStore) SaveConfirm added in v0.2.2

func (c *ChainStore) SaveConfirm(confirm *DPosProposalVoteSlot) error

type ChainStoreMock added in v0.2.2

type ChainStoreMock struct {
	RegisterProducers    []*payload.PayloadRegisterProducer
	BlockHeight          uint32
	CancelProducerHeight uint32
}

func (*ChainStoreMock) Close added in v0.2.2

func (c *ChainStoreMock) Close()

func (*ChainStoreMock) ContainsUnspent added in v0.2.2

func (c *ChainStoreMock) ContainsUnspent(txID common.Uint256, index uint16) (bool, error)

func (*ChainStoreMock) GetActiveRegisteredProducers added in v0.2.2

func (c *ChainStoreMock) GetActiveRegisteredProducers() []*payload.PayloadRegisterProducer

func (*ChainStoreMock) GetAsset added in v0.2.2

func (c *ChainStoreMock) GetAsset(hash common.Uint256) (*payload.Asset, error)

func (*ChainStoreMock) GetAssets added in v0.2.2

func (c *ChainStoreMock) GetAssets() map[common.Uint256]*payload.Asset

func (*ChainStoreMock) GetBlock added in v0.2.2

func (c *ChainStoreMock) GetBlock(hash common.Uint256) (*types.Block, error)

func (*ChainStoreMock) GetBlockHash added in v0.2.2

func (c *ChainStoreMock) GetBlockHash(height uint32) (common.Uint256, error)

func (*ChainStoreMock) GetCancelProducerHeight added in v0.2.2

func (c *ChainStoreMock) GetCancelProducerHeight(publicKey []byte) (uint32, error)

func (*ChainStoreMock) GetConfirm added in v0.2.2

func (c *ChainStoreMock) GetConfirm(hash common.Uint256) (*types.DPosProposalVoteSlot, error)

func (*ChainStoreMock) GetCurrentBlockHash added in v0.2.2

func (c *ChainStoreMock) GetCurrentBlockHash() common.Uint256

func (*ChainStoreMock) GetHeader added in v0.2.2

func (c *ChainStoreMock) GetHeader(hash common.Uint256) (*types.Header, error)

func (*ChainStoreMock) GetHeight added in v0.2.2

func (c *ChainStoreMock) GetHeight() uint32

func (*ChainStoreMock) GetIllegalProducers added in v0.2.2

func (c *ChainStoreMock) GetIllegalProducers() map[string]struct{}

func (*ChainStoreMock) GetProducerStatus added in v0.2.2

func (c *ChainStoreMock) GetProducerStatus(address string) ProducerState

func (*ChainStoreMock) GetProducerVote added in v0.2.2

func (c *ChainStoreMock) GetProducerVote(publicKey []byte) common.Fixed64

func (*ChainStoreMock) GetRegisteredProducers added in v0.2.2

func (c *ChainStoreMock) GetRegisteredProducers() []*payload.PayloadRegisterProducer

func (*ChainStoreMock) GetRegisteredProducersSorted added in v0.2.2

func (c *ChainStoreMock) GetRegisteredProducersSorted() ([]*payload.PayloadRegisterProducer, error)

func (*ChainStoreMock) GetSidechainTx added in v0.2.2

func (c *ChainStoreMock) GetSidechainTx(sidechainTxHash common.Uint256) (byte, error)

func (*ChainStoreMock) GetTransaction added in v0.2.2

func (c *ChainStoreMock) GetTransaction(txID common.Uint256) (*types.Transaction, uint32, error)

func (*ChainStoreMock) GetTxReference added in v0.2.2

func (c *ChainStoreMock) GetTxReference(tx *types.Transaction) (map[*types.Input]*types.Output, error)

func (*ChainStoreMock) GetUnspent added in v0.2.2

func (c *ChainStoreMock) GetUnspent(txID common.Uint256, index uint16) (*types.Output, error)

func (*ChainStoreMock) GetUnspentFromProgramHash added in v0.2.2

func (c *ChainStoreMock) GetUnspentFromProgramHash(programHash common.Uint168, assetid common.Uint256) ([]*UTXO, error)

func (*ChainStoreMock) GetUnspentsFromProgramHash added in v0.2.2

func (c *ChainStoreMock) GetUnspentsFromProgramHash(programHash common.Uint168) (map[common.Uint256][]*UTXO, error)

func (*ChainStoreMock) InitProducerVotes added in v0.2.2

func (c *ChainStoreMock) InitProducerVotes() error

func (*ChainStoreMock) InitWithGenesisBlock added in v0.2.2

func (c *ChainStoreMock) InitWithGenesisBlock(genesisblock *types.Block) (uint32, error)

func (*ChainStoreMock) IsBlockInStore added in v0.2.2

func (c *ChainStoreMock) IsBlockInStore(hash common.Uint256) bool

func (*ChainStoreMock) IsDoubleSpend added in v0.2.2

func (c *ChainStoreMock) IsDoubleSpend(tx *types.Transaction) bool

func (*ChainStoreMock) IsSidechainTxHashDuplicate added in v0.2.2

func (c *ChainStoreMock) IsSidechainTxHashDuplicate(sidechainTxHash common.Uint256) bool

func (*ChainStoreMock) IsTxHashDuplicate added in v0.2.2

func (c *ChainStoreMock) IsTxHashDuplicate(txhash common.Uint256) bool

func (*ChainStoreMock) OnIllegalBlockTxnReceived added in v0.2.2

func (c *ChainStoreMock) OnIllegalBlockTxnReceived(txn *types.Transaction)

func (*ChainStoreMock) PersistAsset added in v0.2.2

func (c *ChainStoreMock) PersistAsset(assetid common.Uint256, asset payload.Asset) error

func (*ChainStoreMock) PersistSidechainTx added in v0.2.2

func (c *ChainStoreMock) PersistSidechainTx(sidechainTxHash common.Uint256)

func (*ChainStoreMock) RollbackBlock added in v0.2.2

func (c *ChainStoreMock) RollbackBlock(hash common.Uint256) error

func (*ChainStoreMock) SaveBlock added in v0.2.2

func (c *ChainStoreMock) SaveBlock(b *types.Block) error

func (*ChainStoreMock) SaveConfirm added in v0.2.2

func (c *ChainStoreMock) SaveConfirm(confirm *types.DPosProposalVoteSlot) error

type DataEntryPrefix

type DataEntryPrefix byte

DataEntryPrefix

const (
	// DATA
	DATABlockHash   DataEntryPrefix = 0x00
	DATAHeader      DataEntryPrefix = 0x01
	DATATransaction DataEntryPrefix = 0x02
	DATAConfirm     DataEntryPrefix = 0x03

	//SYSTEM
	SYSCurrentBlock      DataEntryPrefix = 0x40
	SYSCurrentBookKeeper DataEntryPrefix = 0x42

	// INDEX
	IXHeaderHashList DataEntryPrefix = 0x80
	IXUnspent        DataEntryPrefix = 0x90
	IXUnspentUTXO    DataEntryPrefix = 0x91
	IXSideChainTx    DataEntryPrefix = 0x92

	// ASSET
	STInfo DataEntryPrefix = 0xc0

	// DPOS
	DPOSIllegalProducer DataEntryPrefix = 0xd1

	//CONFIG
	CFGVersion DataEntryPrefix = 0xf0
)

type IChainStore

type IChainStore interface {
	IChainStoreDpos
	protocol.TxnPoolListener

	InitWithGenesisBlock(genesisblock *Block) (uint32, error)
	InitProducerVotes() error

	SaveBlock(b *Block) error
	GetBlock(hash Uint256) (*Block, error)
	GetBlockHash(height uint32) (Uint256, error)
	IsDoubleSpend(tx *Transaction) bool

	SaveConfirm(confirm *DPosProposalVoteSlot) error
	GetConfirm(hash Uint256) (*DPosProposalVoteSlot, error)

	GetHeader(hash Uint256) (*Header, error)

	RollbackBlock(hash Uint256) error

	GetTransaction(txID Uint256) (*Transaction, uint32, error)
	GetTxReference(tx *Transaction) (map[*Input]*Output, error)

	PersistAsset(assetid Uint256, asset Asset) error
	GetAsset(hash Uint256) (*Asset, error)

	PersistSidechainTx(sidechainTxHash Uint256)
	GetSidechainTx(sidechainTxHash Uint256) (byte, error)

	GetCurrentBlockHash() Uint256
	GetHeight() uint32

	GetUnspent(txID Uint256, index uint16) (*Output, error)
	ContainsUnspent(txID Uint256, index uint16) (bool, error)
	GetUnspentFromProgramHash(programHash Uint168, assetid Uint256) ([]*UTXO, error)
	GetUnspentsFromProgramHash(programHash Uint168) (map[Uint256][]*UTXO, error)
	GetAssets() map[Uint256]*Asset

	IsTxHashDuplicate(txhash Uint256) bool
	IsSidechainTxHashDuplicate(sidechainTxHash Uint256) bool
	IsBlockInStore(hash Uint256) bool

	Close()
}

IChainStore provides func with store package.

func NewChainStore

func NewChainStore(filePath string) (IChainStore, error)

type IChainStoreDpos added in v0.2.2

type IChainStoreDpos interface {
	GetRegisteredProducers() []*PayloadRegisterProducer
	GetActiveRegisteredProducers() []*PayloadRegisterProducer
	GetRegisteredProducersSorted() ([]*PayloadRegisterProducer, error)
	GetProducerVote(publicKey []byte) Fixed64
	GetProducerStatus(publicKey string) ProducerState

	GetIllegalProducers() map[string]struct{}
	GetCancelProducerHeight(publicKey []byte) (uint32, error)
}

IChainStoreDpos provides func for dpos

type IIterator

type IIterator interface {
	Next() bool
	Prev() bool
	First() bool
	Last() bool
	Seek(key []byte) bool
	Key() []byte
	Value() []byte
	Release()
}

type IStore

type IStore interface {
	Put(key []byte, value []byte) error
	Get(key []byte) ([]byte, error)
	Delete(key []byte) error
	NewBatch()
	BatchPut(key []byte, value []byte)
	BatchDelete(key []byte)
	BatchCommit() error
	Close() error
	NewIterator(prefix []byte) IIterator
}

type Iterator

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

func (*Iterator) First

func (it *Iterator) First() bool

func (*Iterator) Key

func (it *Iterator) Key() []byte

func (*Iterator) Last

func (it *Iterator) Last() bool

func (*Iterator) Next

func (it *Iterator) Next() bool

func (*Iterator) Prev

func (it *Iterator) Prev() bool

func (*Iterator) Release

func (it *Iterator) Release()

func (*Iterator) Seek

func (it *Iterator) Seek(key []byte) bool

func (*Iterator) Value

func (it *Iterator) Value() []byte

type Ledger

type Ledger struct {
	Blockchain     *Blockchain
	Store          IChainStore
	Arbitrators    interfaces.Arbitrators
	HeightVersions interfaces.HeightVersions
}

Ledger - the struct for ledger

var DefaultLedger *Ledger

func (*Ledger) AppendDposBlocks added in v0.2.2

func (l *Ledger) AppendDposBlocks(confirms []*DposBlock) error

Append blocks and confirms directly

func (*Ledger) BlockInLedger

func (l *Ledger) BlockInLedger(hash Uint256) bool

BlockInLedger checks if the block existed in ledger

func (*Ledger) GetAsset

func (l *Ledger) GetAsset(assetID Uint256) (*Asset, error)

Get the Asset from store.

func (*Ledger) GetBlockWithHash

func (l *Ledger) GetBlockWithHash(hash Uint256) (*Block, error)

Get block with block hash.

func (*Ledger) GetBlockWithHeight

func (l *Ledger) GetBlockWithHeight(height uint32) (*Block, error)

Get Block With Height.

func (*Ledger) GetDposBlocks added in v0.2.2

func (l *Ledger) GetDposBlocks(start, end uint32) ([]*DposBlock, error)

Get blocks and confirms by given height range, if end equals zero will be treat as current highest block height

func (*Ledger) GetLocalBlockChainHeight

func (l *Ledger) GetLocalBlockChainHeight() uint32

Get local block chain height.

func (*Ledger) GetTransactionWithHash

func (l *Ledger) GetTransactionWithHash(hash Uint256) (*Transaction, error)

Get transaction with hash.

func (*Ledger) IsDoubleSpend

func (l *Ledger) IsDoubleSpend(Tx *Transaction) bool

check weather the transaction contains the doubleSpend.

type LevelDB

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

func NewLevelDB

func NewLevelDB(file string) (*LevelDB, error)

func (*LevelDB) BatchCommit

func (ldb *LevelDB) BatchCommit() error

func (*LevelDB) BatchDelete

func (ldb *LevelDB) BatchDelete(key []byte)

func (*LevelDB) BatchPut

func (ldb *LevelDB) BatchPut(key []byte, value []byte)

func (*LevelDB) Close

func (ldb *LevelDB) Close() error

func (*LevelDB) Delete

func (ldb *LevelDB) Delete(key []byte) error

func (*LevelDB) Get

func (ldb *LevelDB) Get(key []byte) ([]byte, error)

func (*LevelDB) NewBatch

func (ldb *LevelDB) NewBatch()

func (*LevelDB) NewIterator

func (ldb *LevelDB) NewIterator(prefix []byte) IIterator

func (*LevelDB) Put

func (ldb *LevelDB) Put(key []byte, value []byte) error

type MedianTimeSource

type MedianTimeSource interface {
	// AdjustedTime returns the current time adjusted by the median time
	// offset as calculated from the time samples added by AddTimeSample.
	AdjustedTime() time.Time

	// AddTimeSample adds a time sample that is used when determining the
	// median time of the added samples.
	AddTimeSample(id string, timeVal time.Time)

	// Offset returns the number of seconds to adjust the local clock based
	// upon the median of the time samples added by AddTimeData.
	Offset() time.Duration
}

MedianTimeSource provides a mechanism to add several time samples which are used to determine a median time which is then used as an offset to the local clock.

func NewMedianTime

func NewMedianTime() MedianTimeSource

NewMedianTime returns a new instance of concurrency-safe implementation of the MedianTimeSource interface. The returned implementation contains the rules necessary for proper time handling in the chain consensus rules and expects the time samples to be added from the timestamp field of the version message received from remote peers that successfully connect and negotiate.

type OrphanBlock

type OrphanBlock struct {
	Block      *Block
	Expiration time.Time
}

type ProducerInfo added in v0.2.2

type ProducerInfo struct {
	Payload   *PayloadRegisterProducer
	RegHeight uint32
	Vote      Fixed64
}

type ProducerState added in v0.2.2

type ProducerState byte
const (
	TaskChanCap = 4

	ProducerUnRegistered ProducerState = 0x00
	ProducerRegistered   ProducerState = 0x01
	ProducerRegistering  ProducerState = 0x02
)

type UTXO

type UTXO struct {
	TxID  common.Uint256
	Index uint32
	Value common.Fixed64
}

func (*UTXO) Deserialize

func (uu *UTXO) Deserialize(r io.Reader) error

func (*UTXO) Serialize

func (uu *UTXO) Serialize(w io.Writer)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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