Skip to content

Commit

Permalink
fix: implement genesis account interface (backport #8) (#9)
Browse files Browse the repository at this point in the history
Co-authored-by: John Letey <[email protected]>
  • Loading branch information
mergify[bot] and johnletey authored Apr 29, 2024
1 parent 16db4b7 commit efeea8d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions x/forwarding/types/account.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
package types

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
channeltypes "github.com/cosmos/ibc-go/v4/modules/core/04-channel/types"
)

var (
_ authtypes.AccountI = &ForwardingAccount{}
_ authtypes.GenesisAccount = &ForwardingAccount{}
)

func GenerateAddress(channel string, recipient string) sdk.AccAddress {
bz := []byte(channel + recipient)
return address.Derive([]byte(ModuleName), bz)[12:]
}

func (fa *ForwardingAccount) Validate() error {
if !channeltypes.IsValidChannelID(fa.Channel) {
return fmt.Errorf("channel id (%s) is invalid for account %s", fa.Channel, fa.Address)
}

if fa.CreatedAt < 0 {
return fmt.Errorf("%d is an invalid creation height for account %s", fa.CreatedAt, fa.Address)
}

return fa.BaseAccount.Validate()
}
1 change: 1 addition & 0 deletions x/forwarding/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {

func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
registry.RegisterImplementations((*authtypes.AccountI)(nil), &ForwardingAccount{})
registry.RegisterImplementations((*authtypes.GenesisAccount)(nil), &ForwardingAccount{})

registry.RegisterImplementations((*sdk.Msg)(nil), &MsgRegisterAccount{})
registry.RegisterImplementations((*sdk.Msg)(nil), &MsgClearAccount{})
Expand Down

0 comments on commit efeea8d

Please sign in to comment.