Documentation ¶
Index ¶
- Constants
- Variables
- func AddChildrenWork(node *BlockNode, work *big.Int)
- func BigToCompact(n *big.Int) uint32
- func CalcNextRequiredDifficulty(prevNode *BlockNode, newBlockTime time.Time) (uint32, error)
- func CalcPastMedianTime(node *BlockNode) time.Time
- func CalcWork(bits uint32) *big.Int
- func CheckAssetPrecision(Tx *tx.Transaction) error
- func CheckAttributeProgram(Tx *tx.Transaction) error
- func CheckProofOfWork(bd *Blockdata, powLimit *big.Int) error
- func CheckTransactionBalance(Tx *tx.Transaction) error
- func CheckTransactionContext(txn *tx.Transaction, ledger *Ledger) ErrCode
- func CheckTransactionContracts(Tx *tx.Transaction) error
- func CheckTransactionInput(txn *tx.Transaction) error
- func CheckTransactionOutput(txn *tx.Transaction) error
- func CheckTransactionPayload(Tx *tx.Transaction) error
- func CheckTransactionSanity(txn *tx.Transaction) ErrCode
- func CheckTransactionSize(txn *tx.Transaction) error
- func CheckTransactionUTXOLock(txn *tx.Transaction) error
- func CompactToBig(compact uint32) *big.Int
- func DumpBlockNode(node *BlockNode)
- func HashToBig(hash *Uint256) *big.Int
- func IsDoubleSpend(tx *tx.Transaction, ledger *Ledger) bool
- func IsFinalizedTransaction(msgTx *tx.Transaction, blockHeight uint32) bool
- func PowCheckBlockContext(block *Block, prevNode *BlockNode, ledger *Ledger) error
- func PowCheckBlockSanity(block *Block, powLimit *big.Int, timeSource MedianTimeSource) error
- type Block
- func (b *Block) Deserialize(r io.Reader) error
- func (b *Block) FromTrimmedData(r io.Reader) error
- func (b *Block) GetDataContent() []byte
- func (b *Block) GetProgramHashes() ([]Uint168, error)
- func (b *Block) GetPrograms() []*program.Program
- func (tx *Block) GetSize() int
- func (b *Block) Hash() Uint256
- func (b *Block) RebuildMerkleRoot() error
- func (b *Block) Serialize(w io.Writer) error
- func (bd *Block) SerializeUnsigned(w io.Writer) error
- func (b *Block) SetPrograms(prog []*program.Program)
- func (b *Block) Trim(w io.Writer) error
- func (b *Block) Verify() error
- type BlockLocator
- type BlockNode
- type Blockchain
- func (bc *Blockchain) AddBlock(block *Block) (bool, bool, error)
- func (b *Blockchain) AddNodeToIndex(node *BlockNode)
- func (bc *Blockchain) AddOrphanBlock(block *Block)
- func (bc *Blockchain) BlockExists(hash *Uint256) (bool, error)
- func (b *Blockchain) BlockLocatorFromHash(inhash *Uint256) BlockLocator
- func (bc *Blockchain) ConnectBestChain(node *BlockNode, block *Block) (bool, error)
- func (bc *Blockchain) ConnectBlock(node *BlockNode, block *Block) error
- func (bc *Blockchain) ContainsTransaction(hash Uint256) bool
- func (bc *Blockchain) CurrentBlockHash() Uint256
- func (bc *Blockchain) DisconnectBlock(node *BlockNode, block *Block) error
- func (bc *Blockchain) DumpState()
- func (bc *Blockchain) GetBestHeight() uint32
- func (bc *Blockchain) GetHeader(hash Uint256) (*Header, error)
- func (bc *Blockchain) GetOrphanRoot(hash *Uint256) *Uint256
- func (bc *Blockchain) GetPrevNodeFromBlock(block *Block) (*BlockNode, error)
- func (bc *Blockchain) GetPrevNodeFromNode(node *BlockNode) (*BlockNode, error)
- func (bc *Blockchain) GetReorganizeNodes(node *BlockNode) (*list.List, *list.List)
- func (bc *Blockchain) IsKnownOrphan(hash *Uint256) bool
- func (b *Blockchain) LatestBlockLocator() (BlockLocator, error)
- func (b *Blockchain) LatestLocatorHash(locator BlockLocator) Uint256
- func (bc *Blockchain) LoadBlockNode(blockHeader *Blockdata, hash *Uint256) (*BlockNode, error)
- func (b *Blockchain) LookupNodeInIndex(hash *Uint256) (*BlockNode, bool)
- func (b *Blockchain) MedianAdjustedTime() time.Time
- func (bc *Blockchain) ProcessBlock(block *Block, timeSource MedianTimeSource, flags uint32) (bool, bool, error)
- func (bc *Blockchain) ProcessOrphans(hash *Uint256) error
- func (bc *Blockchain) PruneBlockNodes() error
- func (bc *Blockchain) RemoveBlockNode(node *BlockNode) error
- func (b *Blockchain) RemoveNodeFromIndex(node *BlockNode)
- func (bc *Blockchain) RemoveOrphanBlock(orphan *OrphanBlock)
- func (bc *Blockchain) ReorganizeChain(detachNodes, attachNodes *list.List) error
- func (bc *Blockchain) UpdateBestHeight(val uint32)
- type Blockdata
- func (bd *Blockdata) Deserialize(r io.Reader) error
- func (bd *Blockdata) DeserializeUnsigned(r io.Reader) error
- func (bd *Blockdata) GetDataContent() []byte
- func (bd *Blockdata) GetPreBlockHash() Uint256
- func (bd *Blockdata) GetProgramHashes() ([]Uint168, error)
- func (bd *Blockdata) GetPrograms() []*program.Program
- func (bd *Blockdata) Hash() Uint256
- func (bd *Blockdata) Serialize(w io.Writer)
- func (bd *Blockdata) SerializeUnsigned(w io.Writer) error
- func (bd *Blockdata) SetPrograms(programs []*program.Program)
- type Header
- type ILedgerStore
- type Ledger
- func (l *Ledger) BlockInLedger(hash Uint256) bool
- func (l *Ledger) GetAsset(assetId Uint256) (*asset.Asset, error)
- func (l *Ledger) GetBlockWithHash(hash Uint256) (*Block, error)
- func (l *Ledger) GetBlockWithHeight(height uint32) (*Block, error)
- func (l *Ledger) GetLocalBlockChainHeight() uint32
- func (l *Ledger) GetTransactionWithHash(hash Uint256) (*tx.Transaction, error)
- func (l *Ledger) IsDoubleSpend(Tx *tx.Transaction) bool
- type MedianTimeSource
- type OrphanBlock
Constants ¶
const ( BlockVersion uint32 = 0 GenesisNonce uint32 = 2083236893 InvalidBlockSize int = -1 )
const (
FoundationAddress = "8VYXVxKKSAxkmRrfmGpQR2Kc66XhG6m3ta"
)
const (
MaxBlockLocatorsPerMsg = 500
)
const (
MaxTimeOffsetSeconds = 2 * 60 * 60
)
Variables ¶
var (
MaxBlockSize = config.Parameters.MaxBlockSize
)
var (
MinMemoryNodes = config.Parameters.ChainParam.MinMemoryNodes
)
Functions ¶
func AddChildrenWork ¶
func BigToCompact ¶
func CalcPastMedianTime ¶
func CheckAssetPrecision ¶
func CheckAssetPrecision(Tx *tx.Transaction) error
func CheckAttributeProgram ¶
func CheckAttributeProgram(Tx *tx.Transaction) error
func CheckTransactionBalance ¶
func CheckTransactionBalance(Tx *tx.Transaction) error
func CheckTransactionContext ¶
func CheckTransactionContext(txn *tx.Transaction, ledger *Ledger) ErrCode
CheckTransactionContext verifys a transaction with history transaction in ledger
func CheckTransactionContracts ¶
func CheckTransactionContracts(Tx *tx.Transaction) error
func CheckTransactionInput ¶
func CheckTransactionInput(txn *tx.Transaction) error
validate the transaction of duplicate UTXO input
func CheckTransactionOutput ¶
func CheckTransactionOutput(txn *tx.Transaction) error
func CheckTransactionPayload ¶
func CheckTransactionPayload(Tx *tx.Transaction) error
func CheckTransactionSanity ¶
func CheckTransactionSanity(txn *tx.Transaction) ErrCode
CheckTransactionSanity verifys received single transaction
func CheckTransactionSize ¶
func CheckTransactionSize(txn *tx.Transaction) error
func CheckTransactionUTXOLock ¶
func CheckTransactionUTXOLock(txn *tx.Transaction) error
func CompactToBig ¶
func DumpBlockNode ¶
func DumpBlockNode(node *BlockNode)
func IsDoubleSpend ¶
func IsDoubleSpend(tx *tx.Transaction, ledger *Ledger) bool
func IsFinalizedTransaction ¶
func IsFinalizedTransaction(msgTx *tx.Transaction, blockHeight uint32) bool
func PowCheckBlockContext ¶
func PowCheckBlockSanity ¶
func PowCheckBlockSanity(block *Block, powLimit *big.Int, timeSource MedianTimeSource) error
Types ¶
type Block ¶
type Block struct { Blockdata *Blockdata Transactions []*tx.Transaction // contains filtered or unexported fields }
func GenesisBlockInit ¶
func (*Block) GetDataContent ¶
func (*Block) GetProgramHashes ¶
func (*Block) GetPrograms ¶
func (*Block) RebuildMerkleRoot ¶
func (*Block) SetPrograms ¶
type BlockLocator ¶
type BlockLocator []Uint256
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 RemoveChildNode ¶
type Blockchain ¶
type Blockchain struct { BlockHeight uint32 GenesisHash Uint256 BestChain *BlockNode Root *BlockNode Index map[Uint256]*BlockNode IndexLock sync.RWMutex DepNodes map[Uint256][]*BlockNode Orphans map[Uint256]*OrphanBlock PrevOrphans map[Uint256][]*OrphanBlock OldestOrphan *OrphanBlock BlockCache map[Uint256]*Block TimeSource MedianTimeSource MedianTimePast time.Time OrphanLock sync.RWMutex BCEvents *events.Event Ledger *Ledger AssetID Uint256 // contains filtered or unexported fields }
func NewBlockchain ¶
func NewBlockchain(height uint32, ledger *Ledger) *Blockchain
func NewBlockchainWithGenesisBlock ¶
func NewBlockchainWithGenesisBlock() (*Blockchain, error)
func (*Blockchain) AddNodeToIndex ¶
func (b *Blockchain) AddNodeToIndex(node *BlockNode)
func (*Blockchain) AddOrphanBlock ¶
func (bc *Blockchain) AddOrphanBlock(block *Block)
func (*Blockchain) BlockExists ¶
func (bc *Blockchain) BlockExists(hash *Uint256) (bool, error)
func (*Blockchain) BlockLocatorFromHash ¶
func (b *Blockchain) BlockLocatorFromHash(inhash *Uint256) BlockLocator
func (*Blockchain) ConnectBestChain ¶
func (bc *Blockchain) ConnectBestChain(node *BlockNode, block *Block) (bool, error)
func (*Blockchain) ConnectBlock ¶
func (bc *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 (bc *Blockchain) ContainsTransaction(hash Uint256) bool
func (*Blockchain) CurrentBlockHash ¶
func (bc *Blockchain) CurrentBlockHash() Uint256
func (*Blockchain) DisconnectBlock ¶
func (bc *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 (bc *Blockchain) DumpState()
func (*Blockchain) GetBestHeight ¶
func (bc *Blockchain) GetBestHeight() uint32
func (*Blockchain) GetHeader ¶
func (bc *Blockchain) GetHeader(hash Uint256) (*Header, error)
func (*Blockchain) GetOrphanRoot ¶
func (bc *Blockchain) GetOrphanRoot(hash *Uint256) *Uint256
func (*Blockchain) GetPrevNodeFromBlock ¶
func (bc *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 (bc *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 ¶
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 (bc *Blockchain) IsKnownOrphan(hash *Uint256) bool
func (*Blockchain) LatestBlockLocator ¶
func (b *Blockchain) LatestBlockLocator() (BlockLocator, error)
func (*Blockchain) LatestLocatorHash ¶
func (b *Blockchain) LatestLocatorHash(locator BlockLocator) Uint256
func (*Blockchain) LoadBlockNode ¶
func (bc *Blockchain) LoadBlockNode(blockHeader *Blockdata, 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 (bc *Blockchain) ProcessBlock(block *Block, timeSource MedianTimeSource, flags uint32) (bool, bool, error)
(bool, bool, error) 1. inMainChain 2. isOphan 3. error
func (*Blockchain) ProcessOrphans ¶
func (bc *Blockchain) ProcessOrphans(hash *Uint256) error
func (*Blockchain) PruneBlockNodes ¶
func (bc *Blockchain) PruneBlockNodes() error
func (*Blockchain) RemoveBlockNode ¶
func (bc *Blockchain) RemoveBlockNode(node *BlockNode) error
func (*Blockchain) RemoveNodeFromIndex ¶
func (b *Blockchain) RemoveNodeFromIndex(node *BlockNode)
func (*Blockchain) RemoveOrphanBlock ¶
func (bc *Blockchain) RemoveOrphanBlock(orphan *OrphanBlock)
func (*Blockchain) ReorganizeChain ¶
func (bc *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 (bc *Blockchain) UpdateBestHeight(val uint32)
type Blockdata ¶
type Blockdata struct { Version uint32 PrevBlockHash Uint256 TransactionsRoot Uint256 Timestamp uint32 Bits uint32 Height uint32 Nonce uint32 AuxPow auxpow.AuxPow Program *program.Program // contains filtered or unexported fields }
func (*Blockdata) GetDataContent ¶
func (*Blockdata) GetPreBlockHash ¶
func (bd *Blockdata) GetPreBlockHash() Uint256
func (*Blockdata) GetProgramHashes ¶
func (*Blockdata) GetPrograms ¶
func (*Blockdata) SerializeUnsigned ¶
Serialize the blockheader data without program
func (*Blockdata) SetPrograms ¶
type ILedgerStore ¶
type ILedgerStore interface { SaveBlock(b *Block, ledger *Ledger) error GetBlock(hash Uint256) (*Block, error) BlockInCache(hash Uint256) bool GetBlockHash(height uint32) (Uint256, error) InitLedgerStore(ledger *Ledger) error IsDoubleSpend(tx *tx.Transaction) bool //SaveHeader(header *Header,ledger *Ledger) error AddHeaders(headers []Header, ledger *Ledger) error GetHeader(hash Uint256) (*Header, error) RollbackBlock(blockHash Uint256) error GetTransaction(hash Uint256) (*tx.Transaction, uint32, error) PersistAsset(assetid Uint256, asset *Asset) error GetAsset(hash Uint256) (*Asset, error) GetCurrentBlockHash() Uint256 GetHeight() uint32 RemoveHeaderListElement(hash Uint256) InitLedgerStoreWithGenesisBlock(genesisblock *Block) (uint32, error) GetUnspent(txid Uint256, index uint16) (*tx.TxOutput, error) ContainsUnspent(txid Uint256, index uint16) (bool, error) GetUnspentFromProgramHash(programHash Uint168, assetid Uint256) ([]*tx.UTXOUnspent, error) GetUnspentsFromProgramHash(programHash Uint168) (map[Uint256][]*tx.UTXOUnspent, error) GetAssets() map[Uint256]*Asset IsTxHashDuplicate(txhash Uint256) bool IsBlockInStore(hash Uint256) bool Close() }
ILedgerStore provides func with store package.
type Ledger ¶
type Ledger struct { Blockchain *Blockchain Store ILedgerStore }
Ledger - the struct for ledger
var DefaultLedger *Ledger
func (*Ledger) BlockInLedger ¶
BlockInLedger checks if the block existed in ledger
func (*Ledger) GetBlockWithHash ¶
Get block with block hash.
func (*Ledger) GetBlockWithHeight ¶
Get Block With Height.
func (*Ledger) GetLocalBlockChainHeight ¶
Get local block chain height.
func (*Ledger) GetTransactionWithHash ¶
func (l *Ledger) GetTransactionWithHash(hash Uint256) (*tx.Transaction, error)
Get transaction with hash.
func (*Ledger) IsDoubleSpend ¶
func (l *Ledger) IsDoubleSpend(Tx *tx.Transaction) bool
check weather the transaction contains the doubleSpend.
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.