Updated tx handling for eyes server
This commit is contained in:
parent
850796bad5
commit
f4b7a6ce40
|
@ -8,9 +8,11 @@ import (
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk"
|
sdk "github.com/cosmos/cosmos-sdk"
|
||||||
client "github.com/cosmos/cosmos-sdk/client/commands"
|
client "github.com/cosmos/cosmos-sdk/client/commands"
|
||||||
"github.com/cosmos/cosmos-sdk/modules/eyes"
|
eyesmod "github.com/cosmos/cosmos-sdk/modules/eyes"
|
||||||
"github.com/cosmos/cosmos-sdk/server/commands"
|
"github.com/cosmos/cosmos-sdk/server/commands"
|
||||||
"github.com/cosmos/cosmos-sdk/util"
|
"github.com/cosmos/cosmos-sdk/util"
|
||||||
|
|
||||||
|
"github.com/cosmos/cosmos-sdk/examples/eyes"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RootCmd is the entry point for this binary
|
// RootCmd is the entry point for this binary
|
||||||
|
@ -25,8 +27,11 @@ func BuildApp() sdk.Handler {
|
||||||
return sdk.ChainDecorators(
|
return sdk.ChainDecorators(
|
||||||
util.Logger{},
|
util.Logger{},
|
||||||
util.Recovery{},
|
util.Recovery{},
|
||||||
|
eyes.Parser{},
|
||||||
|
util.Chain{},
|
||||||
).WithHandler(
|
).WithHandler(
|
||||||
eyes.NewHandler())
|
eyesmod.NewHandler(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
package eyes
|
||||||
|
|
||||||
|
import sdk "github.com/cosmos/cosmos-sdk"
|
||||||
|
|
||||||
|
// Parser converts bytes into a tx struct
|
||||||
|
type Parser struct{}
|
||||||
|
|
||||||
|
var _ sdk.Decorator = Parser{}
|
||||||
|
|
||||||
|
// CheckTx makes sure we are on the proper chain
|
||||||
|
// - fulfills Decorator interface
|
||||||
|
func (c Parser) CheckTx(ctx sdk.Context, store sdk.SimpleDB,
|
||||||
|
txBytes interface{}, next sdk.Checker) (res sdk.CheckResult, err error) {
|
||||||
|
|
||||||
|
tx, err := LoadTx(txBytes.([]byte))
|
||||||
|
if err != nil {
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
return next.CheckTx(ctx, store, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeliverTx makes sure we are on the proper chain
|
||||||
|
// - fulfills Decorator interface
|
||||||
|
func (c Parser) DeliverTx(ctx sdk.Context, store sdk.SimpleDB,
|
||||||
|
txBytes interface{}, next sdk.Deliverer) (res sdk.DeliverResult, err error) {
|
||||||
|
|
||||||
|
tx, err := LoadTx(txBytes.([]byte))
|
||||||
|
if err != nil {
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
return next.DeliverTx(ctx, store, tx)
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
package eyes
|
||||||
|
|
||||||
|
import (
|
||||||
|
wire "github.com/tendermint/go-wire"
|
||||||
|
|
||||||
|
eyesmod "github.com/cosmos/cosmos-sdk/modules/eyes"
|
||||||
|
"github.com/cosmos/cosmos-sdk/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Tx is what is submitted to the chain.
|
||||||
|
// This embeds the tx data along with any info we want for
|
||||||
|
// decorators (just chain for now to demo)
|
||||||
|
type Tx struct {
|
||||||
|
Tx eyesmod.EyesTx `json:"tx"`
|
||||||
|
Chain util.ChainData `json:"chain"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetTx gets the tx info
|
||||||
|
func (e Tx) GetTx() interface{} {
|
||||||
|
return e.Tx
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetChain gets the chain we wish to perform the tx on
|
||||||
|
// (info for decorators)
|
||||||
|
func (e Tx) GetChain() util.ChainData {
|
||||||
|
return e.Chain
|
||||||
|
}
|
||||||
|
|
||||||
|
// LoadTx parses the input data into our blockchain tx structure
|
||||||
|
func LoadTx(data []byte) (tx Tx, err error) {
|
||||||
|
err = wire.ReadBinaryBytes(data, &tx)
|
||||||
|
return
|
||||||
|
}
|
Loading…
Reference in New Issue