github.com/Finschia/ostracon@v1.1.5/consensus/replay_stubs.go (about)

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