{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}

{-# HLINT ignore "Use camelCase" #-}
{-# HLINT ignore "Evaluate" #-}

module Test.Cardano.Ledger.Babbage.CDDL (
  module Test.Cardano.Ledger.Alonzo.CDDL,
  module Test.Cardano.Ledger.Babbage.CDDL,
) where

import Codec.CBOR.Cuddle.Huddle
import Data.Function (($))
import Data.Word (Word64)
import GHC.Num (Integer)
import Test.Cardano.Ledger.Alonzo.CDDL hiding (
  auxiliary_data,
  block,
  cost_models,
  header,
  header_body,
  language,
  major_protocol_version,
  multiasset,
  next_major_protocol_version,
  plutus_data,
  plutus_script,
  proposed_protocol_parameter_updates,
  protocol_param_update,
  protocol_version,
  script_data_hash,
  script_n_of_k,
  transaction,
  transaction_body,
  transaction_output,
  transaction_witness_set,
  update,
 )
import Text.Heredoc

babbageCDDL :: Huddle
babbageCDDL :: Huddle
babbageCDDL = [Rule] -> Huddle
collectFrom [Rule
block, Rule
transaction, Rule
kes_signature, Rule
language, Rule
signkeyKES]

block :: Rule
block :: Rule
block =
  forall a. Text -> Named a -> Named a
comment
    [str|Valid blocks must also satisfy the following two constraints:
        |  1) the length of transaction_bodies and transaction_witness_sets must be
        |     the same
        |  2) every transaction_index must be strictly smaller than the length of
        |     transaction_bodies
        |]
    forall a b. (a -> b) -> a -> b
$ Text
"block"
      forall a. IsType0 a => Text -> a -> Rule
=:= ArrayChoice -> ArrayChoice
arr
        [ forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Rule
header
        , Key
"transaction_bodies" forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> ArrayChoice -> ArrayChoice
arr [Word64
0 forall a. CanQuantify a => Word64 -> a -> a
<+ forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Rule
transaction_body]
        , Key
"transaction_witness_sets" forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> ArrayChoice -> ArrayChoice
arr [Word64
0 forall a. CanQuantify a => Word64 -> a -> a
<+ forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Rule
transaction_witness_set]
        , Key
"auxiliary_data_set" forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> MapChoice -> MapChoice
mp [Word64
0 forall a. CanQuantify a => Word64 -> a -> a
<+ forall r. IsType0 r => r -> Key
asKey Rule
transaction_index forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
auxiliary_data]
        , Key
"invalid_transactions" forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> ArrayChoice -> ArrayChoice
arr [Word64
0 forall a. CanQuantify a => Word64 -> a -> a
<+ forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Rule
transaction_index]
        ]

transaction :: Rule
transaction :: Rule
transaction =
  Text
"transaction"
    forall a. IsType0 a => Text -> a -> Rule
=:= ArrayChoice -> ArrayChoice
arr
      [ forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Rule
transaction_body
      , forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Rule
transaction_witness_set
      , forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Value Bool
VBool
      , forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a (Rule
auxiliary_data forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ Value Void
VNil)
      ]

header :: Rule
header :: Rule
header = Text
"header" forall a. IsType0 a => Text -> a -> Rule
=:= ArrayChoice -> ArrayChoice
arr [forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Rule
header_body, Key
"body_signature" forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
kes_signature]

header_body :: Rule
header_body :: Rule
header_body =
  forall a. Text -> Named a -> Named a
comment
    [str| block_body_size: merkle triple root
        |      vrf_result: NEW, replaces nonce_vrf and leader_vrf
        |]
    forall a b. (a -> b) -> a -> b
$ Text
"header_body"
      forall a. IsType0 a => Text -> a -> Rule
=:= ArrayChoice -> ArrayChoice
arr
        [ Key
"block_number" forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Value Int
VUInt
        , Key
"slot" forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Value Int
VUInt
        , Key
"prev_hash" forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> (Rule
hash32 forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ Value Void
VNil)
        , Key
"issuer_vkey" forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
vkey
        , Key
"vrf_vkey" forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
vrf_vkey
        , Key
"vrf_result" forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
vrf_cert
        , Key
"block_body_size" forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Value Int
VUInt
        , Key
"block_body_hash" forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
hash32
        , forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Named Group
operational_cert
        , forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Rule
protocol_version
        ]

-- TODO Replace with the following once
-- https://github.com/input-output-hk/cuddle/issues/29 is addressed in cuddle.
--
-- next_major_protocol_version :: Rule
-- next_major_protocol_version = "next_major_protocol_version" =:= (7 :: Integer)
next_major_protocol_version :: Integer
next_major_protocol_version :: Integer
next_major_protocol_version = Integer
9

major_protocol_version :: Rule
major_protocol_version :: Rule
major_protocol_version = Text
"major_protocol_version" forall a. IsType0 a => Text -> a -> Rule
=:= (Integer
1 :: Integer) Integer -> Integer -> Ranged
... Integer
next_major_protocol_version

protocol_version :: Rule
protocol_version :: Rule
protocol_version = Text
"protocol_version" forall a. IsType0 a => Text -> a -> Rule
=:= ArrayChoice -> ArrayChoice
arr [forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Rule
major_protocol_version, forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Value Int
VUInt]

transaction_body :: Rule
transaction_body :: Rule
transaction_body =
  forall a. Text -> Named a -> Named a
comment
    [str| 2: fee
        | 3: time to live
        | 8: validity interval start
        |13: collateral inputs
        |NEW:
        |  16: collateral return
        |  17: total collateral
        |  18: reference inputs
        |]
    forall a b. (a -> b) -> a -> b
$ Text
"transaction_body"
      forall a. IsType0 a => Text -> a -> Rule
=:= MapChoice -> MapChoice
mp
        [ Word64 -> Key
idx Word64
0 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> forall t0. IsType0 t0 => t0 -> GRuleCall
set Rule
transaction_input
        , Word64 -> Key
idx Word64
1 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> ArrayChoice -> ArrayChoice
arr [Word64
0 forall a. CanQuantify a => Word64 -> a -> a
<+ forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Rule
transaction_output]
        , Word64 -> Key
idx Word64
2 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
coin
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
3 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Value Int
VUInt)
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
4 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> ArrayChoice -> ArrayChoice
arr [Word64
0 forall a. CanQuantify a => Word64 -> a -> a
<+ forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Rule
certificate])
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
5 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
withdrawals)
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
6 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
update)
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
7 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
auxiliary_data_hash)
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
8 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Value Int
VUInt)
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
9 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
mint)
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
11 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
script_data_hash)
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
13 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> forall t0. IsType0 t0 => t0 -> GRuleCall
set Rule
transaction_input)
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
14 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
required_signers)
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
15 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
network_id)
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
16 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
transaction_output)
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
17 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
coin)
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
18 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> forall t0. IsType0 t0 => t0 -> GRuleCall
set Rule
transaction_input)
        ]

-- TODO: Allow for adding to the comments of a Rule in order to not have to
-- redefine them in the subsequent eras.
script_data_hash :: Rule
script_data_hash :: Rule
script_data_hash =
  forall a. Text -> Named a -> Named a
comment
    [str|This is a hash of data which may affect evaluation of a script.
        |This data consists of:
        |  - The redeemers from the transaction_witness_set (the value of field 5).
        |  - The datums from the transaction_witness_set (the value of field 4).
        |  - The value in the costmdls map corresponding to the script's language
        |    (in field 18 of protocol_param_update.)
        |(In the future it may contain additional protocol parameters.)
        |
        |Since this data does not exist in contiguous form inside a transaction, it needs
        |to be independently constructed by each recipient.
        |
        |The bytestring which is hashed is the concatenation of three things:
        |  redeemers || datums || language views
        |The redeemers are exactly the data present in the transaction witness set.
        |Similarly for the datums, if present. If no datums are provided, the middle
        |field is omitted (i.e. it is the empty/null bytestring).
        |
        |language views CDDL:
        |{ * language => script_integrity_data }
        |
        |This must be encoded canonically, using the same scheme as in
        |RFC7049 section 3.9:
        | - Maps, strings, and bytestrings must use a definite-length encoding
        | - Integers must be as small as possible.
        | - The expressions for map length, string length, and bytestring length
        |   must be as short as possible.
        | - The keys in the map must be sorted as follows:
        |    -  If two keys have different lengths, the shorter one sorts earlier.
        |    -  If two keys have the same length, the one with the lower value
        |       in (byte-wise) lexical order sorts earlier.
        |
        |For PlutusV1 (language id 0), the language view is the following:
        |  - the value of costmdls map at key 0 (in other words, the script_integrity_data)
        |    is encoded as an indefinite length list and the result is encoded as a bytestring.
        |    (our apologies)
        |    For example, the script_integrity_data corresponding to the all zero costmodel for V1
        |    would be encoded as (in hex):
        |    58a89f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ff
        |  - the language ID tag is also encoded twice. first as a uint then as
        |    a bytestring. (our apologies)
        |    Concretely, this means that the language version for V1 is encoded as
        |    4100 in hex.
        |For PlutusV2 (language id 1), the language view is the following:
        |  - the value of costmdls map at key 1 is encoded as an definite length list.
        |    For example, the script_integrity_data corresponding to the all zero costmodel for V2
        |    would be encoded as (in hex):
        |    98af0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
        |  - the language ID tag is encoded as expected.
        |    Concretely, this means that the language version for V2 is encoded as
        |    01 in hex.
        |
        |Note that each Plutus language represented inside a transaction must have
        |a cost model in the costmdls protocol parameter in order to execute,
        |regardless of what the script integrity data is.
        |
        |Finally, note that in the case that a transaction includes datums but does not
        |include the redeemers field, the script data format becomes (in hex):
        |[ 80 | datums | A0 ]
        |corresponding to a CBOR empty list and an empty map.
        |Note that a transaction might include the redeemers field and set it to the
        |empty map, in which case the user supplied encoding of the empty map is used.
        |]
    forall a b. (a -> b) -> a -> b
$ Text
"script_data_hash" forall a. IsType0 a => Text -> a -> Rule
=:= Rule
hash32

transaction_output :: Rule
transaction_output :: Rule
transaction_output =
  forall a. Text -> Named a -> Named a
comment
    [str|Both of the Alonzo and Babbage style TxOut formats are equally valid
        |and can be used interchangeably.
        |NEW:
        |  babbage_transaction_output
        |]
    forall a b. (a -> b) -> a -> b
$ Text
"transaction_output"
      forall a. IsType0 a => Text -> a -> Rule
=:= Rule
shelley_transaction_output
      forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ Rule
babbage_transaction_output

-- TODO: Make it possible to override names in Cuddle to obviate the need for
-- this redefinition here.
shelley_transaction_output :: Rule
shelley_transaction_output :: Rule
shelley_transaction_output =
  Text
"shelley_transaction_output"
    forall a. IsType0 a => Text -> a -> Rule
=:= ArrayChoice -> ArrayChoice
arr [forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Rule
address, Key
"amount" forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
value, forall a. CanQuantify a => a -> a
opt (Key
"datum_hash" forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
hash32)]

babbage_transaction_output :: Rule
babbage_transaction_output :: Rule
babbage_transaction_output =
  forall a. Text -> Named a -> Named a
comment
    [str|NEW
        |  datum_option
        |  script_ref
        |]
    forall a b. (a -> b) -> a -> b
$ Text
"babbage_transaction_output"
      forall a. IsType0 a => Text -> a -> Rule
=:= MapChoice -> MapChoice
mp
        [ Word64 -> Key
idx Word64
0 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
address
        , Word64 -> Key
idx Word64
1 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
value
        , forall a. CanQuantify a => a -> a
opt forall a b. (a -> b) -> a -> b
$ Word64 -> Key
idx Word64
2 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
datum_option
        , forall a. CanQuantify a => a -> a
opt forall a b. (a -> b) -> a -> b
$ Word64 -> Key
idx Word64
3 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
script_ref
        ]

transaction_witness_set :: Rule
transaction_witness_set :: Rule
transaction_witness_set =
  forall a. Text -> Named a -> Named a
comment
    [str|
        |NEW:
        |  6: [* plutus_v2_script]
        |]
    forall a b. (a -> b) -> a -> b
$ Text
"transaction_witness_set"
      forall a. IsType0 a => Text -> a -> Rule
=:= MapChoice -> MapChoice
mp
        [ forall a. CanQuantify a => a -> a
opt forall a b. (a -> b) -> a -> b
$ Word64 -> Key
idx Word64
0 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> ArrayChoice -> ArrayChoice
arr [Word64
0 forall a. CanQuantify a => Word64 -> a -> a
<+ forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Rule
vkeywitness]
        , forall a. CanQuantify a => a -> a
opt forall a b. (a -> b) -> a -> b
$ Word64 -> Key
idx Word64
1 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> ArrayChoice -> ArrayChoice
arr [Word64
0 forall a. CanQuantify a => Word64 -> a -> a
<+ forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Rule
native_script]
        , forall a. CanQuantify a => a -> a
opt forall a b. (a -> b) -> a -> b
$ Word64 -> Key
idx Word64
2 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> ArrayChoice -> ArrayChoice
arr [Word64
0 forall a. CanQuantify a => Word64 -> a -> a
<+ forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Rule
bootstrap_witness]
        , forall a. CanQuantify a => a -> a
opt forall a b. (a -> b) -> a -> b
$ Word64 -> Key
idx Word64
3 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> ArrayChoice -> ArrayChoice
arr [Word64
0 forall a. CanQuantify a => Word64 -> a -> a
<+ forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Rule
plutus_v1_script]
        , forall a. CanQuantify a => a -> a
opt forall a b. (a -> b) -> a -> b
$ Word64 -> Key
idx Word64
4 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> ArrayChoice -> ArrayChoice
arr [Word64
0 forall a. CanQuantify a => Word64 -> a -> a
<+ forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Rule
plutus_data]
        , forall a. CanQuantify a => a -> a
opt forall a b. (a -> b) -> a -> b
$ Word64 -> Key
idx Word64
5 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
redeemers
        , forall a. CanQuantify a => a -> a
opt forall a b. (a -> b) -> a -> b
$ Word64 -> Key
idx Word64
6 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> ArrayChoice -> ArrayChoice
arr [Word64
0 forall a. CanQuantify a => Word64 -> a -> a
<+ forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Rule
plutus_v2_script]
        ]

-- TODO Allow to override the comment in addition to extending it.
plutus_data :: Rule
plutus_data :: Rule
plutus_data =
  Text
"plutus_data"
    forall a. IsType0 a => Text -> a -> Rule
=:= forall t0. IsType0 t0 => t0 -> GRuleCall
constr Rule
plutus_data
    forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ MapChoice -> Seal Map
smp [Word64
0 forall a. CanQuantify a => Word64 -> a -> a
<+ forall r. IsType0 r => r -> Key
asKey Rule
plutus_data forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
plutus_data]
    forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ ArrayChoice -> Seal Array
sarr [Word64
0 forall a. CanQuantify a => Word64 -> a -> a
<+ forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Rule
plutus_data]
    forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ Rule
big_int
    forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ Rule
bounded_bytes

plutus_v1_script :: Rule
plutus_v1_script :: Rule
plutus_v1_script = Text
"plutus_v1_script" forall a. IsType0 a => Text -> a -> Rule
=:= Value ByteString
VBytes

plutus_v2_script :: Rule
plutus_v2_script :: Rule
plutus_v2_script = Text
"plutus_v2_script" forall a. IsType0 a => Text -> a -> Rule
=:= Value ByteString
VBytes

language :: Rule
language :: Rule
language =
  forall a. Text -> Named a -> Named a
comment
    [str|0: Plutus v1
        |1: Plutus v2
        |]
    forall a b. (a -> b) -> a -> b
$ Text
"language" forall a. IsType0 a => Text -> a -> Rule
=:= Integer -> Literal
int Integer
0 forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ Integer -> Literal
int Integer
1

cost_models :: Rule
cost_models :: Rule
cost_models =
  forall a. Text -> Named a -> Named a
comment
    [str|0: Plutus v1
        |1: Plutus v2
        |]
    forall a b. (a -> b) -> a -> b
$ Text
"cost_models"
      forall a. IsType0 a => Text -> a -> Rule
=:= MapChoice -> MapChoice
mp
        [ forall a. CanQuantify a => a -> a
opt forall a b. (a -> b) -> a -> b
$ Word64 -> Key
idx Word64
0 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> ArrayChoice -> ArrayChoice
arr [Word64
166 forall a. CanQuantify a => Word64 -> a -> a
<+ forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Rule
int64 forall a. CanQuantify a => a -> Word64 -> a
+> Word64
166]
        , forall a. CanQuantify a => a -> a
opt forall a b. (a -> b) -> a -> b
$ Word64 -> Key
idx Word64
1 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> ArrayChoice -> ArrayChoice
arr [Word64
175 forall a. CanQuantify a => Word64 -> a -> a
<+ forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Rule
int64 forall a. CanQuantify a => a -> Word64 -> a
+> Word64
175]
        ]

auxiliary_data :: Rule
auxiliary_data :: Rule
auxiliary_data =
  forall a. Text -> Named a -> Named a
comment
    [str|              metadata: shelley
        |  transaction_metadata: shelley-ma
        |#6.259(0 ==> metadata): alonzo onwards
        |NEW:
        |  3: [* plutus_v2_script]
        |]
    forall a b. (a -> b) -> a -> b
$ Text
"auxiliary_data"
      forall a. IsType0 a => Text -> a -> Rule
=:= Rule
metadata
      forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ ArrayChoice -> Seal Array
sarr
        [ Key
"transaction_metadata" forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
metadata
        , Key
"auxiliary_scripts" forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
auxiliary_scripts
        ]
      forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ forall a. Word64 -> a -> Tagged a
tag
        Word64
259
        ( MapChoice -> MapChoice
mp
            [ forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
0 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
metadata)
            , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
1 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> ArrayChoice -> ArrayChoice
arr [Word64
0 forall a. CanQuantify a => Word64 -> a -> a
<+ forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Rule
native_script])
            , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
2 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> ArrayChoice -> ArrayChoice
arr [Word64
0 forall a. CanQuantify a => Word64 -> a -> a
<+ forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Rule
plutus_v1_script])
            , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
3 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> ArrayChoice -> ArrayChoice
arr [Word64
0 forall a. CanQuantify a => Word64 -> a -> a
<+ forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Rule
plutus_v2_script])
            ]
        )

data' :: Rule
data' :: Rule
data' = Text
"data" forall a. IsType0 a => Text -> a -> Rule
=:= forall a. Word64 -> a -> Tagged a
tag Word64
24 (Value ByteString
VBytes Value ByteString -> Rule -> Constrained
`cbor` Rule
plutus_data)

datum_option :: Rule
datum_option :: Rule
datum_option = Text
"datum_option" forall a. IsType0 a => Text -> a -> Rule
=:= ArrayChoice -> ArrayChoice
arr [ArrayEntry
0, forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Rule
hash32] forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ ArrayChoice -> ArrayChoice
arr [ArrayEntry
1, forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Rule
data']

script_ref :: Rule
script_ref :: Rule
script_ref = Text
"script_ref" forall a. IsType0 a => Text -> a -> Rule
=:= forall a. Word64 -> a -> Tagged a
tag Word64
24 (Value ByteString
VBytes Value ByteString -> Rule -> Constrained
`cbor` Rule
script)

script :: Rule
script :: Rule
script =
  Text
"script"
    forall a. IsType0 a => Text -> a -> Rule
=:= ArrayChoice -> ArrayChoice
arr [ArrayEntry
0, forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Rule
native_script]
    forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ ArrayChoice -> ArrayChoice
arr [ArrayEntry
1, forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Rule
plutus_v1_script]
    forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ ArrayChoice -> ArrayChoice
arr [ArrayEntry
2, forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Rule
plutus_v2_script]

protocol_param_update :: Rule
protocol_param_update :: Rule
protocol_param_update =
  forall a. Text -> Named a -> Named a
comment
    [str| 0: minfee A
        | 1: minfee B
        | 2: max block body size
        | 3: max transaction size
        | 4: max block header size
        | 5: key deposit
        | 6: pool deposit
        | 7: maximum epoch
        | 8: n_opt: desired number of stake pools
        | 9: pool pledge influence
        |10: expansion rate
        |11: treasury growth rate
        |14: protocol version
        |16: min pool cost
        |17: ada per utxo byte
        |18: cost models for script languages
        |19: execution costs
        |20: max tx ex units
        |21: max block ex units
        |22: max value size
        |23: collateral percentage
        |24: max collateral inputs
        |]
    forall a b. (a -> b) -> a -> b
$ Text
"protocol_param_update"
      forall a. IsType0 a => Text -> a -> Rule
=:= MapChoice -> MapChoice
mp
        [ forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
0 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Value Int
VUInt)
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
1 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Value Int
VUInt)
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
2 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> (Value Int
VUInt forall a s. (IsSizeable a, IsSize s) => Value a -> s -> Constrained
`sized` (Word64
4 :: Word64)))
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
3 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> (Value Int
VUInt forall a s. (IsSizeable a, IsSize s) => Value a -> s -> Constrained
`sized` (Word64
4 :: Word64)))
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
4 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> (Value Int
VUInt forall a s. (IsSizeable a, IsSize s) => Value a -> s -> Constrained
`sized` (Word64
2 :: Word64)))
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
5 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
coin)
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
6 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
coin)
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
7 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
epoch)
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
8 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Value Int
VUInt forall a s. (IsSizeable a, IsSize s) => Value a -> s -> Constrained
`sized` (Word64
2 :: Word64))
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
9 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
nonnegative_interval)
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
10 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
unit_interval)
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
11 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
unit_interval)
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
14 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
protocol_version)
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
16 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
coin)
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
17 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
coin)
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
18 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
cost_models)
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
19 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
ex_unit_prices)
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
20 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
ex_units)
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
21 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
ex_units)
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
22 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Value Int
VUInt)
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
23 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Value Int
VUInt)
        , forall a. CanQuantify a => a -> a
opt (Word64 -> Key
idx Word64
24 forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Value Int
VUInt)
        ]

proposed_protocol_parameter_updates :: Rule
proposed_protocol_parameter_updates :: Rule
proposed_protocol_parameter_updates =
  Text
"proposed_protocol_parameter_updates"
    forall a. IsType0 a => Text -> a -> Rule
=:= MapChoice -> MapChoice
mp [Word64
0 forall a. CanQuantify a => Word64 -> a -> a
<+ forall r. IsType0 r => r -> Key
asKey Rule
genesis_hash forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
protocol_param_update]

update :: Rule
update :: Rule
update = Text
"update" forall a. IsType0 a => Text -> a -> Rule
=:= ArrayChoice -> ArrayChoice
arr [forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Rule
proposed_protocol_parameter_updates, forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Rule
epoch]