Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICS20v2: use protobuf encoding for packet data of v2 #1118

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading