github.com/vipernet-xyz/tendermint-core@v0.32.0/abci/types/application.go (about)

     1  package types // nolint: goimports
     2  
     3  import (
     4  	context "golang.org/x/net/context"
     5  )
     6  
     7  // Application is an interface that enables any finite, deterministic state machine
     8  // to be driven by a blockchain-based replication engine via the ABCI.
     9  // All methods take a RequestXxx argument and return a ResponseXxx argument,
    10  // except CheckTx/DeliverTx, which take `tx []byte`, and `Commit`, which takes nothing.
    11  type Application interface {
    12  	// Info/Query Connection
    13  	Info(RequestInfo) ResponseInfo                // Return application info
    14  	SetOption(RequestSetOption) ResponseSetOption // Set application option
    15  	Query(RequestQuery) ResponseQuery             // Query for state
    16  
    17  	// Mempool Connection
    18  	CheckTx(RequestCheckTx) ResponseCheckTx // Validate a tx for the mempool
    19  
    20  	// Consensus Connection
    21  	InitChain(RequestInitChain) ResponseInitChain    // Initialize blockchain w validators/other info from TendermintCore
    22  	BeginBlock(RequestBeginBlock) ResponseBeginBlock // Signals the beginning of a block
    23  	DeliverTx(RequestDeliverTx) ResponseDeliverTx    // Deliver a tx for full processing
    24  	EndBlock(RequestEndBlock) ResponseEndBlock       // Signals the end of a block, returns changes to the validator set
    25  	Commit() ResponseCommit                          // Commit the state and return the application Merkle root hash
    26  }
    27  
    28  //-------------------------------------------------------
    29  // BaseApplication is a base form of Application
    30  
    31  var _ Application = (*BaseApplication)(nil)
    32  
    33  type BaseApplication struct {
    34  }
    35  
    36  func NewBaseApplication() *BaseApplication {
    37  	return &BaseApplication{}
    38  }
    39  
    40  func (BaseApplication) Info(req RequestInfo) ResponseInfo {
    41  	return ResponseInfo{}
    42  }
    43  
    44  func (BaseApplication) SetOption(req RequestSetOption) ResponseSetOption {
    45  	return ResponseSetOption{}
    46  }
    47  
    48  func (BaseApplication) DeliverTx(req RequestDeliverTx) ResponseDeliverTx {
    49  	return ResponseDeliverTx{Code: CodeTypeOK}
    50  }
    51  
    52  func (BaseApplication) CheckTx(req RequestCheckTx) ResponseCheckTx {
    53  	return ResponseCheckTx{Code: CodeTypeOK}
    54  }
    55  
    56  func (BaseApplication) Commit() ResponseCommit {
    57  	return ResponseCommit{}
    58  }
    59  
    60  func (BaseApplication) Query(req RequestQuery) ResponseQuery {
    61  	return ResponseQuery{Code: CodeTypeOK}
    62  }
    63  
    64  func (BaseApplication) InitChain(req RequestInitChain) ResponseInitChain {
    65  	return ResponseInitChain{}
    66  }
    67  
    68  func (BaseApplication) BeginBlock(req RequestBeginBlock) ResponseBeginBlock {
    69  	return ResponseBeginBlock{}
    70  }
    71  
    72  func (BaseApplication) EndBlock(req RequestEndBlock) ResponseEndBlock {
    73  	return ResponseEndBlock{}
    74  }
    75  
    76  //-------------------------------------------------------
    77  
    78  // GRPCApplication is a GRPC wrapper for Application
    79  type GRPCApplication struct {
    80  	app Application
    81  }
    82  
    83  func NewGRPCApplication(app Application) *GRPCApplication {
    84  	return &GRPCApplication{app}
    85  }
    86  
    87  func (app *GRPCApplication) Echo(ctx context.Context, req *RequestEcho) (*ResponseEcho, error) {
    88  	return &ResponseEcho{Message: req.Message}, nil
    89  }
    90  
    91  func (app *GRPCApplication) Flush(ctx context.Context, req *RequestFlush) (*ResponseFlush, error) {
    92  	return &ResponseFlush{}, nil
    93  }
    94  
    95  func (app *GRPCApplication) Info(ctx context.Context, req *RequestInfo) (*ResponseInfo, error) {
    96  	res := app.app.Info(*req)
    97  	return &res, nil
    98  }
    99  
   100  func (app *GRPCApplication) SetOption(ctx context.Context, req *RequestSetOption) (*ResponseSetOption, error) {
   101  	res := app.app.SetOption(*req)
   102  	return &res, nil
   103  }
   104  
   105  func (app *GRPCApplication) DeliverTx(ctx context.Context, req *RequestDeliverTx) (*ResponseDeliverTx, error) {
   106  	res := app.app.DeliverTx(*req)
   107  	return &res, nil
   108  }
   109  
   110  func (app *GRPCApplication) CheckTx(ctx context.Context, req *RequestCheckTx) (*ResponseCheckTx, error) {
   111  	res := app.app.CheckTx(*req)
   112  	return &res, nil
   113  }
   114  
   115  func (app *GRPCApplication) Query(ctx context.Context, req *RequestQuery) (*ResponseQuery, error) {
   116  	res := app.app.Query(*req)
   117  	return &res, nil
   118  }
   119  
   120  func (app *GRPCApplication) Commit(ctx context.Context, req *RequestCommit) (*ResponseCommit, error) {
   121  	res := app.app.Commit()
   122  	return &res, nil
   123  }
   124  
   125  func (app *GRPCApplication) InitChain(ctx context.Context, req *RequestInitChain) (*ResponseInitChain, error) {
   126  	res := app.app.InitChain(*req)
   127  	return &res, nil
   128  }
   129  
   130  func (app *GRPCApplication) BeginBlock(ctx context.Context, req *RequestBeginBlock) (*ResponseBeginBlock, error) {
   131  	res := app.app.BeginBlock(*req)
   132  	return &res, nil
   133  }
   134  
   135  func (app *GRPCApplication) EndBlock(ctx context.Context, req *RequestEndBlock) (*ResponseEndBlock, error) {
   136  	res := app.app.EndBlock(*req)
   137  	return &res, nil
   138  }