From e561486b0daf228271ea4f914509a5a8f9cb7491 Mon Sep 17 00:00:00 2001 From: Carlton N Hanna Date: Mon, 9 Oct 2023 10:41:31 -0600 Subject: [PATCH] change logic flow --- x/ibchooks/marker_hooks.go | 96 +++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 47 deletions(-) diff --git a/x/ibchooks/marker_hooks.go b/x/ibchooks/marker_hooks.go index 8477af17b5..76a1998a84 100644 --- a/x/ibchooks/marker_hooks.go +++ b/x/ibchooks/marker_hooks.go @@ -42,60 +42,62 @@ func (h MarkerHooks) AddUpdateMarker(ctx sdktypes.Context, packet exported.Packe return err } ibcDenom := MustExtractDenomFromPacketOnRecv(packet) - if strings.HasPrefix(ibcDenom, "ibc/") { - markerAddress, err := markertypes.MarkerAddress(ibcDenom) - if err != nil { + if !strings.HasPrefix(ibcDenom, "ibc/") { + return nil + } + + markerAddress, err := markertypes.MarkerAddress(ibcDenom) + if err != nil { + return err + } + marker, err := h.MarkerKeeper.GetMarker(ctx, markerAddress) + if err != nil { + return err + } + var transferAuthAddrs []sdktypes.AccAddress + transferAuthAddrs, coinType, err := ProcessMarkerMemo(data.GetMemo()) + if err != nil { + return err + } + if marker == nil { + amount, errParse := strconv.ParseInt(data.Amount, 10, 64) + if errParse != nil { + return errParse + } + marker = markertypes.NewMarkerAccount( + authtypes.NewBaseAccountWithAddress(markertypes.MustGetMarkerAddress(ibcDenom)), + sdktypes.NewInt64Coin(ibcDenom, amount), + nil, + nil, + markertypes.StatusActive, + coinType, + false, // supply fixed + false, // allow gov + false, // allow force transfer + []string{}, + ) + if err = ResetMarkerAccessGrants(transferAuthAddrs, marker); err != nil { return err } - marker, err := h.MarkerKeeper.GetMarker(ctx, markerAddress) - if err != nil { + + if err = h.MarkerKeeper.AddMarkerAccount(ctx, marker); err != nil { return err } - var transferAuthAddrs []sdktypes.AccAddress - transferAuthAddrs, coinType, err := ProcessMarkerMemo(data.GetMemo()) - if err != nil { + chainID := h.GetChainID(ctx, packet, ibcKeeper) + markerMetadata := banktypes.Metadata{ + Base: ibcDenom, + Name: chainID + "/" + data.Denom, + Display: chainID + "/" + data.Denom, + Description: data.Denom + " from chain " + chainID, + } + if err = h.MarkerKeeper.SetDenomMetaData(ctx, markerMetadata, authtypes.NewModuleAddress(types.ModuleName)); err != nil { return err } - if marker == nil { - amount, errParse := strconv.ParseInt(data.Amount, 10, 64) - if errParse != nil { - return errParse - } - marker = markertypes.NewMarkerAccount( - authtypes.NewBaseAccountWithAddress(markertypes.MustGetMarkerAddress(ibcDenom)), - sdktypes.NewInt64Coin(ibcDenom, amount), - nil, - nil, - markertypes.StatusActive, - coinType, - false, // supply fixed - false, // allow gov - false, // allow force transfer - []string{}, - ) - if err = ResetMarkerAccessGrants(transferAuthAddrs, marker); err != nil { - return err - } - - if err = h.MarkerKeeper.AddMarkerAccount(ctx, marker); err != nil { - return err - } - chainID := h.GetChainID(ctx, packet, ibcKeeper) - markerMetadata := banktypes.Metadata{ - Base: ibcDenom, - Name: chainID + "/" + data.Denom, - Display: chainID + "/" + data.Denom, - Description: data.Denom + " from chain " + chainID, - } - if err = h.MarkerKeeper.SetDenomMetaData(ctx, markerMetadata, authtypes.NewModuleAddress(types.ModuleName)); err != nil { - return err - } - } else { - if err = ResetMarkerAccessGrants(transferAuthAddrs, marker); err != nil { - return err - } - h.MarkerKeeper.SetMarker(ctx, marker) + } else { + if err = ResetMarkerAccessGrants(transferAuthAddrs, marker); err != nil { + return err } + h.MarkerKeeper.SetMarker(ctx, marker) } return nil }