-
Notifications
You must be signed in to change notification settings - Fork 193
/
msg_server_restore_interchain_account.go
45 lines (36 loc) · 1.56 KB
/
msg_server_restore_interchain_account.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package keeper
import (
"context"
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
icatypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types"
"github.com/Stride-Labs/stride/x/stakeibc/types"
)
func (k msgServer) RestoreInterchainAccount(goCtx context.Context, msg *types.MsgRestoreInterchainAccount) (*types.MsgRestoreInterchainAccountResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
hostZone, found := k.GetHostZone(ctx, msg.ChainId)
if !found {
k.Logger(ctx).Error(fmt.Sprintf("Host Zone not found: %s", msg.ChainId))
return nil, types.ErrInvalidHostZone
}
owner := types.FormatICAAccountOwner(msg.ChainId, msg.AccountType)
// only allow restoring an account if it already exists
portID, err := icatypes.NewControllerPortID(owner)
if err != nil {
errMsg := fmt.Sprintf("could not create portID for ICA controller account address: %s", owner)
k.Logger(ctx).Error(errMsg)
return nil, err
}
_, exists := k.ICAControllerKeeper.GetInterchainAccountAddress(ctx, hostZone.ConnectionId, portID)
if !exists {
errMsg := fmt.Sprintf("ICA controller account address not found: %s", owner)
k.Logger(ctx).Error(errMsg)
return nil, sdkerrors.Wrapf(types.ErrInvalidInterchainAccountAddress, errMsg)
}
if err := k.ICAControllerKeeper.RegisterInterchainAccount(ctx, hostZone.ConnectionId, owner); err != nil {
k.Logger(ctx).Error(fmt.Sprintf("unable to register %s account : %s", msg.AccountType.String(), err))
return nil, err
}
return &types.MsgRestoreInterchainAccountResponse{}, nil
}