-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathget_program_accounts.go
65 lines (50 loc) · 2.75 KB
/
get_program_accounts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package rpc
import (
"context"
)
type GetProgramAccountsResponse JsonRpcResponse[GetProgramAccounts]
type GetProgramAccountsWithContextResponse JsonRpcResponse[GetProgramAccountsWithContext]
type GetProgramAccount struct {
Pubkey string `json:"pubkey"`
Account AccountInfo `json:"account"`
}
type GetProgramAccounts []GetProgramAccount
type GetProgramAccountsWithContext ValueWithContext[GetProgramAccounts]
// GetProgramAccountsConfig is a option config for `getProgramAccounts`
type GetProgramAccountsConfig struct {
Encoding AccountEncoding `json:"encoding,omitempty"`
Commitment Commitment `json:"commitment,omitempty"`
DataSlice *DataSlice `json:"dataSlice,omitempty"`
Filters []GetProgramAccountsConfigFilter `json:"filters,omitempty"`
}
type getProgramAccountsConfig struct {
GetProgramAccountsConfig
WithContext bool `json:"withContext,omitempty"`
}
// GetProgramAccountsConfigFilter you can set either MemCmp or DataSize but can be both, if needed, separate them into two
type GetProgramAccountsConfigFilter struct {
MemCmp *GetProgramAccountsConfigFilterMemCmp `json:"memcmp,omitempty"`
DataSize uint64 `json:"dataSize,omitempty"`
}
type GetProgramAccountsConfigFilterMemCmp struct {
Offset uint64 `json:"offset"`
Bytes string `json:"bytes"`
}
func (c *RpcClient) GetProgramAccounts(ctx context.Context, programId string) (JsonRpcResponse[GetProgramAccounts], error) {
return call[JsonRpcResponse[GetProgramAccounts]](c, ctx, "getProgramAccounts", programId)
}
func (c *RpcClient) GetProgramAccountsWithConfig(ctx context.Context, programId string, cfg GetProgramAccountsConfig) (JsonRpcResponse[GetProgramAccounts], error) {
return call[JsonRpcResponse[GetProgramAccounts]](c, ctx, "getProgramAccounts", programId, c.toInternalGetProgramAccountsConfig(cfg, false))
}
func (c *RpcClient) GetProgramAccountsWithContext(ctx context.Context, programId string) (JsonRpcResponse[GetProgramAccountsWithContext], error) {
return call[JsonRpcResponse[GetProgramAccountsWithContext]](c, ctx, "getProgramAccounts", programId, c.toInternalGetProgramAccountsConfig(GetProgramAccountsConfig{}, true))
}
func (c *RpcClient) GetProgramAccountsWithContextAndConfig(ctx context.Context, programId string, cfg GetProgramAccountsConfig) (JsonRpcResponse[GetProgramAccountsWithContext], error) {
return call[JsonRpcResponse[GetProgramAccountsWithContext]](c, ctx, "getProgramAccounts", programId, c.toInternalGetProgramAccountsConfig(cfg, true))
}
func (c *RpcClient) toInternalGetProgramAccountsConfig(cfg GetProgramAccountsConfig, withContext bool) getProgramAccountsConfig {
return getProgramAccountsConfig{
GetProgramAccountsConfig: cfg,
WithContext: withContext,
}
}