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.

215 lines
6.3 KiB

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. abciclient "github.com/tendermint/tendermint/abci/client"
  5. "github.com/tendermint/tendermint/abci/types"
  6. )
  7. //go:generate ../../scripts/mockery_generate.sh 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(abciclient.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) (*abciclient.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(abciclient.Callback)
  21. Error() error
  22. CheckTxAsync(context.Context, types.RequestCheckTx) (*abciclient.ReqRes, error)
  23. CheckTxSync(context.Context, types.RequestCheckTx) (*types.ResponseCheckTx, error)
  24. FlushAsync(context.Context) (*abciclient.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 abciclient.Client)
  42. type appConnConsensus struct {
  43. appConn abciclient.Client
  44. }
  45. func NewAppConnConsensus(appConn abciclient.Client) AppConnConsensus {
  46. return &appConnConsensus{
  47. appConn: appConn,
  48. }
  49. }
  50. func (app *appConnConsensus) SetResponseCallback(cb abciclient.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(
  69. ctx context.Context,
  70. req types.RequestDeliverTx,
  71. ) (*abciclient.ReqRes, error) {
  72. return app.appConn.DeliverTxAsync(ctx, req)
  73. }
  74. func (app *appConnConsensus) EndBlockSync(
  75. ctx context.Context,
  76. req types.RequestEndBlock,
  77. ) (*types.ResponseEndBlock, error) {
  78. return app.appConn.EndBlockSync(ctx, req)
  79. }
  80. func (app *appConnConsensus) CommitSync(ctx context.Context) (*types.ResponseCommit, error) {
  81. return app.appConn.CommitSync(ctx)
  82. }
  83. //------------------------------------------------
  84. // Implements AppConnMempool (subset of abciclient.Client)
  85. type appConnMempool struct {
  86. appConn abciclient.Client
  87. }
  88. func NewAppConnMempool(appConn abciclient.Client) AppConnMempool {
  89. return &appConnMempool{
  90. appConn: appConn,
  91. }
  92. }
  93. func (app *appConnMempool) SetResponseCallback(cb abciclient.Callback) {
  94. app.appConn.SetResponseCallback(cb)
  95. }
  96. func (app *appConnMempool) Error() error {
  97. return app.appConn.Error()
  98. }
  99. func (app *appConnMempool) FlushAsync(ctx context.Context) (*abciclient.ReqRes, error) {
  100. return app.appConn.FlushAsync(ctx)
  101. }
  102. func (app *appConnMempool) FlushSync(ctx context.Context) error {
  103. return app.appConn.FlushSync(ctx)
  104. }
  105. func (app *appConnMempool) CheckTxAsync(ctx context.Context, req types.RequestCheckTx) (*abciclient.ReqRes, error) {
  106. return app.appConn.CheckTxAsync(ctx, req)
  107. }
  108. func (app *appConnMempool) CheckTxSync(ctx context.Context, req types.RequestCheckTx) (*types.ResponseCheckTx, error) {
  109. return app.appConn.CheckTxSync(ctx, req)
  110. }
  111. //------------------------------------------------
  112. // Implements AppConnQuery (subset of abciclient.Client)
  113. type appConnQuery struct {
  114. appConn abciclient.Client
  115. }
  116. func NewAppConnQuery(appConn abciclient.Client) AppConnQuery {
  117. return &appConnQuery{
  118. appConn: appConn,
  119. }
  120. }
  121. func (app *appConnQuery) Error() error {
  122. return app.appConn.Error()
  123. }
  124. func (app *appConnQuery) EchoSync(ctx context.Context, msg string) (*types.ResponseEcho, error) {
  125. return app.appConn.EchoSync(ctx, msg)
  126. }
  127. func (app *appConnQuery) InfoSync(ctx context.Context, req types.RequestInfo) (*types.ResponseInfo, error) {
  128. return app.appConn.InfoSync(ctx, req)
  129. }
  130. func (app *appConnQuery) QuerySync(ctx context.Context, reqQuery types.RequestQuery) (*types.ResponseQuery, error) {
  131. return app.appConn.QuerySync(ctx, reqQuery)
  132. }
  133. //------------------------------------------------
  134. // Implements AppConnSnapshot (subset of abciclient.Client)
  135. type appConnSnapshot struct {
  136. appConn abciclient.Client
  137. }
  138. func NewAppConnSnapshot(appConn abciclient.Client) AppConnSnapshot {
  139. return &appConnSnapshot{
  140. appConn: appConn,
  141. }
  142. }
  143. func (app *appConnSnapshot) Error() error {
  144. return app.appConn.Error()
  145. }
  146. func (app *appConnSnapshot) ListSnapshotsSync(
  147. ctx context.Context,
  148. req types.RequestListSnapshots,
  149. ) (*types.ResponseListSnapshots, error) {
  150. return app.appConn.ListSnapshotsSync(ctx, req)
  151. }
  152. func (app *appConnSnapshot) OfferSnapshotSync(
  153. ctx context.Context,
  154. req types.RequestOfferSnapshot,
  155. ) (*types.ResponseOfferSnapshot, error) {
  156. return app.appConn.OfferSnapshotSync(ctx, req)
  157. }
  158. func (app *appConnSnapshot) LoadSnapshotChunkSync(
  159. ctx context.Context,
  160. req types.RequestLoadSnapshotChunk) (*types.ResponseLoadSnapshotChunk, error) {
  161. return app.appConn.LoadSnapshotChunkSync(ctx, req)
  162. }
  163. func (app *appConnSnapshot) ApplySnapshotChunkSync(
  164. ctx context.Context,
  165. req types.RequestApplySnapshotChunk) (*types.ResponseApplySnapshotChunk, error) {
  166. return app.appConn.ApplySnapshotChunkSync(ctx, req)
  167. }