Skip to content

Commit 362366b

Browse files
committed
BugFix: sapling operation, only set the final transaction at the end of the process.
And migrate the member type to CTransactionRef.
1 parent 28aec49 commit 362366b

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/sapling/sapling_operation.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,11 @@ OperationResult SaplingOperation::build()
177177
if (!opTx) {
178178
return errorOut("Failed to build transaction: " + txResult.GetError());
179179
}
180-
finalTx.reset();
181-
finalTx = MakeTransactionRef(*opTx);
182180

183181
// Now check fee
184-
bool isShielded = finalTx->IsShieldedTx();
185-
const CAmount& nFeeNeeded = isShielded ? GetShieldedTxMinFee(*finalTx) :
186-
GetMinRelayFee(finalTx->GetTotalSize(), false);
182+
bool isShielded = opTx->IsShieldedTx();
183+
const CAmount& nFeeNeeded = isShielded ? GetShieldedTxMinFee(*opTx) :
184+
GetMinRelayFee(opTx->GetTotalSize(), false);
187185
if (nFeeNeeded <= nFeeRet) {
188186
// Check that the fee is not too high.
189187
CAmount nMaxFee = nFeeNeeded * (isShielded ? 100 : 10000);
@@ -223,7 +221,6 @@ OperationResult SaplingOperation::build()
223221
if (!opTx) {
224222
return errorOut("Failed to build transaction: " + txResult.GetError());
225223
}
226-
finalTx.reset();
227224
finalTx = MakeTransactionRef(*opTx);
228225
return OperationResult(true);
229226
}

src/test/librust/sapling_rpc_wallet_tests.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,9 @@ BOOST_AUTO_TEST_CASE(rpc_shieldsendmany_taddr_to_sapling)
408408
// Add a fake transaction to the wallet
409409
CMutableTransaction mtx;
410410
mtx.vout.emplace_back(5 * COIN, GetScriptForDestination(taddr));
411-
CWalletTx wtx(pwalletMain, MakeTransactionRef(mtx));
412-
pwalletMain->LoadToWallet(wtx);
411+
// Add to wallet and get the updated wtx
412+
pwalletMain->LoadToWallet({pwalletMain, MakeTransactionRef(mtx)});
413+
CWalletTx& wtx = pwalletMain->mapWallet.at(mtx.GetHash());
413414

414415
// Fake-mine the transaction
415416
BOOST_CHECK_EQUAL(0, chainActive.Height());
@@ -426,6 +427,7 @@ BOOST_AUTO_TEST_CASE(rpc_shieldsendmany_taddr_to_sapling)
426427
BOOST_CHECK_EQUAL(1, chainActive.Height());
427428
wtx.SetMerkleBranch(blockHash, 0);
428429
pwalletMain->LoadToWallet(wtx);
430+
BOOST_CHECK_MESSAGE(pwalletMain->GetAvailableBalance() > 0, "tx not confirmed");
429431

430432
// Context that shieldsendmany requires
431433
auto builder = TransactionBuilder(consensusParams, nextBlockHeight, pwalletMain);

0 commit comments

Comments
 (0)