{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MonoLocalBinds #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Cardano.Ledger.Core.HuddleSpec where

import Cardano.Ledger.BaseTypes (getVersion)
import Cardano.Ledger.Core (ByronEra, eraProtVerHigh, eraProtVerLow)
import Cardano.Ledger.Huddle
import Codec.CBOR.Cuddle.Huddle
import Data.Proxy (Proxy (..))
import qualified Data.Text as T
import Data.Word (Word64)
import Text.Heredoc
import Prelude hiding ((/))

instance Era era => HuddleRule "hash28" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
_ = Text
"hash28" Text -> Constrained -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= Value ByteString
VBytes Value ByteString -> Word64 -> Constrained
forall c a s.
(IsSizeable a, IsSize s, IsConstrainable c a) =>
c -> s -> Constrained
`sized` (Word64
28 :: Word64)

instance Era era => HuddleRule "hash32" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
_ = Text
"hash32" Text -> Constrained -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= Value ByteString
VBytes Value ByteString -> Word64 -> Constrained
forall c a s.
(IsSizeable a, IsSize s, IsConstrainable c a) =>
c -> s -> Constrained
`sized` (Word64
32 :: Word64)

instance Era era => HuddleRule "max_word64" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
_ = Text
"max_word64" Text -> Integer -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= (Integer
18446744073709551615 :: Integer)

instance Era era => HuddleRule "positive_int" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
p = Text
"positive_int" Text -> Ranged -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= (Integer
1 :: Integer) Integer -> Rule -> Ranged
forall a b. (IsRangeBound a, IsRangeBound b) => a -> b -> Ranged
... forall (name :: Symbol) era.
HuddleRule name era =>
Proxy era -> Rule
huddleRule @"max_word64" Proxy era
p

instance Era era => HuddleRule "max_word32" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
_ = Text
"max_word32" Text -> Integer -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= (Integer
4294967295 :: Integer)

instance Era era => HuddleRule "positive_word32" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
p = Text
"positive_word32" Text -> Ranged -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= (Integer
1 :: Integer) Integer -> Rule -> Ranged
forall a b. (IsRangeBound a, IsRangeBound b) => a -> b -> Ranged
... forall (name :: Symbol) era.
HuddleRule name era =>
Proxy era -> Rule
huddleRule @"max_word32" Proxy era
p

instance Era era => HuddleRule "unit_interval" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
_ =
    Text -> Rule -> Rule
forall a. HasField' "description" a (Maybe Text) => Text -> a -> a
comment
      Text
[str|The real unit_interval is: #6.30([uint, uint])
          |
          |A unit interval is a number in the range between 0 and 1, which
          |means there are two extra constraints:
          |  1. numerator <= denominator
          |  2. denominator > 0
          |
          |The relation between numerator and denominator can be
          |expressed in CDDL, but we have a limitation currently
          |(see: https://github.com/input-output-hk/cuddle/issues/30)
          |which poses a problem for testing. We need to be able to
          |generate random valid data for testing implementation of
          |our encoders/decoders. Which means we cannot use the actual
          |definition here and we hard code the value to 1/2
          |]
      (Rule -> Rule) -> Rule -> Rule
forall a b. (a -> b) -> a -> b
$ Text
"unit_interval"
        Text -> Tagged ArrayChoice -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= Word64 -> ArrayChoice -> Tagged ArrayChoice
forall a. Word64 -> a -> Tagged a
tag Word64
30 (ArrayChoice -> ArrayChoice
arr [Item ArrayChoice
ArrayEntry
1, Item ArrayChoice
ArrayEntry
2])

instance Era era => HuddleRule "nonnegative_interval" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
p =
    Text
"nonnegative_interval" Text -> Tagged ArrayChoice -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= Word64 -> ArrayChoice -> Tagged ArrayChoice
forall a. Word64 -> a -> Tagged a
tag Word64
30 (ArrayChoice -> ArrayChoice
arr [Value Int -> ArrayEntry
forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Value Int
VUInt, Rule -> ArrayEntry
forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a (forall (name :: Symbol) era.
HuddleRule name era =>
Proxy era -> Rule
huddleRule @"positive_int" Proxy era
p)])

distinct :: IsSizeable s => Value s -> HuddleItem
distinct :: forall s. IsSizeable s => Value s -> HuddleItem
distinct Value s
x =
  Rule -> HuddleItem
HIRule
    (Rule -> HuddleItem) -> Rule -> HuddleItem
forall a b. (a -> b) -> a -> b
$ Text -> Rule -> Rule
forall a. HasField' "description" a (Maybe Text) => Text -> a -> a
comment
      Text
[str|A type for distinct values.
          |The type parameter must support .size, for example: bytes or uint
          |]
    (Rule -> Rule) -> Rule -> Rule
forall a b. (a -> b) -> a -> b
$ Text
"distinct_"
      Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Value s -> Text
forall s. Value s -> Text
show' Value s
x
        Text -> Choice Type2 -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= (Value s
x Value s -> Word64 -> Constrained
forall c a s.
(IsSizeable a, IsSize s, IsConstrainable c a) =>
c -> s -> Constrained
`sized` (Word64
8 :: Word64))
        Constrained -> Constrained -> Choice Type2
forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ (Value s
x Value s -> Word64 -> Constrained
forall c a s.
(IsSizeable a, IsSize s, IsConstrainable c a) =>
c -> s -> Constrained
`sized` (Word64
16 :: Word64))
        Choice Type2 -> Constrained -> Choice Type2
forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ (Value s
x Value s -> Word64 -> Constrained
forall c a s.
(IsSizeable a, IsSize s, IsConstrainable c a) =>
c -> s -> Constrained
`sized` (Word64
20 :: Word64))
        Choice Type2 -> Constrained -> Choice Type2
forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ (Value s
x Value s -> Word64 -> Constrained
forall c a s.
(IsSizeable a, IsSize s, IsConstrainable c a) =>
c -> s -> Constrained
`sized` (Word64
24 :: Word64))
        Choice Type2 -> Constrained -> Choice Type2
forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ (Value s
x Value s -> Word64 -> Constrained
forall c a s.
(IsSizeable a, IsSize s, IsConstrainable c a) =>
c -> s -> Constrained
`sized` (Word64
30 :: Word64))
        Choice Type2 -> Constrained -> Choice Type2
forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ (Value s
x Value s -> Word64 -> Constrained
forall c a s.
(IsSizeable a, IsSize s, IsConstrainable c a) =>
c -> s -> Constrained
`sized` (Word64
32 :: Word64))
  where
    show' :: Value s -> T.Text
    show' :: forall s. Value s -> Text
show' = \case
      Value s
VBytes -> String -> Text
T.pack String
"bytes"
      Value s
VUInt -> String -> Text
T.pack String
"uint"
      Value s
_ -> String -> Text
forall a. HasCallStack => String -> a
error String
"Unsupported Value for `distinct`"

instance Era era => HuddleRule "nonce" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
p = Text
"nonce" Text -> Choice ArrayChoice -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= ArrayChoice -> ArrayChoice
arr [Item ArrayChoice
ArrayEntry
0] ArrayChoice -> ArrayChoice -> Choice ArrayChoice
forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ ArrayChoice -> ArrayChoice
arr [Item ArrayChoice
ArrayEntry
1, Rule -> ArrayEntry
forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a (forall (name :: Symbol) era.
HuddleRule name era =>
Proxy era -> Rule
huddleRule @"hash32" Proxy era
p)]

instance Era era => HuddleRule "epoch" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
_ = Text
"epoch" Text -> Constrained -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= Value Int
VUInt Value Int -> Word64 -> Constrained
forall c a s.
(IsSizeable a, IsSize s, IsConstrainable c a) =>
c -> s -> Constrained
`sized` (Word64
8 :: Word64)

instance Era era => HuddleRule "epoch_interval" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
_ = Text
"epoch_interval" Text -> Constrained -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= Value Int
VUInt Value Int -> Word64 -> Constrained
forall c a s.
(IsSizeable a, IsSize s, IsConstrainable c a) =>
c -> s -> Constrained
`sized` (Word64
4 :: Word64)

instance Era era => HuddleRule "slot" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
_ = Text
"slot" Text -> Constrained -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= Value Int
VUInt Value Int -> Word64 -> Constrained
forall c a s.
(IsSizeable a, IsSize s, IsConstrainable c a) =>
c -> s -> Constrained
`sized` (Word64
8 :: Word64)

instance Era era => HuddleRule "block_number" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
_ = Text
"block_number" Text -> Constrained -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= Value Int
VUInt Value Int -> Word64 -> Constrained
forall c a s.
(IsSizeable a, IsSize s, IsConstrainable c a) =>
c -> s -> Constrained
`sized` (Word64
8 :: Word64)

instance Era era => HuddleRule "addr_keyhash" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
p = Text
"addr_keyhash" Text -> Rule -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= forall (name :: Symbol) era.
HuddleRule name era =>
Proxy era -> Rule
huddleRule @"hash28" Proxy era
p

instance Era era => HuddleRule "pool_keyhash" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
p = Text
"pool_keyhash" Text -> Rule -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= forall (name :: Symbol) era.
HuddleRule name era =>
Proxy era -> Rule
huddleRule @"hash28" Proxy era
p

instance Era era => HuddleRule "vrf_keyhash" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
p = Text
"vrf_keyhash" Text -> Rule -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= forall (name :: Symbol) era.
HuddleRule name era =>
Proxy era -> Rule
huddleRule @"hash32" Proxy era
p

instance Era era => HuddleRule "vkey" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
_ = Text
"vkey" Text -> Constrained -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= Value ByteString
VBytes Value ByteString -> Word64 -> Constrained
forall c a s.
(IsSizeable a, IsSize s, IsConstrainable c a) =>
c -> s -> Constrained
`sized` (Word64
32 :: Word64)

instance Era era => HuddleRule "vrf_vkey" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
_ = Text
"vrf_vkey" Text -> Constrained -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= Value ByteString
VBytes Value ByteString -> Word64 -> Constrained
forall c a s.
(IsSizeable a, IsSize s, IsConstrainable c a) =>
c -> s -> Constrained
`sized` (Word64
32 :: Word64)

instance Era era => HuddleRule "vrf_cert" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
_ = Text
"vrf_cert" Text -> ArrayChoice -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= ArrayChoice -> ArrayChoice
arr [Value ByteString -> ArrayEntry
forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a Value ByteString
VBytes, Constrained -> ArrayEntry
forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a (Value ByteString
VBytes Value ByteString -> Word64 -> Constrained
forall c a s.
(IsSizeable a, IsSize s, IsConstrainable c a) =>
c -> s -> Constrained
`sized` (Word64
80 :: Word64))]

instance Era era => HuddleRule "kes_vkey" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
_ = Text
"kes_vkey" Text -> Constrained -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= Value ByteString
VBytes Value ByteString -> Word64 -> Constrained
forall c a s.
(IsSizeable a, IsSize s, IsConstrainable c a) =>
c -> s -> Constrained
`sized` (Word64
32 :: Word64)

instance Era era => HuddleRule "kes_signature" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
_ = Text
"kes_signature" Text -> Constrained -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= Value ByteString
VBytes Value ByteString -> Word64 -> Constrained
forall c a s.
(IsSizeable a, IsSize s, IsConstrainable c a) =>
c -> s -> Constrained
`sized` (Word64
448 :: Word64)

instance Era era => HuddleRule "signkey_kes" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
_ = Text
"signkey_kes" Text -> Constrained -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= Value ByteString
VBytes Value ByteString -> Word64 -> Constrained
forall c a s.
(IsSizeable a, IsSize s, IsConstrainable c a) =>
c -> s -> Constrained
`sized` (Word64
64 :: Word64)

instance Era era => HuddleRule "sequence_number" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
_ = Text
"sequence_number" Text -> Constrained -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= Value Int
VUInt Value Int -> Word64 -> Constrained
forall c a s.
(IsSizeable a, IsSize s, IsConstrainable c a) =>
c -> s -> Constrained
`sized` (Word64
8 :: Word64)

instance Era era => HuddleRule "kes_period" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
_ = Text
"kes_period" Text -> Constrained -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= Value Int
VUInt Value Int -> Word64 -> Constrained
forall c a s.
(IsSizeable a, IsSize s, IsConstrainable c a) =>
c -> s -> Constrained
`sized` (Word64
8 :: Word64)

instance Era era => HuddleRule "signature" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
_ = Text
"signature" Text -> Constrained -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= Value ByteString
VBytes Value ByteString -> Word64 -> Constrained
forall c a s.
(IsSizeable a, IsSize s, IsConstrainable c a) =>
c -> s -> Constrained
`sized` (Word64
64 :: Word64)

instance Era era => HuddleRule "coin" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
_ = Text
"coin" Text -> Value Int -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= Value Int
VUInt

instance Era era => HuddleRule "positive_coin" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
p = Text
"positive_coin" Text -> Ranged -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= (Integer
1 :: Integer) Integer -> Rule -> Ranged
forall a b. (IsRangeBound a, IsRangeBound b) => a -> b -> Ranged
... forall (name :: Symbol) era.
HuddleRule name era =>
Proxy era -> Rule
huddleRule @"max_word64" Proxy era
p

instance Era era => HuddleRule "address" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
_ =
    Text -> Rule -> Rule
forall a. HasField' "description" a (Maybe Text) => Text -> a -> a
comment
      Text
[str|address = bytes
          |
          |address format:
          |  [ 8 bit header | payload ];
          |
          |shelley payment addresses:
          |     bit 7: 0
          |     bit 6: base/other
          |     bit 5: pointer/enterprise [for base: stake cred is keyhash/scripthash]
          |     bit 4: payment cred is keyhash/scripthash
          |  bits 3-0: network id
          |
          |reward addresses:
          |  bits 7-5: 111
          |     bit 4: credential is keyhash/scripthash
          |  bits 3-0: network id
          |
          |byron addresses:
          |  bits 7-4: 1000
          |
          |     0000: base address: keyhash28,keyhash28
          |     0001: base address: scripthash28,keyhash28
          |     0010: base address: keyhash28,scripthash28
          |     0011: base address: scripthash28,scripthash28
          |     0100: pointer address: keyhash28, 3 variable length uint
          |     0101: pointer address: scripthash28, 3 variable length uint
          |     0110: enterprise address: keyhash28
          |     0111: enterprise address: scripthash28
          |     1000: byron address
          |     1110: reward account: keyhash28
          |     1111: reward account: scripthash28
          |1001-1101: future formats
          |]
      (Rule -> Rule) -> Rule -> Rule
forall a b. (a -> b) -> a -> b
$ Text
"address"
        Text -> Choice Type2 -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= ByteString -> Literal
bstr
          ByteString
"001000000000000000000000000000000000000000000000000000000011000000000000000000000000000000000000000000000000000000"
        Literal -> Literal -> Choice Type2
forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ ByteString -> Literal
bstr
          ByteString
"102000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000"
        Choice Type2 -> Literal -> Choice Type2
forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ ByteString -> Literal
bstr
          ByteString
"203000000000000000000000000000000000000000000000000000000033000000000000000000000000000000000000000000000000000000"
        Choice Type2 -> Literal -> Choice Type2
forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ ByteString -> Literal
bstr
          ByteString
"304000000000000000000000000000000000000000000000000000000044000000000000000000000000000000000000000000000000000000"
        Choice Type2 -> Literal -> Choice Type2
forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ ByteString -> Literal
bstr ByteString
"405000000000000000000000000000000000000000000000000000000087680203"
        Choice Type2 -> Literal -> Choice Type2
forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ ByteString -> Literal
bstr ByteString
"506000000000000000000000000000000000000000000000000000000087680203"
        Choice Type2 -> Literal -> Choice Type2
forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ ByteString -> Literal
bstr ByteString
"6070000000000000000000000000000000000000000000000000000000"
        Choice Type2 -> Literal -> Choice Type2
forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ ByteString -> Literal
bstr ByteString
"7080000000000000000000000000000000000000000000000000000000"

instance Era era => HuddleRule "reward_account" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
_ =
    Text -> Rule -> Rule
forall a. HasField' "description" a (Maybe Text) => Text -> a -> a
comment
      Text
"reward_account = bytes"
      (Rule -> Rule) -> Rule -> Rule
forall a b. (a -> b) -> a -> b
$ Text
"reward_account"
        Text -> Choice Type2 -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= ByteString -> Literal
bstr ByteString
"E090000000000000000000000000000000000000000000000000000000"
        Literal -> Literal -> Choice Type2
forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ ByteString -> Literal
bstr ByteString
"F0A0000000000000000000000000000000000000000000000000000000"

instance Era era => HuddleRule "transaction_index" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
_ = Text
"transaction_index" Text -> Constrained -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= Value Int
VUInt Value Int -> Word64 -> Constrained
forall c a s.
(IsSizeable a, IsSize s, IsConstrainable c a) =>
c -> s -> Constrained
`sized` (Word64
2 :: Word64)

instance Era era => HuddleRule "metadatum_label" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
_ = Text
"metadatum_label" Text -> Constrained -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= Value Int
VUInt Value Int -> Word64 -> Constrained
forall c a s.
(IsSizeable a, IsSize s, IsConstrainable c a) =>
c -> s -> Constrained
`sized` (Word64
8 :: Word64)

instance Era era => HuddleRule "metadatum" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
p =
    Text
"metadatum"
      Text -> Choice Type2 -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= MapChoice -> Seal Map
smp
        [ Word64
0 Word64 -> MapEntry -> MapEntry
forall a. CanQuantify a => Word64 -> a -> a
<+ Rule -> Key
forall r. IsType0 r => r -> Key
asKey (forall (name :: Symbol) era.
HuddleRule name era =>
Proxy era -> Rule
huddleRule @"metadatum" Proxy era
p) Key -> Rule -> MapEntry
forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> forall (name :: Symbol) era.
HuddleRule name era =>
Proxy era -> Rule
huddleRule @"metadatum" Proxy era
p
        ]
      Seal Map -> Seal (Choice ArrayChoice) -> Choice Type2
forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ ArrayChoice -> Seal (Choice ArrayChoice)
sarr [Word64
0 Word64 -> ArrayEntry -> ArrayEntry
forall a. CanQuantify a => Word64 -> a -> a
<+ Rule -> ArrayEntry
forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a (forall (name :: Symbol) era.
HuddleRule name era =>
Proxy era -> Rule
huddleRule @"metadatum" Proxy era
p)]
      Choice Type2 -> Value Int -> Choice Type2
forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ Value Int
VInt
      Choice Type2 -> Constrained -> Choice Type2
forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ (Value ByteString
VBytes Value ByteString -> (Word64, Word64) -> Constrained
forall c a s.
(IsSizeable a, IsSize s, IsConstrainable c a) =>
c -> s -> Constrained
`sized` (Word64
0 :: Word64, Word64
64 :: Word64))
      Choice Type2 -> Constrained -> Choice Type2
forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ (Value Text
VText Value Text -> (Word64, Word64) -> Constrained
forall c a s.
(IsSizeable a, IsSize s, IsConstrainable c a) =>
c -> s -> Constrained
`sized` (Word64
0 :: Word64, Word64
64 :: Word64))

instance Era era => HuddleRule "metadata" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
p =
    Text
"metadata"
      Text -> MapChoice -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= MapChoice -> MapChoice
mp
        [ Word64
0
            Word64 -> MapEntry -> MapEntry
forall a. CanQuantify a => Word64 -> a -> a
<+ Rule -> Key
forall r. IsType0 r => r -> Key
asKey (forall (name :: Symbol) era.
HuddleRule name era =>
Proxy era -> Rule
huddleRule @"metadatum_label" Proxy era
p)
            Key -> Rule -> MapEntry
forall a me. (IsType0 a, IsEntryLike me) => Key -> a -> me
==> forall (name :: Symbol) era.
HuddleRule name era =>
Proxy era -> Rule
huddleRule @"metadatum" Proxy era
p
        ]

instance Era era => HuddleRule "auxiliary_data_hash" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
p = Text
"auxiliary_data_hash" Text -> Rule -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= forall (name :: Symbol) era.
HuddleRule name era =>
Proxy era -> Rule
huddleRule @"hash32" Proxy era
p

instance Era era => HuddleRule "script_hash" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
p =
    Text -> Rule -> Rule
forall a. HasField' "description" a (Maybe Text) => Text -> a -> a
comment
      Text
[str|To compute a script hash, note that you must prepend
          |a tag to the bytes of the script before hashing.
          |The tag is determined by the language.
          |The tags are:
          |  "\x00" for multisig/native scripts
          |  "\x01" for Plutus V1 scripts
          |  "\x02" for Plutus V2 scripts
          |  "\x03" for Plutus V3 scripts
          |  "\x04" for Plutus V4 scripts
          |]
      (Rule -> Rule) -> Rule -> Rule
forall a b. (a -> b) -> a -> b
$ Text
"script_hash"
        Text -> Rule -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= forall (name :: Symbol) era.
HuddleRule name era =>
Proxy era -> Rule
huddleRule @"hash28" Proxy era
p

instance Era era => HuddleRule "credential" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
p =
    Text
"credential"
      Text -> Choice ArrayChoice -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= ArrayChoice -> ArrayChoice
arr [Item ArrayChoice
ArrayEntry
0, Rule -> ArrayEntry
forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a (forall (name :: Symbol) era.
HuddleRule name era =>
Proxy era -> Rule
huddleRule @"addr_keyhash" Proxy era
p)]
      ArrayChoice -> ArrayChoice -> Choice ArrayChoice
forall a c b.
(IsChoosable a c, IsChoosable b c) =>
a -> b -> Choice c
/ ArrayChoice -> ArrayChoice
arr [Item ArrayChoice
ArrayEntry
1, Rule -> ArrayEntry
forall a e. (IsType0 a, IsGroupOrArrayEntry e) => a -> e
a (forall (name :: Symbol) era.
HuddleRule name era =>
Proxy era -> Rule
huddleRule @"script_hash" Proxy era
p)]

instance Era era => HuddleRule "stake_credential" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
p = Text
"stake_credential" Text -> Rule -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= forall (name :: Symbol) era.
HuddleRule name era =>
Proxy era -> Rule
huddleRule @"credential" Proxy era
p

instance Era era => HuddleRule "port" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
_ = Text
"port" Text -> Constrained -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= Value Int
VUInt Value Int -> Word64 -> Constrained
forall a c.
(IsComparable a, IsConstrainable c a) =>
c -> Word64 -> Constrained
`le` Word64
65535

instance Era era => HuddleRule "ipv4" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
_ = Text
"ipv4" Text -> Constrained -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= Value ByteString
VBytes Value ByteString -> Word64 -> Constrained
forall c a s.
(IsSizeable a, IsSize s, IsConstrainable c a) =>
c -> s -> Constrained
`sized` (Word64
4 :: Word64)

instance Era era => HuddleRule "ipv6" era where
  huddleRule :: Proxy era -> Rule
huddleRule Proxy era
_ = Text
"ipv6" Text -> Constrained -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= Value ByteString
VBytes Value ByteString -> Word64 -> Constrained
forall c a s.
(IsSizeable a, IsSize s, IsConstrainable c a) =>
c -> s -> Constrained
`sized` (Word64
16 :: Word64)

majorProtocolVersionRule :: forall era. Era era => Proxy era -> Rule
majorProtocolVersionRule :: forall era. Era era => Proxy era -> Rule
majorProtocolVersionRule Proxy era
_ =
  Text
"major_protocol_version"
    Text -> Ranged -> Rule
forall a. IsType0 a => Text -> a -> Rule
=:= forall i. Integral i => Version -> i
getVersion @Integer (forall era. Era era => Version
eraProtVerLow @ByronEra)
    Integer -> Integer -> Ranged
forall a b. (IsRangeBound a, IsRangeBound b) => a -> b -> Ranged
... Integer -> Integer
forall a. Enum a => a -> a
succ (forall i. Integral i => Version -> i
getVersion @Integer (forall era. Era era => Version
eraProtVerHigh @era))