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 30 endpoints covering chain info, block headers, transactions, UTXOs, scripts, address queries, broadcast, and health. Seven 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, #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, 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)

    optional Bearer API key

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

    injectable HTTP client for testing



97
98
99
100
101
102
103
104
105
# File 'lib/bsv/network/protocols/woc_rest.rb', line 97

def initialize(base_url:, network: :main, api_key: nil, http_client: nil)
  @network_name = resolve_network(network)
  super(
    base_url: base_url,
    api_key: api_key,
    network: @network_name,
    http_client: http_client
  )
end

Instance Attribute Details

#network_nameObject (readonly)

Returns the value of attribute network_name.



90
91
92
# File 'lib/bsv/network/protocols/woc_rest.rb', line 90

def network_name
  @network_name
end

Instance Method Details

#build_request(http_method, uri, body) ⇒ Object

WoC expects a raw Authorization header (no Bearer prefix). Override the base class which adds “Bearer ”.



109
110
111
112
113
# File 'lib/bsv/network/protocols/woc_rest.rb', line 109

def build_request(http_method, uri, body)
  request = super
  request['Authorization'] = @api_key if @api_key
  request
end