Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing events for admin-related methods #1177

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions x/wasm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking of 2 different events first but then merged them into 1 to make it easier for clients to subscribe to updates. When the admin is cleared, the new admin value would be empty.

Copy link
Author

@tkxkd0159 tkxkd0159 Jan 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like your option as well. I just thought about this and I decided to distinguish those events from the view of a message as a unit of action. (if the admin is cleared, nobody can update the admin after that and only gov can do this)

sdk.NewAttribute(types.AttributeKeyContractAddr, contractAddress.String()),
))
}

return nil
}

Expand Down Expand Up @@ -976,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, ", ")),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The newConfig.Address field is deprecated but we need to support this for some time, until fully removed.
The authorized addresses are not always set. I would prefer to set the attribute only for certain permissions where a value would be expected.

nit: the space in the join pattern makes it easier to read for humans but adds a bit more complexity for the clients. Either they find the pattern or have to trim each address.

Copy link
Author

@tkxkd0159 tkxkd0159 Jan 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The authorized addresses are not always set. I would prefer to set the attribute only for certain permissions where a value would be expected.

I think it's fine to always add addresses attributes in schema perspective. The addresses field will just be left empty(Join nil), and the client can process the event data appropriately according to the CodePermission.

))

return nil
}

Expand Down
34 changes: 20 additions & 14 deletions x/wasm/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,30 @@ 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"
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"
AttributeKeyContractAddr = "_contract_address"
AttributeKeyCodeID = "code_id"
AttributeKeyChecksum = "code_checksum"
AttributeKeyCodePermission = "code_permission"
AttributeKeyAuthorizedAddresses = "auth_addresses"
AttributeKeyResultDataHex = "result"
AttributeKeyRequiredCapability = "required_capability"
AttributeKeyAdmin = "admin"
)