From 09bca64f9db1f1a2c831eb9e303e6e606317f8fc Mon Sep 17 00:00:00 2001 From: Assaf Morami Date: Sun, 24 Jan 2021 14:31:55 +0200 Subject: [PATCH 1/2] Fix ParseEvents to always include wasm.contract_address --- x/wasm/internal/types/types.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/x/wasm/internal/types/types.go b/x/wasm/internal/types/types.go index 66537bd33ce..41d2c9ac7d2 100644 --- a/x/wasm/internal/types/types.go +++ b/x/wasm/internal/types/types.go @@ -219,20 +219,20 @@ 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 to the + 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) } } + return sdk.Events{sdk.NewEvent(CustomEventType, attrs...)} } From 0d5da91468c69ef726a4fd47b462b392c267c762 Mon Sep 17 00:00:00 2001 From: Assaf Morami Date: Sun, 24 Jan 2021 22:08:26 +0200 Subject: [PATCH 2/2] ParseEvents code comments --- x/wasm/internal/types/types.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x/wasm/internal/types/types.go b/x/wasm/internal/types/types.go index 41d2c9ac7d2..ebc82e3ad9f 100644 --- a/x/wasm/internal/types/types.go +++ b/x/wasm/internal/types/types.go @@ -224,7 +224,7 @@ func ParseEvents(wasmOutputAttrs []wasmvmtypes.EventAttribute, contractAddr sdk. // we always tag with the contract address issuing this event attrs := []sdk.Attribute{sdk.NewAttribute(AttributeKeyContractAddr, contractAddr.String())} - // append attributes to the + // 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 { @@ -233,6 +233,7 @@ func ParseEvents(wasmOutputAttrs []wasmvmtypes.EventAttribute, contractAddr sdk. } } + // each wasm invokation always returns one sdk.Event return sdk.Events{sdk.NewEvent(CustomEventType, attrs...)} }