Skip to content

Commit

Permalink
refactor AddUpdateMarker flow
Browse files Browse the repository at this point in the history
  • Loading branch information
nullpointer0x00 committed Oct 9, 2023
1 parent e561486 commit 673eb20
Showing 1 changed file with 44 additions and 34 deletions.
78 changes: 44 additions & 34 deletions x/ibchooks/marker_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,45 +59,55 @@ func (h MarkerHooks) AddUpdateMarker(ctx sdktypes.Context, packet exported.Packe
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
}

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 marker != nil {
if err = ResetMarkerAccessGrants(transferAuthAddrs, marker); err != nil {
return err
}

Check warning on line 66 in x/ibchooks/marker_hooks.go

View check run for this annotation

Codecov / codecov/patch

x/ibchooks/marker_hooks.go#L65-L66

Added lines #L65 - L66 were not covered by tests
h.MarkerKeeper.SetMarker(ctx, marker)
return nil
}
return h.createNewIbcMarker(data, marker, ibcDenom, coinType, err, transferAuthAddrs, ctx, packet, ibcKeeper)
}

// createNewIbcMarker creates a new marker account for ibc token
func (h MarkerHooks) createNewIbcMarker(data transfertypes.FungibleTokenPacketData, marker markertypes.MarkerAccountI, ibcDenom string, coinType markertypes.MarkerType, err error, transferAuthAddrs []sdktypes.AccAddress, ctx sdktypes.Context, packet exported.PacketI, ibcKeeper *ibckeeper.Keeper) error {
amount, errParse := strconv.ParseInt(data.Amount, 10, 64)
if errParse != nil {
return errParse
}

Check warning on line 78 in x/ibchooks/marker_hooks.go

View check run for this annotation

Codecov / codecov/patch

x/ibchooks/marker_hooks.go#L77-L78

Added lines #L77 - L78 were not covered by tests
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
}

Check warning on line 93 in x/ibchooks/marker_hooks.go

View check run for this annotation

Codecov / codecov/patch

x/ibchooks/marker_hooks.go#L92-L93

Added lines #L92 - L93 were not covered by tests
if err = h.MarkerKeeper.AddMarkerAccount(ctx, marker); err != nil {
return err
}

Check warning on line 96 in x/ibchooks/marker_hooks.go

View check run for this annotation

Codecov / codecov/patch

x/ibchooks/marker_hooks.go#L95-L96

Added lines #L95 - L96 were not covered by tests
return h.addDenomMetaData(ctx, packet, ibcKeeper, ibcDenom, data, err)
}

// addDenomMetaData adds denom metadata for ibc token
func (h MarkerHooks) addDenomMetaData(ctx sdktypes.Context, packet exported.PacketI, ibcKeeper *ibckeeper.Keeper, ibcDenom string, data transfertypes.FungibleTokenPacketData, err error) error {
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
}

Check warning on line 111 in x/ibchooks/marker_hooks.go

View check run for this annotation

Codecov / codecov/patch

x/ibchooks/marker_hooks.go#L110-L111

Added lines #L110 - L111 were not covered by tests
return nil
}
Expand Down

0 comments on commit 673eb20

Please sign in to comment.