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.

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