diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b90b6e..20a7a48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.4.5.0] + +### Added + +- Functions to scan relevant transparent notes +- Functions to scan relevant Sapling notes + +### Changed + +- Update `zcash-haskell` + ## [0.4.4.3] ### Added diff --git a/src/Zenith/Core.hs b/src/Zenith/Core.hs index 912f9fe..4a63066 100644 --- a/src/Zenith/Core.hs +++ b/src/Zenith/Core.hs @@ -169,4 +169,13 @@ syncWallet walletDb w = do addrs <- concat <$> mapM (getAddresses walletDb . entityKey) accs lastBlock <- getMaxWalletBlock walletDb trNotes <- mapM (findTransparentNotes walletDb lastBlock . entityVal) addrs - return $ show trNotes + sapNotes <- + mapM + (findSaplingOutputs walletDb lastBlock (zcashWalletNetwork $ entityVal w) . + zcashAccountSapSpendKey . entityVal) + accs + print "Transparent Notes: " + print trNotes + print "Sapling notes: " + print sapNotes + return "Testing" diff --git a/src/Zenith/DB.hs b/src/Zenith/DB.hs index 88704f6..421cd1c 100644 --- a/src/Zenith/DB.hs +++ b/src/Zenith/DB.hs @@ -19,6 +19,7 @@ module Zenith.DB where import Control.Monad (when) +import Data.Bifunctor import qualified Data.ByteString as BS import Data.HexString import Data.Maybe (fromJust, isJust) @@ -35,8 +36,10 @@ import Haskoin.Transaction.Common , txHashToHex ) import ZcashHaskell.Orchard (isValidUnifiedAddress) +import ZcashHaskell.Sapling (decodeSaplingOutputEsk) import ZcashHaskell.Types - ( OrchardAction(..) + ( DecodedNote(..) + , OrchardAction(..) , OrchardBundle(..) , SaplingBundle(..) , Scope(..) @@ -474,6 +477,48 @@ saveWalletTrNote dbPath (zt, tn) wa = do (entityKey tn) False +-- | Find the Sapling notes that match the given spending key +findSaplingOutputs :: + T.Text -- ^ the database path + -> Int -- ^ the starting block + -> ZcashNetDB -- ^ The network + -> SaplingSpendingKeyDB -- ^ The spending key to trial decrypt + -> IO [(Entity ZcashTransaction, DecodedNote)] +findSaplingOutputs dbPath b znet sk = do + r <- + PS.runSqlite dbPath $ do + select $ do + (txs :& sOutputs) <- + from $ table @ZcashTransaction `innerJoin` table @ShieldOutput `on` + (\(txs :& sOutputs) -> + txs ^. ZcashTransactionId ==. sOutputs ^. ShieldOutputTx) + where_ (txs ^. ZcashTransactionBlock >. val b) + pure (txs, sOutputs) + let decryptedList = + map (saplingTrialDecrypt External (getNet znet)) r <> + map (saplingTrialDecrypt Internal (getNet znet)) r + return $ map (second fromJust) $ filter (\(z, n) -> isJust n) decryptedList + where + saplingTrialDecrypt :: + Scope + -> ZcashNet + -> (Entity ZcashTransaction, Entity ShieldOutput) + -> (Entity ZcashTransaction, Maybe DecodedNote) + saplingTrialDecrypt sc n (zt, so) = (zt, decodeShOut sc n so) + decodeShOut :: Scope -> ZcashNet -> Entity ShieldOutput -> Maybe DecodedNote + decodeShOut scope n s = + decodeSaplingOutputEsk + (getSapSK sk) + (ShieldedOutput + (getHex $ shieldOutputCv $ entityVal s) + (getHex $ shieldOutputCmu $ entityVal s) + (getHex $ shieldOutputEphKey $ entityVal s) + (getHex $ shieldOutputEncCipher $ entityVal s) + (getHex $ shieldOutputOutCipher $ entityVal s) + (getHex $ shieldOutputProof $ entityVal s)) + n + scope + -- | Helper function to extract a Unified Address from the database readUnifiedAddressDB :: WalletAddress -> Maybe UnifiedAddress readUnifiedAddressDB = diff --git a/zcash-haskell b/zcash-haskell index 2709d42..817c52d 160000 --- a/zcash-haskell +++ b/zcash-haskell @@ -1 +1 @@ -Subproject commit 2709d422667080527ccc180e97352693a4c6c2c7 +Subproject commit 817c52dacf37b95c81c5ad8c59b6b6783e9c498d diff --git a/zenith.cabal b/zenith.cabal index f78e7ed..7a5a24e 100644 --- a/zenith.cabal +++ b/zenith.cabal @@ -1,6 +1,6 @@ cabal-version: 3.0 name: zenith -version: 0.4.4.3 +version: 0.4.5.0 license: MIT license-file: LICENSE author: Rene Vergara