From 9471a861c64bc72f45323957ff14e61ff8f6350f Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Tue, 9 Apr 2024 13:32:39 -0500 Subject: [PATCH] Add function to check commitment trees --- CHANGELOG.md | 1 + src/Zenith/Core.hs | 18 ++++++++++++++++++ src/Zenith/Types.hs | 24 +++++++++++++++++++++++- zcash-haskell | 2 +- 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20a7a48..64ce3a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 Sapling notes +- Function to query `zebrad` for commitment trees ### Changed diff --git a/src/Zenith/Core.hs b/src/Zenith/Core.hs index 4a63066..cdfc0c5 100644 --- a/src/Zenith/Core.hs +++ b/src/Zenith/Core.hs @@ -32,6 +32,7 @@ import Zenith.Types , TransparentSpendingKeyDB(..) , UnifiedAddressDB(..) , ZcashNetDB(..) + , ZebraTreeInfo(..) ) -- * Zebra Node interaction @@ -57,6 +58,23 @@ checkBlockChain nodeHost nodePort = do Left e -> throwIO $ userError e 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 -- | Create an Orchard Spending Key for the given wallet and account index createOrchardSpendingKey :: ZcashWallet -> Int -> IO OrchardSpendingKey diff --git a/src/Zenith/Types.hs b/src/Zenith/Types.hs index 33a946b..b4447bb 100644 --- a/src/Zenith/Types.hs +++ b/src/Zenith/Types.hs @@ -10,7 +10,6 @@ module Zenith.Types where import Data.Aeson -import Data.Aeson.Types (prependFailure, typeMismatch) import qualified Data.ByteString as BS import qualified Data.ByteString.Base64 as B64 import qualified Data.ByteString.Char8 as C @@ -80,6 +79,29 @@ newtype TransparentSpendingKeyDB = TransparentSpendingKeyDB derivePersistField "TransparentSpendingKeyDB" -- * 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 data AddressSource = LegacyRandom diff --git a/zcash-haskell b/zcash-haskell index 817c52d..ea937f8 160000 --- a/zcash-haskell +++ b/zcash-haskell @@ -1 +1 @@ -Subproject commit 817c52dacf37b95c81c5ad8c59b6b6783e9c498d +Subproject commit ea937f8e5127f64be94bde06e5f1571df8dfbbde