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.

144 lines
3.6 KiB

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. tmspcli "github.com/tendermint/tmsp/client"
  4. "github.com/tendermint/tmsp/types"
  5. )
  6. //----------------------------------------------------------------------------------------
  7. // Enforce which tmsp msgs can be sent on a connection at the type level
  8. type AppConnConsensus interface {
  9. SetResponseCallback(tmspcli.Callback)
  10. Error() error
  11. InitChainSync(validators []*types.Validator) (err error)
  12. BeginBlockSync(hash []byte, header *types.Header) (err error)
  13. AppendTxAsync(tx []byte) *tmspcli.ReqRes
  14. EndBlockSync(height uint64) (changedValidators []*types.Validator, err error)
  15. CommitSync() (res types.Result)
  16. }
  17. type AppConnMempool interface {
  18. SetResponseCallback(tmspcli.Callback)
  19. Error() error
  20. CheckTxAsync(tx []byte) *tmspcli.ReqRes
  21. FlushAsync() *tmspcli.ReqRes
  22. FlushSync() error
  23. }
  24. type AppConnQuery interface {
  25. Error() error
  26. EchoSync(string) (res types.Result)
  27. InfoSync() (types.Result, *types.TMSPInfo, *types.LastBlockInfo, *types.ConfigInfo)
  28. QuerySync(tx []byte) (res types.Result)
  29. // SetOptionSync(key string, value string) (res types.Result)
  30. }
  31. //-----------------------------------------------------------------------------------------
  32. // Implements AppConnConsensus (subset of tmspcli.Client)
  33. type appConnConsensus struct {
  34. appConn tmspcli.Client
  35. }
  36. func NewAppConnConsensus(appConn tmspcli.Client) *appConnConsensus {
  37. return &appConnConsensus{
  38. appConn: appConn,
  39. }
  40. }
  41. func (app *appConnConsensus) SetResponseCallback(cb tmspcli.Callback) {
  42. app.appConn.SetResponseCallback(cb)
  43. }
  44. func (app *appConnConsensus) Error() error {
  45. return app.appConn.Error()
  46. }
  47. func (app *appConnConsensus) InitChainSync(validators []*types.Validator) (err error) {
  48. return app.appConn.InitChainSync(validators)
  49. }
  50. func (app *appConnConsensus) BeginBlockSync(hash []byte, header *types.Header) (err error) {
  51. return app.appConn.BeginBlockSync(hash, header)
  52. }
  53. func (app *appConnConsensus) AppendTxAsync(tx []byte) *tmspcli.ReqRes {
  54. return app.appConn.AppendTxAsync(tx)
  55. }
  56. func (app *appConnConsensus) EndBlockSync(height uint64) (changedValidators []*types.Validator, err error) {
  57. return app.appConn.EndBlockSync(height)
  58. }
  59. func (app *appConnConsensus) CommitSync() (res types.Result) {
  60. return app.appConn.CommitSync()
  61. }
  62. //------------------------------------------------
  63. // Implements AppConnMempool (subset of tmspcli.Client)
  64. type appConnMempool struct {
  65. appConn tmspcli.Client
  66. }
  67. func NewAppConnMempool(appConn tmspcli.Client) *appConnMempool {
  68. return &appConnMempool{
  69. appConn: appConn,
  70. }
  71. }
  72. func (app *appConnMempool) SetResponseCallback(cb tmspcli.Callback) {
  73. app.appConn.SetResponseCallback(cb)
  74. }
  75. func (app *appConnMempool) Error() error {
  76. return app.appConn.Error()
  77. }
  78. func (app *appConnMempool) FlushAsync() *tmspcli.ReqRes {
  79. return app.appConn.FlushAsync()
  80. }
  81. func (app *appConnMempool) FlushSync() error {
  82. return app.appConn.FlushSync()
  83. }
  84. func (app *appConnMempool) CheckTxAsync(tx []byte) *tmspcli.ReqRes {
  85. return app.appConn.CheckTxAsync(tx)
  86. }
  87. //------------------------------------------------
  88. // Implements AppConnQuery (subset of tmspcli.Client)
  89. type appConnQuery struct {
  90. appConn tmspcli.Client
  91. }
  92. func NewAppConnQuery(appConn tmspcli.Client) *appConnQuery {
  93. return &appConnQuery{
  94. appConn: appConn,
  95. }
  96. }
  97. func (app *appConnQuery) Error() error {
  98. return app.appConn.Error()
  99. }
  100. func (app *appConnQuery) EchoSync(msg string) (res types.Result) {
  101. return app.appConn.EchoSync(msg)
  102. }
  103. func (app *appConnQuery) InfoSync() (types.Result, *types.TMSPInfo, *types.LastBlockInfo, *types.ConfigInfo) {
  104. return app.appConn.InfoSync()
  105. }
  106. func (app *appConnQuery) QuerySync(tx []byte) (res types.Result) {
  107. return app.appConn.QuerySync(tx)
  108. }