Skip to content

Commit 3e1e261

Browse files
committed
feature: Add a shell script to fetch params
1 parent 0df46dd commit 3e1e261

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

fetch-params.sh

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/usr/bin/env bash
2+
set -eo pipefail
3+
4+
usage () {
5+
cat << EOF
6+
Usage: fetch-params.sh [options] environment
7+
8+
environments:
9+
mainnet
10+
preprod
11+
preview
12+
all
13+
14+
Options:
15+
-p, --project-id string Blockfrost API key (overrides BLOCKFROST_PROJECT_ID environment variable)
16+
-h, --help Show this help text
17+
}
18+
EOF
19+
}
20+
21+
# Parse command line arguments
22+
if ! OPTS=$(getopt -o p:h --long project-id:,help -n "fetch-cardano-cfg.sh" -- "$@"); then
23+
exit 1
24+
fi
25+
26+
eval set -- "${OPTS}"
27+
28+
while true; do
29+
case "$1" in
30+
-p | --project-id)
31+
PROJECT_ID=$2
32+
shift 2
33+
;;
34+
-h | --help)
35+
HELP=
36+
shift
37+
;;
38+
--)
39+
shift
40+
break
41+
;;
42+
*)
43+
echo "Internal error!" >&2
44+
exit 1
45+
;;
46+
esac
47+
done
48+
49+
# Validate command line arguments
50+
if [[ "${HELP+DEFINED}" = true ]]; then
51+
usage
52+
exit 1
53+
fi
54+
55+
if [[ "$#" -eq 0 || -z "$1" ]]; then
56+
echo "Missing required argument environment!" >&2
57+
exit 1
58+
else
59+
ENV=$1
60+
fi
61+
62+
if [[ -z "${PROJECT_ID}" && -n "${BLOCKFROST_PROJECT_ID}" ]]; then
63+
PROJECT_ID="${BLOCKFROST_PROJECT_ID}"
64+
fi
65+
66+
if [[ -z "${PROJECT_ID}" ]]; then
67+
cat << EOF >&2
68+
Missing Blockfrost API key! \
69+
Use the BLOCKCHAID_PROJECT_ID environment variable or --project-id option to specify it.
70+
EOF
71+
72+
exit 2
73+
fi
74+
75+
# Calculate endpoint
76+
case "${ENV}" in
77+
mainnet)
78+
BLOCKFROST_HOST=cardano-mainnet.blockfrost.io
79+
;;
80+
preprod)
81+
BLOCKFROST_HOST=cardano-preprod.blockfrost.io
82+
;;
83+
preview)
84+
BLOCKFROST_HOST=cardano-preview.blockfrost.io
85+
;;
86+
*)
87+
echo "Invalid environment: '${ENV}'" >&2
88+
esac
89+
90+
tmpfile=$(mktemp --tmpdir "parameters.XXXXXX")
91+
92+
# Do the request
93+
curl \
94+
-H "project_id: ${PROJECT_ID}" \
95+
--no-progress-meter \
96+
--fail \
97+
"https://${BLOCKFROST_HOST}/api/v0/epochs/latest/parameters" \
98+
| jq --sort-keys . \
99+
> "${tmpfile}"
100+
101+
mkdir -p "${ENV}"
102+
mv "${tmpfile}" "${ENV}/parameters.json"

0 commit comments

Comments
 (0)