OSDN Git Service

keep last irreversible block on the main chain (#245)
[bytom/vapor.git] / test / mock / chain.go
index b1601b1..700891f 100644 (file)
@@ -8,19 +8,24 @@ import (
        "github.com/vapor/protocol/bc/types"
 )
 
+type mempool interface {
+       AddTx(tx *types.Tx)
+}
+
 type Chain struct {
        bestBlockHeader *types.BlockHeader
        heightMap       map[uint64]*types.Block
        blockMap        map[bc.Hash]*types.Block
-
-       prevOrphans map[bc.Hash]*types.Block
+       prevOrphans     map[bc.Hash]*types.Block
+       mempool         mempool
 }
 
-func NewChain() *Chain {
+func NewChain(mempool *Mempool) *Chain {
        return &Chain{
                heightMap:   map[uint64]*types.Block{},
                blockMap:    map[bc.Hash]*types.Block{},
                prevOrphans: make(map[bc.Hash]*types.Block),
+               mempool:     mempool,
        }
 }
 
@@ -32,6 +37,10 @@ func (c *Chain) BestBlockHeight() uint64 {
        return c.bestBlockHeader.Height
 }
 
+func (c *Chain) LastIrreversibleHeader() *types.BlockHeader {
+       return c.bestBlockHeader
+}
+
 func (c *Chain) CalcNextSeed(hash *bc.Hash) (*bc.Hash, error) {
        return &bc.Hash{V0: hash.V1, V1: hash.V2, V2: hash.V3, V3: hash.V0}, nil
 }
@@ -137,6 +146,7 @@ func (c *Chain) SetBlockByHeight(height uint64, block *types.Block) {
        c.blockMap[block.Hash()] = block
 }
 
-func (c *Chain) ValidateTx(*types.Tx) (bool, error) {
+func (c *Chain) ValidateTx(tx *types.Tx) (bool, error) {
+       c.mempool.AddTx(tx)
        return false, nil
 }