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.

66 lines
1.4 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "github.com/tendermint/abci/server"
  6. "github.com/tendermint/abci/types"
  7. cmn "github.com/tendermint/tmlibs/common"
  8. "github.com/tendermint/tmlibs/log"
  9. )
  10. func main() {
  11. addrPtr := flag.String("addr", "tcp://0.0.0.0:46658", "Listen address")
  12. abciPtr := flag.String("abci", "socket", "socket | grpc")
  13. flag.Parse()
  14. logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
  15. // Start the listener
  16. srv, err := server.NewServer(*addrPtr, *abciPtr, NewChainAwareApplication())
  17. if err != nil {
  18. logger.Error(err.Error())
  19. os.Exit(1)
  20. }
  21. srv.SetLogger(logger.With("module", "abci-server"))
  22. if _, err := srv.Start(); err != nil {
  23. logger.Error(err.Error())
  24. os.Exit(1)
  25. }
  26. // Wait forever
  27. cmn.TrapSignal(func() {
  28. // Cleanup
  29. srv.Stop()
  30. })
  31. }
  32. type ChainAwareApplication struct {
  33. types.BaseApplication
  34. beginCount int
  35. endCount int
  36. }
  37. func NewChainAwareApplication() *ChainAwareApplication {
  38. return &ChainAwareApplication{}
  39. }
  40. func (app *ChainAwareApplication) Query(reqQuery types.RequestQuery) (resQuery types.ResponseQuery) {
  41. return types.ResponseQuery{
  42. Value: []byte(cmn.Fmt("%d,%d", app.beginCount, app.endCount)),
  43. }
  44. }
  45. func (app *ChainAwareApplication) BeginBlock(hash []byte, header *types.Header) {
  46. app.beginCount++
  47. return
  48. }
  49. func (app *ChainAwareApplication) EndBlock(height uint64) (resEndBlock types.ResponseEndBlock) {
  50. app.endCount++
  51. return
  52. }