|
| 1 | +#! /bin/bash |
| 2 | +# Build + sign the Hydra offline-head seed tx for Preprod (--testnet-magic 1). |
| 3 | +# Tx layout follows infra/hydra-bootstrap/entrypoint.sh: cardano-cli latest transaction build-raw, then sign, then cat. |
| 4 | +# Run from repo host with Docker (entrypoint runs cardano-cli inside its image; we invoke the same CLI via docker run). |
| 5 | +# |
| 6 | +# No --tx-out-reference-script-file: cardano-cli’s reference-script CBOR does not match Hydra 1.3’s ledger check |
| 7 | +# (ConwayUtxowFailure MalformedReferenceScripts). The Pyth UTxO carries inline datum + tokens only; attach Plutus |
| 8 | +# in L2 txs explicitly (e.g. Lucid attach.WithdrawalValidator / attach.Script) instead of readFrom scriptRef. |
| 9 | + |
| 10 | +set -euo pipefail |
| 11 | + |
| 12 | +BOOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 13 | +INFRA="$(cd "${BOOT}/.." && pwd)" |
| 14 | + |
| 15 | +CARDANO_IMAGE="${CARDANO_IMAGE:-ghcr.io/intersectmbo/cardano-node:10.1.4}" |
| 16 | + |
| 17 | +cardano_cli() { |
| 18 | + docker run --rm --user "$(id -u):$(id -g)" --entrypoint cardano-cli \ |
| 19 | + -v "${INFRA}:/work" -w /work/hydra-bootstrap \ |
| 20 | + "${CARDANO_IMAGE}" "$@" |
| 21 | +} |
| 22 | + |
| 23 | +# Preprod (not the devnet 42 from entrypoint.sh) |
| 24 | +testnet_magic="${TESTNET_MAGIC:-1}" |
| 25 | + |
| 26 | +# Define the UTxO details and amounts (initial-utxo-set.json fiction #0) |
| 27 | +tx_in1="0000000000000000000000000000000000000000000000000000000000000000#0" |
| 28 | +tx_in_lovelace=100000000041175 |
| 29 | +fee=41175 |
| 30 | +# Remaining lovelace to the Pyth script output after fee |
| 31 | +out_lovelace=$((tx_in_lovelace - fee)) |
| 32 | + |
| 33 | +policy_id="d799d287105dea9377cdf9ea8502a83d2b9eb2d2050a8aea800a21e6" |
| 34 | +asset_name_hex="50797468205374617465" |
| 35 | +# Must match submit-seed-tx.sh PYTH_OUTPUT_ADDR |
| 36 | +pyth_script_address="${PYTH_OUTPUT_ADDR:-addr_test1wrm3tr5zpw9k2nefjtsz66wfzn6flnphr5kd6ak9ufrl3wcqqfyn8}" |
| 37 | + |
| 38 | +tx_out="${pyth_script_address}+${out_lovelace}+1 ${policy_id}.${asset_name_hex}" |
| 39 | + |
| 40 | +signing_key="${SEED_SIGNING_KEY:-${INFRA}/credentials/hydra-funds.sk}" |
| 41 | +if [[ "${signing_key}" != "${INFRA}"/* ]]; then |
| 42 | + echo "Signing key must be under ${INFRA}" >&2 |
| 43 | + exit 1 |
| 44 | +fi |
| 45 | +signing_key_container="/work/${signing_key#"${INFRA}"/}" |
| 46 | + |
| 47 | +# Inline datum CBOR (hex) — same as seed-output-datum.hex |
| 48 | +datum_hex="$(tr -d ' \n\t' < "${SEED_DATUM_HEX_FILE:-${BOOT}/seed-output-datum.hex}")" |
| 49 | +if command -v xxd >/dev/null 2>&1; then |
| 50 | + printf '%s' "${datum_hex}" | xxd -r -p > "${BOOT}/seed-output-datum.cbor" |
| 51 | +else |
| 52 | + python3 -c "import sys,binascii; sys.stdout.buffer.write(binascii.unhexlify(sys.argv[1]))" "${datum_hex}" > "${BOOT}/seed-output-datum.cbor" |
| 53 | +fi |
| 54 | + |
| 55 | +tx_raw="/work/hydra-bootstrap/seed.body.json" |
| 56 | +tx_signed="/work/hydra-bootstrap/seed.witnessed.json" |
| 57 | + |
| 58 | +# Build the raw transaction (cf. entrypoint.sh — build-raw, then fee, then out-file) |
| 59 | +echo "Building raw transaction..." |
| 60 | +cardano_cli latest transaction build-raw \ |
| 61 | + --tx-in "${tx_in1}" \ |
| 62 | + --tx-out "${tx_out}" \ |
| 63 | + --tx-out-inline-datum-cbor-file seed-output-datum.cbor \ |
| 64 | + --protocol-params-file /work/protocol-parameters.json \ |
| 65 | + --fee "${fee}" \ |
| 66 | + --out-file "${tx_raw}" |
| 67 | + |
| 68 | +# Sign the transaction (Preprod testnet-magic) |
| 69 | +echo "Signing transaction (Preprod testnet-magic ${testnet_magic})..." |
| 70 | +cardano_cli latest transaction sign \ |
| 71 | + --tx-body-file "${tx_raw}" \ |
| 72 | + --signing-key-file "${signing_key_container}" \ |
| 73 | + --testnet-magic "${testnet_magic}" \ |
| 74 | + --out-file "${tx_signed}" |
| 75 | + |
| 76 | +cp "${BOOT}/seed.witnessed.json" "${INFRA}/seed-spend.signed.json" |
| 77 | +cp "${BOOT}/seed.body.json" "${BOOT}/seed-spend.raw" |
| 78 | + |
| 79 | +echo "Wrote ${INFRA}/seed-spend.signed.json and ${BOOT}/seed-spend.raw" |
| 80 | +cat "${INFRA}/seed-spend.signed.json" |
0 commit comments