Change Zcash scan to use parser
This commit is contained in:
parent
e437da2841
commit
63d372c2d5
4 changed files with 41 additions and 24 deletions
|
@ -11,12 +11,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
- New type to handle UI translation objects
|
- New type to handle UI translation objects
|
||||||
- New endpoints for API to get/set translation
|
- New endpoints for API to get/set translation
|
||||||
- Tests for translation endpoints
|
- Tests for translation endpoints
|
||||||
|
- Formal parser of ZGo-related tokens in memos
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Remove old code for PIN generation
|
- Remove old code for PIN generation
|
||||||
- Xero reference field to include the amount of ZEC received
|
- Xero reference field to include the amount of ZEC received
|
||||||
- Separate periodic tasks from API server
|
- Separate periodic tasks from API server
|
||||||
|
- Zcash transaction monitoring changed to use memo parser
|
||||||
|
|
||||||
## [1.2.5] - 2023-02-01
|
## [1.2.5] - 2023-02-01
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
module Server where
|
module Server where
|
||||||
|
|
||||||
import Config
|
import Config
|
||||||
import Control.Concurrent (forkIO)
|
|
||||||
|
--import Control.Concurrent (forkIO)
|
||||||
import Database.MongoDB
|
import Database.MongoDB
|
||||||
import Network.Wai.Handler.Warp (defaultSettings, setPort)
|
import Network.Wai.Handler.Warp (defaultSettings, setPort)
|
||||||
import Network.Wai.Handler.WarpTLS (runTLS, tlsSettings)
|
import Network.Wai.Handler.WarpTLS (runTLS, tlsSettings)
|
||||||
|
@ -30,12 +31,12 @@ main = do
|
||||||
if j
|
if j
|
||||||
then putStrLn "Connected to MongoDB!"
|
then putStrLn "Connected to MongoDB!"
|
||||||
else fail "MongoDB connection failed!"
|
else fail "MongoDB connection failed!"
|
||||||
_ <- forkIO (setInterval 60 (checkZcashPrices pipe (c_dbName loadedConfig)))
|
{-_ <- forkIO (setInterval 60 (checkZcashPrices pipe (c_dbName loadedConfig)))-}
|
||||||
_ <- forkIO (setInterval 75 (scanZcash loadedConfig pipe))
|
{-_ <- forkIO (setInterval 75 (scanZcash loadedConfig pipe))-}
|
||||||
_ <- forkIO (setInterval 90 (scanPayments loadedConfig pipe))
|
{-_ <- forkIO (setInterval 90 (scanPayments loadedConfig pipe))-}
|
||||||
_ <- forkIO (setInterval 60 (checkPayments pipe (c_dbName loadedConfig)))
|
{-_ <- forkIO (setInterval 60 (checkPayments pipe (c_dbName loadedConfig)))-}
|
||||||
_ <- forkIO (setInterval 60 (expireOwners pipe (c_dbName loadedConfig)))
|
{-_ <- forkIO (setInterval 60 (expireOwners pipe (c_dbName loadedConfig)))-}
|
||||||
_ <- forkIO (setInterval 60 (updateLogins pipe loadedConfig))
|
{-_ <- forkIO (setInterval 60 (updateLogins pipe loadedConfig))-}
|
||||||
let appRoutes = routes pipe loadedConfig
|
let appRoutes = routes pipe loadedConfig
|
||||||
case myTlsSettings of
|
case myTlsSettings of
|
||||||
Nothing -> scotty (c_port loadedConfig) appRoutes
|
Nothing -> scotty (c_port loadedConfig) appRoutes
|
||||||
|
|
|
@ -4,7 +4,6 @@ module Tasks where
|
||||||
|
|
||||||
import Config
|
import Config
|
||||||
import Database.MongoDB
|
import Database.MongoDB
|
||||||
import Text.Megaparsec hiding (State)
|
|
||||||
import ZGoBackend
|
import ZGoBackend
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
|
@ -23,7 +22,7 @@ main = do
|
||||||
then do
|
then do
|
||||||
putStrLn "Connected to MongoDB!"
|
putStrLn "Connected to MongoDB!"
|
||||||
checkZcashPrices pipe (c_dbName loadedConfig)
|
checkZcashPrices pipe (c_dbName loadedConfig)
|
||||||
scanZcash loadedConfig pipe
|
scanZcash' loadedConfig pipe
|
||||||
scanPayments loadedConfig pipe
|
scanPayments loadedConfig pipe
|
||||||
checkPayments pipe (c_dbName loadedConfig)
|
checkPayments pipe (c_dbName loadedConfig)
|
||||||
expireOwners pipe (c_dbName loadedConfig)
|
expireOwners pipe (c_dbName loadedConfig)
|
||||||
|
|
|
@ -357,11 +357,13 @@ zToZGoTx (ZcashTx t a aZ bh bt c conf m) = do
|
||||||
ZGoTx Nothing nAddy sess conf bt a t m
|
ZGoTx Nothing nAddy sess conf bt a t m
|
||||||
else ZGoTx Nothing "" "" conf bt a t m
|
else ZGoTx Nothing "" "" conf bt a t m
|
||||||
|
|
||||||
zToZGoTx' :: ZcashTx -> ZGoTx
|
zToZGoTx' :: Config -> Pipe -> ZcashTx -> IO ()
|
||||||
zToZGoTx' (ZcashTx t a aZ bh bt c conf m) = do
|
zToZGoTx' config pipe (ZcashTx t a aZ bh bt c conf m) = do
|
||||||
|
when (conf < 100) $ do
|
||||||
let zM = runParser pZGoMemo (T.unpack t) m
|
let zM = runParser pZGoMemo (T.unpack t) m
|
||||||
case zM of
|
case zM of
|
||||||
Right zM' ->
|
Right zM' -> do
|
||||||
|
let tx =
|
||||||
ZGoTx
|
ZGoTx
|
||||||
Nothing
|
Nothing
|
||||||
(fromMaybe "" $ m_address zM')
|
(fromMaybe "" $ m_address zM')
|
||||||
|
@ -371,6 +373,9 @@ zToZGoTx' (ZcashTx t a aZ bh bt c conf m) = do
|
||||||
a
|
a
|
||||||
t
|
t
|
||||||
m
|
m
|
||||||
|
if m_payment zM'
|
||||||
|
then upsertPayment pipe (c_dbName config) tx
|
||||||
|
else access pipe master (c_dbName config) $ upsertZGoTx "txs" tx
|
||||||
Left e -> error "Failed to parse ZGo memo"
|
Left e -> error "Failed to parse ZGo memo"
|
||||||
|
|
||||||
-- |Type to model a price in the ZGo database
|
-- |Type to model a price in the ZGo database
|
||||||
|
@ -1160,6 +1165,16 @@ isRelevant re t
|
||||||
| zconfirmations t < 100 && (matchTest re . T.unpack . zmemo) t = True
|
| zconfirmations t < 100 && (matchTest re . T.unpack . zmemo) t = True
|
||||||
| otherwise = False
|
| otherwise = False
|
||||||
|
|
||||||
|
-- | New function to scan transactions with parser
|
||||||
|
scanZcash' :: Config -> Pipe -> IO ()
|
||||||
|
scanZcash' config pipe = do
|
||||||
|
myTxs <-
|
||||||
|
listTxs (c_nodeUser config) (c_nodePwd config) (c_nodeAddress config) 1
|
||||||
|
case myTxs of
|
||||||
|
Right txs -> mapM_ (zToZGoTx' config pipe) txs
|
||||||
|
Left e -> do
|
||||||
|
putStrLn $ "Error scanning node transactions: " ++ T.unpack e
|
||||||
|
|
||||||
-- | Function to scan loaded viewing keys for payments
|
-- | Function to scan loaded viewing keys for payments
|
||||||
scanPayments :: Config -> Pipe -> IO ()
|
scanPayments :: Config -> Pipe -> IO ()
|
||||||
scanPayments config pipe = do
|
scanPayments config pipe = do
|
||||||
|
|
Loading…
Reference in a new issue