Class: BSV::Wallet::InlineQueue

Inherits:
Object
  • Object
show all
Includes:
BroadcastQueue
Defined in:
lib/bsv/wallet_interface/inline_queue.rb

Overview

Synchronous broadcast queue adapter — the default for WalletClient.

InlineQueue 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

Methods included from BroadcastQueue

status_for_error

Constructor Details

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

Returns a new instance of InlineQueue.

Parameters:

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

    broadcaster object; nil disables broadcasting

  • storage (StorageAdapter)

    wallet storage adapter



21
22
23
24
# File 'lib/bsv/wallet_interface/inline_queue.rb', line 21

def initialize(storage:, broadcaster: nil)
  @broadcaster = broadcaster
  @storage = storage
end

Instance Method Details

#async?Boolean

Returns false — this adapter executes synchronously.

Returns:

  • (Boolean)


29
30
31
# File 'lib/bsv/wallet_interface/inline_queue.rb', line 29

def async?
  false
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



52
53
54
55
56
57
58
# File 'lib/bsv/wallet_interface/inline_queue.rb', line 52

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)


40
41
42
43
# File 'lib/bsv/wallet_interface/inline_queue.rb', line 40

def status(txid)
  actions = @storage.find_actions({ txid: txid, limit: 1, offset: 0 })
  actions.first&.dig(:status)
end