Skip to content

Commit

Permalink
fix(wasm): wrap smart contract NewKeyRequest using Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Pitasi committed May 31, 2024
1 parent e4d630a commit 27b172a
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions warden/app/wasm-interop/custom_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ package wasm_interop
import (
"encoding/json"
"fmt"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
intenttypes "github.com/warden-protocol/wardenprotocol/warden/x/intent/types"
types "github.com/warden-protocol/wardenprotocol/warden/x/warden/types/v1beta2"
)

Expand All @@ -16,7 +20,6 @@ type WardenMsg struct {
}

type NewKeyRequest struct {
Btl uint64 `json:"btl"`
IntentId uint64 `json:"intent_id"`
KeyType types.KeyType `json:"key_type"`
KeychainID uint64 `json:"keychain_id"`
Expand All @@ -31,16 +34,25 @@ func EncodeCustomMsg(sender sdk.AccAddress, rawMsg json.RawMessage) ([]sdk.Msg,
}
switch {
case msg.Warden.NewKeyRequest != nil:
intentAuthority := authtypes.NewModuleAddress(intenttypes.ModuleName)
newKeyRequest := msg.Warden.NewKeyRequest
setMsg := types.MsgNewKeyRequest{
Creator: sender.String(),
newKeyMsg := &types.MsgNewKeyRequest{
Authority: intentAuthority.String(),
SpaceId: newKeyRequest.SpaceID,
KeychainId: newKeyRequest.KeychainID,
KeyType: newKeyRequest.KeyType,
Btl: newKeyRequest.Btl,
IntentId: newKeyRequest.IntentId,
}
return []sdk.Msg{&setMsg}, nil
msgAny, err := codectypes.NewAnyWithValue(newKeyMsg)
if err != nil {
return nil, err
}

newActionMsg := &intenttypes.MsgNewAction{
Creator: sender.String(),
Message: msgAny,
}
return []sdk.Msg{newActionMsg}, nil
default:
return nil, fmt.Errorf("unknown variant of WardenProtocolMsg")
}
Expand Down

0 comments on commit 27b172a

Please sign in to comment.