Skip to content

Commit

Permalink
draft required TransactionService impl
Browse files Browse the repository at this point in the history
  • Loading branch information
kocubinski committed May 8, 2024
1 parent b36b6cd commit 1becc15
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
15 changes: 8 additions & 7 deletions runtime/v2/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,14 @@ func ProvideEnvironment(logger log.Logger, config *runtimev2.Module, key depinje
memService := stf.NewMemoryStoreService([]byte(memStoreKey))

env := appmodulev2.Environment{
Logger: logger,
BranchService: nil, // TODO
EventService: stf.NewEventService(),
GasService: stf.NewGasMeterService(),
HeaderService: stf.HeaderService{},
KVStoreService: kvService,
MemStoreService: memService,
Logger: logger,
BranchService: nil, // TODO
EventService: stf.NewEventService(),
GasService: stf.NewGasMeterService(),
HeaderService: stf.HeaderService{},
KVStoreService: kvService,
MemStoreService: memService,
TransactionService: services.NewContextAwareTransactionService(),
}

return env, kvService, memService
Expand Down
23 changes: 23 additions & 0 deletions runtime/v2/services/transaction.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package services

import (
"context"

corecontext "cosmossdk.io/core/context"
"cosmossdk.io/core/transaction"
)

var _ transaction.Service = &ContextAwareTransactionService{}

// ContextAwareTransactionService implements the transaction.Service interface.
// It is used to retrieve the execution mode in the context.
type ContextAwareTransactionService struct{}

// ExecMode returns the execution mode stored in the context.
func (c ContextAwareTransactionService) ExecMode(ctx context.Context) transaction.ExecMode {
return ctx.Value(corecontext.ExecModeKey).(transaction.ExecMode)
}

func NewContextAwareTransactionService() transaction.Service {
return &ContextAwareTransactionService{}
}

0 comments on commit 1becc15

Please sign in to comment.