tendermint/example/block_aware/block_aware_app.go

58 lines
1.1 KiB
Go
Raw Normal View History

2016-11-03 16:50:57 -07:00
package main
import (
"flag"
"log"
2016-11-03 16:50:57 -07:00
2017-01-12 12:47:55 -08:00
"github.com/tendermint/abci/server"
"github.com/tendermint/abci/types"
2017-04-21 15:25:13 -07:00
cmn "github.com/tendermint/tmlibs/common"
2016-11-03 16:50:57 -07:00
)
func main() {
addrPtr := flag.String("addr", "tcp://0.0.0.0:46658", "Listen address")
2017-01-12 12:47:55 -08:00
abciPtr := flag.String("abci", "socket", "socket | grpc")
2016-11-03 16:50:57 -07:00
flag.Parse()
// Start the listener
2017-01-12 12:47:55 -08:00
srv, err := server.NewServer(*addrPtr, *abciPtr, NewChainAwareApplication())
2016-11-03 16:50:57 -07:00
if err != nil {
log.Fatal(err.Error())
2016-11-03 16:50:57 -07:00
}
// Wait forever
2017-01-23 20:26:17 -08:00
cmn.TrapSignal(func() {
2016-11-03 16:50:57 -07:00
// Cleanup
2016-12-26 22:12:32 -08:00
srv.Stop()
2016-11-03 16:50:57 -07:00
})
}
type ChainAwareApplication struct {
2017-02-13 15:48:59 -08:00
types.BaseApplication
2016-11-03 16:50:57 -07:00
beginCount int
endCount int
}
func NewChainAwareApplication() *ChainAwareApplication {
return &ChainAwareApplication{}
}
func (app *ChainAwareApplication) Query(reqQuery types.RequestQuery) (resQuery types.ResponseQuery) {
return types.ResponseQuery{
2017-01-27 22:27:32 -08:00
Value: []byte(cmn.Fmt("%d,%d", app.beginCount, app.endCount)),
}
2016-11-03 16:50:57 -07:00
}
2016-11-16 13:22:52 -08:00
func (app *ChainAwareApplication) BeginBlock(hash []byte, header *types.Header) {
2017-01-17 00:26:32 -08:00
app.beginCount++
2016-11-03 16:50:57 -07:00
return
}
2016-12-26 22:12:32 -08:00
func (app *ChainAwareApplication) EndBlock(height uint64) (resEndBlock types.ResponseEndBlock) {
2017-01-17 00:26:32 -08:00
app.endCount++
2016-12-26 22:12:32 -08:00
return
2016-11-03 16:50:57 -07:00
}