diff --git a/example/block_aware/block_aware_app.go b/example/block_aware/block_aware_app.go index 90a7a440..454c3560 100644 --- a/example/block_aware/block_aware_app.go +++ b/example/block_aware/block_aware_app.go @@ -30,6 +30,8 @@ func main() { } type ChainAwareApplication struct { + types.BaseApplication + beginCount int endCount int } @@ -38,26 +40,6 @@ func NewChainAwareApplication() *ChainAwareApplication { return &ChainAwareApplication{} } -func (app *ChainAwareApplication) Info() types.ResponseInfo { - return types.ResponseInfo{} -} - -func (app *ChainAwareApplication) SetOption(key string, value string) (log string) { - return "" -} - -func (app *ChainAwareApplication) DeliverTx(tx []byte) types.Result { - 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{ Value: []byte(cmn.Fmt("%d,%d", app.beginCount, app.endCount)), @@ -73,7 +55,3 @@ func (app *ChainAwareApplication) EndBlock(height uint64) (resEndBlock types.Res app.endCount++ return } - -func (app *ChainAwareApplication) InitChain(vals []*types.Validator) { - return -} diff --git a/example/counter/counter.go b/example/counter/counter.go index 8fce72e2..fa0bab58 100644 --- a/example/counter/counter.go +++ b/example/counter/counter.go @@ -9,6 +9,8 @@ import ( ) type CounterApplication struct { + types.BaseApplication + hashCount int txCount int serial bool @@ -80,13 +82,3 @@ func (app *CounterApplication) Query(reqQuery types.RequestQuery) types.Response return types.ResponseQuery{Log: Fmt("Invalid query path. Expected hash or tx, got %v", reqQuery.Path)} } } - -func (app *CounterApplication) InitChain(validators []*types.Validator) { -} - -func (app *CounterApplication) BeginBlock(hash []byte, header *types.Header) { -} - -func (app *CounterApplication) EndBlock(height uint64) types.ResponseEndBlock { - return types.ResponseEndBlock{} -} diff --git a/example/dummy/dummy.go b/example/dummy/dummy.go index 73c938e7..fd66250b 100644 --- a/example/dummy/dummy.go +++ b/example/dummy/dummy.go @@ -9,6 +9,8 @@ import ( ) type DummyApplication struct { + types.BaseApplication + state merkle.Tree } @@ -21,10 +23,6 @@ func (app *DummyApplication) Info() (resInfo types.ResponseInfo) { return types.ResponseInfo{Data: fmt.Sprintf("{\"size\":%v}", app.state.Size())} } -func (app *DummyApplication) SetOption(key string, value string) (log string) { - return "" -} - // tx is either "key=value" or just arbitrary bytes func (app *DummyApplication) DeliverTx(tx []byte) types.Result { parts := strings.Split(string(tx), "=") @@ -70,13 +68,3 @@ func (app *DummyApplication) Query(reqQuery types.RequestQuery) (resQuery types. return } } - -func (app *DummyApplication) InitChain(validators []*types.Validator) { -} - -func (app *DummyApplication) BeginBlock(hash []byte, header *types.Header) { -} - -func (app *DummyApplication) EndBlock(height uint64) types.ResponseEndBlock { - return types.ResponseEndBlock{} -} diff --git a/example/example_test.go b/example/example_test.go index 26921083..9f18c421 100644 --- a/example/example_test.go +++ b/example/example_test.go @@ -14,7 +14,6 @@ import ( "github.com/tendermint/abci/client" "github.com/tendermint/abci/example/dummy" - nilapp "github.com/tendermint/abci/example/nil" "github.com/tendermint/abci/server" "github.com/tendermint/abci/types" cmn "github.com/tendermint/go-common" @@ -25,14 +24,14 @@ func TestDummy(t *testing.T) { testStream(t, dummy.NewDummyApplication()) } -func TestNilApp(t *testing.T) { - fmt.Println("### Testing NilApp") - testStream(t, nilapp.NewNilApplication()) +func TestBaseApp(t *testing.T) { + fmt.Println("### Testing BaseApp") + testStream(t, types.NewBaseApplication()) } func TestGRPC(t *testing.T) { fmt.Println("### Testing GRPC") - testGRPCSync(t, types.NewGRPCApplication(nilapp.NewNilApplication())) + testGRPCSync(t, types.NewGRPCApplication(types.NewBaseApplication())) } func testStream(t *testing.T, app types.Application) { diff --git a/example/nil/nil_app.go b/example/nil/nil_app.go deleted file mode 100644 index 5285cc39..00000000 --- a/example/nil/nil_app.go +++ /dev/null @@ -1,46 +0,0 @@ -package nilapp - -import ( - "github.com/tendermint/abci/types" -) - -type NilApplication struct { -} - -func NewNilApplication() *NilApplication { - return &NilApplication{} -} - -func (app *NilApplication) Info() (resInfo types.ResponseInfo) { - return -} - -func (app *NilApplication) SetOption(key string, value string) (log string) { - return "" -} - -func (app *NilApplication) DeliverTx(tx []byte) types.Result { - return types.NewResultOK(nil, "") -} - -func (app *NilApplication) CheckTx(tx []byte) types.Result { - return types.NewResultOK(nil, "") -} - -func (app *NilApplication) Commit() types.Result { - return types.NewResultOK([]byte("nil"), "") -} - -func (app *NilApplication) Query(reqQuery types.RequestQuery) (resQuery types.ResponseQuery) { - return resQuery -} - -func (app *NilApplication) InitChain(validators []*types.Validator) { -} - -func (app *NilApplication) BeginBlock(hash []byte, header *types.Header) { -} - -func (app *NilApplication) EndBlock(height uint64) types.ResponseEndBlock { - return types.ResponseEndBlock{} -} diff --git a/types/base_app.go b/types/base_app.go new file mode 100644 index 00000000..1d4f84b8 --- /dev/null +++ b/types/base_app.go @@ -0,0 +1,42 @@ +package types + +type BaseApplication struct { +} + +func NewBaseApplication() *BaseApplication { + return &BaseApplication{} +} + +func (app *BaseApplication) Info() (resInfo ResponseInfo) { + return +} + +func (app *BaseApplication) SetOption(key string, value string) (log string) { + return "" +} + +func (app *BaseApplication) DeliverTx(tx []byte) Result { + return NewResultOK(nil, "") +} + +func (app *BaseApplication) CheckTx(tx []byte) Result { + return NewResultOK(nil, "") +} + +func (app *BaseApplication) Commit() Result { + return NewResultOK([]byte("nil"), "") +} + +func (app *BaseApplication) Query(reqQuery RequestQuery) (resQuery ResponseQuery) { + return +} + +func (app *BaseApplication) InitChain(validators []*Validator) { +} + +func (app *BaseApplication) BeginBlock(hash []byte, header *Header) { +} + +func (app *BaseApplication) EndBlock(height uint64) (resEndBlock ResponseEndBlock) { + return +}