Skip to content

Commit

Permalink
Merge pull request #8 from bianjieai/release/v1.1.1-beta
Browse files Browse the repository at this point in the history
add changelog
  • Loading branch information
aofengli authored Feb 7, 2023
2 parents 3717108 + f60bef6 commit 6b8596c
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 24 deletions.
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,23 @@ Ref: https://keepachangelog.com/en/1.0.0/

# Changelog

## [Unreleased]
## [v1.1.1-beta]

### Dependencies

### API Breaking

### State Machine Breaking

### Improvements

* [\#7](https://github.com/bianjieai/nft-transfer/pull/7) modify JSON encoding rules

### Features

### Bug Fixes

## [v1.1.0-beta]

### Dependencies

Expand Down
4 changes: 3 additions & 1 deletion RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,6 @@ Versions of Golang, Cosmos SDK and Tendermint used by ibc-go in the currently ac

| Go | nft-transfer | ibc-go | Cosmos SDK | Tendermint |
| ---- | ------------ | ------ | ---------- | ---------- |
| 1.18 | main | v5.0.1 | v0.46.3 | v0.34.22 |
| 1.18 | v1.1.1-beta | v5.0.1 | v0.46.3 | v0.34.22 |
| 1.18 | v1.1.0-beta | v5.0.1 | v0.46.3 | v0.34.22 |
| 1.18 | v1.0.0-beta | v5.0.1 | v0.46.3 | v0.34.22 |
36 changes: 14 additions & 22 deletions ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,36 +182,25 @@ func (im IBCModule) OnRecvPacket(
relayer sdk.AccAddress,
) ibcexported.Acknowledgement {
var (
ack = channeltypes.NewResultAcknowledgement([]byte{byte(1)})
data types.NonFungibleTokenPacketData
ackErr error
ack = channeltypes.NewResultAcknowledgement([]byte{byte(1)})
data types.NonFungibleTokenPacketData
err error
)

if err := types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil {
ackErr = sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "cannot unmarshal ICS-721 nft-transfer packet data")
ack = channeltypes.NewErrorAcknowledgement(ackErr)
if err = types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil {
ack = channeltypes.NewErrorAcknowledgement(
sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "cannot unmarshal ICS-721 nft-transfer packet data"),
)
}

// only attempt the application logic if the packet data
// was successfully decoded
if ack.Success() {
if err := im.keeper.OnRecvPacket(ctx, packet, data); err != nil {
if err = im.keeper.OnRecvPacket(ctx, packet, data); err != nil {
ack = channeltypes.NewErrorAcknowledgement(err)
}
}

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypePacket,
sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName),
sdk.NewAttribute(sdk.AttributeKeySender, data.Sender),
sdk.NewAttribute(types.AttributeKeyReceiver, data.Receiver),
sdk.NewAttribute(types.AttributeKeyClassID, data.ClassId),
sdk.NewAttribute(types.AttributeKeyTokenIDs, strings.Join(data.TokenIds, ",")),
sdk.NewAttribute(types.AttributeKeyAckSuccess, fmt.Sprintf("%t", ack.Success())),
),
)

keeper.EmitAcknowledgementEvent(ctx, data, ack, err)
// NOTE: acknowledgement will be written synchronously during IBC handler execution.
return ack
}
Expand All @@ -225,11 +214,14 @@ func (im IBCModule) OnAcknowledgementPacket(
) error {
var ack channeltypes.Acknowledgement
if err := types.ModuleCdc.UnmarshalJSON(acknowledgement, &ack); err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-721 transfer packet acknowledgement: %v", err)
return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest,
"cannot unmarshal ICS-721 transfer packet acknowledgement: %v", err)
}

var data types.NonFungibleTokenPacketData
if err := types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-721 transfer packet data: %s", err.Error())
return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest,
"cannot unmarshal ICS-721 transfer packet data: %s", err.Error())
}

if err := im.keeper.OnAcknowledgementPacket(ctx, packet, data, ack); err != nil {
Expand Down
36 changes: 36 additions & 0 deletions keeper/events.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package keeper

import (
"fmt"
"strings"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/ibc-go/v5/modules/core/exported"

"github.com/bianjieai/nft-transfer/types"
)

// EmitAcknowledgementEvent emits an event signalling a successful or failed acknowledgement and including the error
// details if any.
func EmitAcknowledgementEvent(ctx sdk.Context, data types.NonFungibleTokenPacketData, ack exported.Acknowledgement, err error) {
attributes := []sdk.Attribute{
sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName),
sdk.NewAttribute(sdk.AttributeKeySender, data.Sender),
sdk.NewAttribute(types.AttributeKeyReceiver, data.Receiver),
sdk.NewAttribute(types.AttributeKeyClassID, data.ClassId),
sdk.NewAttribute(types.AttributeKeyTokenIDs, strings.Join(data.TokenIds, ",")),
sdk.NewAttribute(types.AttributeKeyAckSuccess, fmt.Sprintf("%t", ack.Success())),
}

if err != nil {
attributes = append(attributes, sdk.NewAttribute(types.AttributeKeyAckError, err.Error()))
}

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypePacket,
attributes...,
),
)
}

0 comments on commit 6b8596c

Please sign in to comment.