indexer

package
v0.0.0-...-97165cf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package indexer provides an HTTP REST client for the Mintlayer indexer (api-web-server, default mainnet port 3000). All endpoints are under /api/v2/.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddressInfo

type AddressInfo struct {
	CoinBalance        Amount         `json:"coin_balance"`
	LockedCoinBalance  Amount         `json:"locked_coin_balance"`
	TransactionHistory []string       `json:"transaction_history"`
	Tokens             []TokenBalance `json:"tokens"`
}

AddressInfo is returned by GetAddressInfo.

type Amount

type Amount struct {
	Atoms   string `json:"atoms"`
	Decimal string `json:"decimal"`
}

Amount represents a Mintlayer coin or token amount in both atoms and decimal form.

type Block

type Block struct {
	Height uint64      `json:"height"`
	Header BlockHeader `json:"header"`
	Body   BlockBody   `json:"body"`
}

Block is returned by GetBlock.

type BlockBody

type BlockBody struct {
	Reward       []TxOutput    `json:"reward"`
	Transactions []Transaction `json:"transactions"`
}

BlockBody holds the reward outputs and transactions of a block.

type BlockHeader

type BlockHeader struct {
	PreviousBlockID   string          `json:"previous_block_id"`
	Timestamp         Timestamp       `json:"timestamp"`
	MerkleRoot        string          `json:"merkle_root"`
	WitnessMerkleRoot string          `json:"witness_merkle_root"`
	ConsensusData     json.RawMessage `json:"consensus_data"`
}

BlockHeader holds the header fields of a block.

type ChainTip

type ChainTip struct {
	BlockHeight uint64 `json:"block_height"`
	BlockID     string `json:"block_id"`
}

ChainTip is returned by GetTip.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is an HTTP REST client for the Mintlayer indexer (api-web-server).

func New

func New(baseURL string, opts ...Option) *Client

New creates a Client targeting baseURL (e.g. "http://127.0.0.1:3000").

func (*Client) FindTokensByTicker

func (c *Client) FindTokensByTicker(ctx context.Context, ticker string, opts PageOpts) ([]string, error)

FindTokensByTicker returns token ids (bech32) that match the given ticker string.

func (*Client) GetAddressInfo

func (c *Client) GetAddressInfo(ctx context.Context, address string) (*AddressInfo, error)

GetAddressInfo returns the balance and transaction history for a bech32 address. Returns an *HTTPError with StatusCode 404 if the address has no transaction history.

func (*Client) GetAllUTXOs

func (c *Client) GetAllUTXOs(ctx context.Context, address string) ([]UTXO, error)

GetAllUTXOs returns all UTXOs (including locked/unspendable) for an address.

func (*Client) GetBlock

func (c *Client) GetBlock(ctx context.Context, id string) (*Block, error)

GetBlock returns the full block data for the given block id (hex).

func (*Client) GetBlockHeader

func (c *Client) GetBlockHeader(ctx context.Context, id string) (*BlockHeader, error)

GetBlockHeader returns only the header for the given block id (hex).

func (*Client) GetBlockIDAtHeight

func (c *Client) GetBlockIDAtHeight(ctx context.Context, height uint64) (string, error)

GetBlockIDAtHeight returns the block id (hex) at the given mainchain height. Returns an *HTTPError with StatusCode 404 if no block exists at that height.

func (*Client) GetBlockReward

func (c *Client) GetBlockReward(ctx context.Context, id string) ([]TxOutput, error)

GetBlockReward returns the reward outputs for the given block id (hex).

func (*Client) GetBlockTransactionIDs

func (c *Client) GetBlockTransactionIDs(ctx context.Context, id string) ([]string, error)

GetBlockTransactionIDs returns all transaction ids in the given block (hex block id).

func (*Client) GetCoinStatistics

func (c *Client) GetCoinStatistics(ctx context.Context) (*CoinStats, error)

GetCoinStatistics returns aggregate ML coin supply statistics.

func (*Client) GetDelegation

func (c *Client) GetDelegation(ctx context.Context, id string) (*Delegation, error)

GetDelegation returns a single delegation by id (bech32).

func (*Client) GetDelegations

func (c *Client) GetDelegations(ctx context.Context, address string) ([]DelegationInfo, error)

GetDelegations returns all delegations owned by an address.

func (*Client) GetFeeRate

func (c *Client) GetFeeRate(ctx context.Context, inTopXMb uint32) (string, error)

GetFeeRate returns the current fee rate (atoms per kilobyte) required to be in the top inTopXMb megabytes of the mempool. Pass 0 to use the server default (5 MB).

func (*Client) GetGenesis

func (c *Client) GetGenesis(ctx context.Context) (*GenesisInfo, error)

GetGenesis returns the genesis block info.

func (*Client) GetNFT

func (c *Client) GetNFT(ctx context.Context, id string) (*NFTInfo, error)

GetNFT returns NFT details by token id (bech32).

func (*Client) GetOrder

func (c *Client) GetOrder(ctx context.Context, id string) (*Order, error)

GetOrder returns a single order by id (bech32).

func (*Client) GetPool

func (c *Client) GetPool(ctx context.Context, id string) (*Pool, error)

GetPool returns a single staking pool by id (bech32).

func (*Client) GetPoolBlockStats

func (c *Client) GetPoolBlockStats(ctx context.Context, id string, from, to time.Time) (uint64, error)

GetPoolBlockStats returns the number of blocks produced by a pool in the half-open interval [from, to).

func (*Client) GetPoolDelegations

func (c *Client) GetPoolDelegations(ctx context.Context, id string) ([]PoolDelegation, error)

GetPoolDelegations returns all delegations in a pool.

func (*Client) GetSpendableUTXOs

func (c *Client) GetSpendableUTXOs(ctx context.Context, address string) ([]UTXO, error)

GetSpendableUTXOs returns the currently spendable (confirmed, unspent) UTXOs for an address.

func (*Client) GetTip

func (c *Client) GetTip(ctx context.Context) (*ChainTip, error)

GetTip returns the current chain tip (highest confirmed block).

func (*Client) GetToken

func (c *Client) GetToken(ctx context.Context, id string) (*TokenInfo, error)

GetToken returns fungible token details by token id (bech32).

func (*Client) GetTokenAuthority

func (c *Client) GetTokenAuthority(ctx context.Context, address string) ([]string, error)

GetTokenAuthority returns the ids (bech32) of fungible tokens for which the address is the authority (can mint, freeze, etc.).

func (*Client) GetTokenStatistics

func (c *Client) GetTokenStatistics(ctx context.Context, tokenID string) (*CoinStats, error)

GetTokenStatistics returns aggregate supply statistics for a specific token (bech32 id).

func (*Client) GetTokenTransactions

func (c *Client) GetTokenTransactions(ctx context.Context, id string, opts PageOpts) ([]TokenTx, error)

GetTokenTransactions returns transactions involving a token, with pagination.

func (*Client) GetTransaction

func (c *Client) GetTransaction(ctx context.Context, id string) (*Transaction, error)

GetTransaction returns the transaction with the given id (hex). BlockID, Timestamp, and Confirmations are empty strings if the transaction is not yet confirmed.

func (*Client) GetTransactionMerklePath

func (c *Client) GetTransactionMerklePath(ctx context.Context, id string) (*MerklePath, error)

GetTransactionMerklePath returns the Merkle inclusion proof for a transaction. Returns an *HTTPError with StatusCode 404 if the transaction is not yet in a block.

func (*Client) GetTransactionOutput

func (c *Client) GetTransactionOutput(ctx context.Context, txID string, idx uint32) (json.RawMessage, error)

GetTransactionOutput returns a single output by transaction id and output index. The returned JSON includes a "spent_at_block_height" field (null if unspent).

func (*Client) ListOrders

func (c *Client) ListOrders(ctx context.Context, opts PageOpts) ([]Order, error)

ListOrders returns active orders with pagination.

func (*Client) ListOrdersByPair

func (c *Client) ListOrdersByPair(ctx context.Context, askCurrency, giveCurrency string, opts PageOpts) ([]Order, error)

ListOrdersByPair returns orders for a trading pair with pagination. askCurrency and giveCurrency are either the coin ticker (e.g. "ML") or a token id (bech32).

func (*Client) ListPools

func (c *Client) ListPools(ctx context.Context, opts PoolListOpts) ([]Pool, error)

ListPools returns staking pools with optional pagination and sorting.

func (*Client) ListTokens

func (c *Client) ListTokens(ctx context.Context, opts PageOpts) ([]string, error)

ListTokens returns fungible token ids with pagination.

func (*Client) ListTransactions

func (c *Client) ListTransactions(ctx context.Context, opts PageOpts) ([]Transaction, error)

ListTransactions returns paginated transactions.

func (*Client) SubmitTransaction

func (c *Client) SubmitTransaction(ctx context.Context, signedTxHex string) (string, error)

SubmitTransaction submits a signed transaction (hex-encoded bytes) to the network. Returns the transaction id on success. Note: POST routes must be enabled on the server (--enable-post-routes).

type CoinStats

type CoinStats struct {
	CirculatingSupply Amount `json:"circulating_supply"`
	Preminted         Amount `json:"preminted"`
	Burned            Amount `json:"burned"`
	Staked            Amount `json:"staked"`
}

CoinStats is returned by GetCoinStatistics and GetTokenStatistics.

type Delegation

type Delegation struct {
	DelegationID        string `json:"delegation_id"`
	PoolID              string `json:"pool_id"`
	NextNonce           Uint64 `json:"next_nonce"`
	SpendDestination    string `json:"spend_destination"`
	Balance             Amount `json:"balance"`
	CreationBlockHeight Uint64 `json:"creation_block_height"`
}

Delegation is returned by GetDelegation.

type DelegationInfo

type DelegationInfo struct {
	DelegationID     string `json:"delegation_id"`
	PoolID           string `json:"pool_id"`
	NextNonce        Uint64 `json:"next_nonce"`
	SpendDestination string `json:"spend_destination"`
	Balance          Amount `json:"balance"`
}

DelegationInfo is one entry returned by GetDelegations (address endpoint).

type GenesisInfo

type GenesisInfo struct {
	BlockID        string          `json:"block_id"`
	GenesisMessage string          `json:"genesis_message"`
	Timestamp      Timestamp       `json:"timestamp"`
	UTXOs          json.RawMessage `json:"utxos"`
}

GenesisInfo is returned by GetGenesis.

type HTTPError

type HTTPError struct {
	StatusCode int
	Body       string
}

HTTPError is returned when the server responds with a non-2xx status code.

func (*HTTPError) Error

func (e *HTTPError) Error() string

type MerklePath

type MerklePath struct {
	BlockID          string   `json:"block_id"`
	TransactionIndex uint32   `json:"transaction_index"`
	MerkleRoot       string   `json:"merkle_root"`
	Path             []string `json:"merkle_path"`
}

MerklePath is returned by GetTransactionMerklePath.

type NFTInfo

type NFTInfo struct {
	Owner    string      `json:"owner"`
	TokenID  string      `json:"token_id"`
	Metadata NFTMetadata `json:"metadata"`
}

NFTInfo is returned by GetNFT.

type NFTMetadata

type NFTMetadata struct {
	Creator               *string `json:"creator"`
	Name                  string  `json:"name"`
	Description           string  `json:"description"`
	Ticker                string  `json:"ticker"`
	IconURI               string  `json:"icon_uri"`
	AdditionalMetadataURI *string `json:"additional_metadata_uri"`
	MediaURI              *string `json:"media_uri"`
	MediaHash             string  `json:"media_hash"`
}

NFTMetadata holds the on-chain metadata of an NFT.

type Option

type Option func(*Client)

Option configures a Client.

func WithHTTPClient

func WithHTTPClient(hc *http.Client) Option

WithHTTPClient replaces the default HTTP client.

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout sets a per-request timeout on the default HTTP client. Cannot be combined with WithHTTPClient — the last option applied wins.

type Order

type Order struct {
	OrderID             string          `json:"order_id"`
	ConcludeDestination string          `json:"conclude_destination"`
	GiveCurrency        json.RawMessage `json:"give_currency"`
	InitiallyGiven      Amount          `json:"initially_given"`
	GiveBalance         Amount          `json:"give_balance"`
	AskCurrency         json.RawMessage `json:"ask_currency"`
	InitiallyAsked      Amount          `json:"initially_asked"`
	AskBalance          Amount          `json:"ask_balance"`
	Nonce               Uint64          `json:"nonce"`
}

Order is one entry returned by ListOrders, GetOrder, and ListOrdersByPair. GiveCurrency and AskCurrency are raw JSON with a "type" field of "Coin" or "Token".

type PageOpts

type PageOpts struct {
	Offset uint32
	Items  uint32
}

PageOpts controls pagination for list endpoints. Zero values use server defaults (offset=0, items=10).

type PerThousand

type PerThousand float64

PerThousand holds a margin_ratio_per_thousand value as a float64. The API may return the value as a bare number (35), a quoted integer ("35"), or a quoted decimal with a spurious percent sign ("3.5%"). In all cases the numeric part is stored as-is in per-thousand units.

func (PerThousand) MarshalJSON

func (n PerThousand) MarshalJSON() ([]byte, error)

func (*PerThousand) UnmarshalJSON

func (n *PerThousand) UnmarshalJSON(b []byte) error

type Pool

type Pool struct {
	PoolID                  string      `json:"pool_id"`
	DecommissionDestination string      `json:"decommission_destination"`
	StakerBalance           Amount      `json:"staker_balance"`
	MarginRatioPerThousand  PerThousand `json:"margin_ratio_per_thousand"`
	CostPerBlock            Amount      `json:"cost_per_block"`
	VRFPublicKey            string      `json:"vrf_public_key"`
	DelegationsBalance      Amount      `json:"delegations_balance"`
}

Pool is one entry returned by ListPools and GetPool.

type PoolDelegation

type PoolDelegation struct {
	DelegationID        string `json:"delegation_id"`
	NextNonce           Uint64 `json:"next_nonce"`
	SpendDestination    string `json:"spend_destination"`
	Balance             Amount `json:"balance"`
	CreationBlockHeight Uint64 `json:"creation_block_height"`
}

PoolDelegation is one entry returned by GetPoolDelegations.

type PoolListOpts

type PoolListOpts struct {
	PageOpts
	// Sort is "by_height" (default, newest first) or "by_pledge" (largest staker balance first).
	Sort string
}

PoolListOpts extends PageOpts with a pool-specific sort order.

type Timestamp

type Timestamp struct {
	Timestamp int64 `json:"timestamp"`
}

Timestamp wraps a Unix seconds timestamp returned by the indexer.

type TokenBalance

type TokenBalance struct {
	TokenID string `json:"token_id"`
	Amount  Amount `json:"amount"`
}

TokenBalance is one entry in AddressInfo.Tokens.

type TokenInfo

type TokenInfo struct {
	Authority         string          `json:"authority"`
	IsLocked          bool            `json:"is_locked"`
	CirculatingSupply Amount          `json:"circulating_supply"`
	TokenTicker       string          `json:"token_ticker"`
	MetadataURI       string          `json:"metadata_uri"`
	NumberOfDecimals  uint8           `json:"number_of_decimals"`
	TotalSupply       json.RawMessage `json:"total_supply"`
	Frozen            bool            `json:"frozen"`
	// IsTokenUnfreezable is non-nil only when Frozen is true.
	IsTokenUnfreezable *bool `json:"is_token_unfreezable"`
	// IsTokenFreezable is non-nil only when Frozen is false.
	IsTokenFreezable *bool  `json:"is_token_freezable"`
	NextNonce        Uint64 `json:"next_nonce"`
}

TokenInfo is returned by GetToken.

type TokenTx

type TokenTx struct {
	TxGlobalIndex uint64 `json:"tx_global_index"`
	TxID          string `json:"tx_id"`
}

TokenTx is one entry returned by GetTokenTransactions.

type Transaction

type Transaction struct {
	ID            string          `json:"id"`
	Inputs        json.RawMessage `json:"inputs"`
	Outputs       json.RawMessage `json:"outputs"`
	BlockID       string          `json:"block_id"`
	Timestamp     string          `json:"timestamp"`
	Confirmations string          `json:"confirmations"`
}

Transaction is returned by GetTransaction and ListTransactions. BlockID, Timestamp, and Confirmations are empty strings for unconfirmed transactions.

type TxOutput

type TxOutput = json.RawMessage

TxOutput is the raw JSON of one transaction output. Its shape is determined by the "type" field. Common types: "Transfer", "LockThenTransfer", "Burn", "CreateStakePool", "ProduceBlockFromStake", "CreateDelegationId", "DelegateStaking", "IssueFungibleToken", "IssueNft", "DataDeposit", "Htlc", "CreateOrder".

type UTXO

type UTXO struct {
	Outpoint UTXOOutpoint `json:"outpoint"`
	Output   TxOutput     `json:"utxo"`
}

UTXO is one entry returned by GetSpendableUTXOs and GetAllUTXOs.

type UTXOOutpoint

type UTXOOutpoint struct {
	SourceID string `json:"source_id"`
	Index    uint32 `json:"index"`
}

UTXOOutpoint identifies a UTXO by its source transaction id and output index.

type Uint64

type Uint64 uint64

Uint64 is a uint64 that accepts both a bare JSON number and a quoted-string number (e.g. both 42 and "42"). Several Mintlayer API fields are documented as integers but are serialised as strings by the server.

func (Uint64) MarshalJSON

func (n Uint64) MarshalJSON() ([]byte, error)

func (*Uint64) UnmarshalJSON

func (n *Uint64) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL