diff --git a/scripts/metadata-create.sh b/scripts/metadata-create.sh index 62d93ee..fa425e8 100755 --- a/scripts/metadata-create.sh +++ b/scripts/metadata-create.sh @@ -27,15 +27,23 @@ if ! command -v pandoc >/dev/null 2>&1; then exit 1 fi +# Check if cardano-cli is installed (needed for deposit querying) +if ! command -v cardano-cli >/dev/null 2>&1; then + echo -e "${YELLOW}Warning: cardano-cli is not installed. Deposit amount will need to be provided manually.${NC}" >&2 +fi + # Usage message usage() { echo " " - echo "Usage: $0 <.md-file> --governance-action-type --deposit-return-addr " + 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)" echo " --deposit-return-addr Stake address for deposit return (bech32)" echo " -h, --help Show this help message and exit" + echo " " + echo "Note: This script generates CIP169-compliant metadata with CIP-116 ProposalProcedure onChain format." + echo " The deposit amount will be queried from chain if cardano-cli and node connection are available." exit 1 } @@ -114,7 +122,7 @@ fi echo -e " " echo -e "${YELLOW}Creating a governance action metadata file from a markdown file${NC}" echo -e "${CYAN}This script assumes a basic structure for the markdown file, using H2 headers${NC}" -echo -e "${CYAN}This script uses Intersect's governance action schemas (extended CIP108)${NC}" +echo -e "${CYAN}This script uses CIP169 governance metadata extension with CIP-116 ProposalProcedure format${NC}" # Generate output filename: same directory and name as input, but with .jsonld extension input_dir=$(dirname "$input_file") @@ -161,6 +169,52 @@ get_section_last() { | jq -Rs . } +# Query governance action deposit from chain (required for CIP-116 ProposalProcedure format) +# Returns the deposit amount in lovelace, or "null" if query fails +query_governance_deposit() { + # Check if cardano-cli is available + if ! command -v cardano-cli >/dev/null 2>&1; then + echo -e "${YELLOW}Warning: cardano-cli not found. Cannot query deposit from chain.${NC}" >&2 + echo "null" + return 1 + fi + + # Check if node socket path is set + if [ -z "${CARDANO_NODE_SOCKET_PATH:-}" ]; then + echo -e "${YELLOW}Warning: CARDANO_NODE_SOCKET_PATH not set. Cannot query deposit from chain.${NC}" >&2 + echo "null" + return 1 + fi + + # Check if network id is set + if [ -z "${CARDANO_NODE_NETWORK_ID:-}" ]; then + echo -e "${YELLOW}Warning: CARDANO_NODE_NETWORK_ID not set. Cannot query deposit from chain.${NC}" >&2 + echo "null" + return 1 + fi + + # Determine network flag + local network_flag="" + if [ "$CARDANO_NODE_NETWORK_ID" = "764824073" ] || [ "$CARDANO_NODE_NETWORK_ID" = "mainnet" ]; then + network_flag="--mainnet" + else + network_flag="--testnet-magic $CARDANO_NODE_NETWORK_ID" + fi + + # Query deposit amount + local deposit + deposit=$(cardano-cli conway query gov-state $network_flag 2>/dev/null | jq -r '.currentPParams.govActionDeposit // empty' 2>/dev/null) + + if [ -z "$deposit" ] || [ "$deposit" = "null" ] || [ "$deposit" = "" ]; then + echo -e "${YELLOW}Warning: Could not query deposit from chain.${NC}" >&2 + echo "null" + return 1 + fi + + echo "$deposit" + return 0 +} + # Extract references from References section extract_references() { awk ' @@ -209,25 +263,55 @@ extract_references() { ' "$TEMP_MD" } -# Generate onChain property for info governance action +# Generate onChain property for info governance action (CIP-116 ProposalProcedure format) generate_info_onchain() { + local deposit_amount + deposit_amount=$(query_governance_deposit) + + # If deposit query failed, use null (JSON null, not string) + local deposit_json + if [ "$deposit_amount" = "null" ] || [ -z "$deposit_amount" ]; then + deposit_json="null" + else + deposit_json="$deposit_amount" + fi + cat <