Add parser for Unified addresses

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

View file

@ -9,16 +9,17 @@ import qualified Data.Bson as B
import Data.Char import Data.Char
import Data.Maybe import Data.Maybe
import qualified Data.Text as T import qualified Data.Text as T
import qualified Data.Text.Encoding as E
import qualified Data.UUID as U import qualified Data.UUID as U
import Data.Void import Data.Void
import Database.MongoDB import Database.MongoDB
import GHC.Generics import GHC.Generics
import Text.Megaparsec hiding (State) import Text.Megaparsec hiding (State)
import Text.Megaparsec.Char import Text.Megaparsec.Char
import ZcashHaskell.Orchard
-- | Type to model a ZGo transaction -- | Type to model a ZGo transaction
data ZGoTx = data ZGoTx = ZGoTx
ZGoTx
{ _id :: Maybe ObjectId { _id :: Maybe ObjectId
, address :: T.Text , address :: T.Text
, session :: T.Text , session :: T.Text
@ -27,8 +28,7 @@ data ZGoTx =
, amount :: Double , amount :: Double
, txid :: T.Text , txid :: T.Text
, memo :: T.Text , memo :: T.Text
} } deriving (Eq, Show, Generic)
deriving (Eq, Show, Generic)
parseZGoTxBson :: B.Document -> Maybe ZGoTx parseZGoTxBson :: B.Document -> Maybe ZGoTx
parseZGoTxBson d = do parseZGoTxBson d = do
@ -100,13 +100,11 @@ instance Val ZGoTx where
] ]
-- | Type to represent and parse ZGo memos -- | Type to represent and parse ZGo memos
data ZGoMemo = data ZGoMemo = ZGoMemo
ZGoMemo
{ m_session :: Maybe U.UUID { m_session :: Maybe U.UUID
, m_address :: Maybe T.Text , m_address :: Maybe T.Text
, m_payment :: Bool , m_payment :: Bool
} } deriving (Eq, Show)
deriving (Eq, Show)
data MemoToken data MemoToken
= Login !U.UUID = Login !U.UUID
@ -139,6 +137,14 @@ pSaplingAddress = do
then fail "Failed to parse Sapling address" then fail "Failed to parse Sapling address"
else pure $ Address $ T.pack ("zs" <> a) else pure $ Address $ T.pack ("zs" <> a)
pUnifiedAddress :: Parser MemoToken
pUnifiedAddress = do
string "u1"
a <- some alphaNumChar
if isValidUnifiedAddress (E.encodeUtf8 $ "u1" <> T.pack a)
then pure $ Address $ T.pack ("u1" <> a)
else fail "Failed to parse Unified Address"
pMsg :: Parser MemoToken pMsg :: Parser MemoToken
pMsg = do pMsg = do
msg <- msg <-