-
Notifications
You must be signed in to change notification settings - Fork 1
/
GetAllInputKeys.java
executable file
·67 lines (56 loc) · 2.11 KB
/
GetAllInputKeys.java
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import java.io.BufferedReader;
import java.io.FileReader;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.HashSet;
import java.util.Set;
public class GetAllInputKeys {
private static final String BASE_URL = "http://127.0.0.1:8081/api/";
// one instance, reuse
private static final HttpClient httpClient = HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_2)
.build();
public static void main(String[] args) throws Exception {
String file = args[0];
System.err.println("Getting all input keys from txs in file " + file);
int count = 0;
int i = 0;
Set<String> inputKeys = new HashSet<>();
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
for (String tx; (tx = br.readLine()) != null; ) {
parseTx(tx, inputKeys);
i++;
if (i % 1000 == 0) {
System.err.println("Processed " + i + " transactions.");
}
}
}
System.err.println("Total number of input keys from txs in file " + file + ": " + inputKeys.size());
for (String key : inputKeys) {
System.out.println(key);
}
System.err.println("Total number of input keys from txs in file " + file + ": " + inputKeys.size());
}
private static void parseTx(String tx, Set<String> inputKeys) throws Exception {
String url = BASE_URL + "transaction/" + tx;
HttpRequest request = HttpRequest.newBuilder()
.GET()
.uri(URI.create(url))
.build();
String data = httpClient.send(request, HttpResponse.BodyHandlers.ofString()).body();
int inputStart = data.indexOf("inputs\":[{");
int inputEnd = data.indexOf("}]}]", inputStart);
String inputs = data.substring(inputStart, inputEnd);
int currIdx = 0;
while (true) {
currIdx = inputs.indexOf("public_key", currIdx);
if (currIdx == -1) {
break;
}
inputKeys.add(inputs.substring(currIdx + 13, currIdx + 77));
currIdx += 77;
}
}
}