Skip to content

Commit

Permalink
init auth account from update auth
Browse files Browse the repository at this point in the history
  • Loading branch information
freeelancer committed Mar 7, 2024
1 parent d8a0a4f commit 519bdca
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
11 changes: 7 additions & 4 deletions x/smartaccount/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,22 @@ import (
// Keeper of this module maintains collections of smartaccount for contracts
// registered to receive transaction fees.
type Keeper struct {
storeKey storetypes.StoreKey
cdc codec.BinaryCodec
storeKey storetypes.StoreKey
cdc codec.BinaryCodec
wasmKeeper types.WasmKeeper
}

// NewKeeper creates new instances of the fees Keeper
func NewKeeper(
cdc codec.BinaryCodec,
storeKey storetypes.StoreKey,
wk types.WasmKeeper,
) Keeper {

return Keeper{
storeKey: storeKey,
cdc: cdc,
storeKey: storeKey,
cdc: cdc,
wasmKeeper: wk,
}
}

Expand Down
29 changes: 29 additions & 0 deletions x/smartaccount/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"context"
"encoding/json"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -53,6 +54,34 @@ func (ms MsgServer) UpdateAuthorization(
return nil, err
}
setting.Authorization = msg.AuthorizationMsgs
// TODO: check if this is right
for _, auth := range msg.AuthorizationMsgs {
if auth.ContractAddress == "" {
return nil, sdkerrors.ErrInvalidRequest.Wrapf("contract address cannot be empty")
}
if auth.InitMsg == "" {
return nil, sdkerrors.ErrInvalidRequest.Wrapf("init msg cannot be empty")
}
var sudoMsg types.SudoMsg
err := json.Unmarshal([]byte(auth.InitMsg), &sudoMsg)
if err != nil {
return nil, sdkerrors.ErrInvalidRequest.Wrapf("failed to unmarshal auth msg: %s", err)
}

initMsg := types.Initialization{
Sender: sudoMsg.Authorization.Senders[0],
Account: sudoMsg.Authorization.Senders[0],
Msg: sudoMsg.Authorization.Data,
}
sudoInitMsg := types.SudoMsg{Initialization: &initMsg}
sudoInitMsgBs, err := json.Marshal(sudoInitMsg)
if err != nil {
return nil, err
}

contractAddress := sdk.AccAddress(auth.ContractAddress)
ms.k.wasmKeeper.Sudo(ctx, contractAddress, sudoInitMsgBs)
}
setting.Fallback = msg.Fallback
if err := ms.k.SetSetting(ctx, *setting); err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions x/smartaccount/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ type BankKeeper interface {
// WasmKeeper defines the expected interface needed to retrieve cosmwasm contracts.
type WasmKeeper interface {
GetContractInfo(ctx sdk.Context, contractAddr sdk.AccAddress) (wasmtypes.ContractInfo, error)
Sudo(ctx sdk.Context, contractAddress sdk.AccAddress, msg []byte) ([]byte, error)
}

0 comments on commit 519bdca

Please sign in to comment.