diff --git a/src/ZGoTx.hs b/src/ZGoTx.hs index 8f786b8..30e7ef7 100644 --- a/src/ZGoTx.hs +++ b/src/ZGoTx.hs @@ -9,26 +9,26 @@ 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 - { _id :: Maybe ObjectId - , address :: T.Text - , session :: T.Text - , confirmations :: Integer - , blocktime :: Integer - , amount :: Double - , txid :: T.Text - , memo :: T.Text - } - deriving (Eq, Show, Generic) +data ZGoTx = ZGoTx + { _id :: Maybe ObjectId + , address :: T.Text + , session :: T.Text + , confirmations :: Integer + , blocktime :: Integer + , amount :: Double + , txid :: T.Text + , memo :: T.Text + } 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 - { m_session :: Maybe U.UUID - , m_address :: Maybe T.Text - , m_payment :: Bool - } - deriving (Eq, Show) +data ZGoMemo = ZGoMemo + { m_session :: Maybe U.UUID + , m_address :: Maybe T.Text + , m_payment :: Bool + } 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 <-