-
Notifications
You must be signed in to change notification settings - Fork 4
/
data_source_epoch.go
62 lines (54 loc) · 1.65 KB
/
data_source_epoch.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
package solana
import (
"context"
"fmt"
"github.com/gagliardetto/solana-go/rpc"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceEpoch() *schema.Resource {
return &schema.Resource{
Description: "[(JSON RPC)](https://docs.solana.com/developing/clients/jsonrpc-api#getepochinfo) Provides all of the relevant information about the current epoch.",
Read: dataSourceEpochRead,
Schema: map[string]*schema.Schema{
"absolute_slot": {
Type: schema.TypeInt,
Description: "The current absolute slot in the epoch.",
Computed: true,
},
"block_height": {
Type: schema.TypeInt,
Description: "The current block height.",
Computed: true,
},
"epoch": {
Type: schema.TypeInt,
Description: "The current epoch count.",
Computed: true,
},
"slot_index": {
Type: schema.TypeInt,
Description: "The current slot relative to the start of the current epoch.",
Computed: true,
},
"slots_in_epoch": {
Type: schema.TypeInt,
Description: "The number of slots in this epoch.",
Computed: true,
},
},
}
}
func dataSourceEpochRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*providerConfig).rpcClient
res, err := client.GetEpochInfo(context.Background(), rpc.CommitmentRecent)
if err != nil {
return err
}
d.SetId(fmt.Sprintf("epoch:%d", uint64(res.Epoch)))
d.Set("absolute_slot", uint64(res.AbsoluteSlot))
d.Set("block_height", uint64(res.TransactionCount))
d.Set("epoch", uint64(res.Epoch))
d.Set("slot_index", uint64(res.SlotIndex))
d.Set("slots_in_epoch", uint64(res.SlotsInEpoch))
return nil
}