Skip to content

Commit

Permalink
Fix shellcheck.
Browse files Browse the repository at this point in the history
  • Loading branch information
rkachowski authored and karlb committed Sep 10, 2024
1 parent 6a1b651 commit 92e876e
Showing 1 changed file with 32 additions and 29 deletions.
61 changes: 32 additions & 29 deletions packages/contracts-bedrock/scripts/contract_map.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -99,16 +99,19 @@ 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\"];")
}

# 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))
Expand All @@ -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

0 comments on commit 92e876e

Please sign in to comment.