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.success?  # => true

Attributes

name [R]

Returns the value of attribute name.

Public Instance Methods

call(command_name, *args, **kwargs)

Dispatches a command to the first-registered protocol that serves it. - @param command_name [Symbol, String] command to invoke - @param args [Array] positional arguments forwarded to the protocol - @param kwargs [Hash] keyword arguments forwarded to the protocol - @raise [ArgumentError] when no registered protocol serves the command - @return [Result::Success, Result::Error, Result::NotFound]

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, &block)

  • @param name [String] human-readable provider name (e.g. 'GorillaPool')
  • @param block [Proc] optional configuration block — yields +self+
  • @return [Provider] a new instance of Provider

protocol(klass, **kwargs)

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 kwargs [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]