Documentation
¶
Index ¶
- Constants
- Variables
- func SetPaginationHeaders(w http.ResponseWriter, totalItems int, params PaginationParams)
- type BlockInfo
- type BlockResponse
- type Blockfrost
- type BlockfrostConfig
- type BlockfrostNode
- type ChainTipInfo
- type EpochInfo
- type EpochResponse
- type ErrorResponse
- type HealthResponse
- type NetworkResponse
- type NetworkStake
- type NetworkSupply
- type NodeAdapter
- func (a *NodeAdapter) ChainTip() (ChainTipInfo, error)
- func (a *NodeAdapter) CurrentEpoch() (EpochInfo, error)
- func (a *NodeAdapter) CurrentProtocolParams() (ProtocolParamsInfo, error)
- func (a *NodeAdapter) LatestBlock() (BlockInfo, error)
- func (a *NodeAdapter) LatestBlockTxHashes() ([]string, error)
- type PaginationParams
- type ProtocolParamsInfo
- type ProtocolParamsResponse
- type RootResponse
Constants ¶
const ( DefaultPaginationCount = 100 MaxPaginationCount = 100 DefaultPaginationPage = 1 PaginationOrderAsc = "asc" PaginationOrderDesc = "desc" )
Variables ¶
var ErrInvalidPaginationParameters = errors.New(
"invalid pagination parameters",
)
Functions ¶
func SetPaginationHeaders ¶
func SetPaginationHeaders( w http.ResponseWriter, totalItems int, params PaginationParams, )
SetPaginationHeaders sets Blockfrost pagination headers.
Types ¶
type BlockInfo ¶
type BlockInfo struct {
Hash string
Slot uint64
Epoch uint64
EpochSlot uint64
Height uint64
Time int64
Size uint64
TxCount int
SlotLeader string
PreviousBlock string
Confirmations uint64
}
BlockInfo holds block data needed by the API.
type BlockResponse ¶
type BlockResponse struct {
Time int64 `json:"time"`
Height uint64 `json:"height"`
Hash string `json:"hash"`
Slot uint64 `json:"slot"`
Epoch uint64 `json:"epoch"`
EpochSlot uint64 `json:"epoch_slot"`
SlotLeader string `json:"slot_leader"`
Size uint64 `json:"size"`
TxCount int `json:"tx_count"`
Output *string `json:"output"`
Fees *string `json:"fees"`
BlockVRF *string `json:"block_vrf"`
OPCert *string `json:"op_cert"`
OPCertCounter *string `json:"op_cert_counter"`
PreviousBlock string `json:"previous_block"`
NextBlock *string `json:"next_block"`
Confirmations uint64 `json:"confirmations"`
}
BlockResponse represents a Blockfrost block object.
type Blockfrost ¶
type Blockfrost struct {
// contains filtered or unexported fields
}
Blockfrost is the Blockfrost-compatible REST API server.
func New ¶
func New( cfg BlockfrostConfig, node BlockfrostNode, logger *slog.Logger, ) *Blockfrost
New creates a new Blockfrost API server instance.
type BlockfrostConfig ¶
type BlockfrostConfig struct {
// ListenAddress is the address to listen on.
// Defaults to ":3000".
ListenAddress string
}
BlockfrostConfig holds configuration for the Blockfrost API server.
type BlockfrostNode ¶
type BlockfrostNode interface {
// ChainTip returns the current chain tip info.
ChainTip() (ChainTipInfo, error)
// LatestBlock returns information about the latest
// block on the chain.
LatestBlock() (BlockInfo, error)
// LatestBlockTxHashes returns the transaction hashes
// for the latest block.
LatestBlockTxHashes() ([]string, error)
// CurrentEpoch returns information about the current
// epoch.
CurrentEpoch() (EpochInfo, error)
// CurrentProtocolParams returns the current protocol
// parameters.
CurrentProtocolParams() (ProtocolParamsInfo, error)
}
BlockfrostNode is the interface that the Blockfrost API server uses to query the node for blockchain data. This decouples the HTTP server from the concrete Node struct and enables testing with mock implementations.
type ChainTipInfo ¶
ChainTipInfo holds chain tip data needed by the API.
type EpochInfo ¶
type EpochInfo struct {
Epoch uint64
StartTime int64
EndTime int64
FirstBlockTime int64
LastBlockTime int64
BlockCount int
TxCount int
}
EpochInfo holds epoch data needed by the API.
type EpochResponse ¶
type EpochResponse struct {
Epoch uint64 `json:"epoch"`
StartTime int64 `json:"start_time"`
EndTime int64 `json:"end_time"`
FirstBlockTime int64 `json:"first_block_time"`
LastBlockTime int64 `json:"last_block_time"`
BlockCount int `json:"block_count"`
TxCount int `json:"tx_count"`
Output string `json:"output"`
Fees string `json:"fees"`
ActiveStake *string `json:"active_stake"`
}
EpochResponse represents a Blockfrost epoch object.
type ErrorResponse ¶
type ErrorResponse struct {
StatusCode int `json:"status_code"`
Error string `json:"error"`
Message string `json:"message"`
}
ErrorResponse represents a Blockfrost error response.
type HealthResponse ¶
type HealthResponse struct {
IsHealthy bool `json:"is_healthy"`
}
HealthResponse is returned by GET /health.
type NetworkResponse ¶
type NetworkResponse struct {
Supply NetworkSupply `json:"supply"`
Stake NetworkStake `json:"stake"`
}
NetworkResponse represents Blockfrost network info.
type NetworkStake ¶
NetworkStake holds stake information.
type NetworkSupply ¶
type NetworkSupply struct {
Max string `json:"max"`
Total string `json:"total"`
Circulating string `json:"circulating"`
Locked string `json:"locked"`
Treasury string `json:"treasury"`
Reserves string `json:"reserves"`
}
NetworkSupply holds supply information.
type NodeAdapter ¶
type NodeAdapter struct {
// contains filtered or unexported fields
}
NodeAdapter wraps a real dingo Node's LedgerState to implement the BlockfrostNode interface.
func NewNodeAdapter ¶
func NewNodeAdapter( ls *ledger.LedgerState, ) *NodeAdapter
NewNodeAdapter creates a NodeAdapter that queries the given LedgerState for blockchain data. Panics if ls is nil.
func (*NodeAdapter) ChainTip ¶
func (a *NodeAdapter) ChainTip() ( ChainTipInfo, error, )
ChainTip returns the current chain tip from the ledger state.
func (*NodeAdapter) CurrentEpoch ¶
func (a *NodeAdapter) CurrentEpoch() ( EpochInfo, error, )
CurrentEpoch returns information about the current epoch.
func (*NodeAdapter) CurrentProtocolParams ¶
func (a *NodeAdapter) CurrentProtocolParams() ( ProtocolParamsInfo, error, )
CurrentProtocolParams returns the current protocol parameters.
func (*NodeAdapter) LatestBlock ¶
func (a *NodeAdapter) LatestBlock() ( BlockInfo, error, )
LatestBlock returns information about the latest block.
func (*NodeAdapter) LatestBlockTxHashes ¶
func (a *NodeAdapter) LatestBlockTxHashes() ( []string, error, )
LatestBlockTxHashes returns transaction hashes from the latest block.
type PaginationParams ¶
PaginationParams contains parsed pagination query values.
func ParsePagination ¶
func ParsePagination(r *http.Request) (PaginationParams, error)
ParsePagination parses pagination query parameters and applies defaults and bounds clamping.
type ProtocolParamsInfo ¶
type ProtocolParamsInfo struct {
Epoch uint64
MinFeeA int
MinFeeB int
MaxBlockSize int
MaxTxSize int
MaxBlockHeaderSize int
KeyDeposit string
PoolDeposit string
EMax int
NOpt int
A0 float64
Rho float64
Tau float64
ProtocolMajorVer int
ProtocolMinorVer int
MinPoolCost string
CoinsPerUtxoSize string
PriceMem float64
PriceStep float64
MaxTxExMem string
MaxTxExSteps string
MaxBlockExMem string
MaxBlockExSteps string
MaxValSize string
CollateralPercent int
MaxCollateralInputs int
}
ProtocolParamsInfo holds protocol parameter data needed by the API.
type ProtocolParamsResponse ¶
type ProtocolParamsResponse struct {
Epoch uint64 `json:"epoch"`
MinFeeA int `json:"min_fee_a"`
MinFeeB int `json:"min_fee_b"`
MaxBlockSize int `json:"max_block_size"`
MaxTxSize int `json:"max_tx_size"`
MaxBlockHeaderSize int `json:"max_block_header_size"`
KeyDeposit string `json:"key_deposit"`
PoolDeposit string `json:"pool_deposit"`
EMax int `json:"e_max"`
NOpt int `json:"n_opt"`
A0 float64 `json:"a0"`
Rho float64 `json:"rho"`
Tau float64 `json:"tau"`
//nolint:tagliatelle
DecentralisationParam float64 `json:"decentralisation_param"`
ExtraEntropy *map[string]any `json:"extra_entropy"`
ProtocolMajorVer int `json:"protocol_major_ver"`
ProtocolMinorVer int `json:"protocol_minor_ver"`
MinUtxo string `json:"min_utxo"`
MinPoolCost string `json:"min_pool_cost"`
Nonce string `json:"nonce"`
CoinsPerUtxoSize *string `json:"coins_per_utxo_size"`
CoinsPerUtxoWord string `json:"coins_per_utxo_word"`
CostModels *any `json:"cost_models"`
PriceMem *float64 `json:"price_mem"`
PriceStep *float64 `json:"price_step"`
MaxTxExMem *string `json:"max_tx_ex_mem"`
MaxTxExSteps *string `json:"max_tx_ex_steps"`
MaxBlockExMem *string `json:"max_block_ex_mem"`
MaxBlockExSteps *string `json:"max_block_ex_steps"`
MaxValSize *string `json:"max_val_size"`
CollateralPercent *int `json:"collateral_percent"`
MaxCollateralInputs *int `json:"max_collateral_inputs"`
}
ProtocolParamsResponse represents Blockfrost protocol parameters.
type RootResponse ¶
RootResponse is returned by GET /.