From c4f51b6fb866e174c5f1354616dd340e9374a499 Mon Sep 17 00:00:00 2001 From: Dmitry Demin Date: Mon, 7 Aug 2023 10:11:11 +0200 Subject: [PATCH] Fix bad_optional_access and segmentation fault in gtests --- src/transaction_builder.cpp | 5 ++++- src/wallet/wallet_tx_builder.cpp | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/transaction_builder.cpp b/src/transaction_builder.cpp index 4712c05e57c..0fc709c1276 100644 --- a/src/transaction_builder.cpp +++ b/src/transaction_builder.cpp @@ -482,7 +482,10 @@ TransactionBuilderResult TransactionBuilder::Build() // if (change > 0) { - auto asset = orchardBuilder.value().primaryAsset.value(); + // FIXME: orchardBuilder is not set in TransactionBuilder::TransactionBuilder as orchardAnchor passed as nullopt + auto asset = orchardBuilder.has_value() && orchardBuilder.value().primaryAsset.has_value() + ? orchardBuilder.value().primaryAsset.value() + : Asset::Native(); // Send change to the specified change address. If no change address // was set, send change to the first Sapling address given as input // if any; otherwise the first Sprout address given as input. diff --git a/src/wallet/wallet_tx_builder.cpp b/src/wallet/wallet_tx_builder.cpp index dd279bbcdd6..2bb073823e0 100644 --- a/src/wallet/wallet_tx_builder.cpp +++ b/src/wallet/wallet_tx_builder.cpp @@ -535,7 +535,8 @@ AddChangePayment( CAmount targetAmount) { // TODO: This is a hack to get the asset from the first spendable input. We need to implement transaction with multiple assets - auto asset = spendable.orchardNoteMetadata[0].GetAsset(); + // TODO: FIXME: Is this a correct fix? + auto asset = spendable.orchardNoteMetadata.empty() ? Asset::Native() : spendable.orchardNoteMetadata[0].GetAsset(); assert(changeAmount > 0);