Skip to content

Commit

Permalink
feat(cosmos): publish event when x/swingset storage is modified
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Sep 8, 2021
1 parent cb6c5ad commit 8b63eb0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions golang/cosmos/x/swingset/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ func (k Keeper) SetStorage(ctx sdk.Context, path string, storage *types.Storage)
dataStore.Set(pathKey, k.cdc.MustMarshalLengthPrefixed(storage))
}

ctx.EventManager().EmitEvent(
types.NewStorageEvent(path, storage.Value),
)

// Update the parent keys.
pathComponents := strings.Split(path, ".")
for i := len(pathComponents) - 1; i >= 0; i-- {
Expand Down
25 changes: 25 additions & 0 deletions golang/cosmos/x/swingset/types/events.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package types

import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

// swingset module event types
const (
EventTypeStorage = "storage"

AttributeKeyPath = "path"
AttributeKeyValue = "value"

AttributeValueCategory = ModuleName
)

// NewStorageSetEvent constructs a new storage change sdk.Event
// nolint: interfacer
func NewStorageEvent(path, value string) sdk.Event {
return sdk.NewEvent(
EventTypeStorage,
sdk.NewAttribute(AttributeKeyPath, path),
sdk.NewAttribute(AttributeKeyValue, value),
)
}

0 comments on commit 8b63eb0

Please sign in to comment.