Class: BSV::Wallet::BroadcastQueue::Inline
- Inherits:
-
Object
- Object
- BSV::Wallet::BroadcastQueue::Inline
- Includes:
- Interface::BroadcastQueue
- Defined in:
- lib/bsv/wallet/broadcast_queue/inline.rb
Overview
Synchronous broadcast queue adapter — the default for Client.
BroadcastQueue::Inline replicates the current wallet broadcast behaviour exactly:
-
With a broadcaster: calls
broadcaster.broadcast, promotes UTXO state on success, rolls back on failure. -
Without a broadcaster: promotes immediately and returns BEEF for the caller to broadcast manually (backwards-compatible fallback).
Because this adapter executes synchronously, async? returns false and the caller can rely on the returned hash containing the final result.
Instance Method Summary collapse
-
#async? ⇒ Boolean
Returns
false— this adapter executes synchronously. -
#broadcast_enabled? ⇒ Boolean
Returns
truewhen a broadcaster has been configured. -
#enqueue(payload) ⇒ Hash
Broadcasts and promotes (or just promotes) a transaction synchronously.
-
#initialize(storage:, broadcaster: nil) ⇒ Inline
constructor
A new instance of Inline.
-
#status(txid) ⇒ String?
Returns the broadcast status for a previously enqueued transaction.
Constructor Details
#initialize(storage:, broadcaster: nil) ⇒ Inline
Returns a new instance of Inline.
22 23 24 25 |
# File 'lib/bsv/wallet/broadcast_queue/inline.rb', line 22 def initialize(storage:, broadcaster: nil) @broadcaster = broadcaster @storage = storage end |
Instance Method Details
#async? ⇒ Boolean
Returns false — this adapter executes synchronously.
30 31 32 |
# File 'lib/bsv/wallet/broadcast_queue/inline.rb', line 30 def async? false end |
#broadcast_enabled? ⇒ Boolean
Returns true when a broadcaster has been configured.
Client delegates its own broadcast_enabled? to this method so the check works correctly when the broadcaster is embedded in the queue rather than passed directly to the wallet.
41 42 43 |
# File 'lib/bsv/wallet/broadcast_queue/inline.rb', line 41 def broadcast_enabled? !@broadcaster.nil? end |
#enqueue(payload) ⇒ Hash
Broadcasts and promotes (or just promotes) a transaction synchronously.
Dispatches to broadcast_and_promote when a broadcaster is configured, or promote_without_broadcast when none is present.
64 65 66 67 68 69 70 |
# File 'lib/bsv/wallet/broadcast_queue/inline.rb', line 64 def enqueue(payload) if @broadcaster broadcast_and_promote(payload) else promote_without_broadcast(payload) end end |
#status(txid) ⇒ String?
Returns the broadcast status for a previously enqueued transaction.
Delegates to storage and returns the action status field, or nil if the action is not found.
52 53 54 55 |
# File 'lib/bsv/wallet/broadcast_queue/inline.rb', line 52 def status(txid) actions = @storage.find_actions({ txid: txid, limit: 1, offset: 0 }) actions.first&.dig(:status) end |