Skip to content

Commit

Permalink
CAD-2907 workbench: keep copy of original plutus testscript
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcFontaine committed Jun 16, 2021
1 parent 5eace83 commit 33249c1
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 14 deletions.
99 changes: 99 additions & 0 deletions scripts/plutus/example-txin-locking-plutus-script-workbench.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/usr/bin/env bash

set -e
# Unoffiical bash strict mode.
# See: http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -u
set -o pipefail

# This script demonstrates how to lock a tx output with a plutus script.
# NB: In this example the Datum must be 42!

# Step 1: Create a tx ouput with a datum hash at the script address. In order for a tx ouput to be locked
# by a plutus script, it must have a datahash. We also need collateral tx inputs so we split the utxo
# in order to accomodate this.

# This is the end to end always succeeds plutus script example
plutusscriptinuse=scripts/plutus/untyped-always-succeeds-txin.plutus

export CARDANO_NODE_SOCKET_PATH=run/current/node-1/node.socket

mkdir -p example/shelley/utxo-keys/
cp -f run/current/genesis/utxo-keys/utxo1.* example/shelley/utxo-keys/

plutusscriptaddr=$(cardano-cli address build --payment-script-file $plutusscriptinuse --testnet-magic 42 | grep -v Temporary)

mkdir -p example/work

utxovkey=example/shelley/utxo-keys/utxo1.vkey
utxoskey=example/shelley/utxo-keys/utxo1.skey

utxoaddr=$(cardano-cli address build --testnet-magic 42 --payment-verification-key-file $utxovkey | grep -v Temporary)

cardano-cli query utxo --address $utxoaddr --cardano-mode --testnet-magic 42 --out-file example/work/utxo.json

txin=$(jq -r 'keys[]' example/work/utxo.json)

cardano-cli transaction build-raw \
--alonzo-era \
--fee 200000 \
--tx-in $txin \
--tx-out $plutusscriptaddr+49999999900000 \
--tx-out-datum-hash 9e1199a988ba72ffd6e9c269cadb3b53b5f360ff99f112d9b2ee30c4d74ad88b \
--tx-out $utxoaddr+49999999900000 \
--out-file example/work/create-datum-output.body

cardano-cli transaction sign \
--tx-body-file example/work/create-datum-output.body \
--testnet-magic 42 \
--signing-key-file $utxoskey\
--out-file example/work/create-datum-output.tx

# SUBMIT
cardano-cli transaction submit --tx-file example/work/create-datum-output.tx --testnet-magic 42

echo "Pausing for 15 seconds..."
sleep 15

# Step 2
# 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 $utxoaddr --cardano-mode --testnet-magic 42 --out-file example/work/utxo.json
txinCollateral=$(jq -r 'keys[]' example/work/utxo.json)

echo "Plutus TxIn"
echo $plutusutxotxin

echo "Collateral TxIn"
echo $txinCollateral

cardano-cli query protocol-parameters --testnet-magic 42 --out-file example/pparams.json

dummyaddress=addr_test1vpqgspvmh6m2m5pwangvdg499srfzre2dd96qq57nlnw6yctpasy4

cardano-cli transaction build-raw \
--alonzo-era \
--fee 500000000 \
--tx-in $plutusutxotxin \
--tx-in-collateral $txinCollateral \
--tx-out "$dummyaddress+49999499900000" \
--tx-in-script-file $plutusscriptinuse \
--tx-in-datum-value 42 \
--protocol-params-file example/pparams.json\
--tx-in-redeemer-value 42 \
--tx-in-execution-units "(200000000,200000000)" \
--out-file example/work/test-alonzo.body

cardano-cli transaction sign \
--tx-body-file example/work/test-alonzo.body \
--testnet-magic 42 \
--signing-key-file example/shelley/utxo-keys/utxo1.skey \
--out-file example/work/alonzo.tx

# SUBMIT example/work/alonzo.tx
echo "Manually submit the tx with plutus script via:"
echo "cardano-cli transaction submit --tx-file example/work/alonzo.tx --testnet-magic 42"
24 changes: 10 additions & 14 deletions scripts/plutus/example-txin-locking-plutus-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,27 @@ set -o pipefail
# This is the end to end always succeeds plutus script example
plutusscriptinuse=scripts/plutus/untyped-always-succeeds-txin.plutus

export CARDANO_NODE_SOCKET_PATH=run/current/node-1/node.socket

mkdir -p example/shelley/utxo-keys/
cp -f run/current/genesis/utxo-keys/utxo1.* example/shelley/utxo-keys/

plutusscriptaddr=$(cardano-cli address build --payment-script-file $plutusscriptinuse --testnet-magic 42 | grep -v Temporary)
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

utxoaddr=$(cardano-cli address build --testnet-magic 42 --payment-verification-key-file $utxovkey | grep -v Temporary)
utxoaddr=$(cardano-cli address build --testnet-magic 42 --payment-verification-key-file $utxovkey)

cardano-cli query utxo --address $utxoaddr --cardano-mode --testnet-magic 42 --out-file example/work/utxo.json
utxo=$(cardano-cli query utxo --address $utxoaddr --cardano-mode --testnet-magic 42 --out-file example/work/utxo.json)

txin=$(jq -r 'keys[]' example/work/utxo.json)

cardano-cli transaction build-raw \
--alonzo-era \
--fee 200000 \
--fee 0 \
--tx-in $txin \
--tx-out $plutusscriptaddr+49999999900000 \
--tx-out $plutusscriptaddr+500000000 \
--tx-out-datum-hash 9e1199a988ba72ffd6e9c269cadb3b53b5f360ff99f112d9b2ee30c4d74ad88b \
--tx-out $utxoaddr+49999999900000 \
--tx-out $utxoaddr+500000000 \
--out-file example/work/create-datum-output.body

cardano-cli transaction sign \
Expand All @@ -52,8 +48,8 @@ cardano-cli transaction sign \
# SUBMIT
cardano-cli transaction submit --tx-file example/work/create-datum-output.tx --testnet-magic 42

echo "Pausing for 15 seconds..."
sleep 15
echo "Pausing for 5 seconds..."
sleep 5

# Step 2
# After "locking" the tx output at the script address, we can now can attempt to spend
Expand All @@ -77,10 +73,10 @@ dummyaddress=addr_test1vpqgspvmh6m2m5pwangvdg499srfzre2dd96qq57nlnw6yctpasy4

cardano-cli transaction build-raw \
--alonzo-era \
--fee 500000000 \
--fee 400000000 \
--tx-in $plutusutxotxin \
--tx-in-collateral $txinCollateral \
--tx-out "$dummyaddress+49999499900000" \
--tx-out "$dummyaddress+100000000" \
--tx-in-script-file $plutusscriptinuse \
--tx-in-datum-value 42 \
--protocol-params-file example/pparams.json\
Expand Down

0 comments on commit 33249c1

Please sign in to comment.