diff --git a/scripts/action-create-info.sh b/scripts/action-create-info.sh index 5e8dc93..987a231 100755 --- a/scripts/action-create-info.sh +++ b/scripts/action-create-info.sh @@ -216,7 +216,11 @@ is_stake_address_script() { is_stake_address_registered(){ local address="$1" + echo -e "Checking if stake address $address is registered on-chain..." + which cardano-cli + cardano-cli conway query stake-address-info --address "$address" stake_address_deposit=$(cardano-cli conway query stake-address-info --address "$address" | jq -r '.[0].delegationDeposit') + if [ "$stake_address_deposit" != "null" ]; then return 0 else diff --git a/scripts/metadata-create.sh b/scripts/metadata-create.sh index 62d93ee..0495dc8 100755 --- a/scripts/metadata-create.sh +++ b/scripts/metadata-create.sh @@ -33,7 +33,7 @@ usage() { echo "Usage: $0 <.md-file> --governance-action-type --deposit-return-addr " echo "Options:" echo " <.md-file> Path to the .md file as input" - echo " --governance-action-type Type of governance action (info, treasury, protocol param update, etc.)" + echo " --governance-action-type Type of governance action (info, treasury, protocol param update, etc.)" echo " --deposit-return-addr Stake address for deposit return (bech32)" echo " -h, --help Show this help message and exit" exit 1 @@ -157,8 +157,8 @@ get_section() { get_section_last() { local label="$1" - awk "/^${label}\$/,/^### References\$/" "$TEMP_MD" | sed "1d" \ - | jq -Rs . + awk "/^${label}\$/ {found=1; next} /^## References$/ {found=0} found" "$TEMP_MD" | jq -Rs . + } # Extract references from References section @@ -323,6 +323,172 @@ generate_treasury_onchain() { EOF } +collect_remove_committee_credentials() { + echo " " >&2 + echo -e "${YELLOW}Collecting credentials to REMOVE from committee...${NC}" >&2 + + echo -n "How many credentials do you want to remove? (0 if none): " >&2 + IFS= read -r remove_count &2 + exit 1 + fi + + local remove_credentials="[]" + + if [ "$remove_count" -gt 0 ]; then + local creds="[" + for ((i=1; i<=remove_count; i++)); do + echo " " >&2 + echo -e "${CYAN}Credential $i to remove:${NC}" >&2 + + # Ask for credential type + echo -n " Type (script/key): " >&2 + IFS= read -r cred_type &2 + exit 1 + fi + + # Ask for credential hash + echo -n " Hash: " >&2 + IFS= read -r cred_hash &2 + exit 1 + fi + + # Add to credentials array + if [ $i -gt 1 ]; then + creds+="," + fi + creds+="{\"type\":\"$cred_type\",\"hash\":\"$cred_hash\"}" + done + creds+="]" + remove_credentials="$creds" + fi + + echo "$remove_credentials" +} + +collect_add_committee_credentials() { + echo " " >&2 + echo -e "${YELLOW}Collecting credentials to ADD to committee...${NC}" >&2 + + echo -n "How many credentials do you want to add? (0 if none): " >&2 + IFS= read -r add_count &2 + exit 1 + fi + + local add_credentials="[]" + + if [ "$add_count" -gt 0 ]; then + local creds="[" + for ((i=1; i<=add_count; i++)); do + echo " " >&2 + echo -e "${CYAN}Credential $i to add:${NC}" >&2 + + # Ask for credential type + echo -n " Type (script/key): " >&2 + IFS= read -r cred_type &2 + exit 1 + fi + + # Ask for credential hash + echo -n " Hash: " >&2 + IFS= read -r cred_hash &2 + exit 1 + fi + + # Ask for epoch expiry + echo -n " Epoch expiry: " >&2 + IFS= read -r epoch_expiry &2 + exit 1 + fi + + # Add to credentials array + if [ $i -gt 1 ]; then + creds+="," + fi + creds+="{\"type\":\"$cred_type\",\"hash\":\"$cred_hash\",\"epochExpiry\":$epoch_expiry}" + done + creds+="]" + add_credentials="$creds" + fi + + echo "$add_credentials" +} + +generate_update_committee_onchain() { + # Collect credentials to remove and add + local remove_creds=$(collect_remove_committee_credentials) + local add_creds=$(collect_add_committee_credentials) + + # Display summary + echo " " >&2 + echo -e "${GREEN}Committee changes summary:${NC}" >&2 + echo -e " Credentials to remove: $remove_creds" >&2 + echo -e " Credentials to add: $add_creds" >&2 + + # Confirm with user + echo -n "Is this correct? (y/n): " >&2 + IFS= read -r confirm &2 + exit 1 + fi + + # Build committeeChanges object dynamically, excluding empty arrays + local committee_changes="{" + + # Check if add_creds is not empty + if [ "$add_creds" != "[]" ]; then + committee_changes+="\"addCommitteeCredentials\": $add_creds" + fi + + # Check if remove_creds is not empty + if [ "$remove_creds" != "[]" ]; then + # Add comma if add_creds was added + if [ "$add_creds" != "[]" ]; then + committee_changes+="," + fi + committee_changes+="\"removeCommitteeCredentials\": $remove_creds" + fi + + committee_changes+="}" + + # Generate JSON output + cat <