{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}

module Cardano.Chain.Common.AddrAttributes (
  AddrAttributes (..),
  HDAddressPayload (..),
) where

import Cardano.Chain.Common.Attributes (
  Attributes (..),
  decCBORAttributes,
  encCBORAttributes,
 )
import Cardano.Chain.Common.NetworkMagic (NetworkMagic (..))
import Cardano.HeapWords (HeapWords (..))
import Cardano.Ledger.Binary (
  DecCBOR (..),
  Decoder,
  EncCBOR (..),
  FromCBOR (..),
  ToCBOR (..),
  byronProtVer,
  decodeBytesCanonical,
  decodeFull,
  decodeFullDecoder,
  decodeWord32Canonical,
  fromByronCBOR,
  serialize,
  toByronCBOR,
  toCborError,
 )
import Cardano.Prelude hiding (toCborError)
import Data.Aeson (ToJSON (..), object, (.=))
import qualified Data.ByteString.Char8 as Char8
import Data.Text.Lazy.Builder (Builder)
import Formatting (bprint, builder)
import qualified Formatting.Buildable as B
import NoThunks.Class (NoThunks (..))

-- | Additional information stored along with address. It's intended
-- to be put into 'Attributes' data type to make it extensible with
-- softfork.
data AddrAttributes = AddrAttributes
  { AddrAttributes -> Maybe HDAddressPayload
aaVKDerivationPath :: !(Maybe HDAddressPayload)
  , AddrAttributes -> NetworkMagic
aaNetworkMagic :: !NetworkMagic
  }
  deriving (AddrAttributes -> AddrAttributes -> Bool
(AddrAttributes -> AddrAttributes -> Bool)
-> (AddrAttributes -> AddrAttributes -> Bool) -> Eq AddrAttributes
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AddrAttributes -> AddrAttributes -> Bool
== :: AddrAttributes -> AddrAttributes -> Bool
$c/= :: AddrAttributes -> AddrAttributes -> Bool
/= :: AddrAttributes -> AddrAttributes -> Bool
Eq, Eq AddrAttributes
Eq AddrAttributes =>
(AddrAttributes -> AddrAttributes -> Ordering)
-> (AddrAttributes -> AddrAttributes -> Bool)
-> (AddrAttributes -> AddrAttributes -> Bool)
-> (AddrAttributes -> AddrAttributes -> Bool)
-> (AddrAttributes -> AddrAttributes -> Bool)
-> (AddrAttributes -> AddrAttributes -> AddrAttributes)
-> (AddrAttributes -> AddrAttributes -> AddrAttributes)
-> Ord AddrAttributes
AddrAttributes -> AddrAttributes -> Bool
AddrAttributes -> AddrAttributes -> Ordering
AddrAttributes -> AddrAttributes -> AddrAttributes
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: AddrAttributes -> AddrAttributes -> Ordering
compare :: AddrAttributes -> AddrAttributes -> Ordering
$c< :: AddrAttributes -> AddrAttributes -> Bool
< :: AddrAttributes -> AddrAttributes -> Bool
$c<= :: AddrAttributes -> AddrAttributes -> Bool
<= :: AddrAttributes -> AddrAttributes -> Bool
$c> :: AddrAttributes -> AddrAttributes -> Bool
> :: AddrAttributes -> AddrAttributes -> Bool
$c>= :: AddrAttributes -> AddrAttributes -> Bool
>= :: AddrAttributes -> AddrAttributes -> Bool
$cmax :: AddrAttributes -> AddrAttributes -> AddrAttributes
max :: AddrAttributes -> AddrAttributes -> AddrAttributes
$cmin :: AddrAttributes -> AddrAttributes -> AddrAttributes
min :: AddrAttributes -> AddrAttributes -> AddrAttributes
Ord, Int -> AddrAttributes -> ShowS
[AddrAttributes] -> ShowS
AddrAttributes -> String
(Int -> AddrAttributes -> ShowS)
-> (AddrAttributes -> String)
-> ([AddrAttributes] -> ShowS)
-> Show AddrAttributes
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AddrAttributes -> ShowS
showsPrec :: Int -> AddrAttributes -> ShowS
$cshow :: AddrAttributes -> String
show :: AddrAttributes -> String
$cshowList :: [AddrAttributes] -> ShowS
showList :: [AddrAttributes] -> ShowS
Show, (forall x. AddrAttributes -> Rep AddrAttributes x)
-> (forall x. Rep AddrAttributes x -> AddrAttributes)
-> Generic AddrAttributes
forall x. Rep AddrAttributes x -> AddrAttributes
forall x. AddrAttributes -> Rep AddrAttributes x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. AddrAttributes -> Rep AddrAttributes x
from :: forall x. AddrAttributes -> Rep AddrAttributes x
$cto :: forall x. Rep AddrAttributes x -> AddrAttributes
to :: forall x. Rep AddrAttributes x -> AddrAttributes
Generic, AddrAttributes -> ()
(AddrAttributes -> ()) -> NFData AddrAttributes
forall a. (a -> ()) -> NFData a
$crnf :: AddrAttributes -> ()
rnf :: AddrAttributes -> ()
NFData, Context -> AddrAttributes -> IO (Maybe ThunkInfo)
Proxy AddrAttributes -> String
(Context -> AddrAttributes -> IO (Maybe ThunkInfo))
-> (Context -> AddrAttributes -> IO (Maybe ThunkInfo))
-> (Proxy AddrAttributes -> String)
-> NoThunks AddrAttributes
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
$cnoThunks :: Context -> AddrAttributes -> IO (Maybe ThunkInfo)
noThunks :: Context -> AddrAttributes -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> AddrAttributes -> IO (Maybe ThunkInfo)
wNoThunks :: Context -> AddrAttributes -> IO (Maybe ThunkInfo)
$cshowTypeOf :: Proxy AddrAttributes -> String
showTypeOf :: Proxy AddrAttributes -> String
NoThunks)

instance HeapWords AddrAttributes where
  heapWords :: AddrAttributes -> Int
heapWords AddrAttributes
aa =
    Int
3
      Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Maybe HDAddressPayload -> Int
forall a. HeapWords a => a -> Int
heapWords (AddrAttributes -> Maybe HDAddressPayload
aaVKDerivationPath AddrAttributes
aa)
      Int -> Int -> Int
forall a. Num a => a -> a -> a
+ NetworkMagic -> Int
forall a. HeapWords a => a -> Int
heapWords (AddrAttributes -> NetworkMagic
aaNetworkMagic AddrAttributes
aa)

instance B.Buildable AddrAttributes where
  build :: AddrAttributes -> Builder
build AddrAttributes
aa =
    Format Builder (Builder -> Builder) -> Builder -> Builder
forall a. Format Builder a -> a
bprint
      (Format (Builder -> Builder) (Builder -> Builder)
"AddrAttributes { derivation path: " Format (Builder -> Builder) (Builder -> Builder)
-> Format Builder (Builder -> Builder)
-> Format Builder (Builder -> Builder)
forall b c a. Format b c -> Format a b -> Format a c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Format Builder (Builder -> Builder)
forall r. Format r (Builder -> r)
builder Format Builder (Builder -> Builder)
-> Format Builder Builder -> Format Builder (Builder -> Builder)
forall b c a. Format b c -> Format a b -> Format a c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Format Builder Builder
" }")
      Builder
derivationPathBuilder
    where
      derivationPathBuilder :: Builder
      derivationPathBuilder :: Builder
derivationPathBuilder = case AddrAttributes -> Maybe HDAddressPayload
aaVKDerivationPath AddrAttributes
aa of
        Maybe HDAddressPayload
Nothing -> Builder
"{}"
        Just HDAddressPayload
_ -> Builder
"{path is encrypted}"

-- Used for debugging purposes only
instance ToJSON AddrAttributes

{- NOTE: Address attributes serialization
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

'Attributes' are conceptually a map, where keys are numbers ('Word8').

For address there are two attributes:
  - 1 - derivation path, defaults to 'Nothing'.

-}

instance ToCBOR (Attributes AddrAttributes) where
  toCBOR :: Attributes AddrAttributes -> Encoding
toCBOR = Attributes AddrAttributes -> Encoding
forall a. EncCBOR a => a -> Encoding
toByronCBOR

instance FromCBOR (Attributes AddrAttributes) where
  fromCBOR :: forall s. Decoder s (Attributes AddrAttributes)
fromCBOR = Decoder s (Attributes AddrAttributes)
forall a s. DecCBOR a => Decoder s a
fromByronCBOR

instance EncCBOR (Attributes AddrAttributes) where
  -- FIXME @avieth it was observed that for a 150kb block, this call to
  -- encCBORAttributes allocated 3.685mb
  -- Try using serialize rather than serialize', to avoid the
  -- toStrict call.
  -- Also consider using a custom builder strategy; serialized attributes are
  -- probably small, right?
  encCBOR :: Attributes AddrAttributes -> Encoding
encCBOR attrs :: Attributes AddrAttributes
attrs@Attributes {attrData :: forall h. Attributes h -> h
attrData = AddrAttributes Maybe HDAddressPayload
derivationPath NetworkMagic
networkMagic} =
    [(Word8, AddrAttributes -> LByteString)]
-> Attributes AddrAttributes -> Encoding
forall t. [(Word8, t -> LByteString)] -> Attributes t -> Encoding
encCBORAttributes [(Word8, AddrAttributes -> LByteString)]
listWithIndices Attributes AddrAttributes
attrs
    where
      listWithIndices :: [(Word8, AddrAttributes -> LByteString)]
      listWithIndices :: [(Word8, AddrAttributes -> LByteString)]
listWithIndices =
        [(Word8, AddrAttributes -> LByteString)]
derivationPathListWithIndices
          [(Word8, AddrAttributes -> LByteString)]
-> [(Word8, AddrAttributes -> LByteString)]
-> [(Word8, AddrAttributes -> LByteString)]
forall a. Semigroup a => a -> a -> a
<> [(Word8, AddrAttributes -> LByteString)]
networkMagicListWithIndices

      derivationPathListWithIndices :: [(Word8, AddrAttributes -> LByteString)]
      derivationPathListWithIndices :: [(Word8, AddrAttributes -> LByteString)]
derivationPathListWithIndices = case Maybe HDAddressPayload
derivationPath of
        Maybe HDAddressPayload
Nothing -> []
        -- 'unsafeFromJust' is safe, because 'case' ensures
        -- that derivation path is 'Just'.
        Just HDAddressPayload
_ -> [(Word8
1, Version -> HDAddressPayload -> LByteString
forall a. EncCBOR a => Version -> a -> LByteString
serialize Version
byronProtVer (HDAddressPayload -> LByteString)
-> (AddrAttributes -> HDAddressPayload)
-> AddrAttributes
-> LByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Maybe HDAddressPayload -> HDAddressPayload
forall a. Maybe a -> a
unsafeFromJust (Maybe HDAddressPayload -> HDAddressPayload)
-> (AddrAttributes -> Maybe HDAddressPayload)
-> AddrAttributes
-> HDAddressPayload
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. AddrAttributes -> Maybe HDAddressPayload
aaVKDerivationPath)]
      unsafeFromJust :: Maybe a -> a
      unsafeFromJust :: forall a. Maybe a -> a
unsafeFromJust =
        a -> Maybe a -> a
forall a. a -> Maybe a -> a
fromMaybe (Text -> a
forall a. HasCallStack => Text -> a
panic Text
"Maybe was Nothing in EncCBOR (Attributes AddrAttributes)")

      networkMagicListWithIndices :: [(Word8, AddrAttributes -> LByteString)]
      networkMagicListWithIndices :: [(Word8, AddrAttributes -> LByteString)]
networkMagicListWithIndices =
        case NetworkMagic
networkMagic of
          NetworkMagic
NetworkMainOrStage -> []
          NetworkTestnet Word32
x ->
            [(Word8
2, \AddrAttributes
_ -> Version -> Word32 -> LByteString
forall a. EncCBOR a => Version -> a -> LByteString
serialize Version
byronProtVer Word32
x)]

instance DecCBOR (Attributes AddrAttributes) where
  decCBOR :: forall s. Decoder s (Attributes AddrAttributes)
decCBOR = AddrAttributes
-> (Word8
    -> LByteString
    -> AddrAttributes
    -> Decoder s (Maybe AddrAttributes))
-> Decoder s (Attributes AddrAttributes)
forall t s.
t
-> (Word8 -> LByteString -> t -> Decoder s (Maybe t))
-> Decoder s (Attributes t)
decCBORAttributes AddrAttributes
initValue Word8
-> LByteString
-> AddrAttributes
-> Decoder s (Maybe AddrAttributes)
forall s.
Word8
-> LByteString
-> AddrAttributes
-> Decoder s (Maybe AddrAttributes)
go
    where
      initValue :: AddrAttributes
initValue =
        AddrAttributes
          { aaVKDerivationPath :: Maybe HDAddressPayload
aaVKDerivationPath = Maybe HDAddressPayload
forall a. Maybe a
Nothing
          , aaNetworkMagic :: NetworkMagic
aaNetworkMagic = NetworkMagic
NetworkMainOrStage
          }

      go ::
        Word8 ->
        LByteString ->
        AddrAttributes ->
        Decoder s (Maybe AddrAttributes)
      go :: forall s.
Word8
-> LByteString
-> AddrAttributes
-> Decoder s (Maybe AddrAttributes)
go Word8
n LByteString
v AddrAttributes
acc = case Word8
n of
        Word8
1 ->
          (\HDAddressPayload
deriv -> AddrAttributes -> Maybe AddrAttributes
forall a. a -> Maybe a
Just (AddrAttributes -> Maybe AddrAttributes)
-> AddrAttributes -> Maybe AddrAttributes
forall a b. (a -> b) -> a -> b
$ AddrAttributes
acc {aaVKDerivationPath = Just deriv})
            (HDAddressPayload -> Maybe AddrAttributes)
-> Decoder s HDAddressPayload -> Decoder s (Maybe AddrAttributes)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Either DecoderError HDAddressPayload -> Decoder s HDAddressPayload
forall (m :: * -> *) e a.
(MonadFail m, Buildable e) =>
Either e a -> m a
toCborError (Version -> LByteString -> Either DecoderError HDAddressPayload
forall a.
DecCBOR a =>
Version -> LByteString -> Either DecoderError a
decodeFull Version
byronProtVer LByteString
v)
        Word8
2 ->
          (\Word32
deriv -> AddrAttributes -> Maybe AddrAttributes
forall a. a -> Maybe a
Just (AddrAttributes -> Maybe AddrAttributes)
-> AddrAttributes -> Maybe AddrAttributes
forall a b. (a -> b) -> a -> b
$ AddrAttributes
acc {aaNetworkMagic = NetworkTestnet deriv})
            (Word32 -> Maybe AddrAttributes)
-> Decoder s Word32 -> Decoder s (Maybe AddrAttributes)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Either DecoderError Word32 -> Decoder s Word32
forall (m :: * -> *) e a.
(MonadFail m, Buildable e) =>
Either e a -> m a
toCborError
              (Version
-> Text
-> (forall s. Decoder s Word32)
-> LByteString
-> Either DecoderError Word32
forall a.
Version
-> Text
-> (forall s. Decoder s a)
-> LByteString
-> Either DecoderError a
decodeFullDecoder Version
byronProtVer Text
"NetworkMagic" Decoder s Word32
forall s. Decoder s Word32
decodeWord32Canonical LByteString
v)
        Word8
_ -> Maybe AddrAttributes -> Decoder s (Maybe AddrAttributes)
forall a. a -> Decoder s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe AddrAttributes
forall a. Maybe a
Nothing

-- | Passphrase is a hash of root verification key.
data HDPassphrase = HDPassphrase !ByteString
  deriving (HDPassphrase -> HDPassphrase -> Bool
(HDPassphrase -> HDPassphrase -> Bool)
-> (HDPassphrase -> HDPassphrase -> Bool) -> Eq HDPassphrase
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: HDPassphrase -> HDPassphrase -> Bool
== :: HDPassphrase -> HDPassphrase -> Bool
$c/= :: HDPassphrase -> HDPassphrase -> Bool
/= :: HDPassphrase -> HDPassphrase -> Bool
Eq, Int -> HDPassphrase -> ShowS
[HDPassphrase] -> ShowS
HDPassphrase -> String
(Int -> HDPassphrase -> ShowS)
-> (HDPassphrase -> String)
-> ([HDPassphrase] -> ShowS)
-> Show HDPassphrase
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> HDPassphrase -> ShowS
showsPrec :: Int -> HDPassphrase -> ShowS
$cshow :: HDPassphrase -> String
show :: HDPassphrase -> String
$cshowList :: [HDPassphrase] -> ShowS
showList :: [HDPassphrase] -> ShowS
Show)

-- | HDAddressPayload is a specific address attribute that was used by the
-- Cardano wallet at mainnet launch, prior to moving to a BIP-44 style scheme.
--
-- It consisted of
--
--   * serialized and encrypted using HDPassphrase derivation path from the
--   root key to given descendant key (using ChaChaPoly1305 algorithm)
--
--   * cryptographic tag
--
-- It is still distinguished as an attribute, but not used by the ledger,
-- because the attributes size limits treat this attribute specially.
newtype HDAddressPayload = HDAddressPayload
  { HDAddressPayload -> ByteString
getHDAddressPayload :: ByteString
  }
  deriving (HDAddressPayload -> HDAddressPayload -> Bool
(HDAddressPayload -> HDAddressPayload -> Bool)
-> (HDAddressPayload -> HDAddressPayload -> Bool)
-> Eq HDAddressPayload
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: HDAddressPayload -> HDAddressPayload -> Bool
== :: HDAddressPayload -> HDAddressPayload -> Bool
$c/= :: HDAddressPayload -> HDAddressPayload -> Bool
/= :: HDAddressPayload -> HDAddressPayload -> Bool
Eq, Eq HDAddressPayload
Eq HDAddressPayload =>
(HDAddressPayload -> HDAddressPayload -> Ordering)
-> (HDAddressPayload -> HDAddressPayload -> Bool)
-> (HDAddressPayload -> HDAddressPayload -> Bool)
-> (HDAddressPayload -> HDAddressPayload -> Bool)
-> (HDAddressPayload -> HDAddressPayload -> Bool)
-> (HDAddressPayload -> HDAddressPayload -> HDAddressPayload)
-> (HDAddressPayload -> HDAddressPayload -> HDAddressPayload)
-> Ord HDAddressPayload
HDAddressPayload -> HDAddressPayload -> Bool
HDAddressPayload -> HDAddressPayload -> Ordering
HDAddressPayload -> HDAddressPayload -> HDAddressPayload
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: HDAddressPayload -> HDAddressPayload -> Ordering
compare :: HDAddressPayload -> HDAddressPayload -> Ordering
$c< :: HDAddressPayload -> HDAddressPayload -> Bool
< :: HDAddressPayload -> HDAddressPayload -> Bool
$c<= :: HDAddressPayload -> HDAddressPayload -> Bool
<= :: HDAddressPayload -> HDAddressPayload -> Bool
$c> :: HDAddressPayload -> HDAddressPayload -> Bool
> :: HDAddressPayload -> HDAddressPayload -> Bool
$c>= :: HDAddressPayload -> HDAddressPayload -> Bool
>= :: HDAddressPayload -> HDAddressPayload -> Bool
$cmax :: HDAddressPayload -> HDAddressPayload -> HDAddressPayload
max :: HDAddressPayload -> HDAddressPayload -> HDAddressPayload
$cmin :: HDAddressPayload -> HDAddressPayload -> HDAddressPayload
min :: HDAddressPayload -> HDAddressPayload -> HDAddressPayload
Ord, Int -> HDAddressPayload -> ShowS
[HDAddressPayload] -> ShowS
HDAddressPayload -> String
(Int -> HDAddressPayload -> ShowS)
-> (HDAddressPayload -> String)
-> ([HDAddressPayload] -> ShowS)
-> Show HDAddressPayload
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> HDAddressPayload -> ShowS
showsPrec :: Int -> HDAddressPayload -> ShowS
$cshow :: HDAddressPayload -> String
show :: HDAddressPayload -> String
$cshowList :: [HDAddressPayload] -> ShowS
showList :: [HDAddressPayload] -> ShowS
Show, (forall x. HDAddressPayload -> Rep HDAddressPayload x)
-> (forall x. Rep HDAddressPayload x -> HDAddressPayload)
-> Generic HDAddressPayload
forall x. Rep HDAddressPayload x -> HDAddressPayload
forall x. HDAddressPayload -> Rep HDAddressPayload x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. HDAddressPayload -> Rep HDAddressPayload x
from :: forall x. HDAddressPayload -> Rep HDAddressPayload x
$cto :: forall x. Rep HDAddressPayload x -> HDAddressPayload
to :: forall x. Rep HDAddressPayload x -> HDAddressPayload
Generic)
  deriving newtype (Typeable HDAddressPayload
Typeable HDAddressPayload =>
(HDAddressPayload -> Encoding)
-> ((forall t. EncCBOR t => Proxy t -> Size)
    -> Proxy HDAddressPayload -> Size)
-> ((forall t. EncCBOR t => Proxy t -> Size)
    -> Proxy [HDAddressPayload] -> Size)
-> EncCBOR HDAddressPayload
HDAddressPayload -> Encoding
(forall t. EncCBOR t => Proxy t -> Size)
-> Proxy [HDAddressPayload] -> Size
(forall t. EncCBOR t => Proxy t -> Size)
-> Proxy HDAddressPayload -> Size
forall a.
Typeable a =>
(a -> Encoding)
-> ((forall t. EncCBOR t => Proxy t -> Size) -> Proxy a -> Size)
-> ((forall t. EncCBOR t => Proxy t -> Size) -> Proxy [a] -> Size)
-> EncCBOR a
$cencCBOR :: HDAddressPayload -> Encoding
encCBOR :: HDAddressPayload -> Encoding
$cencodedSizeExpr :: (forall t. EncCBOR t => Proxy t -> Size)
-> Proxy HDAddressPayload -> Size
encodedSizeExpr :: (forall t. EncCBOR t => Proxy t -> Size)
-> Proxy HDAddressPayload -> Size
$cencodedListSizeExpr :: (forall t. EncCBOR t => Proxy t -> Size)
-> Proxy [HDAddressPayload] -> Size
encodedListSizeExpr :: (forall t. EncCBOR t => Proxy t -> Size)
-> Proxy [HDAddressPayload] -> Size
EncCBOR, HDAddressPayload -> Int
(HDAddressPayload -> Int) -> HeapWords HDAddressPayload
forall a. (a -> Int) -> HeapWords a
$cheapWords :: HDAddressPayload -> Int
heapWords :: HDAddressPayload -> Int
HeapWords)
  deriving anyclass (HDAddressPayload -> ()
(HDAddressPayload -> ()) -> NFData HDAddressPayload
forall a. (a -> ()) -> NFData a
$crnf :: HDAddressPayload -> ()
rnf :: HDAddressPayload -> ()
NFData, Context -> HDAddressPayload -> IO (Maybe ThunkInfo)
Proxy HDAddressPayload -> String
(Context -> HDAddressPayload -> IO (Maybe ThunkInfo))
-> (Context -> HDAddressPayload -> IO (Maybe ThunkInfo))
-> (Proxy HDAddressPayload -> String)
-> NoThunks HDAddressPayload
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
$cnoThunks :: Context -> HDAddressPayload -> IO (Maybe ThunkInfo)
noThunks :: Context -> HDAddressPayload -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> HDAddressPayload -> IO (Maybe ThunkInfo)
wNoThunks :: Context -> HDAddressPayload -> IO (Maybe ThunkInfo)
$cshowTypeOf :: Proxy HDAddressPayload -> String
showTypeOf :: Proxy HDAddressPayload -> String
NoThunks)

instance ToCBOR HDAddressPayload where
  toCBOR :: HDAddressPayload -> Encoding
toCBOR = HDAddressPayload -> Encoding
forall a. EncCBOR a => a -> Encoding
toByronCBOR

instance FromCBOR HDAddressPayload where
  fromCBOR :: forall s. Decoder s HDAddressPayload
fromCBOR = Decoder s HDAddressPayload
forall a s. DecCBOR a => Decoder s a
fromByronCBOR

-- Used for debugging purposes only
instance ToJSON HDAddressPayload where
  toJSON :: HDAddressPayload -> Value
toJSON (HDAddressPayload ByteString
bs) = [Pair] -> Value
object [Key
"HDAddressPayload" Key -> String -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= ByteString -> String
Char8.unpack ByteString
bs]

instance DecCBOR HDAddressPayload where
  decCBOR :: forall s. Decoder s HDAddressPayload
decCBOR = ByteString -> HDAddressPayload
HDAddressPayload (ByteString -> HDAddressPayload)
-> Decoder s ByteString -> Decoder s HDAddressPayload
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s ByteString
forall s. Decoder s ByteString
decodeBytesCanonical