|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +[ -n "${DEBUG:-}" ] && set -x |
| 5 | + |
| 6 | +if [ "$#" -ne "4" ]; then |
| 7 | + echo "Three arguments are required:" |
| 8 | + echo " $0 \$ENV \$ACTION_ID \$ACTION_IX \$VOTE" |
| 9 | + echo |
| 10 | + echo "Where:" |
| 11 | + echo " ENV be 'preview' or 'preprod'" |
| 12 | + echo " VOTE must be 'yes', 'no' or 'abstain'" |
| 13 | + exit 1 |
| 14 | +else |
| 15 | + ENV="$1" |
| 16 | + ACTION_ID="$2" |
| 17 | + ACTION_IX="$3" |
| 18 | + VOTE="$4" |
| 19 | +fi |
| 20 | + |
| 21 | +ORCH_DIR="secrets/envs/$ENV/icc-keys" |
| 22 | +INITHOT_DIR="$ORCH_DIR/init-hot" |
| 23 | +SIGNER_DIR="$ORCH_DIR/testnets-secret" |
| 24 | +ORCH_ADDR=$(just sops-decrypt-binary "$ORCH_DIR/orchestrator.addr") |
| 25 | + |
| 26 | +case "$VOTE" in |
| 27 | + yes) |
| 28 | + ANCHOR="https://raw.githubusercontent.com/carloslodelar/proposals/refs/heads/main/voteYES.jsonld" |
| 29 | + ;; |
| 30 | + no) |
| 31 | + ANCHOR="https://raw.githubusercontent.com/carloslodelar/proposals/refs/heads/main/voteNO.jsonld" |
| 32 | + ;; |
| 33 | + abstain) |
| 34 | + ANCHOR="https://raw.githubusercontent.com/carloslodelar/proposals/refs/heads/main/voteABSTAIN.jsonld" |
| 35 | + ;; |
| 36 | + *) |
| 37 | + echo "Error: Invalid third argument. Please provide 'yes', 'no', or 'abstain'." |
| 38 | + exit 1 |
| 39 | + ;; |
| 40 | +esac |
| 41 | + |
| 42 | +# Hash the anchor data using cardano-cli. |
| 43 | +# Note that using the `--text` option would result in an incorrect hash. |
| 44 | +cardano-cli hash anchor-data \ |
| 45 | + --file-text <(curl -sL "$ANCHOR") \ |
| 46 | + --out-file anchor.hash |
| 47 | + |
| 48 | +cardano-cli conway query utxo \ |
| 49 | + --address "$(just sops-decrypt-binary "$INITHOT_DIR/nft.addr")" \ |
| 50 | + --output-json \ |
| 51 | + | jq ' |
| 52 | + [ |
| 53 | + to_entries |
| 54 | + | .[] |
| 55 | + | select(.value.value["'"$(cat <(just sops-decrypt-binary "$INITHOT_DIR/minting.plutus.hash"))"'"]["'"$(cat <(just sops-decrypt-binary "$INITHOT_DIR/nft-token-name"))"'"]) |
| 56 | + ] | from_entries' \ |
| 57 | + > hot-nft.utxo |
| 58 | + |
| 59 | +orchestrator-cli vote \ |
| 60 | + --utxo-file hot-nft.utxo \ |
| 61 | + --hot-credential-script-file <(just sops-decrypt-binary "$INITHOT_DIR/credential.plutus") \ |
| 62 | + --governance-action-tx-id "$ACTION_ID" \ |
| 63 | + --governance-action-index "$ACTION_IX" \ |
| 64 | + --"$VOTE" \ |
| 65 | + --metadata-url "$ANCHOR" \ |
| 66 | + --metadata-hash "$(cat anchor.hash)" \ |
| 67 | + --out-dir vote |
| 68 | + |
| 69 | +cardano-cli conway transaction build \ |
| 70 | + --tx-in "$(cardano-cli conway query utxo --address "$ORCH_ADDR" --output-json | jq -r 'keys[0]')" \ |
| 71 | + --tx-in-collateral "$(cardano-cli conway query utxo --address "$ORCH_ADDR" --output-json | jq -r 'keys[0]')" \ |
| 72 | + --tx-in "$(jq -r 'keys[0]' hot-nft.utxo)" \ |
| 73 | + --tx-in-script-file <(just sops-decrypt-binary "$INITHOT_DIR/nft.plutus") \ |
| 74 | + --tx-in-inline-datum-present \ |
| 75 | + --tx-in-redeemer-file "vote/redeemer.json" \ |
| 76 | + --tx-out "$(cat vote/value)" \ |
| 77 | + --tx-out-inline-datum-file "vote/datum.json" \ |
| 78 | + --required-signer-hash "$(orchestrator-cli extract-pub-key-hash <(just sops-decrypt-binary "$SIGNER_DIR/voter-1.crt"))" \ |
| 79 | + --required-signer-hash "$(orchestrator-cli extract-pub-key-hash <(just sops-decrypt-binary "$SIGNER_DIR/voter-2.crt"))" \ |
| 80 | + --required-signer-hash "$(orchestrator-cli extract-pub-key-hash <(just sops-decrypt-binary "$SIGNER_DIR/voter-3.crt"))" \ |
| 81 | + --vote-file "vote/vote" \ |
| 82 | + --vote-script-file <(just sops-decrypt-binary "$INITHOT_DIR/credential.plutus") \ |
| 83 | + --vote-redeemer-value {} \ |
| 84 | + --change-address "$ORCH_ADDR" \ |
| 85 | + --out-file body.json |
| 86 | + |
| 87 | +cardano-cli conway transaction witness \ |
| 88 | + --tx-body-file body.json \ |
| 89 | + --signing-key-file <(just sops-decrypt-binary "${SIGNER_DIR}/voter-1.skey") \ |
| 90 | + --out-file voter1.witness |
| 91 | + |
| 92 | +cardano-cli conway transaction witness \ |
| 93 | + --tx-body-file body.json \ |
| 94 | + --signing-key-file <(just sops-decrypt-binary "${SIGNER_DIR}/voter-2.skey") \ |
| 95 | + --out-file voter2.witness |
| 96 | + |
| 97 | +cardano-cli conway transaction witness \ |
| 98 | + --tx-body-file body.json \ |
| 99 | + --signing-key-file <(just sops-decrypt-binary "${SIGNER_DIR}/voter-3.skey") \ |
| 100 | + --out-file voter3.witness |
| 101 | + |
| 102 | +cardano-cli conway transaction witness \ |
| 103 | + --tx-body-file body.json \ |
| 104 | + --signing-key-file <(just sops-decrypt-binary "${ORCH_DIR}/orchestrator.skey") \ |
| 105 | + --out-file orchestrator.witness |
| 106 | + |
| 107 | +cardano-cli conway transaction assemble \ |
| 108 | + --tx-body-file body.json \ |
| 109 | + --witness-file voter1.witness \ |
| 110 | + --witness-file voter2.witness \ |
| 111 | + --witness-file voter3.witness \ |
| 112 | + --witness-file orchestrator.witness \ |
| 113 | + --out-file vote-tx.signed |
| 114 | + |
| 115 | +echo |
| 116 | +echo "The debug view of the transaction body is:" |
| 117 | +cardano-cli debug transaction view --tx-file vote-tx.signed |
| 118 | +echo |
| 119 | +echo |
| 120 | +echo "This transaction may be submitted to the network with the following command:" |
| 121 | +echo "cardano-cli conway transaction submit --tx-file vote-tx.signed" |
0 commit comments