github.com/badrootd/celestia-core@v0.0.0-20240305091328-aa4207a4b25d/proxy/app_conn.go (about) 1 package proxy 2 3 import ( 4 abcicli "github.com/badrootd/celestia-core/abci/client" 5 "github.com/badrootd/celestia-core/abci/types" 6 ) 7 8 //go:generate ../scripts/mockery_generate.sh AppConnConsensus|AppConnMempool|AppConnQuery|AppConnSnapshot 9 10 //---------------------------------------------------------------------------------------- 11 // Enforce which abci msgs can be sent on a connection at the type level 12 13 type AppConnConsensus interface { 14 SetResponseCallback(abcicli.Callback) 15 Error() error 16 17 InitChainSync(types.RequestInitChain) (*types.ResponseInitChain, error) 18 19 BeginBlockSync(types.RequestBeginBlock) (*types.ResponseBeginBlock, error) 20 DeliverTxAsync(types.RequestDeliverTx) *abcicli.ReqRes 21 EndBlockSync(types.RequestEndBlock) (*types.ResponseEndBlock, error) 22 CommitSync() (*types.ResponseCommit, error) 23 24 PrepareProposalSync(types.RequestPrepareProposal) (*types.ResponsePrepareProposal, error) 25 ProcessProposalSync(types.RequestProcessProposal) (*types.ResponseProcessProposal, error) 26 } 27 28 type AppConnMempool interface { 29 SetResponseCallback(abcicli.Callback) 30 Error() error 31 32 CheckTxAsync(types.RequestCheckTx) *abcicli.ReqRes 33 CheckTxSync(types.RequestCheckTx) (*types.ResponseCheckTx, error) 34 35 FlushAsync() *abcicli.ReqRes 36 FlushSync() error 37 } 38 39 type AppConnQuery interface { 40 Error() error 41 42 EchoSync(string) (*types.ResponseEcho, error) 43 InfoSync(types.RequestInfo) (*types.ResponseInfo, error) 44 QuerySync(types.RequestQuery) (*types.ResponseQuery, error) 45 } 46 47 type AppConnSnapshot interface { 48 Error() error 49 50 ListSnapshotsSync(types.RequestListSnapshots) (*types.ResponseListSnapshots, error) 51 OfferSnapshotSync(types.RequestOfferSnapshot) (*types.ResponseOfferSnapshot, error) 52 LoadSnapshotChunkSync(types.RequestLoadSnapshotChunk) (*types.ResponseLoadSnapshotChunk, error) 53 ApplySnapshotChunkSync(types.RequestApplySnapshotChunk) (*types.ResponseApplySnapshotChunk, error) 54 } 55 56 //----------------------------------------------------------------------------------------- 57 // Implements AppConnConsensus (subset of abcicli.Client) 58 59 type appConnConsensus struct { 60 appConn abcicli.Client 61 } 62 63 func NewAppConnConsensus(appConn abcicli.Client) AppConnConsensus { 64 return &appConnConsensus{ 65 appConn: appConn, 66 } 67 } 68 69 func (app *appConnConsensus) SetResponseCallback(cb abcicli.Callback) { 70 app.appConn.SetResponseCallback(cb) 71 } 72 73 func (app *appConnConsensus) Error() error { 74 return app.appConn.Error() 75 } 76 77 func (app *appConnConsensus) InitChainSync(req types.RequestInitChain) (*types.ResponseInitChain, error) { 78 return app.appConn.InitChainSync(req) 79 } 80 81 func (app *appConnConsensus) BeginBlockSync(req types.RequestBeginBlock) (*types.ResponseBeginBlock, error) { 82 return app.appConn.BeginBlockSync(req) 83 } 84 85 func (app *appConnConsensus) DeliverTxAsync(req types.RequestDeliverTx) *abcicli.ReqRes { 86 return app.appConn.DeliverTxAsync(req) 87 } 88 89 func (app *appConnConsensus) EndBlockSync(req types.RequestEndBlock) (*types.ResponseEndBlock, error) { 90 return app.appConn.EndBlockSync(req) 91 } 92 93 func (app *appConnConsensus) CommitSync() (*types.ResponseCommit, error) { 94 return app.appConn.CommitSync() 95 } 96 97 func (app *appConnConsensus) PrepareProposalSync( 98 req types.RequestPrepareProposal, 99 ) (*types.ResponsePrepareProposal, error) { 100 return app.appConn.PrepareProposalSync(req) 101 } 102 103 func (app *appConnConsensus) ProcessProposalSync( 104 req types.RequestProcessProposal, 105 ) (*types.ResponseProcessProposal, error) { 106 return app.appConn.ProcessProposalSync(req) 107 } 108 109 //------------------------------------------------ 110 // Implements AppConnMempool (subset of abcicli.Client) 111 112 type appConnMempool struct { 113 appConn abcicli.Client 114 } 115 116 func NewAppConnMempool(appConn abcicli.Client) AppConnMempool { 117 return &appConnMempool{ 118 appConn: appConn, 119 } 120 } 121 122 func (app *appConnMempool) SetResponseCallback(cb abcicli.Callback) { 123 app.appConn.SetResponseCallback(cb) 124 } 125 126 func (app *appConnMempool) Error() error { 127 return app.appConn.Error() 128 } 129 130 func (app *appConnMempool) FlushAsync() *abcicli.ReqRes { 131 return app.appConn.FlushAsync() 132 } 133 134 func (app *appConnMempool) FlushSync() error { 135 return app.appConn.FlushSync() 136 } 137 138 func (app *appConnMempool) CheckTxAsync(req types.RequestCheckTx) *abcicli.ReqRes { 139 return app.appConn.CheckTxAsync(req) 140 } 141 142 func (app *appConnMempool) CheckTxSync(req types.RequestCheckTx) (*types.ResponseCheckTx, error) { 143 return app.appConn.CheckTxSync(req) 144 } 145 146 //------------------------------------------------ 147 // Implements AppConnQuery (subset of abcicli.Client) 148 149 type appConnQuery struct { 150 appConn abcicli.Client 151 } 152 153 func NewAppConnQuery(appConn abcicli.Client) AppConnQuery { 154 return &appConnQuery{ 155 appConn: appConn, 156 } 157 } 158 159 func (app *appConnQuery) Error() error { 160 return app.appConn.Error() 161 } 162 163 func (app *appConnQuery) EchoSync(msg string) (*types.ResponseEcho, error) { 164 return app.appConn.EchoSync(msg) 165 } 166 167 func (app *appConnQuery) InfoSync(req types.RequestInfo) (*types.ResponseInfo, error) { 168 return app.appConn.InfoSync(req) 169 } 170 171 func (app *appConnQuery) QuerySync(reqQuery types.RequestQuery) (*types.ResponseQuery, error) { 172 return app.appConn.QuerySync(reqQuery) 173 } 174 175 //------------------------------------------------ 176 // Implements AppConnSnapshot (subset of abcicli.Client) 177 178 type appConnSnapshot struct { 179 appConn abcicli.Client 180 } 181 182 func NewAppConnSnapshot(appConn abcicli.Client) AppConnSnapshot { 183 return &appConnSnapshot{ 184 appConn: appConn, 185 } 186 } 187 188 func (app *appConnSnapshot) Error() error { 189 return app.appConn.Error() 190 } 191 192 func (app *appConnSnapshot) ListSnapshotsSync(req types.RequestListSnapshots) (*types.ResponseListSnapshots, error) { 193 return app.appConn.ListSnapshotsSync(req) 194 } 195 196 func (app *appConnSnapshot) OfferSnapshotSync(req types.RequestOfferSnapshot) (*types.ResponseOfferSnapshot, error) { 197 return app.appConn.OfferSnapshotSync(req) 198 } 199 200 func (app *appConnSnapshot) LoadSnapshotChunkSync( 201 req types.RequestLoadSnapshotChunk) (*types.ResponseLoadSnapshotChunk, error) { 202 return app.appConn.LoadSnapshotChunkSync(req) 203 } 204 205 func (app *appConnSnapshot) ApplySnapshotChunkSync( 206 req types.RequestApplySnapshotChunk) (*types.ResponseApplySnapshotChunk, error) { 207 return app.appConn.ApplySnapshotChunkSync(req) 208 }