Add full validation of Sapling address to parser

This commit is contained in:
Rene Vergara 2023-09-27 13:18:16 -05:00
parent 528fdebe61
commit fb436f1499
Signed by: pitmutt
GPG key ID: 65122AD495A7F5B2

View file

@ -17,6 +17,7 @@ import GHC.Generics
import Text.Megaparsec hiding (State)
import Text.Megaparsec.Char
import ZcashHaskell.Orchard
import ZcashHaskell.Sapling (isValidShieldedAddress)
-- | Type to model a ZGo transaction
data ZGoTx = ZGoTx
@ -133,9 +134,9 @@ pSaplingAddress :: Parser MemoToken
pSaplingAddress = do
string "zs"
a <- some alphaNumChar
if length a /= 76
then fail "Failed to parse Sapling address"
else pure $ Address $ T.pack ("zs" <> a)
if isValidShieldedAddress (E.encodeUtf8 $ "zs" <> T.pack a)
then pure $ Address $ T.pack ("zs" <> a)
else fail "Failed to parse Sapling address"
pUnifiedAddress :: Parser MemoToken
pUnifiedAddress = do