1#!/usr/bin/ruby
2# frozen_string_literal: true
3
4# This is meant to be run with the output of detect_duplicate_addrs on stdin
5# The assumption is that some logging will dump that, and then someone will
6# run this after looking into why
7# Theoretically they could be piped together directly for automated fixing
8
9require 'redis'
10
11redis = Redis.new
12
13customer_id = ENV['DEFAULT_CUSTOMER_ID']
14unless customer_id
15 puts "The env-var DEFAULT_CUSTOMER_ID must be set to the ID of the customer who will receive the duplicated addrs, preferably a support customer or something linked to notifications when stray money is sent to these addresses"
16 exit 1
17end
18
19
20STDIN.each_line do |line|
21 match = line.match(/^(\w+) is used by the following \d+ keys: (.*)/)
22 unless match
23 puts "The following line can't be understood and is being ignored"
24 puts " #{line}"
25 next
26 end
27
28 addr = match[1]
29 keys = match[2].split(" ")
30
31 # This is the customer ID of the support chat
32 # All duplicates are moved to the support addr so we still hear when people
33 # send money there
34 redis.sadd("jmp_customer_btc_addresses-#{customer_id}", addr)
35
36 keys.each do |key|
37 redis.srem(key, addr)
38 end
39end