Browse Source

BaseApplication

pull/1780/head
Ethan Buchman 8 years ago
parent
commit
e909cafa0b
6 changed files with 52 additions and 99 deletions
  1. +2
    -24
      example/block_aware/block_aware_app.go
  2. +2
    -10
      example/counter/counter.go
  3. +2
    -14
      example/dummy/dummy.go
  4. +4
    -5
      example/example_test.go
  5. +0
    -46
      example/nil/nil_app.go
  6. +42
    -0
      types/base_app.go

+ 2
- 24
example/block_aware/block_aware_app.go View File

@ -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
}

+ 2
- 10
example/counter/counter.go View File

@ -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{}
}

+ 2
- 14
example/dummy/dummy.go View File

@ -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{}
}

+ 4
- 5
example/example_test.go View File

@ -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) {


+ 0
- 46
example/nil/nil_app.go View File

@ -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{}
}

+ 42
- 0
types/base_app.go View File

@ -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
}

Loading…
Cancel
Save