-
Notifications
You must be signed in to change notification settings - Fork 73
/
aspect_context.go
37 lines (29 loc) · 1.13 KB
/
aspect_context.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
package evm
import (
"errors"
"github.com/cosmos/cosmos-sdk/baseapp"
cosmos "github.com/cosmos/cosmos-sdk/types"
"github.com/artela-network/artela/app/interfaces"
"github.com/artela-network/artela/x/evm/artela/types"
)
// CreateAspectRuntimeContextDecorator prepare the aspect runtime context
type AspectRuntimeContextDecorator struct {
evmKeeper interfaces.EVMKeeper
app *baseapp.BaseApp
}
// NewAspectRuntimeContextDecorator creates a new AspectRuntimeContextDecorator
func NewAspectRuntimeContextDecorator(app *baseapp.BaseApp, ek interfaces.EVMKeeper) AspectRuntimeContextDecorator {
return AspectRuntimeContextDecorator{
evmKeeper: ek,
app: app,
}
}
func (aspd AspectRuntimeContextDecorator) PostHandle(ctx cosmos.Context, tx cosmos.Tx, simulate, success bool, next cosmos.PostHandler) (newCtx cosmos.Context, err error) {
// Aspect Runtime Context Lifecycle: destory AspectRuntimeContext
aspectCtx, ok := ctx.Value(types.AspectContextKey).(*types.AspectRuntimeContext)
if !ok {
return ctx, errors.New("EthereumTx: unwrap AspectRuntimeContext failed")
}
aspectCtx.Destroy()
return next(ctx, tx, simulate, success)
}