Skip to content

Commit

Permalink
Adapt to new send rewards packet format
Browse files Browse the repository at this point in the history
  • Loading branch information
maurolacy committed Jan 14, 2025
1 parent db97a1d commit 08907cf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
20 changes: 8 additions & 12 deletions x/zoneconcierge/keeper/ibc_packet_btc_staking_consumer_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ package keeper

import (
"context"
"encoding/json"
"fmt"

bbn "github.com/babylonlabs-io/babylon/types"
bsctypes "github.com/babylonlabs-io/babylon/x/btcstkconsumer/types"
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,
Expand Down Expand Up @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions x/zoneconcierge/module_ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 08907cf

Please sign in to comment.