~singpolyma/jmp-pay

ref: 6b4d0a87bf73edfa1fe40868ca915d3152c7ffef jmp-pay/bin/correct_duplicate_addrs -rwxr-xr-x 1.2 KiB
6b4d0a87Stephen Paul Weber Update rubocop 1 year, 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/ruby
# frozen_string_literal: true

# This is meant to be run with the output of detect_duplicate_addrs on stdin
# The assumption is that some logging will dump that, and then someone will
# run this after looking into why
# Theoretically they could be piped together directly for automated fixing

require "redis"

redis = Redis.new

customer_id = ENV["DEFAULT_CUSTOMER_ID"]
unless customer_id
	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"
	exit 1
end

$stdin.each_line do |line|
	match = line.match(/^(\w+) is used by the following \d+ keys: (.*)/)
	unless match
		puts "The following line can't be understood and is being ignored"
		puts "  #{line}"
		next
	end

	addr = match[1]
	keys = match[2].split(" ")

	# This is the customer ID of the support chat
	# All duplicates are moved to the support addr so we still hear when people
	# send money there
	redis.sadd("jmp_customer_btc_addresses-#{customer_id}", addr)

	keys.each do |key|
		redis.srem(key, addr)
	end
end