-
Notifications
You must be signed in to change notification settings - Fork 657
/
Copy pathaccount.go
26 lines (20 loc) · 953 Bytes
/
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
package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
icatypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types"
)
// RegisterInterchainAccount attempts to create a new account using the provided address and stores it in state keyed by the provided port identifier
// If an account for the provided address already exists this function returns early (no-op)
func (k Keeper) RegisterInterchainAccount(ctx sdk.Context, accAddr sdk.AccAddress, controllerPortID string) {
if acc := k.accountKeeper.GetAccount(ctx, accAddr); acc != nil {
return
}
interchainAccount := icatypes.NewInterchainAccount(
authtypes.NewBaseAccountWithAddress(accAddr),
controllerPortID,
)
k.accountKeeper.NewAccount(ctx, interchainAccount)
k.accountKeeper.SetAccount(ctx, interchainAccount)
k.SetInterchainAccountAddress(ctx, controllerPortID, interchainAccount.Address)
}