Add parser for Unified addresses
This commit is contained in:
parent
c58aa2f8c0
commit
528fdebe61
1 changed files with 25 additions and 19 deletions
44
src/ZGoTx.hs
44
src/ZGoTx.hs
|
@ -9,26 +9,26 @@ 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
|
, confirmations :: Integer
|
||||||
, confirmations :: Integer
|
, blocktime :: Integer
|
||||||
, blocktime :: Integer
|
, 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 <-
|
||||||
|
|
Loading…
Reference in a new issue