Class: BSV::Wallet::BroadcastQueue::Inline

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(storage:, broadcaster: nil) ⇒ Inline

Returns a new instance of Inline.

Parameters:

  • broadcaster (#broadcast, nil) (defaults to: nil)

    broadcaster object; nil disables broadcasting

  • storage (BSV::Wallet::Store)

    wallet storage adapter



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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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.

Parameters:

  • payload (Hash)

    broadcast payload (see BroadcastQueue module docs)

Returns:

  • (Hash)

    result hash containing at minimum :txid and :tx



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.

Parameters:

  • txid (String)

    hex transaction identifier

Returns:

  • (String, nil)


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