cardano-docker/scripts/generate_registration_certificates
2021-02-13 10:19:38 -05:00

167 lines
5.6 KiB
Bash

#!/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_waller 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
if [ "${PUBLIC_RELAY_IP}" == "TOPOLOGY" ]; then
PUBLIC_RELAY_IP=$(jq -r ".Producers[0].addr" ${NODE_PATH}/topology.json)
PUBLIC_RELAY_PORT=$(jq -r ".Producers[0].port" ${NODE_PATH}/topology.json)
fi
if [ "${PUBLIC_RELAY_IP}" == "PUBLIC" ]; then
PUBLIC_RELAY_IP=$(get_public_ip)
fi
if [ -z "$PUBLIC_RELAY_PORT" ]; then
PUBLIC_RELAY_PORT=$(jq -r ".Producers[0].port" ${NODE_PATH}/topology.json)
fi
echo "Generating pool.cert"
stakepool_info
echo "Public Relay IP: ${PUBLIC_RELAY_IP}"
echo "Public Relay Port: ${PUBLIC_RELAY_PORT}"
# 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-relay-port ${PUBLIC_RELAY_PORT} \
--pool-relay-ipv4 ${PUBLIC_RELAY_IP} \
--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