From 9d3269545c394fe2b442f963c867ea5e76dd7de7 Mon Sep 17 00:00:00 2001 From: Francisco de Borja Aranda Castillejo Date: Thu, 3 Oct 2024 08:38:43 +0200 Subject: [PATCH] add query to get cctx error message --- go.mod | 1 - x/crosschain/keeper/cctx.go | 17 +++++++++++++++++ x/crosschain/keeper/cctx_test.go | 3 +++ x/crosschain/types/status_test.go | 2 +- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 8842e1f2d7..7625fc2047 100644 --- a/go.mod +++ b/go.mod @@ -337,7 +337,6 @@ require ( github.com/bnb-chain/tss-lib v1.5.0 github.com/showa-93/go-mask v0.6.2 github.com/tonkeeper/tongo v1.9.3 - gotest.tools v2.2.0+incompatible ) require ( diff --git a/x/crosschain/keeper/cctx.go b/x/crosschain/keeper/cctx.go index f2234362f0..0c633345b8 100644 --- a/x/crosschain/keeper/cctx.go +++ b/x/crosschain/keeper/cctx.go @@ -81,6 +81,23 @@ func (k Keeper) GetCrossChainTx(ctx sdk.Context, index string) (val types.CrossC return val, true } +// GetCrossChainTxError returns the error message for a given cctx index. +func (k Keeper) GetCrossChainTxError(ctx sdk.Context, index string) (errMsg string, found bool) { + var cctx types.CrossChainTx + + p := types.KeyPrefix(fmt.Sprintf("%s", types.CCTXKey)) + store := prefix.NewStore(ctx.KVStore(k.storeKey), p) + + b := store.Get(types.KeyPrefix(index)) + if b == nil { + return "", false + } + + k.cdc.MustUnmarshal(b, &cctx) + + return cctx.CctxStatus.ErrorMessage, true +} + // GetAllCrossChainTx returns all cctxs func (k Keeper) GetAllCrossChainTx(ctx sdk.Context) (list []types.CrossChainTx) { p := types.KeyPrefix(fmt.Sprintf("%s", types.CCTXKey)) diff --git a/x/crosschain/keeper/cctx_test.go b/x/crosschain/keeper/cctx_test.go index 8a51b4cf2a..10a70883d5 100644 --- a/x/crosschain/keeper/cctx_test.go +++ b/x/crosschain/keeper/cctx_test.go @@ -169,6 +169,9 @@ func TestCCTXs(t *testing.T) { send, found := keeper.GetCrossChainTx(ctx, s.Index) require.True(t, found) require.Equal(t, s, send) + err, found := keeper.GetCrossChainTxError(ctx, s.Index) + require.True(t, found) + require.Equal(t, "", err) } }) diff --git a/x/crosschain/types/status_test.go b/x/crosschain/types/status_test.go index 06a101bb72..93b1a2c8b0 100644 --- a/x/crosschain/types/status_test.go +++ b/x/crosschain/types/status_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "gotest.tools/assert" "github.com/zeta-chain/node/x/crosschain/types" )