-
Notifications
You must be signed in to change notification settings - Fork 1
/
CountTxs2.java
executable file
·50 lines (40 loc) · 1.58 KB
/
CountTxs2.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
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
// javac -cp .:commons-lang3-3.10/* CountTxs2.java
// java -cp .:commons-lang3-3.10/* CountTxs2 1220517 2077095
public class CountTxs2 {
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 {
int start = Integer.parseInt(args[0]);
int end = Integer.parseInt(args[1]);
System.err.println("Count total number of txs in blocks in range [" + start + ", " + end + ")");
int count = 0;
for (int i = start; i < end; i++) {
if (i % 100 == 0) {
System.err.println("Processing block " + i);
}
count += parseBlock(i);
}
System.out.println("Total number of non-coinbase txs in blocks in [" + start + ", " + end + "): "
+ count);
}
private static int parseBlock(int block) throws Exception {
String url = BASE_URL + "block/" + block;
HttpRequest request = HttpRequest.newBuilder()
.GET()
.uri(URI.create(url))
.build();
String data = httpClient.send(request, HttpResponse.BodyHandlers.ofString()).body();
// ignore coinbase txn
return StringUtils.countMatches(data, "coinbase") - 1;
}
}