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.

61 lines
1.5 KiB

9 years ago
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. "encoding/hex"
  4. "fmt"
  5. "strings"
  6. "github.com/tendermint/abci/types"
  7. "github.com/tendermint/go-merkle"
  8. "github.com/tendermint/go-wire"
  9. )
  10. type DummyApplication struct {
  11. state merkle.Tree
  12. }
  13. func NewDummyApplication() *DummyApplication {
  14. state := merkle.NewIAVLTree(0, nil)
  15. return &DummyApplication{state: state}
  16. }
  17. func (app *DummyApplication) Info() (resInfo types.ResponseInfo) {
  18. return types.ResponseInfo{Data: fmt.Sprintf("{\"size\":%v}", app.state.Size())}
  19. }
  20. func (app *DummyApplication) SetOption(key string, value string) (log string) {
  21. return ""
  22. }
  23. // tx is either "key=value" or just arbitrary bytes
  24. func (app *DummyApplication) DeliverTx(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. queryResult := QueryResult{index, string(value), hex.EncodeToString(value), exists}
  43. return types.NewResultOK(wire.JSONBytes(queryResult), "")
  44. }
  45. type QueryResult struct {
  46. Index int `json:"index"`
  47. Value string `json:"value"`
  48. ValueHex string `json:"valueHex"`
  49. Exists bool `json:"exists"`
  50. }