blockchain

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2019 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

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 TaskChanCap = 4
View Source
const ValueExist = 1
View Source
const ValueNone = 0

Variables

View Source
var (
	OriginIssuanceAmount           = 20000 * 10000 * 100000000
	InflationPerYear               = OriginIssuanceAmount * 3 / 100
	BlockGenerateInterval          = int64(config.Parameters.ChainParam.TargetTimePerBlock / time.Second)
	GeneratedBlocksPerYear         = 365 * 24 * 60 * 60 / BlockGenerateInterval
	TotalRewardAmountPerBlock      = common.Fixed64(float64(24 * 100000000))
	MinerRewardAmountPerBlock      = common.Fixed64(float64(4 * 100000000))
	FoundationRewardAmountPerBlock = common.Fixed64(float64(20 * 100000000))
)
View Source
var FoundationAddress Uint168
View Source
var FoundationAddress1 Uint168
View Source
var FoundationAddress10 Uint168
View Source
var FoundationAddress11 Uint168
View Source
var FoundationAddress2 Uint168
View Source
var FoundationAddress3 Uint168
View Source
var FoundationAddress4 Uint168
View Source
var FoundationAddress5 Uint168
View Source
var FoundationAddress6 Uint168
View Source
var FoundationAddress7 Uint168
View Source
var FoundationAddress8 Uint168
View Source
var FoundationAddress9 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(tx *Transaction) error

func CheckBlockContext added in v0.2.0

func CheckBlockContext(block *Block) error

func CheckDestructionAddress added in v0.2.0

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

func CheckDuplicateSidechainTx added in v0.2.0

func CheckDuplicateSidechainTx(txn *Transaction) error

validate the transaction of duplicate sidechain transaction

func CheckOutputProgramHash added in v0.2.0

func CheckOutputProgramHash(programHash Uint168) bool

func CheckProofOfWork

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

func CheckSideChainPowConsensus added in v0.2.0

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

func CheckTransactionCoinbaseOutputLock added in v0.2.0

func CheckTransactionCoinbaseOutputLock(txn *Transaction) error

func CheckTransactionContext

func CheckTransactionContext(txn *Transaction) ErrCode

CheckTransactionContext verifys a transaction with history transaction in ledger

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(version uint32, txn *Transaction) error

func CheckTransactionPayload

func CheckTransactionPayload(txn *Transaction) error

func CheckTransactionSanity

func CheckTransactionSanity(version 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.2.0

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

func CheckWithdrawFromSideChainTransaction added in v0.2.0

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

func CompactToBig

func CompactToBig(compact uint32) *big.Int

func DumpBlockNode

func DumpBlockNode(node *BlockNode)

func GetCurrentArbiter added in v0.2.0

func GetCurrentArbiter() ([]byte, error)

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) error

func IsFinalizedTransaction

func IsFinalizedTransaction(msgTx *Transaction, blockHeight uint32) 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, hashes []common.Uint168, programs []*Program) error

func SortPrograms added in v0.2.0

func SortPrograms(programs []*Program) (err error)

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
	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

	AssetID Uint256
	// 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) 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) 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) 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) 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) 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) GetSidechainTx added in v0.2.0

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) 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.2.0

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

func (*ChainStore) IsTxHashDuplicate

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

func (*ChainStore) PersistAsset

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

func (*ChainStore) PersistBlockHash

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

key: DATA_BlockHash || height value: block hash

func (*ChainStore) PersistCurrentBlock

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

key: SYS_CurrentBlock value: current block hash || height

func (*ChainStore) PersistSidechainTx added in v0.2.0

func (c *ChainStore) PersistSidechainTx(sidechainTxHash Uint256)

func (*ChainStore) PersistTransaction

func (c *ChainStore) PersistTransaction(tx *Transaction, height uint32) error

func (*ChainStore) PersistTransactions

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

func (*ChainStore) PersistTrimmedBlock

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

key: DATA_Header || block hash value: sysfee(8bytes) || trimmed block

func (*ChainStore) PersistUnspend

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

func (*ChainStore) PersistUnspendUTXOs

func (c *ChainStore) PersistUnspendUTXOs(b *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 *Block) error

func (*ChainStore) RollbackCurrentBlock

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

func (*ChainStore) RollbackSidechainTx added in v0.2.0

func (c *ChainStore) RollbackSidechainTx(sidechainTxHash Uint256) error

func (*ChainStore) RollbackTransaction

func (c *ChainStore) RollbackTransaction(txn *Transaction) 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

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

	// 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 *Block) (uint32, error)

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

	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

	RemoveHeaderListElement(hash Uint256)

	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() (IChainStore, error)

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
}

Ledger - the struct for ledger

var DefaultLedger *Ledger

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) 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 TxPool

type TxPool struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*TxPool) AppendToTxnPool

func (pool *TxPool) AppendToTxnPool(txn *Transaction) ErrCode

append transaction to txnpool when check ok. 1.check 2.check with ledger(db) 3.check with pool

func (*TxPool) CleanSubmittedTransactions

func (pool *TxPool) CleanSubmittedTransactions(block *Block) error

clean the trasaction Pool with committed block.

func (*TxPool) GetTransaction

func (pool *TxPool) GetTransaction(hash Uint256) *Transaction

get the transaction by hash

func (*TxPool) GetTransactionCount

func (pool *TxPool) GetTransactionCount() int

func (*TxPool) GetTransactionPool added in v0.2.0

func (pool *TxPool) GetTransactionPool(hasMaxCount bool) map[Uint256]*Transaction

get the transaction in txnpool

func (*TxPool) Init

func (pool *TxPool) Init()

func (*TxPool) IsDuplicateSidechainTx added in v0.2.0

func (pool *TxPool) IsDuplicateSidechainTx(sidechainTxHash Uint256) bool

func (*TxPool) MaybeAcceptTransaction

func (pool *TxPool) MaybeAcceptTransaction(txn *Transaction) error

func (*TxPool) RemoveTransaction

func (pool *TxPool) RemoveTransaction(txn *Transaction)

type UTXO

type UTXO struct {
	TxID  Uint256
	Index uint32
	Value Fixed64
}

func (*UTXO) Deserialize

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

func (*UTXO) Serialize

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

Jump to

Keyboard shortcuts

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