Unified Address support #8
1 changed files with 25 additions and 19 deletions
22
src/ZGoTx.hs
22
src/ZGoTx.hs
|
@ -9,16 +9,17 @@ import qualified Data.Bson as B
|
|||
import Data.Char
|
||||
import Data.Maybe
|
||||
import qualified Data.Text as T
|
||||
import qualified Data.Text.Encoding as E
|
||||
import qualified Data.UUID as U
|
||||
import Data.Void
|
||||
import Database.MongoDB
|
||||
import GHC.Generics
|
||||
import Text.Megaparsec hiding (State)
|
||||
import Text.Megaparsec.Char
|
||||
import ZcashHaskell.Orchard
|
||||
|
||||
-- | Type to model a ZGo transaction
|
||||
data ZGoTx =
|
||||
ZGoTx
|
||||
data ZGoTx = ZGoTx
|
||||
{ _id :: Maybe ObjectId
|
||||
, address :: T.Text
|
||||
, session :: T.Text
|
||||
|
@ -27,8 +28,7 @@ data ZGoTx =
|
|||
, amount :: Double
|
||||
, txid :: T.Text
|
||||
, memo :: T.Text
|
||||
}
|
||||
deriving (Eq, Show, Generic)
|
||||
} deriving (Eq, Show, Generic)
|
||||
|
||||
parseZGoTxBson :: B.Document -> Maybe ZGoTx
|
||||
parseZGoTxBson d = do
|
||||
|
@ -100,13 +100,11 @@ instance Val ZGoTx where
|
|||
]
|
||||
|
||||
-- | Type to represent and parse ZGo memos
|
||||
data ZGoMemo =
|
||||
ZGoMemo
|
||||
data ZGoMemo = ZGoMemo
|
||||
{ m_session :: Maybe U.UUID
|
||||
, m_address :: Maybe T.Text
|
||||
, m_payment :: Bool
|
||||
}
|
||||
deriving (Eq, Show)
|
||||
} deriving (Eq, Show)
|
||||
|
||||
data MemoToken
|
||||
= Login !U.UUID
|
||||
|
@ -139,6 +137,14 @@ pSaplingAddress = do
|
|||
then fail "Failed to parse Sapling address"
|
||||
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 = do
|
||||
msg <-
|
||||
|
|
Loading…
Reference in a new issue