github.com/ari-anchor/sei-tendermint@v0.0.0-20230519144642-dc826b7b56bb/abci/types/application.go (about) 1 package types 2 3 import "context" 4 5 // Application is an interface that enables any finite, deterministic state machine 6 // to be driven by a blockchain-based replication engine via the ABCI. 7 // 8 //go:generate ../../scripts/mockery_generate.sh Application 9 type Application interface { 10 // Info/Query Connection 11 Info(context.Context, *RequestInfo) (*ResponseInfo, error) // Return application info 12 Query(context.Context, *RequestQuery) (*ResponseQuery, error) // Query for state 13 14 // Mempool Connection 15 CheckTx(context.Context, *RequestCheckTx) (*ResponseCheckTx, error) // Validate a tx for the mempool 16 17 // Consensus Connection 18 InitChain(context.Context, *RequestInitChain) (*ResponseInitChain, error) // Initialize blockchain w validators/other info from TendermintCore 19 PrepareProposal(context.Context, *RequestPrepareProposal) (*ResponsePrepareProposal, error) 20 ProcessProposal(context.Context, *RequestProcessProposal) (*ResponseProcessProposal, error) 21 // Commit the state and return the application Merkle root hash 22 Commit(context.Context) (*ResponseCommit, error) 23 // Create application specific vote extension 24 ExtendVote(context.Context, *RequestExtendVote) (*ResponseExtendVote, error) 25 // Verify application's vote extension data 26 VerifyVoteExtension(context.Context, *RequestVerifyVoteExtension) (*ResponseVerifyVoteExtension, error) 27 // Deliver the decided block with its txs to the Application 28 FinalizeBlock(context.Context, *RequestFinalizeBlock) (*ResponseFinalizeBlock, error) 29 30 // State Sync Connection 31 ListSnapshots(context.Context, *RequestListSnapshots) (*ResponseListSnapshots, error) // List available snapshots 32 OfferSnapshot(context.Context, *RequestOfferSnapshot) (*ResponseOfferSnapshot, error) // Offer a snapshot to the application 33 LoadSnapshotChunk(context.Context, *RequestLoadSnapshotChunk) (*ResponseLoadSnapshotChunk, error) // Load a snapshot chunk 34 ApplySnapshotChunk(context.Context, *RequestApplySnapshotChunk) (*ResponseApplySnapshotChunk, error) // Apply a shapshot chunk 35 // Notify application to load latest application state (e.g. after DBSync finishes) 36 LoadLatest(context.Context, *RequestLoadLatest) (*ResponseLoadLatest, error) 37 } 38 39 //------------------------------------------------------- 40 // BaseApplication is a base form of Application 41 42 var _ Application = (*BaseApplication)(nil) 43 44 type BaseApplication struct{} 45 46 func NewBaseApplication() *BaseApplication { 47 return &BaseApplication{} 48 } 49 50 func (BaseApplication) Info(_ context.Context, req *RequestInfo) (*ResponseInfo, error) { 51 return &ResponseInfo{}, nil 52 } 53 54 func (BaseApplication) CheckTx(_ context.Context, req *RequestCheckTx) (*ResponseCheckTx, error) { 55 return &ResponseCheckTx{Code: CodeTypeOK}, nil 56 } 57 58 func (BaseApplication) Commit(_ context.Context) (*ResponseCommit, error) { 59 return &ResponseCommit{}, nil 60 } 61 62 func (BaseApplication) ExtendVote(_ context.Context, req *RequestExtendVote) (*ResponseExtendVote, error) { 63 return &ResponseExtendVote{}, nil 64 } 65 66 func (BaseApplication) VerifyVoteExtension(_ context.Context, req *RequestVerifyVoteExtension) (*ResponseVerifyVoteExtension, error) { 67 return &ResponseVerifyVoteExtension{ 68 Status: ResponseVerifyVoteExtension_ACCEPT, 69 }, nil 70 } 71 72 func (BaseApplication) Query(_ context.Context, req *RequestQuery) (*ResponseQuery, error) { 73 return &ResponseQuery{Code: CodeTypeOK}, nil 74 } 75 76 func (BaseApplication) InitChain(_ context.Context, req *RequestInitChain) (*ResponseInitChain, error) { 77 return &ResponseInitChain{}, nil 78 } 79 80 func (BaseApplication) ListSnapshots(_ context.Context, req *RequestListSnapshots) (*ResponseListSnapshots, error) { 81 return &ResponseListSnapshots{}, nil 82 } 83 84 func (BaseApplication) OfferSnapshot(_ context.Context, req *RequestOfferSnapshot) (*ResponseOfferSnapshot, error) { 85 return &ResponseOfferSnapshot{}, nil 86 } 87 88 func (BaseApplication) LoadSnapshotChunk(_ context.Context, _ *RequestLoadSnapshotChunk) (*ResponseLoadSnapshotChunk, error) { 89 return &ResponseLoadSnapshotChunk{}, nil 90 } 91 92 func (BaseApplication) ApplySnapshotChunk(_ context.Context, req *RequestApplySnapshotChunk) (*ResponseApplySnapshotChunk, error) { 93 return &ResponseApplySnapshotChunk{}, nil 94 } 95 96 func (BaseApplication) PrepareProposal(_ context.Context, req *RequestPrepareProposal) (*ResponsePrepareProposal, error) { 97 trs := make([]*TxRecord, 0, len(req.Txs)) 98 var totalBytes int64 99 for _, tx := range req.Txs { 100 totalBytes += int64(len(tx)) 101 if totalBytes > req.MaxTxBytes { 102 break 103 } 104 trs = append(trs, &TxRecord{ 105 Action: TxRecord_UNMODIFIED, 106 Tx: tx, 107 }) 108 } 109 return &ResponsePrepareProposal{TxRecords: trs}, nil 110 } 111 112 func (BaseApplication) ProcessProposal(_ context.Context, req *RequestProcessProposal) (*ResponseProcessProposal, error) { 113 return &ResponseProcessProposal{Status: ResponseProcessProposal_ACCEPT}, nil 114 } 115 116 func (BaseApplication) FinalizeBlock(_ context.Context, req *RequestFinalizeBlock) (*ResponseFinalizeBlock, error) { 117 txs := make([]*ExecTxResult, len(req.Txs)) 118 for i := range req.Txs { 119 txs[i] = &ExecTxResult{Code: CodeTypeOK} 120 } 121 return &ResponseFinalizeBlock{ 122 TxResults: txs, 123 }, nil 124 } 125 126 func (BaseApplication) LoadLatest(_ context.Context, _ *RequestLoadLatest) (*ResponseLoadLatest, error) { 127 return &ResponseLoadLatest{}, nil 128 }