2016-11-03 19:50:57 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
|
2017-01-12 15:47:55 -05:00
|
|
|
"github.com/tendermint/abci/server"
|
|
|
|
"github.com/tendermint/abci/types"
|
2017-01-16 22:48:24 -08:00
|
|
|
common "github.com/tendermint/go-common"
|
2016-11-03 19:50:57 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
|
|
|
addrPtr := flag.String("addr", "tcp://0.0.0.0:46658", "Listen address")
|
2017-01-12 15:47:55 -05:00
|
|
|
abciPtr := flag.String("abci", "socket", "socket | grpc")
|
2016-11-03 19:50:57 -04:00
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
// Start the listener
|
2017-01-12 15:47:55 -05:00
|
|
|
srv, err := server.NewServer(*addrPtr, *abciPtr, NewChainAwareApplication())
|
2016-11-03 19:50:57 -04:00
|
|
|
if err != nil {
|
2017-01-16 22:48:24 -08:00
|
|
|
common.Exit(err.Error())
|
2016-11-03 19:50:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Wait forever
|
2017-01-16 22:48:24 -08:00
|
|
|
common.TrapSignal(func() {
|
2016-11-03 19:50:57 -04:00
|
|
|
// Cleanup
|
2016-12-26 22:12:32 -08:00
|
|
|
srv.Stop()
|
2016-11-03 19:50:57 -04: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 19:50:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (app *ChainAwareApplication) SetOption(key string, value string) (log string) {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2017-01-12 15:27:08 -05:00
|
|
|
func (app *ChainAwareApplication) DeliverTx(tx []byte) types.Result {
|
2016-11-03 19:50:57 -04: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(query []byte) types.Result {
|
2017-01-16 22:48:24 -08:00
|
|
|
return types.NewResultOK([]byte(common.Fmt("%d,%d", app.beginCount, app.endCount)), "")
|
2016-11-03 19:50:57 -04:00
|
|
|
}
|
|
|
|
|
2016-11-16 16:22:52 -05:00
|
|
|
func (app *ChainAwareApplication) BeginBlock(hash []byte, header *types.Header) {
|
2016-11-03 19:50:57 -04:00
|
|
|
app.beginCount += 1
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-12-26 22:12:32 -08:00
|
|
|
func (app *ChainAwareApplication) EndBlock(height uint64) (resEndBlock types.ResponseEndBlock) {
|
2016-11-03 19:50:57 -04:00
|
|
|
app.endCount += 1
|
2016-12-26 22:12:32 -08:00
|
|
|
return
|
2016-11-03 19:50:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (app *ChainAwareApplication) InitChain(vals []*types.Validator) {
|
|
|
|
return
|
|
|
|
}
|