You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

212 lines
6.2 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. package proxy
  2. import (
  3. "context"
  4. abcicli "github.com/tendermint/tendermint/abci/client"
  5. "github.com/tendermint/tendermint/abci/types"
  6. )
  7. //go:generate mockery --case underscore --name AppConnConsensus|AppConnMempool|AppConnQuery|AppConnSnapshot
  8. //----------------------------------------------------------------------------------------
  9. // Enforce which abci msgs can be sent on a connection at the type level
  10. type AppConnConsensus interface {
  11. SetResponseCallback(abcicli.Callback)
  12. Error() error
  13. InitChainSync(context.Context, types.RequestInitChain) (*types.ResponseInitChain, error)
  14. BeginBlockSync(context.Context, types.RequestBeginBlock) (*types.ResponseBeginBlock, error)
  15. DeliverTxAsync(context.Context, types.RequestDeliverTx) (*abcicli.ReqRes, error)
  16. EndBlockSync(context.Context, types.RequestEndBlock) (*types.ResponseEndBlock, error)
  17. CommitSync(context.Context) (*types.ResponseCommit, error)
  18. }
  19. type AppConnMempool interface {
  20. SetResponseCallback(abcicli.Callback)
  21. Error() error
  22. CheckTxAsync(context.Context, types.RequestCheckTx) (*abcicli.ReqRes, error)
  23. CheckTxSync(context.Context, types.RequestCheckTx) (*types.ResponseCheckTx, error)
  24. FlushAsync(context.Context) (*abcicli.ReqRes, error)
  25. FlushSync(context.Context) error
  26. }
  27. type AppConnQuery interface {
  28. Error() error
  29. EchoSync(context.Context, string) (*types.ResponseEcho, error)
  30. InfoSync(context.Context, types.RequestInfo) (*types.ResponseInfo, error)
  31. QuerySync(context.Context, types.RequestQuery) (*types.ResponseQuery, error)
  32. }
  33. type AppConnSnapshot interface {
  34. Error() error
  35. ListSnapshotsSync(context.Context, types.RequestListSnapshots) (*types.ResponseListSnapshots, error)
  36. OfferSnapshotSync(context.Context, types.RequestOfferSnapshot) (*types.ResponseOfferSnapshot, error)
  37. LoadSnapshotChunkSync(context.Context, types.RequestLoadSnapshotChunk) (*types.ResponseLoadSnapshotChunk, error)
  38. ApplySnapshotChunkSync(context.Context, types.RequestApplySnapshotChunk) (*types.ResponseApplySnapshotChunk, error)
  39. }
  40. //-----------------------------------------------------------------------------------------
  41. // Implements AppConnConsensus (subset of abcicli.Client)
  42. type appConnConsensus struct {
  43. appConn abcicli.Client
  44. }
  45. func NewAppConnConsensus(appConn abcicli.Client) AppConnConsensus {
  46. return &appConnConsensus{
  47. appConn: appConn,
  48. }
  49. }
  50. func (app *appConnConsensus) SetResponseCallback(cb abcicli.Callback) {
  51. app.appConn.SetResponseCallback(cb)
  52. }
  53. func (app *appConnConsensus) Error() error {
  54. return app.appConn.Error()
  55. }
  56. func (app *appConnConsensus) InitChainSync(
  57. ctx context.Context,
  58. req types.RequestInitChain,
  59. ) (*types.ResponseInitChain, error) {
  60. return app.appConn.InitChainSync(ctx, req)
  61. }
  62. func (app *appConnConsensus) BeginBlockSync(
  63. ctx context.Context,
  64. req types.RequestBeginBlock,
  65. ) (*types.ResponseBeginBlock, error) {
  66. return app.appConn.BeginBlockSync(ctx, req)
  67. }
  68. func (app *appConnConsensus) DeliverTxAsync(ctx context.Context, req types.RequestDeliverTx) (*abcicli.ReqRes, error) {
  69. return app.appConn.DeliverTxAsync(ctx, req)
  70. }
  71. func (app *appConnConsensus) EndBlockSync(
  72. ctx context.Context,
  73. req types.RequestEndBlock,
  74. ) (*types.ResponseEndBlock, error) {
  75. return app.appConn.EndBlockSync(ctx, req)
  76. }
  77. func (app *appConnConsensus) CommitSync(ctx context.Context) (*types.ResponseCommit, error) {
  78. return app.appConn.CommitSync(ctx)
  79. }
  80. //------------------------------------------------
  81. // Implements AppConnMempool (subset of abcicli.Client)
  82. type appConnMempool struct {
  83. appConn abcicli.Client
  84. }
  85. func NewAppConnMempool(appConn abcicli.Client) AppConnMempool {
  86. return &appConnMempool{
  87. appConn: appConn,
  88. }
  89. }
  90. func (app *appConnMempool) SetResponseCallback(cb abcicli.Callback) {
  91. app.appConn.SetResponseCallback(cb)
  92. }
  93. func (app *appConnMempool) Error() error {
  94. return app.appConn.Error()
  95. }
  96. func (app *appConnMempool) FlushAsync(ctx context.Context) (*abcicli.ReqRes, error) {
  97. return app.appConn.FlushAsync(ctx)
  98. }
  99. func (app *appConnMempool) FlushSync(ctx context.Context) error {
  100. return app.appConn.FlushSync(ctx)
  101. }
  102. func (app *appConnMempool) CheckTxAsync(ctx context.Context, req types.RequestCheckTx) (*abcicli.ReqRes, error) {
  103. return app.appConn.CheckTxAsync(ctx, req)
  104. }
  105. func (app *appConnMempool) CheckTxSync(ctx context.Context, req types.RequestCheckTx) (*types.ResponseCheckTx, error) {
  106. return app.appConn.CheckTxSync(ctx, req)
  107. }
  108. //------------------------------------------------
  109. // Implements AppConnQuery (subset of abcicli.Client)
  110. type appConnQuery struct {
  111. appConn abcicli.Client
  112. }
  113. func NewAppConnQuery(appConn abcicli.Client) AppConnQuery {
  114. return &appConnQuery{
  115. appConn: appConn,
  116. }
  117. }
  118. func (app *appConnQuery) Error() error {
  119. return app.appConn.Error()
  120. }
  121. func (app *appConnQuery) EchoSync(ctx context.Context, msg string) (*types.ResponseEcho, error) {
  122. return app.appConn.EchoSync(ctx, msg)
  123. }
  124. func (app *appConnQuery) InfoSync(ctx context.Context, req types.RequestInfo) (*types.ResponseInfo, error) {
  125. return app.appConn.InfoSync(ctx, req)
  126. }
  127. func (app *appConnQuery) QuerySync(ctx context.Context, reqQuery types.RequestQuery) (*types.ResponseQuery, error) {
  128. return app.appConn.QuerySync(ctx, reqQuery)
  129. }
  130. //------------------------------------------------
  131. // Implements AppConnSnapshot (subset of abcicli.Client)
  132. type appConnSnapshot struct {
  133. appConn abcicli.Client
  134. }
  135. func NewAppConnSnapshot(appConn abcicli.Client) AppConnSnapshot {
  136. return &appConnSnapshot{
  137. appConn: appConn,
  138. }
  139. }
  140. func (app *appConnSnapshot) Error() error {
  141. return app.appConn.Error()
  142. }
  143. func (app *appConnSnapshot) ListSnapshotsSync(
  144. ctx context.Context,
  145. req types.RequestListSnapshots,
  146. ) (*types.ResponseListSnapshots, error) {
  147. return app.appConn.ListSnapshotsSync(ctx, req)
  148. }
  149. func (app *appConnSnapshot) OfferSnapshotSync(
  150. ctx context.Context,
  151. req types.RequestOfferSnapshot,
  152. ) (*types.ResponseOfferSnapshot, error) {
  153. return app.appConn.OfferSnapshotSync(ctx, req)
  154. }
  155. func (app *appConnSnapshot) LoadSnapshotChunkSync(
  156. ctx context.Context,
  157. req types.RequestLoadSnapshotChunk) (*types.ResponseLoadSnapshotChunk, error) {
  158. return app.appConn.LoadSnapshotChunkSync(ctx, req)
  159. }
  160. func (app *appConnSnapshot) ApplySnapshotChunkSync(
  161. ctx context.Context,
  162. req types.RequestApplySnapshotChunk) (*types.ResponseApplySnapshotChunk, error) {
  163. return app.appConn.ApplySnapshotChunkSync(ctx, req)
  164. }