forked from blocto/solana-go-sdk
/
get_latest_blockhash.go
45 lines (37 loc) · 1.72 KB
/
get_latest_blockhash.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
package rpc
import (
"context"
)
// GetLatestBlockhashResponse is a full raw rpc response of `getLatestBlockhash`
type GetLatestBlockhashResponse struct {
GeneralResponse
Result GetLatestBlockhashResult `json:"result"`
}
// GetLatestBlockhashResult is a part of raw rpc response of `getLatestBlockhash`
type GetLatestBlockhashResult struct {
Context Context `json:"context"`
Value GetLatestBlockhashValue `json:"value"`
}
// GetLatestBlockhashResult is a part of raw rpc response of `getLatestBlockhash`
type GetLatestBlockhashValue struct {
Blockhash string `json:"blockhash"`
LatestValidBlockHeight uint64 `json:"lastValidBlockHeight"`
}
// GetLatestBlockhashConfig is a option config for `getLatestBlockhash`
type GetLatestBlockhashConfig struct {
Commitment Commitment `json:"commitment,omitempty"`
}
// NEW: This method is only available in solana-core v1.9 or newer. Please use getRecentBlockhash for solana-core v1.8
// GetLatestBlockhash returns the latest blockhash
func (c *RpcClient) GetLatestBlockhash(ctx context.Context) (GetLatestBlockhashResponse, error) {
return c.processGetLatestBlockhash(c.Call(ctx, "getLatestBlockhash"))
}
// NEW: This method is only available in solana-core v1.9 or newer. Please use getRecentBlockhash for solana-core v1.8
// GetLatestBlockhashWithConfig returns the latest blockhash
func (c *RpcClient) GetLatestBlockhashWithConfig(ctx context.Context, cfg GetLatestBlockhashConfig) (GetLatestBlockhashResponse, error) {
return c.processGetLatestBlockhash(c.Call(ctx, "getLatestBlockhash", cfg))
}
func (c *RpcClient) processGetLatestBlockhash(body []byte, rpcErr error) (res GetLatestBlockhashResponse, err error) {
err = c.processRpcCall(body, rpcErr, &res)
return
}