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.

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