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.

54 lines
1.2 KiB

9 years ago
9 years ago
9 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/go-common"
  5. "github.com/tendermint/go-merkle"
  6. "github.com/tendermint/tmsp/types"
  7. )
  8. type DummyApplication struct {
  9. state merkle.Tree
  10. }
  11. func NewDummyApplication() *DummyApplication {
  12. state := merkle.NewIAVLTree(
  13. 0,
  14. nil,
  15. )
  16. return &DummyApplication{state: state}
  17. }
  18. func (app *DummyApplication) Info() string {
  19. return Fmt("size:%v", app.state.Size())
  20. }
  21. func (app *DummyApplication) SetOption(key string, value string) (log string) {
  22. return ""
  23. }
  24. func (app *DummyApplication) AppendTx(tx []byte) types.Result {
  25. parts := strings.Split(string(tx), "=")
  26. if len(parts) == 2 {
  27. app.state.Set([]byte(parts[0]), []byte(parts[1]))
  28. } else {
  29. app.state.Set(tx, tx)
  30. }
  31. return types.OK
  32. }
  33. func (app *DummyApplication) CheckTx(tx []byte) types.Result {
  34. return types.OK
  35. }
  36. func (app *DummyApplication) Commit() types.Result {
  37. hash := app.state.Hash()
  38. return types.NewResultOK(hash, "")
  39. }
  40. func (app *DummyApplication) Query(query []byte) types.Result {
  41. index, value, exists := app.state.Get(query)
  42. resStr := Fmt("Index=%v value=%v exists=%v", index, string(value), exists)
  43. return types.NewResultOK([]byte(resStr), "")
  44. }