From f46cfbccf93cfb4d845ba2b7b5586d1eaa32c4ac Mon Sep 17 00:00:00 2001 From: Salvionied Date: Tue, 19 Sep 2023 17:17:24 +0200 Subject: [PATCH] Add All indexer endpoints --- client/asset.go | 120 +++++++++++++++++++++++++++++++++ client/asset_policy.go | 104 +++++++++++++++++++++++++++++ client/datum.go | 23 +++++++ client/ecosystem.go | 23 +++++++ client/epochs.go | 38 +++++++++++ client/general.go | 67 +++++++++++++++++++ client/pools.go | 147 +++++++++++++++++++++++++++++++++++++++++ client/scripts.go | 24 +++++++ client/transactions.go | 112 +++++++++++++++++++++++++++++++ models/asset.go | 69 +++++++++++++++++++ models/asset_policy.go | 73 ++++++++++++++++++++ models/common.go | 7 ++ models/datum.go | 13 ++++ models/epochs.go | 16 +++++ models/general.go | 82 +++++++++++++++++++++++ models/pools.go | 128 +++++++++++++++++++++++++++++++++++ models/scripts.go | 21 ++++++ models/transactions.go | 65 ++++++++++++++++++ utils/parameters.go | 4 ++ 19 files changed, 1136 insertions(+) create mode 100644 client/asset.go create mode 100644 client/asset_policy.go create mode 100644 client/datum.go create mode 100644 client/ecosystem.go create mode 100644 client/epochs.go create mode 100644 client/general.go create mode 100644 client/pools.go create mode 100644 client/scripts.go create mode 100644 client/transactions.go create mode 100644 models/asset.go create mode 100644 models/asset_policy.go create mode 100644 models/datum.go create mode 100644 models/epochs.go create mode 100644 models/general.go create mode 100644 models/pools.go create mode 100644 models/scripts.go create mode 100644 models/transactions.go diff --git a/client/asset.go b/client/asset.go new file mode 100644 index 0000000..94d33cf --- /dev/null +++ b/client/asset.go @@ -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 +} diff --git a/client/asset_policy.go b/client/asset_policy.go new file mode 100644 index 0000000..d11a537 --- /dev/null +++ b/client/asset_policy.go @@ -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 +} diff --git a/client/datum.go b/client/datum.go new file mode 100644 index 0000000..17be2ce --- /dev/null +++ b/client/datum.go @@ -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 +} diff --git a/client/ecosystem.go b/client/ecosystem.go new file mode 100644 index 0000000..aa4c386 --- /dev/null +++ b/client/ecosystem.go @@ -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 +} diff --git a/client/epochs.go b/client/epochs.go new file mode 100644 index 0000000..22276c4 --- /dev/null +++ b/client/epochs.go @@ -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(¤tEpoch) + if err != nil { + return nil, err + } + return ¤tEpoch, 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 +} diff --git a/client/general.go b/client/general.go new file mode 100644 index 0000000..c74ef22 --- /dev/null +++ b/client/general.go @@ -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 +} diff --git a/client/pools.go b/client/pools.go new file mode 100644 index 0000000..d58d19b --- /dev/null +++ b/client/pools.go @@ -0,0 +1,147 @@ +package client + +import ( + "encoding/json" + "fmt" + + "github.com/maestro-org/go-sdk/models" + "github.com/maestro-org/go-sdk/utils" +) + +func (c *Client) ListOfRegisteredPools(params *utils.Parameters) (*models.RegisteredPools, error) { + formattedParams := "" + if params != nil { + formattedParams = params.Format() + } + url := fmt.Sprintf("/pools%s", formattedParams) + resp, err := c.get(url) + if err != nil { + return nil, err + } + defer resp.Body.Close() + var registeredPools models.RegisteredPools + err = json.NewDecoder(resp.Body).Decode(®isteredPools) + if err != nil { + return nil, err + } + return ®isteredPools, nil +} + +func (c *Client) StakePoolMintedBlocks(poolId string, params *utils.Parameters) (*models.PoolMintedBlocks, error) { + formattedParams := "" + if params != nil { + formattedParams = params.Format() + } + url := fmt.Sprintf("/pools/%s/blocks%s", poolId, formattedParams) + resp, err := c.get(url) + if err != nil { + return nil, err + } + defer resp.Body.Close() + var poolMintedBlocks models.PoolMintedBlocks + err = json.NewDecoder(resp.Body).Decode(&poolMintedBlocks) + if err != nil { + return nil, err + } + return &poolMintedBlocks, nil +} + +func (c *Client) StakePoolDelegators(poolId string, params *utils.Parameters) (*models.StakePoolDelegators, error) { + formattedParams := "" + if params != nil { + formattedParams = params.Format() + } + url := fmt.Sprintf("/pools/%s/delegators%s", poolId, formattedParams) + resp, err := c.get(url) + if err != nil { + return nil, err + } + defer resp.Body.Close() + var stakePoolDelegators models.StakePoolDelegators + err = json.NewDecoder(resp.Body).Decode(&stakePoolDelegators) + if err != nil { + return nil, err + } + return &stakePoolDelegators, nil +} + +func (c *Client) StakePoolHistory(poolId string, params *utils.Parameters) (*models.StakePoolHistory, error) { + formattedParams := "" + if params != nil { + formattedParams = params.Format() + } + url := fmt.Sprintf("/pools/%s/history%s", poolId, formattedParams) + resp, err := c.get(url) + if err != nil { + return nil, err + } + defer resp.Body.Close() + var stakePoolHistory models.StakePoolHistory + err = json.NewDecoder(resp.Body).Decode(&stakePoolHistory) + if err != nil { + return nil, err + } + return &stakePoolHistory, nil +} + +func (c *Client) StakePoolInformation(poolId string) (*models.StakePoolInformation, error) { + url := fmt.Sprintf("/pools/%s/info", poolId) + resp, err := c.get(url) + if err != nil { + return nil, err + } + defer resp.Body.Close() + var stakePoolInformation models.StakePoolInformation + err = json.NewDecoder(resp.Body).Decode(&stakePoolInformation) + if err != nil { + return nil, err + } + return &stakePoolInformation, nil +} + +func (c *Client) StakePoolMetadata(poolId string) (*models.StakePoolMetadata, error) { + url := fmt.Sprintf("/pools/%s/metadata", poolId) + resp, err := c.get(url) + if err != nil { + return nil, err + } + defer resp.Body.Close() + var stakePoolMetadata models.StakePoolMetadata + err = json.NewDecoder(resp.Body).Decode(&stakePoolMetadata) + if err != nil { + return nil, err + } + return &stakePoolMetadata, nil +} + +func (c *Client) StakePoolRelays(poolId string) (*models.StakePoolRelays, error) { + url := fmt.Sprintf("/pools/%s/relays", poolId) + resp, err := c.get(url) + if err != nil { + return nil, err + } + defer resp.Body.Close() + var stakePoolRelays models.StakePoolRelays + err = json.NewDecoder(resp.Body).Decode(&stakePoolRelays) + if err != nil { + return nil, err + } + return &stakePoolRelays, nil + +} + +func (c *Client) StakePoolUpdates(poolId string) (*models.StakePoolUpdates, error) { + url := fmt.Sprintf("/pools/%s/updates", poolId) + resp, err := c.get(url) + if err != nil { + return nil, err + } + defer resp.Body.Close() + var stakePoolUpdates models.StakePoolUpdates + err = json.NewDecoder(resp.Body).Decode(&stakePoolUpdates) + if err != nil { + return nil, err + } + return &stakePoolUpdates, nil + +} diff --git a/client/scripts.go b/client/scripts.go new file mode 100644 index 0000000..a67e46a --- /dev/null +++ b/client/scripts.go @@ -0,0 +1,24 @@ +package client + +import ( + "encoding/json" + "fmt" + + "github.com/maestro-org/go-sdk/models" +) + +func (c *Client) ScriptByHash(hash string) (*models.ScriptByHash, error) { + url := fmt.Sprintf("/scripts/%s", hash) + resp, err := c.get(url) + if err != nil { + return nil, err + } + defer resp.Body.Close() + var scriptByHash models.ScriptByHash + err = json.NewDecoder(resp.Body).Decode(&scriptByHash) + if err != nil { + return nil, err + } + return &scriptByHash, nil + +} diff --git a/client/transactions.go b/client/transactions.go new file mode 100644 index 0000000..3a605e4 --- /dev/null +++ b/client/transactions.go @@ -0,0 +1,112 @@ +package client + +import ( + "encoding/json" + "fmt" + + "github.com/maestro-org/go-sdk/models" + "github.com/maestro-org/go-sdk/utils" +) + +func (c *Client) AddressByOutputReference(txHash string, index int) (*models.BasicResponse, error) { + url := fmt.Sprintf("/transactions/%s/outputs/%d/address", txHash, index) + resp, err := c.get(url) + if err != nil { + return nil, err + } + defer resp.Body.Close() + var addressByOutputReference models.BasicResponse + err = json.NewDecoder(resp.Body).Decode(&addressByOutputReference) + if err != nil { + return nil, err + } + return &addressByOutputReference, nil + +} + +func (c *Client) SubmitTx(cbor string) (models.BasicResponse, error) { + url := "/submit/tx" + resp, err := c.post(url, cbor) + if err != nil { + return models.BasicResponse{}, err + } + defer resp.Body.Close() + var submitTx models.BasicResponse + err = json.NewDecoder(resp.Body).Decode(&submitTx) + if err != nil { + return models.BasicResponse{}, err + } + return submitTx, nil +} + +func (c *Client) TransactionCbor(txHash string) (*models.BasicResponse, error) { + url := fmt.Sprintf("/transactions/%s/cbor", txHash) + resp, err := c.get(url) + if err != nil { + return nil, err + } + defer resp.Body.Close() + var transactionCbor models.BasicResponse + err = json.NewDecoder(resp.Body).Decode(&transactionCbor) + if err != nil { + return nil, err + } + return &transactionCbor, nil + +} + +func (c *Client) TransactionDetails(txHash string) (*models.TransactionDetails, error) { + url := fmt.Sprintf("/transactions/%s", txHash) + resp, err := c.get(url) + if err != nil { + return nil, err + } + defer resp.Body.Close() + var transactionDetails models.TransactionDetails + err = json.NewDecoder(resp.Body).Decode(&transactionDetails) + if err != nil { + return nil, err + } + return &transactionDetails, nil + +} + +func (c *Client) TransactionOutputFromReference(txHash string, index int, params *utils.Parameters) (*models.TransactionOutputFromReference, error) { + formattedParams := "" + if params != nil { + formattedParams = params.Format() + } + url := fmt.Sprintf("/transactions/%s/outputs/%d/txo%s", txHash, index, formattedParams) + resp, err := c.get(url) + if err != nil { + return nil, err + } + defer resp.Body.Close() + var transactionOutputFromReference models.TransactionOutputFromReference + err = json.NewDecoder(resp.Body).Decode(&transactionOutputFromReference) + if err != nil { + return nil, err + } + return &transactionOutputFromReference, nil +} + +func (c *Client) TransactionOutputsFromReferences(references []models.TxoReference, params *utils.Parameters) (*models.TransactionOutputsFromReferences, error) { + formattedParams := "" + if params != nil { + formattedParams = params.Format() + } + + url := "/transactions/outputs" + formattedParams + resp, err := c.post(url, references) + if err != nil { + return nil, err + } + defer resp.Body.Close() + var transactionOutputsFromReferences models.TransactionOutputsFromReferences + err = json.NewDecoder(resp.Body).Decode(&transactionOutputsFromReferences) + if err != nil { + return nil, err + } + return &transactionOutputsFromReferences, nil + +} diff --git a/models/asset.go b/models/asset.go new file mode 100644 index 0000000..3545178 --- /dev/null +++ b/models/asset.go @@ -0,0 +1,69 @@ +package models + +import "github.com/maestro-org/go-sdk/utils" + +type AccountHoldingAsset struct { + Account string `json:"account"` + Amount int64 `json:"amount"` +} + +type AccountsHoldingAsset struct { + Data []AccountHoldingAsset `json:"data"` + LastUpdated utils.LastUpdated `json:"last_updated"` + NextCursor string `json:"next_cursor"` +} + +type AddressHoldingAsset struct { + Address string `json:"address"` + Amount int64 `json:"amount"` +} + +type AddressesHoldingAsset struct { + Data []AddressHoldingAsset `json:"data"` + LastUpdated utils.LastUpdated `json:"last_updated"` + NextCursor string `json:"next_cursor"` +} + +type AssetInformations struct { + Data AssetInformation `json:"data"` + LastUpdated utils.LastUpdated `json:"last_updated"` + NextCursor string `json:"next_cursor"` +} + +type AssetTransactions struct { + Data []PolicyTransaction `json:"data"` + LastUpdated utils.LastUpdated `json:"last_updated"` + NextCursor string `json:"next_cursor"` +} + +type Metadata struct { + Json any `json:"json"` + Key any `json:"key"` +} + +type AssetUpdate struct { + BlockTimestamp int64 `json:"block_timestamp"` + Metadata Metadata `json:"metadata"` + MintAmount int64 `json:"mint_amount"` + TxHash string `json:"tx_hash"` +} + +type AssetUpdates struct { + Data []AssetUpdate `json:"data"` + LastUpdated utils.LastUpdated `json:"last_updated"` + NextCursor string `json:"next_cursor"` +} + +type AssetUtxo struct { + Address string `json:"address"` + Amount int64 `json:"amount"` + Index int64 `json:"index"` + Slot int64 `json:"slot"` + TxHash string `json:"tx_hash"` +} + +type AssetUtxos struct { + Data []AssetUtxo `json:"data"` + LastUpdated utils.LastUpdated `json:"last_updated"` + NextCursor string `json:"next_cursor"` +} diff --git a/models/asset_policy.go b/models/asset_policy.go new file mode 100644 index 0000000..960d19c --- /dev/null +++ b/models/asset_policy.go @@ -0,0 +1,73 @@ +package models + +import ( + "github.com/maestro-org/go-sdk/utils" +) + +type AssetNameAndAmount struct { + Name string `json:"name"` + Amount int64 `json:"amount"` +} +type AccountHolding struct { + Account string `json:"account"` + Assets []AssetNameAndAmount `json:"assets"` +} + +type AccountsHoldingPolicy struct { + Data []AccountHolding `json:"data"` + LastUpdated utils.LastUpdated `json:"last_updated"` + NextCursor string `json:"next_cursor"` +} + +type AddressHolding struct { + Address string `json:"address"` + Assets []AssetNameAndAmount `json:"assets"` +} + +type AddressesHoldingPolicy struct { + Data []AddressHolding `json:"data"` + LastUpdated utils.LastUpdated `json:"last_updated"` + NextCursor string `json:"next_cursor"` +} + +type Standards struct { + Cip25Metadata any `json:"cip25_metadata"` + Cip68Metadata any `json:"cip68_metadata"` +} + +type AssetInformation struct { + AssetName string `json:"asset_name"` + AssetNameAscii string `json:"asset_name_ascii"` + AssetStandards Standards `json:"asset_standards"` + BurnTxCount int64 `json:"burn_tx_count"` + FingerPrint string `json:"fingerprint"` + FirstMintTime int64 `json:"first_mint_time"` + FirstMintTx string `json:"first_mint_tx"` + LatestMintTxMetadata any `json:"latest_mint_tx_metadata"` + MintTxCount int64 `json:"mint_tx_count"` + TokenRegistryMetadata any `json:"token_registry_metadata"` + TotalSuppply int64 `json:"total_supply"` +} +type PolicyInformation struct { + Data []AssetInformation `json:"data"` + LastUpdated utils.LastUpdated `json:"last_updated"` + NextCursor string `json:"next_cursor"` +} + +type PolicyTransaction struct { + BlockHeight int64 `json:"block_height"` + EpochNo int64 `json:"epoch_no"` + TxHash string `json:"tx_hash"` +} + +type PolicyTransactions struct { + Data []PolicyTransaction `json:"data"` + LastUpdated utils.LastUpdated `json:"last_updated"` + NextCursor string `json:"next_cursor"` +} + +type UtxosContainingPolicy struct { + Data []Utxo `json:"data"` + LastUpdated utils.LastUpdated `json:"last_updated"` + NextCursor string `json:"next_cursor"` +} diff --git a/models/common.go b/models/common.go index 2640e7f..9101dd1 100644 --- a/models/common.go +++ b/models/common.go @@ -1 +1,8 @@ package models + +import "github.com/maestro-org/go-sdk/utils" + +type BasicResponse struct { + Data string `json:"data"` + LastUpdated utils.LastUpdated `json:"last_updated"` +} diff --git a/models/datum.go b/models/datum.go new file mode 100644 index 0000000..5a15d89 --- /dev/null +++ b/models/datum.go @@ -0,0 +1,13 @@ +package models + +import "github.com/maestro-org/go-sdk/utils" + +type Datum struct { + Bytes string `json:"bytes"` + Json any `json:"json"` +} + +type DatumFromHash struct { + Data Datum `json:"data"` + LastUpdated utils.LastUpdated `json:"last_updated"` +} diff --git a/models/epochs.go b/models/epochs.go new file mode 100644 index 0000000..85bd62e --- /dev/null +++ b/models/epochs.go @@ -0,0 +1,16 @@ +package models + +import "github.com/maestro-org/go-sdk/utils" + +type Epoch struct { + BlkCount int `json:"blk_count"` + EpochNo int `json:"epoch_no"` + Fees int `json:"fees"` + StartTime int `json:"start_time"` + TxCount int `json:"tx_count"` +} + +type EpochResp struct { + Data Epoch `json:"data"` + LastUpdated utils.LastUpdated `json:"last_updated"` +} diff --git a/models/general.go b/models/general.go new file mode 100644 index 0000000..e9f3176 --- /dev/null +++ b/models/general.go @@ -0,0 +1,82 @@ +package models + +import "github.com/maestro-org/go-sdk/utils" + +type ChainTipData struct { + BlockHash string `json:"block_hash"` + Height int64 `json:"height"` + Slot int64 `json:"slot"` +} + +type ChainTip struct { + Data ChainTipData `json:"data"` + LastUpdated utils.LastUpdated `json:"last_updated"` +} + +type EraTimeStamp struct { + Epoch int64 `json:"epoch"` + Slot int64 `json:"slot"` + Time int64 `json:"time"` +} + +type EraParams struct { + EpochLength int64 `json:"epoch_length"` + SafeZone int64 `json:"safe_zone"` + SlotLength int64 `json:"slot_length"` +} + +type Era struct { + End EraTimeStamp `json:"end"` + Parameters EraParams `json:"parameters"` + Start EraTimeStamp `json:"start"` +} + +type EraHistory struct { + Data []Era `json:"data"` + LastUpdated utils.LastUpdated `json:"last_updated"` +} + +type ProtocolParameters struct { + Data ProtocolParams `json:"data"` + LastUpdated utils.LastUpdated `json:"last_updated"` +} + +type ExUnits struct { + Memory int64 `json:"memory"` + Steps int64 `json:"steps"` +} + +type StringExUnits struct { + Memory string `json:"memory"` + Steps string `json:"steps"` +} + +type ProtocolVersion struct { + Major int64 `json:"major"` + Minor int64 `json:"minor"` +} + +type ProtocolParams struct { + CoinsPerUtxoByte int64 `json:"coins_per_utxo_byte"` + CollateralPercentage int64 `json:"collateral_percentage"` + CostModels any `json:"cost_models"` + DesiredNumberOfPools int64 `json:"desired_number_of_pools"` + MaxBlockBodySize int64 `json:"max_block_body_size"` + MaxBlockHeaderSize int64 `json:"max_block_header_size"` + MaxCollateralInputs int64 `json:"max_collateral_inputs"` + MaxExecutionUnitsPerBlock ExUnits `json:"max_execution_units_per_block"` + MaxExecutionUnitsPerTransaction ExUnits `json:"max_execution_units_per_transaction"` + MaxTxSize int64 `json:"max_tx_size"` + MaxValueSize int64 `json:"max_value_size"` + MinFeeCoefficient int64 `json:"min_fee_coefficient"` + MinFeeConstant int64 `json:"min_fee_constant"` + MinPoolCost int64 `json:"min_pool_cost"` + MonetaryExpansion string `json:"monetary_expansion"` + PoolDeposit int64 `json:"pool_deposit"` + PoolInfluence string `json:"pool_influence"` + PoolRetirementEpochBound int64 `json:"pool_retirement_epoch_bound"` + Prices StringExUnits `json:"prices"` + ProtocolVersion ProtocolVersion `json:"protocol_version"` + StakeKeyDeposit int64 `json:"stake_key_deposit"` + TreasuryExpansion string `json:"treasury_expansion"` +} diff --git a/models/pools.go b/models/pools.go new file mode 100644 index 0000000..08adcad --- /dev/null +++ b/models/pools.go @@ -0,0 +1,128 @@ +package models + +import "github.com/maestro-org/go-sdk/utils" + +type Pool struct { + PoolIdBech32 string `json:"pool_id_bech32"` + Ticker string `json:"ticker"` +} + +type RegisteredPools struct { + Data []Pool `json:"data"` + LastUpdated utils.LastUpdated `json:"last_updated"` + NextCursor string `json:"next_cursor"` +} + +type Block struct { + AbsSlot int64 `json:"abs_slot"` + BlockHash string `json:"block_hash"` + BlockHeight int64 `json:"block_height"` + BlockTime int64 `json:"block_time"` + EpochNo int64 `json:"epoch_no"` + EpochSlot int64 `json:"epoch_slot"` +} + +type PoolMintedBlocks struct { + Data []Block `json:"data"` + LastUpdated utils.LastUpdated `json:"last_updated"` + NextCursor string `json:"next_cursor"` +} + +type StakePoolDelegator struct { + ActiveEpochNo int64 `json:"active_epoch_no"` + Amount string `json:"amount"` + LatestDelegationTxHash string `json:"latest_delegation_tx_hash"` + StakeAddress string `json:"stake_address"` +} + +type StakePoolDelegators struct { + Data []StakePoolDelegator `json:"data"` + LastUpdated utils.LastUpdated `json:"last_updated"` + NextCursor string `json:"next_cursor"` +} + +type StakePoolHistoryData struct { + ActiveStake int64 `json:"active_stake"` + ActiveStakePct string `json:"active_stake_pct"` + BlockCnt int64 `json:"block_cnt"` + DelegRewards int64 `json:"deleg_rewards"` + DelegatorCnt int64 `json:"delegator_cnt"` + EpochNo int64 `json:"epoch_no"` + EpochRos string `json:"epoch_ros"` + FixedCost int64 `json:"fixed_cost"` + Margin int64 `json:"margin"` + PoolFees int64 `json:"pool_fees"` + SaturationPct any `json:"saturation_pct"` +} +type StakePoolHistory struct { + Data []StakePoolHistoryData `json:"data"` + LastUpdated utils.LastUpdated `json:"last_updated"` + NextCursor string `json:"next_cursor"` +} + +type Relay struct { + Dns string `json:"dns"` + Ipv4 string `json:"ipv4"` + Ipv6 string `json:"ipv6"` + Port int64 `json:"port"` + Srv string `json:"srv"` +} + +type StakePoolDetails struct { + ActiveEpochNo int64 `json:"active_epoch_no"` + ActiveStake int64 `json:"active_stake"` + BlockCount int64 `json:"block_count"` + FixedCost int64 `json:"fixed_cost"` + LiveDelegators int64 `json:"live_delegators"` + LivePledge int64 `json:"live_pledge"` + LiveSaturation string `json:"live_saturation"` + LiveStake int64 `json:"live_stake"` + Margin int64 `json:"margin"` + MetaHash any `json:"meta_hash"` + MetaJson any `json:"meta_json"` + MetaUrl any `json:"meta_url"` + OpCert string `json:"op_cert"` + OpCertCounter int64 `json:"op_cert_counter"` + Owners []string `json:"owners"` + Pledge int64 `json:"pledge"` + PoolIdBech32 string `json:"pool_id_bech32"` + PoolIdHex string `json:"pool_id_hex"` + PoolStatus string `json:"pool_status"` + Relays []Relay `json:"relays"` + RetiringEpoch any `json:"retiring_epoch"` + RewardAddr string `json:"reward_addr"` + Sigma string `json:"sigma"` + VrfKeyHash string `json:"vrf_key_hash"` +} + +type StakePoolInformation struct { + Data StakePoolDetails `json:"data"` + LastUpdated utils.LastUpdated `json:"last_updated"` +} + +type Poolmetadata struct { + MetaHash string `json:"meta_hash"` + MetaJson any `json:"meta_json"` + MetaUrl string `json:"meta_url"` + PoolIdBech32 string `json:"pool_id_bech32"` +} + +type StakePoolMetadata struct { + Data Poolmetadata `json:"data"` + LastUpdated utils.LastUpdated `json:"last_updated"` +} + +type RelaysAndId struct { + PoolIdBech32 string `json:"pool_id_bech32"` + Relays []Relay `json:"relays"` +} + +type StakePoolRelays struct { + Data []RelaysAndId `json:"data"` + LastUpdated utils.LastUpdated `json:"last_updated"` +} + +type StakePoolUpdates struct { + Data []StakePoolDetails `json:"data"` + LastUpdated utils.LastUpdated `json:"last_updated"` +} diff --git a/models/scripts.go b/models/scripts.go new file mode 100644 index 0000000..9f638ac --- /dev/null +++ b/models/scripts.go @@ -0,0 +1,21 @@ +package models + +import "github.com/maestro-org/go-sdk/utils" + +type ScriptVersion string + +const ( + PlutusV1 ScriptVersion = "plutusv1" + PlutusV2 ScriptVersion = "plutusv2" +) + +type Script struct { + Bytes string `json:"bytes"` + Hash string `json:"hash"` + Json any `json:"json"` + Type ScriptVersion `json:"type"` +} +type ScriptByHash struct { + Data Script `json:"data"` + LastUpdated utils.LastUpdated `json:"last_updated"` +} diff --git a/models/transactions.go b/models/transactions.go new file mode 100644 index 0000000..68adaf5 --- /dev/null +++ b/models/transactions.go @@ -0,0 +1,65 @@ +package models + +import "github.com/maestro-org/go-sdk/utils" + +type Certificates struct { + MirTransfers []any `json:"mir_transfers"` + PoolRegistrations []any `json:"pool_registrations"` + PoolRetirements []any `json:"pool_retirements"` + StakeDelegations []any `json:"stake_delegations"` + StakeDeregistrations []any `json:"stake_deregistrations"` + StakeRegistrationsReserves []any `json:"stake_registrations_reserves"` +} +type Redeemers struct { + Certificates []any `json:"certificates"` + Mints []any `json:"mints"` + Spends []any `json:"spends"` + Withdrawals []any `json:"withdrawals"` +} +type TransactionDetail struct { + AdditionalSigners []string `json:"additional_signers"` + BlockAbsoluteSlot int64 `json:"block_absolute_slot"` + BlockHash string `json:"block_hash"` + BlockHeight int64 `json:"block_height"` + BlockTimestamp int64 `json:"block_timestamp"` + BlockTxIndex int64 `json:"block_tx_index"` + Certificates Certificates `json:"certificates"` + CollateralInputs []Utxo `json:"collateral_inputs"` + CollateralReturn any `json:"collateral_return"` + Deposit int64 `json:"deposit"` + Fee int64 `json:"fee"` + Inputs []Utxo `json:"inputs"` + InvalidBefore int64 `json:"invalid_before"` + InvalidHereafter int64 `json:"invalid_hereafter"` + Metadata any `json:"metadata"` + Mint []any `json:"mint"` + Outputs []Utxo `json:"outputs"` + Redeemers []Redeemers `json:"redeemers"` + ReferenceInputs []any `json:"reference_inputs"` + ScriptsExecuted []Script `json:"scripts_executed"` + ScriptsSuccesful bool `json:"scripts_succesful"` + Size int64 `json:"size"` + TxHash string `json:"tx_hash"` + Withdrawals []any `json:"withdrawals"` +} + +type TransactionDetails struct { + Data TransactionDetail `json:"data"` + LastUpdated utils.LastUpdated `json:"last_updated"` +} + +type TransactionOutputFromReference struct { + Data Utxo `json:"data"` + LastUpdated utils.LastUpdated `json:"last_updated"` +} + +type TxoReference struct { + TxHash string `json:"tx_hash"` + Index int `json:"index"` +} + +type TransactionOutputsFromReferences struct { + Data []Utxo `json:"data"` + LastUpdated utils.LastUpdated `json:"last_updated"` + NextCursor string `json:"next_cursor"` +} diff --git a/utils/parameters.go b/utils/parameters.go index 7fef151..2bb65e1 100644 --- a/utils/parameters.go +++ b/utils/parameters.go @@ -60,3 +60,7 @@ func (p *Parameters) WithCbor() { func (p *Parameters) ResolveDatums() { p.params = append(p.params, "resolve_datums=true") } + +func (p *Parameters) FromHeight(height int64) { + p.params = append(p.params, "from_height="+fmt.Sprint(height)) +}