diff --git a/client/rpc_get_slot_leaders.go b/client/rpc_get_slot_leaders.go new file mode 100644 index 00000000..0c077cc3 --- /dev/null +++ b/client/rpc_get_slot_leaders.go @@ -0,0 +1,18 @@ +package client + +import ( + "context" + + "github.com/blocto/solana-go-sdk/rpc" +) + +// GetSlotLeaders returns the slot leaders for a given slot range +// (limit: 1~5000) +func (c *Client) GetSlotLeaders(ctx context.Context, startSlot uint64, limit uint64) ([]string, error) { + return process( + func() (rpc.JsonRpcResponse[[]string], error) { + return c.RpcClient.GetSlotLeaders(ctx, startSlot, limit) + }, + forward[[]string], + ) +} diff --git a/client/rpc_get_slot_leaders_test.go b/client/rpc_get_slot_leaders_test.go new file mode 100644 index 00000000..084e460c --- /dev/null +++ b/client/rpc_get_slot_leaders_test.go @@ -0,0 +1,37 @@ +package client + +import ( + "context" + "testing" + + "github.com/blocto/solana-go-sdk/internal/client_test" +) + +func TestClient_GetSlotLeaders(t *testing.T) { + client_test.TestAll( + t, + []client_test.Param{ + { + RequestBody: `{"jsonrpc":"2.0", "id":1, "method": "getSlotLeaders", "params": [264431722, 10]}`, + ResponseBody: `{"jsonrpc":"2.0","result":["DUND26mEDfFeaPsVof3YvbXDRvpuQX7HMUJrLgEWzYw4","DUND26mEDfFeaPsVof3YvbXDRvpuQX7HMUJrLgEWzYw4","3JotfSFPaod4KVK7nj7ULvcq5PjUBdZNVGracNkJNhrt","3JotfSFPaod4KVK7nj7ULvcq5PjUBdZNVGracNkJNhrt","3JotfSFPaod4KVK7nj7ULvcq5PjUBdZNVGracNkJNhrt","3JotfSFPaod4KVK7nj7ULvcq5PjUBdZNVGracNkJNhrt","BXAxLMMMUNYfC1z166VjWHR3WjTmqzLxB837o5ghmRtH","BXAxLMMMUNYfC1z166VjWHR3WjTmqzLxB837o5ghmRtH","BXAxLMMMUNYfC1z166VjWHR3WjTmqzLxB837o5ghmRtH","BXAxLMMMUNYfC1z166VjWHR3WjTmqzLxB837o5ghmRtH"],"id":1}`, + F: func(url string) (any, error) { + c := NewClient(url) + return c.GetSlotLeaders(context.TODO(), 264431722, 10) + }, + ExpectedValue: []string{ + "DUND26mEDfFeaPsVof3YvbXDRvpuQX7HMUJrLgEWzYw4", + "DUND26mEDfFeaPsVof3YvbXDRvpuQX7HMUJrLgEWzYw4", + "3JotfSFPaod4KVK7nj7ULvcq5PjUBdZNVGracNkJNhrt", + "3JotfSFPaod4KVK7nj7ULvcq5PjUBdZNVGracNkJNhrt", + "3JotfSFPaod4KVK7nj7ULvcq5PjUBdZNVGracNkJNhrt", + "3JotfSFPaod4KVK7nj7ULvcq5PjUBdZNVGracNkJNhrt", + "BXAxLMMMUNYfC1z166VjWHR3WjTmqzLxB837o5ghmRtH", + "BXAxLMMMUNYfC1z166VjWHR3WjTmqzLxB837o5ghmRtH", + "BXAxLMMMUNYfC1z166VjWHR3WjTmqzLxB837o5ghmRtH", + "BXAxLMMMUNYfC1z166VjWHR3WjTmqzLxB837o5ghmRtH", + }, + ExpectedError: nil, + }, + }, + ) +} diff --git a/rpc/get_slot_leaders.go b/rpc/get_slot_leaders.go new file mode 100644 index 00000000..b8116fce --- /dev/null +++ b/rpc/get_slot_leaders.go @@ -0,0 +1,11 @@ +package rpc + +import "context" + +type GetSlotLeadersResponse JsonRpcResponse[[]string] + +// GetSlotLeaders returns the slot leaders for a given slot range +// (limit: 1~5000) +func (c *RpcClient) GetSlotLeaders(ctx context.Context, startSlot uint64, limit uint64) (JsonRpcResponse[[]string], error) { + return call[JsonRpcResponse[[]string]](c, ctx, "getSlotLeaders", startSlot, limit) +} diff --git a/rpc/get_slot_leaders_test.go b/rpc/get_slot_leaders_test.go new file mode 100644 index 00000000..d94e9802 --- /dev/null +++ b/rpc/get_slot_leaders_test.go @@ -0,0 +1,42 @@ +package rpc + +import ( + "context" + "testing" + + "github.com/blocto/solana-go-sdk/internal/client_test" +) + +func TestGetSlotLeaders(t *testing.T) { + client_test.TestAll( + t, + []client_test.Param{ + { + RequestBody: `{"jsonrpc":"2.0", "id":1, "method": "getSlotLeaders", "params": [264431722, 10]}`, + ResponseBody: `{"jsonrpc":"2.0","result":["DUND26mEDfFeaPsVof3YvbXDRvpuQX7HMUJrLgEWzYw4","DUND26mEDfFeaPsVof3YvbXDRvpuQX7HMUJrLgEWzYw4","3JotfSFPaod4KVK7nj7ULvcq5PjUBdZNVGracNkJNhrt","3JotfSFPaod4KVK7nj7ULvcq5PjUBdZNVGracNkJNhrt","3JotfSFPaod4KVK7nj7ULvcq5PjUBdZNVGracNkJNhrt","3JotfSFPaod4KVK7nj7ULvcq5PjUBdZNVGracNkJNhrt","BXAxLMMMUNYfC1z166VjWHR3WjTmqzLxB837o5ghmRtH","BXAxLMMMUNYfC1z166VjWHR3WjTmqzLxB837o5ghmRtH","BXAxLMMMUNYfC1z166VjWHR3WjTmqzLxB837o5ghmRtH","BXAxLMMMUNYfC1z166VjWHR3WjTmqzLxB837o5ghmRtH"],"id":1}`, + F: func(url string) (any, error) { + c := NewRpcClient(url) + return c.GetSlotLeaders(context.TODO(), 264431722, 10) + }, + ExpectedValue: JsonRpcResponse[[]string]{ + JsonRpc: "2.0", + Id: 1, + Error: nil, + Result: []string{ + "DUND26mEDfFeaPsVof3YvbXDRvpuQX7HMUJrLgEWzYw4", + "DUND26mEDfFeaPsVof3YvbXDRvpuQX7HMUJrLgEWzYw4", + "3JotfSFPaod4KVK7nj7ULvcq5PjUBdZNVGracNkJNhrt", + "3JotfSFPaod4KVK7nj7ULvcq5PjUBdZNVGracNkJNhrt", + "3JotfSFPaod4KVK7nj7ULvcq5PjUBdZNVGracNkJNhrt", + "3JotfSFPaod4KVK7nj7ULvcq5PjUBdZNVGracNkJNhrt", + "BXAxLMMMUNYfC1z166VjWHR3WjTmqzLxB837o5ghmRtH", + "BXAxLMMMUNYfC1z166VjWHR3WjTmqzLxB837o5ghmRtH", + "BXAxLMMMUNYfC1z166VjWHR3WjTmqzLxB837o5ghmRtH", + "BXAxLMMMUNYfC1z166VjWHR3WjTmqzLxB837o5ghmRtH", + }, + }, + ExpectedError: nil, + }, + }, + ) +}