github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/ibc-go/modules/apps/27-interchain-accounts/host/keeper/account.go (about)

     1  package keeper
     2  
     3  import (
     4  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
     5  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/auth"
     6  	icatypes "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/apps/27-interchain-accounts/types"
     7  )
     8  
     9  // RegisterInterchainAccount attempts to create a new account using the provided address and
    10  // stores it in state keyed by the provided connection and port identifiers
    11  // If an account for the provided address already exists this function returns early (no-op)
    12  func (k Keeper) RegisterInterchainAccount(ctx sdk.Context, connectionID, controllerPortID string, accAddress sdk.AccAddress) {
    13  	if acc := k.accountKeeper.GetAccount(ctx, accAddress); acc != nil {
    14  		return
    15  	}
    16  	baseAcc := auth.NewBaseAccountWithAddress(accAddress)
    17  	interchainAccount := icatypes.NewAminoInterchainAccount(
    18  		&baseAcc,
    19  		controllerPortID,
    20  	)
    21  
    22  	k.accountKeeper.NewAccount(ctx, interchainAccount)
    23  	k.accountKeeper.SetAccount(ctx, interchainAccount)
    24  
    25  	k.SetInterchainAccountAddress(ctx, connectionID, controllerPortID, interchainAccount.Address.String())
    26  }