Skip to content

Commit 147f78a

Browse files
Merge #4006
4006: Update example-reference-script-usage.sh to also use inline datums r=Jimbo4350 a=Jimbo4350 We introduce `--reference-tx-in-inline-datum-present` and `--tx-in-inline-datum-present` to indicate when we are using an inline datum. Co-authored-by: Jordan Millar <[email protected]>
2 parents fe4997a + be290c5 commit 147f78a

File tree

8 files changed

+33
-21
lines changed

8 files changed

+33
-21
lines changed

cardano-api/src/Cardano/Api/Script.hs

+1
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,7 @@ type ScriptRedeemer = ScriptData
788788

789789
data ScriptDatum witctx where
790790
ScriptDatumForTxIn :: ScriptData -> ScriptDatum WitCtxTxIn
791+
InlineScriptDatum :: ScriptDatum WitCtxTxIn
791792
NoScriptDatumForMint :: ScriptDatum WitCtxMint
792793
NoScriptDatumForStake :: ScriptDatum WitCtxStake
793794

cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs

+10-2
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,22 @@ pScriptRedeemerOrFile scriptFlagPrefix =
322322
pScriptDatumOrFile :: String -> WitCtx witctx -> Parser (ScriptDatumOrFile witctx)
323323
pScriptDatumOrFile scriptFlagPrefix witctx =
324324
case witctx of
325-
WitCtxTxIn -> ScriptDatumOrFileForTxIn <$>
325+
WitCtxTxIn -> (ScriptDatumOrFileForTxIn <$>
326326
pScriptDataOrFile
327327
(scriptFlagPrefix ++ "-datum")
328328
"The script datum, in JSON syntax."
329-
"The script datum, in the given JSON file."
329+
"The script datum, in the given JSON file.") <|>
330+
pInlineDatumPresent scriptFlagPrefix
330331
WitCtxMint -> pure NoScriptDatumOrFileForMint
331332
WitCtxStake -> pure NoScriptDatumOrFileForStake
332333

334+
pInlineDatumPresent :: String -> Parser (ScriptDatumOrFile WitCtxTxIn)
335+
pInlineDatumPresent scriptFlagPrefix =
336+
flag' InlineDatumPresentAtTxIn
337+
( long (scriptFlagPrefix ++ "-inline-datum-present")
338+
<> Opt.help "Inline datum present at transaction input."
339+
)
340+
333341
pScriptDataOrFile :: String -> String -> String -> Parser ScriptDataOrFile
334342
pScriptDataOrFile dataFlagPrefix helpTextForValue helpTextForFile =
335343
pScriptDataCborFile

cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs

+1
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,7 @@ readScriptDatumOrFile :: ScriptDatumOrFile witctx
11351135
-> ExceptT ShelleyTxCmdError IO (ScriptDatum witctx)
11361136
readScriptDatumOrFile (ScriptDatumOrFileForTxIn df) = ScriptDatumForTxIn <$>
11371137
readScriptDataOrFile df
1138+
readScriptDatumOrFile InlineDatumPresentAtTxIn = pure InlineScriptDatum
11381139
readScriptDatumOrFile NoScriptDatumOrFileForMint = pure NoScriptDatumForMint
11391140
readScriptDatumOrFile NoScriptDatumOrFileForStake = pure NoScriptDatumForStake
11401141

cardano-cli/src/Cardano/CLI/Types.hs

+1
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ deriving instance Show (ScriptWitnessFiles witctx)
309309
data ScriptDatumOrFile witctx where
310310
ScriptDatumOrFileForTxIn :: ScriptDataOrFile
311311
-> ScriptDatumOrFile WitCtxTxIn
312+
InlineDatumPresentAtTxIn :: ScriptDatumOrFile WitCtxTxIn
312313

313314
NoScriptDatumOrFileForMint :: ScriptDatumOrFile WitCtxMint
314315
NoScriptDatumOrFileForStake :: ScriptDatumOrFile WitCtxStake

cardano-testnet/cardano-testnet.cabal

-5
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,8 @@ common project-config
2525
-Wredundant-constraints
2626
-Wunused-packages
2727

28-
common maybe-unix
29-
if !os(windows)
30-
build-depends: unix
31-
3228
library
3329
import: base, project-config
34-
, maybe-unix
3530

3631
build-depends: aeson
3732
, base16-bytestring

doc/reference/plutus/reference-script-example.md renamed to doc/reference/plutus/babbage-script-example.md

+17-11
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,26 @@
44

55
A reference script is a script that exists at a particular transaction output. It can be used to witness, for example, a UTxO at the corresponding script address of said reference script. This is useful because the script does not have to be included in the transaction anymore, which significantly reduces the transaction size.
66

7+
## What is an inline datum?
8+
9+
An inline datum, is a datum that exists at a transaction output. We no longer have to include a datum within our transaction for our plutus spending scripts. Instead we can specify the transaction output where our datum exists to be used in conjunction with our Plutus spending script. This reduces the overall size of our transaction.
10+
711
### An example of using a Plutus V2 reference script
812

9-
Below is an example that shows how to use a Plutus spending script. Here we discuss a [shell script example of how to use a reference script to spend a tx input](scripts/plutus/example-reference-script-usage.sh). This is a step-by-step process involving:
13+
Below is an example that shows how to use a Plutus spending script and an inline datum. Here we discuss a [shell script example of how to use a reference script to spend a tx input](scripts/plutus/example-babbage-script-usage.sh). This is a step-by-step process involving:
1014

1115
+ the creation of the `Required Redeemer` Plutus txin script
1216
+ the creation of the `Required Redeemer` Plutus script at a transaction output (creation of the reference script)
13-
+ sending ada and a datum to the Plutus script address
17+
+ the creation of the inline datum at a transaction output
18+
+ sending ada to the Plutus script address
1419
+ spending ada at the Plutus script address using the Plutus reference script
1520

1621
In this example we will use the [Required Redeemer](scripts/plutus/scripts/v2/required-redeemer.plutus) Plutus spending script. In order to execute a reference Plutus spending script, we require the following:
1722

1823
- Collateral tx input(s) - these are provided and are forfeited in the event the Plutus script fails to execute.
19-
- A Plutus tx output with accompanying datum hash. This is the tx output that sits at the Plutus script address. It must have a datum hash, otherwise, it is unspendable.
24+
- A Plutus tx output. This is the tx output that sits at the Plutus script address.
2025
- The reference transaction input containing the corresponding Plutus script. We must create the transaction output containing the reference Plutus script.
26+
- An inline datum at the Plutus tx output. The Plutus spending script requires an inline datum or datum hash and in this case we are using an inline datum.
2127

2228
#### Creating the `Required Redeemer` Plutus spending script
2329

@@ -48,10 +54,10 @@ cabal install cardano-node
4854
```
4955

5056
To start your babbage cluster, you need to run the `example/run/all.sh` shell script.
51-
The remainder of this guide provides a brief walkthrough of the [shell script example](scripts/plutus/example-reference-script-usage.sh) that automatically creates a reference script and spends the utxo at
57+
The remainder of this guide provides a brief walkthrough of the [shell script example](scripts/plutus/example-babbage-script-usage.sh) that automatically creates a reference script and spends the utxo at
5258
the reference script's corresponding script address.
5359

54-
#### Creating a reference script at a transaction output and
60+
#### Creating a reference script at a transaction output, inline datum and
5561
#### sending ada to the script address (with a datum)
5662

5763
In order to use a reference script, we must first create this script at a particular transaction output.
@@ -65,7 +71,7 @@ cardano-cli transaction build \
6571
--tx-in "$txin" \
6672
--tx-out "$utxoaddr+$lovelace" \
6773
--tx-out "$plutusscriptaddr+$lovelace" \
68-
--tx-out-datum-hash "$scriptdatumhash" \
74+
--tx-out-inline-datum-file "$datumfilepath" \
6975
--tx-out "$dummyaddress+$lovelaceattxindiv3" \
7076
--tx-out-reference-script-file "$plutusscriptinuse" \
7177
--protocol-params-file "$WORK/pparams.json" \
@@ -74,12 +80,12 @@ cardano-cli transaction build \
7480

7581
The following should be noted about this build command:
7682

77-
Firstly, we are sending ada to the plutus script address along with a datum hash. This is reflected in the following lines:
83+
Firstly, we are sending ada and an inline datum to the plutus script address. This is reflected in the following lines:
7884

7985
```bash
8086
...
8187
--tx-out "$plutusscriptaddr+$lovelace" \
82-
--tx-out-datum-hash "$scriptdatumhash" \
88+
--tx-out-inline-datum-file "$datumfilepath" \
8389
...
8490
```
8591

@@ -115,7 +121,7 @@ Because we are using the `build` command, we should only note the following:
115121
`$plutusutxotxin` - This is the tx input that sits at the Plutus script address (NB: It has a datum hash).
116122
`tx-in-reference` - This specifies the reference input you are using to witness a transaction input.
117123
`plutus-script-v2`- This specifies the version of the reference script at the reference input.
118-
`reference-tx-in-datum-file` - This is the datum to be used with the reference script.
124+
`reference-tx-in-inline-datum-present` - This indicates that we are using an inline datum which exists at the utxo we are trying to spend (the utxo at the Plutus script address).
119125
`reference-tx-in-redeemer-file` - This is the redeemer to be used with the reference script.
120126

121127
```bash
@@ -130,7 +136,7 @@ cardano-cli transaction build \
130136
--tx-in "$plutuslockedutxotxin" \
131137
--tx-in-reference "$plutusreferencescripttxin" \
132138
--plutus-script-v2 \
133-
--reference-tx-in-datum-file "$datumfilepath" \
139+
--reference-tx-in-inline-datum-present \
134140
--reference-tx-in-redeemer-file "$redeemerfilepath" \
135141
--tx-out "$dummyaddress2+10000000" \
136142
--protocol-params-file "$WORK/pparams.json"
@@ -142,7 +148,7 @@ cardano-cli transaction sign \
142148
--out-file $WORK/alonzo-ref-script.tx
143149
```
144150

145-
If there is ada at `$dummyaddress2`, then the Plutus script was successfully executed. Conversely, if the Plutus script failed, the collateral input would have been consumed.
151+
If there is ada at `$dummyaddress2`, then the Plutus script was successfully executed.
146152

147153
You can use the [example-txin-locking-plutus-script.sh](../../../scripts/plutus/example-txin-locking-plutus-script.sh) in conjunction with [mkfiles.sh alonzo](../../../scripts/byron-to-alonzo/mkfiles.sh) script to automagically run the `AlwaysSucceeds` script.
148154

scripts/plutus/example-reference-script-usage.sh renamed to scripts/plutus/example-babbage-script-usage.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ $CARDANO_CLI transaction build \
6161
--tx-in "$txin" \
6262
--tx-out "$utxoaddr+$lovelaceattxindiv3" \
6363
--tx-out "$plutusscriptaddr+$lovelaceattxindiv3" \
64-
--tx-out-datum-hash "$scriptdatumhash" \
64+
--tx-out-inline-datum-file "$datumfilepath" \
6565
--tx-out "$dummyaddress+$lovelaceattxindiv3" \
6666
--tx-out-reference-script-file "$plutusscriptinuse" \
6767
--protocol-params-file "$WORK/pparams.json" \
@@ -147,7 +147,7 @@ $CARDANO_CLI transaction build \
147147
--tx-in "$plutuslockedutxotxin" \
148148
--tx-in-reference "$plutusreferencescripttxin" \
149149
--plutus-script-v2 \
150-
--reference-tx-in-datum-file "$datumfilepath" \
150+
--reference-tx-in-inline-datum-present \
151151
--reference-tx-in-redeemer-file "$redeemerfilepath" \
152152
--tx-out "$dummyaddress2+10000000" \
153153
--protocol-params-file "$WORK/pparams.json"
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"type": "PlutusScriptV2",
33
"description": "",
4-
"cborHex": "59077e59077b010000323322323232323232323232323232332232323232322223232533532325335333573466e3c00522010001c01b101b101c376600a6666ae68cdc39aab9d5002480008cc8848cc00400c008c8c8c8c8c8c8c8c8c8c8c8c8c8cccd5cd19b8735573aa018900011999999999999111111111110919999999999980080680600580500480400380300280200180119a80a80b1aba1500c33501501635742a01666a02a02e6ae854028ccd54065d7280c1aba150093335501975ca0306ae854020cd4054080d5d0a803999aa80c810bad35742a00c6464646666ae68cdc39aab9d5002480008cc8848cc00400c008c8c8c8cccd5cd19b8735573aa004900011991091980080180119a815bad35742a00460586ae84d5d1280111931901719ab9c02f02e02c135573ca00226ea8004d5d0a8011919191999ab9a3370e6aae754009200023322123300100300233502b75a6ae854008c0b0d5d09aba2500223263202e33573805e05c05826aae7940044dd50009aba135744a004464c6405466ae700ac0a80a04d55cf280089baa00135742a00a66a02aeb8d5d0a802199aa80c80e90009aba150033335501975c40026ae854008c07cd5d09aba2500223263202633573804e04c04826ae8940044d5d1280089aba25001135744a00226ae8940044d5d1280089aba25001135744a00226ae8940044d5d1280089aab9e5001137540026ae854008c03cd5d09aba2500223263201833573803203002c202e264c6402e66ae7124010350543500017135573ca00226ea800448c88c008dd6000990009aa80b111999aab9f0012500a233500930043574200460066ae880080508c8c8cccd5cd19b8735573aa004900011991091980080180118061aba150023005357426ae8940088c98c8050cd5ce00a80a00909aab9e5001137540024646464646666ae68cdc39aab9d5004480008cccc888848cccc00401401000c008c8c8c8cccd5cd19b8735573aa0049000119910919800801801180a9aba1500233500f014357426ae8940088c98c8064cd5ce00d00c80b89aab9e5001137540026ae854010ccd54021d728039aba150033232323333573466e1d4005200423212223002004357426aae79400c8cccd5cd19b875002480088c84888c004010dd71aba135573ca00846666ae68cdc3a801a400042444006464c6403666ae7007006c06406005c4d55cea80089baa00135742a00466a016eb8d5d09aba2500223263201533573802c02a02626ae8940044d5d1280089aab9e500113754002266aa002eb9d6889119118011bab00132001355013223233335573e0044a010466a00e66442466002006004600c6aae754008c014d55cf280118021aba200301213574200222440042442446600200800624464646666ae68cdc3a800a40004642446004006600a6ae84d55cf280191999ab9a3370ea0049001109100091931900819ab9c01101000e00d135573aa00226ea80048c8c8cccd5cd19b875001480188c848888c010014c01cd5d09aab9e500323333573466e1d400920042321222230020053009357426aae7940108cccd5cd19b875003480088c848888c004014c01cd5d09aab9e500523333573466e1d40112000232122223003005375c6ae84d55cf280311931900819ab9c01101000e00d00c00b135573aa00226ea80048c8c8cccd5cd19b8735573aa004900011991091980080180118029aba15002375a6ae84d5d1280111931900619ab9c00d00c00a135573ca00226ea80048c8cccd5cd19b8735573aa002900011bae357426aae7940088c98c8028cd5ce00580500409baa001232323232323333573466e1d4005200c21222222200323333573466e1d4009200a21222222200423333573466e1d400d2008233221222222233001009008375c6ae854014dd69aba135744a00a46666ae68cdc3a8022400c4664424444444660040120106eb8d5d0a8039bae357426ae89401c8cccd5cd19b875005480108cc8848888888cc018024020c030d5d0a8049bae357426ae8940248cccd5cd19b875006480088c848888888c01c020c034d5d09aab9e500b23333573466e1d401d2000232122222223005008300e357426aae7940308c98c804ccd5ce00a00980880800780700680600589aab9d5004135573ca00626aae7940084d55cf280089baa0012323232323333573466e1d400520022333222122333001005004003375a6ae854010dd69aba15003375a6ae84d5d1280191999ab9a3370ea0049000119091180100198041aba135573ca00c464c6401866ae700340300280244d55cea80189aba25001135573ca00226ea80048c8c8cccd5cd19b875001480088c8488c00400cdd71aba135573ca00646666ae68cdc3a8012400046424460040066eb8d5d09aab9e500423263200933573801401200e00c26aae7540044dd500089119191999ab9a3370ea00290021091100091999ab9a3370ea00490011190911180180218031aba135573ca00846666ae68cdc3a801a400042444004464c6401466ae7002c02802001c0184d55cea80089baa0012323333573466e1d40052002200823333573466e1d40092000200823263200633573800e00c00800626aae74dd5000a4c240029210350543100122002122001112323001001223300330020020011"
4+
"cborHex": "59087f59087c01000032323322323322323232323232323232323232323322323232323232322223232533532323253350021001101f32533500121021101f32333553021120013212330012253350022100310010025010253353253335002153335001102221022210222153335002102221333573466ebc00800409008c8408c854ccd400840888408c84cc088008004c034cd540948004dd4240a826a0240022a02200266aa0466aa6038240024646a00244440046a00244002646a0024444444444440186a0044400464a66a6603a00291100101e101f376600a6666ae68cdc39aab9d5002480008cc8848cc00400c008c8c8c8c8c8c8c8c8c8c8c8c8c8cccd5cd19b8735573aa018900011999999999999111111111110919999999999980080680600580500480400380300280200180119a80a80b1aba1500c33501501635742a01666a02a02e6ae854028ccd54069d7280c9aba150093335501a75ca0326ae854020cd4054084d5d0a803999aa80d0113ad35742a00c6464646666ae68cdc39aab9d5002480008cc8848cc00400c008c8c8c8cccd5cd19b8735573aa004900011991091980080180119a8163ad35742a004605a6ae84d5d1280111931901799ab9c03002f02d135573ca00226ea8004d5d0a8011919191999ab9a3370e6aae754009200023322123300100300233502c75a6ae854008c0b4d5d09aba2500223263202f33573806005e05a26aae7940044dd50009aba135744a004464c6405666ae700b00ac0a44d55cf280089baa00135742a00a66a02aeb8d5d0a802199aa80d00f10009aba150033335501a75c40026ae854008c080d5d09aba2500223263202733573805004e04a26ae8940044d5d1280089aba25001135744a00226ae8940044d5d1280089aba25001135744a00226ae8940044d5d1280089aab9e5001137540026ae854008c040d5d09aba2500223263201933573803403202e2030264c6403066ae7124010350543500018135573ca00226ea800448c88c008dd6000990009aa80e911999aab9f0012501e233501d30043574200460066ae880080548c8c8cccd5cd19b8735573aa004900011991091980080180118069aba150023005357426ae8940088c98c8054cd5ce00b00a80989aab9e5001137540024646464646666ae68cdc39aab9d5004480008cccc888848cccc00401401000c008c8c8c8cccd5cd19b8735573aa0049000119910919800801801180b1aba1500233500e015357426ae8940088c98c8068cd5ce00d80d00c09aab9e5001137540026ae854010ccd54025d728041aba150033232323333573466e1d400520042300b357426aae79400c8cccd5cd19b875002480088c84888c004010dd71aba135573ca00846666ae68cdc3a801a400042444006464c6403866ae700740700680640604d55cea80089baa00135742a00466a014eb8d5d09aba2500223263201633573802e02c02826ae8940044d5d1280089aab9e500113754002424446004008266aa002eb9d6889119118011bab00132001355019223233335573e0044a036466a03466442466002006004600c6aae754008c014d55cf280118021aba200301213574200224464646666ae68cdc3a800a400046a00e600a6ae84d55cf280191999ab9a3370ea00490011280391931900919ab9c01301201000f135573aa00226ea800448488c00800c44880048c8c8cccd5cd19b875001480188c848888c010014c01cd5d09aab9e500323333573466e1d400920042321222230020053009357426aae7940108cccd5cd19b875003480088c848888c004014c01cd5d09aab9e500523333573466e1d40112000232122223003005375c6ae84d55cf280311931900819ab9c01101000e00d00c00b135573aa00226ea80048c8c8cccd5cd19b8735573aa004900011991091980080180118029aba15002375a6ae84d5d1280111931900619ab9c00d00c00a135573ca00226ea80048c8cccd5cd19b8735573aa002900011bae357426aae7940088c98c8028cd5ce00580500409baa001232323232323333573466e1d4005200c21222222200323333573466e1d4009200a21222222200423333573466e1d400d2008233221222222233001009008375c6ae854014dd69aba135744a00a46666ae68cdc3a8022400c4664424444444660040120106eb8d5d0a8039bae357426ae89401c8cccd5cd19b875005480108cc8848888888cc018024020c030d5d0a8049bae357426ae8940248cccd5cd19b875006480088c848888888c01c020c034d5d09aab9e500b23333573466e1d401d2000232122222223005008300e357426aae7940308c98c804ccd5ce00a00980880800780700680600589aab9d5004135573ca00626aae7940084d55cf280089baa0012323232323333573466e1d400520022333222122333001005004003375a6ae854010dd69aba15003375a6ae84d5d1280191999ab9a3370ea0049000119091180100198041aba135573ca00c464c6401866ae700340300280244d55cea80189aba25001135573ca00226ea80048c8c8cccd5cd19b875001480088c8488c00400cdd71aba135573ca00646666ae68cdc3a8012400046424460040066eb8d5d09aab9e500423263200933573801401200e00c26aae7540044dd500089119191999ab9a3370ea00290021091100091999ab9a3370ea00490011190911180180218031aba135573ca00846666ae68cdc3a801a400042444004464c6401466ae7002c02802001c0184d55cea80089baa0012323333573466e1d40052002200a23333573466e1d40092000200a23263200633573800e00c00800626aae74dd5000a4c24002920103505431003200135500822112253350011500a22133500b3004002335530061200100400122333573466e3c00800401000c488008488004c8004d5401088448894cd40044d400c88004884ccd401488008c010008ccd54c01c480040140100044488008488488cc00401000c4488c008004448c8c00400488cc00cc0080080041"
55
}

0 commit comments

Comments
 (0)