From 0e5f476e282e17e5b5e168f12034aeb12b7a2043 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Sun, 27 Oct 2024 06:27:59 -0500 Subject: [PATCH 1/2] fix: correct fee calculation for shielding --- src/Zenith/Core.hs | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/src/Zenith/Core.hs b/src/Zenith/Core.hs index 45422ee..249e19c 100644 --- a/src/Zenith/Core.hs +++ b/src/Zenith/Core.hs @@ -827,7 +827,6 @@ shieldTransparentNotes pool zebraHost zebraPort znet za bh = do dRecvs forM fNotes $ \trNotes -> do let noteTotal = getTotalAmount (trNotes, [], []) - let fee = calculateTxFee (trNotes, [], []) 4 tSpends <- liftIO $ prepTSpends @@ -839,27 +838,53 @@ shieldTransparentNotes pool zebraHost zebraPort znet za bh = do let oRcvr = fromJust $ o_rec =<< isValidUnifiedAddress (E.encodeUtf8 internalUA) - let snote = + let dummy = OutgoingNote 4 (getBytes $ getOrchSK $ zcashAccountOrchSpendKey $ entityVal acc) (getBytes oRcvr) - (fromIntegral $ noteTotal - fee) + (fromIntegral $ noteTotal - 5000) "" True - let tx = + let feeResponse = createTransaction Nothing Nothing tSpends [] [] - [snote] + [dummy] znet - (bh + 3) - True - logDebugN $ T.pack $ show tx - return tx + bh + False + case feeResponse of + Left e1 -> return $ Left Fee + Right fee -> do + let feeAmt = + fromIntegral + (runGet getInt64le $ LBS.fromStrict $ toBytes fee) + let snote = + OutgoingNote + 4 + (getBytes $ + getOrchSK $ zcashAccountOrchSpendKey $ entityVal acc) + (getBytes oRcvr) + (fromIntegral $ noteTotal - feeAmt) + "" + True + let tx = + createTransaction + Nothing + Nothing + tSpends + [] + [] + [snote] + znet + (bh + 3) + True + logDebugN $ T.pack $ show tx + return tx where getTotalAmount :: ( [Entity WalletTrNote] From 723d1b4e1cf7ae865d65399c42f5385c3065e109 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Sun, 27 Oct 2024 06:37:07 -0500 Subject: [PATCH 2/2] docs: update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d019ed..abbf77e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `getoperationstatus` RPC method - `sendmany` RPC method - Function `prepareTxV2` implementing `PrivacyPolicy` +- Functionality to shield transparent balance +- Functionality to de-shield shielded notes ### Changed