Skip to content

Commit

Permalink
improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamer committed Oct 23, 2023
1 parent 48f48b8 commit c60b970
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
3 changes: 1 addition & 2 deletions ibc_module.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package nfttransfer

import (
"fmt"
"math"
"strings"

Expand Down Expand Up @@ -236,7 +235,7 @@ func (im IBCModule) OnAcknowledgementPacket(
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())),
sdk.NewAttribute(types.AttributeKeyAck, ack.String()),
),
)

Expand Down
2 changes: 1 addition & 1 deletion keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (k Keeper) ClassTrace(c context.Context,

hash, err := types.ParseHexHash(strings.TrimPrefix(req.Hash, "ibc/"))
if err != nil {
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid denom trace hash: %s, error: %s", hash.String(), err))
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid denom trace hash: %s, error: %s", req.Hash, err))
}

ctx := sdk.UnwrapSDKContext(c)
Expand Down
6 changes: 3 additions & 3 deletions keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ func (k Keeper) refundPacketToken(ctx sdk.Context, packet channeltypes.Packet, d
return err
}
if types.IsAwayFromOrigin(packet.GetSourcePort(), packet.GetSourceChannel(), data.ClassId) {
for _, tokenID := range data.TokenIds {
if err := k.nftKeeper.Transfer(ctx, voucherClassID, tokenID, "", sender); err != nil {
for i, tokenID := range data.TokenIds {
if err := k.nftKeeper.Transfer(ctx, voucherClassID, tokenID, types.GetIfExist(i, data.TokenData), sender); err != nil {
return err
}
}
Expand Down Expand Up @@ -260,7 +260,7 @@ func (k Keeper) createOutgoingPacket(ctx sdk.Context,
if isAwayFromOrigin {
// create the escrow address for the tokens
escrowAddress := types.GetEscrowAddress(sourcePort, sourceChannel)
if err := k.nftKeeper.Transfer(ctx, classID, tokenID, "", escrowAddress); err != nil {
if err := k.nftKeeper.Transfer(ctx, classID, tokenID, nft.GetData(), escrowAddress); err != nil {
return channeltypes.Packet{}, err
}
} else {
Expand Down
1 change: 1 addition & 0 deletions types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const (
AttributeKeyReceiver = "receiver"
AttributeKeyClassID = "classID"
AttributeKeyTokenIDs = "tokenIDs"
AttributeKeyAck = "acknowledgement"
AttributeKeyAckSuccess = "success"
AttributeKeyAckError = "error"
AttributeKeyTraceHash = "trace_hash"
Expand Down
9 changes: 4 additions & 5 deletions types/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@ import (

// ParseHexHash parses a hex hash in string format to bytes and validates its correctness.
func ParseHexHash(hexHash string) (tmbytes.HexBytes, error) {
if strings.TrimSpace(hexHash) == "" {
return nil, fmt.Errorf("empty hex hash")
}
hash, err := hex.DecodeString(hexHash)
if err != nil {
return nil, err
}

if err := tmtypes.ValidateHash(hash); err != nil {
return nil, err
}

return hash, nil
return hash, tmtypes.ValidateHash(hash)
}

// GetClassPrefix returns the receiving class prefix
Expand Down

0 comments on commit c60b970

Please sign in to comment.