Account for missing response fields in Zebra response #43

Merged
pitmutt merged 9 commits from rav001 into dev040 2024-03-22 18:04:05 +00:00
3 changed files with 33 additions and 2 deletions
Showing only changes of commit 9c8a851ead - Show all commits

View file

@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [0.5.1.0] ## [0.5.1.0]
### Added
- Functionality to capture Sapling Spends
### Changed ### Changed
- Modified the `makeZebraCall` function to handle errors explicitly - Modified the `makeZebraCall` function to handle errors explicitly

View file

@ -90,11 +90,13 @@ instance FromJSON RawTxResponse where
ht <- obj .: "height" ht <- obj .: "height"
c <- obj .: "confirmations" c <- obj .: "confirmations"
b <- obj .: "blocktime" b <- obj .: "blocktime"
sSpend <- obj .: "vShieldedSpend"
case o of case o of
Nothing -> pure $ RawTxResponse i h (getShieldedOutputs h) [] ht c b Nothing ->
pure $ RawTxResponse i h sSpend (getShieldedOutputs h) [] ht c b
Just o' -> do Just o' -> do
a <- o' .: "actions" a <- o' .: "actions"
pure $ RawTxResponse i h (getShieldedOutputs h) a ht c b pure $ RawTxResponse i h sSpend (getShieldedOutputs h) a ht c b
-- | Attempts to obtain a sapling SpendingKey using a HDSeed -- | Attempts to obtain a sapling SpendingKey using a HDSeed
genSaplingSpendingKey :: Seed -> CoinType -> Int -> Maybe SaplingSpendingKey genSaplingSpendingKey :: Seed -> CoinType -> Int -> Maybe SaplingSpendingKey

View file

@ -207,6 +207,7 @@ instance FromJSON BlockResponse where
data RawTxResponse = RawTxResponse data RawTxResponse = RawTxResponse
{ rt_id :: !HexString { rt_id :: !HexString
, rt_hex :: !HexString , rt_hex :: !HexString
, rt_shieldedSpends :: ![ShieldedSpend]
, rt_shieldedOutputs :: ![BS.ByteString] , rt_shieldedOutputs :: ![BS.ByteString]
, rt_orchardActions :: ![OrchardAction] , rt_orchardActions :: ![OrchardAction]
, rt_blockheight :: !Integer , rt_blockheight :: !Integer
@ -283,6 +284,30 @@ newtype SaplingReceiver =
instance ToBytes SaplingReceiver where instance ToBytes SaplingReceiver where
getBytes (SaplingReceiver s) = s getBytes (SaplingReceiver s) = s
-- | Type to represent a Sapling Shielded Spend as provided by the @getrawtransaction@ RPC method
data ShieldedSpend = ShieldedSpend
{ sp_cv :: !HexString
, sp_anchor :: !HexString
, sp_nullifier :: !HexString
, sp_rk :: !HexString
, sp_proof :: !HexString
, sp_auth :: !HexString
} deriving stock (Eq, Prelude.Show, GHC.Generic, Read)
deriving anyclass (SOP.Generic, SOP.HasDatatypeInfo)
deriving anyclass (Data.Structured.Show)
deriving (BorshSize, ToBorsh, FromBorsh) via AsStruct ShieldedSpend
instance FromJSON ShieldedSpend where
parseJSON =
withObject "ShieldedSpend" $ \obj -> do
cv <- obj .: "cv"
anchor <- obj .: "anchor"
nullifier <- obj .: "nullifier"
rk <- obj .: "rk"
p <- obj .: "proof"
sig <- obj .: "spendAuthSig"
pure $ ShieldedSpend cv anchor nullifier rk p sig
-- | Type to represent a Sapling Shielded Output as provided by the @getrawtransaction@ RPC method of @zcashd@. -- | Type to represent a Sapling Shielded Output as provided by the @getrawtransaction@ RPC method of @zcashd@.
data ShieldedOutput = ShieldedOutput data ShieldedOutput = ShieldedOutput
{ s_cv :: !HexString -- ^ Value commitment to the input note { s_cv :: !HexString -- ^ Value commitment to the input note