github.com/line/ostracon@v1.0.10-0.20230328032236-7f20145f065d/abci/types/application.go (about)

     1  package types
     2  
     3  import (
     4  	context "golang.org/x/net/context"
     5  
     6  	"github.com/tendermint/tendermint/abci/types"
     7  )
     8  
     9  //go:generate mockery --case underscore --name Application
    10  
    11  type CheckTxCallback func(ResponseCheckTx)
    12  
    13  // Application is an interface that enables any finite, deterministic state machine
    14  // to be driven by a blockchain-based replication engine via the ABCI.
    15  // All methods take a RequestXxx argument and return a ResponseXxx argument,
    16  // except CheckTx/DeliverTx, which take `tx []byte`, and `Commit`, which takes nothing.
    17  type Application interface {
    18  	// Info/Query Connection
    19  	Info(types.RequestInfo) types.ResponseInfo                // Return application info
    20  	SetOption(types.RequestSetOption) types.ResponseSetOption // Set application option
    21  	Query(types.RequestQuery) types.ResponseQuery             // Query for state
    22  
    23  	// Mempool Connection
    24  	CheckTxSync(types.RequestCheckTx) ResponseCheckTx            // Validate a tx for the mempool
    25  	CheckTxAsync(types.RequestCheckTx, CheckTxCallback)          // Asynchronously validate a tx for the mempool
    26  	BeginRecheckTx(RequestBeginRecheckTx) ResponseBeginRecheckTx // Signals the beginning of rechecking
    27  	EndRecheckTx(RequestEndRecheckTx) ResponseEndRecheckTx       // Signals the end of rechecking
    28  
    29  	// Consensus Connection
    30  	InitChain(types.RequestInitChain) types.ResponseInitChain // Initialize blockchain w validators/other info from OstraconCore
    31  	BeginBlock(RequestBeginBlock) types.ResponseBeginBlock    // Signals the beginning of a block
    32  	DeliverTx(types.RequestDeliverTx) types.ResponseDeliverTx // Deliver a tx for full processing
    33  	EndBlock(types.RequestEndBlock) types.ResponseEndBlock    // Signals the end of a block, returns changes to the validator set
    34  	Commit() types.ResponseCommit                             // Commit the state and return the application Merkle root hash
    35  
    36  	// State Sync Connection
    37  	ListSnapshots(types.RequestListSnapshots) types.ResponseListSnapshots                // List available snapshots
    38  	OfferSnapshot(types.RequestOfferSnapshot) types.ResponseOfferSnapshot                // Offer a snapshot to the application
    39  	LoadSnapshotChunk(types.RequestLoadSnapshotChunk) types.ResponseLoadSnapshotChunk    // Load a snapshot chunk
    40  	ApplySnapshotChunk(types.RequestApplySnapshotChunk) types.ResponseApplySnapshotChunk // Apply a shapshot chunk
    41  }
    42  
    43  //-------------------------------------------------------
    44  // BaseApplication is a base form of Application
    45  
    46  var _ Application = (*BaseApplication)(nil)
    47  
    48  type BaseApplication struct {
    49  }
    50  
    51  func NewBaseApplication() *BaseApplication {
    52  	return &BaseApplication{}
    53  }
    54  
    55  func (BaseApplication) Info(req types.RequestInfo) types.ResponseInfo {
    56  	return types.ResponseInfo{}
    57  }
    58  
    59  func (BaseApplication) SetOption(req types.RequestSetOption) types.ResponseSetOption {
    60  	return types.ResponseSetOption{}
    61  }
    62  
    63  func (BaseApplication) DeliverTx(req types.RequestDeliverTx) types.ResponseDeliverTx {
    64  	return types.ResponseDeliverTx{Code: CodeTypeOK}
    65  }
    66  
    67  func (BaseApplication) CheckTxSync(req types.RequestCheckTx) ResponseCheckTx {
    68  	return ResponseCheckTx{Code: CodeTypeOK}
    69  }
    70  
    71  func (BaseApplication) CheckTxAsync(req types.RequestCheckTx, callback CheckTxCallback) {
    72  	callback(ResponseCheckTx{Code: CodeTypeOK})
    73  }
    74  
    75  func (BaseApplication) BeginRecheckTx(req RequestBeginRecheckTx) ResponseBeginRecheckTx {
    76  	return ResponseBeginRecheckTx{Code: CodeTypeOK}
    77  }
    78  
    79  func (BaseApplication) EndRecheckTx(req RequestEndRecheckTx) ResponseEndRecheckTx {
    80  	return ResponseEndRecheckTx{Code: CodeTypeOK}
    81  }
    82  
    83  func (BaseApplication) Commit() types.ResponseCommit {
    84  	return types.ResponseCommit{}
    85  }
    86  
    87  func (BaseApplication) Query(req types.RequestQuery) types.ResponseQuery {
    88  	return types.ResponseQuery{Code: CodeTypeOK}
    89  }
    90  
    91  func (BaseApplication) InitChain(req types.RequestInitChain) types.ResponseInitChain {
    92  	return types.ResponseInitChain{}
    93  }
    94  
    95  func (BaseApplication) BeginBlock(req RequestBeginBlock) types.ResponseBeginBlock {
    96  	return types.ResponseBeginBlock{}
    97  }
    98  
    99  func (BaseApplication) EndBlock(req types.RequestEndBlock) types.ResponseEndBlock {
   100  	return types.ResponseEndBlock{}
   101  }
   102  
   103  func (BaseApplication) ListSnapshots(req types.RequestListSnapshots) types.ResponseListSnapshots {
   104  	return types.ResponseListSnapshots{}
   105  }
   106  
   107  func (BaseApplication) OfferSnapshot(req types.RequestOfferSnapshot) types.ResponseOfferSnapshot {
   108  	return types.ResponseOfferSnapshot{}
   109  }
   110  
   111  func (BaseApplication) LoadSnapshotChunk(req types.RequestLoadSnapshotChunk) types.ResponseLoadSnapshotChunk {
   112  	return types.ResponseLoadSnapshotChunk{}
   113  }
   114  
   115  func (BaseApplication) ApplySnapshotChunk(req types.RequestApplySnapshotChunk) types.ResponseApplySnapshotChunk {
   116  	return types.ResponseApplySnapshotChunk{}
   117  }
   118  
   119  //-------------------------------------------------------
   120  
   121  // GRPCApplication is a GRPC wrapper for Application
   122  type GRPCApplication struct {
   123  	app Application
   124  }
   125  
   126  func NewGRPCApplication(app Application) *GRPCApplication {
   127  	return &GRPCApplication{app}
   128  }
   129  
   130  func (app *GRPCApplication) Echo(ctx context.Context, req *types.RequestEcho) (*types.ResponseEcho, error) {
   131  	return &types.ResponseEcho{Message: req.Message}, nil
   132  }
   133  
   134  func (app *GRPCApplication) Flush(ctx context.Context, req *types.RequestFlush) (*types.ResponseFlush, error) {
   135  	return &types.ResponseFlush{}, nil
   136  }
   137  
   138  func (app *GRPCApplication) Info(ctx context.Context, req *types.RequestInfo) (*types.ResponseInfo, error) {
   139  	res := app.app.Info(*req)
   140  	return &res, nil
   141  }
   142  
   143  func (app *GRPCApplication) SetOption(ctx context.Context, req *types.RequestSetOption) (*types.ResponseSetOption, error) {
   144  	res := app.app.SetOption(*req)
   145  	return &res, nil
   146  }
   147  
   148  func (app *GRPCApplication) DeliverTx(ctx context.Context, req *types.RequestDeliverTx) (*types.ResponseDeliverTx, error) {
   149  	res := app.app.DeliverTx(*req)
   150  	return &res, nil
   151  }
   152  
   153  func (app *GRPCApplication) CheckTx(ctx context.Context, req *types.RequestCheckTx) (*ResponseCheckTx, error) {
   154  	res := app.app.CheckTxSync(*req)
   155  	return &res, nil
   156  }
   157  
   158  func (app *GRPCApplication) BeginRecheckTx(ctx context.Context, req *RequestBeginRecheckTx) (
   159  	*ResponseBeginRecheckTx, error) {
   160  	res := app.app.BeginRecheckTx(*req)
   161  	return &res, nil
   162  }
   163  
   164  func (app *GRPCApplication) EndRecheckTx(ctx context.Context, req *RequestEndRecheckTx) (*ResponseEndRecheckTx, error) {
   165  	res := app.app.EndRecheckTx(*req)
   166  	return &res, nil
   167  }
   168  
   169  func (app *GRPCApplication) Query(ctx context.Context, req *types.RequestQuery) (*types.ResponseQuery, error) {
   170  	res := app.app.Query(*req)
   171  	return &res, nil
   172  }
   173  
   174  func (app *GRPCApplication) Commit(ctx context.Context, req *types.RequestCommit) (*types.ResponseCommit, error) {
   175  	res := app.app.Commit()
   176  	return &res, nil
   177  }
   178  
   179  func (app *GRPCApplication) InitChain(ctx context.Context, req *types.RequestInitChain) (*types.ResponseInitChain, error) {
   180  	res := app.app.InitChain(*req)
   181  	return &res, nil
   182  }
   183  
   184  func (app *GRPCApplication) BeginBlock(ctx context.Context, req *RequestBeginBlock) (*types.ResponseBeginBlock, error) {
   185  	res := app.app.BeginBlock(*req)
   186  	return &res, nil
   187  }
   188  
   189  func (app *GRPCApplication) EndBlock(ctx context.Context, req *types.RequestEndBlock) (*types.ResponseEndBlock, error) {
   190  	res := app.app.EndBlock(*req)
   191  	return &res, nil
   192  }
   193  
   194  func (app *GRPCApplication) ListSnapshots(
   195  	ctx context.Context, req *types.RequestListSnapshots) (*types.ResponseListSnapshots, error) {
   196  	res := app.app.ListSnapshots(*req)
   197  	return &res, nil
   198  }
   199  
   200  func (app *GRPCApplication) OfferSnapshot(
   201  	ctx context.Context, req *types.RequestOfferSnapshot) (*types.ResponseOfferSnapshot, error) {
   202  	res := app.app.OfferSnapshot(*req)
   203  	return &res, nil
   204  }
   205  
   206  func (app *GRPCApplication) LoadSnapshotChunk(
   207  	ctx context.Context, req *types.RequestLoadSnapshotChunk) (*types.ResponseLoadSnapshotChunk, error) {
   208  	res := app.app.LoadSnapshotChunk(*req)
   209  	return &res, nil
   210  }
   211  
   212  func (app *GRPCApplication) ApplySnapshotChunk(
   213  	ctx context.Context, req *types.RequestApplySnapshotChunk) (*types.ResponseApplySnapshotChunk, error) {
   214  	res := app.app.ApplySnapshotChunk(*req)
   215  	return &res, nil
   216  }