tendermint/example/block_aware/block_aware_app.go

80 lines
1.7 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-01-23 20:26:17 -08:00
cmn "github.com/tendermint/go-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 {
beginCount int
endCount int
}
func NewChainAwareApplication() *ChainAwareApplication {
return &ChainAwareApplication{}
}
2016-12-26 17:44:36 -08:00
func (app *ChainAwareApplication) Info() types.ResponseInfo {
return types.ResponseInfo{}
2016-11-03 16:50:57 -07:00
}
func (app *ChainAwareApplication) SetOption(key string, value string) (log string) {
return ""
}
2017-01-12 12:27:08 -08:00
func (app *ChainAwareApplication) DeliverTx(tx []byte) types.Result {
2016-11-03 16:50:57 -07:00
return types.NewResultOK(nil, "")
}
func (app *ChainAwareApplication) CheckTx(tx []byte) types.Result {
return types.NewResultOK(nil, "")
}
func (app *ChainAwareApplication) Commit() types.Result {
return types.NewResultOK([]byte("nil"), "")
}
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
}
func (app *ChainAwareApplication) InitChain(vals []*types.Validator) {
return
}