Skip to content

Commit da392fa

Browse files
Ryun1elenabardho
authored andcommitted
init cip169
1 parent 3f5087b commit da392fa

1 file changed

Lines changed: 163 additions & 19 deletions

File tree

scripts/metadata-create.sh

Lines changed: 163 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ if ! command -v pandoc >/dev/null 2>&1; then
3030
exit 1
3131
fi
3232

33+
# Check if cardano-cli is installed (needed for deposit querying)
34+
if ! command -v cardano-cli >/dev/null 2>&1; then
35+
echo -e "${YELLOW}Warning: cardano-cli is not installed. Deposit amount will need to be provided manually.${NC}" >&2
36+
fi
37+
3338
# Usage message
3439
usage() {
3540
local col=50
@@ -118,7 +123,7 @@ fi
118123
echo -e " "
119124
echo -e "${YELLOW}Creating a governance action metadata file from a markdown file${NC}"
120125
echo -e "${CYAN}This script assumes a basic structure for the markdown file, using H2 headers${NC}"
121-
echo -e "${CYAN}This script uses Intersect's governance action schemas (extended CIP108)${NC}"
126+
echo -e "${CYAN}This script uses CIP169 governance metadata extension with CIP-116 ProposalProcedure format${NC}"
122127

123128
# Generate output filename: same directory and name as input, but with .jsonld extension
124129
input_dir=$(dirname "$input_file")
@@ -165,6 +170,98 @@ get_section_last() {
165170

166171
}
167172

173+
# Query governance action deposit from chain (required for CIP-116 ProposalProcedure format)
174+
# Returns the deposit amount in lovelace, or "null" if query fails
175+
query_governance_deposit() {
176+
# Check if cardano-cli is available
177+
if ! command -v cardano-cli >/dev/null 2>&1; then
178+
echo -e "${YELLOW}Warning: cardano-cli not found. Cannot query deposit from chain.${NC}" >&2
179+
echo "null"
180+
return 1
181+
fi
182+
183+
# Check if node socket path is set
184+
if [ -z "${CARDANO_NODE_SOCKET_PATH:-}" ]; then
185+
echo -e "${YELLOW}Warning: CARDANO_NODE_SOCKET_PATH not set. Cannot query deposit from chain.${NC}" >&2
186+
echo "null"
187+
return 1
188+
fi
189+
190+
# Check if network id is set
191+
if [ -z "${CARDANO_NODE_NETWORK_ID:-}" ]; then
192+
echo -e "${YELLOW}Warning: CARDANO_NODE_NETWORK_ID not set. Cannot query deposit from chain.${NC}" >&2
193+
echo "null"
194+
return 1
195+
fi
196+
197+
# Determine network flag
198+
local network_flag=""
199+
if [ "$CARDANO_NODE_NETWORK_ID" = "764824073" ] || [ "$CARDANO_NODE_NETWORK_ID" = "mainnet" ]; then
200+
network_flag="--mainnet"
201+
else
202+
network_flag="--testnet-magic $CARDANO_NODE_NETWORK_ID"
203+
fi
204+
205+
# Query deposit amount
206+
local deposit
207+
deposit=$(cardano-cli conway query gov-state $network_flag 2>/dev/null | jq -r '.currentPParams.govActionDeposit // empty' 2>/dev/null)
208+
209+
if [ -z "$deposit" ] || [ "$deposit" = "null" ] || [ "$deposit" = "" ]; then
210+
echo -e "${YELLOW}Warning: Could not query deposit from chain.${NC}" >&2
211+
echo "null"
212+
return 1
213+
fi
214+
215+
echo "$deposit"
216+
return 0
217+
}
218+
219+
# Query governance action deposit from chain (required for CIP-116 ProposalProcedure format)
220+
# Returns the deposit amount in lovelace, or "null" if query fails
221+
query_governance_deposit() {
222+
# Check if cardano-cli is available
223+
if ! command -v cardano-cli >/dev/null 2>&1; then
224+
echo -e "${YELLOW}Warning: cardano-cli not found. Cannot query deposit from chain.${NC}" >&2
225+
echo "null"
226+
return 1
227+
fi
228+
229+
# Check if node socket path is set
230+
if [ -z "${CARDANO_NODE_SOCKET_PATH:-}" ]; then
231+
echo -e "${YELLOW}Warning: CARDANO_NODE_SOCKET_PATH not set. Cannot query deposit from chain.${NC}" >&2
232+
echo "null"
233+
return 1
234+
fi
235+
236+
# Check if network id is set
237+
if [ -z "${CARDANO_NODE_NETWORK_ID:-}" ]; then
238+
echo -e "${YELLOW}Warning: CARDANO_NODE_NETWORK_ID not set. Cannot query deposit from chain.${NC}" >&2
239+
echo "null"
240+
return 1
241+
fi
242+
243+
# Determine network flag
244+
local network_flag=""
245+
if [ "$CARDANO_NODE_NETWORK_ID" = "764824073" ] || [ "$CARDANO_NODE_NETWORK_ID" = "mainnet" ]; then
246+
network_flag="--mainnet"
247+
else
248+
network_flag="--testnet-magic $CARDANO_NODE_NETWORK_ID"
249+
fi
250+
251+
# Query deposit amount
252+
local deposit
253+
deposit=$(cardano-cli conway query gov-state $network_flag 2>/dev/null | jq -r '.currentPParams.govActionDeposit // empty' 2>/dev/null)
254+
255+
if [ -z "$deposit" ] || [ "$deposit" = "null" ] || [ "$deposit" = "" ]; then
256+
echo -e "${YELLOW}Warning: Could not query deposit from chain.${NC}" >&2
257+
echo "null"
258+
return 1
259+
fi
260+
261+
echo "$deposit"
262+
return 0
263+
}
264+
168265
# Extract references from References section
169266
extract_references() {
170267
awk '
@@ -213,25 +310,55 @@ extract_references() {
213310
' "$TEMP_MD"
214311
}
215312

216-
# Generate onChain property for info governance action
313+
# Generate onChain property for info governance action (CIP-116 ProposalProcedure format)
217314
generate_info_onchain() {
315+
local deposit_amount
316+
deposit_amount=$(query_governance_deposit)
317+
318+
# If deposit query failed, use null (JSON null, not string)
319+
local deposit_json
320+
if [ "$deposit_amount" = "null" ] || [ -z "$deposit_amount" ]; then
321+
deposit_json="null"
322+
else
323+
deposit_json="$deposit_amount"
324+
fi
325+
218326
cat <<EOF
219327
{
220-
"governanceActionType": "info",
221-
"depositReturnAddress": "$deposit_return_address"
328+
"@type": "ProposalProcedure",
329+
"deposit": $deposit_json,
330+
"reward_account": "$deposit_return_address",
331+
"gov_action": {
332+
"tag": "info_action"
333+
}
222334
}
223335
EOF
224336
}
225337

226-
# Generate onChain property for ppu governance action
338+
# Generate onChain property for ppu governance action (CIP-116 ProposalProcedure format)
227339
generate_ppu_onchain() {
340+
local deposit_amount
341+
deposit_amount=$(query_governance_deposit)
342+
343+
# If deposit query failed, use null (JSON null, not string)
344+
local deposit_json
345+
if [ "$deposit_amount" = "null" ] || [ -z "$deposit_amount" ]; then
346+
deposit_json="null"
347+
else
348+
deposit_json="$deposit_amount"
349+
fi
228350

229-
# todo, improve this
230-
351+
# Note: protocol_param_update field is required for parameter_change_action
352+
# This is a placeholder - full implementation would require protocol parameter update details
231353
cat <<EOF
232354
{
233-
"governanceActionType": "protocolParameterChanges",
234-
"depositReturnAddress": "$deposit_return_address"
355+
"@type": "ProposalProcedure",
356+
"deposit": $deposit_json,
357+
"reward_account": "$deposit_return_address",
358+
"gov_action": {
359+
"tag": "parameter_change_action",
360+
"protocol_param_update": {}
361+
}
235362
}
236363
EOF
237364
}
@@ -312,17 +439,33 @@ generate_treasury_onchain() {
312439
# Collect inputs and log to stderr
313440
treasury_collect_inputs
314441

315-
# Emit ONLY JSON to stdout
442+
local deposit_amount
443+
deposit_amount=$(query_governance_deposit)
444+
445+
# If deposit query failed, use null (JSON null, not string)
446+
local deposit_json
447+
if [ "$deposit_amount" = "null" ] || [ -z "$deposit_amount" ]; then
448+
deposit_json="null"
449+
else
450+
deposit_json="$deposit_amount"
451+
fi
452+
453+
# Emit ONLY JSON to stdout (CIP-116 ProposalProcedure format)
454+
# Convert withdrawals to rewards array with key-value pairs
316455
cat <<EOF
317456
{
318-
"governanceActionType": "treasuryWithdrawals",
319-
"depositReturnAddress": "$deposit_return_address",
320-
"withdrawals": [
321-
{
322-
"withdrawalAddress": "$T_WITHDRAWAL_ADDRESS",
323-
"withdrawalAmount": $T_LOVELACE
324-
}
325-
]
457+
"@type": "ProposalProcedure",
458+
"deposit": $deposit_json,
459+
"reward_account": "$deposit_return_address",
460+
"gov_action": {
461+
"tag": "treasury_withdrawals_action",
462+
"rewards": [
463+
{
464+
"key": "$T_WITHDRAWAL_ADDRESS",
465+
"value": $T_LOVELACE
466+
}
467+
]
468+
}
326469
}
327470
EOF
328471
}
@@ -369,14 +512,15 @@ ONCHAIN_PROPERTY=$(generate_onchain_property "$governance_action_type")
369512
# Generate references JSON
370513
REFERENCES_JSON=$(extract_references)
371514

372-
# Replace the cat <<EOF section (around line 249) with:
515+
# Download context (CIP169 onChain property uses CIP-116 format, which is standard JSON)
373516
echo -e " "
374517
echo -e "${CYAN}Downloading context from $METADATA_COMMON_URL...${NC}"
375518
if ! curl -sSfL "$METADATA_COMMON_URL" -o "$TEMP_CONTEXT"; then
376519
echo -e "${RED}Error: Failed to download context from $METADATA_COMMON_URL${NC}" >&2
377520
exit 1
378521
fi
379522

523+
# Build the metadata JSON-LD with CIP-116 ProposalProcedure format onChain property
380524
jq --argjson context "$(cat "$TEMP_CONTEXT")" \
381525
--argjson title "$TITLE" \
382526
--argjson abstract "$ABSTRACT" \

0 commit comments

Comments
 (0)