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

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

import Cardano.Binary
  ( Decoder,
    FromCBOR (..),
    ToCBOR (..),
    decodeBytesCanonical,
    decodeFull,
    decodeFullDecoder,
    decodeWord32Canonical,
    serialize,
  )
import Cardano.Chain.Common.Attributes
  ( Attributes (..),
    fromCBORAttributes,
    toCBORAttributes,
  )
import Cardano.Chain.Common.NetworkMagic (NetworkMagic (..))
import Cardano.Prelude
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
/= :: AddrAttributes -> AddrAttributes -> Bool
$c/= :: AddrAttributes -> AddrAttributes -> Bool
== :: AddrAttributes -> AddrAttributes -> Bool
$c== :: 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
min :: AddrAttributes -> AddrAttributes -> AddrAttributes
$cmin :: AddrAttributes -> AddrAttributes -> AddrAttributes
max :: AddrAttributes -> AddrAttributes -> AddrAttributes
$cmax :: AddrAttributes -> AddrAttributes -> AddrAttributes
>= :: AddrAttributes -> AddrAttributes -> Bool
$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
compare :: AddrAttributes -> AddrAttributes -> Ordering
$ccompare :: AddrAttributes -> AddrAttributes -> Ordering
$cp1Ord :: Eq 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
showList :: [AddrAttributes] -> ShowS
$cshowList :: [AddrAttributes] -> ShowS
show :: AddrAttributes -> String
$cshow :: AddrAttributes -> String
showsPrec :: Int -> AddrAttributes -> ShowS
$cshowsPrec :: Int -> 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
$cto :: forall x. Rep AddrAttributes x -> AddrAttributes
$cfrom :: forall x. AddrAttributes -> Rep AddrAttributes x
Generic, AddrAttributes -> ()
(AddrAttributes -> ()) -> NFData AddrAttributes
forall a. (a -> ()) -> NFData a
rnf :: AddrAttributes -> ()
$crnf :: 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
showTypeOf :: Proxy AddrAttributes -> String
$cshowTypeOf :: Proxy AddrAttributes -> String
wNoThunks :: Context -> AddrAttributes -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> AddrAttributes -> IO (Maybe ThunkInfo)
noThunks :: Context -> AddrAttributes -> IO (Maybe ThunkInfo)
$cnoThunks :: Context -> AddrAttributes -> IO (Maybe ThunkInfo)
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 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 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
  -- FIXME @avieth it was observed that for a 150kb block, this call to
  -- toCBORAttributes 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?
  toCBOR :: Attributes AddrAttributes -> Encoding
toCBOR attrs :: Attributes AddrAttributes
attrs@Attributes {attrData :: forall h. Attributes h -> h
attrData = AddrAttributes Maybe HDAddressPayload
derivationPath NetworkMagic
networkMagic} =
    [(Word8, AddrAttributes -> ByteString)]
-> Attributes AddrAttributes -> Encoding
forall t. [(Word8, t -> ByteString)] -> Attributes t -> Encoding
toCBORAttributes [(Word8, AddrAttributes -> ByteString)]
listWithIndices Attributes AddrAttributes
attrs
    where
      listWithIndices :: [(Word8, AddrAttributes -> LByteString)]
      listWithIndices :: [(Word8, AddrAttributes -> ByteString)]
listWithIndices =
        [(Word8, AddrAttributes -> ByteString)]
derivationPathListWithIndices
          [(Word8, AddrAttributes -> ByteString)]
-> [(Word8, AddrAttributes -> ByteString)]
-> [(Word8, AddrAttributes -> ByteString)]
forall a. Semigroup a => a -> a -> a
<> [(Word8, AddrAttributes -> ByteString)]
networkMagicListWithIndices

      derivationPathListWithIndices :: [(Word8, AddrAttributes -> LByteString)]
      derivationPathListWithIndices :: [(Word8, AddrAttributes -> ByteString)]
derivationPathListWithIndices = case Maybe HDAddressPayload
derivationPath of
        Maybe HDAddressPayload
Nothing -> []
        -- 'unsafeFromJust' is safe, because 'case' ensures
        -- that derivation path is 'Just'.
        Just HDAddressPayload
_ -> [(Word8
1, HDAddressPayload -> ByteString
forall a. ToCBOR a => a -> ByteString
serialize (HDAddressPayload -> ByteString)
-> (AddrAttributes -> HDAddressPayload)
-> AddrAttributes
-> ByteString
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 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 :: 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 ToCBOR (Attributes AddrAttributes)")

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

instance FromCBOR (Attributes AddrAttributes) where
  fromCBOR :: Decoder s (Attributes AddrAttributes)
fromCBOR = AddrAttributes
-> (Word8
    -> ByteString
    -> AddrAttributes
    -> Decoder s (Maybe AddrAttributes))
-> Decoder s (Attributes AddrAttributes)
forall t s.
t
-> (Word8 -> ByteString -> t -> Decoder s (Maybe t))
-> Decoder s (Attributes t)
fromCBORAttributes AddrAttributes
initValue Word8
-> ByteString -> AddrAttributes -> Decoder s (Maybe AddrAttributes)
forall s.
Word8
-> ByteString -> AddrAttributes -> Decoder s (Maybe AddrAttributes)
go
    where
      initValue :: AddrAttributes
initValue =
        AddrAttributes :: Maybe HDAddressPayload -> NetworkMagic -> AddrAttributes
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 :: Word8
-> ByteString -> AddrAttributes -> Decoder s (Maybe AddrAttributes)
go Word8
n ByteString
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 :: Maybe HDAddressPayload
aaVKDerivationPath = HDAddressPayload -> Maybe HDAddressPayload
forall a. a -> Maybe a
Just HDAddressPayload
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 e a s. Buildable e => Either e a -> Decoder s a
toCborError (ByteString -> Either DecoderError HDAddressPayload
forall a. FromCBOR a => ByteString -> Either DecoderError a
decodeFull ByteString
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 :: NetworkMagic
aaNetworkMagic = Word32 -> NetworkMagic
NetworkTestnet Word32
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 e a s. Buildable e => Either e a -> Decoder s a
toCborError
              (Text
-> (forall s. Decoder s Word32)
-> ByteString
-> Either DecoderError Word32
forall a.
Text
-> (forall s. Decoder s a) -> ByteString -> Either DecoderError a
decodeFullDecoder Text
"NetworkMagic" forall s. Decoder s Word32
decodeWord32Canonical ByteString
v)
        Word8
_ -> Maybe AddrAttributes -> Decoder s (Maybe AddrAttributes)
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
/= :: HDPassphrase -> HDPassphrase -> Bool
$c/= :: HDPassphrase -> HDPassphrase -> Bool
== :: HDPassphrase -> HDPassphrase -> Bool
$c== :: 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
showList :: [HDPassphrase] -> ShowS
$cshowList :: [HDPassphrase] -> ShowS
show :: HDPassphrase -> String
$cshow :: HDPassphrase -> String
showsPrec :: Int -> HDPassphrase -> ShowS
$cshowsPrec :: Int -> 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
--
--   * serialiazed 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
/= :: HDAddressPayload -> HDAddressPayload -> Bool
$c/= :: HDAddressPayload -> HDAddressPayload -> Bool
== :: HDAddressPayload -> HDAddressPayload -> Bool
$c== :: 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
min :: HDAddressPayload -> HDAddressPayload -> HDAddressPayload
$cmin :: HDAddressPayload -> HDAddressPayload -> HDAddressPayload
max :: HDAddressPayload -> HDAddressPayload -> HDAddressPayload
$cmax :: HDAddressPayload -> HDAddressPayload -> HDAddressPayload
>= :: HDAddressPayload -> HDAddressPayload -> Bool
$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
compare :: HDAddressPayload -> HDAddressPayload -> Ordering
$ccompare :: HDAddressPayload -> HDAddressPayload -> Ordering
$cp1Ord :: Eq 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
showList :: [HDAddressPayload] -> ShowS
$cshowList :: [HDAddressPayload] -> ShowS
show :: HDAddressPayload -> String
$cshow :: HDAddressPayload -> String
showsPrec :: Int -> HDAddressPayload -> ShowS
$cshowsPrec :: Int -> 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
$cto :: forall x. Rep HDAddressPayload x -> HDAddressPayload
$cfrom :: forall x. HDAddressPayload -> Rep HDAddressPayload x
Generic)
  deriving newtype (Typeable HDAddressPayload
Typeable HDAddressPayload
-> (HDAddressPayload -> Encoding)
-> ((forall t. ToCBOR t => Proxy t -> Size)
    -> Proxy HDAddressPayload -> Size)
-> ((forall t. ToCBOR t => Proxy t -> Size)
    -> Proxy [HDAddressPayload] -> Size)
-> ToCBOR HDAddressPayload
HDAddressPayload -> Encoding
(forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [HDAddressPayload] -> Size
(forall t. ToCBOR t => Proxy t -> Size)
-> Proxy HDAddressPayload -> Size
forall a.
Typeable a
-> (a -> Encoding)
-> ((forall t. ToCBOR t => Proxy t -> Size) -> Proxy a -> Size)
-> ((forall t. ToCBOR t => Proxy t -> Size) -> Proxy [a] -> Size)
-> ToCBOR a
encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [HDAddressPayload] -> Size
$cencodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [HDAddressPayload] -> Size
encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy HDAddressPayload -> Size
$cencodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy HDAddressPayload -> Size
toCBOR :: HDAddressPayload -> Encoding
$ctoCBOR :: HDAddressPayload -> Encoding
$cp1ToCBOR :: Typeable HDAddressPayload
ToCBOR, HDAddressPayload -> Int
(HDAddressPayload -> Int) -> HeapWords HDAddressPayload
forall a. (a -> Int) -> HeapWords a
heapWords :: HDAddressPayload -> Int
$cheapWords :: HDAddressPayload -> Int
HeapWords)
  deriving anyclass (HDAddressPayload -> ()
(HDAddressPayload -> ()) -> NFData HDAddressPayload
forall a. (a -> ()) -> NFData a
rnf :: HDAddressPayload -> ()
$crnf :: 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
showTypeOf :: Proxy HDAddressPayload -> String
$cshowTypeOf :: Proxy HDAddressPayload -> String
wNoThunks :: Context -> HDAddressPayload -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> HDAddressPayload -> IO (Maybe ThunkInfo)
noThunks :: Context -> HDAddressPayload -> IO (Maybe ThunkInfo)
$cnoThunks :: Context -> HDAddressPayload -> IO (Maybe ThunkInfo)
NoThunks)

-- 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 kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= ByteString -> String
Char8.unpack ByteString
bs]

instance FromCBOR HDAddressPayload where
  fromCBOR :: Decoder s HDAddressPayload
fromCBOR = 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