From f632b48f324bc75b0f18252d143511903b402256 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Tue, 20 Jun 2023 07:54:24 -0500 Subject: [PATCH] Add parameter for confirmation window --- src/Config.hs | 3 +++ src/ZGoBackend.hs | 34 ++++------------------------------ zgo.cfg | 1 + zgotest.cfg | 1 + 4 files changed, 9 insertions(+), 30 deletions(-) diff --git a/src/Config.hs b/src/Config.hs index 9455cca..0804305 100644 --- a/src/Config.hs +++ b/src/Config.hs @@ -26,6 +26,7 @@ data Config = , c_smtpPort :: Integer , c_smtpUser :: String , c_smtpPwd :: String + , c_confirmations :: Integer } deriving (Eq, Show) @@ -48,6 +49,7 @@ loadZGoConfig path = do mailPort <- require config "smtpPort" mailUser <- require config "smtpUser" mailPwd <- require config "smtpPwd" + conf <- require config "confirmations" return $ Config dbHost @@ -66,3 +68,4 @@ loadZGoConfig path = do mailPort mailUser mailPwd + conf diff --git a/src/ZGoBackend.hs b/src/ZGoBackend.hs index 603eea8..675a665 100644 --- a/src/ZGoBackend.hs +++ b/src/ZGoBackend.hs @@ -1388,36 +1388,10 @@ listTxs user pwd a confs = do Just e -> return $ Left $ "Error reading transactions: " <> emessage e Left ex -> return $ Left $ (T.pack . show) ex --- | Function to check the ZGo full node for new txs -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 -> do - let r = - mkRegex - ".*ZGO::([0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12})\\sReply-To:\\s(zs[a-z0-9]{76}).*" - let p = - mkRegex - ".*ZGOp::([0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}).*" - let y = - mkRegex - ".*MSG\\s(zs[a-z0-9]{76})\\s+ZGO::([0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}).*" - let k = map zToZGoTx (filter (isRelevant r) txs) - mapM_ (access pipe master (c_dbName config) . upsertZGoTx "txs") k - let j = map zToZGoTx (filter (isRelevant p) txs) - mapM_ (upsertPayment pipe (c_dbName config)) j - let l = map zToZGoTx (filter (isRelevant y) txs) - mapM_ (access pipe master (c_dbName config) . upsertZGoTx "txs") l - Left e -> do - putStrLn $ "Error scanning node transactions: " ++ T.unpack e - return () - -- | Function to filter transactions -isRelevant :: Text.Regex.Regex -> ZcashTx -> Bool -isRelevant re t - | zconfirmations t < 100 && (matchTest re . T.unpack . zmemo) t = True +isRelevant :: Integer -> Text.Regex.Regex -> ZcashTx -> Bool +isRelevant conf re t + | zconfirmations t < conf && (matchTest re . T.unpack . zmemo) t = True | otherwise = False -- | New function to scan transactions with parser @@ -1447,7 +1421,7 @@ scanPayments config pipe = do case paidTxs of Right txs -> do let r = mkRegex ".*ZGo Order::([0-9a-fA-F]{24}).*" - let k = filter (isRelevant r) txs + let k = filter (isRelevant (c_confirmations c) r) txs print k let j = map (getOrderId r) k mapM_ (recordPayment p (c_dbName config) z) j diff --git a/zgo.cfg b/zgo.cfg index 1502706..d7db771 100644 --- a/zgo.cfg +++ b/zgo.cfg @@ -6,6 +6,7 @@ dbUser = "zgo" dbPassword = "zcashrules" nodeUser = "zecwallet" nodePassword = "rdsxlun6v4a" +confirmations = 100 port = 3000 tls = false certificate = "/path/to/cert.pem" diff --git a/zgotest.cfg b/zgotest.cfg index 4fc6230..a703b28 100644 --- a/zgotest.cfg +++ b/zgotest.cfg @@ -6,6 +6,7 @@ dbUser = "zgo" dbPassword = "zcashrules" nodeUser = "zecwallet" nodePassword = "rdsxlun6v4a" +confirmations = 100 port = 3000 tls = false certificate = "/path/to/cert.pem"