Class: BSV::Network::Providers::WhatsOnChain
- Inherits:
-
Object
- Object
- BSV::Network::Providers::WhatsOnChain
- Defined in:
- lib/bsv/network/providers/whats_on_chain.rb
Overview
WhatsOnChain returns pre-configured Provider instances using the WhatsOnChain REST API (WoCREST protocol).
The base URL is fully resolved per network — no {network} template is used in provider defaults. The WoCREST protocol’s network: param is omitted since the URL already encodes the network segment.
Example
provider = BSV::Network::Providers::WhatsOnChain.mainnet
provider.call(:get_tx, 'abc123...')
provider = BSV::Network::Providers::WhatsOnChain.mainnet(auth: { api_key: 'my-key' })
provider.call(:broadcast, tx)
# Legacy api_key: shorthand — still supported
provider = BSV::Network::Providers::WhatsOnChain.testnet(api_key: 'my-key')
Constant Summary collapse
- DEFAULT_RATE_LIMIT =
Default requests-per-second limit for unauthenticated use.
3
Class Method Summary collapse
-
.default(testnet: false, network: nil, auth: nil, rate_limit: DEFAULT_RATE_LIMIT, **opts) ⇒ Provider
Returns a Provider for the given network.
-
.mainnet(auth: nil, rate_limit: DEFAULT_RATE_LIMIT, **opts) ⇒ Provider
Returns a mainnet Provider configured with WoCREST.
-
.stn(auth: nil, rate_limit: DEFAULT_RATE_LIMIT, **opts) ⇒ Provider
Returns a Provider for the BSV Scaling Test Network (STN).
-
.testnet(auth: nil, rate_limit: DEFAULT_RATE_LIMIT, **opts) ⇒ Provider
Returns a testnet Provider configured with WoCREST.
Class Method Details
.default(testnet: false, network: nil, auth: nil, rate_limit: DEFAULT_RATE_LIMIT, **opts) ⇒ Provider
Returns a Provider for the given network.
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/bsv/network/providers/whats_on_chain.rb', line 77 def self.default(testnet: false, network: nil, auth: nil, rate_limit: DEFAULT_RATE_LIMIT, **opts) kwargs = { auth: auth, rate_limit: rate_limit, **opts } if network case network.to_sym when :main, :mainnet then mainnet(**kwargs) when :test, :testnet then testnet(**kwargs) when :stn then stn(**kwargs) else raise ArgumentError, "unknown network: #{network}" end else testnet ? testnet(**kwargs) : mainnet(**kwargs) end end |
.mainnet(auth: nil, rate_limit: DEFAULT_RATE_LIMIT, **opts) ⇒ Provider
Returns a mainnet Provider configured with WoCREST.
33 34 35 36 37 38 39 |
# File 'lib/bsv/network/providers/whats_on_chain.rb', line 33 def self.mainnet(auth: nil, rate_limit: DEFAULT_RATE_LIMIT, **opts) resolved_auth = auth || (opts[:api_key] ? { api_key: opts[:api_key] } : :none) Provider.new('WhatsOnChain', auth: resolved_auth, rate_limit: rate_limit) do |p| p.protocol Protocols::WoCREST, base_url: 'https://api.whatsonchain.com/v1/bsv/main', auth: auth, **opts end end |
.stn(auth: nil, rate_limit: DEFAULT_RATE_LIMIT, **opts) ⇒ Provider
Returns a Provider for the BSV Scaling Test Network (STN).
61 62 63 64 65 66 67 |
# File 'lib/bsv/network/providers/whats_on_chain.rb', line 61 def self.stn(auth: nil, rate_limit: DEFAULT_RATE_LIMIT, **opts) resolved_auth = auth || (opts[:api_key] ? { api_key: opts[:api_key] } : :none) Provider.new('WhatsOnChain', auth: resolved_auth, rate_limit: rate_limit) do |p| p.protocol Protocols::WoCREST, base_url: 'https://api.whatsonchain.com/v1/bsv/stn', auth: auth, **opts end end |
.testnet(auth: nil, rate_limit: DEFAULT_RATE_LIMIT, **opts) ⇒ Provider
Returns a testnet Provider configured with WoCREST.
47 48 49 50 51 52 53 |
# File 'lib/bsv/network/providers/whats_on_chain.rb', line 47 def self.testnet(auth: nil, rate_limit: DEFAULT_RATE_LIMIT, **opts) resolved_auth = auth || (opts[:api_key] ? { api_key: opts[:api_key] } : :none) Provider.new('WhatsOnChain', auth: resolved_auth, rate_limit: rate_limit) do |p| p.protocol Protocols::WoCREST, base_url: 'https://api.whatsonchain.com/v1/bsv/test', auth: auth, **opts end end |