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.

123 lines
2.5 KiB

  1. package proxy
  2. import (
  3. tmsp "github.com/tendermint/tmsp/types"
  4. )
  5. type localAppContext struct {
  6. tmsp.AppContext
  7. Callback
  8. }
  9. func NewLocalAppContext(app tmsp.AppContext) *localAppContext {
  10. return &localAppContext{
  11. AppContext: app,
  12. }
  13. }
  14. func (app *localAppContext) SetResponseCallback(cb Callback) {
  15. app.Callback = cb
  16. }
  17. // TODO: change tmsp.AppContext to include Error()?
  18. func (app *localAppContext) Error() error {
  19. return nil
  20. }
  21. func (app *localAppContext) EchoAsync(msg string) {
  22. msg2 := app.AppContext.Echo(msg)
  23. app.Callback(
  24. tmsp.RequestEcho{msg},
  25. tmsp.ResponseEcho{msg2},
  26. )
  27. }
  28. func (app *localAppContext) FlushAsync() {
  29. // Do nothing
  30. }
  31. func (app *localAppContext) SetOptionAsync(key string, value string) {
  32. retCode := app.AppContext.SetOption(key, value)
  33. app.Callback(
  34. tmsp.RequestSetOption{key, value},
  35. tmsp.ResponseSetOption{retCode},
  36. )
  37. }
  38. func (app *localAppContext) AppendTxAsync(tx []byte) {
  39. events, retCode := app.AppContext.AppendTx(tx)
  40. app.Callback(
  41. tmsp.RequestAppendTx{tx},
  42. tmsp.ResponseAppendTx{retCode},
  43. )
  44. for _, event := range events {
  45. app.Callback(
  46. nil,
  47. tmsp.ResponseEvent{event},
  48. )
  49. }
  50. }
  51. func (app *localAppContext) GetHashAsync() {
  52. hash, retCode := app.AppContext.GetHash()
  53. app.Callback(
  54. tmsp.RequestGetHash{},
  55. tmsp.ResponseGetHash{retCode, hash},
  56. )
  57. }
  58. func (app *localAppContext) CommitAsync() {
  59. retCode := app.AppContext.Commit()
  60. app.Callback(
  61. tmsp.RequestCommit{},
  62. tmsp.ResponseCommit{retCode},
  63. )
  64. }
  65. func (app *localAppContext) RollbackAsync() {
  66. retCode := app.AppContext.Rollback()
  67. app.Callback(
  68. tmsp.RequestRollback{},
  69. tmsp.ResponseRollback{retCode},
  70. )
  71. }
  72. func (app *localAppContext) AddListenerAsync(key string) {
  73. retCode := app.AppContext.AddListener(key)
  74. app.Callback(
  75. tmsp.RequestAddListener{key},
  76. tmsp.ResponseAddListener{retCode},
  77. )
  78. }
  79. func (app *localAppContext) RemListenerAsync(key string) {
  80. retCode := app.AppContext.RemListener(key)
  81. app.Callback(
  82. tmsp.RequestRemListener{key},
  83. tmsp.ResponseRemListener{retCode},
  84. )
  85. }
  86. func (app *localAppContext) InfoSync() (info []string, err error) {
  87. info = app.AppContext.Info()
  88. return info, nil
  89. }
  90. func (app *localAppContext) FlushSync() error {
  91. return nil
  92. }
  93. func (app *localAppContext) GetHashSync() (hash []byte, err error) {
  94. hash, retCode := app.AppContext.GetHash()
  95. return hash, retCode.Error()
  96. }
  97. func (app *localAppContext) CommitSync() (err error) {
  98. retCode := app.AppContext.Commit()
  99. return retCode.Error()
  100. }
  101. func (app *localAppContext) RollbackSync() (err error) {
  102. retCode := app.AppContext.Rollback()
  103. return retCode.Error()
  104. }