Skip to content

Commit

Permalink
Add All indexer endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Salvionied committed Sep 19, 2023
1 parent 7944a78 commit f46cfbc
Show file tree
Hide file tree
Showing 19 changed files with 1,136 additions and 0 deletions.
120 changes: 120 additions & 0 deletions client/asset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package client

import (
"encoding/json"
"fmt"

"github.com/maestro-org/go-sdk/models"
"github.com/maestro-org/go-sdk/utils"
)

func (c *Client) AccountsHoldingAsset(assetId string, params *utils.Parameters) (*models.AccountsHoldingAsset, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
}
url := fmt.Sprintf("/assets/%s/accounts%s", assetId, formattedParams)
resp, err := c.get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var accountsHoldingAsset models.AccountsHoldingAsset
err = json.NewDecoder(resp.Body).Decode(&accountsHoldingAsset)
if err != nil {
return nil, err
}
return &accountsHoldingAsset, nil
}

func (c *Client) AddressHoldingAsset(assetId string, params *utils.Parameters) (*models.AddressesHoldingAsset, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
}
url := fmt.Sprintf("/assets/%s/addresses%s", assetId, formattedParams)
resp, err := c.get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var addressesHoldingAsset models.AddressesHoldingAsset
err = json.NewDecoder(resp.Body).Decode(&addressesHoldingAsset)
if err != nil {
return nil, err
}
return &addressesHoldingAsset, nil
}

func (c *Client) Asset(assetId string) (*models.AssetInformations, error) {
url := fmt.Sprintf("/assets/%s", assetId)
resp, err := c.get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var assetInformation models.AssetInformations
err = json.NewDecoder(resp.Body).Decode(&assetInformation)
if err != nil {
return nil, err
}
return &assetInformation, nil
}

func (c *Client) AssetTransactions(assetId string, params *utils.Parameters) (*models.AssetTransactions, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
}
url := fmt.Sprintf("/assets/%s/txs%s", assetId, formattedParams)
resp, err := c.get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var assetTransactions models.AssetTransactions
err = json.NewDecoder(resp.Body).Decode(&assetTransactions)
if err != nil {
return nil, err
}
return &assetTransactions, nil
}

func (c *Client) AssetUpdates(assetId string, params *utils.Parameters) (*models.AssetUpdates, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
}
url := fmt.Sprintf("/assets/%s/updates%s", assetId, formattedParams)
resp, err := c.get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var assetUpdates models.AssetUpdates
err = json.NewDecoder(resp.Body).Decode(&assetUpdates)
if err != nil {
return nil, err
}
return &assetUpdates, nil

}

func (c *Client) AssetUtxos(assetId string, params *utils.Parameters) (*models.AssetUtxos, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
}
url := fmt.Sprintf("/assets/%s/utxos%s", assetId, formattedParams)
resp, err := c.get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var assetUtxos models.AssetUtxos
err = json.NewDecoder(resp.Body).Decode(&assetUtxos)
if err != nil {
return nil, err
}
return &assetUtxos, nil
}
104 changes: 104 additions & 0 deletions client/asset_policy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package client

import (
"encoding/json"
"fmt"

"github.com/maestro-org/go-sdk/models"
"github.com/maestro-org/go-sdk/utils"
)

func (c *Client) AccountsHoldingPolicy(policy string, params *utils.Parameters) (*models.AccountsHoldingPolicy, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
}
url := fmt.Sprintf("/assets/policy/%s/accounts?%s", policy, formattedParams)
resp, err := c.get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var response models.AccountsHoldingPolicy
err = json.NewDecoder(resp.Body).Decode(&response)
if err != nil {
return nil, err
}
return &response, err
}

func (c *Client) AddressesHoldingPolicy(policy string, params *utils.Parameters) (*models.AddressesHoldingPolicy, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
}
url := fmt.Sprintf("/assets/policy/%s/addresses?%s", policy, formattedParams)
resp, err := c.get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var response models.AddressesHoldingPolicy
err = json.NewDecoder(resp.Body).Decode(&response)
if err != nil {
return nil, err
}
return &response, err
}

func (c *Client) SpecificPolicyInformations(policy string, params *utils.Parameters) (*models.PolicyInformation, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
}
url := fmt.Sprintf("/assets/policy/%s?%s", policy, formattedParams)
resp, err := c.get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var response models.PolicyInformation
err = json.NewDecoder(resp.Body).Decode(&response)
if err != nil {
return nil, err
}
return &response, err
}

func (c *Client) TransactionsMovingPolicy(policy string, params *utils.Parameters) (*models.PolicyTransactions, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
}
url := fmt.Sprintf("/assets/policy/%s/txs?%s", policy, formattedParams)
resp, err := c.get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var response models.PolicyTransactions
err = json.NewDecoder(resp.Body).Decode(&response)
if err != nil {
return nil, err
}
return &response, err
}

func (c *Client) UtxosContainingPolicy(policy string, params *utils.Parameters) (*models.UtxosContainingPolicy, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
}
url := fmt.Sprintf("/assets/policy/%s/utxos?%s", policy, formattedParams)
resp, err := c.get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var response models.UtxosContainingPolicy
err = json.NewDecoder(resp.Body).Decode(&response)
if err != nil {
return nil, err
}
return &response, err
}
23 changes: 23 additions & 0 deletions client/datum.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package client

import (
"encoding/json"
"fmt"

"github.com/maestro-org/go-sdk/models"
)

func (c *Client) DatumFromHash(hash string) (*models.DatumFromHash, error) {
url := fmt.Sprintf("/data/%s", hash)
resp, err := c.get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var datum models.DatumFromHash
err = json.NewDecoder(resp.Body).Decode(&datum)
if err != nil {
return nil, err
}
return &datum, nil
}
23 changes: 23 additions & 0 deletions client/ecosystem.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package client

import (
"encoding/json"
"fmt"

"github.com/maestro-org/go-sdk/models"
)

func (c *Client) ResolveAdaHandle(handle string) (*models.BasicResponse, error) {
url := fmt.Sprintf("/ecosystem/adahandle/%s", handle)
resp, err := c.get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var adaHandle models.BasicResponse
err = json.NewDecoder(resp.Body).Decode(&adaHandle)
if err != nil {
return nil, err
}
return &adaHandle, nil
}
38 changes: 38 additions & 0 deletions client/epochs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package client

import (
"encoding/json"
"fmt"

"github.com/maestro-org/go-sdk/models"
)

func (c *Client) CurrentEpoch() (*models.EpochResp, error) {
url := "/epochs/current"
resp, err := c.get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var currentEpoch models.EpochResp
err = json.NewDecoder(resp.Body).Decode(&currentEpoch)
if err != nil {
return nil, err
}
return &currentEpoch, nil
}

func (c *Client) SpecificEpoch(epochNo int) (*models.EpochResp, error) {
url := fmt.Sprintf("/epochs/%d/info", epochNo)
resp, err := c.get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var specificEpoch models.EpochResp
err = json.NewDecoder(resp.Body).Decode(&specificEpoch)
if err != nil {
return nil, err
}
return &specificEpoch, nil
}
67 changes: 67 additions & 0 deletions client/general.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package client

import (
"encoding/json"

"github.com/maestro-org/go-sdk/models"
)

func (c *Client) ChainTip() (*models.ChainTip, error) {
url := "/chain-tip"
resp, err := c.get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var chainTip models.ChainTip
err = json.NewDecoder(resp.Body).Decode(&chainTip)
if err != nil {
return nil, err
}
return &chainTip, nil
}

func (c *Client) EraHistory() (*models.EraHistory, error) {
url := "/era-history"
resp, err := c.get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var eraHistory models.EraHistory
err = json.NewDecoder(resp.Body).Decode(&eraHistory)
if err != nil {
return nil, err
}
return &eraHistory, nil
}

func (c *Client) ProtocolParameters() (*models.ProtocolParameters, error) {
url := "/protocol-params"
resp, err := c.get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var protocolParameters models.ProtocolParameters
err = json.NewDecoder(resp.Body).Decode(&protocolParameters)
if err != nil {
return nil, err
}
return &protocolParameters, nil
}

func (c *Client) BlockChainStartTime() (models.BasicResponse, error) {
url := "/system-start"
resp, err := c.get(url)
if err != nil {
return models.BasicResponse{}, err
}
defer resp.Body.Close()
var blockchainStartTime models.BasicResponse
err = json.NewDecoder(resp.Body).Decode(&blockchainStartTime)
if err != nil {
return models.BasicResponse{}, err
}
return blockchainStartTime, nil
}
Loading

0 comments on commit f46cfbc

Please sign in to comment.