Documentation ¶
Index ¶
- Constants
- Variables
- func CanVerifyHeight(height uint32) bool
- func CheckTransactionAttribute(txn *transaction.Transaction) error
- func CheckTransactionFee(txn *transaction.Transaction) error
- func CheckTransactionNonce(txn *transaction.Transaction) error
- func CheckTransactionPayload(txn *transaction.Transaction) error
- func CheckTransactionSize(txn *transaction.Transaction) error
- func GetNextBlockSigner(height uint32, timestamp int64) ([]byte, []byte, pb.WinnerType, error)
- func GetNextMiningSigChainTxnHash(height uint32) (Uint256, pb.WinnerType, error)
- func GetRewardByHeight(height uint32) common.Fixed64
- func HeaderCheck(header *block.Header) error
- func NextBlockProposerCheck(header *block.Header) error
- func SignerCheck(header *block.Header) error
- func TimestampCheck(header *block.Header, soft bool) error
- func TransactionCheck(ctx context.Context, block *block.Block) error
- func VerifyHeader(header *block.Header) bool
- func VerifyTransaction(txn *transaction.Transaction) error
- func VerifyTransactionWithLedger(txn *transaction.Transaction) error
- type BlockValidationState
- func (bvs *BlockValidationState) CleanSubmittedTransactions(txns []*transaction.Transaction) error
- func (bvs *BlockValidationState) Commit()
- func (bvs *BlockValidationState) RefreshBlockValidationState(txns []*transaction.Transaction) error
- func (bvs *BlockValidationState) Reset()
- func (bvs *BlockValidationState) VerifyTransactionWithBlock(txn *transaction.Transaction, height uint32) (e error)
- type Blockchain
- type BuiltinMining
- func (bm *BuiltinMining) BuildBlock(ctx context.Context, height uint32, chordID []byte, winnerHash common.Uint256, ...) (*block.Block, error)
- func (bm *BuiltinMining) CreateCoinbaseTransaction(reward common.Fixed64) *transaction.Transaction
- func (bm *BuiltinMining) SignBlock(b *block.Block, timestamp int64) error
- type ILedgerStore
- type Ledger
- func (l *Ledger) BlockInLedger(hash Uint256) bool
- func (l *Ledger) GetBlockWithHash(hash Uint256) (*block.Block, error)
- func (l *Ledger) GetBlockWithHeight(height uint32) (*block.Block, error)
- func (l *Ledger) GetLocalBlockChainHeight() uint32
- func (l *Ledger) GetTransactionWithHash(hash Uint256) (*transaction.Transaction, error)
- func (l *Ledger) IsDoubleSpend(Tx *transaction.Transaction) bool
- type Mining
- type TransactionArray
- type TxnCollection
- type TxnCollector
- type TxnSource
- type VBlock
Constants ¶
const ( TimestampToleranceFuture = config.ConsensusDuration / 4 TimestampTolerancePast = config.ConsensusDuration / 2 TimestampToleranceVariance = config.ConsensusDuration / 6 ProposingTimeTolerance = config.ConsensusDuration / 2 NumGenesisBlocks = 4 )
const (
MaxCollectableEntityNum = 20480
)
Variables ¶
var ( ErrIDRegistered = errors.New("ID has be registered") ErrDuplicateGenerateIDTxn = errors.New("[VerifyTransactionWithBlock], duplicate GenerateID txns") ErrDuplicateIssueAssetTxn = errors.New("[VerifyTransactionWithBlock], duplicate IssueAsset txns") )
var (
MiningRewards = make(map[uint32]common.Fixed64)
)
Functions ¶
func CanVerifyHeight ¶
func CheckTransactionAttribute ¶
func CheckTransactionAttribute(txn *transaction.Transaction) error
func CheckTransactionFee ¶
func CheckTransactionFee(txn *transaction.Transaction) error
func CheckTransactionNonce ¶
func CheckTransactionNonce(txn *transaction.Transaction) error
func CheckTransactionPayload ¶
func CheckTransactionPayload(txn *transaction.Transaction) error
func CheckTransactionSize ¶
func CheckTransactionSize(txn *transaction.Transaction) error
func GetNextBlockSigner ¶
GetNextBlockSigner gets the next block signer after block height at timestamp. Returns next signer's public key, chord ID, winner type, and error
func GetNextMiningSigChainTxnHash ¶
func GetNextMiningSigChainTxnHash(height uint32) (Uint256, pb.WinnerType, error)
GetWinner returns the winner hash and winner type of a block height using sigchain from PoR server.
func GetRewardByHeight ¶
func HeaderCheck ¶
func NextBlockProposerCheck ¶
func SignerCheck ¶
func VerifyHeader ¶
func VerifyTransaction ¶
func VerifyTransaction(txn *transaction.Transaction) error
VerifyTransaction verifys received single transaction
func VerifyTransactionWithLedger ¶
func VerifyTransactionWithLedger(txn *transaction.Transaction) error
VerifyTransactionWithLedger verifys a transaction with history transaction in ledger
Types ¶
type BlockValidationState ¶
func NewBlockValidationState ¶
func NewBlockValidationState() *BlockValidationState
func (*BlockValidationState) CleanSubmittedTransactions ¶
func (bvs *BlockValidationState) CleanSubmittedTransactions(txns []*transaction.Transaction) error
func (*BlockValidationState) Commit ¶
func (bvs *BlockValidationState) Commit()
func (*BlockValidationState) RefreshBlockValidationState ¶
func (bvs *BlockValidationState) RefreshBlockValidationState(txns []*transaction.Transaction) error
func (*BlockValidationState) Reset ¶
func (bvs *BlockValidationState) Reset()
func (*BlockValidationState) VerifyTransactionWithBlock ¶
func (bvs *BlockValidationState) VerifyTransactionWithBlock(txn *transaction.Transaction, height uint32) (e error)
VerifyTransactionWithBlock verifys a transaction with current transaction pool in memory
type Blockchain ¶
type Blockchain struct { BlockHeight uint32 AssetID Uint256 BlockPersistTime map[Uint256]int64 // contains filtered or unexported fields }
func NewBlockchain ¶
func NewBlockchain(height uint32, asset Uint256) *Blockchain
func NewBlockchainWithGenesisBlock ¶
func NewBlockchainWithGenesisBlock(store ILedgerStore) (*Blockchain, error)
type BuiltinMining ¶
type BuiltinMining struct {
// contains filtered or unexported fields
}
func NewBuiltinMining ¶
func NewBuiltinMining(account *vault.Account, txnCollector *TxnCollector) *BuiltinMining
func (*BuiltinMining) BuildBlock ¶
func (*BuiltinMining) CreateCoinbaseTransaction ¶
func (bm *BuiltinMining) CreateCoinbaseTransaction(reward common.Fixed64) *transaction.Transaction
type ILedgerStore ¶
type ILedgerStore interface { SaveBlock(b *block.Block, fastAdd bool) error GetBlock(hash Uint256) (*block.Block, error) GetBlockByHeight(height uint32) (*block.Block, error) GetBlockHash(height uint32) (Uint256, error) IsDoubleSpend(tx *transaction.Transaction) bool AddHeader(header *block.Header) error GetHeader(hash Uint256) (*block.Header, error) GetHeaderByHeight(height uint32) (*block.Header, error) GetTransaction(hash Uint256) (*transaction.Transaction, error) GetName(registrant []byte) (string, error) GetRegistrant(name string) ([]byte, error) IsSubscribed(topic string, bucket uint32, subscriber []byte, identifier string) (bool, error) GetSubscribers(topic string, bucket uint32) (map[string]string, error) GetSubscribersCount(topic string, bucket uint32) int GetFirstAvailableTopicBucket(topic string) int GetTopicBucketsCount(topic string) (uint32, error) GetID(publicKey []byte) ([]byte, error) GetBalance(addr Uint160) Fixed64 GetBalanceByAssetID(addr Uint160, assetID Uint256) Fixed64 GetNonce(addr Uint160) uint64 GetNanoPay(addr Uint160, recipient Uint160, nonce uint64) (Fixed64, uint32, error) GetCurrentBlockHash() Uint256 GetCurrentHeaderHash() Uint256 GetHeaderHeight() uint32 GetHeight() uint32 GetHeightByBlockHash(hash Uint256) (uint32, error) GetHeaderHashByHeight(height uint32) Uint256 GetHeaderWithCache(hash Uint256) (*block.Header, error) InitLedgerStoreWithGenesisBlock(genesisblock *block.Block) (uint32, error) GetDonation() (Fixed64, error) IsTxHashDuplicate(txhash Uint256) bool IsBlockInStore(hash Uint256) bool Rollback(b *block.Block) error GenerateStateRoot(b *block.Block, genesisBlockInitialized, needBeCommitted bool) (Uint256, error) GetAsset(assetID Uint256) (name, symbol string, totalSupply Fixed64, precision uint32, err error) Close() }
ILedgerStore provides func with store package.
type Ledger ¶
type Ledger struct { Blockchain *Blockchain Store ILedgerStore }
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) (*transaction.Transaction, error)
Get transaction with hash.
func (*Ledger) IsDoubleSpend ¶
func (l *Ledger) IsDoubleSpend(Tx *transaction.Transaction) bool
double spend checking for transaction
type TransactionArray ¶
type TransactionArray []*transaction.Transaction
func (TransactionArray) Iterate ¶
func (iterable TransactionArray) Iterate(handler func(item *transaction.Transaction) error) error
type TxnCollection ¶
type TxnCollection struct {
// contains filtered or unexported fields
}
func NewTxnCollection ¶
func NewTxnCollection(txnLists map[Uint160][]*transaction.Transaction) *TxnCollection
func (*TxnCollection) Peek ¶
func (tc *TxnCollection) Peek() *transaction.Transaction
func (*TxnCollection) Pop ¶
func (tc *TxnCollection) Pop() *transaction.Transaction
func (*TxnCollection) Update ¶
func (tc *TxnCollection) Update() error
type TxnCollector ¶
TxnCollector collects transactions from transaction pool
func NewTxnCollector ¶
func NewTxnCollector(source TxnSource, num int) *TxnCollector
func (*TxnCollector) Cleanup ¶
func (tc *TxnCollector) Cleanup(txns []*transaction.Transaction) error
func (*TxnCollector) Collect ¶
func (tc *TxnCollector) Collect() (*TxnCollection, error)
func (*TxnCollector) GetTransaction ¶
func (tc *TxnCollector) GetTransaction(hash Uint256) *transaction.Transaction
type TxnSource ¶
type TxnSource interface { GetAllTransactionLists() map[Uint160][]*transaction.Transaction GetTxnByCount(num int) (map[Uint256]*transaction.Transaction, error) GetTransaction(hash Uint256) *transaction.Transaction AppendTxnPool(txn *transaction.Transaction) error CleanSubmittedTransactions(txns []*transaction.Transaction) error }
Transaction pool should be a concrete entity of this interface