Skip to content

Commit

Permalink
ICS20v2: use protobuf encoding for packet data of v2 (#1118)
Browse files Browse the repository at this point in the history
* ics20: use protobuf encoding for packet data of v2

* Update README.md
  • Loading branch information
crodriguezvega authored Jun 19, 2024
1 parent ec5fcc3 commit 89aec20
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions spec/app/ics-020-fungible-token-transfer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ function sendFungibleTokens(
}
}

var dataBytes bytes
channel = provableStore.get(channelPath(sourcePort, sourceChannel))
// getAppVersion returns the transfer version that is embedded in the channel version
// as the channel version may contain additional app or middleware version(s)
Expand All @@ -348,9 +349,13 @@ function sendFungibleTokens(
v1Denom = constructOnChainDenom(token.trace, token.denom)
// v1 packet data does not support forwarding fields
data = FungibleTokenPacketData{v1Denom, token.amount, sender, receiver, memo}
// JSON-marshal packet data into bytes
dataBytes = json.marshal(data)
} else if transferVersion == "ics20-2" {
// create FungibleTokenPacket data
data = FungibleTokenPacketDataV2{tokens, sender, receiver, memo, forwarding}
// protobuf-marshal packet data into bytes
dataBytes = protobuf.marshal(data)
} else {
// should never be reached as transfer version must be negotiated to be either
// ics20-1 or ics20-2 during channel handshake
Expand All @@ -364,7 +369,7 @@ function sendFungibleTokens(
sourceChannel,
timeoutHeight,
timeoutTimestamp,
MarshalJSON(data) // json-marshalled bytes of packet data
dataBytes,
)

return sequence
Expand All @@ -387,7 +392,7 @@ function onRecvPacket(packet: Packet) {
var finalReceiver string // final intended address in forwarding case

if transferVersion == "ics20-1" {
FungibleTokenPacketData data = UnmarshalJSON(packet.data)
FungibleTokenPacketData data = json.unmarshal(packet.data)
trace, denom = parseICS20V1Denom(data.denom)
token = Token{
denom: denom
Expand All @@ -398,7 +403,7 @@ function onRecvPacket(packet: Packet) {
sender = data.sender
receiver = data.receiver
} else if transferVersion == "ics20-2" {
FungibleTokenPacketDataV2 data = UnmarshalJSON(packet.data)
FungibleTokenPacketDataV2 data = protobuf.unmarshal(packet.data)
tokens = data.tokens
sender = data.sender

Expand Down Expand Up @@ -609,7 +614,7 @@ function refundTokens(packet: Packet) {
// as the channel version may contain additional app or middleware version(s)
transferVersion = getAppVersion(channel.version)
if transferVersion == "ics20-1" {
FungibleTokenPacketData data = UnmarshalJSON(packet.data)
FungibleTokenPacketData data = json.unmarshal(packet.data)
trace, denom = parseICS20V1Denom(data.denom)
token = Token{
denom: denom
Expand All @@ -618,7 +623,7 @@ function refundTokens(packet: Packet) {
}
tokens = []Token{token}
} else if transferVersion == "ics20-2" {
FungibleTokenPacketDataV2 data = UnmarshalJSON(packet.data)
FungibleTokenPacketDataV2 data = protobuf.unmarshal(packet.data)
tokens = data.tokens
} else {
// should never be reached as transfer version must be negotiated to be either
Expand Down

0 comments on commit 89aec20

Please sign in to comment.