-
Notifications
You must be signed in to change notification settings - Fork 62
/
generate_registration_certificates
188 lines (163 loc) · 6.21 KB
/
generate_registration_certificates
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/bin/bash
# From Documentation
# https://github.com/input-output-hk/cardano-tutorials/blob/ecbfd0ec06e0515701ee3749ce96780c27d2249d/node-setup/080_register_stakepool.md
# Init vars
source /scripts/init_node_vars
source /scripts/functions/get_public_ip
source /scripts/functions/stakepool_info
TIMESTAMP=$(date +%s)
# Enter staking directory
cd ${NODE_PATH}/staking/
echo ""
echo "Generate registration certificates"
# Check for required files
if [ ! -f "wallets/owner/stake.vkey" ]; then
echo "Missing required staking/stake.vkey. You need to run \`generate_wallet owner\` to generate this key."
MISSING_FILES=1
fi
if [ ! -f "cold-keys/cold.vkey" ]; then
echo "Missing required staking/cold-keys/cold.vkey. You need to run \`generate_operational_certificate\` to generate this key."
MISSING_FILES=1
fi
if [ ! -f "pool-keys/vrf.vkey" ]; then
echo "Missing required staking/pool-keys/vrf.vkey. You need to run \`generate_operational_certificate\` to generate this key."
MISSING_FILES=1
fi
if [ -n "$MISSING_FILES" ]; then
exit
fi
if [ -z "$METADATA_URL" ]; then
echo "Missing METADATA_URL You need to upload your metadata.json file at pass the URL to the METADATA_URL variable."
exit
fi
# Handle arguments
for i in "$@"
do
case $i in
--update)
UPDATE_CERT=1
;;
--cold-create)
COLD_CREATE=1
;;
esac
done
# 1. Create a JSON file with your pool's metadata
if [ ! -f "metadata.json" ] || [ -n "$UPDATE_CERT" ]; then
if [ -z "$COLD_CREATE" ]; then
echo "Getting metadata file from ${METADATA_URL}"
wget -O metadata.json ${METADATA_URL}
else
read -n 1 -r -s -p "Missing ${NODE_PATH}/staking/metadata.json. Please add this file, and ENTER when you have placed the file and are ready to continue."
fi
fi
# 2. get hash of file
echo "Getting hash of metadata.json"
METADATA_HASH=$(cardano-cli stake-pool metadata-hash --pool-metadata-file metadata.json)
echo "metadata.json hash: ${METADATA_HASH}"
# 3. Generate Stake pool registration certificate
if [ ! -f "pool.cert" ] || [ -n "$UPDATE_CERT" ]; then
if [ -f "pool.cert" ]; then
echo "backing up pool.cert."
cp pool.cert pool.${TIMESTAMP}.cert
fi
echo "Generating pool.cert"
stakepool_info
# Collect relay information
POOL_RELAYS=""
if [ -n "$PUBLIC_RELAY_HOSTS" ]; then
IFS=',' read -ra hosts <<< "$PUBLIC_RELAY_HOSTS"
for host_port in "${hosts[@]}"; do
IFS=':' read -ra parts <<< "$host_port"
if [ "${#parts[@]}" -eq 2 ]; then
host="${parts[0]}"
port="${parts[1]}"
POOL_RELAYS="$POOL_RELAYS --single-host-pool-relay $host --pool-relay-port $port"
echo "POOL RELAY: ${host}:${port}"
else
echo "Invalid format in PUBLIC_RELAY_HOSTS: $host_port."
exit
fi
done
else
if [ "${PUBLIC_RELAY_IP}" == "TOPOLOGY" ]; then
relay_ip=$(jq -r ".Producers[0].addr" ${NODE_PATH}/topology.json)
port=$(jq -r ".Producers[0].port" ${NODE_PATH}/topology.json)
fi
if [ "${PUBLIC_RELAY_IP}" == "PUBLIC" ]; then
relay_ip=$(get_public_ip)
fi
if [ -z "$PUBLIC_RELAY_PORT" ]; then
relay_port=$(jq -r ".Producers[0].port" ${NODE_PATH}/topology.json)
fi
POOL_RELAYS="--pool-relay-ipv4 ${relay_ip} --pool-relay-port ${relay_port}"
echo "POOL RELAY: ${relay_ip}:${relay_port}"
fi
# Multiple owners
if [ -n "$MULTI_OWNERS" ]; then
echo "Multiple owners"
for i in $(echo ${MULTI_OWNERS} | sed "s/,/ /g")
do
echo "$i"
MULTIOWNERS_STRING="${MULTIOWNERS_STRING} --pool-owner-stake-verification-key-file wallets/${i}/stake.vkey"
done
echo $MULTIOWNERS_STRING
echo ""
fi
cardano-cli stake-pool registration-certificate \
--cold-verification-key-file cold-keys/cold.vkey \
--vrf-verification-key-file pool-keys/vrf.vkey \
--pool-pledge ${POOL_PLEDGE} \
--pool-cost ${POOL_COST} \
--pool-margin ${POOL_MARGIN} \
--pool-reward-account-verification-key-file wallets/owner/stake.vkey \
--pool-owner-stake-verification-key-file wallets/owner/stake.vkey \
${MULTIOWNERS_STRING} \
${POOL_RELAYS##*( )} \
--metadata-url ${METADATA_URL} \
--metadata-hash ${METADATA_HASH} \
${NETWORK_ARGUMENT} \
--out-file pool.cert \
&& echo "Generated pool.cert"
PAYMENT_ADDR=$(cat ${NODE_PATH}/staking/wallets/owner/payment.addr)
STAKE_ADDR=$(cat ${NODE_PATH}/staking/wallets/owner/stake.addr)
POOL_ID=$(cat ${NODE_PATH}/staking/POOL_ID)
echo "export POOL_PLEDGE=${POOL_PLEDGE}" > POOL_VARS
echo "export POOL_COST=${POOL_COST}" >> POOL_VARS
echo "export POOL_MARGIN=${POOL_MARGIN}" >> POOL_VARS
echo "export POOL_MARGIN=${POOL_MARGIN}" >> POOL_VARS
echo "export PAYMENT_ADDR=${PAYMENT_ADDR}" >> POOL_VARS
echo "export STAKE_ADDR=${STAKE_ADDR}" >> POOL_VARS
echo "export POOL_ID=${POOL_ID}" >> POOL_VARS
echo "export MULTI_OWNERS=${MULTI_OWNERS}" >> POOL_VARS
echo ""
else
echo "pool.cert already exists."
fi
# 2. Generate delegation certificate (pledge)
if [ ! -f "wallets/owner/delegation.cert" ]; then
cardano-cli stake-address delegation-certificate \
--stake-verification-key-file wallets/owner/stake.vkey \
--cold-verification-key-file cold-keys/cold.vkey \
--out-file wallets/owner/delegation.cert \
&& echo "Generated delegation.cert"
else
echo "delegation.cert already exists."
fi
# Multiple owners
if [ -n "$MULTI_OWNERS" ]; then
echo "Generating delegation certificates for multiple owners"
for i in $(echo ${MULTI_OWNERS} | sed "s/,/ /g")
do
echo "- $i"
if [ ! -f "wallets/$i/delegation.cert" ]; then
cardano-cli stake-address delegation-certificate \
--stake-verification-key-file wallets/$i/stake.vkey \
--cold-verification-key-file cold-keys/cold.vkey \
--out-file wallets/$i/delegation.cert \
&& echo "-- generated delegation.cert"
else
echo "-- delegation.cert already exists."
fi
done
fi