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

Account migration #206

Merged
merged 14 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
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
44 changes: 26 additions & 18 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,30 +425,13 @@ func NewStrideApp(
// monitoringModule := monitoringp.NewAppModule(appCodec, app.MonitoringKeeper)

// Note: must be above app.StakeibcKeeper

scopedRecordsKeeper := app.CapabilityKeeper.ScopeToModule(recordsmoduletypes.ModuleName)
app.ScopedRecordsKeeper = scopedRecordsKeeper

app.RecordsKeeper = *recordsmodulekeeper.NewKeeper(
appCodec,
keys[recordsmoduletypes.StoreKey],
keys[recordsmoduletypes.MemStoreKey],
app.GetSubspace(recordsmoduletypes.ModuleName),
scopedRecordsKeeper,
app.AccountKeeper,
)
recordsModule := recordsmodule.NewAppModule(appCodec, app.RecordsKeeper, app.AccountKeeper, app.BankKeeper)

app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper(
appCodec, keys[icacontrollertypes.StoreKey], app.GetSubspace(icacontrollertypes.SubModuleName),
app.IBCKeeper.ChannelKeeper, // may be replaced with middleware such as ics29 fee
app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
scopedICAControllerKeeper, app.MsgServiceRouter(),
)

app.InterchainqueryKeeper = interchainquerykeeper.NewKeeper(appCodec, keys[interchainquerytypes.StoreKey], app.IBCKeeper)
interchainQueryModule := interchainquery.NewAppModule(appCodec, app.InterchainqueryKeeper)

scopedIcacallbacksKeeper := app.CapabilityKeeper.ScopeToModule(icacallbacksmoduletypes.ModuleName)
app.ScopedIcacallbacksKeeper = scopedIcacallbacksKeeper
app.IcacallbacksKeeper = *icacallbacksmodulekeeper.NewKeeper(
Expand All @@ -461,6 +444,26 @@ func NewStrideApp(
app.ICAControllerKeeper,
)

app.InterchainqueryKeeper = interchainquerykeeper.NewKeeper(appCodec, keys[interchainquerytypes.StoreKey], app.IBCKeeper)
interchainQueryModule := interchainquery.NewAppModule(appCodec, app.InterchainqueryKeeper)


scopedRecordsKeeper := app.CapabilityKeeper.ScopeToModule(recordsmoduletypes.ModuleName)
app.ScopedRecordsKeeper = scopedRecordsKeeper
app.RecordsKeeper = *recordsmodulekeeper.NewKeeper(
appCodec,
keys[recordsmoduletypes.StoreKey],
keys[recordsmoduletypes.MemStoreKey],
app.GetSubspace(recordsmoduletypes.ModuleName),
scopedRecordsKeeper,
app.AccountKeeper,
app.TransferKeeper,
*app.IBCKeeper,
app.IcacallbacksKeeper,
)
recordsModule := recordsmodule.NewAppModule(appCodec, app.RecordsKeeper, app.AccountKeeper, app.BankKeeper)


scopedStakeibcKeeper := app.CapabilityKeeper.ScopeToModule(stakeibcmoduletypes.ModuleName)
app.ScopedStakeibcKeeper = scopedStakeibcKeeper
app.StakeibcKeeper = stakeibcmodulekeeper.NewKeeper(
Expand All @@ -475,7 +478,6 @@ func NewStrideApp(
app.ICAControllerKeeper,
*app.IBCKeeper,
scopedStakeibcKeeper,
app.TransferKeeper,
app.InterchainqueryKeeper,
app.RecordsKeeper,
app.StakingKeeper,
Expand All @@ -501,10 +503,16 @@ func NewStrideApp(

icacallbacksModule := icacallbacksmodule.NewAppModule(appCodec, app.IcacallbacksKeeper, app.AccountKeeper, app.BankKeeper)
// Register ICA calllbacks
// stakeibc
err = app.IcacallbacksKeeper.SetICACallbackHandler(stakeibcmoduletypes.ModuleName, app.StakeibcKeeper.ICACallbackHandler())
if err != nil {
return nil
}
// records
err = app.IcacallbacksKeeper.SetICACallbackHandler(recordsmoduletypes.ModuleName, app.RecordsKeeper.ICACallbackHandler())
if err != nil {
return nil
}

// this line is used by starport scaffolding # stargate/app/keeperDefinition

Expand Down
2 changes: 1 addition & 1 deletion deps/hermes
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ require (
github.com/dvsekhvalnov/jose2go v0.0.0-20200901110807-248326c1351b // indirect
github.com/felixge/httpsnoop v1.0.1 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-kit/kit v0.12.0 // indirect
github.com/go-kit/log v0.2.0 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
Expand All @@ -70,7 +69,6 @@ require (
github.com/gorilla/handlers v1.5.1 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/gtank/merlin v0.1.1 // indirect
github.com/gtank/ristretto255 v0.1.2 // indirect
Expand Down
5 changes: 0 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5
github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
Expand Down Expand Up @@ -510,8 +509,6 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t
github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 h1:lLT7ZLSzGLI08vc9cpd+tYmNWjdKDqyr/2L+f6U12Fk=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3/go.mod h1:o//XUCC/F+yRGJoPO/VU0GSB0f8Nhgmxx0VIRUvaC0w=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0=
github.com/gtank/merlin v0.1.1-0.20191105220539-8318aed1a79f/go.mod h1:T86dnYJhcGOh5BjZFCJWTDeTK7XW8uE+E21Cy/bIQ+s=
Expand Down Expand Up @@ -1533,8 +1530,6 @@ google.golang.org/genproto v0.0.0-20211028162531-8db9c33dc351/go.mod h1:5CzLGKJ6
google.golang.org/genproto v0.0.0-20211118181313-81c1377c94b1/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
google.golang.org/genproto v0.0.0-20211206160659-862468c7d6e0/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
google.golang.org/genproto v0.0.0-20220805133916-01dd62135a58 h1:sRT5xdTkj1Kbk30qbYC7VyMj73N5pZYsw6v+Nrzdhno=
google.golang.org/genproto v0.0.0-20220805133916-01dd62135a58/go.mod h1:iHe1svFLAZg9VWz891+QbRMwUv9O/1Ww+/mngYeThbc=
google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc h1:Nf+EdcTLHR8qDNN/KfkQL0u0ssxt9OhbaWCl5C0ucEI=
google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc/go.mod h1:dbqgFATTzChvnt+ujMdZwITVAJHFtfyN1qUhDqEiIlk=
google.golang.org/grpc v1.33.2 h1:EQyQC3sa8M+p6Ulc8yy9SWSS2GVwyRc83gAbG8lrl4o=
Expand Down
8 changes: 8 additions & 0 deletions proto/records/callbacks.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
syntax = "proto3";
package Stridelabs.stride.records;
option go_package = "github.com/Stride-Labs/stride/x/records/types";

// ---------------------- Transfer Callback ---------------------- //
message TransferCallback {
uint64 depositRecordId = 1;
}
3 changes: 2 additions & 1 deletion proto/stakeibc/host_zone.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import "records/genesis.proto";

option go_package = "github.com/Stride-Labs/stride/x/stakeibc/types";

// next id: 18
// next id: 19
message HostZone {
string chainId = 1;
string connectionId = 2;
Expand Down Expand Up @@ -41,5 +41,6 @@ message HostZone {
uint64 unbondingFrequency = 14;
//TODO(TEST-101) int to dec
uint64 stakedBal = 13;
string address = 18 [ (gogoproto.moretags) = "yaml:\"address\"" ];
reserved 15;
}
14 changes: 10 additions & 4 deletions scripts-local/test-utils/run_any_cli_command.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@ source ${SCRIPT_DIR}/../account_vars.sh


# transfer tokens to stride
# $GAIA_CMD tx ibc-transfer transfer transfer channel-0 stride1uk4ze0x4nvh4fk0xm4jdud58eqn4yxhrt52vv7 1000000uatom --from gval1 --chain-id GAIA -y --keyring-backend test
# $GAIA_CMD q tx F382BB9C7B9970C41F0BE5F04CB59B85A68CF360949A97C599DFA92A80CAD5D0
# exit
# $GAIA_CMD tx ibc-transfer transfer transfer channel-0 stride1uk4ze0x4nvh4fk0xm4jdud58eqn4yxhrt52vv7 333uatom --from gval1 --chain-id GAIA -y --keyring-backend test
# exit

# $STRIDE_CMD q stakeibc show-host-zone OSMO
$OSMO_CMD q bank balances osmo1cx04p5974f8hzh2lqev48kjrjugdxsxy7mzrd0eyweycpr90vk8q8d6f3h
exit
# $OSMO_CMD q bank balances osmo1cx04p5974f8hzh2lqev48kjrjugdxsxy7mzrd0eyweycpr90vk8q8d6f3h
# exit

# $STRIDE_CMD q ibc channel channels
# exit

$STRIDE_CMD q bank balances stride19uvw0azm9u0k6vqe4e22cga6kteskdqq3ulj6q
# $STRIDE_CMD q stakeibc list-host-zone
# exit
# $STRIDE_CMD tx stakeibc liquid-stake 10 uatom --keyring-backend test --from val1 -y --chain-id $STRIDE_CHAIN
# exit
$STRIDE_CMD q bank balances stride1755g4dkhpw73gz9h9nwhlcefc6sdf8kcmvcwrk4rxfrz8xpxxjms7savm8
exit


Expand Down
89 changes: 89 additions & 0 deletions scripts-local/test_upgrade.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/bin/bash

# kill previous networks
# loop three times in bash
echo "Killing previous networks..."
for i in {1..3}; do
make stop &> /dev/null
sleep 1
done

UPGRADE_NAME="v2"

set -eu
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source $SCRIPT_DIR/vars.sh

mkdir -p $SCRIPT_DIR/logs

CACHE="${1:-false}"

STRIDE_STATE=$SCRIPT_DIR/state/stride
STRIDE_LOGS=$SCRIPT_DIR/logs/stride.log
GAIA_STATE=$SCRIPT_DIR/state/gaia
GAIA_LOGS=$SCRIPT_DIR/logs/gaia.log
GAIA_LOGS_2=$SCRIPT_DIR/logs/gaia2.log
GAIA_LOGS_3=$SCRIPT_DIR/logs/gaia3.log
HERMES_LOGS=$SCRIPT_DIR/logs/hermes.log
ICQ_LOGS=$SCRIPT_DIR/logs/icq.log

# Stop processes and clear state and logs
make stop 2>/dev/null || true
rm -rf $SCRIPT_DIR/logs/*.log $SCRIPT_DIR/logs/temp

# Recreate each log file
for log in $STRIDE_LOGS $STRIDE_LOGS_2 $STRIDE_LOGS_3 $STRIDE_LOGS_4 $STRIDE_LOGS_5 $GAIA_LOGS $GAIA_LOGS_2 $HERMES_LOGS $ICQ_LOGS $JUNO_LOGS $TX_LOGS $KEYS_LOGS $OSMO_LOGS $RLY_GAIA_LOGS $RLY_OSMO_LOGS $RLY_JUNO_LOGS; do
touch $log
done

printf '\n%s' "Starting Stride, Gaia, Osmo, and Juno... "
nohup $STRIDE_CMD start | sed -r -u "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" > $STRIDE_LOGS 2>&1 &
nohup $STRIDE_CMD_2 start | sed -r -u "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" > $STRIDE_LOGS_2 2>&1 &
nohup $STRIDE_CMD_3 start | sed -r -u "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" > $STRIDE_LOGS_3 2>&1 &
nohup $STRIDE_CMD_4 start | sed -r -u "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" > $STRIDE_LOGS_4 2>&1 &
nohup $STRIDE_CMD_5 start | sed -r -u "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" > $STRIDE_LOGS_5 2>&1 &

( tail -f -n0 $STRIDE_LOGS & ) | grep -q "finalizing commit of block"
( tail -f -n0 $STRIDE_LOGS_2 & ) | grep -q "finalizing commit of block"
( tail -f -n0 $STRIDE_LOGS_3 & ) | grep -q "finalizing commit of block"
( tail -f -n0 $STRIDE_LOGS_4 & ) | grep -q "finalizing commit of block"
( tail -f -n0 $STRIDE_LOGS_5 & ) | grep -q "finalizing commit of block"
sleep 2
echo "Done"

echo "Done! Go get em.\n\n"

# Setup upgrade and cosmovisor directories
mkdir -p $SCRIPT_DIR/upgrades/cosmovisor/genesis/bin/
mkdir -p $SCRIPT_DIR/upgrades/cosmovisor/upgrades/$UPGRADE_NAME/bin/
mkdir -p $SCRIPT_DIR/state/stride/cosmovisor

rm -f $SCRIPT_DIR/upgrades/binaries/strided2
cp $SCRIPT_DIR/../build/strided $SCRIPT_DIR/upgrades/binaries/strided2
cp $SCRIPT_DIR/../build/strided $SCRIPT_DIR/upgrades/cosmovisor/genesis/bin/strided
cp $SCRIPT_DIR/../build/strided $SCRIPT_DIR/upgrades/cosmovisor/upgrades/$UPGRADE_NAME/bin/strided
cp $SCRIPT_DIR/../build/strided $SCRIPT_DIR/upgrades/binaries/strided1
cp $SCRIPT_DIR/../build/strided $SCRIPT_DIR/upgrades/binaries/strided2

printf '\n%s' "Starting Stride and Gaia... "
cp -r $SCRIPT_DIR/upgrades/cosmovisor/* $STATE/stride/cosmovisor/
nohup cosmovisor run start --home $STATE/stride | sed -r -u "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" > $STRIDE_LOGS 2>&1 &
nohup cosmovisor run start --home $STATE/stride2 | sed -r -u "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" > $STRIDE_LOGS_2 2>&1 &
nohup cosmovisor run start --home $STATE/stride3 | sed -r -u "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" > $STRIDE_LOGS_3 2>&1 &
nohup cosmovisor run start --home $STATE/stride4 | sed -r -u "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" > $STRIDE_LOGS_4 2>&1 &
nohup cosmovisor run start --home $STATE/stride5 | sed -r -u "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" > $STRIDE_LOGS_5 2>&1 &

( tail -f -n0 $STRIDE_LOGS & ) | grep -q "finalizing commit of block"
sleep 5
echo "Done"

# Create a copy of the state that can be used for the "cache" option
echo "Network is ready for transactions.\n"

# Add more detailed log files
$SCRIPT_DIR/create_logs.sh &

# Propose upgrades
bash $SCRIPT_DIR/upgrades/submit_upgrade.sh

tail -f $SCRIPT_DIR/logs/stride.log
50 changes: 36 additions & 14 deletions x/icacallbacks/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper"

"github.com/Stride-Labs/stride/x/icacallbacks/types"
recordstypes "github.com/Stride-Labs/stride/x/records/types"

channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"

Expand Down Expand Up @@ -87,37 +88,58 @@ func (k *Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capabilit
return k.scopedKeeper.ClaimCapability(ctx, cap, name)
}

func (k Keeper) CallRegisteredICACallback(ctx sdk.Context, modulePacket channeltypes.Packet, txMsgData *sdk.TxMsgData) error {
func (k Keeper) GetCallbackDataFromPacket(ctx sdk.Context, modulePacket channeltypes.Packet, callbackDataKey string) (cbd *types.CallbackData, found bool) {
asalzmann marked this conversation as resolved.
Show resolved Hide resolved
// get the relevant module from the channel and port
portID := modulePacket.GetSourcePort()
channelID := modulePacket.GetSourceChannel()
module, _, err := k.IBCKeeper.ChannelKeeper.LookupModuleByChannel(ctx, portID, channelID)
if err != nil {
return err
}
// fetch the callback data
callbackDataKey := types.PacketID(portID, channelID, modulePacket.Sequence)
callbackData, found := k.GetCallbackData(ctx, callbackDataKey)
if !found {
errMsg := fmt.Sprintf("callback data not found for portID: %s, channelID: %s, sequence: %d", portID, channelID, modulePacket.Sequence)
k.Logger(ctx).Error(errMsg)
return nil
k.Logger(ctx).Info(fmt.Sprintf("callback data not found for portID: %s, channelID: %s, sequence: %d", portID, channelID, modulePacket.Sequence))
sampocs marked this conversation as resolved.
Show resolved Hide resolved
return nil, false
} else {
k.Logger(ctx).Info(fmt.Sprintf("callback data found for portID: %s, channelID: %s, sequence: %d", portID, channelID, modulePacket.Sequence))
}
return &callbackData, true
}

func (k Keeper) GetICACallbackHandlerFromPacket(ctx sdk.Context, modulePacket channeltypes.Packet) (*types.ICACallbackHandler, error) {
module, _, err := k.IBCKeeper.ChannelKeeper.LookupModuleByChannel(ctx, modulePacket.GetSourcePort(), modulePacket.GetSourceChannel())
if err != nil {
k.Logger(ctx).Error(fmt.Sprintf("error LookupModuleByChannel for portID: %s, channelID: %s, sequence: %d", modulePacket.GetSourcePort(), modulePacket.GetSourceChannel(), modulePacket.Sequence))
return nil, err
}
// redirect transfer callbacks to the records module
// is there a better way to do this?
if module == "transfer" {
module = recordstypes.ModuleName
}
// fetch the callback function
callbackHandler, err := k.GetICACallbackHandler(module)
if err != nil {
errMsg := fmt.Sprintf("Callback handler does not exist for module %s | err: %s", module, err.Error())
k.Logger(ctx).Error(errMsg)
return sdkerrors.Wrapf(types.ErrCallbackHandlerNotFound, errMsg)
return nil, sdkerrors.Wrapf(types.ErrCallbackHandlerNotFound, "Callback handler does not exist for module %s | err: %s", module, err.Error())
}
return &callbackHandler, nil
}


func (k Keeper) CallRegisteredICACallback(ctx sdk.Context, modulePacket channeltypes.Packet, ack *channeltypes.Acknowledgement) error {
callbackDataKey := types.PacketID(modulePacket.GetSourcePort(), modulePacket.GetSourceChannel(), modulePacket.Sequence)
callbackData, found := k.GetCallbackDataFromPacket(ctx, modulePacket, callbackDataKey)
if !found {
return nil
}
callbackHandler, err := k.GetICACallbackHandlerFromPacket(ctx, modulePacket)
if err != nil {
k.Logger(ctx).Error(fmt.Sprintf("GetICACallbackHandlerFromPacket %s", err.Error()))
return err
}

// call the callback
if callbackHandler.HasICACallback(callbackData.CallbackId) {
if (*callbackHandler).HasICACallback(callbackData.CallbackId) {
k.Logger(ctx).Info(fmt.Sprintf("Calling callback for %s", callbackData.CallbackId))
// if acknowledgement is empty, then it is a timeout
err := callbackHandler.CallICACallback(ctx, callbackData.CallbackId, modulePacket, txMsgData, callbackData.CallbackArgs)
err := (*callbackHandler).CallICACallback(ctx, callbackData.CallbackId, modulePacket, ack, callbackData.CallbackArgs)
if err != nil {
errMsg := fmt.Sprintf("Error occured while calling ICACallback (%s) | err: %s", callbackData.CallbackId, err.Error())
k.Logger(ctx).Error(errMsg)
Expand Down
28 changes: 28 additions & 0 deletions x/icacallbacks/module_ibc.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package icacallbacks

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
porttypes "github.com/cosmos/ibc-go/v3/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v3/modules/core/exported"
"github.com/gogo/protobuf/proto"
"github.com/tendermint/tendermint/libs/log"

"github.com/Stride-Labs/stride/x/icacallbacks/keeper"
)
Expand Down Expand Up @@ -85,6 +90,29 @@ func (im IBCModule) NegotiateAppVersion(
return proposedVersion, nil
}

// GetTxMsgData returns the msgs from an ICA transaction and can be reused across authentication modules
func GetTxMsgData(ctx sdk.Context, ack channeltypes.Acknowledgement, logger log.Logger) (*sdk.TxMsgData, error) {
asalzmann marked this conversation as resolved.
Show resolved Hide resolved
txMsgData := &sdk.TxMsgData{}
switch response := ack.Response.(type) {
case *channeltypes.Acknowledgement_Result:
if len(response.Result) == 0 {
return nil, sdkerrors.Wrapf(channeltypes.ErrInvalidAcknowledgement, "acknowledgement result cannot be empty")
}
err := proto.Unmarshal(ack.GetResult(), txMsgData)
if err != nil {
logger.Error(fmt.Sprintf("cannot unmarshal ICS-27 tx message data: %s", err.Error()))
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-27 tx message data: %s", err.Error())
}
return txMsgData, nil
case *channeltypes.Acknowledgement_Error:
logger.Error(fmt.Sprintf("acknowledgement error: %s", response.Error))
return txMsgData, nil

default:
return nil, sdkerrors.Wrapf(channeltypes.ErrInvalidAcknowledgement, "unsupported acknowledgement response field type %T", response)
}
}

// ###################################################################################
// Required functions to satisfy interface but not implemented for ICA auth modules
// ###################################################################################
Expand Down
Loading