solana-go/rpc/getBlocks.go

38 lines
996 B
Go
Raw Normal View History

2021-07-01 04:18:42 -07:00
package rpc
import (
"context"
bin "github.com/dfuse-io/binary"
)
// GetBlocks returns a list of confirmed blocks between two slots.
// The result will be an array of u64 integers listing confirmed blocks
// between start_slot and either end_slot, if provided, or latest
// confirmed block, inclusive. Max range allowed is 500,000 slots.
//
// NEW: This method is only available in solana-core v1.7 or newer.
// Please use `getConfirmedBlocks` for solana-core v1.6.
2021-07-01 04:18:42 -07:00
func (cl *Client) GetBlocks(
ctx context.Context,
2021-07-09 08:56:15 -07:00
startSlot uint64,
endSlot *uint64, // optional
commitment CommitmentType, // optional
2021-07-01 04:27:39 -07:00
) (out *BlocksResult, err error) {
2021-07-01 04:18:42 -07:00
params := []interface{}{startSlot}
if endSlot != nil {
params = append(params, endSlot)
}
if commitment != "" {
params = append(params,
2021-07-11 09:08:29 -07:00
// TODO: provide commitment as string instead of object?
2021-07-01 04:18:42 -07:00
M{"commitment": commitment},
)
}
2021-07-20 12:29:06 -07:00
err = cl.rpcClient.CallForInto(ctx, &out, "getBlocks", params)
2021-07-01 04:18:42 -07:00
return
}
type BlocksResult []bin.Uint64