-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckpoints.sh
More file actions
executable file
·66 lines (48 loc) · 1.79 KB
/
Copy pathcheckpoints.sh
File metadata and controls
executable file
·66 lines (48 loc) · 1.79 KB
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
#!/usr/bin/env bash
OUTPUT="CryptoNoteCheckpoints.h"
# Set your DeroGold API base URL here (e.g. your own node or a public explorer)
API_BASE="https://your-api-node-here"
LATEST=$(curl -s "$API_BASE/height" | jq '.height')
if [ -f "$OUTPUT" ]; then
LAST_HEIGHT=$(grep -oE '\{[0-9]+,' "$OUTPUT" | tail -1 | grep -oE '[0-9]+')
START_FROM=$((LAST_HEIGHT + 5000))
if [ "$START_FROM" -gt "$LATEST" ]; then
echo "Already up to date. Last checkpoint: $LAST_HEIGHT, network tip: $LATEST"
exit 0
fi
echo "Existing file found. Last checkpoint: $LAST_HEIGHT. Fetching $START_FROM to $LATEST..."
# Strip the closing lines before appending
head -n -2 "$OUTPUT" > "${OUTPUT}.tmp" && mv "${OUTPUT}.tmp" "$OUTPUT"
CHUNK_START=$(( (START_FROM / 1000) * 1000 ))
for start in $(seq $CHUNK_START 1000 $LATEST); do
curl -s "$API_BASE/block/headers/$((start + 999))/bulk" | \
jq -r --argjson from "$START_FROM" \
'[.[] | select(.height % 5000 == 0 and .height >= $from)] | sort_by(.height)[] | " {\(.height), \"\(.hash)\"},"' >> "$OUTPUT"
done
else
echo "No existing file. Generating from scratch..."
cat > "$OUTPUT" << 'HEADER'
// Copyright (c) 2018-2026, The DeroGold Developers
// Copyright (c) 2012-2017, The CryptoNote developers, The Bytecoin developers
//
#pragma once
#include <cstdint>
namespace CryptoNote
{
struct CheckpointData
{
uint32_t index;
const char *blockId;
};
const CheckpointData CHECKPOINTS[] = {
HEADER
for start in $(seq 0 1000 $LATEST); do
curl -s "$API_BASE/block/headers/$((start + 999))/bulk" | \
jq -r '[.[] | select(.height % 5000 == 0)] | sort_by(.height)[] | " {\(.height), \"\(.hash)\"},"' >> "$OUTPUT"
done
fi
cat >> "$OUTPUT" << 'EOF'
};
} // namespace CryptoNote
EOF
echo "Done: $OUTPUT"