Add InitValidate method for setup

This commit is contained in:
Ethan Frey
2017-08-03 21:41:23 +02:00
parent 4b69f1d5ba
commit 37550ca91d
22 changed files with 164 additions and 39 deletions
+2 -1
View File
@@ -17,7 +17,8 @@ const (
// Signatures parses out go-crypto signatures and adds permissions to the
// context for use inside the application
type Signatures struct {
stack.PassOption
stack.PassInitState
stack.PassInitValidate
}
// Name of the module - fulfills Middleware interface
+2 -1
View File
@@ -13,7 +13,8 @@ const (
// Chain enforces that this tx was bound to the named chain
type Chain struct {
stack.PassOption
stack.PassInitState
stack.PassInitValidate
}
// Name of the module - fulfills Middleware interface
+10
View File
@@ -3,6 +3,7 @@ package base
import (
"time"
abci "github.com/tendermint/abci/types"
"github.com/tendermint/tmlibs/log"
"github.com/tendermint/basecoin"
@@ -70,6 +71,15 @@ func (Logger) InitState(l log.Logger, store state.SimpleDB, module, key, value s
return res, err
}
// InitValidate logs time and result - fulfills Middlware interface
func (Logger) InitValidate(l log.Logger, store state.SimpleDB, vals []*abci.Validator, next basecoin.InitValidater) {
start := time.Now()
next.InitValidate(l, store, vals)
delta := time.Now().Sub(start)
l = l.With("duration", micros(delta))
l.Info("InitValidate")
}
// micros returns how many microseconds passed in a call
func micros(d time.Duration) int {
return int(d.Seconds() * 1000000)
+1 -1
View File
@@ -18,7 +18,7 @@ package base
// // Multiplexer grabs a MultiTx and sends them sequentially down the line
// type Multiplexer struct {
// stack.PassOption
// stack.PassInitState
// }
// // Name of the module - fulfills Middleware interface
+3 -1
View File
@@ -16,7 +16,9 @@ import (
const NameCoin = "coin"
// Handler includes an accountant
type Handler struct{}
type Handler struct {
stack.PassInitValidate
}
var _ stack.Dispatchable = Handler{}
+2 -1
View File
@@ -24,7 +24,8 @@ type SimpleFeeMiddleware struct {
// all fees go here, which could be a dump (Bank) or something reachable
// by other app logic
Collector basecoin.Actor
stack.PassOption
stack.PassInitState
stack.PassInitValidate
}
var _ stack.Middleware = SimpleFeeMiddleware{}
+3 -1
View File
@@ -34,7 +34,9 @@ func AllowIBC(app string) basecoin.Actor {
}
// Handler updates the chain state or creates an ibc packet
type Handler struct{}
type Handler struct {
basecoin.NopInitValidate
}
var _ basecoin.Handler = Handler{}
+2 -1
View File
@@ -9,7 +9,8 @@ import (
// Middleware allows us to verify the IBC proof on a packet and
// and if valid, attach this permission to the wrapped packet
type Middleware struct {
stack.PassOption
stack.PassInitState
stack.PassInitValidate
}
var _ stack.Middleware = Middleware{}
+2 -1
View File
@@ -13,7 +13,8 @@ const (
// ReplayCheck uses the sequence to check for replay attacks
type ReplayCheck struct {
stack.PassOption
stack.PassInitState
stack.PassInitValidate
}
// Name of the module - fulfills Middleware interface
+2 -1
View File
@@ -11,7 +11,8 @@ const NameRole = "role"
// Handler allows us to create new roles
type Handler struct {
basecoin.NopOption
basecoin.NopInitState
basecoin.NopInitValidate
}
var _ basecoin.Handler = Handler{}
+2 -1
View File
@@ -9,7 +9,8 @@ import (
// Middleware allows us to add a requested role as a permission
// if the tx requests it and has sufficient authority
type Middleware struct {
stack.PassOption
stack.PassInitState
stack.PassInitValidate
}
var _ stack.Middleware = Middleware{}