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

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

module Test.Cardano.Ledger.Allegra.CDDL where

import Codec.CBOR.Cuddle.Huddle
import Data.Function (($))
import Test.Cardano.Ledger.Core.Binary.CDDL
import Test.Cardano.Ledger.Shelley.CDDL (
  bootstrap_witness,
  certificate,
  header,
  metadata_hash,
  set,
  transaction_index,
  transaction_input,
  transaction_metadatum,
  transaction_metadatum_label,
  transaction_output,
  update,
  vkeywitness,
  withdrawals,
 )

cddl :: Huddle
cddl :: Huddle
cddl = [Rule] -> Huddle
collectFrom [Rule
block, Rule
transaction]

--------------------------------------------------------------------------------
-- Things changed in Allegra
--------------------------------------------------------------------------------

native_script :: Rule
native_script :: Rule
native_script =
  forall a. Text -> Named a -> Named a
comment Text
"Timelock validity intervals are half-open intervals [a, b)." forall a b. (a -> b) -> a -> b
$
    Text
"native_script"
      forall a. IsType0 a => Text -> a -> Rule
=:= ArrayChoice -> ArrayChoice
arr [forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Named Group
script_pubkey]
      forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ ArrayChoice -> ArrayChoice
arr [forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Named Group
script_all]
      forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ ArrayChoice -> ArrayChoice
arr [forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Named Group
script_any]
      forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ ArrayChoice -> ArrayChoice
arr [forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Named Group
script_n_of_k]
      forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ ArrayChoice -> ArrayChoice
arr [forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Named Group
invalid_before]
      -- Timelock validity intervals are half-open intervals [a, b).
      -- This field specifies the left (included) endpoint a.
      forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ ArrayChoice -> ArrayChoice
arr [forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Named Group
invalid_hereafter]

-- Timelock validity intervals are half-open intervals [a, b).
-- This field specifies the right (excluded) endpoint b.

script_pubkey :: Named Group
script_pubkey :: Named Group
script_pubkey = Text
"script_pubkey" Text -> Group -> Named Group
=:~ Group -> Group
grp [Type0
0, forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Rule
addr_keyhash]

script_all :: Named Group
script_all :: Named Group
script_all = Text
"script_all" Text -> Group -> Named Group
=:~ Group -> Group
grp [Type0
1, forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a (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])]

script_any :: Named Group
script_any :: Named Group
script_any = Text
"script_any" Text -> Group -> Named Group
=:~ Group -> Group
grp [Type0
2, forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a (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])]

script_n_of_k :: Named Group
script_n_of_k :: Named Group
script_n_of_k =
  Text
"script_n_of_k"
    Text -> Group -> Named Group
=:~ Group -> Group
grp [Type0
3, Key
"n" forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
int64, forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a (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])]

invalid_before :: Named Group
invalid_before :: Named Group
invalid_before = Text
"invalid_before" Text -> Group -> Named Group
=:~ Group -> Group
grp [Type0
4, forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Value Int
VUInt]

invalid_hereafter :: Named Group
invalid_hereafter :: Named Group
invalid_hereafter = Text
"invalid_hereafter" Text -> Group -> Named Group
=:~ Group -> Group
grp [Type0
5, forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Value Int
VUInt]

transaction_witness_set :: Rule
transaction_witness_set :: Rule
transaction_witness_set =
  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]
      ]

auxiliary_data :: Rule
auxiliary_data :: Rule
auxiliary_data =
  Text
"auxiliary_data"
    forall a. IsType0 a => Text -> a -> Rule
=:= MapChoice -> Seal Map
smp
      [ Word64
0
          forall a. CanQuantify a => Word64 -> a -> a
<+ forall r. IsType0 r => r -> Key
asKey Rule
transaction_metadatum_label
          forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
transaction_metadatum
      ]
    forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ ArrayChoice -> Seal (Choice ArrayChoice)
sarr
      [ Key
"transaction_metadata"
          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_metadatum_label
                forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> Rule
transaction_metadatum
            ]
      , Key
"auxiliary_scripts" 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]
      ]

transaction_body :: Rule
transaction_body :: Rule
transaction_body =
  forall a. Text -> Named a -> Named a
comment
    Text
"Allegra transaction body adds the validity interval start at index 8"
    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
        , 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
metadata_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)
        ]

--------------------------------------------------------------------------------
-- Closure
--------------------------------------------------------------------------------

block :: Rule
block :: Rule
block =
  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]
      ]

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 (Rule
auxiliary_data forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ Value Void
VNil)
      ]