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.

78 lines
1.7 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
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "log"
  6. "github.com/tendermint/abci/server"
  7. "github.com/tendermint/abci/types"
  8. common "github.com/tendermint/go-common"
  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. // Start the listener
  15. srv, err := server.NewServer(*addrPtr, *abciPtr, NewChainAwareApplication())
  16. if err != nil {
  17. log.Fatal(err.Error())
  18. }
  19. // Wait forever
  20. common.TrapSignal(func() {
  21. // Cleanup
  22. srv.Stop()
  23. })
  24. }
  25. type ChainAwareApplication struct {
  26. beginCount int
  27. endCount int
  28. }
  29. func NewChainAwareApplication() *ChainAwareApplication {
  30. return &ChainAwareApplication{}
  31. }
  32. func (app *ChainAwareApplication) Info() types.ResponseInfo {
  33. return types.ResponseInfo{}
  34. }
  35. func (app *ChainAwareApplication) SetOption(key string, value string) (log string) {
  36. return ""
  37. }
  38. func (app *ChainAwareApplication) DeliverTx(tx []byte) types.Result {
  39. return types.NewResultOK(nil, "")
  40. }
  41. func (app *ChainAwareApplication) CheckTx(tx []byte) types.Result {
  42. return types.NewResultOK(nil, "")
  43. }
  44. func (app *ChainAwareApplication) Commit() types.Result {
  45. return types.NewResultOK([]byte("nil"), "")
  46. }
  47. func (app *ChainAwareApplication) Query(query []byte) types.Result {
  48. return types.NewResultOK([]byte(fmt.Sprintf("%d,%d", app.beginCount, app.endCount)), "")
  49. }
  50. func (app *ChainAwareApplication) BeginBlock(hash []byte, header *types.Header) {
  51. app.beginCount++
  52. return
  53. }
  54. func (app *ChainAwareApplication) EndBlock(height uint64) (resEndBlock types.ResponseEndBlock) {
  55. app.endCount++
  56. return
  57. }
  58. func (app *ChainAwareApplication) InitChain(vals []*types.Validator) {
  59. return
  60. }