Skip to content

Commit 03d62a2

Browse files
committed
add governance demo: propose, vote, tally, verify in one script
1 parent c74bffe commit 03d62a2

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

examples/governance_demo.sh

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Governance attestation demo.
5+
# Shows the full cycle: propose -> vote -> tally -> verify.
6+
# Runs against the live API. Takes an API key as argument.
7+
8+
API="https://pay.frontiercompute.io"
9+
KEY="${1:?Usage: $0 <api_key>}"
10+
GREEN='\033[0;32m'
11+
GOLD='\033[0;33m'
12+
DIM='\033[0;90m'
13+
RST='\033[0m'
14+
15+
echo -e "${GOLD}ZAP1 Governance Demo${RST}"
16+
echo -e "${DIM}Propose, vote, tally - all attested on Zcash mainnet.${RST}"
17+
echo ""
18+
19+
# 1. Create proposal
20+
PROPOSAL_ID="demo-proposal-$(date +%s)"
21+
PROPOSAL_HASH=$(echo -n "Should ZAP1 adopt ZIP 302 as the memo container?" | sha256sum | cut -d' ' -f1)
22+
23+
echo -e "${GREEN}1. Creating proposal${RST}"
24+
echo " ID: $PROPOSAL_ID"
25+
echo " Hash: ${PROPOSAL_HASH:0:32}..."
26+
27+
RESULT=$(curl -sf -X POST "$API/event" \
28+
-H "Authorization: Bearer $KEY" \
29+
-H "Content-Type: application/json" \
30+
-d "{\"event_type\":\"GOVERNANCE_PROPOSAL\",\"wallet_hash\":\"dao_operator\",\"proposal_id\":\"$PROPOSAL_ID\",\"proposal_hash\":\"$PROPOSAL_HASH\"}")
31+
PROPOSAL_LEAF=$(echo "$RESULT" | python3 -c "import json,sys; print(json.load(sys.stdin)['leaf_hash'])")
32+
echo " Leaf: ${PROPOSAL_LEAF:0:24}..."
33+
echo ""
34+
35+
# 2. Cast votes (3 voters)
36+
echo -e "${GREEN}2. Casting votes${RST}"
37+
VOTE_LEAVES=""
38+
for voter in alice bob carol; do
39+
COMMITMENT=$(echo -n "${voter}_yes_${PROPOSAL_ID}" | sha256sum | cut -d' ' -f1)
40+
RESULT=$(curl -sf -X POST "$API/event" \
41+
-H "Authorization: Bearer $KEY" \
42+
-H "Content-Type: application/json" \
43+
-d "{\"event_type\":\"GOVERNANCE_VOTE\",\"wallet_hash\":\"${voter}\",\"proposal_id\":\"$PROPOSAL_ID\",\"vote_commitment\":\"$COMMITMENT\"}")
44+
LEAF=$(echo "$RESULT" | python3 -c "import json,sys; print(json.load(sys.stdin)['leaf_hash'])")
45+
echo " $voter voted -> ${LEAF:0:24}..."
46+
VOTE_LEAVES="$VOTE_LEAVES $LEAF"
47+
done
48+
echo ""
49+
50+
# 3. Record result
51+
RESULT_HASH=$(echo -n "3_yes_0_no_proposal_${PROPOSAL_ID}" | sha256sum | cut -d' ' -f1)
52+
echo -e "${GREEN}3. Recording result${RST}"
53+
RESULT=$(curl -sf -X POST "$API/event" \
54+
-H "Authorization: Bearer $KEY" \
55+
-H "Content-Type: application/json" \
56+
-d "{\"event_type\":\"GOVERNANCE_RESULT\",\"wallet_hash\":\"dao_operator\",\"proposal_id\":\"$PROPOSAL_ID\",\"result_hash\":\"$RESULT_HASH\"}")
57+
RESULT_LEAF=$(echo "$RESULT" | python3 -c "import json,sys; print(json.load(sys.stdin)['leaf_hash'])")
58+
echo " Result: 3 yes, 0 no -> ${RESULT_LEAF:0:24}..."
59+
echo ""
60+
61+
# 4. Verify
62+
echo -e "${GREEN}4. Verifying proposal attestation${RST}"
63+
CHECK=$(curl -sf "$API/verify/$PROPOSAL_LEAF/check")
64+
VALID=$(echo "$CHECK" | python3 -c "import json,sys; print(json.load(sys.stdin).get('valid', False))")
65+
echo " Proposal leaf valid: $VALID"
66+
67+
echo -e "${GREEN} Verifying vote attestations${RST}"
68+
for leaf in $VOTE_LEAVES; do
69+
CHECK=$(curl -sf "$API/verify/$leaf/check")
70+
VALID=$(echo "$CHECK" | python3 -c "import json,sys; print(json.load(sys.stdin).get('valid', False))")
71+
echo " Vote ${leaf:0:16}... valid: $VALID"
72+
done
73+
74+
echo ""
75+
echo -e "${GOLD}All events committed to Merkle tree.${RST}"
76+
echo -e "${DIM}Anchor the tree root to make them permanently verifiable on Zcash mainnet.${RST}"
77+
echo ""
78+
echo "Receipt URLs:"
79+
echo " Proposal: https://frontiercompute.io/receipt.html?leaf=$PROPOSAL_LEAF"
80+
echo " Result: https://frontiercompute.io/receipt.html?leaf=$RESULT_LEAF"

0 commit comments

Comments
 (0)