-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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], | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}, | ||
}, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}, | ||
}, | ||
) | ||
} |