Documentation
¶
Index ¶
- Variables
- type APIError
- type Address
- type AddressTransactionOptions
- type AddressTransactionPage
- type AddressesService
- type Block
- type BlockPage
- type Blockchain
- type BlockchainStatus
- type BlocksService
- type Client
- type ClientOption
- func WithBaseURL(u string) ClientOption
- func WithHTTPClient(hc *http.Client) ClientOption
- func WithRequestHook(hook RequestHook) ClientOption
- func WithRetry(maxAttempts int, initialDelay, maxDelay time.Duration) ClientOption
- func WithTimeout(d time.Duration) ClientOption
- func WithUserAgent(ua string) ClientOption
- type RequestHook
- type RetryConfig
- type StatusService
- type SubTransaction
- type Transaction
- type TransactionIterator
- type TransactionOptions
- type TransactionPage
- type TransactionsService
- func (s *TransactionsService) GetTransaction(ctx context.Context, blockchain, hash string) (*Transaction, error)
- func (s *TransactionsService) ListTransactions(ctx context.Context, blockchain string, opts TransactionOptions) (*TransactionPage, error)
- func (s *TransactionsService) ListTransactionsNext(ctx context.Context, nextURL string) (*TransactionPage, error)
Constants ¶
This section is empty.
Variables ¶
var ( ErrForbidden = errors.New("whalealert: forbidden") ErrNotFound = errors.New("whalealert: not found") ErrRateLimited = errors.New("whalealert: rate limited") ErrBadRequest = errors.New("whalealert: bad request") ErrValidation = errors.New("whalealert: validation error") ErrTransport = errors.New("whalealert: transport error") ErrDecoding = errors.New("whalealert: decoding error") ErrProviderAPI = errors.New("whalealert: provider API error") ErrMissingAPIKey = errors.New("whalealert: API key required for this endpoint") )
Sentinel errors for use with errors.Is.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct {
StatusCode int
Message string
BodyExcerpt string
Headers http.Header
RetryAfter *time.Duration
}
APIError represents an error returned by the Whale Alert API.
type Address ¶
type Address struct {
Amount string `json:"amount"`
Address string `json:"address"`
Owner string `json:"owner,omitempty"`
}
Address represents an input or output address in a sub-transaction. Amount is kept as a string to preserve provider-provided precision.
type AddressTransactionOptions ¶
type AddressTransactionOptions struct {
Symbol string // Optional: filter by symbol
TransactionType string // Optional: filter by transaction type
Limit int // Optional: max results per page
StartIndex int // Optional: pagination offset within the page
Order string // Optional: "asc" or "desc"
}
AddressTransactionOptions controls the query parameters for listing address transactions.
type AddressTransactionPage ¶
type AddressTransactionPage struct {
Transactions []Transaction `json:"transactions"`
Next string `json:"next"`
}
AddressTransactionPage represents a page of address transactions with a next URL.
type AddressesService ¶
type AddressesService struct {
// contains filtered or unexported fields
}
AddressesService provides access to address-related endpoints.
func (*AddressesService) GetAddressTransactions ¶
func (s *AddressesService) GetAddressTransactions(ctx context.Context, blockchain, address string, opts AddressTransactionOptions) (*AddressTransactionPage, error)
GetAddressTransactions returns transactions for an address from the last 30 days.
GET /{blockchain}/address/{hash}/transactions https://developer.whale-alert.io/api-account/documentation#v2-address
func (*AddressesService) GetAddressTransactionsNext ¶
func (s *AddressesService) GetAddressTransactionsNext(ctx context.Context, nextURL string) (*AddressTransactionPage, error)
GetAddressTransactionsNext fetches the next page of address transactions using the provider-supplied next URL.
type Block ¶
type Block struct {
Timestamp int64 `json:"timestamp"`
Hash string `json:"hash"`
Transactions []Transaction `json:"transactions"`
}
Block represents a block at a specific height.
type BlockPage ¶
type BlockPage struct {
Timestamp int64 `json:"timestamp"`
Hash string `json:"hash"`
Transactions []Transaction `json:"transactions"`
Next string `json:"next"`
}
BlockPage represents a block response that includes transactions and a next URL.
type Blockchain ¶
Blockchain represents a supported blockchain and its symbols.
type BlockchainStatus ¶
type BlockchainStatus struct {
StartHeight int64 `json:"start_height"`
EndHeight int64 `json:"end_height"`
BlockCount int64 `json:"block_count"`
}
BlockchainStatus represents the availability window of a blockchain.
type BlocksService ¶
type BlocksService struct {
// contains filtered or unexported fields
}
BlocksService provides access to block-related endpoints.
func (*BlocksService) GetBlock ¶
func (s *BlocksService) GetBlock(ctx context.Context, blockchain string, height int64) (*Block, error)
GetBlock returns a block at a specific height.
GET /{blockchain}/block/{height} https://developer.whale-alert.io/api-account/documentation#v2-block
type Client ¶
type Client struct {
Status *StatusService
Transactions *TransactionsService
Blocks *BlocksService
Addresses *AddressesService
// contains filtered or unexported fields
}
Client is the Whale Alert API HTTP client. It is safe for concurrent use by multiple goroutines. Do not mutate fields after construction.
func NewClient ¶
func NewClient(apiKey string, opts ...ClientOption) *Client
NewClient creates a new Whale Alert API client. The apiKey is required for authenticated endpoints; the public GET /status endpoint works without it.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption configures a Client.
func WithBaseURL ¶
func WithBaseURL(u string) ClientOption
WithBaseURL overrides the default production base URL.
func WithHTTPClient ¶
func WithHTTPClient(hc *http.Client) ClientOption
WithHTTPClient replaces the default HTTP client.
func WithRequestHook ¶
func WithRequestHook(hook RequestHook) ClientOption
WithRequestHook adds a hook invoked before each HTTP request. Multiple hooks are called in registration order.
func WithRetry ¶
func WithRetry(maxAttempts int, initialDelay, maxDelay time.Duration) ClientOption
WithRetry configures the retry policy for idempotent GET requests. Set maxAttempts to 0 to disable retries (the default).
func WithTimeout ¶
func WithTimeout(d time.Duration) ClientOption
WithTimeout sets the HTTP client timeout.
func WithUserAgent ¶
func WithUserAgent(ua string) ClientOption
WithUserAgent overrides the default User-Agent header.
type RequestHook ¶
RequestHook is called before each HTTP request is sent. The URL passed to the hook has the api_key query parameter redacted.
type RetryConfig ¶
type RetryConfig struct {
// MaxAttempts is the maximum number of retry attempts (0 = no retries).
MaxAttempts int
// InitialDelay is the delay before the first retry.
InitialDelay time.Duration
// MaxDelay caps the exponential backoff delay.
MaxDelay time.Duration
}
RetryConfig controls the retry behavior for idempotent GET requests.
type StatusService ¶
type StatusService struct {
// contains filtered or unexported fields
}
StatusService provides access to status-related endpoints.
func (*StatusService) GetBlockchainStatus ¶
func (s *StatusService) GetBlockchainStatus(ctx context.Context, blockchain string) (*BlockchainStatus, error)
GetBlockchainStatus returns the availability window for a specific blockchain. An API key is required.
GET /{blockchain}/status https://developer.whale-alert.io/api-account/documentation#v2-blockchainstatus
func (*StatusService) GetSupportedBlockchains ¶
func (s *StatusService) GetSupportedBlockchains(ctx context.Context) ([]Blockchain, error)
GetSupportedBlockchains returns the list of supported blockchains and their symbols. This endpoint does not require an API key.
GET /status https://developer.whale-alert.io/api-account/documentation#v2-blockchains
type SubTransaction ¶
type SubTransaction struct {
Symbol string `json:"symbol"`
TransactionType string `json:"transaction_type"`
Inputs []Address `json:"inputs"`
Outputs []Address `json:"outputs"`
}
SubTransaction represents a single currency/type split within a transaction.
type Transaction ¶
type Transaction struct {
Height int64 `json:"height"`
IndexInBlock int64 `json:"index_in_block"`
Timestamp int64 `json:"timestamp"`
Hash string `json:"hash"`
Fee string `json:"fee"`
FeeSymbol string `json:"fee_symbol"`
FeeSymbolPrice json.Number `json:"fee_symbol_price"`
SubTransactions []SubTransaction `json:"sub_transactions"`
}
Transaction represents a normalized blockchain transaction. Fee and fee_symbol_price may be strings or numbers from the provider; fee is always kept as a string to preserve precision.
type TransactionIterator ¶
type TransactionIterator struct {
// contains filtered or unexported fields
}
TransactionIterator provides lazy iteration over paginated transaction results. It fetches the next page only when the consumer advances it. Do not retain every page in memory; process items as they arrive.
func NewTransactionIterator ¶
func NewTransactionIterator(ctx context.Context, client *Client, page *TransactionPage) *TransactionIterator
NewTransactionIterator creates an iterator from an initial page.
func (*TransactionIterator) HasNext ¶
func (it *TransactionIterator) HasNext() bool
HasNext returns true if there are more transactions to iterate, either in the current page or via the next URL.
func (*TransactionIterator) Next ¶
func (it *TransactionIterator) Next() (*Transaction, error)
Next advances the iterator and returns the next transaction. It returns io.EOF when all pages are exhausted. It fetches the next page lazily.
type TransactionOptions ¶
type TransactionOptions struct {
StartHeight int64 // Required: starting block height
Symbol string // Optional: filter by symbol (e.g. "BTC")
TransactionType string // Optional: filter by transaction type (e.g. "transfer")
Limit int // Optional: max results per page
StartIndex int // Optional: pagination offset within the page
Order string // Optional: "asc" or "desc"
Format string // Optional: response format
}
TransactionOptions controls the query parameters for listing transactions.
type TransactionPage ¶
type TransactionPage struct {
Transactions []Transaction `json:"transactions"`
Next string `json:"next"`
}
TransactionPage represents a page of transactions with a next URL.
type TransactionsService ¶
type TransactionsService struct {
// contains filtered or unexported fields
}
TransactionsService provides access to transaction-related endpoints.
func (*TransactionsService) GetTransaction ¶
func (s *TransactionsService) GetTransaction(ctx context.Context, blockchain, hash string) (*Transaction, error)
GetTransaction returns a single transaction by its hash.
GET /{blockchain}/transaction/{hash} https://developer.whale-alert.io/api-account/documentation#v2-transaction
func (*TransactionsService) ListTransactions ¶
func (s *TransactionsService) ListTransactions(ctx context.Context, blockchain string, opts TransactionOptions) (*TransactionPage, error)
ListTransactions returns a page of transactions starting at the given height.
GET /{blockchain}/transactions https://developer.whale-alert.io/api-account/documentation#v2-transactions
func (*TransactionsService) ListTransactionsNext ¶
func (s *TransactionsService) ListTransactionsNext(ctx context.Context, nextURL string) (*TransactionPage, error)
ListTransactionsNext fetches the next page of transactions using the provider-supplied next URL. The URL is validated against the configured base URL to prevent following unsafe external URLs.
