stack

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2017 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

nolint

nolint

Index

Constants

View Source
const (
	NameOK    = "ok"
	NameFail  = "fail"
	NamePanic = "panic"
	NameEcho  = "echo"
)

nolint

View Source
const (
	ByteRawTx   = 0xF0
	ByteCheckTx = 0xF1
	ByteFailTx  = 0xF2

	TypeRawTx   = NameOK + "/raw" // this will just say a-ok to RawTx
	TypeCheckTx = NameCheck + "/tx"
	TypeFailTx  = NameFail + "/tx"
)

nolint

View Source
const (
	NameCheck = "check"
	NameGrant = "grant"
)
View Source
const (
	NameCheckpoint = "check"
)

nolint

View Source
const (
	NameDispatcher = "disp"
)

nolint

View Source
const (
	NameRecovery = "rcvr"
)

nolint

Variables

This section is empty.

Functions

func MockContext

func MockContext(chain string, height uint64) sdk.Context

MockContext returns a simple, non-checking context for test cases.

Always use NewContext() for production code to sandbox malicious code better

func NewCheckTx

func NewCheckTx(req []sdk.Actor) sdk.Tx

nolint

func NewContext

func NewContext(chain string, height uint64, logger log.Logger) sdk.Context

NewContext - create a new secureContext

func NewFailTx

func NewFailTx() sdk.Tx

func NewRawTx

func NewRawTx(d []byte) sdk.Tx

nolint

func PrefixedKey

func PrefixedKey(app string, key []byte) []byte

PrefixedKey returns the absolute path to a given key in a particular app's state-space

This is useful for tests or utilities that have access to the global state to check individual app spaces. Individual apps should not be able to use this to read each other's space

func PrefixedStore

func PrefixedStore(app string, store state.SimpleDB) state.SimpleDB

PrefixedStore allows one to create an isolated state-space for a given app prefix, but it cannot easily be unwrapped

This is useful for tests or utilities that have access to the global state to check individual app spaces. Individual apps should not be able to use this to read each other's space

Types

type CheckHandler

type CheckHandler struct {
	sdk.NopInitState
	sdk.NopInitValidate
}

CheckHandler accepts CheckTx and verifies the permissions

func (CheckHandler) CheckTx

func (c CheckHandler) CheckTx(ctx sdk.Context, store state.SimpleDB, tx sdk.Tx) (res sdk.CheckResult, err error)

CheckTx verifies the permissions

func (CheckHandler) DeliverTx

func (c CheckHandler) DeliverTx(ctx sdk.Context, store state.SimpleDB, tx sdk.Tx) (res sdk.DeliverResult, err error)

DeliverTx verifies the permissions

func (CheckHandler) Name

func (CheckHandler) Name() string

Name - return handler's name

type CheckMiddleware

type CheckMiddleware struct {
	Required sdk.Actor
	PassInitState
	PassInitValidate
}

CheckMiddleware returns an error if the tx doesn't have auth of this Required Actor, otherwise passes along the call untouched

func (CheckMiddleware) CheckTx

func (p CheckMiddleware) CheckTx(ctx sdk.Context, store state.SimpleDB, tx sdk.Tx, next sdk.Checker) (res sdk.CheckResult, err error)

func (CheckMiddleware) DeliverTx

func (p CheckMiddleware) DeliverTx(ctx sdk.Context, store state.SimpleDB, tx sdk.Tx, next sdk.Deliver) (res sdk.DeliverResult, err error)

func (CheckMiddleware) Name

func (_ CheckMiddleware) Name() string

type CheckTx

type CheckTx struct {
	Required []sdk.Actor
}

CheckTx contains a list of permissions to be tested

func (CheckTx) ValidateBasic

func (CheckTx) ValidateBasic() error

func (CheckTx) Wrap

func (c CheckTx) Wrap() sdk.Tx

type CheckerMiddle

type CheckerMiddle interface {
	CheckTx(ctx sdk.Context, store state.SimpleDB,
		tx sdk.Tx, next sdk.Checker) (sdk.CheckResult, error)
}

type CheckerMiddleFunc

type CheckerMiddleFunc func(sdk.Context, state.SimpleDB,
	sdk.Tx, sdk.Checker) (sdk.CheckResult, error)

func (CheckerMiddleFunc) CheckTx

func (c CheckerMiddleFunc) CheckTx(ctx sdk.Context, store state.SimpleDB,
	tx sdk.Tx, next sdk.Checker) (sdk.CheckResult, error)

type Checkpoint

type Checkpoint struct {
	OnCheck   bool
	OnDeliver bool
	PassInitState
	PassInitValidate
}

Checkpoint isolates all data store below this

func (Checkpoint) CheckTx

func (c Checkpoint) CheckTx(ctx sdk.Context, store state.SimpleDB, tx sdk.Tx, next sdk.Checker) (res sdk.CheckResult, err error)

CheckTx reverts all data changes if there was an error

func (Checkpoint) DeliverTx

func (c Checkpoint) DeliverTx(ctx sdk.Context, store state.SimpleDB, tx sdk.Tx, next sdk.Deliver) (res sdk.DeliverResult, err error)

DeliverTx reverts all data changes if there was an error

func (Checkpoint) Name

func (Checkpoint) Name() string

Name of the module - fulfills Middleware interface

type DeliverMiddle

type DeliverMiddle interface {
	DeliverTx(ctx sdk.Context, store state.SimpleDB, tx sdk.Tx,
		next sdk.Deliver) (sdk.DeliverResult, error)
}

type DeliverMiddleFunc

type DeliverMiddleFunc func(sdk.Context, state.SimpleDB,
	sdk.Tx, sdk.Deliver) (sdk.DeliverResult, error)

func (DeliverMiddleFunc) DeliverTx

func (d DeliverMiddleFunc) DeliverTx(ctx sdk.Context, store state.SimpleDB,
	tx sdk.Tx, next sdk.Deliver) (sdk.DeliverResult, error)

type Dispatchable

type Dispatchable interface {
	Middleware
	AssertDispatcher()
}

Dispatchable is like middleware, except the meaning of "next" is different. Whereas in the middleware, it is the next handler that we should pass the same tx into, for dispatchers, it is a dispatcher, which it can use to

func WrapHandler

func WrapHandler(h sdk.Handler) Dispatchable

WrapHandler turns a sdk.Handler into a Dispatchable interface

type Dispatcher

type Dispatcher struct {
	// contains filtered or unexported fields
}

Dispatcher grabs a bunch of Dispatchables and groups them into one Handler.

It will route tx to the proper locations and also allows them to call each other synchronously through the same tx methods.

Please note that iterating through a map is a non-deteministic operation and, as such, should never be done in the context of an ABCI app. Only use this map to look up an exact route by name.

func NewDispatcher

func NewDispatcher(routes ...Dispatchable) *Dispatcher

NewDispatcher creates a dispatcher and adds the given routes. You can also add routes later with .AddRoutes()

func (*Dispatcher) AddRoutes

func (d *Dispatcher) AddRoutes(routes ...Dispatchable)

AddRoutes registers all these dispatchable choices under their subdomains

Panics on attempt to double-register a route name, as this is a configuration error. Should I retrun an error instead?

func (*Dispatcher) CheckTx

func (d *Dispatcher) CheckTx(ctx sdk.Context, store state.SimpleDB, tx sdk.Tx) (res sdk.CheckResult, err error)

CheckTx - implements Handler interface

Tries to find a registered module (Dispatchable) based on the name of the tx. The tx name (as registered with go-data) should be in the form `<module name>/XXXX`, where `module name` must match the name of a dispatchable and XXX can be any string.

func (*Dispatcher) DeliverTx

func (d *Dispatcher) DeliverTx(ctx sdk.Context, store state.SimpleDB, tx sdk.Tx) (res sdk.DeliverResult, err error)

DeliverTx - implements Handler interface

Tries to find a registered module (Dispatchable) based on the name of the tx. The tx name (as registered with go-data) should be in the form `<module name>/XXXX`, where `module name` must match the name of a dispatchable and XXX can be any string.

func (*Dispatcher) InitState

func (d *Dispatcher) InitState(l log.Logger, store state.SimpleDB, module, key, value string) (string, error)

InitState - implements Handler interface

Tries to find a registered module (Dispatchable) based on the module name from InitState of the tx.

func (*Dispatcher) InitValidate

func (d *Dispatcher) InitValidate(log log.Logger, store state.SimpleDB, vals []*abci.Validator)

InitValidate makes sure all modules are informed

func (*Dispatcher) Name

func (d *Dispatcher) Name() string

Name - defines the name of this module

type EchoHandler

type EchoHandler struct {
	sdk.NopInitState
	sdk.NopInitValidate
}

EchoHandler returns success, echoing res.Data = tx bytes

func (EchoHandler) CheckTx

func (EchoHandler) CheckTx(ctx sdk.Context, store state.SimpleDB, tx sdk.Tx) (res sdk.CheckResult, err error)

CheckTx always returns an empty success tx

func (EchoHandler) DeliverTx

func (EchoHandler) DeliverTx(ctx sdk.Context, store state.SimpleDB, tx sdk.Tx) (res sdk.DeliverResult, err error)

DeliverTx always returns an empty success tx

func (EchoHandler) Name

func (EchoHandler) Name() string

Name - return handler's name

type FailHandler

type FailHandler struct {
	Err error
	sdk.NopInitState
	sdk.NopInitValidate
}

FailHandler always returns an error

func (FailHandler) CheckTx

func (f FailHandler) CheckTx(ctx sdk.Context, store state.SimpleDB, tx sdk.Tx) (res sdk.CheckResult, err error)

CheckTx always returns the given error

func (FailHandler) DeliverTx

func (f FailHandler) DeliverTx(ctx sdk.Context, store state.SimpleDB, tx sdk.Tx) (res sdk.DeliverResult, err error)

DeliverTx always returns the given error

func (FailHandler) Name

func (FailHandler) Name() string

Name - return handler's name

type FailTx

type FailTx struct{}

FailTx just gets routed to filaure

func (FailTx) ValidateBasic

func (r FailTx) ValidateBasic() error

func (FailTx) Wrap

func (f FailTx) Wrap() sdk.Tx

type GrantMiddleware

type GrantMiddleware struct {
	Auth sdk.Actor
	PassInitState
	PassInitValidate
}

GrantMiddleware tries to set the permission to this Actor, which may be prohibited

func (GrantMiddleware) CheckTx

func (g GrantMiddleware) CheckTx(ctx sdk.Context, store state.SimpleDB, tx sdk.Tx, next sdk.Checker) (res sdk.CheckResult, err error)

func (GrantMiddleware) DeliverTx

func (g GrantMiddleware) DeliverTx(ctx sdk.Context, store state.SimpleDB, tx sdk.Tx, next sdk.Deliver) (res sdk.DeliverResult, err error)

func (GrantMiddleware) Name

func (_ GrantMiddleware) Name() string

type InitStaterMiddle

type InitStaterMiddle interface {
	InitState(l log.Logger, store state.SimpleDB, module,
		key, value string, next sdk.InitStater) (string, error)
}

type InitStaterMiddleFunc

type InitStaterMiddleFunc func(log.Logger, state.SimpleDB,
	string, string, string, sdk.InitStater) (string, error)

func (InitStaterMiddleFunc) InitState

func (c InitStaterMiddleFunc) InitState(l log.Logger, store state.SimpleDB,
	module, key, value string, next sdk.InitStater) (string, error)

type InitValidaterMiddle

type InitValidaterMiddle interface {
	InitValidate(l log.Logger, store state.SimpleDB, vals []*abci.Validator, next sdk.InitValidater)
}

type InitValidaterMiddleFunc

type InitValidaterMiddleFunc func(log.Logger, state.SimpleDB,
	[]*abci.Validator, sdk.InitValidater)

func (InitValidaterMiddleFunc) InitValidate

func (c InitValidaterMiddleFunc) InitValidate(l log.Logger, store state.SimpleDB,
	vals []*abci.Validator, next sdk.InitValidater)

type Middleware

Middleware is anything that wraps another handler to enhance functionality.

You can use utilities in handlers to construct them, the interfaces are exposed in the top-level package to avoid import loops.

type OKHandler

type OKHandler struct {
	Log string
	sdk.NopInitState
	sdk.NopInitValidate
}

OKHandler just used to return okay to everything

func (OKHandler) CheckTx

func (ok OKHandler) CheckTx(ctx sdk.Context, store state.SimpleDB, tx sdk.Tx) (res sdk.CheckResult, err error)

CheckTx always returns an empty success tx

func (OKHandler) DeliverTx

func (ok OKHandler) DeliverTx(ctx sdk.Context, store state.SimpleDB, tx sdk.Tx) (res sdk.DeliverResult, err error)

DeliverTx always returns an empty success tx

func (OKHandler) Name

func (OKHandler) Name() string

Name - return handler's name

type PanicHandler

type PanicHandler struct {
	Msg string
	Err error
	sdk.NopInitState
	sdk.NopInitValidate
}

PanicHandler always panics, using the given error (first choice) or msg (fallback)

func (PanicHandler) CheckTx

func (p PanicHandler) CheckTx(ctx sdk.Context, store state.SimpleDB, tx sdk.Tx) (res sdk.CheckResult, err error)

CheckTx always panics

func (PanicHandler) DeliverTx

func (p PanicHandler) DeliverTx(ctx sdk.Context, store state.SimpleDB, tx sdk.Tx) (res sdk.DeliverResult, err error)

DeliverTx always panics

func (PanicHandler) Name

func (PanicHandler) Name() string

Name - return handler's name

type PassCheck

type PassCheck struct{}

holders

func (PassCheck) CheckTx

func (_ PassCheck) CheckTx(ctx sdk.Context, store state.SimpleDB,
	tx sdk.Tx, next sdk.Checker) (sdk.CheckResult, error)

type PassDeliver

type PassDeliver struct{}

func (PassDeliver) DeliverTx

func (_ PassDeliver) DeliverTx(ctx sdk.Context, store state.SimpleDB,
	tx sdk.Tx, next sdk.Deliver) (sdk.DeliverResult, error)

type PassInitState

type PassInitState struct{}

func (PassInitState) InitState

func (_ PassInitState) InitState(l log.Logger, store state.SimpleDB, module,
	key, value string, next sdk.InitStater) (string, error)

type PassInitValidate

type PassInitValidate struct{}

func (PassInitValidate) InitValidate

func (_ PassInitValidate) InitValidate(l log.Logger, store state.SimpleDB,
	vals []*abci.Validator, next sdk.InitValidater)

type RawTx

type RawTx struct {
	data.Bytes
}

RawTx just contains bytes that can be hex-ified

func (RawTx) ValidateBasic

func (r RawTx) ValidateBasic() error

func (RawTx) Wrap

func (r RawTx) Wrap() sdk.Tx

type Recovery

type Recovery struct{}

Recovery catches any panics and returns them as errors instead

func (Recovery) CheckTx

func (Recovery) CheckTx(ctx sdk.Context, store state.SimpleDB, tx sdk.Tx, next sdk.Checker) (res sdk.CheckResult, err error)

CheckTx catches any panic and converts to error - fulfills Middlware interface

func (Recovery) DeliverTx

func (Recovery) DeliverTx(ctx sdk.Context, store state.SimpleDB, tx sdk.Tx, next sdk.Deliver) (res sdk.DeliverResult, err error)

DeliverTx catches any panic and converts to error - fulfills Middlware interface

func (Recovery) InitState

func (Recovery) InitState(l log.Logger, store state.SimpleDB, module, key, value string, next sdk.InitStater) (log string, err error)

InitState catches any panic and converts to error - fulfills Middlware interface

func (Recovery) InitValidate

func (Recovery) InitValidate(l log.Logger, store state.SimpleDB,
	vals []*abci.Validator, next sdk.InitValidater)

InitValidate catches any panic and logs it TODO: return an error???

func (Recovery) Name

func (Recovery) Name() string

Name of the module - fulfills Middleware interface

type Stack

type Stack struct {
	sdk.Handler // the compiled version, which we expose
	// contains filtered or unexported fields
}

Stack is the entire application stack

func New

func New(middlewares ...Middleware) *Stack

New prepares a middleware stack, you must `.Use()` a Handler before you can execute it.

func (*Stack) Apps

func (s *Stack) Apps(middlewares ...Middleware) *Stack

Apps adds the following Middlewares as typical application middleware to the stack (limit permission to one app)

func (*Stack) Dispatch

func (s *Stack) Dispatch(routes ...Dispatchable) *Stack

Dispatch is like Use, but a convenience method to construct a dispatcher with a set of modules to route.

func (*Stack) IBC

func (s *Stack) IBC(m Middleware) *Stack

IBC add the following middleware with permission to add cross-chain permissions

func (*Stack) Use

func (s *Stack) Use(handler sdk.Handler) *Stack

Use sets the final handler for the stack and prepares it for use

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL