Skip to content

Class BSV::Network::Provider

Inherits: Object

Provider is a named configuration container that hosts one or more Protocol instances and dispatches commands to the appropriate protocol.

Protocols are registered via a block DSL or by calling #protocol directly after construction. For each command symbol, the first-registered protocol that serves it wins (first-registered-wins, no warning on duplicates).

Example

gorillapool = BSV::Network::Provider.new('GorillaPool') do |p|
  p.protocol Protocols::ARC,         base_url: 'https://arcade.gorillapool.io'
  p.protocol Protocols::Chaintracks, base_url: 'https://arcade.gorillapool.io'
  p.protocol Protocols::Ordinals,    base_url: 'https://ordinals.gorillapool.io'
end

result = gorillapool.call(:broadcast, tx)
result.http_success?  # => true

Attributes

auth [R]

Returns the value of attribute auth.

name [R]

Returns the value of attribute name.

rate_limit [R]

Returns the value of attribute rate_limit.

Public Instance Methods

authenticated?()

Returns true when the provider is configured with authentication credentials (i.e. auth is not :none and not an empty hash). - @return [Boolean]

call(command_name)

Dispatches a command to the first-registered protocol that serves it. - @param command_name [Symbol, String] command to invoke - @param * [Array] positional arguments forwarded to the protocol - @param ** [Hash] keyword arguments forwarded to the protocol - @raise [ArgumentError] when no registered protocol serves the command - @return [ProtocolResponse]

capability_matrix()

Returns a hash mapping each protocol instance to the sorted list of commands it actually serves within this provider (respecting first-registered-wins — a protocol that lost a command to an earlier registration is not listed for that command).

Protocols that serve no commands in this provider are omitted. - @return [Hash{Protocol => Array}]

commands()

Returns the set of all command symbols available on this provider. - @return [Set]

initialize(name, auth: = :none, rate_limit: = nil, &block)

  • @param name [String] human-readable provider name (e.g. 'GorillaPool')
  • @param auth [Hash, Symbol] authentication config or +:none+ (default: +:none+). An empty hash or +nil+ is treated as +:none+.
  • @param rate_limit [Numeric, nil] maximum requests per second (+nil+ = unlimited)
  • @param block [Proc] optional configuration block — yields +self+
  • @return [Provider] a new instance of Provider

protocol(klass)

Registers a protocol class with the provider.

The class is instantiated with the supplied kwargs. Its commands are indexed: each command not yet in the index is mapped to this instance. Commands already in the index are left unchanged (first-registered wins).

The provider remains mutable — protocol may be called after block execution. - @param klass [Class] a Protocol subclass - @param ** [Hash] keyword arguments forwarded to +klass.new+ - @return [Protocol] the newly created protocol instance

protocol_for(command_name)

Returns the protocol instance that serves a given command, or nil if no registered protocol handles it. - @param command_name [Symbol, String] - @return [Protocol, nil]

protocols()

Returns a frozen copy of the registered protocol instances, in registration order. - @return [Array]

to_s()

Returns a human-readable representation of the provider. - @return [String]