diff --git a/contrib/rpcimportable/go.mod b/contrib/rpcimportable/go.mod new file mode 100644 index 0000000000..8f2ed43abc --- /dev/null +++ b/contrib/rpcimportable/go.mod @@ -0,0 +1,12 @@ +module github.com/zeta-chain/node/contrib/rpcimportable + +go 1.22.5 + +require github.com/zeta-chain/node v0.0.0-20240903163921-74f1ab59c658 // indirect + +replace ( + github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 +) + +// uncomment this for local testing/development +// replace github.com/zeta-chain/node => ../.. \ No newline at end of file diff --git a/contrib/rpcimportable/go.sum b/contrib/rpcimportable/go.sum new file mode 100644 index 0000000000..8e3117f269 --- /dev/null +++ b/contrib/rpcimportable/go.sum @@ -0,0 +1,3 @@ +github.com/zeta-chain/node v0.0.0-20240903163921-74f1ab59c658 h1:+KzsEBBWfxAMqMjwOcivdpSHPncDSMU3yw7oIG5YJAw= +github.com/zeta-chain/node v0.0.0-20240903163921-74f1ab59c658/go.mod h1:XJj15D2+sgtX3wqx1O85A0bKUI3srKyZwkxdcfgoK6I= +github.com/zeta-chain/node v1.2.1/go.mod h1:z72YVX6jPPst8K06l0LTKORJXN7XB1RKUiliU52Cwk0= diff --git a/contrib/rpcimportable/rpcimportable_test.go b/contrib/rpcimportable/rpcimportable_test.go new file mode 100644 index 0000000000..b2bc8959a5 --- /dev/null +++ b/contrib/rpcimportable/rpcimportable_test.go @@ -0,0 +1,11 @@ +package rpcimportable + +import ( + "testing" + + "github.com/zeta-chain/node/pkg/rpc" +) + +func TestRPCImportable(t *testing.T) { + _ = rpc.Clients{} +} diff --git a/pkg/rpc/clients_crosschain.go b/pkg/rpc/clients_crosschain.go index 30d9c9c926..f1ef8f5e34 100644 --- a/pkg/rpc/clients_crosschain.go +++ b/pkg/rpc/clients_crosschain.go @@ -2,15 +2,12 @@ package rpc import ( "context" - "sort" "cosmossdk.io/errors" - "github.com/cosmos/cosmos-sdk/types/query" "google.golang.org/grpc" "github.com/zeta-chain/node/pkg/chains" "github.com/zeta-chain/node/x/crosschain/types" - "github.com/zeta-chain/node/zetaclient/chains/interfaces" ) // 32MB @@ -157,38 +154,3 @@ func (c *Clients) GetInboundTrackersForChain(ctx context.Context, chainID int64) return resp.InboundTracker, nil } - -// GetAllOutboundTrackerByChain returns all outbound trackers for a chain -func (c *Clients) GetAllOutboundTrackerByChain( - ctx context.Context, - chainID int64, - order interfaces.Order, -) ([]types.OutboundTracker, error) { - in := &types.QueryAllOutboundTrackerByChainRequest{ - Chain: chainID, - Pagination: &query.PageRequest{ - Key: nil, - Offset: 0, - Limit: 2000, - CountTotal: false, - Reverse: false, - }, - } - - resp, err := c.Crosschain.OutboundTrackerAllByChain(ctx, in) - if err != nil { - return nil, errors.Wrap(err, "failed to get all outbound trackers") - } - - if order == interfaces.Ascending { - sort.SliceStable(resp.OutboundTracker, func(i, j int) bool { - return resp.OutboundTracker[i].Nonce < resp.OutboundTracker[j].Nonce - }) - } else if order == interfaces.Descending { - sort.SliceStable(resp.OutboundTracker, func(i, j int) bool { - return resp.OutboundTracker[i].Nonce > resp.OutboundTracker[j].Nonce - }) - } - - return resp.OutboundTracker, nil -} diff --git a/pkg/rpc/clients_test.go b/pkg/rpc/clients_test.go index ca5abf0d92..9e14266770 100644 --- a/pkg/rpc/clients_test.go +++ b/pkg/rpc/clients_test.go @@ -12,7 +12,6 @@ import ( tmtypes "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/query" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/stretchr/testify/require" @@ -27,7 +26,6 @@ import ( crosschaintypes "github.com/zeta-chain/node/x/crosschain/types" lightclienttypes "github.com/zeta-chain/node/x/lightclient/types" observertypes "github.com/zeta-chain/node/x/observer/types" - "github.com/zeta-chain/node/zetaclient/chains/interfaces" ) const skipMethod = "skip" @@ -688,44 +686,6 @@ func TestZetacore_GetOutboundTracker(t *testing.T) { require.Equal(t, expectedOutput.OutboundTracker, *resp) } -func TestZetacore_GetAllOutboundTrackerByChain(t *testing.T) { - ctx := context.Background() - - chain := chains.BscMainnet - expectedOutput := crosschaintypes.QueryAllOutboundTrackerByChainResponse{ - OutboundTracker: []crosschaintypes.OutboundTracker{ - { - Index: "tracker23456", - ChainId: chain.ChainId, - Nonce: 123456, - HashList: nil, - }, - }, - } - input := crosschaintypes.QueryAllOutboundTrackerByChainRequest{ - Chain: chain.ChainId, - Pagination: &query.PageRequest{ - Key: nil, - Offset: 0, - Limit: 2000, - CountTotal: false, - Reverse: false, - }, - } - method := "/zetachain.zetacore.crosschain.Query/OutboundTrackerAllByChain" - setupMockServer(t, crosschaintypes.RegisterQueryServer, method, input, expectedOutput) - - client := setupZetacoreClients(t) - - resp, err := client.GetAllOutboundTrackerByChain(ctx, chain.ChainId, interfaces.Ascending) - require.NoError(t, err) - require.Equal(t, expectedOutput.OutboundTracker, resp) - - resp, err = client.GetAllOutboundTrackerByChain(ctx, chain.ChainId, interfaces.Descending) - require.NoError(t, err) - require.Equal(t, expectedOutput.OutboundTracker, resp) -} - func TestZetacore_GetPendingNoncesByChain(t *testing.T) { ctx := context.Background() diff --git a/zetaclient/zetacore/client_crosschain.go b/zetaclient/zetacore/client_crosschain.go new file mode 100644 index 0000000000..2f028752e9 --- /dev/null +++ b/zetaclient/zetacore/client_crosschain.go @@ -0,0 +1,46 @@ +package zetacore + +import ( + "context" + "sort" + + "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/types/query" + "github.com/zeta-chain/node/x/crosschain/types" + "github.com/zeta-chain/node/zetaclient/chains/interfaces" +) + +// GetAllOutboundTrackerByChain returns all outbound trackers for a chain +func (c *Client) GetAllOutboundTrackerByChain( + ctx context.Context, + chainID int64, + order interfaces.Order, +) ([]types.OutboundTracker, error) { + in := &types.QueryAllOutboundTrackerByChainRequest{ + Chain: chainID, + Pagination: &query.PageRequest{ + Key: nil, + Offset: 0, + Limit: 2000, + CountTotal: false, + Reverse: false, + }, + } + + resp, err := c.Crosschain.OutboundTrackerAllByChain(ctx, in) + if err != nil { + return nil, errors.Wrap(err, "failed to get all outbound trackers") + } + + if order == interfaces.Ascending { + sort.SliceStable(resp.OutboundTracker, func(i, j int) bool { + return resp.OutboundTracker[i].Nonce < resp.OutboundTracker[j].Nonce + }) + } else if order == interfaces.Descending { + sort.SliceStable(resp.OutboundTracker, func(i, j int) bool { + return resp.OutboundTracker[i].Nonce > resp.OutboundTracker[j].Nonce + }) + } + + return resp.OutboundTracker, nil +} diff --git a/zetaclient/zetacore/client_test.go b/zetaclient/zetacore/client_test.go index 060d96515d..024ea9cce9 100644 --- a/zetaclient/zetacore/client_test.go +++ b/zetaclient/zetacore/client_test.go @@ -9,12 +9,15 @@ import ( cosmosclient "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/testutil/mock" "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/golang/mock/gomock" "github.com/rs/zerolog" "github.com/stretchr/testify/require" feemarkettypes "github.com/zeta-chain/ethermint/x/feemarket/types" + "github.com/zeta-chain/node/pkg/chains" + "github.com/zeta-chain/node/zetaclient/chains/interfaces" keyinterfaces "github.com/zeta-chain/node/zetaclient/keys/interfaces" "go.nhat.io/grpcmock" "go.nhat.io/grpcmock/planner" @@ -189,3 +192,41 @@ func TestZetacore_GetZetaHotKeyBalance(t *testing.T) { require.Error(t, err) require.Equal(t, types.ZeroInt(), resp) } + +func TestZetacore_GetAllOutboundTrackerByChain(t *testing.T) { + ctx := context.Background() + + chain := chains.BscMainnet + expectedOutput := crosschaintypes.QueryAllOutboundTrackerByChainResponse{ + OutboundTracker: []crosschaintypes.OutboundTracker{ + { + Index: "tracker23456", + ChainId: chain.ChainId, + Nonce: 123456, + HashList: nil, + }, + }, + } + input := crosschaintypes.QueryAllOutboundTrackerByChainRequest{ + Chain: chain.ChainId, + Pagination: &query.PageRequest{ + Key: nil, + Offset: 0, + Limit: 2000, + CountTotal: false, + Reverse: false, + }, + } + method := "/zetachain.zetacore.crosschain.Query/OutboundTrackerAllByChain" + setupMockServer(t, crosschaintypes.RegisterQueryServer, method, input, expectedOutput) + + client := setupZetacoreClient(t) + + resp, err := client.GetAllOutboundTrackerByChain(ctx, chain.ChainId, interfaces.Ascending) + require.NoError(t, err) + require.Equal(t, expectedOutput.OutboundTracker, resp) + + resp, err = client.GetAllOutboundTrackerByChain(ctx, chain.ChainId, interfaces.Descending) + require.NoError(t, err) + require.Equal(t, expectedOutput.OutboundTracker, resp) +}