Skip to content

Commit

Permalink
add query to get cctx error message
Browse files Browse the repository at this point in the history
  • Loading branch information
fbac committed Oct 3, 2024
1 parent 8758f27 commit 9d32695
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
17 changes: 17 additions & 0 deletions x/crosschain/keeper/cctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 93 in x/crosschain/keeper/cctx.go

View check run for this annotation

Codecov / codecov/patch

x/crosschain/keeper/cctx.go#L93

Added line #L93 was not covered by tests
}

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))
Expand Down
3 changes: 3 additions & 0 deletions x/crosschain/keeper/cctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

})
Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/types/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down

0 comments on commit 9d32695

Please sign in to comment.