Add function to check commitment trees

This commit is contained in:
Rene Vergara 2024-04-09 13:32:39 -05:00
parent 0543c1141c
commit 9471a861c6
Signed by: pitmutt
GPG Key ID: 65122AD495A7F5B2
4 changed files with 43 additions and 2 deletions

View File

@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Functions to scan relevant transparent notes - Functions to scan relevant transparent notes
- Functions to scan relevant Sapling notes - Functions to scan relevant Sapling notes
- Function to query `zebrad` for commitment trees
### Changed ### Changed

View File

@ -32,6 +32,7 @@ import Zenith.Types
, TransparentSpendingKeyDB(..) , TransparentSpendingKeyDB(..)
, UnifiedAddressDB(..) , UnifiedAddressDB(..)
, ZcashNetDB(..) , ZcashNetDB(..)
, ZebraTreeInfo(..)
) )
-- * Zebra Node interaction -- * Zebra Node interaction
@ -57,6 +58,23 @@ checkBlockChain nodeHost nodePort = do
Left e -> throwIO $ userError e Left e -> throwIO $ userError e
Right bci -> return bci Right bci -> return bci
-- | Get commitment trees from Zebra
getCommitmentTrees ::
T.Text -- ^ Host where `zebrad` is avaiable
-> Int -- ^ Port where `zebrad` is available
-> Int -- ^ Block height
-> IO ZebraTreeInfo
getCommitmentTrees nodeHost nodePort block = do
r <-
makeZebraCall
nodeHost
nodePort
"z_gettreestate"
[Data.Aeson.String $ T.pack $ show block]
case r of
Left e -> throwIO $ userError e
Right zti -> return zti
-- * Spending Keys -- * Spending Keys
-- | Create an Orchard Spending Key for the given wallet and account index -- | Create an Orchard Spending Key for the given wallet and account index
createOrchardSpendingKey :: ZcashWallet -> Int -> IO OrchardSpendingKey createOrchardSpendingKey :: ZcashWallet -> Int -> IO OrchardSpendingKey

View File

@ -10,7 +10,6 @@
module Zenith.Types where module Zenith.Types where
import Data.Aeson import Data.Aeson
import Data.Aeson.Types (prependFailure, typeMismatch)
import qualified Data.ByteString as BS import qualified Data.ByteString as BS
import qualified Data.ByteString.Base64 as B64 import qualified Data.ByteString.Base64 as B64
import qualified Data.ByteString.Char8 as C import qualified Data.ByteString.Char8 as C
@ -80,6 +79,29 @@ newtype TransparentSpendingKeyDB = TransparentSpendingKeyDB
derivePersistField "TransparentSpendingKeyDB" derivePersistField "TransparentSpendingKeyDB"
-- * RPC -- * RPC
-- ** `zebrad`
-- | Type for modeling the tree state response
data ZebraTreeInfo = ZebraTreeInfo
{ ztiHeight :: !Int
, ztiTime :: !Int
, ztiSapling :: !HexString
, ztiOrchard :: !HexString
} deriving (Eq, Show, Read)
instance FromJSON ZebraTreeInfo where
parseJSON =
withObject "ZebraTreeInfo" $ \obj -> do
h <- obj .: "height"
t <- obj .: "time"
s <- obj .: "sapling"
o <- obj .: "orchard"
sc <- s .: "commitments"
oc <- o .: "commitments"
sf <- sc .: "finalState"
ocf <- oc .: "finalState"
pure $ ZebraTreeInfo h t sf ocf
-- ** `zcashd`
-- | Type for modelling the different address sources for `zcashd` 5.0.0 -- | Type for modelling the different address sources for `zcashd` 5.0.0
data AddressSource data AddressSource
= LegacyRandom = LegacyRandom

@ -1 +1 @@
Subproject commit 817c52dacf37b95c81c5ad8c59b6b6783e9c498d Subproject commit ea937f8e5127f64be94bde06e5f1571df8dfbbde