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.

190 lines
5.3 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. FlushAsync() *abcicli.ReqRes
  23. FlushSync() error
  24. }
  25. type AppConnQuery interface {
  26. Error() error
  27. EchoSync(string) (*types.ResponseEcho, error)
  28. InfoSync(types.RequestInfo) (*types.ResponseInfo, error)
  29. QuerySync(types.RequestQuery) (*types.ResponseQuery, error)
  30. // SetOptionSync(key string, value string) (res types.Result)
  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. //------------------------------------------------
  96. // Implements AppConnQuery (subset of abcicli.Client)
  97. type appConnQuery struct {
  98. appConn abcicli.Client
  99. }
  100. func NewAppConnQuery(appConn abcicli.Client) AppConnQuery {
  101. return &appConnQuery{
  102. appConn: appConn,
  103. }
  104. }
  105. func (app *appConnQuery) Error() error {
  106. return app.appConn.Error()
  107. }
  108. func (app *appConnQuery) EchoSync(msg string) (*types.ResponseEcho, error) {
  109. return app.appConn.EchoSync(msg)
  110. }
  111. func (app *appConnQuery) InfoSync(req types.RequestInfo) (*types.ResponseInfo, error) {
  112. return app.appConn.InfoSync(req)
  113. }
  114. func (app *appConnQuery) QuerySync(reqQuery types.RequestQuery) (*types.ResponseQuery, error) {
  115. return app.appConn.QuerySync(reqQuery)
  116. }
  117. //------------------------------------------------
  118. // Implements AppConnSnapshot (subset of abcicli.Client)
  119. type appConnSnapshot struct {
  120. appConn abcicli.Client
  121. }
  122. func NewAppConnSnapshot(appConn abcicli.Client) AppConnSnapshot {
  123. return &appConnSnapshot{
  124. appConn: appConn,
  125. }
  126. }
  127. func (app *appConnSnapshot) Error() error {
  128. return app.appConn.Error()
  129. }
  130. func (app *appConnSnapshot) ListSnapshotsSync(req types.RequestListSnapshots) (*types.ResponseListSnapshots, error) {
  131. return app.appConn.ListSnapshotsSync(req)
  132. }
  133. func (app *appConnSnapshot) OfferSnapshotSync(req types.RequestOfferSnapshot) (*types.ResponseOfferSnapshot, error) {
  134. return app.appConn.OfferSnapshotSync(req)
  135. }
  136. func (app *appConnSnapshot) LoadSnapshotChunkSync(
  137. req types.RequestLoadSnapshotChunk) (*types.ResponseLoadSnapshotChunk, error) {
  138. return app.appConn.LoadSnapshotChunkSync(req)
  139. }
  140. func (app *appConnSnapshot) ApplySnapshotChunkSync(
  141. req types.RequestApplySnapshotChunk) (*types.ResponseApplySnapshotChunk, error) {
  142. return app.appConn.ApplySnapshotChunkSync(req)
  143. }