@@ -3958,30 +3958,33 @@ bool CWallet::ApplyMigrationData(MigrationData& data, bilingual_str& error)
3958
3958
}
3959
3959
}
3960
3960
for (const auto & [_pos, wtx] : wtxOrdered) {
3961
- if (!IsMine (*wtx->tx ) && !IsFromMe (*wtx->tx )) {
3962
- // Check it is the watchonly wallet's
3963
- // solvable_wallet doesn't need to be checked because transactions for those scripts weren't being watched for
3964
- if (data.watchonly_wallet ) {
3965
- LOCK (data.watchonly_wallet ->cs_wallet );
3966
- if (data.watchonly_wallet ->IsMine (*wtx->tx ) || data.watchonly_wallet ->IsFromMe (*wtx->tx )) {
3967
- // Add to watchonly wallet
3968
- const uint256& hash = wtx->GetHash ();
3969
- const CWalletTx& to_copy_wtx = *wtx;
3970
- if (!data.watchonly_wallet ->LoadToWallet (hash, [&](CWalletTx& ins_wtx, bool new_tx) EXCLUSIVE_LOCKS_REQUIRED (data.watchonly_wallet ->cs_wallet ) {
3971
- if (!new_tx) return false ;
3972
- ins_wtx.SetTx (to_copy_wtx.tx );
3973
- ins_wtx.CopyFrom (to_copy_wtx);
3974
- return true ;
3975
- })) {
3976
- error = strprintf (_ (" Error: Could not add watchonly tx %s to watchonly wallet" ), wtx->GetHash ().GetHex ());
3977
- return false ;
3978
- }
3979
- watchonly_batch->WriteTx (data.watchonly_wallet ->mapWallet .at (hash));
3980
- // Mark as to remove from this wallet
3961
+ // Check it is the watchonly wallet's
3962
+ // solvable_wallet doesn't need to be checked because transactions for those scripts weren't being watched for
3963
+ bool is_mine = IsMine (*wtx->tx ) || IsFromMe (*wtx->tx );
3964
+ if (data.watchonly_wallet ) {
3965
+ LOCK (data.watchonly_wallet ->cs_wallet );
3966
+ if (data.watchonly_wallet ->IsMine (*wtx->tx ) || data.watchonly_wallet ->IsFromMe (*wtx->tx )) {
3967
+ // Add to watchonly wallet
3968
+ const uint256& hash = wtx->GetHash ();
3969
+ const CWalletTx& to_copy_wtx = *wtx;
3970
+ if (!data.watchonly_wallet ->LoadToWallet (hash, [&](CWalletTx& ins_wtx, bool new_tx) EXCLUSIVE_LOCKS_REQUIRED (data.watchonly_wallet ->cs_wallet ) {
3971
+ if (!new_tx) return false ;
3972
+ ins_wtx.SetTx (to_copy_wtx.tx );
3973
+ ins_wtx.CopyFrom (to_copy_wtx);
3974
+ return true ;
3975
+ })) {
3976
+ error = strprintf (_ (" Error: Could not add watchonly tx %s to watchonly wallet" ), wtx->GetHash ().GetHex ());
3977
+ return false ;
3978
+ }
3979
+ watchonly_batch->WriteTx (data.watchonly_wallet ->mapWallet .at (hash));
3980
+ // Mark as to remove from the migrated wallet only if it does not also belong to it
3981
+ if (!is_mine) {
3981
3982
txids_to_delete.push_back (hash);
3982
- continue ;
3983
3983
}
3984
+ continue ;
3984
3985
}
3986
+ }
3987
+ if (!is_mine) {
3985
3988
// Both not ours and not in the watchonly wallet
3986
3989
error = strprintf (_ (" Error: Transaction %s in wallet cannot be identified to belong to migrated wallets" ), wtx->GetHash ().GetHex ());
3987
3990
return false ;
0 commit comments