Include display of balance and transactions #76

Merged
pitmutt merged 9 commits from rav001 into dev041 2024-04-25 19:25:00 +00:00
5 changed files with 69 additions and 4 deletions
Showing only changes of commit 0543c1141c - Show all commits

View file

@ -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

View file

@ -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"

View file

@ -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 =

@ -1 +1 @@
Subproject commit 2709d422667080527ccc180e97352693a4c6c2c7
Subproject commit 817c52dacf37b95c81c5ad8c59b6b6783e9c498d

View file

@ -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