Documentation ¶
Index ¶
- Constants
- Variables
- func AddChildrenWork(node *BlockNode, work *big.Int)
- func AssertBigInt(value interface{}) *big.Int
- func AssertBlock(value interface{}) *types.Block
- func AssertBlockHeight(value interface{}) uint32
- func AssertHeader(value interface{}) *types.Header
- func AssertTransaction(value interface{}) *types.Transaction
- func AssertUint32(value interface{}) uint32
- func BigToCompact(n *big.Int) uint32
- func CalcPastMedianTime(node *BlockNode) time.Time
- func CalcWork(bits uint32) *big.Int
- func CheckTransactionFinalize(tx *types.Transaction, blockHeight uint32) error
- func CompactToBig(compact uint32) *big.Int
- func DisableLog()
- func GetUint16Array(source []byte) ([]uint16, error)
- func HashToBig(hash *common.Uint256) *big.Int
- func ToByteArray(source []uint16) []byte
- func UseLogger(logger elalog.Logger)
- type BlockChain
- func (b *BlockChain) AddNodeToIndex(node *BlockNode)
- func (b *BlockChain) AddOrphanBlock(block *types.Block)
- func (b *BlockChain) BlockExists(hash *common.Uint256) (bool, error)
- func (b *BlockChain) BlockLocatorFromHash(inhash *common.Uint256) []*common.Uint256
- func (b *BlockChain) CalcCurrentDifficulty(currentBits uint32) string
- func (b *BlockChain) CalcNextRequiredDifficulty(prevNode *BlockNode, newBlockTime time.Time) (uint32, error)
- func (b *BlockChain) CheckBlockContext(block *types.Block) error
- func (b *BlockChain) ContainsTransaction(hash common.Uint256) bool
- func (b *BlockChain) CurrentBlockHash() common.Uint256
- func (b *BlockChain) DumpState()
- func (b *BlockChain) GetAsset(assetId common.Uint256) (*types.Asset, error)
- func (b *BlockChain) GetAssetUnspents(programHash common.Uint168, assetid common.Uint256) ([]*types.UTXO, error)
- func (b *BlockChain) GetAssets() map[common.Uint256]*types.Asset
- func (b *BlockChain) GetBestHeight() uint32
- func (b *BlockChain) GetBlockByHash(hash common.Uint256) (*types.Block, error)
- func (b *BlockChain) GetBlockHash(height uint32) (common.Uint256, error)
- func (b *BlockChain) GetBlockWithHeight(height uint32) (*types.Block, error)
- func (b *BlockChain) GetHeader(hash common.Uint256) (*types.Header, error)
- func (b *BlockChain) GetOrphanRoot(hash *common.Uint256) *common.Uint256
- func (b *BlockChain) GetPrevNodeFromBlock(block *types.Block) (*BlockNode, error)
- func (b *BlockChain) GetPrevNodeFromNode(node *BlockNode) (*BlockNode, error)
- func (b *BlockChain) GetTransaction(hash common.Uint256) (*types.Transaction, uint32, error)
- func (b *BlockChain) GetTxReference(tx *types.Transaction) (map[*types.Input]*types.Output, error)
- func (b *BlockChain) GetUnspents(programHash common.Uint168) (map[common.Uint256][]*types.UTXO, error)
- func (b *BlockChain) HaveBlock(hash *common.Uint256) (bool, error)
- func (b *BlockChain) IsDoubleSpend(tx *types.Transaction) bool
- func (b *BlockChain) IsDuplicateMainchainTx(txId common.Uint256) bool
- func (b *BlockChain) IsDuplicateTx(txId common.Uint256) bool
- func (b *BlockChain) IsKnownOrphan(hash *common.Uint256) bool
- func (b *BlockChain) LatestBlockLocator() ([]*common.Uint256, error)
- func (b *BlockChain) LoadBlockNode(blockHeader *types.Header, hash *common.Uint256) (*BlockNode, error)
- func (b *BlockChain) LocateBlocks(locator []*common.Uint256, hashStop *common.Uint256, maxHashes uint32) []*common.Uint256
- func (b *BlockChain) LookupNodeInIndex(hash *common.Uint256) (*BlockNode, bool)
- func (b *BlockChain) MedianAdjustedTime() time.Time
- func (b *BlockChain) ProcessBlock(block *types.Block) (bool, bool, error)
- func (b *BlockChain) ProcessOrphans(hash *common.Uint256) error
- func (b *BlockChain) PruneBlockNodes() error
- func (b *BlockChain) RemoveBlockNode(node *BlockNode) error
- func (b *BlockChain) RemoveNodeFromIndex(node *BlockNode)
- func (b *BlockChain) RemoveOrphanBlock(orphan *OrphanBlock)
- type BlockNode
- type BlockValidateAction
- type ChainStore
- func (s *ChainStore) Close()
- func (s *ChainStore) ContainsUnspent(txid common.Uint256, index uint16) (bool, error)
- func (s *ChainStore) GetAsset(hash common.Uint256) (*types.Asset, error)
- func (s *ChainStore) GetAssetUnspents(programHash common.Uint168, assetid common.Uint256) ([]*types.UTXO, error)
- func (s *ChainStore) GetAssets() map[common.Uint256]*types.Asset
- func (s *ChainStore) GetBlock(hash common.Uint256) (*types.Block, error)
- func (s *ChainStore) GetBlockHash(height uint32) (common.Uint256, error)
- func (s *ChainStore) GetCurrentBlockHash() common.Uint256
- func (s *ChainStore) GetHeader(hash common.Uint256) (*types.Header, error)
- func (s *ChainStore) GetHeight() uint32
- func (s *ChainStore) GetMainchainTx(mainchainTxHash common.Uint256) (byte, error)
- func (s *ChainStore) GetTransaction(txId common.Uint256) (*types.Transaction, uint32, error)
- func (s *ChainStore) GetTxReference(tx *types.Transaction) (map[*types.Input]*types.Output, error)
- func (s *ChainStore) GetUnspent(txid common.Uint256, index uint16) (*types.Output, error)
- func (s *ChainStore) GetUnspentElementFromProgramHash(programHash common.Uint168, assetid common.Uint256, height uint32) ([]*types.UTXO, error)
- func (s *ChainStore) GetUnspents(programHash common.Uint168) (map[common.Uint256][]*types.UTXO, error)
- func (s *ChainStore) IsBlockInStore(hash *common.Uint256) bool
- func (s *ChainStore) IsDoubleSpend(txn *types.Transaction) bool
- func (s *ChainStore) IsDuplicateMainchainTx(mainchainTxHash common.Uint256) bool
- func (s *ChainStore) IsDuplicateTx(txId common.Uint256) bool
- func (s *ChainStore) PersistAsset(batch database.Batch, assetId common.Uint256, asset types.Asset) error
- func (s *ChainStore) PersistMainchainTx(batch database.Batch, mainchainTxHash common.Uint256)
- func (s *ChainStore) PersistTransaction(batch database.Batch, tx *types.Transaction, height uint32) error
- func (s *ChainStore) PersistUnspentWithProgramHash(batch database.Batch, programHash common.Uint168, assetid common.Uint256, ...) error
- func (s *ChainStore) RegisterFunctions(isPersist bool, name StoreFuncName, ...)
- func (s *ChainStore) RollbackAsset(batch database.Batch, assetId common.Uint256) error
- func (s *ChainStore) RollbackBlock(blockHash common.Uint256) error
- func (s *ChainStore) RollbackMainchainTx(batch database.Batch, mainchainTxHash common.Uint256) error
- func (s *ChainStore) RollbackTransaction(batch database.Batch, txn *types.Transaction) error
- func (s *ChainStore) SaveBlock(b *types.Block) error
- type Config
- type EntryPrefix
- type MedianTimeSource
- type OrphanBlock
- type StoreFuncName
- type ValidateFuncName
- type Validator
- func (v *Validator) CheckBlockContext(block *types.Block, prevNode *BlockNode) (err error)
- func (v *Validator) CheckBlockSanity(block *types.Block, powLimit *big.Int, timeSource MedianTimeSource) error
- func (v *Validator) RegisterFunc(name ValidateFuncName, function func(params ...interface{}) error)
Constants ¶
const ( ValueNone = 0 ValueExist = 1 TaskChanCap = 4 )
const (
MaxTimeOffsetSeconds = 2 * 60 * 60
)
Variables ¶
var ( ValidateFuncNames = blockValidateFuncs{ PowCheckBlockSanity: "checkblocksanity", CheckHeader: "checkheader", CheckTransactionsCount: "checktransactionscount", CheckBlockSize: "checkblocksize", CheckCoinBaseTransaction: "checkcoinbasetransaction", CheckTransactionsMerkle: "checktransactionsmerkle", PowCheckBlockContext: "checkblockcontext", CheckProofOfWork: "checkproofofwork", CheckFinalizedTransaction: "checkfinalizedtransaction", } StoreFuncNames = storeFuncs{ PersistTrimmedBlock: "persisttrimmedblock", PersistBlockHash: "persistblockhash", PersistCurrentBlock: "persistcurrentblock", PersistUnspendUTXOs: "persistunspendutxos", PersistTransactions: "persisttransactions", PersistUnspend: "persistunspend", RollbackTrimmedBlock: "rollbacktrimmedblock", RollbackBlockHash: "rollbackblockhash", RollbackCurrentBlock: "rollbackcurrentblock", RollbackUnspendUTXOs: "rollbackunspendutxos", RollbackTransactions: "rollbacktransactions", RollbackUnspend: "rollbackunspend", } )
Functions ¶
func AddChildrenWork ¶
func AssertBigInt ¶ added in v0.1.1
func AssertBlock ¶ added in v0.1.1
func AssertBlockHeight ¶ added in v0.1.1
func AssertBlockHeight(value interface{}) uint32
func AssertHeader ¶ added in v0.1.1
func AssertTransaction ¶ added in v0.1.1
func AssertTransaction(value interface{}) *types.Transaction
func AssertUint32 ¶ added in v0.1.1
func AssertUint32(value interface{}) uint32
func BigToCompact ¶
func CalcPastMedianTime ¶
func CheckTransactionFinalize ¶ added in v0.1.1
func CheckTransactionFinalize(tx *types.Transaction, blockHeight uint32) error
func CompactToBig ¶
func DisableLog ¶ added in v0.1.1
func DisableLog()
DisableLog disables all library log output. Logging output is disabled by default until either UseLogger or SetLogWriter are called.
func GetUint16Array ¶
func ToByteArray ¶
Types ¶
type BlockChain ¶ added in v0.1.1
type BlockChain struct { GenesisHash common.Uint256 BestChain *BlockNode Root *BlockNode Index map[common.Uint256]*BlockNode IndexLock sync.RWMutex DepNodes map[common.Uint256][]*BlockNode Orphans map[common.Uint256]*OrphanBlock PrevOrphans map[common.Uint256][]*OrphanBlock OldestOrphan *OrphanBlock BlockCache map[common.Uint256]*types.Block TimeSource MedianTimeSource MedianTimePast time.Time OrphanLock sync.RWMutex // contains filtered or unexported fields }
func New ¶ added in v0.1.1
func New(cfg *Config) (*BlockChain, error)
func (*BlockChain) AddNodeToIndex ¶ added in v0.1.1
func (b *BlockChain) AddNodeToIndex(node *BlockNode)
func (*BlockChain) AddOrphanBlock ¶ added in v0.1.1
func (b *BlockChain) AddOrphanBlock(block *types.Block)
func (*BlockChain) BlockExists ¶ added in v0.1.1
func (b *BlockChain) BlockExists(hash *common.Uint256) (bool, error)
func (*BlockChain) BlockLocatorFromHash ¶ added in v0.1.1
func (b *BlockChain) BlockLocatorFromHash(inhash *common.Uint256) []*common.Uint256
func (*BlockChain) CalcCurrentDifficulty ¶ added in v0.1.1
func (b *BlockChain) CalcCurrentDifficulty(currentBits uint32) string
func (*BlockChain) CalcNextRequiredDifficulty ¶ added in v0.1.1
func (*BlockChain) CheckBlockContext ¶ added in v0.1.1
func (b *BlockChain) CheckBlockContext(block *types.Block) error
func (*BlockChain) ContainsTransaction ¶ added in v0.1.1
func (b *BlockChain) ContainsTransaction(hash common.Uint256) bool
func (*BlockChain) CurrentBlockHash ¶ added in v0.1.1
func (b *BlockChain) CurrentBlockHash() common.Uint256
func (*BlockChain) DumpState ¶ added in v0.1.1
func (b *BlockChain) DumpState()
func (*BlockChain) GetAssetUnspents ¶ added in v0.1.1
func (*BlockChain) GetAssets ¶ added in v0.1.1
func (b *BlockChain) GetAssets() map[common.Uint256]*types.Asset
func (*BlockChain) GetBestHeight ¶ added in v0.1.1
func (b *BlockChain) GetBestHeight() uint32
func (*BlockChain) GetBlockByHash ¶ added in v0.1.1
Get block with block hash.
func (*BlockChain) GetBlockHash ¶ added in v0.1.1
func (b *BlockChain) GetBlockHash(height uint32) (common.Uint256, error)
Get Block hash with height
func (*BlockChain) GetBlockWithHeight ¶ added in v0.1.1
func (b *BlockChain) GetBlockWithHeight(height uint32) (*types.Block, error)
Get Block With Height.
func (*BlockChain) GetOrphanRoot ¶ added in v0.1.1
func (b *BlockChain) GetOrphanRoot(hash *common.Uint256) *common.Uint256
func (*BlockChain) GetPrevNodeFromBlock ¶ added in v0.1.1
func (b *BlockChain) GetPrevNodeFromBlock(block *types.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 ¶ added in v0.1.1
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) GetTransaction ¶ added in v0.1.1
func (b *BlockChain) GetTransaction(hash common.Uint256) (*types.Transaction, uint32, error)
Get transaction with hash.
func (*BlockChain) GetTxReference ¶ added in v0.1.1
func (b *BlockChain) GetTxReference(tx *types.Transaction) (map[*types.Input]*types.Output, error)
func (*BlockChain) GetUnspents ¶ added in v0.1.1
func (*BlockChain) HaveBlock ¶ added in v0.1.1
func (b *BlockChain) HaveBlock(hash *common.Uint256) (bool, error)
func (*BlockChain) IsDoubleSpend ¶ added in v0.1.1
func (b *BlockChain) IsDoubleSpend(tx *types.Transaction) bool
check weather the transaction contains the doubleSpend.
func (*BlockChain) IsDuplicateMainchainTx ¶ added in v0.1.1
func (b *BlockChain) IsDuplicateMainchainTx(txId common.Uint256) bool
func (*BlockChain) IsDuplicateTx ¶ added in v0.1.1
func (b *BlockChain) IsDuplicateTx(txId common.Uint256) bool
func (*BlockChain) IsKnownOrphan ¶ added in v0.1.1
func (b *BlockChain) IsKnownOrphan(hash *common.Uint256) bool
func (*BlockChain) LatestBlockLocator ¶ added in v0.1.1
func (b *BlockChain) LatestBlockLocator() ([]*common.Uint256, error)
func (*BlockChain) LoadBlockNode ¶ added in v0.1.1
func (*BlockChain) LocateBlocks ¶ added in v0.1.1
func (b *BlockChain) LocateBlocks(locator []*common.Uint256, hashStop *common.Uint256, maxHashes uint32) []*common.Uint256
LocateBlocks returns the hashes of the blocks after the first known block in the locator until the provided stop hash is reached, or up to the provided max number of block hashes.
In addition, there are two special cases:
- When no locators are provided, the stop hash is treated as a request for that block, so it will either return the stop hash itself if it is known, or nil if it is unknown
- When locators are provided, but none of them are known, hashes starting after the genesis block will be returned
This function is safe for concurrent access.
func (*BlockChain) LookupNodeInIndex ¶ added in v0.1.1
func (b *BlockChain) LookupNodeInIndex(hash *common.Uint256) (*BlockNode, bool)
func (*BlockChain) MedianAdjustedTime ¶ added in v0.1.1
func (b *BlockChain) MedianAdjustedTime() time.Time
func (*BlockChain) ProcessBlock ¶ added in v0.1.1
(bool, bool, error) 1. inMainChain 2. isOphan 3. error
func (*BlockChain) ProcessOrphans ¶ added in v0.1.1
func (b *BlockChain) ProcessOrphans(hash *common.Uint256) error
func (*BlockChain) PruneBlockNodes ¶ added in v0.1.1
func (b *BlockChain) PruneBlockNodes() error
func (*BlockChain) RemoveBlockNode ¶ added in v0.1.1
func (b *BlockChain) RemoveBlockNode(node *BlockNode) error
func (*BlockChain) RemoveNodeFromIndex ¶ added in v0.1.1
func (b *BlockChain) RemoveNodeFromIndex(node *BlockNode)
func (*BlockChain) RemoveOrphanBlock ¶ added in v0.1.1
func (b *BlockChain) RemoveOrphanBlock(orphan *OrphanBlock)
type BlockNode ¶
type BlockNode struct { Hash *common.Uint256 ParentHash *common.Uint256 Height uint32 Version uint32 Bits uint32 Timestamp uint32 WorkSum *big.Int InMainChain bool Parent *BlockNode Children []*BlockNode }
func AssertBlockNode ¶ added in v0.1.1
func AssertBlockNode(value interface{}) *BlockNode
func RemoveChildNode ¶
type BlockValidateAction ¶ added in v0.1.1
type BlockValidateAction struct { Name ValidateFuncName Handler func(params ...interface{}) error }
type ChainStore ¶
func NewChainStore ¶
func NewChainStore(path string, genesisBlock *types.Block) (*ChainStore, error)
func (*ChainStore) Close ¶
func (s *ChainStore) Close()
func (*ChainStore) ContainsUnspent ¶
func (*ChainStore) GetAssetUnspents ¶ added in v0.1.1
func (*ChainStore) GetBlockHash ¶
func (s *ChainStore) GetBlockHash(height uint32) (common.Uint256, error)
func (*ChainStore) GetCurrentBlockHash ¶
func (s *ChainStore) GetCurrentBlockHash() common.Uint256
func (*ChainStore) GetHeight ¶
func (s *ChainStore) GetHeight() uint32
func (*ChainStore) GetMainchainTx ¶
func (s *ChainStore) GetMainchainTx(mainchainTxHash common.Uint256) (byte, error)
func (*ChainStore) GetTransaction ¶
func (s *ChainStore) GetTransaction(txId common.Uint256) (*types.Transaction, uint32, error)
func (*ChainStore) GetTxReference ¶
func (s *ChainStore) GetTxReference(tx *types.Transaction) (map[*types.Input]*types.Output, error)
func (*ChainStore) GetUnspent ¶
func (*ChainStore) GetUnspentElementFromProgramHash ¶
func (*ChainStore) GetUnspents ¶ added in v0.1.1
func (*ChainStore) IsBlockInStore ¶
func (s *ChainStore) IsBlockInStore(hash *common.Uint256) bool
func (*ChainStore) IsDoubleSpend ¶
func (s *ChainStore) IsDoubleSpend(txn *types.Transaction) bool
func (*ChainStore) IsDuplicateMainchainTx ¶ added in v0.1.1
func (s *ChainStore) IsDuplicateMainchainTx(mainchainTxHash common.Uint256) bool
func (*ChainStore) IsDuplicateTx ¶ added in v0.1.1
func (s *ChainStore) IsDuplicateTx(txId common.Uint256) bool
func (*ChainStore) PersistAsset ¶
func (*ChainStore) PersistMainchainTx ¶
func (s *ChainStore) PersistMainchainTx(batch database.Batch, mainchainTxHash common.Uint256)
func (*ChainStore) PersistTransaction ¶
func (s *ChainStore) PersistTransaction(batch database.Batch, tx *types.Transaction, height uint32) error
func (*ChainStore) PersistUnspentWithProgramHash ¶
func (*ChainStore) RegisterFunctions ¶ added in v0.1.1
func (s *ChainStore) RegisterFunctions(isPersist bool, name StoreFuncName, handler func(batch database.Batch, b *types.Block) error)
func (*ChainStore) RollbackAsset ¶
func (*ChainStore) RollbackBlock ¶
func (s *ChainStore) RollbackBlock(blockHash common.Uint256) error
func (*ChainStore) RollbackMainchainTx ¶
func (*ChainStore) RollbackTransaction ¶
func (s *ChainStore) RollbackTransaction(batch database.Batch, txn *types.Transaction) error
type Config ¶ added in v0.1.1
type Config struct { ChainStore *ChainStore ChainParams *config.Params Validator *Validator CheckTxSanity func(*types.Transaction) error CheckTxContext func(*types.Transaction) error GetTxFee func(tx *types.Transaction, assetId common.Uint256) (common.Fixed64, error) }
type EntryPrefix ¶ added in v0.1.1
type EntryPrefix byte
EntryPrefix
const ( // DATA DATA_BlockHash EntryPrefix = 0x00 DATA_Header EntryPrefix = 0x01 DATA_Transaction EntryPrefix = 0x02 // INDEX IX_HeaderHashList EntryPrefix = 0x80 IX_Unspent EntryPrefix = 0x90 IX_Unspent_UTXO EntryPrefix = 0x91 IX_SideChain_Tx EntryPrefix = 0x92 IX_MainChain_Tx EntryPrefix = 0x93 IX_Identification EntryPrefix = 0x94 // ASSET ST_Info EntryPrefix = 0xc0 //NEOVM ST_Contract EntryPrefix = 0xc1 ST_Storage EntryPrefix = 0xc2 ST_Account EntryPrefix = 0xc3 ST_AssetState EntryPrefix = 0xc4 //SYSTEM SYS_CurrentBlock EntryPrefix = 0x40 SYS_CurrentBookKeeper EntryPrefix = 0x42 //CONFIG CFG_Version EntryPrefix = 0xf0 )
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 AssertMedianTimeSource ¶ added in v0.1.1
func AssertMedianTimeSource(value interface{}) MedianTimeSource
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 StoreFuncName ¶ added in v0.1.1
type StoreFuncName string
type ValidateFuncName ¶ added in v0.1.1
type ValidateFuncName string
type Validator ¶ added in v0.1.1
type Validator struct {
// contains filtered or unexported fields
}
func NewValidator ¶ added in v0.1.1
func NewValidator(chain *BlockChain, spv *spv.Service) *Validator
func (*Validator) CheckBlockContext ¶ added in v0.1.1
func (*Validator) CheckBlockSanity ¶ added in v0.1.1
func (*Validator) RegisterFunc ¶ added in v0.1.1
func (v *Validator) RegisterFunc(name ValidateFuncName, function func(params ...interface{}) error)