Skip to content

Class BSV::Transaction::FeeModels::LivePolicy

Inherits: BSV::Transaction::FeeModel

Dynamic fee model that fetches the live mining fee rate from an ARC policy endpoint.

The fetched rate is cached for a configurable TTL (default 5 minutes) so repeated calls to {#compute_fee} do not repeatedly query the API. If a fetch fails, the model falls back to a configurable default rate.

@example

model = BSV::Transaction::FeeModels::LivePolicy.new(
  arc_url: 'https://arcade.gorillapool.io',
  fallback_rate: 50
)
fee = model.compute_fee(transaction)

Constants

DEFAULT_CACHE_TTL

5 minutes in seconds

DEFAULT_FALLBACK_RATE

Not documented.

Attributes

arc_url [R]

  • @return [String] the ARC base URL

cache_ttl [R]

  • @return [Integer] cache TTL in seconds

fallback_rate [R]

  • @return [Integer] fallback sat/kB when fetch fails

Public Class Methods

default(api_key: = nil)

Returns a LivePolicy with sensible defaults (GorillaPool ARC, 100 sat/kB fallback, 5-minute cache). - @param api_key [String, nil] optional ARC API key - @return [LivePolicy]

Public Instance Methods

compute_fee(transaction)

Compute the fee for a transaction using the latest ARC rate. - @param transaction [Transaction] the transaction to compute the fee for - @return [Integer] the fee in satoshis

current_rate()

Return the current sat/kB rate, fetching from ARC if the cache has expired. - @return [Integer] satoshis per kilobyte

initialize(arc_url:, fallback_rate: = DEFAULT_FALLBACK_RATE, cache_ttl: = DEFAULT_CACHE_TTL, api_key: = nil, http_client: = nil)

  • @param arc_url [String] ARC base URL (e.g. 'https://arcade.gorillapool.io')
  • @param fallback_rate [Integer] sat/kB to use when fetch fails (default: 100)
  • @param cache_ttl [Integer] seconds to cache a fetched rate (default: 300)
  • @param api_key [String, nil] optional Bearer token for ARC authentication
  • @param http_client [#request, nil] injectable HTTP client for testing
  • @return [LivePolicy] a new instance of LivePolicy