Skip to content

Commit

Permalink
add networkVal
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Mar 27, 2023
1 parent dadd317 commit eea110c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/wallet/src/Cardano/Wallet/Primitive/AddressDerivation.hs
Expand Up @@ -63,6 +63,7 @@ module Cardano.Wallet.Primitive.AddressDerivation
, NetworkDiscriminant (..)
, NetworkDiscriminantVal
, networkDiscriminantVal
, networkVal

-- * Backends Interoperability
, PaymentAddress(..)
Expand Down Expand Up @@ -605,6 +606,25 @@ instance KnownNat pm => NetworkDiscriminantVal ('Staging pm) where
networkDiscriminantVal =
"staging (" <> T.pack (show $ natVal $ Proxy @pm) <> ")"

networkVal
:: forall (n :: NetworkDiscriminant) pm. (Typeable n, KnownNat pm)
=> Word8
networkVal = fromMaybe (error $ "network: unmatched type" <> show (typeRep @n))
(tryMainnet <|> tryTestnet <|> tryStaging)
where
tryMainnet =
case testEquality (typeRep @n) (typeRep @'Mainnet) of
Just Refl -> Just 0b00000001
Nothing -> Nothing
tryTestnet =
case testEquality (typeRep @n) (typeRep @('Testnet pm)) of
Just Refl -> Just 0b00000000
Nothing -> Nothing
tryStaging =
case testEquality (typeRep @n) (typeRep @('Staging pm)) of
Just Refl -> Just 0b00000000
Nothing -> Nothing

{-------------------------------------------------------------------------------
Interface over keys / address types
-------------------------------------------------------------------------------}
Expand Down

0 comments on commit eea110c

Please sign in to comment.