github.com/DFWallet/tendermint-cosmos@v0.0.2/consensus/replay_stubs.go (about)

     1  package consensus
     2  
     3  import (
     4  	abci "github.com/DFWallet/tendermint-cosmos/abci/types"
     5  	"github.com/DFWallet/tendermint-cosmos/libs/clist"
     6  	mempl "github.com/DFWallet/tendermint-cosmos/mempool"
     7  	tmstate "github.com/DFWallet/tendermint-cosmos/proto/tendermint/state"
     8  	"github.com/DFWallet/tendermint-cosmos/proxy"
     9  	"github.com/DFWallet/tendermint-cosmos/types"
    10  )
    11  
    12  //-----------------------------------------------------------------------------
    13  
    14  type emptyMempool struct{}
    15  
    16  var _ mempl.Mempool = emptyMempool{}
    17  
    18  func (emptyMempool) Lock()     {}
    19  func (emptyMempool) Unlock()   {}
    20  func (emptyMempool) Size() int { return 0 }
    21  func (emptyMempool) CheckTx(_ types.Tx, _ func(*abci.Response), _ mempl.TxInfo) error {
    22  	return nil
    23  }
    24  func (emptyMempool) ReapMaxBytesMaxGas(_, _ int64) types.Txs { return types.Txs{} }
    25  func (emptyMempool) ReapMaxTxs(n int) types.Txs              { return types.Txs{} }
    26  func (emptyMempool) Update(
    27  	_ int64,
    28  	_ types.Txs,
    29  	_ []*abci.ResponseDeliverTx,
    30  	_ mempl.PreCheckFunc,
    31  	_ mempl.PostCheckFunc,
    32  ) error {
    33  	return nil
    34  }
    35  func (emptyMempool) Flush()                        {}
    36  func (emptyMempool) FlushAppConn() error           { return nil }
    37  func (emptyMempool) TxsAvailable() <-chan struct{} { return make(chan struct{}) }
    38  func (emptyMempool) EnableTxsAvailable()           {}
    39  func (emptyMempool) TxsBytes() int64               { return 0 }
    40  
    41  func (emptyMempool) TxsFront() *clist.CElement    { return nil }
    42  func (emptyMempool) TxsWaitChan() <-chan struct{} { return nil }
    43  
    44  func (emptyMempool) InitWAL() error { return nil }
    45  func (emptyMempool) CloseWAL()      {}
    46  
    47  //-----------------------------------------------------------------------------
    48  // mockProxyApp uses ABCIResponses to give the right results.
    49  //
    50  // Useful because we don't want to call Commit() twice for the same block on
    51  // the real app.
    52  
    53  func newMockProxyApp(appHash []byte, abciResponses *tmstate.ABCIResponses) proxy.AppConnConsensus {
    54  	clientCreator := proxy.NewLocalClientCreator(&mockProxyApp{
    55  		appHash:       appHash,
    56  		abciResponses: abciResponses,
    57  	})
    58  	cli, _ := clientCreator.NewABCIClient()
    59  	err := cli.Start()
    60  	if err != nil {
    61  		panic(err)
    62  	}
    63  	return proxy.NewAppConnConsensus(cli)
    64  }
    65  
    66  type mockProxyApp struct {
    67  	abci.BaseApplication
    68  
    69  	appHash       []byte
    70  	txCount       int
    71  	abciResponses *tmstate.ABCIResponses
    72  }
    73  
    74  func (mock *mockProxyApp) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx {
    75  	r := mock.abciResponses.DeliverTxs[mock.txCount]
    76  	mock.txCount++
    77  	if r == nil {
    78  		return abci.ResponseDeliverTx{}
    79  	}
    80  	return *r
    81  }
    82  
    83  func (mock *mockProxyApp) EndBlock(req abci.RequestEndBlock) abci.ResponseEndBlock {
    84  	mock.txCount = 0
    85  	return *mock.abciResponses.EndBlock
    86  }
    87  
    88  func (mock *mockProxyApp) Commit() abci.ResponseCommit {
    89  	return abci.ResponseCommit{Data: mock.appHash}
    90  }