Skip to content

Commit

Permalink
TMSP -> ABCI
Browse files Browse the repository at this point in the history
  • Loading branch information
jaekwon committed Jan 15, 2017
1 parent 8a6e409 commit 6cb9549
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 106 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.swp
vendor
36 changes: 18 additions & 18 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package app
import (
"strings"

abci "github.com/tendermint/abci/types"
sm "github.com/tendermint/basecoin/state"
"github.com/tendermint/basecoin/types"
. "github.com/tendermint/go-common"
"github.com/tendermint/go-wire"
eyes "github.com/tendermint/merkleeyes/client"
tmsp "github.com/tendermint/tmsp/types"
)

const (
Expand Down Expand Up @@ -37,8 +37,8 @@ func NewBasecoin(eyesCli *eyes.Client) *Basecoin {
}

// TMSP::Info
func (app *Basecoin) Info() string {
return Fmt("Basecoin v%v", version)
func (app *Basecoin) Info() abci.ResponseInfo {
return abci.ResponseInfo{Data: Fmt("Basecoin v%v", version)}
}

func (app *Basecoin) RegisterPlugin(name string, plugin types.Plugin) {
Expand Down Expand Up @@ -75,59 +75,59 @@ func (app *Basecoin) SetOption(key string, value string) (log string) {
}
}

// TMSP::AppendTx
func (app *Basecoin) AppendTx(txBytes []byte) (res tmsp.Result) {
// TMSP::DeliverTx
func (app *Basecoin) DeliverTx(txBytes []byte) (res abci.Result) {
if len(txBytes) > maxTxSize {
return tmsp.ErrBaseEncodingError.AppendLog("Tx size exceeds maximum")
return abci.ErrBaseEncodingError.AppendLog("Tx size exceeds maximum")
}

// Decode tx
var tx types.Tx
err := wire.ReadBinaryBytes(txBytes, &tx)
if err != nil {
return tmsp.ErrBaseEncodingError.AppendLog("Error decoding tx: " + err.Error())
return abci.ErrBaseEncodingError.AppendLog("Error decoding tx: " + err.Error())
}

// Validate and exec tx
res = sm.ExecTx(app.state, app.plugins, tx, false, nil)
if res.IsErr() {
return res.PrependLog("Error in AppendTx")
return res.PrependLog("Error in DeliverTx")
}
return tmsp.OK
return abci.OK
}

// TMSP::CheckTx
func (app *Basecoin) CheckTx(txBytes []byte) (res tmsp.Result) {
func (app *Basecoin) CheckTx(txBytes []byte) (res abci.Result) {
if len(txBytes) > maxTxSize {
return tmsp.ErrBaseEncodingError.AppendLog("Tx size exceeds maximum")
return abci.ErrBaseEncodingError.AppendLog("Tx size exceeds maximum")
}

// Decode tx
var tx types.Tx
err := wire.ReadBinaryBytes(txBytes, &tx)
if err != nil {
return tmsp.ErrBaseEncodingError.AppendLog("Error decoding tx: " + err.Error())
return abci.ErrBaseEncodingError.AppendLog("Error decoding tx: " + err.Error())
}

// Validate tx
res = sm.ExecTx(app.cacheState, app.plugins, tx, true, nil)
if res.IsErr() {
return res.PrependLog("Error in CheckTx")
}
return tmsp.OK
return abci.OK
}

// TMSP::Query
func (app *Basecoin) Query(query []byte) (res tmsp.Result) {
func (app *Basecoin) Query(query []byte) (res abci.Result) {
if len(query) == 0 {
return tmsp.ErrEncodingError.SetLog("Query cannot be zero length")
return abci.ErrEncodingError.SetLog("Query cannot be zero length")
}

return app.eyesCli.QuerySync(query)
}

// TMSP::Commit
func (app *Basecoin) Commit() (res tmsp.Result) {
func (app *Basecoin) Commit() (res abci.Result) {

// Commit state
res = app.state.Commit()
Expand All @@ -142,7 +142,7 @@ func (app *Basecoin) Commit() (res tmsp.Result) {
}

// TMSP::InitChain
func (app *Basecoin) InitChain(validators []*tmsp.Validator) {
func (app *Basecoin) InitChain(validators []*abci.Validator) {
for _, plugin := range app.plugins.GetList() {
plugin.Plugin.InitChain(app.state, validators)
}
Expand All @@ -156,7 +156,7 @@ func (app *Basecoin) BeginBlock(height uint64) {
}

// TMSP::EndBlock
func (app *Basecoin) EndBlock(height uint64) (diffs []*tmsp.Validator) {
func (app *Basecoin) EndBlock(height uint64) (diffs []*abci.Validator) {
for _, plugin := range app.plugins.GetList() {
moreDiffs := plugin.Plugin.EndBlock(app.state, height)
diffs = append(diffs, moreDiffs...)
Expand Down
10 changes: 5 additions & 5 deletions app/tmsp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestSendTx(t *testing.T) {

// Write request
txBytes := wire.BinaryBytes(struct{ types.Tx }{tx})
res = bcApp.AppendTx(txBytes)
res = bcApp.DeliverTx(txBytes)
t.Log(res)
if res.IsErr() {
t.Errorf(Fmt("Failed: %v", res.Error()))
Expand Down Expand Up @@ -111,9 +111,9 @@ func TestSequence(t *testing.T) {

// Write request
txBytes := wire.BinaryBytes(struct{ types.Tx }{tx})
res := bcApp.AppendTx(txBytes)
res := bcApp.DeliverTx(txBytes)
if res.IsErr() {
t.Errorf("AppendTx error: " + res.Error())
t.Errorf("DeliverTx error: " + res.Error())
}

}
Expand Down Expand Up @@ -160,9 +160,9 @@ func TestSequence(t *testing.T) {

// Write request
txBytes := wire.BinaryBytes(struct{ types.Tx }{tx})
res := bcApp.AppendTx(txBytes)
res := bcApp.DeliverTx(txBytes)
if res.IsErr() {
t.Errorf("AppendTx error: " + res.Error())
t.Errorf("DeliverTx error: " + res.Error())
}
}
}
2 changes: 1 addition & 1 deletion cmd/basecoin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"fmt"
"reflect"

"github.com/tendermint/abci/server"
"github.com/tendermint/basecoin/app"
. "github.com/tendermint/go-common"
eyes "github.com/tendermint/merkleeyes/client"
"github.com/tendermint/tmsp/server"
)

func main() {
Expand Down
37 changes: 17 additions & 20 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,30 @@ import:
- package: github.com/gorilla/websocket
version: v1.1.0
- package: github.com/tendermint/go-common
version: develop
- package: github.com/tendermint/go-crypto
version: develop
- package: github.com/tendermint/go-events
version: develop
- package: github.com/tendermint/go-logger
version: develop
- package: github.com/tendermint/go-rpc
version: develop
subpackages:
- client
- types
- package: github.com/tendermint/go-wire
- package: github.com/tendermint/governmint
subpackages:
- gov
- types
version: develop
- package: github.com/tendermint/merkleeyes
version: develop
subpackages:
- client
- package: github.com/tendermint/tendermint
version: ~0.7.4
version: develop
subpackages:
- rpc/core/types
- package: github.com/tendermint/tmsp
- package: github.com/tendermint/abci
version: develop
subpackages:
- server
- types
16 changes: 8 additions & 8 deletions plugins/vote/vote.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package vote

import (
abci "github.com/tendermint/abci/types"
"github.com/tendermint/basecoin/types"
"github.com/tendermint/go-wire"
tmsp "github.com/tendermint/tmsp/types"
)

type Vote struct {
Expand Down Expand Up @@ -35,13 +35,13 @@ func (app Vote) SetOption(store types.KVStore, key string, value string) (log st
}

//because no coins are being exchanged ctx is unused
func (app Vote) RunTx(store types.KVStore, ctx types.CallContext, txBytes []byte) (res tmsp.Result) {
func (app Vote) RunTx(store types.KVStore, ctx types.CallContext, txBytes []byte) (res abci.Result) {

// Decode tx
var tx Tx
err := wire.ReadBinaryBytes(txBytes, &tx)
if err != nil {
return tmsp.ErrBaseEncodingError.AppendLog("Error decoding tx: " + err.Error())
return abci.ErrBaseEncodingError.AppendLog("Error decoding tx: " + err.Error())
}

//Read the ballotBox from the store
Expand All @@ -52,7 +52,7 @@ func (app Vote) RunTx(store types.KVStore, ctx types.CallContext, txBytes []byte
if kvBytes != nil {
err := wire.ReadBinaryBytes(kvBytes, &tempBB)
if err != nil {
return tmsp.ErrBaseEncodingError.AppendLog("Error decoding BallotBox: " + err.Error())
return abci.ErrBaseEncodingError.AppendLog("Error decoding BallotBox: " + err.Error())
}
} else {

Expand All @@ -76,17 +76,17 @@ func (app Vote) RunTx(store types.KVStore, ctx types.CallContext, txBytes []byte
issueBytes := wire.BinaryBytes(struct{ ballotBox }{tempBB})
store.Set([]byte(app.bb.issue), issueBytes)

return tmsp.OK
return abci.OK
}

//unused
func (app Vote) InitChain(store types.KVStore, vals []*tmsp.Validator) {
func (app Vote) InitChain(store types.KVStore, vals []*abci.Validator) {
}

func (app Vote) BeginBlock(store types.KVStore, height uint64) {
}

func (app Vote) EndBlock(store types.KVStore, height uint64) []*tmsp.Validator {
var diffs []*tmsp.Validator
func (app Vote) EndBlock(store types.KVStore, height uint64) []*abci.Validator {
var diffs []*abci.Validator
return diffs
}
2 changes: 1 addition & 1 deletion plugins/vote/vote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestVote(t *testing.T) {

// Write request
txBytes := wire.BinaryBytes(struct{ types.Tx }{tx})
res = bcApp.AppendTx(txBytes)
res = bcApp.DeliverTx(txBytes)
fmt.Println(res)

if res.IsOK() {
Expand Down
Loading

0 comments on commit 6cb9549

Please sign in to comment.