Documentation
¶
Overview ¶
Package explorer provides an explorer client with support for multiple concurrent WebSocket connections for addresses tracking.
Architecture ¶
- Multiple concurrent WebSocket connections
- Hash-based address distribution for consistent routing
- Automatic fallback to polling if WebSocket connections fails
Usage ¶
Basic usage with default settings:
svc, err := explorer.NewExplorer("", arklib.Bitcoin, explorer.WithTracker(true))
if err != nil {
log.Fatal(err)
}
defer svc.Stop()
Subscribe to addresses:
addresses := []string{"bc1q...", "bc1p...", ...}
if err := svc.SubscribeForAddresses(addresses); err != nil {
log.Fatal(err)
}
// Listen for events
for event := range svc.GetAddressesEvents() {
fmt.Printf("New UTXOs: %d, Spent: %d\n", len(event.NewUtxos), len(event.SpentUtxos))
}
Thread Safety ¶
All public methods are thread-safe and can be called concurrently.
Index ¶
Constants ¶
const (
BitcoinExplorer = "bitcoin"
)
Variables ¶
This section is empty.
Functions ¶
func NewExplorer ¶
NewExplorer creates a new Explorer instance for the specified network. If baseUrl is empty, it uses the default explorer URL for the network.
The explorer supports:
- Multiple concurrent WebSocket connections for scalability
- Automatic fallback to polling if WebSocket connections fail
Example:
svc, err := explorer.NewExplorer("https://mempool.space/api", arklib.Bitcoin, explorer.WithTracker(true))
Types ¶
type Option ¶
type Option func(*explorerSvc)
Option is a functional option for configuring the Explorer service.
func WithPollInterval ¶
WithPollInterval sets the polling interval for address tracking when WebSocket is unavailable. Default: 10 seconds.
func WithTracker ¶
WithTracker enables or disables address tracking. When disabled, the explorer only provides REST API functionality without WebSocket connections. Default: tracking is disabled.