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.

84 lines
1.7 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. package main
  2. import (
  3. . "github.com/tendermint/go-common"
  4. "github.com/tendermint/go-merkle"
  5. "github.com/tendermint/go-wire"
  6. "github.com/tendermint/tmsp/server"
  7. "github.com/tendermint/tmsp/types"
  8. )
  9. func main() {
  10. // Start the listener
  11. _, err := server.StartListener("tcp://127.0.0.1:8080", NewDummyApplication())
  12. if err != nil {
  13. Exit(err.Error())
  14. }
  15. // Wait forever
  16. TrapSignal(func() {
  17. // Cleanup
  18. })
  19. }
  20. //--------------------------------------------------------------------------------
  21. type DummyApplication struct {
  22. state merkle.Tree
  23. lastCommitState merkle.Tree
  24. }
  25. func NewDummyApplication() *DummyApplication {
  26. state := merkle.NewIAVLTree(
  27. wire.BasicCodec,
  28. wire.BasicCodec,
  29. 0,
  30. nil,
  31. )
  32. return &DummyApplication{
  33. state: state,
  34. lastCommitState: state,
  35. }
  36. }
  37. func (dapp *DummyApplication) Echo(message string) string {
  38. return message
  39. }
  40. func (dapp *DummyApplication) Info() []string {
  41. return []string{Fmt("size:%v", dapp.state.Size())}
  42. }
  43. func (dapp *DummyApplication) SetOption(key string, value string) types.RetCode {
  44. return 0
  45. }
  46. func (dapp *DummyApplication) AppendTx(tx []byte) ([]types.Event, types.RetCode) {
  47. dapp.state.Set(tx, tx)
  48. return nil, 0
  49. }
  50. func (dapp *DummyApplication) GetHash() ([]byte, types.RetCode) {
  51. hash := dapp.state.Hash()
  52. return hash, 0
  53. }
  54. func (dapp *DummyApplication) Commit() types.RetCode {
  55. dapp.lastCommitState = dapp.state.Copy()
  56. return 0
  57. }
  58. func (dapp *DummyApplication) Rollback() types.RetCode {
  59. dapp.state = dapp.lastCommitState.Copy()
  60. return 0
  61. }
  62. func (dapp *DummyApplication) AddListener(key string) types.RetCode {
  63. return 0
  64. }
  65. func (dapp *DummyApplication) RemListener(key string) types.RetCode {
  66. return 0
  67. }