From a2654a6f011abce4c9a4869a1365c422774b1c7d Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Mon, 9 Oct 2023 16:28:17 -0500 Subject: [PATCH] Correct the Sapling vk call --- src/ZGoBackend.hs | 27 ++++++++++++++------------- src/ZGoTx.hs | 2 +- test/Spec.hs | 15 +++++++++------ 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/ZGoBackend.hs b/src/ZGoBackend.hs index fcd0358..cafe0f7 100644 --- a/src/ZGoBackend.hs +++ b/src/ZGoBackend.hs @@ -1176,19 +1176,20 @@ routes pipe config = do case cast' . Doc =<< u of Nothing -> status unauthorized401 Just u' -> do - if isValidSaplingViewingKey qBytes - then if matchSaplingAddress - qBytes - (bytes . decodeBech32 . C.pack . T.unpack $ uaddress u') - then do - owner <- liftAndCatchIO $ run (findOwner $ uaddress u') - case cast' . Doc =<< owner of - Nothing -> status badRequest400 - Just o' -> do - unless (oviewkey o' /= "") $ do - liftAndCatchIO $ run (upsertViewingKey o' q) - status created201 - else status forbidden403 + if isValidSaplingViewingKey $ C.pack q + then do + if matchSaplingAddress + qBytes + (bytes . decodeBech32 . C.pack . T.unpack $ uaddress u') + then do + owner <- liftAndCatchIO $ run (findOwner $ uaddress u') + case cast' . Doc =<< owner of + Nothing -> status badRequest400 + Just o' -> do + unless (oviewkey o' /= "") $ do + liftAndCatchIO $ run (upsertViewingKey o' q) + status created201 + else status forbidden403 else case decodeUfvk (C.pack q) of Nothing -> status badRequest400 Just fvk -> diff --git a/src/ZGoTx.hs b/src/ZGoTx.hs index bf7b3d8..e453346 100644 --- a/src/ZGoTx.hs +++ b/src/ZGoTx.hs @@ -157,7 +157,7 @@ pMsg = do pMemo :: Parser MemoToken pMemo = do optional $ some spaceChar - t <- pSession <|> pSaplingAddress <|> pMsg + t <- pSession <|> pSaplingAddress <|> pUnifiedAddress <|> pMsg optional $ some spaceChar return t diff --git a/test/Spec.hs b/test/Spec.hs index aadaec1..4e53f46 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -101,8 +101,9 @@ main = do case m of Left e -> putStrLn $ errorBundlePretty e Right m' -> - m_session m' `shouldBe` - U.fromString "5d3d4494-51c0-432d-8495-050419957aea" + m_address m' `shouldBe` + Just + "u17n7hpwaujyq7ux8f9jpyymtnk5urw7pyrf60smp5mawy7jgz325hfvz3jn3zsfya8yxryf9q7ldk8nu8df0emra5wne28zq9d9nm2pu4x6qwjha565av9aze0xgujgslz74ufkj0c0cylqwjyrh9msjfh7jzal6d3qzrnhkkqy3pqm8j63y07jxj7txqeac982778rmt64f32aum94x" it "parse YWallet memo - Orchard" $ do let m = runParser @@ -112,8 +113,9 @@ main = do case m of Left e -> putStrLn $ errorBundlePretty e Right m' -> - m_session m' `shouldBe` - U.fromString "ad8477d3-4fdd-4c97-90b2-76630b5f77e1" + m_address m' `shouldBe` + Just + "u17n7hpwaujyq7ux8f9jpyymtnk5urw7pyrf60smp5mawy7jgz325hfvz3jn3zsfya8yxryf9q7ldk8nu8df0emra5wne28zq9d9nm2pu4x6qwjha565av9aze0xgujgslz74ufkj0c0cylqwjyrh9msjfh7jzal6d3qzrnhkkqy3pqm8j63y07jxj7txqeac982778rmt64f32aum94x" it "parse Zingo memo - Orchard" $ do let m = runParser @@ -123,8 +125,9 @@ main = do case m of Left e -> putStrLn $ errorBundlePretty e Right m' -> - m_session m' `shouldBe` - U.fromString "5d3d4494-51c0-432d-8495-050419957aea" + m_address m' `shouldBe` + Just + "u17n7hpwaujyq7ux8f9jpyymtnk5urw7pyrf60smp5mawy7jgz325hfvz3jn3zsfya8yxryf9q7ldk8nu8df0emra5wne28zq9d9nm2pu4x6qwjha565av9aze0xgujgslz74ufkj0c0cylqwjyrh9msjfh7jzal6d3qzrnhkkqy3pqm8j63y07jxj7txqeac982778rmt64f32aum94x" describe "PIN generator" $ do it "should give a 7 digit" $ do pin <- generatePin