-
Notifications
You must be signed in to change notification settings - Fork 4
/
data_source_supply.go
50 lines (42 loc) · 1.25 KB
/
data_source_supply.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
package solana
import (
"context"
"fmt"
"github.com/gagliardetto/solana-go/rpc"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceSupply() *schema.Resource {
return &schema.Resource{
Description: "[(JSON RPC)](https://docs.solana.com/developing/clients/jsonrpc-api#getsupply) Provides information about the current supply on the network.",
Read: dataSourceSupplyRead,
Schema: map[string]*schema.Schema{
"total": {
Type: schema.TypeInt,
Description: "Total supply of lamports.",
Computed: true,
},
"circulating": {
Type: schema.TypeInt,
Description: "Circulating supply in lamports.",
Computed: true,
},
"non_circulating": {
Type: schema.TypeInt,
Description: "Non-circulating supply in lamports.",
Computed: true,
},
},
}
}
func dataSourceSupplyRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*providerConfig).rpcClient
res, err := client.GetSupply(context.Background(), rpc.CommitmentRecent)
if err != nil {
return err
}
d.SetId(fmt.Sprintf("supply:%d", res.Value.Total))
d.Set("total", res.Value.Total)
d.Set("circulating", res.Value.Circulating)
d.Set("non_circulating", res.Value.NonCirculating)
return nil
}