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.

195 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. // SetOptionSync(key string, value string) (res types.Result)
  32. }
  33. type AppConnSnapshot interface {
  34. Error() error
  35. ListSnapshotsSync(types.RequestListSnapshots) (*types.ResponseListSnapshots, error)
  36. OfferSnapshotSync(types.RequestOfferSnapshot) (*types.ResponseOfferSnapshot, error)
  37. LoadSnapshotChunkSync(types.RequestLoadSnapshotChunk) (*types.ResponseLoadSnapshotChunk, error)
  38. ApplySnapshotChunkSync(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(req types.RequestInitChain) (*types.ResponseInitChain, error) {
  57. return app.appConn.InitChainSync(req)
  58. }
  59. func (app *appConnConsensus) BeginBlockSync(req types.RequestBeginBlock) (*types.ResponseBeginBlock, error) {
  60. return app.appConn.BeginBlockSync(req)
  61. }
  62. func (app *appConnConsensus) DeliverTxAsync(req types.RequestDeliverTx) *abcicli.ReqRes {
  63. return app.appConn.DeliverTxAsync(req)
  64. }
  65. func (app *appConnConsensus) EndBlockSync(req types.RequestEndBlock) (*types.ResponseEndBlock, error) {
  66. return app.appConn.EndBlockSync(req)
  67. }
  68. func (app *appConnConsensus) CommitSync() (*types.ResponseCommit, error) {
  69. return app.appConn.CommitSync()
  70. }
  71. //------------------------------------------------
  72. // Implements AppConnMempool (subset of abcicli.Client)
  73. type appConnMempool struct {
  74. appConn abcicli.Client
  75. }
  76. func NewAppConnMempool(appConn abcicli.Client) AppConnMempool {
  77. return &appConnMempool{
  78. appConn: appConn,
  79. }
  80. }
  81. func (app *appConnMempool) SetResponseCallback(cb abcicli.Callback) {
  82. app.appConn.SetResponseCallback(cb)
  83. }
  84. func (app *appConnMempool) Error() error {
  85. return app.appConn.Error()
  86. }
  87. func (app *appConnMempool) FlushAsync() *abcicli.ReqRes {
  88. return app.appConn.FlushAsync()
  89. }
  90. func (app *appConnMempool) FlushSync() error {
  91. return app.appConn.FlushSync()
  92. }
  93. func (app *appConnMempool) CheckTxAsync(req types.RequestCheckTx) *abcicli.ReqRes {
  94. return app.appConn.CheckTxAsync(req)
  95. }
  96. func (app *appConnMempool) CheckTxSync(req types.RequestCheckTx) (*types.ResponseCheckTx, error) {
  97. return app.appConn.CheckTxSync(req)
  98. }
  99. //------------------------------------------------
  100. // Implements AppConnQuery (subset of abcicli.Client)
  101. type appConnQuery struct {
  102. appConn abcicli.Client
  103. }
  104. func NewAppConnQuery(appConn abcicli.Client) AppConnQuery {
  105. return &appConnQuery{
  106. appConn: appConn,
  107. }
  108. }
  109. func (app *appConnQuery) Error() error {
  110. return app.appConn.Error()
  111. }
  112. func (app *appConnQuery) EchoSync(msg string) (*types.ResponseEcho, error) {
  113. return app.appConn.EchoSync(msg)
  114. }
  115. func (app *appConnQuery) InfoSync(req types.RequestInfo) (*types.ResponseInfo, error) {
  116. return app.appConn.InfoSync(req)
  117. }
  118. func (app *appConnQuery) QuerySync(reqQuery types.RequestQuery) (*types.ResponseQuery, error) {
  119. return app.appConn.QuerySync(reqQuery)
  120. }
  121. //------------------------------------------------
  122. // Implements AppConnSnapshot (subset of abcicli.Client)
  123. type appConnSnapshot struct {
  124. appConn abcicli.Client
  125. }
  126. func NewAppConnSnapshot(appConn abcicli.Client) AppConnSnapshot {
  127. return &appConnSnapshot{
  128. appConn: appConn,
  129. }
  130. }
  131. func (app *appConnSnapshot) Error() error {
  132. return app.appConn.Error()
  133. }
  134. func (app *appConnSnapshot) ListSnapshotsSync(req types.RequestListSnapshots) (*types.ResponseListSnapshots, error) {
  135. return app.appConn.ListSnapshotsSync(req)
  136. }
  137. func (app *appConnSnapshot) OfferSnapshotSync(req types.RequestOfferSnapshot) (*types.ResponseOfferSnapshot, error) {
  138. return app.appConn.OfferSnapshotSync(req)
  139. }
  140. func (app *appConnSnapshot) LoadSnapshotChunkSync(
  141. req types.RequestLoadSnapshotChunk) (*types.ResponseLoadSnapshotChunk, error) {
  142. return app.appConn.LoadSnapshotChunkSync(req)
  143. }
  144. func (app *appConnSnapshot) ApplySnapshotChunkSync(
  145. req types.RequestApplySnapshotChunk) (*types.ResponseApplySnapshotChunk, error) {
  146. return app.appConn.ApplySnapshotChunkSync(req)
  147. }