Class: BSV::Wallet::Postgres::BroadcastCallback

Inherits:
Object
  • Object
show all
Defined in:
lib/bsv/wallet/postgres/broadcast_callback.rb

Overview

Rack app that receives ARC TransactionStatus webhook POSTs and delegates to a BroadcastQueue instance.

Mount however the host application prefers:

- Standalone: rackup with config.ru
- Rails: mount BroadcastCallback.new(broadcast_queue:) => '/arc/callback'

Instance Method Summary collapse

Constructor Details

#initialize(broadcast_queue:) ⇒ BroadcastCallback

Returns a new instance of BroadcastCallback.



16
17
18
# File 'lib/bsv/wallet/postgres/broadcast_callback.rb', line 16

def initialize(broadcast_queue:)
  @broadcast_queue = broadcast_queue
end

Instance Method Details

#call(env) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/bsv/wallet/postgres/broadcast_callback.rb', line 20

def call(env)
  request = Rack::Request.new(env)
  body = JSON.parse(request.body.read, symbolize_names: true)
  event = decode_event(body)
  @broadcast_queue.handle_event(event)
  [200, { 'content-type' => 'text/plain' }, ['OK']]
rescue JSON::ParserError
  [400, { 'content-type' => 'text/plain' }, ['Bad Request']]
end