Skip to content

Commit b6dc6f8

Browse files
committed
fix(Transaction): prevent regeneration of manually set TransactionId
1 parent 1278dbb commit b6dc6f8

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/sdk/main/src/Transaction.cc

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,18 @@ struct Transaction<SdkRequestType>::TransactionImpl
150150
* The public key of the trusted batch assembler.
151151
*/
152152
std::shared_ptr<Key> mBatchKey = nullptr;
153+
/**
154+
*
155+
* This flag is used to determine whether a Transaction's TransactionId
156+
* should be regenerated if the Transaction expires.
157+
*
158+
* - If `mTransactionIdManualSet` is true, the TransactionId was set manually by the user,
159+
* and it **must not be regenerated**, regardless of the client-wide or transaction-specific
160+
* regeneration policies.
161+
* - If `mTransactionIdManualSet` is false (default), the TransactionId may be regenerated
162+
* based on the transaction's own `mTransactionIdRegenerationPolicy` or the client's policy.
163+
*/
164+
bool mTransactionIdManualSet = false;
153165
};
154166

155167
//-----
@@ -654,6 +666,7 @@ SdkRequestType& Transaction<SdkRequestType>::setTransactionId(const TransactionI
654666
{
655667
requireNotFrozen();
656668
mImpl->mTransactionId = id;
669+
mImpl->mTransactionIdManualSet = true;
657670
return static_cast<SdkRequestType&>(*this);
658671
}
659672

@@ -1245,9 +1258,13 @@ typename Executable<SdkRequestType, proto::Transaction, proto::TransactionRespon
12451258
}
12461259

12471260
bool shouldRegenerate = DEFAULT_REGENERATE_TRANSACTION_ID;
1261+
if (mImpl->mTransactionIdManualSet)
1262+
{
1263+
shouldRegenerate = false;
1264+
}
12481265

12491266
// Follow this Transaction's policy if it has been explicitly set.
1250-
if (mImpl->mTransactionIdRegenerationPolicy.has_value())
1267+
else if (mImpl->mTransactionIdRegenerationPolicy.has_value())
12511268
{
12521269
shouldRegenerate = mImpl->mTransactionIdRegenerationPolicy.value();
12531270
}

0 commit comments

Comments
 (0)