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.

71 lines
1.6 KiB

9 years ago
8 years ago
9 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. package dummy
  2. import (
  3. "strings"
  4. "github.com/tendermint/abci/types"
  5. "github.com/tendermint/merkleeyes/iavl"
  6. cmn "github.com/tendermint/tmlibs/common"
  7. "github.com/tendermint/tmlibs/merkle"
  8. )
  9. type DummyApplication struct {
  10. types.BaseApplication
  11. state merkle.Tree
  12. }
  13. func NewDummyApplication() *DummyApplication {
  14. state := iavl.NewIAVLTree(0, nil)
  15. return &DummyApplication{state: state}
  16. }
  17. func (app *DummyApplication) Info() (resInfo types.ResponseInfo) {
  18. return types.ResponseInfo{Data: cmn.Fmt("{\"size\":%v}", app.state.Size())}
  19. }
  20. // tx is either "key=value" or just arbitrary bytes
  21. func (app *DummyApplication) DeliverTx(tx []byte) types.Result {
  22. parts := strings.Split(string(tx), "=")
  23. if len(parts) == 2 {
  24. app.state.Set([]byte(parts[0]), []byte(parts[1]))
  25. } else {
  26. app.state.Set(tx, tx)
  27. }
  28. return types.OK
  29. }
  30. func (app *DummyApplication) CheckTx(tx []byte) types.Result {
  31. return types.OK
  32. }
  33. func (app *DummyApplication) Commit() types.Result {
  34. hash := app.state.Hash()
  35. return types.NewResultOK(hash, "")
  36. }
  37. func (app *DummyApplication) Query(reqQuery types.RequestQuery) (resQuery types.ResponseQuery) {
  38. if reqQuery.Prove {
  39. value, proof, exists := app.state.Proof(reqQuery.Data)
  40. resQuery.Index = -1 // TODO make Proof return index
  41. resQuery.Key = reqQuery.Data
  42. resQuery.Value = value
  43. resQuery.Proof = proof
  44. if exists {
  45. resQuery.Log = "exists"
  46. } else {
  47. resQuery.Log = "does not exist"
  48. }
  49. return
  50. } else {
  51. index, value, exists := app.state.Get(reqQuery.Data)
  52. resQuery.Index = int64(index)
  53. resQuery.Value = value
  54. if exists {
  55. resQuery.Log = "exists"
  56. } else {
  57. resQuery.Log = "does not exist"
  58. }
  59. return
  60. }
  61. }