From 33bf5791d5222c3454c0951feba9d4eee8d0cd52 Mon Sep 17 00:00:00 2001 From: Jayden Lee <41176085+tkxkd0159@users.noreply.github.com> Date: Thu, 26 Jan 2023 13:25:31 +0900 Subject: [PATCH 1/2] Add events for `setContractAdmin` --- x/wasm/keeper/keeper.go | 14 ++++++++++++++ x/wasm/types/events.go | 21 ++++++++++++--------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/x/wasm/keeper/keeper.go b/x/wasm/keeper/keeper.go index 195a4614ce..9d20d0cd37 100644 --- a/x/wasm/keeper/keeper.go +++ b/x/wasm/keeper/keeper.go @@ -639,6 +639,20 @@ func (k Keeper) setContractAdmin(ctx sdk.Context, contractAddress, caller, newAd } contractInfo.Admin = newAdmin.String() k.storeContractInfo(ctx, contractAddress, contractInfo) + + if newAdmin != nil { + ctx.EventManager().EmitEvent(sdk.NewEvent( + types.EventTypeUpdateContractAdmin, + sdk.NewAttribute(types.AttributeKeyContractAddr, contractAddress.String()), + sdk.NewAttribute(types.AttributeKeyAdmin, newAdmin.String()), + )) + } else { + ctx.EventManager().EmitEvent(sdk.NewEvent( + types.EventTypeClearContractAdmin, + sdk.NewAttribute(types.AttributeKeyContractAddr, contractAddress.String()), + )) + } + return nil } diff --git a/x/wasm/types/events.go b/x/wasm/types/events.go index 579024ed0c..6becc4d01b 100644 --- a/x/wasm/types/events.go +++ b/x/wasm/types/events.go @@ -6,15 +6,17 @@ const ( // CustomContractEventPrefix contracts can create custom events. To not mix them with other system events they got the `wasm-` prefix. CustomContractEventPrefix = "wasm-" - EventTypeStoreCode = "store_code" - EventTypeInstantiate = "instantiate" - EventTypeExecute = "execute" - EventTypeMigrate = "migrate" - EventTypePinCode = "pin_code" - EventTypeUnpinCode = "unpin_code" - EventTypeSudo = "sudo" - EventTypeReply = "reply" - EventTypeGovContractResult = "gov_contract_result" + EventTypeStoreCode = "store_code" + EventTypeInstantiate = "instantiate" + EventTypeExecute = "execute" + EventTypeMigrate = "migrate" + EventTypePinCode = "pin_code" + EventTypeUnpinCode = "unpin_code" + EventTypeSudo = "sudo" + EventTypeReply = "reply" + EventTypeGovContractResult = "gov_contract_result" + EventTypeUpdateContractAdmin = "update_contract_admin" + EventTypeClearContractAdmin = "clear_contract_admin" ) // event attributes returned from contract execution @@ -26,4 +28,5 @@ const ( AttributeKeyChecksum = "code_checksum" AttributeKeyResultDataHex = "result" AttributeKeyRequiredCapability = "required_capability" + AttributeKeyAdmin = "admin" ) From 8a2d601365a51e86347b564f543e7a4efed38a14 Mon Sep 17 00:00:00 2001 From: Jayden Lee <41176085+tkxkd0159@users.noreply.github.com> Date: Thu, 26 Jan 2023 13:38:34 +0900 Subject: [PATCH 2/2] Add events for `setAccessConfig` --- x/wasm/keeper/keeper.go | 8 ++++++++ x/wasm/types/events.go | 15 +++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/x/wasm/keeper/keeper.go b/x/wasm/keeper/keeper.go index 9d20d0cd37..fadd59ff64 100644 --- a/x/wasm/keeper/keeper.go +++ b/x/wasm/keeper/keeper.go @@ -990,6 +990,14 @@ func (k Keeper) setAccessConfig(ctx sdk.Context, codeID uint64, caller sdk.AccAd info.InstantiateConfig = newConfig k.storeCodeInfo(ctx, codeID, *info) + + ctx.EventManager().EmitEvent(sdk.NewEvent( + types.EventTypeSetAccessConfig, + sdk.NewAttribute(types.AttributeKeyCodeID, strconv.FormatUint(codeID, 10)), + sdk.NewAttribute(types.AttributeKeyCodePermission, newConfig.Permission.String()), + sdk.NewAttribute(types.AttributeKeyAuthorizedAddresses, strings.Join(newConfig.Addresses, ", ")), + )) + return nil } diff --git a/x/wasm/types/events.go b/x/wasm/types/events.go index 6becc4d01b..58d9e88900 100644 --- a/x/wasm/types/events.go +++ b/x/wasm/types/events.go @@ -17,16 +17,19 @@ const ( EventTypeGovContractResult = "gov_contract_result" EventTypeUpdateContractAdmin = "update_contract_admin" EventTypeClearContractAdmin = "clear_contract_admin" + EventTypeSetAccessConfig = "set_access_config" ) // event attributes returned from contract execution const ( AttributeReservedPrefix = "_" - AttributeKeyContractAddr = "_contract_address" - AttributeKeyCodeID = "code_id" - AttributeKeyChecksum = "code_checksum" - AttributeKeyResultDataHex = "result" - AttributeKeyRequiredCapability = "required_capability" - AttributeKeyAdmin = "admin" + AttributeKeyContractAddr = "_contract_address" + AttributeKeyCodeID = "code_id" + AttributeKeyChecksum = "code_checksum" + AttributeKeyCodePermission = "code_permission" + AttributeKeyAuthorizedAddresses = "auth_addresses" + AttributeKeyResultDataHex = "result" + AttributeKeyRequiredCapability = "required_capability" + AttributeKeyAdmin = "admin" )