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