Class: BSV::Network::Protocols::WoCREST

Inherits:
BSV::Network::Protocol show all
Defined in:
lib/bsv/network/protocols/woc_rest.rb

Overview

WoCREST implements the WhatsOnChain REST API as a Protocol subclass.

Provides endpoints covering chain info, block headers, transactions, UTXOs, scripts, address queries, broadcast, search, stats, and health. Escape hatches handle WoC-specific body formats and field remapping.

Network resolution

WoC uses main and test in its URL paths. The constructor accepts symbolic aliases (:mainnet, :testnet, :stn) and resolves them to the correct string.

Usage

woc = BSV::Network::Protocols::WoCREST.new(network: :main)
result = woc.call(:get_tx, 'abc123...')
puts result.data if result.success?

Constant Summary collapse

NETWORKS =
{
  'main' => 'main',
  'test' => 'test',
  'stn' => 'stn',
  main: 'main',
  test: 'test',
  stn: 'stn',
  mainnet: 'main',
  testnet: 'test'
}.freeze

Instance Attribute Summary collapse

Attributes inherited from BSV::Network::Protocol

#api_key, #auth, #base_url, #http_client, #network

Instance Method Summary collapse

Methods inherited from BSV::Network::Protocol

#call, commands, #default_call, endpoint, endpoints, inherited, subscription, subscriptions

Constructor Details

#initialize(base_url:, network: :main, api_key: nil, auth: nil, http_client: nil) ⇒ WoCREST

Returns a new instance of WoCREST.

Parameters:

  • base_url (String)

    base URL for the WoC API; may contain {network} which will be interpolated with the resolved network name

  • network (Symbol, String) (defaults to: :main)

    :main, :mainnet, :test, :testnet, :stn

  • api_key (String, nil) (defaults to: nil)

    legacy API key — sends Authorization: key (no Bearer prefix, matching WoC’s expected auth format)

  • auth (Hash, Symbol, nil) (defaults to: nil)

    auth config hash forwarded to Protocol; when provided, takes precedence over api_key:

  • http_client (Object, nil) (defaults to: nil)

    injectable HTTP client for testing



132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/bsv/network/protocols/woc_rest.rb', line 132

def initialize(base_url:, network: :main, api_key: nil, auth: nil, http_client: nil)
  @network_name = resolve_network(network)
  # Translate legacy api_key: to auth: { api_key: } so the base class sends
  # the raw key without a Bearer prefix, matching WoC's expected auth format.
  resolved_auth = auth || (api_key ? { api_key: api_key } : nil)
  super(
    base_url: base_url,
    auth: resolved_auth,
    network: @network_name,
    http_client: http_client
  )
end

Instance Attribute Details

#network_nameObject (readonly)

Returns the value of attribute network_name.



122
123
124
# File 'lib/bsv/network/protocols/woc_rest.rb', line 122

def network_name
  @network_name
end