Add constants to library #21

Merged
pitmutt merged 3 commits from rav001 into dev040 2024-03-06 21:37:05 +00:00
2 changed files with 54 additions and 10 deletions
Showing only changes of commit d118a83993 - Show all commits

View file

@ -26,19 +26,12 @@ import ZcashHaskell.Types
( TransparentAddress(..) ( TransparentAddress(..)
, TransparentType(..) , TransparentType(..)
, ZcashNet(..) , ZcashNet(..)
, getTransparentPrefix
) )
encodeTransparent :: TransparentAddress -> T.Text encodeTransparent :: TransparentAddress -> T.Text
encodeTransparent t = encodeTransparent t =
case ta_type t of encodeTransparent' (getTransparentPrefix (ta_net t) (ta_type t)) $ ta_bytes t
P2SH ->
case ta_net t of
MainNet -> encodeTransparent' (0x1c, 0xbd) $ ta_bytes t
_ -> encodeTransparent' (0x1c, 0xba) $ ta_bytes t
P2PKH ->
case ta_net t of
MainNet -> encodeTransparent' (0x1c, 0xb8) $ ta_bytes t
_ -> encodeTransparent' (0x1d, 0x25) $ ta_bytes t
where where
encodeTransparent' :: (Word8, Word8) -> BS.ByteString -> T.Text encodeTransparent' :: (Word8, Word8) -> BS.ByteString -> T.Text
encodeTransparent' (a, b) h = encodeTransparent' (a, b) h =

View file

@ -64,7 +64,7 @@ data ZcashNet
type AccountId = Int type AccountId = Int
-- ** Constants -- ** Constants
-- | Types for coin types on the different networks -- | Type for coin types on the different networks
data CoinType data CoinType
= MainNetCoin = MainNetCoin
| TestNetCoin | TestNetCoin
@ -77,6 +77,57 @@ getValue c =
TestNetCoin -> 1 TestNetCoin -> 1
RegTestNetCoin -> 1 RegTestNetCoin -> 1
-- | Type for Sapling Human-readable part
data SaplingHrp
= SapExtSpendingKey
| SapExtFullViewingKey
| SapPaymentAddress
| SapTestExtSpendingKey
| SapTestExtFullViewingKey
| SapTestPaymentAddress
getSaplingHrp :: SaplingHrp -> String
getSaplingHrp s =
case s of
SapExtSpendingKey -> "secret-extended-key-main"
SapExtFullViewingKey -> "zxviews"
SapPaymentAddress -> "zs"
SapTestExtSpendingKey -> "secret-extended-key-test"
SapTestExtFullViewingKey -> "zxviewtestsapling"
SapTestPaymentAddress -> "ztestsapling"
-- | Type for Unified Human-readable part
data UnifiedHrp
= UniPaymentAddress
| UniFullViewingKey
| UniIncomingViewingKey
| UniTestPaymentAddress
| UniTestFullViewingKey
| UniTestIncomingViewingKey
getUnifiedHrp :: UnifiedHrp -> String
getUnifiedHrp s =
case s of
UniPaymentAddress -> "u"
UniFullViewingKey -> "uview"
UniIncomingViewingKey -> "uivk"
UniTestPaymentAddress -> "utest"
UniTestFullViewingKey -> "uviewtest"
UniTestIncomingViewingKey -> "uivktest"
-- | Function to get the Base58 prefix for encoding a 'TransparentAddress'
getTransparentPrefix :: ZcashNet -> TransparentType -> (Word8, Word8)
getTransparentPrefix n t =
case t of
P2SH ->
case n of
MainNet -> (0x1c, 0xbd)
_ -> (0x1c, 0xba)
P2PKH ->
case n of
MainNet -> (0x1c, 0xb8)
_ -> (0x1d, 0x25)
-- * RPC -- * RPC
-- | A type to model Zcash RPC calls -- | A type to model Zcash RPC calls
data RpcCall = RpcCall data RpcCall = RpcCall