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.

55 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. // tx is either "key=value" or just arbitrary bytes
  25. func (app *DummyApplication) AppendTx(tx []byte) types.Result {
  26. parts := strings.Split(string(tx), "=")
  27. if len(parts) == 2 {
  28. app.state.Set([]byte(parts[0]), []byte(parts[1]))
  29. } else {
  30. app.state.Set(tx, tx)
  31. }
  32. return types.OK
  33. }
  34. func (app *DummyApplication) CheckTx(tx []byte) types.Result {
  35. return types.OK
  36. }
  37. func (app *DummyApplication) Commit() types.Result {
  38. hash := app.state.Hash()
  39. return types.NewResultOK(hash, "")
  40. }
  41. func (app *DummyApplication) Query(query []byte) types.Result {
  42. index, value, exists := app.state.Get(query)
  43. resStr := Fmt("Index=%v value=%v exists=%v", index, string(value), exists)
  44. return types.NewResultOK([]byte(resStr), "")
  45. }