Skip to content

Commit

Permalink
json unmarshal and base64 decode for dapps
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Sep 27, 2023
1 parent 5052c3b commit 0960e47
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 3 additions & 1 deletion integration_tests/test_ica_precompile.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ def submit_msgs_ro(func, str):
assert tcontract.caller.getLastAckSeq() == seq
balance -= amt
ack = tcontract.caller.getLastAck()
assert ack == b"\x12&\n$/cosmos.bank.v1beta1.MsgSendResponse", ack
assert ack == tcontract.caller.acknowledgement(seq)
assert cli_host.balance(ica_address, denom=denom) == balance
seq = 2
Expand All @@ -209,4 +210,5 @@ def submit_msgs_ro(func, str):
balance -= amt1
assert cli_host.balance(ica_address, denom=denom) == balance
ack = tcontract.caller.getLastAck()
assert ack == tcontract.caller.acknowledgement(seq)
expected = b"\x12&\n$/cosmos.bank.v1beta1.MsgSendResponse\x12-\n+/cosmos.staking.v1beta1.MsgDelegateResponse" # noqa: E501
assert ack == expected, ack
19 changes: 18 additions & 1 deletion x/cronos/keeper/keeper.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper

import (
"encoding/json"
"fmt"
"math/big"
"strings"
Expand Down Expand Up @@ -282,6 +283,14 @@ func (k Keeper) RegisterOrUpdateTokenMapping(ctx sdk.Context, msg *types.MsgUpda
return nil
}

type IncentivizedAcknowledgement struct {
AppAcknowledgement []byte `json:"app_acknowledgement"`
}

type PacketResult struct {
Result []byte `json:"result"`
}

func (k Keeper) onPacketResult(
ctx sdk.Context,
packet channeltypes.Packet,
Expand All @@ -296,7 +305,15 @@ func (k Keeper) onPacketResult(
}
sender := common.BytesToAddress(senderAddr.Bytes())
precompileAddr := common.HexToAddress(contractAddress)
data, err := cronosprecompiles.OnPacketResult(packet.Sequence, sender, acknowledgement)
var ack IncentivizedAcknowledgement
if err := json.Unmarshal(acknowledgement, &ack); err != nil {
return err
}
var res PacketResult
if err := json.Unmarshal(ack.AppAcknowledgement, &res); err != nil {
return err
}
data, err := cronosprecompiles.OnPacketResult(packet.Sequence, sender, res.Result)
if err != nil {
return err
}
Expand Down

0 comments on commit 0960e47

Please sign in to comment.