Fix ParseEvents to always include wasm.contract_address

This commit is contained in:
Assaf Morami 2021-01-24 14:31:55 +02:00 committed by GitHub
parent 1920f80d18
commit 09bca64f9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 6 deletions

View File

@ -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...)}
}