github.com/number571/tendermint@v0.34.11-gost/abci/types/application.go (about)

     1  package types
     2  
     3  import (
     4  	"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  	Query(RequestQuery) ResponseQuery // Query for state
    15  
    16  	// Mempool Connection
    17  	CheckTx(RequestCheckTx) ResponseCheckTx // Validate a tx for the mempool
    18  
    19  	// Consensus Connection
    20  	InitChain(RequestInitChain) ResponseInitChain    // Initialize blockchain w validators/other info from TendermintCore
    21  	BeginBlock(RequestBeginBlock) ResponseBeginBlock // Signals the beginning of a block
    22  	DeliverTx(RequestDeliverTx) ResponseDeliverTx    // Deliver a tx for full processing
    23  	EndBlock(RequestEndBlock) ResponseEndBlock       // Signals the end of a block, returns changes to the validator set
    24  	Commit() ResponseCommit                          // Commit the state and return the application Merkle root hash
    25  
    26  	// State Sync Connection
    27  	ListSnapshots(RequestListSnapshots) ResponseListSnapshots                // List available snapshots
    28  	OfferSnapshot(RequestOfferSnapshot) ResponseOfferSnapshot                // Offer a snapshot to the application
    29  	LoadSnapshotChunk(RequestLoadSnapshotChunk) ResponseLoadSnapshotChunk    // Load a snapshot chunk
    30  	ApplySnapshotChunk(RequestApplySnapshotChunk) ResponseApplySnapshotChunk // Apply a shapshot chunk
    31  }
    32  
    33  //-------------------------------------------------------
    34  // BaseApplication is a base form of Application
    35  
    36  var _ Application = (*BaseApplication)(nil)
    37  
    38  type BaseApplication struct {
    39  }
    40  
    41  func NewBaseApplication() *BaseApplication {
    42  	return &BaseApplication{}
    43  }
    44  
    45  func (BaseApplication) Info(req RequestInfo) ResponseInfo {
    46  	return ResponseInfo{}
    47  }
    48  
    49  func (BaseApplication) DeliverTx(req RequestDeliverTx) ResponseDeliverTx {
    50  	return ResponseDeliverTx{Code: CodeTypeOK}
    51  }
    52  
    53  func (BaseApplication) CheckTx(req RequestCheckTx) ResponseCheckTx {
    54  	return ResponseCheckTx{Code: CodeTypeOK}
    55  }
    56  
    57  func (BaseApplication) Commit() ResponseCommit {
    58  	return ResponseCommit{}
    59  }
    60  
    61  func (BaseApplication) Query(req RequestQuery) ResponseQuery {
    62  	return ResponseQuery{Code: CodeTypeOK}
    63  }
    64  
    65  func (BaseApplication) InitChain(req RequestInitChain) ResponseInitChain {
    66  	return ResponseInitChain{}
    67  }
    68  
    69  func (BaseApplication) BeginBlock(req RequestBeginBlock) ResponseBeginBlock {
    70  	return ResponseBeginBlock{}
    71  }
    72  
    73  func (BaseApplication) EndBlock(req RequestEndBlock) ResponseEndBlock {
    74  	return ResponseEndBlock{}
    75  }
    76  
    77  func (BaseApplication) ListSnapshots(req RequestListSnapshots) ResponseListSnapshots {
    78  	return ResponseListSnapshots{}
    79  }
    80  
    81  func (BaseApplication) OfferSnapshot(req RequestOfferSnapshot) ResponseOfferSnapshot {
    82  	return ResponseOfferSnapshot{}
    83  }
    84  
    85  func (BaseApplication) LoadSnapshotChunk(req RequestLoadSnapshotChunk) ResponseLoadSnapshotChunk {
    86  	return ResponseLoadSnapshotChunk{}
    87  }
    88  
    89  func (BaseApplication) ApplySnapshotChunk(req RequestApplySnapshotChunk) ResponseApplySnapshotChunk {
    90  	return ResponseApplySnapshotChunk{}
    91  }
    92  
    93  //-------------------------------------------------------
    94  
    95  // GRPCApplication is a GRPC wrapper for Application
    96  type GRPCApplication struct {
    97  	app Application
    98  }
    99  
   100  func NewGRPCApplication(app Application) *GRPCApplication {
   101  	return &GRPCApplication{app}
   102  }
   103  
   104  func (app *GRPCApplication) Echo(ctx context.Context, req *RequestEcho) (*ResponseEcho, error) {
   105  	return &ResponseEcho{Message: req.Message}, nil
   106  }
   107  
   108  func (app *GRPCApplication) Flush(ctx context.Context, req *RequestFlush) (*ResponseFlush, error) {
   109  	return &ResponseFlush{}, nil
   110  }
   111  
   112  func (app *GRPCApplication) Info(ctx context.Context, req *RequestInfo) (*ResponseInfo, error) {
   113  	res := app.app.Info(*req)
   114  	return &res, nil
   115  }
   116  
   117  func (app *GRPCApplication) DeliverTx(ctx context.Context, req *RequestDeliverTx) (*ResponseDeliverTx, error) {
   118  	res := app.app.DeliverTx(*req)
   119  	return &res, nil
   120  }
   121  
   122  func (app *GRPCApplication) CheckTx(ctx context.Context, req *RequestCheckTx) (*ResponseCheckTx, error) {
   123  	res := app.app.CheckTx(*req)
   124  	return &res, nil
   125  }
   126  
   127  func (app *GRPCApplication) Query(ctx context.Context, req *RequestQuery) (*ResponseQuery, error) {
   128  	res := app.app.Query(*req)
   129  	return &res, nil
   130  }
   131  
   132  func (app *GRPCApplication) Commit(ctx context.Context, req *RequestCommit) (*ResponseCommit, error) {
   133  	res := app.app.Commit()
   134  	return &res, nil
   135  }
   136  
   137  func (app *GRPCApplication) InitChain(ctx context.Context, req *RequestInitChain) (*ResponseInitChain, error) {
   138  	res := app.app.InitChain(*req)
   139  	return &res, nil
   140  }
   141  
   142  func (app *GRPCApplication) BeginBlock(ctx context.Context, req *RequestBeginBlock) (*ResponseBeginBlock, error) {
   143  	res := app.app.BeginBlock(*req)
   144  	return &res, nil
   145  }
   146  
   147  func (app *GRPCApplication) EndBlock(ctx context.Context, req *RequestEndBlock) (*ResponseEndBlock, error) {
   148  	res := app.app.EndBlock(*req)
   149  	return &res, nil
   150  }
   151  
   152  func (app *GRPCApplication) ListSnapshots(
   153  	ctx context.Context, req *RequestListSnapshots) (*ResponseListSnapshots, error) {
   154  	res := app.app.ListSnapshots(*req)
   155  	return &res, nil
   156  }
   157  
   158  func (app *GRPCApplication) OfferSnapshot(
   159  	ctx context.Context, req *RequestOfferSnapshot) (*ResponseOfferSnapshot, error) {
   160  	res := app.app.OfferSnapshot(*req)
   161  	return &res, nil
   162  }
   163  
   164  func (app *GRPCApplication) LoadSnapshotChunk(
   165  	ctx context.Context, req *RequestLoadSnapshotChunk) (*ResponseLoadSnapshotChunk, error) {
   166  	res := app.app.LoadSnapshotChunk(*req)
   167  	return &res, nil
   168  }
   169  
   170  func (app *GRPCApplication) ApplySnapshotChunk(
   171  	ctx context.Context, req *RequestApplySnapshotChunk) (*ResponseApplySnapshotChunk, error) {
   172  	res := app.app.ApplySnapshotChunk(*req)
   173  	return &res, nil
   174  }