github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/tm2/pkg/bft/appconn/app_conn.go (about)

     1  // Package appconn manages the connection of Tendermint to the application layer.
     2  package appconn
     3  
     4  import (
     5  	abcicli "github.com/gnolang/gno/tm2/pkg/bft/abci/client"
     6  	abci "github.com/gnolang/gno/tm2/pkg/bft/abci/types"
     7  )
     8  
     9  //----------------------------------------------------------------------------------------
    10  // Enforce which abci msgs can be sent on a connection at the type level
    11  
    12  type Consensus interface {
    13  	SetResponseCallback(abcicli.Callback)
    14  	Error() error
    15  
    16  	InitChainSync(abci.RequestInitChain) (abci.ResponseInitChain, error)
    17  
    18  	BeginBlockSync(abci.RequestBeginBlock) (abci.ResponseBeginBlock, error)
    19  	DeliverTxAsync(abci.RequestDeliverTx) *abcicli.ReqRes
    20  	EndBlockSync(abci.RequestEndBlock) (abci.ResponseEndBlock, error)
    21  	CommitSync() (abci.ResponseCommit, error)
    22  }
    23  
    24  type Mempool interface {
    25  	SetResponseCallback(abcicli.Callback)
    26  	Error() error
    27  
    28  	CheckTxAsync(abci.RequestCheckTx) *abcicli.ReqRes
    29  
    30  	FlushAsync() *abcicli.ReqRes
    31  	FlushSync() error
    32  }
    33  
    34  type Query interface {
    35  	Error() error
    36  
    37  	EchoSync(string) (abci.ResponseEcho, error)
    38  	InfoSync(abci.RequestInfo) (abci.ResponseInfo, error)
    39  	QuerySync(abci.RequestQuery) (abci.ResponseQuery, error)
    40  
    41  	//	SetOptionSync(key string, value string) (res abci.Result)
    42  }
    43  
    44  //-----------------------------------------------------------------------------------------
    45  // Implements Consensus (subset of abcicli.Client)
    46  
    47  type consensus struct {
    48  	appConn abcicli.Client
    49  }
    50  
    51  func NewConsensus(appConn abcicli.Client) *consensus {
    52  	return &consensus{
    53  		appConn: appConn,
    54  	}
    55  }
    56  
    57  func (app *consensus) SetResponseCallback(cb abcicli.Callback) {
    58  	app.appConn.SetResponseCallback(cb)
    59  }
    60  
    61  func (app *consensus) Error() error {
    62  	return app.appConn.Error()
    63  }
    64  
    65  func (app *consensus) InitChainSync(req abci.RequestInitChain) (abci.ResponseInitChain, error) {
    66  	return app.appConn.InitChainSync(req)
    67  }
    68  
    69  func (app *consensus) BeginBlockSync(req abci.RequestBeginBlock) (abci.ResponseBeginBlock, error) {
    70  	return app.appConn.BeginBlockSync(req)
    71  }
    72  
    73  func (app *consensus) DeliverTxAsync(req abci.RequestDeliverTx) *abcicli.ReqRes {
    74  	return app.appConn.DeliverTxAsync(req)
    75  }
    76  
    77  func (app *consensus) EndBlockSync(req abci.RequestEndBlock) (abci.ResponseEndBlock, error) {
    78  	return app.appConn.EndBlockSync(req)
    79  }
    80  
    81  func (app *consensus) CommitSync() (abci.ResponseCommit, error) {
    82  	return app.appConn.CommitSync()
    83  }
    84  
    85  //------------------------------------------------
    86  // Implements Mempool (subset of abcicli.Client)
    87  
    88  type mempool struct {
    89  	appConn abcicli.Client
    90  }
    91  
    92  func NewMempool(appConn abcicli.Client) *mempool {
    93  	return &mempool{
    94  		appConn: appConn,
    95  	}
    96  }
    97  
    98  func (app *mempool) SetResponseCallback(cb abcicli.Callback) {
    99  	app.appConn.SetResponseCallback(cb)
   100  }
   101  
   102  func (app *mempool) Error() error {
   103  	return app.appConn.Error()
   104  }
   105  
   106  func (app *mempool) FlushAsync() *abcicli.ReqRes {
   107  	return app.appConn.FlushAsync()
   108  }
   109  
   110  func (app *mempool) FlushSync() error {
   111  	return app.appConn.FlushSync()
   112  }
   113  
   114  func (app *mempool) CheckTxAsync(req abci.RequestCheckTx) *abcicli.ReqRes {
   115  	return app.appConn.CheckTxAsync(req)
   116  }
   117  
   118  //------------------------------------------------
   119  // Implements Query (subset of abcicli.Client)
   120  
   121  type query struct {
   122  	appConn abcicli.Client
   123  }
   124  
   125  func NewQuery(appConn abcicli.Client) *query {
   126  	return &query{
   127  		appConn: appConn,
   128  	}
   129  }
   130  
   131  func (app *query) Error() error {
   132  	return app.appConn.Error()
   133  }
   134  
   135  func (app *query) EchoSync(msg string) (abci.ResponseEcho, error) {
   136  	return app.appConn.EchoSync(msg)
   137  }
   138  
   139  func (app *query) InfoSync(req abci.RequestInfo) (abci.ResponseInfo, error) {
   140  	return app.appConn.InfoSync(req)
   141  }
   142  
   143  func (app *query) QuerySync(reqQuery abci.RequestQuery) (abci.ResponseQuery, error) {
   144  	return app.appConn.QuerySync(reqQuery)
   145  }