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.

75 lines
1.7 KiB

8 years ago
8 years ago
8 years ago
  1. package main
  2. import (
  3. "flag"
  4. . "github.com/tendermint/go-common"
  5. "github.com/tendermint/tmsp/server"
  6. "github.com/tendermint/tmsp/types"
  7. )
  8. func main() {
  9. addrPtr := flag.String("addr", "tcp://0.0.0.0:46658", "Listen address")
  10. tmspPtr := flag.String("tmsp", "socket", "socket | grpc")
  11. flag.Parse()
  12. // Start the listener
  13. _, err := server.NewServer(*addrPtr, *tmspPtr, NewChainAwareApplication())
  14. if err != nil {
  15. Exit(err.Error())
  16. }
  17. // Wait forever
  18. TrapSignal(func() {
  19. // Cleanup
  20. })
  21. }
  22. type ChainAwareApplication struct {
  23. beginCount int
  24. endCount int
  25. }
  26. func NewChainAwareApplication() *ChainAwareApplication {
  27. return &ChainAwareApplication{}
  28. }
  29. func (app *ChainAwareApplication) Info() (string, *types.TMSPInfo, *types.LastBlockInfo, *types.ConfigInfo) {
  30. return "nil", nil, nil, nil
  31. }
  32. func (app *ChainAwareApplication) SetOption(key string, value string) (log string) {
  33. return ""
  34. }
  35. func (app *ChainAwareApplication) AppendTx(tx []byte) types.Result {
  36. return types.NewResultOK(nil, "")
  37. }
  38. func (app *ChainAwareApplication) CheckTx(tx []byte) types.Result {
  39. return types.NewResultOK(nil, "")
  40. }
  41. func (app *ChainAwareApplication) Commit() types.Result {
  42. return types.NewResultOK([]byte("nil"), "")
  43. }
  44. func (app *ChainAwareApplication) Query(query []byte) types.Result {
  45. return types.NewResultOK([]byte(Fmt("%d,%d", app.beginCount, app.endCount)), "")
  46. }
  47. func (app *ChainAwareApplication) BeginBlock(hash []byte, header *types.Header) {
  48. app.beginCount += 1
  49. return
  50. }
  51. func (app *ChainAwareApplication) EndBlock(height uint64) []*types.Validator {
  52. app.endCount += 1
  53. return nil
  54. }
  55. func (app *ChainAwareApplication) InitChain(vals []*types.Validator) {
  56. return
  57. }