github.com/vipernet-xyz/tm@v0.34.24/abci/types/application.go (about)

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