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.3 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. package example
  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) (code types.CodeType, result []byte, log string) {
  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.CodeType_OK, nil, ""
  32. }
  33. func (app *DummyApplication) CheckTx(tx []byte) (code types.CodeType, result []byte, log string) {
  34. return types.CodeType_OK, nil, ""
  35. }
  36. func (app *DummyApplication) GetHash() (hash []byte, log string) {
  37. hash = app.state.Hash()
  38. return hash, ""
  39. }
  40. func (app *DummyApplication) Query(query []byte) (code types.CodeType, result []byte, log string) {
  41. index, value, exists := app.state.Get(query)
  42. resStr := Fmt("Index=%v value=%v exists=%v", index, string(value), exists)
  43. return types.CodeType_OK, []byte(resStr), ""
  44. }