Skip to content

Commit b7acd26

Browse files
authored
Merge pull request #1056 from lifinance/added-checkNetworksJsonFilePath
Added checkNetworksJsonFilePath
2 parents b24cd9f + 5b63feb commit b7acd26

12 files changed

+32
-1
lines changed

script/deploy/deployFacetAndAddToDiamond.sh

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function deployFacetAndAddToDiamond() {
2121

2222
# if no NETWORK was passed to this function, ask user to select it
2323
if [[ -z "$NETWORK" ]]; then
24+
checkNetworksJsonFilePath || checkFailure $? "retrieve NETWORKS_JSON_FILE_PATH"
2425
NETWORK=$(jq -r 'keys[]' "$NETWORKS_JSON_FILE_PATH" | gum filter --placeholder "Network")
2526
checkRequiredVariablesInDotEnv $NETWORK
2627
fi

script/helperFunctions.sh

+19-1
Original file line numberDiff line numberDiff line change
@@ -1965,6 +1965,7 @@ function getAddressOfDeployedContractFromDeploymentsFiles() {
19651965

19661966
}
19671967
function getAllNetworksArray() {
1968+
checkNetworksJsonFilePath || checkFailure $? "retrieve NETWORKS_JSON_FILE_PATH"
19681969
# prepare required variables
19691970
local FILE="$NETWORKS_JSON_FILE_PATH"
19701971
local ARRAY=()
@@ -2010,9 +2011,24 @@ function getCoreFacetsArray() {
20102011
printf '%s\n' "${ARRAY[@]}"
20112012
}
20122013

2014+
# Function to check if NETWORKS_JSON_FILE_PATH is set and valid
2015+
checkNetworksJsonFilePath() {
2016+
if [[ -z "$NETWORKS_JSON_FILE_PATH" ]]; then
2017+
error "NETWORKS_JSON_FILE_PATH is not set. Please check your configuration."
2018+
return 1
2019+
elif [[ ! -f "$NETWORKS_JSON_FILE_PATH" ]]; then
2020+
error "NETWORKS_JSON_FILE_PATH does not point to a valid file: $NETWORKS_JSON_FILE_PATH"
2021+
return 1
2022+
elif [[ ! -s "$NETWORKS_JSON_FILE_PATH" ]]; then
2023+
error "NETWORKS_JSON_FILE_PATH file is empty: $NETWORKS_JSON_FILE_PATH"
2024+
return 1
2025+
fi
2026+
}
2027+
20132028

20142029
function getIncludedNetworksArray() {
20152030
# prepare required variables
2031+
checkNetworksJsonFilePath || checkFailure $? "retrieve NETWORKS_JSON_FILE_PATH"
20162032
local FILE="$NETWORKS_JSON_FILE_PATH"
20172033
local ARRAY=()
20182034

@@ -2148,6 +2164,7 @@ function userDialogSelectDiamondType() {
21482164
echo "$DIAMOND_CONTRACT_NAME"
21492165
}
21502166
function getUserSelectedNetwork() {
2167+
checkNetworksJsonFilePath || checkFailure $? "retrieve NETWORKS_JSON_FILE_PATH"
21512168
# get user-selected network
21522169
local NETWORK=$(jq -r 'keys[]' "$NETWORKS_JSON_FILE_PATH" | gum filter --placeholder "Network...")
21532170

@@ -2849,6 +2866,7 @@ function getPrivateKey() {
28492866
function getChainId() {
28502867
local NETWORK="$1"
28512868

2869+
checkNetworksJsonFilePath || checkFailure $? "retrieve NETWORKS_JSON_FILE_PATH"
28522870
if [[ ! -f "$NETWORKS_JSON_FILE_PATH" ]]; then
28532871
echo "Error: JSON file '$NETWORKS_JSON_FILE_PATH' not found." >&2
28542872
return 1
@@ -2866,7 +2884,7 @@ function getChainId() {
28662884

28672885
function getCreate3FactoryAddress() {
28682886
NETWORK="$1"
2869-
2887+
checkNetworksJsonFilePath || checkFailure $? "retrieve NETWORKS_JSON_FILE_PATH"
28702888
CREATE3_FACTORY=$(jq --arg NETWORK "$NETWORK" -r '.[$NETWORK].create3Factory // empty' "$NETWORKS_JSON_FILE_PATH")
28712889

28722890
if [ -z "$CREATE3_FACTORY" ]; then

script/scriptMaster.sh

+3
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ scriptMaster() {
117117
echo ""
118118
echo "[info] selected use case: Deploy one specific contract to one network"
119119

120+
checkNetworksJsonFilePath || checkFailure $? "retrieve NETWORKS_JSON_FILE_PATH"
120121
# get user-selected network from list
121122
local NETWORK=$(jq -r 'keys[]' "$NETWORKS_JSON_FILE_PATH" | gum filter --placeholder "Network")
122123

@@ -244,6 +245,7 @@ scriptMaster() {
244245
echo ""
245246
echo "[info] selected use case: Deploy all contracts to one selected network (=new network)"
246247

248+
checkNetworksJsonFilePath || checkFailure $? "retrieve NETWORKS_JSON_FILE_PATH"
247249
# get user-selected network from list
248250
local NETWORK=$(jq -r 'keys[]' "$NETWORKS_JSON_FILE_PATH" | gum filter --placeholder "Network")
249251
# get deployer wallet balance
@@ -499,6 +501,7 @@ scriptMaster() {
499501
# call update diamond log function
500502
updateDiamondLogs
501503
else
504+
checkNetworksJsonFilePath || checkFailure $? "retrieve NETWORKS_JSON_FILE_PATH"
502505
# get user-selected network from list
503506
local NETWORK=$(jq -r 'keys[]' "$NETWORKS_JSON_FILE_PATH" | gum filter --placeholder "Network")
504507

script/tasks/acceptOwnershipTransferPeriphery.sh

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ acceptOwnershipTransferPeriphery() {
2727
# get array of all (not-excluded) networks
2828
NETWORKS=($(getIncludedNetworksArray))
2929
else
30+
checkNetworksJsonFilePath || checkFailure $? "retrieve NETWORKS_JSON_FILE_PATH"
3031
# get user-selected network from list
3132
local NETWORK=$(jq -r 'keys[]' "$NETWORKS_JSON_FILE_PATH" | gum filter --placeholder "Network")
3233
# create array with selected network as only entry

script/tasks/checkExecutorAndReceiver.sh

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ checkExecutorAndReceiver() {
4646
# get array of all (not-excluded) networks
4747
NETWORKS=($(getIncludedNetworksArray))
4848
else
49+
checkNetworksJsonFilePath || checkFailure $? "retrieve NETWORKS_JSON_FILE_PATH"
4950
# get user-selected network from list
5051
local NETWORK=$(jq -r 'keys[]' "$NETWORKS_JSON_FILE_PATH" | gum filter --placeholder "Network")
5152
# create array with selected network as only entry

script/tasks/diamondEMERGENCYPause.sh

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function diamondEMERGENCYPause {
2121
# if no NETWORK was passed to this function, ask user to select it
2222
if [[ -z "$NETWORK" ]]; then
2323
# find out if script should be executed for one network or for all networks
24+
checkNetworksJsonFilePath || checkFailure $? "retrieve NETWORKS_JSON_FILE_PATH"
2425
echo ""
2526
echo "Should the script be executed on one network or all networks?"
2627
NETWORK=$(echo -e "All (non-excluded) Networks\n$(jq -r 'keys[]' "$NETWORKS_JSON_FILE_PATH")" | gum filter --placeholder "Network")

script/tasks/diamondSyncDEXs.sh

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ function diamondSyncDEXs {
2020

2121
# if no NETWORK was passed to this function, ask user to select it
2222
if [[ -z "$NETWORK" ]]; then
23+
checkNetworksJsonFilePath || checkFailure $? "retrieve NETWORKS_JSON_FILE_PATH"
2324
echo ""
2425
echo "Should the script be executed on one network or all networks"
2526
NETWORK=$(echo -e "All (non-excluded) Networks\n$(jq -r 'keys[]' "$NETWORKS_JSON_FILE_PATH")" | gum filter --placeholder "Network")

script/tasks/diamondSyncSigs.sh

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ function diamondSyncSigs {
1818
# if no NETWORK was passed to this function, ask user to select it
1919
if [[ -z "$NETWORK" ]]; then
2020
# find out if script should be executed for one network or for all networks
21+
checkNetworksJsonFilePath || checkFailure $? "retrieve NETWORKS_JSON_FILE_PATH"
2122
echo ""
2223
echo "Should the script be executed on one network or all networks?"
2324
NETWORK=$(echo -e "All (non-excluded) Networks\n$(jq -r 'keys[]' "$NETWORKS_JSON_FILE_PATH")" | gum filter --placeholder "Network")

script/tasks/diamondUpdatePeriphery.sh

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function diamondUpdatePeriphery() {
1919

2020
# if no NETWORK was passed to this function, ask user to select it
2121
if [[ -z "$NETWORK" ]]; then
22+
checkNetworksJsonFilePath || checkFailure $? "retrieve NETWORKS_JSON_FILE_PATH"
2223
NETWORK=$(jq -r 'keys[]' "$NETWORKS_JSON_FILE_PATH" | gum filter --placeholder "Network")
2324
checkRequiredVariablesInDotEnv $NETWORK
2425
fi

script/tasks/diamondUpdateSgConfig.sh

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ diamondUpdateSgConfig() {
2626
USE_DEF_DIAMOND=false
2727
fi
2828

29+
checkNetworksJsonFilePath || checkFailure $? "retrieve NETWORKS_JSON_FILE_PATH"
2930
# get user-selected network from list
3031
NETWORK=$(jq -r 'keys[]' "$NETWORKS_JSON_FILE_PATH" | gum filter --placeholder "Network...")
3132
# get user-selected script from list

script/tasks/updateFacetConfig.sh

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ updateFacetConfig() {
1616
# get user-selected network from list
1717
echo "Select Networks"
1818
if command -v gum >/dev/null 2>&1; then
19+
checkNetworksJsonFilePath || checkFailure $? "retrieve NETWORKS_JSON_FILE_PATH"
1920
# Read the networks into an array, works on both Mac and Linux
2021
IFS=$'\n' read -r -d '' -a NETWORKS < <(jq -r 'keys[]' "$NETWORKS_JSON_FILE_PATH" | gum choose --no-limit)
2122

script/utils/diamondEMERGENCYPauseGitHub.sh

+1
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ function main {
173173
local NETWORKS=()
174174

175175
# loop through networks.json list and add each network to ARRAY that is not excluded
176+
checkNetworksJsonFilePath || checkFailure $? "retrieve NETWORKS_JSON_FILE_PATH"
176177
while IFS= read -r network; do
177178
NETWORKS+=("$network")
178179
done < <(jq -r 'keys[]' "$NETWORKS_JSON_FILE_PATH")

0 commit comments

Comments
 (0)