Skip to content

Commit

Permalink
channel: add virtual packet setter/getter
Browse files Browse the repository at this point in the history
  • Loading branch information
nicopernas committed Apr 30, 2024
1 parent d0b047c commit a485548
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
17 changes: 17 additions & 0 deletions modules/core/04-channel/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,23 @@ func (k Keeper) deletePacketCommitment(ctx sdk.Context, portID, channelID string
store.Delete(host.PacketCommitmentKey(portID, channelID, sequence))
}

func (k Keeper) SetVirtualPacket(ctx sdk.Context, portID, channelID string, sequence uint64, packet types.Packet) {
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshal(&packet)
store.Set(host.VirtualPacketKey(portID, channelID, sequence), bz)
}

func (k Keeper) GetVirtualPacket(ctx sdk.Context, portID, channelID string, sequence uint64) (types.Packet, bool) {
store := ctx.KVStore(k.storeKey)
bz := store.Get(host.VirtualPacketKey(portID, channelID, sequence))
if len(bz) == 0 {
return types.Packet{}, false
}
var packet types.Packet
k.cdc.MustUnmarshal(bz, &packet)
return packet, true
}

// SetPacketAcknowledgement sets the packet ack hash to the store
func (k Keeper) SetPacketAcknowledgement(ctx sdk.Context, portID, channelID string, sequence uint64, ackHash []byte) {
store := ctx.KVStore(k.storeKey)
Expand Down
16 changes: 16 additions & 0 deletions modules/core/24-host/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const (
KeyNextSeqRecvPrefix = "nextSequenceRecv"
KeyNextSeqAckPrefix = "nextSequenceAck"
KeyPacketCommitmentPrefix = "commitments"
KeyVirtualPacketPrefix = "virtualPacket"
KeyPacketAckPrefix = "acks"
KeyPacketReceiptPrefix = "receipts"
)
Expand Down Expand Up @@ -186,6 +187,21 @@ func PacketCommitmentKey(portID, channelID string, sequence uint64) []byte {
return []byte(PacketCommitmentPath(portID, channelID, sequence))
}

// Defines the prefix for virtual packet store path.
func VirtualPacketPrefixPath(portID, channelID string) string {
return fmt.Sprintf("%s/%s/%s", KeyVirtualPacketPrefix, channelPath(portID, channelID), KeySequencePrefix)
}

// Defines the virtual packet store path
func VirtualPacketPath(portID, channelID string, sequence uint64) string {
return fmt.Sprintf("%s/%d", VirtualPacketPrefixPath(portID, channelID), sequence)
}

// Returns the store key of under which a virtual packet is stored
func VirtualPacketKey(portID, channelID string, sequence uint64) []byte {
return []byte(VirtualPacketPath(portID, channelID, sequence))
}

// PacketCommitmentPrefixPath defines the prefix for commitments to packet data fields store path.
func PacketCommitmentPrefixPath(portID, channelID string) string {
return fmt.Sprintf("%s/%s/%s", KeyPacketCommitmentPrefix, channelPath(portID, channelID), KeySequencePrefix)
Expand Down

0 comments on commit a485548

Please sign in to comment.