refactor!(core): add in environment bundler of service (#19041)
Co-authored-by: Facundo <facundomedica@gmail.com>
This commit is contained in:
@@ -40,12 +40,14 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
* [#18379](https://github.com/cosmos/cosmos-sdk/pull/18379) Add branch service.
|
||||
* [#18457](https://github.com/cosmos/cosmos-sdk/pull/18457) Add branch.ExecuteWithGasLimit.
|
||||
* [#19041](https://github.com/cosmos/cosmos-sdk/pull/19041) Add `appmodule.Environment` interface to fetch different services
|
||||
|
||||
### API Breaking
|
||||
|
||||
* [#18857](https://github.com/cosmos/cosmos-sdk/pull/18857) Moved `FormatCoins` to `x/tx`.
|
||||
* [#18861](httpes://github.com/cosmos/cosmos-sdk/pull/18861) Moved `coin.ParseCoin` to `client/v2/internal`.
|
||||
* [#18866](https://github.com/cosmos/cosmos-sdk/pull/18866) All items related to depinject have been moved to `cosmossdk.io/depinject` (`Provide`, `Invoke`, `Register`)
|
||||
* [#19041](https://github.com/cosmos/cosmos-sdk/pull/19041) `HasEventListeners` was removed from appmodule due to the fact that it was not used anywhere in the SDK nor implemented
|
||||
|
||||
## [v0.12.0](https://github.com/cosmos/cosmos-sdk/releases/tag/core%2Fv0.12.0)
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package appmodule
|
||||
|
||||
import (
|
||||
"cosmossdk.io/core/branch"
|
||||
"cosmossdk.io/core/event"
|
||||
"cosmossdk.io/core/gas"
|
||||
"cosmossdk.io/core/header"
|
||||
"cosmossdk.io/core/store"
|
||||
)
|
||||
|
||||
// Environment is used to get all services to their respective module
|
||||
type Environment struct {
|
||||
BranchService branch.Service
|
||||
EventService event.Service
|
||||
GasService gas.Service
|
||||
HeaderService header.Service
|
||||
KVStoreService store.KVStoreService
|
||||
MemStoreService store.MemoryStoreService
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package appmodule
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"google.golang.org/protobuf/runtime/protoiface"
|
||||
)
|
||||
|
||||
// HasEventListeners is the extension interface that modules should implement to register
|
||||
// event listeners.
|
||||
type HasEventListeners interface {
|
||||
AppModule
|
||||
|
||||
// RegisterEventListeners registers the module's events listeners.
|
||||
RegisterEventListeners(registrar *EventListenerRegistrar)
|
||||
}
|
||||
|
||||
// EventListenerRegistrar allows registering event listeners.
|
||||
type EventListenerRegistrar struct {
|
||||
listeners []any
|
||||
}
|
||||
|
||||
// GetListeners gets the event listeners that have been registered
|
||||
func (e *EventListenerRegistrar) GetListeners() []any {
|
||||
return e.listeners
|
||||
}
|
||||
|
||||
// RegisterEventListener registers an event listener for event type E. If a non-nil error is returned by the listener,
|
||||
// it will cause the process which emitted the event to fail.
|
||||
func RegisterEventListener[E protoiface.MessageV1](registrar *EventListenerRegistrar, listener func(context.Context, E) error) {
|
||||
registrar.listeners = append(registrar.listeners, listener)
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package appmodule
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
)
|
||||
|
||||
func TestEventListenerRegistrar(t *testing.T) {
|
||||
registrar := &EventListenerRegistrar{}
|
||||
RegisterEventListener(registrar, func(ctx context.Context, dummy *timestamppb.Timestamp) error { return nil })
|
||||
require.Len(t, registrar.listeners, 1)
|
||||
require.Equal(t, reflect.Func, reflect.TypeOf(registrar.listeners[0]).Kind())
|
||||
}
|
||||
@@ -21,23 +21,27 @@ type Manager interface {
|
||||
// Callers SHOULD assume that these events may be included in consensus. These events
|
||||
// MUST be emitted deterministically and adding, removing or changing these events SHOULD
|
||||
// be considered state-machine breaking.
|
||||
Emit(ctx context.Context, event protoiface.MessageV1) error
|
||||
Emit(event protoiface.MessageV1) error
|
||||
|
||||
// EmitKV emits an event based on an event and kv-pair attributes.
|
||||
//
|
||||
// These events will not be part of consensus and adding, removing or changing these events is
|
||||
// not a state-machine breaking change.
|
||||
EmitKV(ctx context.Context, eventType string, attrs ...Attribute) error
|
||||
EmitKV(eventType string, attrs ...Attribute) error
|
||||
|
||||
// EmitNonConsensus emits events represented as a protobuf message (as described in ADR 032), without
|
||||
// including it in blockchain consensus.
|
||||
//
|
||||
// These events will not be part of consensus and adding, removing or changing events is
|
||||
// not a state-machine breaking change.
|
||||
EmitNonConsensus(ctx context.Context, event protoiface.MessageV1) error
|
||||
EmitNonConsensus(event protoiface.MessageV1) error
|
||||
}
|
||||
|
||||
// KVEventAttribute is a kv-pair event attribute.
|
||||
type Attribute struct {
|
||||
Key, Value string
|
||||
}
|
||||
|
||||
func NewAttribute(key, value string) Attribute {
|
||||
return Attribute{Key: key, Value: value}
|
||||
}
|
||||
|
||||
+4
-9
@@ -26,15 +26,10 @@ type Service interface {
|
||||
WithBlockGasMeter(ctx context.Context, meter Meter) context.Context
|
||||
}
|
||||
|
||||
// Meter represents a gas meter.
|
||||
// Meter represents a gas meter for modules consumption
|
||||
type Meter interface {
|
||||
GasConsumed() Gas
|
||||
GasConsumedToLimit() Gas
|
||||
GasRemaining() Gas
|
||||
Consume(amount Gas, descriptor string)
|
||||
Refund(amount Gas, descriptor string)
|
||||
Remaining() Gas
|
||||
Limit() Gas
|
||||
ConsumeGas(amount Gas, descriptor string)
|
||||
RefundGas(amount Gas, descriptor string)
|
||||
IsPastLimit() bool
|
||||
IsOutOfGas() bool
|
||||
String() string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user