forked from dmitrymomot/solana-go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpc_get_balance.go
57 lines (49 loc) · 1.73 KB
/
rpc_get_balance.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
package client
import (
"context"
"github.com/EntySquare/solana-go-sdk/rpc"
)
type GetBalanceConfig struct {
Commitment rpc.Commitment
}
func (c GetBalanceConfig) toRpc() rpc.GetBalanceConfig {
return rpc.GetBalanceConfig{
Commitment: c.Commitment,
}
}
// GetBalance fetch users lamports(SOL) balance
func (c *Client) GetBalance(ctx context.Context, base58Addr string) (uint64, error) {
return process(
func() (rpc.JsonRpcResponse[rpc.ValueWithContext[uint64]], error) {
return c.RpcClient.GetBalance(ctx, base58Addr)
},
value[uint64],
)
}
// GetBalanceWithConfig fetch users lamports(SOL) balance with specific commitment
func (c *Client) GetBalanceWithConfig(ctx context.Context, base58Addr string, cfg GetBalanceConfig) (uint64, error) {
return process(
func() (rpc.JsonRpcResponse[rpc.ValueWithContext[uint64]], error) {
return c.RpcClient.GetBalanceWithConfig(ctx, base58Addr, cfg.toRpc())
},
value[uint64],
)
}
// GetBalanceAndContext fetch users lamports(SOL) balance
func (c *Client) GetBalanceAndContext(ctx context.Context, base58Addr string) (rpc.ValueWithContext[uint64], error) {
return process(
func() (rpc.JsonRpcResponse[rpc.ValueWithContext[uint64]], error) {
return c.RpcClient.GetBalance(ctx, base58Addr)
},
forward[rpc.ValueWithContext[uint64]],
)
}
// GetBalanceAndContextWithConfig fetch users lamports(SOL) balance with specific commitment
func (c *Client) GetBalanceAndContextWithConfig(ctx context.Context, base58Addr string, cfg GetBalanceConfig) (rpc.ValueWithContext[uint64], error) {
return process(
func() (rpc.JsonRpcResponse[rpc.ValueWithContext[uint64]], error) {
return c.RpcClient.GetBalanceWithConfig(ctx, base58Addr, cfg.toRpc())
},
forward[rpc.ValueWithContext[uint64]],
)
}