-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
middleware.go
71 lines (60 loc) · 2.13 KB
/
middleware.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package tx
import (
context "context"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
abci "github.com/tendermint/tendermint/abci/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// RequestSimulateTx is the request type for the tx.Handler.RequestSimulateTx
// method.
type RequestSimulateTx struct {
TxBytes []byte
}
// ResponseSimulateTx is the response type for the tx.Handler.RequestSimulateTx
// method.
type ResponseSimulateTx struct {
GasInfo sdk.GasInfo
Result *sdk.Result
}
// Request is the tx request type used in middlewares.
// At least one of Tx or TxBytes must be set. If only TxBytes is set, then
// Tx will be populated by the TxDecoderMiddleware. If only Tx is set, then
// some middlewares (such as signature verification) will fail.
//
// In practice, the middleware stack is called from {Check,Deliver}Tx, which
// only passes the TxBytes. Then, the TxDecoderMiddleware decodes the bytes
// into the Tx field.
type Request struct {
Tx sdk.Tx
TxBytes []byte
}
// Response is the tx response type used in middlewares.
type Response struct {
GasWanted uint64
GasUsed uint64
// MsgResponses is an array containing each Msg service handler's response
// type, packed in an Any. This will get proto-serialized into the `Data` field
// in the ABCI Check/DeliverTx responses.
MsgResponses []*codectypes.Any
Log string
Events []abci.Event
}
// RequestCheckTx is the additional request type used in middlewares CheckTx
// method.
type RequestCheckTx struct {
Type abci.CheckTxType
}
// RequestCheckTx is the additional response type used in middlewares CheckTx
// method.
type ResponseCheckTx struct {
Priority int64
}
// TxHandler defines the baseapp's CheckTx, DeliverTx and Simulate respective
// handlers. It is designed as a middleware stack.
type Handler interface {
CheckTx(ctx context.Context, req Request, checkReq RequestCheckTx) (Response, ResponseCheckTx, error)
DeliverTx(ctx context.Context, req Request) (Response, error)
SimulateTx(ctx context.Context, req Request) (Response, error)
}
// TxMiddleware defines one layer of the TxHandler middleware stack.
type Middleware func(Handler) Handler