1# frozen_string_literal: true
2
3require 'redis'
4require 'dhall'
5require_relative '../lib/redis_addresses'
6require_relative '../lib/electrum'
7
8config =
9 Dhall::Coder
10 .new(safe: Dhall::Coder::JSON_LIKE + [Symbol, Proc])
11 .load(ARGV[0], transform_keys: :to_sym)
12
13redis = Redis.new
14electrum = Electrum.new(**config)
15
16get_addresses_with_users(redis).each do |addr, keys|
17 match = keys.first.match(/.*-(\d+)$/)
18 unless match
19 puts "Can't understand key #{keys.first}, skipping"
20 next
21 end
22
23 customer_id = match[1]
24 url = "https://pay.jmp.chat/electrum_notify?address=#{addr}&customer_id=#{customer_id}"
25
26 unless electrum.notify(addr, url)
27 puts "Failed to setup #{addr} to notify #{url}. Skipping"
28 end
29end