diff --git a/packages/contracts-bedrock/scripts/contract_map.sh b/packages/contracts-bedrock/scripts/contract_map.sh index 1dc9716df31d2..caa8a716a13ba 100755 --- a/packages/contracts-bedrock/scripts/contract_map.sh +++ b/packages/contracts-bedrock/scripts/contract_map.sh @@ -27,12 +27,12 @@ address_exists() { check_admin() { local addr="$1" - admin=$(cast adm "$addr" --rpc-url $L1_URL) + admin=$(cast adm "$addr" --rpc-url "$L1_URL") if [[ $? == 0 && "$admin" != "0x0000000000000000000000000000000000000000" ]]; then - contract_addresses+=( $admin ) + contract_addresses+=( "$admin" ) echo " -> Admin: $admin" - add_relation $admin $addr "admin" + add_relation "$admin" "$addr" "admin" fi return 0 @@ -43,27 +43,24 @@ check_owners() { # suppressing stderr (and unset -e) as failure is expected when this abi does not exist # getOwners defined in OwnerManager on GnosisSafe contract - owners=$(cast call "$addr" --rpc-url $L1_URL 'getOwners()(address[])' 2>/dev/null) - - if [[ $? == 0 ]]; then + if owners=$(cast call "$addr" --rpc-url "$L1_URL" 'getOwners()(address[])' 2>/dev/null) ; then # trim pseudo json output - tr=$(echo $owners | tr -d '[],') - owners_arr=($tr) + tr=$(echo "$owners" | tr -d '[],') + owners_arr=( "$tr" ) # Iterate over the values for owner in "${owners_arr[@]}"; do echo " -> Multisig Owner: $owner" - add_relation $owner $addr "multisig_owner" - contract_addresses+=( $owner ) + add_relation "$owner" "$addr" "multisig_owner" + contract_addresses+=( "$owner" ) done fi # owner defined in Ownable on OpenZeppelin abstract contract - owner=$(cast call "$addr" --rpc-url $L1_URL 'owner()(address)' 2>/dev/null) - if [[ $? == 0 ]]; then + if owner=$(cast call "$addr" --rpc-url "$L1_URL" 'owner()(address)' 2>/dev/null) ; then echo " -> Owner: $owner" - add_relation $owner $addr "owner" - contract_addresses+=( $owner ) + add_relation "$owner" "$addr" "owner" + contract_addresses+=( "$owner" ) fi return 0 @@ -72,23 +69,26 @@ check_owners() { check_implementation() { local addr="$1" - impl=$(cast implementation "$addr" --rpc-url $L1_URL) + impl=$(cast implementation "$addr" --rpc-url "$L1_URL") if [[ $? == 0 && "$impl" != "0x0000000000000000000000000000000000000000" ]]; then - contract_addresses+=( $impl ) + contract_addresses+=( "$impl" ) echo " -> Impl: $impl" - add_relation $addr $impl "proxies" + add_relation "$addr" "$impl" "proxies" fi return 0 } get_name() { - local addr=$(cast to-check-sum-address "$1") - local result=$(jq -r "to_entries | map(select(.value == \"$addr\")) | .[0].key" "$L1_ADDRESSES") + local addr + local result + + addr=$(cast to-check-sum-address "$1") + result=$(jq -r "to_entries | map(select(.value == \"$addr\")) | .[0].key" "$L1_ADDRESSES") if [[ ${#result} -gt 4 ]]; then - echo "$addr\n($result)" + printf "%s\n(%s)" "$addr" "$result" else echo "$addr" fi @@ -99,8 +99,11 @@ add_relation() { local destination="$2" local label="$3" - local source_name=$(get_name "$source") - local destination_name=$(get_name "$destination") + local source_name + local destination_name + + source_name=$(get_name "$source") + destination_name=$(get_name "$destination") dots+=("\"$source_name\" -> \"$destination_name\"[label = \"$label\"];") } @@ -108,7 +111,7 @@ add_relation() { # while loop to allow for modification of the array during iteration i=0 while [ $i -lt ${#contract_addresses[@]} ]; do - address="$(cast to-check-sum-address ${contract_addresses[$i]})" + address="$(cast to-check-sum-address "${contract_addresses[$i]}")" if address_exists "$address"; then # already processed this address, skip iteration i=$((i + 1)) @@ -126,12 +129,12 @@ while [ $i -lt ${#contract_addresses[@]} ]; do done # write out chart -echo "digraph {" > $OUTPUT.dot -echo "rankdir="LR";" >> $OUTPUT.dot +echo "digraph {" > "$OUTPUT".dot +echo "rankdir=\"LR\";" >> "$OUTPUT".dot for dot in "${dots[@]}"; do - echo "$dot" >> $OUTPUT.dot + echo "$dot" >> "$OUTPUT".dot done -echo "}" >> $OUTPUT.dot +echo "}" >> "$OUTPUT".dot -dot $OUTPUT.dot -Tpng -o $OUTPUT.png -open $OUTPUT.png +dot "$OUTPUT".dot -Tpng -o "$OUTPUT".png +open "$OUTPUT".png