diff --git a/scripts/plutus/example-txin-locking-plutus-script.sh b/scripts/plutus/example-txin-locking-plutus-script.sh index c5fb5076b62..cfa54eb6f14 100755 --- a/scripts/plutus/example-txin-locking-plutus-script.sh +++ b/scripts/plutus/example-txin-locking-plutus-script.sh @@ -5,6 +5,11 @@ set -e set -o pipefail +export CARDANO_NODE_SOCKET_PATH="${CARDANO_NODE_SOCKET_PATH:-example/node-bft1/node.sock}" +export UTXO_VKEY="${UTXO_VKEY:-example/shelley/utxo-keys/utxo1.vkey}" +export UTXO_SKEY="${UTXO_SKEY:-example/shelley/utxo-keys/utxo1.skey}" +export WORK="${WORK:-example/work}" + if [ "$1" == "guessinggame" ]; then # NB: This plutus script uses a "typed" redeemer and "typed" datum. plutusscriptinuse=scripts/plutus/scripts/typed-guessing-game-redeemer-42-datum-42.plutus @@ -38,17 +43,14 @@ fi plutusscriptaddr=$(cardano-cli address build --payment-script-file $plutusscriptinuse --testnet-magic 42) -mkdir -p example/work - -utxovkey=example/shelley/utxo-keys/utxo1.vkey -utxoskey=example/shelley/utxo-keys/utxo1.skey +mkdir -p $WORK -utxoaddr=$(cardano-cli address build --testnet-magic 42 --payment-verification-key-file $utxovkey) +utxoaddr=$(cardano-cli address build --testnet-magic 42 --payment-verification-key-file $UTXO_VKEY) -cardano-cli query utxo --address $utxoaddr --cardano-mode --testnet-magic 42 --out-file example/work/utxo.json +cardano-cli query utxo --address $utxoaddr --cardano-mode --testnet-magic 42 --out-file $WORK/utxo.json -txin=$(jq -r 'keys[]' example/work/utxo.json) -lovelaceattxin=$(jq -r ".[\"$txin\"].value.lovelace" example/work/utxo.json) +txin=$(jq -r 'keys[]' $WORK/utxo.json) +lovelaceattxin=$(jq -r ".[\"$txin\"].value.lovelace" $WORK/utxo.json) lovelaceattxindiv2=$(expr $lovelaceattxin / 2) cardano-cli transaction build-raw \ @@ -58,16 +60,16 @@ cardano-cli transaction build-raw \ --tx-out "$plutusscriptaddr+$lovelaceattxindiv2" \ --tx-out-datum-hash "$scriptdatumhash" \ --tx-out "$utxoaddr+$lovelaceattxindiv2" \ - --out-file example/work/create-datum-output.body + --out-file $WORK/create-datum-output.body cardano-cli transaction sign \ - --tx-body-file example/work/create-datum-output.body \ + --tx-body-file $WORK/create-datum-output.body \ --testnet-magic 42 \ - --signing-key-file $utxoskey\ - --out-file example/work/create-datum-output.tx + --signing-key-file $UTXO_SKEY \ + --out-file $WORK/create-datum-output.tx # SUBMIT -cardano-cli transaction submit --tx-file example/work/create-datum-output.tx --testnet-magic 42 +cardano-cli transaction submit --tx-file $WORK/create-datum-output.tx --testnet-magic 42 echo "Pausing for 5 seconds..." sleep 5 @@ -75,17 +77,17 @@ sleep 5 # After "locking" the tx output at the script address, we can now can attempt to spend # the "locked" tx output below. -cardano-cli query utxo --address $plutusscriptaddr --testnet-magic 42 --out-file example/work/plutusutxo.json -plutusutxotxin=$(jq -r 'keys[]' example/work/plutusutxo.json) +cardano-cli query utxo --address $plutusscriptaddr --testnet-magic 42 --out-file $WORK/plutusutxo.json +plutusutxotxin=$(jq -r 'keys[]' $WORK/plutusutxo.json) -cardano-cli query utxo --address $utxoaddr --cardano-mode --testnet-magic 42 --out-file example/work/utxo.json -txinCollateral=$(jq -r 'keys[]' example/work/utxo.json) +cardano-cli query utxo --address $utxoaddr --cardano-mode --testnet-magic 42 --out-file $WORK/utxo.json +txinCollateral=$(jq -r 'keys[]' $WORK/utxo.json) cardano-cli query protocol-parameters --testnet-magic 42 --out-file example/pparams.json dummyaddress=addr_test1vpqgspvmh6m2m5pwangvdg499srfzre2dd96qq57nlnw6yctpasy4 -lovelaceatplutusscriptaddr=$(jq -r ".[\"$plutusutxotxin\"].value.lovelace" example/work/plutusutxo.json) +lovelaceatplutusscriptaddr=$(jq -r ".[\"$plutusutxotxin\"].value.lovelace" $WORK/plutusutxo.json) txfee=$(expr $plutusrequiredtime + $plutusrequiredtime) spendable=$(expr $lovelaceatplutusscriptaddr - $plutusrequiredtime - $plutusrequiredtime) @@ -101,17 +103,17 @@ cardano-cli transaction build-raw \ --protocol-params-file example/pparams.json\ --tx-in-redeemer-file "$redeemerfilepath" \ --tx-in-execution-units "($plutusrequiredtime, $plutusrequiredspace)" \ - --out-file example/work/test-alonzo.body + --out-file $WORK/test-alonzo.body cardano-cli transaction sign \ - --tx-body-file example/work/test-alonzo.body \ + --tx-body-file $WORK/test-alonzo.body \ --testnet-magic 42 \ - --signing-key-file example/shelley/utxo-keys/utxo1.skey \ - --out-file example/work/alonzo.tx + --signing-key-file "${UTXO_SKEY}" \ + --out-file $WORK/alonzo.tx -# SUBMIT example/work/alonzo.tx +# SUBMIT $WORK/alonzo.tx echo "Submit the tx with plutus script and wait 5 seconds..." -cardano-cli transaction submit --tx-file example/work/alonzo.tx --testnet-magic 42 +cardano-cli transaction submit --tx-file $WORK/alonzo.tx --testnet-magic 42 sleep 5 echo "" echo "Querying UTxO at $dummyaddress. If there is ADA at the address the Plutus script successfully executed!" diff --git a/scripts/plutus/simple-minting-policy.sh b/scripts/plutus/simple-minting-policy.sh index 952ac435d79..fe80a4f5994 100644 --- a/scripts/plutus/simple-minting-policy.sh +++ b/scripts/plutus/simple-minting-policy.sh @@ -13,7 +13,7 @@ set -o pipefail # Step 1 - Send ADA to token script owner -export CARDANO_NODE_SOCKET_PATH=example/node-bft1/node.sock +export CARDANO_NODE_SOCKET_PATH="${CARDANO_NODE_SOCKET_PATH:-example/node-bft1/node.sock}" utxovkey=example/shelley/utxo-keys/utxo1.vkey utxoskey=example/shelley/utxo-keys/utxo1.skey