Skip to content

Commit

Permalink
several new data sources added with updated documentation and resourc…
Browse files Browse the repository at this point in the history
…e level descriptions
  • Loading branch information
callensm committed Aug 30, 2021
1 parent f81985e commit c4ff161
Show file tree
Hide file tree
Showing 20 changed files with 503 additions and 20 deletions.
4 changes: 2 additions & 2 deletions docs/data-sources/account.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
page_title: "solana_account Data Source - terraform-provider-solana"
subcategory: ""
description: |-
Provides all information associated with the account of the provided public key
---

# solana_account (Data Source)


Provides all information associated with the account of the provided public key



Expand Down
4 changes: 2 additions & 2 deletions docs/data-sources/balance.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
page_title: "solana_balance Data Source - terraform-provider-solana"
subcategory: ""
description: |-
Provides the balance of the account of the provided public key
---

# solana_balance (Data Source)


Provides the balance of the account of the provided public key



Expand Down
4 changes: 2 additions & 2 deletions docs/data-sources/epoch.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
page_title: "solana_epoch Data Source - terraform-provider-solana"
subcategory: ""
description: |-
Provides all of the relevant information about the current epoch
---

# solana_epoch (Data Source)


Provides all of the relevant information about the current epoch



Expand Down
27 changes: 27 additions & 0 deletions docs/data-sources/recent_blockhash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "solana_recent_blockhash Data Source - terraform-provider-solana"
subcategory: ""
description: |-
Retrieves a recent block hash from the ledger and the associated cost in lamports per signature on a new transaction for that block
---

# solana_recent_blockhash (Data Source)

Retrieves a recent block hash from the ledger and the associated cost in lamports per signature on a new transaction for that block



<!-- schema generated by tfplugindocs -->
## Schema

### Optional

- **id** (String) The ID of this resource.

### Read-Only

- **blockhash** (String) Base-58 encoded hash string of the block
- **lamports_per_signature** (Number) The lamports cost per signature of the block


30 changes: 30 additions & 0 deletions docs/data-sources/rent_exemption_cost.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "solana_rent_exemption_cost Data Source - terraform-provider-solana"
subcategory: ""
description: |-
Provides the minimum balance required to make an account rent exempt in lamports
---

# solana_rent_exemption_cost (Data Source)

Provides the minimum balance required to make an account rent exempt in lamports



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- **data_length** (Number) The length of the data stored in the account

### Optional

- **id** (String) The ID of this resource.

### Read-Only

- **lamports** (Number) The calculated minimum cost of rent exemption for the account size


28 changes: 28 additions & 0 deletions docs/data-sources/supply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "solana_supply Data Source - terraform-provider-solana"
subcategory: ""
description: |-
Provides information about the current supply on the network
---

# solana_supply (Data Source)

Provides information about the current supply on the network



<!-- schema generated by tfplugindocs -->
## Schema

### Optional

- **id** (String) The ID of this resource.

### Read-Only

- **circulating** (Number) Circulating supply in lamports
- **non_circulating** (Number) Non-circulating supply in lamports
- **total** (Number) Total supply of lamports


27 changes: 27 additions & 0 deletions docs/data-sources/version.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "solana_version Data Source - terraform-provider-solana"
subcategory: ""
description: |-
Provides the current Solana software version running on the network node
---

# solana_version (Data Source)

Provides the current Solana software version running on the network node



<!-- schema generated by tfplugindocs -->
## Schema

### Optional

- **id** (String) The ID of this resource.

### Read-Only

- **feature_set** (Number) A unique identifier of the current software's feature set
- **solana_core** (String) Software version of `solana-core` running on the node


4 changes: 2 additions & 2 deletions solana/data_source_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

func dataSourceAccount() *schema.Resource {
return &schema.Resource{
Read: dataSourceAccountRead,

Description: "Provides all information associated with the account of the provided public key",
Read: dataSourceAccountRead,
Schema: map[string]*schema.Schema{
"public_key": {
Type: schema.TypeString,
Expand Down
4 changes: 2 additions & 2 deletions solana/data_source_balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

func dataSourceBalance() *schema.Resource {
return &schema.Resource{
Read: dataSourceBalanceRead,

Description: "Provides the balance of the account of the provided public key",
Read: dataSourceBalanceRead,
Schema: map[string]*schema.Schema{
"public_key": {
Type: schema.TypeString,
Expand Down
4 changes: 2 additions & 2 deletions solana/data_source_epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

func dataSourceEpoch() *schema.Resource {
return &schema.Resource{
Read: dataSourceEpochRead,

Description: "Provides all of the relevant information about the current epoch",
Read: dataSourceEpochRead,
Schema: map[string]*schema.Schema{
"absolute_slot": {
Type: schema.TypeInt,
Expand Down
10 changes: 5 additions & 5 deletions solana/data_source_epoch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

const (
testEpocDataConfig = `
testEpochDataConfig = `
provider "solana" {
endpoint = "https://api.testnet.solana.com"
}
Expand All @@ -18,21 +18,21 @@ const (
`
)

func TestAccEpocDataSource(t *testing.T) {
func TestAccEpochDataSource(t *testing.T) {
resource.Test(t, resource.TestCase{
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testEpocDataConfig,
Config: testEpochDataConfig,
Check: resource.ComposeTestCheckFunc(
testEpocDataSucceeds("data.solana_epoch.test"),
testEpochDataSucceeds("data.solana_epoch.test"),
),
},
},
})
}

func testEpocDataSucceeds(name string) resource.TestCheckFunc {
func testEpochDataSucceeds(name string) resource.TestCheckFunc {
return func(state *terraform.State) error {
val, ok := state.RootModule().Resources[name]
if !ok {
Expand Down
42 changes: 42 additions & 0 deletions solana/data_source_recent_blockhash.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package solana

import (
"context"
"fmt"

"github.com/gagliardetto/solana-go/rpc"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func dataSourceRecentBlockhash() *schema.Resource {
return &schema.Resource{
Description: "Retrieves a recent block hash from the ledger and the associated cost in lamports per signature on a new transaction for that block",
Read: dataSourceRecentBlockhashRead,
Schema: map[string]*schema.Schema{
"blockhash": {
Type: schema.TypeString,
Description: "Base-58 encoded hash string of the block",
Computed: true,
},
"lamports_per_signature": {
Type: schema.TypeInt,
Description: "The lamports cost per signature of the block",
Computed: true,
},
},
}
}

func dataSourceRecentBlockhashRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*providerConfig).rpcClient

res, err := client.GetRecentBlockhash(context.Background(), rpc.CommitmentRecent)
if err != nil {
return err
}

d.SetId(fmt.Sprintf("recent_blockhash:%s", res.Value.Blockhash.String()))
d.Set("blockhash", res.Value.Blockhash.String())
d.Set("lamports_per_signature", uint64(res.Value.FeeCalculator.LamportsPerSignature))
return nil
}
48 changes: 48 additions & 0 deletions solana/data_source_recent_blockhash_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package solana

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

const (
testRecentBlockhashDataConfig = `
provider "solana" {
endpoint = "https://api.testnet.solana.com"
}
data "solana_recent_blockhash" "test" {}
`
)

func TestAccRecentBlockhashDataSource(t *testing.T) {
resource.Test(t, resource.TestCase{
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testRecentBlockhashDataConfig,
Check: resource.ComposeTestCheckFunc(
testRecentBlockhashDataSucceeds("data.solana_recent_blockhash.test"),
),
},
},
})
}

func testRecentBlockhashDataSucceeds(name string) resource.TestCheckFunc {
return func(state *terraform.State) error {
val, ok := state.RootModule().Resources[name]
if !ok {
return fmt.Errorf("Recent Blockhash Failure: %s not found", name)
}

if val.Primary.ID == "" {
return fmt.Errorf("Recent Blockhash Failure: ID was not set")
}

return nil
}
}
42 changes: 42 additions & 0 deletions solana/data_source_rent_exemption_cost.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package solana

import (
"context"
"fmt"

"github.com/gagliardetto/solana-go/rpc"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func dataSourceRentExemptionCost() *schema.Resource {
return &schema.Resource{
Description: "Provides the minimum balance required to make an account rent exempt in lamports",
Read: dataSourceRentExemptionCostRead,
Schema: map[string]*schema.Schema{
"data_length": {
Type: schema.TypeInt,
Description: "The length of the data stored in the account",
Required: true,
},
"lamports": {
Type: schema.TypeInt,
Description: "The calculated minimum cost of rent exemption for the account size",
Computed: true,
},
},
}
}

func dataSourceRentExemptionCostRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*providerConfig).rpcClient

dataLength := d.Get("data_length").(int)
res, err := client.GetMinimumBalanceForRentExemption(context.Background(), dataLength, rpc.CommitmentRecent)
if err != nil {
return err
}

d.SetId(fmt.Sprintf("rent_exemption_cost:%d", dataLength))
d.Set("lamports", res)
return nil
}
Loading

0 comments on commit c4ff161

Please sign in to comment.