Change ABCI app to implement abci.BlockchainAware interface

This commit is contained in:
Matt Bell 2017-02-04 14:47:36 -08:00
parent 5c9d63c6e0
commit 4ea03bc9dd
2 changed files with 17 additions and 19 deletions

View File

@ -1,7 +1,6 @@
package app package app
import ( import (
"fmt"
"strings" "strings"
abci "github.com/tendermint/abci/types" abci "github.com/tendermint/abci/types"
@ -42,7 +41,7 @@ func (app *Basecoin) GetState() *sm.State {
return app.state.CacheWrap() return app.state.CacheWrap()
} }
// TMSP::Info // ABCI::Info
func (app *Basecoin) Info() abci.ResponseInfo { func (app *Basecoin) Info() abci.ResponseInfo {
return abci.ResponseInfo{Data: Fmt("Basecoin v%v", version)} return abci.ResponseInfo{Data: Fmt("Basecoin v%v", version)}
} }
@ -51,7 +50,7 @@ func (app *Basecoin) RegisterPlugin(plugin types.Plugin) {
app.plugins.RegisterPlugin(plugin) app.plugins.RegisterPlugin(plugin)
} }
// TMSP::SetOption // ABCI::SetOption
func (app *Basecoin) SetOption(key string, value string) (log string) { func (app *Basecoin) SetOption(key string, value string) (log string) {
PluginName, key := splitKey(key) PluginName, key := splitKey(key)
if PluginName != PluginNameBase { if PluginName != PluginNameBase {
@ -81,7 +80,7 @@ func (app *Basecoin) SetOption(key string, value string) (log string) {
} }
} }
// TMSP::DeliverTx // ABCI::DeliverTx
func (app *Basecoin) DeliverTx(txBytes []byte) (res abci.Result) { func (app *Basecoin) DeliverTx(txBytes []byte) (res abci.Result) {
if len(txBytes) > maxTxSize { if len(txBytes) > maxTxSize {
return abci.ErrBaseEncodingError.AppendLog("Tx size exceeds maximum") return abci.ErrBaseEncodingError.AppendLog("Tx size exceeds maximum")
@ -102,14 +101,12 @@ func (app *Basecoin) DeliverTx(txBytes []byte) (res abci.Result) {
return res return res
} }
// TMSP::CheckTx // ABCI::CheckTx
func (app *Basecoin) CheckTx(txBytes []byte) (res abci.Result) { func (app *Basecoin) CheckTx(txBytes []byte) (res abci.Result) {
if len(txBytes) > maxTxSize { if len(txBytes) > maxTxSize {
return abci.ErrBaseEncodingError.AppendLog("Tx size exceeds maximum") return abci.ErrBaseEncodingError.AppendLog("Tx size exceeds maximum")
} }
fmt.Printf("%X\n", txBytes)
// Decode tx // Decode tx
var tx types.Tx var tx types.Tx
err := wire.ReadBinaryBytes(txBytes, &tx) err := wire.ReadBinaryBytes(txBytes, &tx)
@ -125,7 +122,7 @@ func (app *Basecoin) CheckTx(txBytes []byte) (res abci.Result) {
return abci.OK return abci.OK
} }
// TMSP::Query // ABCI::Query
func (app *Basecoin) Query(reqQuery abci.RequestQuery) (resQuery abci.ResponseQuery) { func (app *Basecoin) Query(reqQuery abci.RequestQuery) (resQuery abci.ResponseQuery) {
if len(reqQuery.Data) == 0 { if len(reqQuery.Data) == 0 {
resQuery.Log = "Query cannot be zero length" resQuery.Log = "Query cannot be zero length"
@ -142,7 +139,7 @@ func (app *Basecoin) Query(reqQuery abci.RequestQuery) (resQuery abci.ResponseQu
return return
} }
// TMSP::Commit // ABCI::Commit
func (app *Basecoin) Commit() (res abci.Result) { func (app *Basecoin) Commit() (res abci.Result) {
// Commit state // Commit state
@ -157,25 +154,25 @@ func (app *Basecoin) Commit() (res abci.Result) {
return res return res
} }
// TMSP::InitChain // ABCI::InitChain
func (app *Basecoin) InitChain(validators []*abci.Validator) { func (app *Basecoin) InitChain(validators []*abci.Validator) {
for _, plugin := range app.plugins.GetList() { for _, plugin := range app.plugins.GetList() {
plugin.InitChain(app.state, validators) plugin.InitChain(app.state, validators)
} }
} }
// TMSP::BeginBlock // ABCI::BeginBlock
func (app *Basecoin) BeginBlock(height uint64) { func (app *Basecoin) BeginBlock(hash []byte, header *abci.Header) {
for _, plugin := range app.plugins.GetList() { for _, plugin := range app.plugins.GetList() {
plugin.BeginBlock(app.state, height) plugin.BeginBlock(app.state, hash, header)
} }
} }
// TMSP::EndBlock // ABCI::EndBlock
func (app *Basecoin) EndBlock(height uint64) (diffs []*abci.Validator) { func (app *Basecoin) EndBlock(height uint64) (res abci.ResponseEndBlock) {
for _, plugin := range app.plugins.GetList() { for _, plugin := range app.plugins.GetList() {
moreDiffs := plugin.EndBlock(app.state, height) pluginRes := plugin.EndBlock(app.state, height)
diffs = append(diffs, moreDiffs...) res.Diffs = append(res.Diffs, pluginRes.Diffs...)
} }
return return
} }

View File

@ -2,6 +2,7 @@ package types
import ( import (
"fmt" "fmt"
abci "github.com/tendermint/abci/types" abci "github.com/tendermint/abci/types"
) )
@ -16,8 +17,8 @@ type Plugin interface {
// Other ABCI message handlers // Other ABCI message handlers
SetOption(store KVStore, key string, value string) (log string) SetOption(store KVStore, key string, value string) (log string)
InitChain(store KVStore, vals []*abci.Validator) InitChain(store KVStore, vals []*abci.Validator)
BeginBlock(store KVStore, height uint64) BeginBlock(store KVStore, hash []byte, header *abci.Header)
EndBlock(store KVStore, height uint64) []*abci.Validator EndBlock(store KVStore, height uint64) abci.ResponseEndBlock
} }
//---------------------------------------- //----------------------------------------