Class: BSV::Transaction::ChainTrackers::WhatsOnChain
- Inherits:
-
BSV::Transaction::ChainTracker
- Object
- BSV::Transaction::ChainTracker
- BSV::Transaction::ChainTrackers::WhatsOnChain
- Defined in:
- lib/bsv/transaction/chain_trackers/whats_on_chain.rb
Overview
Chain tracker that verifies merkle roots using the WhatsOnChain API.
Delegates all HTTP communication to Network::Protocols::WoCREST. The constructor signature and BSV::Transaction::ChainTracker contract are preserved.
Note: the WoC API key is sent as a raw Authorization header value (not Bearer-prefixed) to match the existing WoC API convention.
Defined Under Namespace
Classes: RawAuthClient
Class Method Summary collapse
-
.default(testnet: false, **opts) ⇒ WhatsOnChain
Returns a WhatsOnChain chain tracker using the provider default.
Instance Method Summary collapse
-
#current_height ⇒ Integer
Return the current blockchain height.
-
#initialize(network: :main, api_key: nil, http_client: nil, protocol: nil) ⇒ WhatsOnChain
constructor
A new instance of WhatsOnChain.
-
#valid_root_for_height?(root, height) ⇒ Boolean
Verify that a merkle root is valid for the given block height.
Constructor Details
#initialize(network: :main, api_key: nil, http_client: nil, protocol: nil) ⇒ WhatsOnChain
Returns a new instance of WhatsOnChain.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/bsv/transaction/chain_trackers/whats_on_chain.rb', line 34 def initialize(network: :main, api_key: nil, http_client: nil, protocol: nil) super() if protocol @protocol = protocol else wrapped_client = api_key ? RawAuthClient.new(api_key, http_client) : http_client provider = BSV::Network::Providers::WhatsOnChain.default(network: network, http_client: wrapped_client) @protocol = provider.protocol_for(:valid_root) end end |
Class Method Details
.default(testnet: false, **opts) ⇒ WhatsOnChain
Returns a WhatsOnChain chain tracker using the provider default.
25 26 27 28 |
# File 'lib/bsv/transaction/chain_trackers/whats_on_chain.rb', line 25 def self.default(testnet: false, **opts) provider = BSV::Network::Providers::WhatsOnChain.default(testnet: testnet, **opts) new(protocol: provider.protocol_for(:valid_root)) end |
Instance Method Details
#current_height ⇒ Integer
Return the current blockchain height.
69 70 71 72 73 74 75 76 77 |
# File 'lib/bsv/transaction/chain_trackers/whats_on_chain.rb', line 69 def current_height result = @protocol.call(:current_height) return result.data if result.success? raise BSV::Network::ChainProviderError.new( result..to_s, status_code: result.[:status_code] ) end |
#valid_root_for_height?(root, height) ⇒ Boolean
Verify that a merkle root is valid for the given block height.
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/bsv/transaction/chain_trackers/whats_on_chain.rb', line 51 def valid_root_for_height?(root, height) result = @protocol.call(:valid_root, root, height) return false if result.not_found? if result.error? raise BSV::Network::ChainProviderError.new( result..to_s, status_code: result.[:status_code] ) end result.data == true end |