Documentation
¶
Index ¶
Constants ¶
const ( Name = "pyth_api" URL = "http://localhost:8444/prices" // SolanaFormatMagic is the Pyth Lazer Solana format magic (LE u32). SolanaFormatMagic uint32 = 0x821a01b9 )
const ( // PythPubKeyEnv is the environment variable holding the trusted Pyth // signer public key (base58-encoded Solana ed25519 public key). PythPubKeyEnv = "PYTH_PUB_KEY" )
Variables ¶
var DefaultAPIConfig = config.APIConfig{ Name: Name, Atomic: false, Enabled: true, Timeout: 3000 * time.Millisecond, Interval: 3000 * time.Millisecond, ReconnectTimeout: 2000 * time.Millisecond, MaxQueries: 1, Endpoints: []config.Endpoint{{URL: URL}}, }
Functions ¶
func NewAPIHandler ¶
func NewAPIHandler( api config.APIConfig, ) (types.PriceAPIDataHandler, error)
NewAPIHandler returns a new Pyth PriceAPIDataHandler.
func VerifyPythSolanaSignature ¶
VerifyPythSolanaSignature decodes the base64 Pyth Lazer Solana-format payload, verifies the ed25519 signature, and checks that the embedded public key matches the trusted key from PYTH_PUB_KEY.
Payload layout (Pyth Lazer "solana" format):
[0..4) magic – LE u32, must be 0x821a01b9 [4..68) signature – 64-byte ed25519 signature [68..100) pubkey – 32-byte ed25519 public key [100..102) msgLen – LE u16, length of signed message [102..102+msgLen) – signed message bytes
Types ¶
type APIHandler ¶
type APIHandler struct {
// contains filtered or unexported fields
}
APIHandler implements the PriceAPIDataHandler interface for Pyth.
func (*APIHandler) CreateURL ¶
func (h *APIHandler) CreateURL( tickers []types.ProviderTicker, ) (string, error)
CreateURL returns the URL used to fetch prices from the Pyth oracle service. Feed IDs are passed as a comma-separated "asset" query parameter, with "&provider=pyth" appended.
func (*APIHandler) ParseResponse ¶
func (h *APIHandler) ParseResponse( tickers []types.ProviderTicker, resp *http.Response, ) types.PriceResponse
ParseResponse parses a batch Pyth API response ({"data": [...]}), verifies each entry's Pyth Solana ed25519 signature, and returns the parsed prices.
type BatchPriceResponse ¶
type BatchPriceResponse struct {
Data []PriceResponse `json:"data"`
}
BatchPriceResponse is the top-level response containing prices for multiple feeds.