Skip to content

Commit

Permalink
add ack cb
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Sep 26, 2023
1 parent 6ce558b commit 8bb190b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,8 @@ func New(
var icaControllerStack porttypes.IBCModule
icaControllerStack = icacontroller.NewIBCMiddleware(icaAuthIBCModule, app.ICAControllerKeeper)
icaControllerStack = ibcfee.NewIBCMiddleware(icaControllerStack, app.IBCFeeKeeper)
// Since the callbacks middleware itself is an ics4wrapper, it needs to be passed to the ica controller keeper
app.ICAControllerKeeper.WithICS4Wrapper(icaControllerStack.(porttypes.Middleware))
const maxCallbackGas = uint64(1000000)
icaControllerStack = ibccallbacks.NewIBCMiddleware(icaControllerStack, app.IBCFeeKeeper, app.CronosKeeper, maxCallbackGas)

Expand Down
20 changes: 20 additions & 0 deletions x/cronos/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"fmt"
"math/big"
"strings"

"cosmossdk.io/errors"
Expand All @@ -20,6 +21,7 @@ import (
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
"github.com/crypto-org-chain/cronos/v2/x/cronos/types"
"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
// this line is used by starport scaffolding # ibc/keeper/import
)

Expand Down Expand Up @@ -292,6 +294,24 @@ func (k Keeper) IBCOnAcknowledgementPacketCallback(
contractAddress,
packetSenderAddress string,
) error {
relayerAddr := common.BytesToAddress(relayer.Bytes())
nonce := k.evmKeeper.GetNonce(ctx, relayerAddr)
precompileAddr := common.HexToAddress(contractAddress)
msg := ethtypes.NewMessage(
types.EVMModuleAddress,
&precompileAddr,
nonce,
big.NewInt(0), // amount
DefaultGasCap,
big.NewInt(0), nil, nil, // gasPrice
packet.Data,
nil, // accessList
false, // isFake
)
_, err := k.evmKeeper.ApplyMessage(ctx, msg, nil, true)
if err != nil {
return err
}
// return k.processMockCallback(ctx, callbacktypes.CallbackTypeAcknowledgementPacket, packetSenderAddress)
return nil
}
Expand Down
1 change: 1 addition & 0 deletions x/cronos/keeper/precompiles/ica.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ func (ic *IcaContract) Run(evm *vm.EVM, contract *vm.Contract, readonly bool) ([
icaMsgData := icatypes.InterchainAccountPacketData{
Type: icatypes.EXECUTE_TX,
Data: data,
Memo: fmt.Sprintf(`{"src_callback": {"address": "%s"}}`, icaContractAddress.String()),
}
timeoutDuration := time.Duration(timeout.Uint64())
seq := uint64(0)
Expand Down

0 comments on commit 8bb190b

Please sign in to comment.