Skip to content

Commit

Permalink
Merge pull request cosmos#386 from assafmo/patch-1
Browse files Browse the repository at this point in the history
Fix ParseEvents to always include wasm.contract_address
  • Loading branch information
ethanfrey authored Jan 25, 2021
2 parents 1920f80 + 0d5da91 commit bd1ee82
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions x/wasm/internal/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,20 +219,21 @@ func NewWasmCoins(cosmosCoins sdk.Coins) (wasmCoins []wasmvmtypes.Coin) {
const CustomEventType = "wasm"
const AttributeKeyContractAddr = "contract_address"

// ParseEvents converts wasm LogAttributes into an sdk.Events (with 0 or 1 elements)
func ParseEvents(logs []wasmvmtypes.EventAttribute, contractAddr sdk.AccAddress) sdk.Events {
if len(logs) == 0 {
return nil
}
// ParseEvents converts wasm LogAttributes into an sdk.Events
func ParseEvents(wasmOutputAttrs []wasmvmtypes.EventAttribute, contractAddr sdk.AccAddress) sdk.Events {
// we always tag with the contract address issuing this event
attrs := []sdk.Attribute{sdk.NewAttribute(AttributeKeyContractAddr, contractAddr.String())}
for _, l := range logs {

// append attributes from wasm to the sdk.Event
for _, l := range wasmOutputAttrs {
// and reserve the contract_address key for our use (not contract)
if l.Key != AttributeKeyContractAddr {
attr := sdk.NewAttribute(l.Key, l.Value)
attrs = append(attrs, attr)
}
}

// each wasm invokation always returns one sdk.Event
return sdk.Events{sdk.NewEvent(CustomEventType, attrs...)}
}

Expand Down

0 comments on commit bd1ee82

Please sign in to comment.