From 08907cfaf4bc6dd9fde7e84e7b849345bba31024 Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Tue, 14 Jan 2025 08:10:28 +0100 Subject: [PATCH] Adapt to new send rewards packet format --- .../ibc_packet_btc_staking_consumer_event.go | 20 ++++++++----------- x/zoneconcierge/module_ibc.go | 6 +++--- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/x/zoneconcierge/keeper/ibc_packet_btc_staking_consumer_event.go b/x/zoneconcierge/keeper/ibc_packet_btc_staking_consumer_event.go index 33630f8d6..0f4bfeb5a 100644 --- a/x/zoneconcierge/keeper/ibc_packet_btc_staking_consumer_event.go +++ b/x/zoneconcierge/keeper/ibc_packet_btc_staking_consumer_event.go @@ -2,7 +2,6 @@ package keeper import ( "context" - "encoding/json" "fmt" bbn "github.com/babylonlabs-io/babylon/types" @@ -10,7 +9,6 @@ import ( finalitytypes "github.com/babylonlabs-io/babylon/x/finality/types" "github.com/babylonlabs-io/babylon/x/zoneconcierge/types" sdk "github.com/cosmos/cosmos-sdk/types" - ibctransfer "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" ) // BroadcastBTCStakingConsumerEvents retrieves all BTC staking consumer events from the event store, @@ -166,22 +164,20 @@ func (k Keeper) HandleConsumerDistribution( ctx sdk.Context, portID string, channelID string, - consumerDistribution *ibctransfer.FungibleTokenPacketData, + consumerFpDistribution *types.ConsumerSendRewardsIBCPacket, ) error { - // clientID, _, err := k.channelKeeper.GetChannelClientState(ctx, portID, channelID) - // if err != nil { - // return fmt.Errorf("failed to get client state: %w", err) - // } + //clientID, _, err := k.channelKeeper.GetChannelClientState(ctx, portID, channelID) + _, _, err := k.channelKeeper.GetChannelClientState(ctx, portID, channelID) + if err != nil { + return fmt.Errorf("failed to get client state: %w", err) + } // Deserialize the memo - var rewardsDistribution []RewardsDistribution - if err := json.Unmarshal([]byte(consumerDistribution.Memo), &rewardsDistribution); err != nil { - return fmt.Errorf("failed to unmarshal memo: %w", err) - } + var rewardsDistribution = consumerFpDistribution.FpDistribution // Process the distribution list for _, reward := range rewardsDistribution { - fpPubkey, err := bbn.NewBIP340PubKeyFromHex(reward.FpPubkeyHex) + fpPubkey, err := reward.FpBtcPk.ToBTCPK() if err != nil { return fmt.Errorf("failed to create BIP340 public key: %w", err) } diff --git a/x/zoneconcierge/module_ibc.go b/x/zoneconcierge/module_ibc.go index 28b283bbb..3a91c7450 100644 --- a/x/zoneconcierge/module_ibc.go +++ b/x/zoneconcierge/module_ibc.go @@ -191,12 +191,12 @@ func (im IBCModule) OnRecvPacket( return channeltypes.NewErrorAcknowledgement(err) } return channeltypes.NewResultAcknowledgement([]byte("Consumer slashing handled successfully")) - case *types.ZoneconciergePacketData_ConsumerFpDistribution: - err := im.keeper.HandleConsumerDistribution(ctx, modulePacket.DestinationPort, modulePacket.DestinationChannel, packet.ConsumerFpDistribution) + case *types.ZoneconciergePacketData_ConsumerRewards: + err := im.keeper.HandleConsumerDistribution(ctx, modulePacket.DestinationPort, modulePacket.DestinationChannel, packet.ConsumerRewards) if err != nil { return channeltypes.NewErrorAcknowledgement(err) } - return channeltypes.NewResultAcknowledgement([]byte("Consumer distribution handled successfully")) + return channeltypes.NewResultAcknowledgement([]byte("Consumer rewards distribution handled successfully")) // Add other packet types here if needed default: errMsg := fmt.Sprintf("unrecognized %s packet type: %T", types.ModuleName, packet)