Make it all compile with new Deliver/CheckTx

This commit is contained in:
Ethan Frey
2017-08-03 21:41:23 +02:00
parent cb4277f4b7
commit cbfd2cd611
22 changed files with 193 additions and 167 deletions
+2 -2
View File
@@ -24,7 +24,7 @@ func (Chain) Name() string {
var _ stack.Middleware = Chain{}
// CheckTx makes sure we are on the proper chain - fulfills Middlware interface
func (c Chain) CheckTx(ctx basecoin.Context, store state.SimpleDB, tx basecoin.Tx, next basecoin.Checker) (res basecoin.Result, err error) {
func (c Chain) CheckTx(ctx basecoin.Context, store state.SimpleDB, tx basecoin.Tx, next basecoin.Checker) (res basecoin.CheckResult, err error) {
stx, err := c.checkChainTx(ctx.ChainID(), ctx.BlockHeight(), tx)
if err != nil {
return res, err
@@ -33,7 +33,7 @@ func (c Chain) CheckTx(ctx basecoin.Context, store state.SimpleDB, tx basecoin.T
}
// DeliverTx makes sure we are on the proper chain - fulfills Middlware interface
func (c Chain) DeliverTx(ctx basecoin.Context, store state.SimpleDB, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) {
func (c Chain) DeliverTx(ctx basecoin.Context, store state.SimpleDB, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.DeliverResult, err error) {
stx, err := c.checkChainTx(ctx.ChainID(), ctx.BlockHeight(), tx)
if err != nil {
return res, err
+2 -2
View File
@@ -26,7 +26,7 @@ func (Logger) Name() string {
var _ stack.Middleware = Logger{}
// CheckTx logs time and result - fulfills Middlware interface
func (Logger) CheckTx(ctx basecoin.Context, store state.SimpleDB, tx basecoin.Tx, next basecoin.Checker) (res basecoin.Result, err error) {
func (Logger) CheckTx(ctx basecoin.Context, store state.SimpleDB, tx basecoin.Tx, next basecoin.Checker) (res basecoin.CheckResult, err error) {
start := time.Now()
res, err = next.CheckTx(ctx, store, tx)
delta := time.Now().Sub(start)
@@ -41,7 +41,7 @@ func (Logger) CheckTx(ctx basecoin.Context, store state.SimpleDB, tx basecoin.Tx
}
// DeliverTx logs time and result - fulfills Middlware interface
func (Logger) DeliverTx(ctx basecoin.Context, store state.SimpleDB, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) {
func (Logger) DeliverTx(ctx basecoin.Context, store state.SimpleDB, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.DeliverResult, err error) {
start := time.Now()
res, err = next.DeliverTx(ctx, store, tx)
delta := time.Now().Sub(start)
+61 -61
View File
@@ -1,73 +1,73 @@
package base
import (
"strings"
// import (
// "strings"
wire "github.com/tendermint/go-wire"
"github.com/tendermint/go-wire/data"
// wire "github.com/tendermint/go-wire"
// "github.com/tendermint/go-wire/data"
"github.com/tendermint/basecoin"
"github.com/tendermint/basecoin/stack"
"github.com/tendermint/basecoin/state"
)
// "github.com/tendermint/basecoin"
// "github.com/tendermint/basecoin/stack"
// "github.com/tendermint/basecoin/state"
// )
//nolint
const (
NameMultiplexer = "mplx"
)
// //nolint
// const (
// NameMultiplexer = "mplx"
// )
// Multiplexer grabs a MultiTx and sends them sequentially down the line
type Multiplexer struct {
stack.PassOption
}
// // Multiplexer grabs a MultiTx and sends them sequentially down the line
// type Multiplexer struct {
// stack.PassOption
// }
// Name of the module - fulfills Middleware interface
func (Multiplexer) Name() string {
return NameMultiplexer
}
// // Name of the module - fulfills Middleware interface
// func (Multiplexer) Name() string {
// return NameMultiplexer
// }
var _ stack.Middleware = Multiplexer{}
// var _ stack.Middleware = Multiplexer{}
// CheckTx splits the input tx and checks them all - fulfills Middlware interface
func (Multiplexer) CheckTx(ctx basecoin.Context, store state.SimpleDB, tx basecoin.Tx, next basecoin.Checker) (res basecoin.Result, err error) {
if mtx, ok := tx.Unwrap().(*MultiTx); ok {
return runAll(ctx, store, mtx.Txs, next.CheckTx)
}
return next.CheckTx(ctx, store, tx)
}
// // CheckTx splits the input tx and checks them all - fulfills Middlware interface
// func (Multiplexer) CheckTx(ctx basecoin.Context, store state.SimpleDB, tx basecoin.Tx, next basecoin.Checker) (res basecoin.CheckResult, err error) {
// if mtx, ok := tx.Unwrap().(*MultiTx); ok {
// return runAll(ctx, store, mtx.Txs, next.CheckTx)
// }
// return next.CheckTx(ctx, store, tx)
// }
// DeliverTx splits the input tx and checks them all - fulfills Middlware interface
func (Multiplexer) DeliverTx(ctx basecoin.Context, store state.SimpleDB, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) {
if mtx, ok := tx.Unwrap().(*MultiTx); ok {
return runAll(ctx, store, mtx.Txs, next.DeliverTx)
}
return next.DeliverTx(ctx, store, tx)
}
// // DeliverTx splits the input tx and checks them all - fulfills Middlware interface
// func (Multiplexer) DeliverTx(ctx basecoin.Context, store state.SimpleDB, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.DeliverResult, err error) {
// if mtx, ok := tx.Unwrap().(*MultiTx); ok {
// return runAll(ctx, store, mtx.Txs, next.DeliverTx)
// }
// return next.DeliverTx(ctx, store, tx)
// }
func runAll(ctx basecoin.Context, store state.SimpleDB, txs []basecoin.Tx, next basecoin.CheckerFunc) (res basecoin.Result, err error) {
// store all results, unless anything errors
rs := make([]basecoin.Result, len(txs))
for i, stx := range txs {
rs[i], err = next(ctx, store, stx)
if err != nil {
return
}
}
// now combine the results into one...
return combine(rs), nil
}
// func runAll(ctx basecoin.Context, store state.SimpleDB, txs []basecoin.Tx, next basecoin.CheckerFunc) (res basecoin.Result, err error) {
// // store all results, unless anything errors
// rs := make([]basecoin.Result, len(txs))
// for i, stx := range txs {
// rs[i], err = next(ctx, store, stx)
// if err != nil {
// return
// }
// }
// // now combine the results into one...
// return combine(rs), nil
// }
// combines all data bytes as a go-wire array.
// joins all log messages with \n
func combine(all []basecoin.Result) basecoin.Result {
datas := make([]data.Bytes, len(all))
logs := make([]string, len(all))
for i, r := range all {
datas[i] = r.Data
logs[i] = r.Log
}
return basecoin.Result{
Data: wire.BinaryBytes(datas),
Log: strings.Join(logs, "\n"),
}
}
// // combines all data bytes as a go-wire array.
// // joins all log messages with \n
// func combine(all []basecoin.Result) basecoin.Result {
// datas := make([]data.Bytes, len(all))
// logs := make([]string, len(all))
// for i, r := range all {
// datas[i] = r.Data
// logs[i] = r.Log
// }
// return basecoin.Result{
// Data: wire.BinaryBytes(datas),
// Log: strings.Join(logs, "\n"),
// }
// }
+2 -2
View File
@@ -16,13 +16,13 @@ const (
//nolint
const (
TypeMultiTx = NameMultiplexer + "/tx"
// TypeMultiTx = NameMultiplexer + "/tx"
TypeChainTx = NameChain + "/tx"
)
func init() {
basecoin.TxMapper.
RegisterImplementation(MultiTx{}, TypeMultiTx, ByteMultiTx).
// RegisterImplementation(MultiTx{}, TypeMultiTx, ByteMultiTx).
RegisterImplementation(ChainTx{}, TypeChainTx, ByteChainTx)
}