Documentation ¶
Index ¶
- Constants
- Variables
- func AddChildrenWork(node *BlockNode, work *big.Int)
- func BigToCompact(n *big.Int) uint32
- func CalcCurrentDifficulty(currentBits uint32) string
- func CalcNextRequiredDifficulty(prevNode *BlockNode, newBlockTime time.Time) (uint32, error)
- func CalcPastMedianTime(node *BlockNode) time.Time
- func CalcWork(bits uint32) *big.Int
- func CheckAssetPrecision(txn *core.Transaction) error
- func CheckAttributeProgram(txn *core.Transaction) error
- func CheckOutputProgramHash(programHash Uint168) bool
- func CheckProofOfWork(header *Header, powLimit *big.Int) error
- func CheckRechargeToSideChainTransaction(txn *core.Transaction) error
- func CheckTransactionBalance(txn *core.Transaction) error
- func CheckTransactionContext(txn *core.Transaction) ErrCode
- func CheckTransactionInput(txn *core.Transaction) error
- func CheckTransactionOutput(txn *core.Transaction) error
- func CheckTransactionPayload(txn *core.Transaction) error
- func CheckTransactionSanity(txn *core.Transaction) ErrCode
- func CheckTransactionSignature(txn *core.Transaction) error
- func CheckTransactionSize(txn *core.Transaction) error
- func CheckTransactionUTXOLock(txn *core.Transaction) error
- func CheckTransferCrossChainAssetTransaction(txn *core.Transaction) error
- func CompactToBig(compact uint32) *big.Int
- func DumpBlockNode(node *BlockNode)
- func GetGenesisBlock() (*core.Block, error)
- func GetTxFee(tx *core.Transaction, assetId Uint256) Fixed64
- func GetTxFeeMap(tx *core.Transaction) (map[Uint256]Fixed64, error)
- func GetTxProgramHashes(tx *core.Transaction) ([]Uint168, error)
- func GetUint16Array(source []byte) ([]uint16, error)
- func HashToBig(hash *Uint256) *big.Int
- func Init(store IChainStore) error
- func IsFinalizedTransaction(msgTx *Transaction, blockHeight uint32) bool
- func NewCoinBaseTransaction(coinBasePayload *core.PayloadCoinBase, currentHeight uint32) *core.Transaction
- func PowCheckBlockContext(block *Block, prevNode *BlockNode, ledger *Ledger) error
- func PowCheckBlockSanity(block *Block, powLimit *big.Int, timeSource MedianTimeSource) error
- func RunPrograms(tx *core.Transaction, hashes []Uint168, programs []*core.Program) error
- func SortPrograms(programs []*core.Program)
- func ToByteArray(source []uint16) []byte
- func VerifySignature(tx *core.Transaction) error
- type BlockNode
- type Blockchain
- func (bc *Blockchain) AddBlock(block *core.Block) (bool, bool, error)
- func (b *Blockchain) AddNodeToIndex(node *BlockNode)
- func (bc *Blockchain) AddOrphanBlock(block *core.Block)
- func (bc *Blockchain) BlockExists(hash *Uint256) (bool, error)
- func (b *Blockchain) BlockLocatorFromHash(inhash *Uint256) []*Uint256
- func (bc *Blockchain) ConnectBestChain(node *BlockNode, block *core.Block) (bool, error)
- func (bc *Blockchain) ConnectBlock(node *BlockNode, block *core.Block) error
- func (bc *Blockchain) ContainsTransaction(hash Uint256) bool
- func (bc *Blockchain) CurrentBlockHash() Uint256
- func (bc *Blockchain) DisconnectBlock(node *BlockNode, block *core.Block) error
- func (bc *Blockchain) DumpState()
- func (bc *Blockchain) GetBestHeight() uint32
- func (bc *Blockchain) GetHeader(hash Uint256) (*core.Header, error)
- func (bc *Blockchain) GetOrphanRoot(hash *Uint256) *Uint256
- func (bc *Blockchain) GetPrevNodeFromBlock(block *core.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() ([]*Uint256, error)
- func (b *Blockchain) LatestLocatorHash(locator []*Uint256) *Uint256
- func (bc *Blockchain) LoadBlockNode(blockHeader *core.Header, hash *Uint256) (*BlockNode, error)
- func (b *Blockchain) LookupNodeInIndex(hash *Uint256) (*BlockNode, bool)
- func (b *Blockchain) MedianAdjustedTime() time.Time
- func (bc *Blockchain) ProcessBlock(block *core.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(height uint32)
- type ChainStore
- func (c *ChainStore) Close()
- func (c *ChainStore) ContainsUnspent(txid Uint256, index uint16) (bool, error)
- func (c *ChainStore) GetAsset(hash Uint256) (*core.Asset, error)
- func (c *ChainStore) GetAssets() map[Uint256]*core.Asset
- func (c *ChainStore) GetBlock(hash Uint256) (*core.Block, error)
- func (c *ChainStore) GetBlockHash(height uint32) (Uint256, error)
- func (c *ChainStore) GetCurrentBlockHash() Uint256
- func (c *ChainStore) GetHeader(hash Uint256) (*core.Header, error)
- func (c *ChainStore) GetHeight() uint32
- func (c *ChainStore) GetMainchainTx(mainchainTxHash Uint256) (byte, error)
- func (c *ChainStore) GetTransaction(txId Uint256) (*core.Transaction, uint32, error)
- func (c *ChainStore) GetTxReference(tx *core.Transaction) (map[*core.Input]*core.Output, error)
- func (c *ChainStore) GetUnspent(txid Uint256, index uint16) (*core.Output, error)
- func (c *ChainStore) GetUnspentElementFromProgramHash(programHash Uint168, assetid Uint256, height uint32) ([]*UTXO, error)
- func (c *ChainStore) GetUnspentFromProgramHash(programHash Uint168, assetid Uint256) ([]*UTXO, error)
- func (c *ChainStore) GetUnspentsFromProgramHash(programHash Uint168) (map[Uint256][]*UTXO, error)
- func (c *ChainStore) InitWithGenesisBlock(genesisBlock *core.Block) (uint32, error)
- func (c *ChainStore) IsBlockInStore(hash Uint256) bool
- func (c *ChainStore) IsDoubleSpend(txn *core.Transaction) bool
- func (c *ChainStore) IsMainchainTxHashDuplicate(mainchainTxHash Uint256) bool
- func (c *ChainStore) IsTxHashDuplicate(txhash Uint256) bool
- func (c *ChainStore) PersistAsset(assetId Uint256, asset core.Asset) error
- func (c *ChainStore) PersistBlockHash(b *core.Block) error
- func (c *ChainStore) PersistCurrentBlock(b *core.Block) error
- func (c *ChainStore) PersistMainchainTx(mainchainTxHash Uint256)
- func (c *ChainStore) PersistTransaction(tx *core.Transaction, height uint32) error
- func (c *ChainStore) PersistTransactions(b *core.Block) error
- func (c *ChainStore) PersistTrimmedBlock(b *core.Block) error
- func (c *ChainStore) PersistUnspend(b *core.Block) error
- func (c *ChainStore) PersistUnspendUTXOs(b *core.Block) error
- func (c *ChainStore) PersistUnspentWithProgramHash(programHash Uint168, assetid Uint256, height uint32, unspents []*UTXO) error
- func (c *ChainStore) RemoveHeaderListElement(hash Uint256)
- func (c *ChainStore) RollbackAsset(assetId Uint256) error
- func (c *ChainStore) RollbackBlock(blockHash Uint256) error
- func (c *ChainStore) RollbackBlockHash(b *core.Block) error
- func (c *ChainStore) RollbackCurrentBlock(b *core.Block) error
- func (c *ChainStore) RollbackMainchainTx(mainchainTxHash Uint256) error
- func (c *ChainStore) RollbackTransaction(txn *core.Transaction) error
- func (c *ChainStore) RollbackTransactions(b *core.Block) error
- func (c *ChainStore) RollbackTrimmedBlock(b *core.Block) error
- func (c *ChainStore) RollbackUnspend(b *core.Block) error
- func (c *ChainStore) RollbackUnspendUTXOs(b *core.Block) error
- func (c *ChainStore) SaveBlock(b *core.Block) error
- type DataEntryPrefix
- type IChainStore
- type IIterator
- type IStore
- type Iterator
- type Ledger
- func (l *Ledger) BlockInLedger(hash Uint256) bool
- func (l *Ledger) GetAsset(assetId Uint256) (*core.Asset, error)
- func (l *Ledger) GetBlockWithHash(hash Uint256) (*core.Block, error)
- func (l *Ledger) GetBlockWithHeight(height uint32) (*core.Block, error)
- func (l *Ledger) GetLocalBlockChainHeight() uint32
- func (l *Ledger) GetTransactionWithHash(hash Uint256) (*core.Transaction, error)
- func (l *Ledger) IsDoubleSpend(Tx *core.Transaction) bool
- type LevelDB
- func (db *LevelDB) BatchCommit() error
- func (db *LevelDB) BatchDelete(key []byte)
- func (db *LevelDB) BatchPut(key []byte, value []byte)
- func (db *LevelDB) Close() error
- func (db *LevelDB) Delete(key []byte) error
- func (db *LevelDB) Get(key []byte) ([]byte, error)
- func (db *LevelDB) NewBatch()
- func (db *LevelDB) NewIterator(prefix []byte) IIterator
- func (db *LevelDB) Put(key []byte, value []byte) error
- type MedianTimeSource
- type OrphanBlock
- type TxPool
- func (pool *TxPool) AppendToTxnPool(txn *core.Transaction) ErrCode
- func (pool *TxPool) CleanSubmittedTransactions(block *core.Block) error
- func (pool *TxPool) GetTransaction(hash Uint256) *core.Transaction
- func (pool *TxPool) GetTransactionCount() int
- func (pool *TxPool) GetTxInPool(txId Uint256) (*core.Transaction, bool)
- func (pool *TxPool) GetTxsInPool() map[Uint256]*core.Transaction
- func (pool *TxPool) Init()
- func (pool *TxPool) IsDuplicateMainchainTx(mainchainTxHash Uint256) bool
- func (pool *TxPool) MaybeAcceptTransaction(txn *core.Transaction) error
- func (pool *TxPool) RemoveTransaction(txn *core.Transaction)
- type UTXO
Constants ¶
const BITSPERKEY = 10
used to compute the size of bloom filter bits array . too small will lead to high false positive rate.
const (
MaxBlockLocatorsPerMsg = 500
)
const (
MaxTimeOffsetSeconds = 2 * 60 * 60
)
const (
PrefixRegisterId = 0x67
)
const TaskChanCap = 4
const ValueExist = 1
const ValueNone = 0
Variables ¶
var (
ErrDBNotFound = errors.New("leveldb: not found")
)
var FoundationAddress Uint168
var (
MinMemoryNodes = config.Parameters.ChainParam.MinMemoryNodes
)
Functions ¶
func AddChildrenWork ¶
func BigToCompact ¶
func CalcCurrentDifficulty ¶
func CalcPastMedianTime ¶
func CheckAssetPrecision ¶
func CheckAssetPrecision(txn *core.Transaction) error
func CheckAttributeProgram ¶
func CheckAttributeProgram(txn *core.Transaction) error
func CheckOutputProgramHash ¶
func CheckOutputProgramHash(programHash Uint168) bool
func CheckProofOfWork ¶
func CheckRechargeToSideChainTransaction ¶
func CheckRechargeToSideChainTransaction(txn *core.Transaction) error
func CheckTransactionBalance ¶
func CheckTransactionBalance(txn *core.Transaction) error
func CheckTransactionContext ¶
func CheckTransactionContext(txn *core.Transaction) ErrCode
CheckTransactionContext verifys a transaction with history transaction in ledger
func CheckTransactionInput ¶
func CheckTransactionInput(txn *core.Transaction) error
validate the transaction of duplicate UTXO input
func CheckTransactionOutput ¶
func CheckTransactionOutput(txn *core.Transaction) error
func CheckTransactionPayload ¶
func CheckTransactionPayload(txn *core.Transaction) error
func CheckTransactionSanity ¶
func CheckTransactionSanity(txn *core.Transaction) ErrCode
CheckTransactionSanity verifys received single transaction
func CheckTransactionSignature ¶
func CheckTransactionSignature(txn *core.Transaction) error
func CheckTransactionSize ¶
func CheckTransactionSize(txn *core.Transaction) error
func CheckTransactionUTXOLock ¶
func CheckTransactionUTXOLock(txn *core.Transaction) error
func CheckTransferCrossChainAssetTransaction ¶
func CheckTransferCrossChainAssetTransaction(txn *core.Transaction) error
func CompactToBig ¶
func DumpBlockNode ¶
func DumpBlockNode(node *BlockNode)
func GetGenesisBlock ¶
func GetTxFee ¶
func GetTxFee(tx *core.Transaction, assetId Uint256) Fixed64
func GetTxFeeMap ¶
func GetTxFeeMap(tx *core.Transaction) (map[Uint256]Fixed64, error)
func GetTxProgramHashes ¶
func GetTxProgramHashes(tx *core.Transaction) ([]Uint168, error)
func GetUint16Array ¶
func Init ¶
func Init(store IChainStore) error
func IsFinalizedTransaction ¶
func NewCoinBaseTransaction ¶
func NewCoinBaseTransaction(coinBasePayload *core.PayloadCoinBase, currentHeight uint32) *core.Transaction
func PowCheckBlockContext ¶
func PowCheckBlockSanity ¶
func PowCheckBlockSanity(block *Block, powLimit *big.Int, timeSource MedianTimeSource) error
func RunPrograms ¶
func RunPrograms(tx *core.Transaction, hashes []Uint168, programs []*core.Program) error
func SortPrograms ¶
func ToByteArray ¶
func VerifySignature ¶
func VerifySignature(tx *core.Transaction) error
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 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]*core.Block TimeSource MedianTimeSource MedianTimePast time.Time OrphanLock sync.RWMutex BCEvents *events.Event AssetID Uint256 // contains filtered or unexported fields }
func NewBlockchain ¶
func NewBlockchain(height uint32) *Blockchain
func (*Blockchain) AddNodeToIndex ¶
func (b *Blockchain) AddNodeToIndex(node *BlockNode)
func (*Blockchain) AddOrphanBlock ¶
func (bc *Blockchain) AddOrphanBlock(block *core.Block)
func (*Blockchain) BlockExists ¶
func (bc *Blockchain) BlockExists(hash *Uint256) (bool, error)
func (*Blockchain) BlockLocatorFromHash ¶
func (b *Blockchain) BlockLocatorFromHash(inhash *Uint256) []*Uint256
func (*Blockchain) ConnectBestChain ¶
func (*Blockchain) ConnectBlock ¶
func (bc *Blockchain) ConnectBlock(node *BlockNode, block *core.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 *core.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) GetOrphanRoot ¶
func (bc *Blockchain) GetOrphanRoot(hash *Uint256) *Uint256
func (*Blockchain) GetPrevNodeFromBlock ¶
func (bc *Blockchain) GetPrevNodeFromBlock(block *core.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() ([]*Uint256, error)
func (*Blockchain) LatestLocatorHash ¶
func (b *Blockchain) LatestLocatorHash(locator []*Uint256) *Uint256
func (*Blockchain) LoadBlockNode ¶
func (bc *Blockchain) LoadBlockNode(blockHeader *core.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 (bc *Blockchain) ProcessBlock(block *core.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(height 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) GetAssets ¶
func (c *ChainStore) GetAssets() map[Uint256]*core.Asset
func (*ChainStore) GetBlockHash ¶
func (c *ChainStore) GetBlockHash(height uint32) (Uint256, error)
func (*ChainStore) GetCurrentBlockHash ¶
func (c *ChainStore) GetCurrentBlockHash() Uint256
func (*ChainStore) GetHeight ¶
func (c *ChainStore) GetHeight() uint32
func (*ChainStore) GetMainchainTx ¶
func (c *ChainStore) GetMainchainTx(mainchainTxHash Uint256) (byte, error)
func (*ChainStore) GetTransaction ¶
func (c *ChainStore) GetTransaction(txId Uint256) (*core.Transaction, uint32, error)
func (*ChainStore) GetTxReference ¶
func (c *ChainStore) GetTxReference(tx *core.Transaction) (map[*core.Input]*core.Output, error)
func (*ChainStore) GetUnspent ¶
func (c *ChainStore) GetUnspent(txid Uint256, index uint16) (*core.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) InitWithGenesisBlock ¶
func (c *ChainStore) InitWithGenesisBlock(genesisBlock *core.Block) (uint32, error)
func (*ChainStore) IsBlockInStore ¶
func (c *ChainStore) IsBlockInStore(hash Uint256) bool
func (*ChainStore) IsDoubleSpend ¶
func (c *ChainStore) IsDoubleSpend(txn *core.Transaction) bool
func (*ChainStore) IsMainchainTxHashDuplicate ¶
func (c *ChainStore) IsMainchainTxHashDuplicate(mainchainTxHash Uint256) bool
func (*ChainStore) IsTxHashDuplicate ¶
func (c *ChainStore) IsTxHashDuplicate(txhash Uint256) bool
func (*ChainStore) PersistAsset ¶
func (c *ChainStore) PersistAsset(assetId Uint256, asset core.Asset) error
func (*ChainStore) PersistBlockHash ¶
func (c *ChainStore) PersistBlockHash(b *core.Block) error
key: DATA_BlockHash || height value: block hash
func (*ChainStore) PersistCurrentBlock ¶
func (c *ChainStore) PersistCurrentBlock(b *core.Block) error
key: SYS_CurrentBlock value: current block hash || height
func (*ChainStore) PersistMainchainTx ¶
func (c *ChainStore) PersistMainchainTx(mainchainTxHash Uint256)
func (*ChainStore) PersistTransaction ¶
func (c *ChainStore) PersistTransaction(tx *core.Transaction, height uint32) error
func (*ChainStore) PersistTransactions ¶
func (c *ChainStore) PersistTransactions(b *core.Block) error
func (*ChainStore) PersistTrimmedBlock ¶
func (c *ChainStore) PersistTrimmedBlock(b *core.Block) error
key: DATA_Header || block hash value: sysfee(8bytes) || trimmed block
func (*ChainStore) PersistUnspend ¶
func (c *ChainStore) PersistUnspend(b *core.Block) error
func (*ChainStore) PersistUnspendUTXOs ¶
func (c *ChainStore) PersistUnspendUTXOs(b *core.Block) error
func (*ChainStore) PersistUnspentWithProgramHash ¶
func (c *ChainStore) PersistUnspentWithProgramHash(programHash Uint168, assetid Uint256, height uint32, unspents []*UTXO) error
func (*ChainStore) RemoveHeaderListElement ¶
func (c *ChainStore) RemoveHeaderListElement(hash Uint256)
func (*ChainStore) RollbackAsset ¶
func (c *ChainStore) RollbackAsset(assetId Uint256) error
func (*ChainStore) RollbackBlock ¶
func (c *ChainStore) RollbackBlock(blockHash Uint256) error
func (*ChainStore) RollbackBlockHash ¶
func (c *ChainStore) RollbackBlockHash(b *core.Block) error
func (*ChainStore) RollbackCurrentBlock ¶
func (c *ChainStore) RollbackCurrentBlock(b *core.Block) error
func (*ChainStore) RollbackMainchainTx ¶
func (c *ChainStore) RollbackMainchainTx(mainchainTxHash Uint256) error
func (*ChainStore) RollbackTransaction ¶
func (c *ChainStore) RollbackTransaction(txn *core.Transaction) error
func (*ChainStore) RollbackTransactions ¶
func (c *ChainStore) RollbackTransactions(b *core.Block) error
func (*ChainStore) RollbackTrimmedBlock ¶
func (c *ChainStore) RollbackTrimmedBlock(b *core.Block) error
func (*ChainStore) RollbackUnspend ¶
func (c *ChainStore) RollbackUnspend(b *core.Block) error
func (*ChainStore) RollbackUnspendUTXOs ¶
func (c *ChainStore) RollbackUnspendUTXOs(b *core.Block) error
type DataEntryPrefix ¶
type DataEntryPrefix byte
DataEntryPrefix
const ( // DATA DATA_BlockHash DataEntryPrefix = 0x00 DATA_Header DataEntryPrefix = 0x01 DATA_Transaction DataEntryPrefix = 0x02 // INDEX IX_HeaderHashList DataEntryPrefix = 0x80 IX_Unspent DataEntryPrefix = 0x90 IX_Unspent_UTXO DataEntryPrefix = 0x91 IX_SideChain_Tx DataEntryPrefix = 0x92 IX_MainChain_Tx DataEntryPrefix = 0x93 // ASSET ST_Info DataEntryPrefix = 0xc0 //SYSTEM SYS_CurrentBlock DataEntryPrefix = 0x40 SYS_CurrentBookKeeper DataEntryPrefix = 0x42 //CONFIG CFG_Version DataEntryPrefix = 0xf0 )
type IChainStore ¶
type IChainStore interface { InitWithGenesisBlock(genesisblock *core.Block) (uint32, error) SaveBlock(b *core.Block) error GetBlock(hash Uint256) (*core.Block, error) GetBlockHash(height uint32) (Uint256, error) IsDoubleSpend(tx *core.Transaction) bool GetHeader(hash Uint256) (*core.Header, error) RollbackBlock(hash Uint256) error GetTransaction(txId Uint256) (*core.Transaction, uint32, error) GetTxReference(tx *core.Transaction) (map[*core.Input]*core.Output, error) PersistAsset(assetid Uint256, asset core.Asset) error GetAsset(hash Uint256) (*core.Asset, error) PersistMainchainTx(mainchainTxHash Uint256) GetMainchainTx(mainchainTxHash Uint256) (byte, error) GetCurrentBlockHash() Uint256 GetHeight() uint32 RemoveHeaderListElement(hash Uint256) GetUnspent(txid Uint256, index uint16) (*core.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]*core.Asset IsTxHashDuplicate(txhash Uint256) bool IsMainchainTxHashDuplicate(mainchainTxHash Uint256) bool IsBlockInStore(hash Uint256) bool Close() }
IChainStore provides func with store package.
func NewChainStore ¶
func NewChainStore() (IChainStore, error)
type Ledger ¶
type Ledger struct { Blockchain *Blockchain Store IChainStore }
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) (*core.Transaction, error)
Get transaction with hash.
func (*Ledger) IsDoubleSpend ¶
func (l *Ledger) IsDoubleSpend(Tx *core.Transaction) bool
check weather the transaction contains the doubleSpend.
type LevelDB ¶
type LevelDB struct {
// contains filtered or unexported fields
}
func NewLevelDB ¶
func (*LevelDB) BatchCommit ¶
func (*LevelDB) BatchDelete ¶
func (*LevelDB) NewIterator ¶
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 TxPool ¶
func (*TxPool) AppendToTxnPool ¶
func (pool *TxPool) AppendToTxnPool(txn *core.Transaction) ErrCode
append transaction to txnpool when check ok. 1.check 2.check with ledger(db) 3.check with pool
func (*TxPool) CleanSubmittedTransactions ¶
clean the trasaction Pool with committed block.
func (*TxPool) GetTransaction ¶
func (pool *TxPool) GetTransaction(hash Uint256) *core.Transaction
get the transaction by hash
func (*TxPool) GetTransactionCount ¶
func (*TxPool) GetTxInPool ¶
func (pool *TxPool) GetTxInPool(txId Uint256) (*core.Transaction, bool)
GetTxInPool returns a transaction in transaction pool by the given transaction id. If no transaction match the transaction id, return nil, false
func (*TxPool) GetTxsInPool ¶
func (pool *TxPool) GetTxsInPool() map[Uint256]*core.Transaction
GetTxsInPool returns a copy of the transactions in transaction pool, It is safe to modify the returned map.
func (*TxPool) IsDuplicateMainchainTx ¶
func (*TxPool) MaybeAcceptTransaction ¶
func (pool *TxPool) MaybeAcceptTransaction(txn *core.Transaction) error
func (*TxPool) RemoveTransaction ¶
func (pool *TxPool) RemoveTransaction(txn *core.Transaction)