Skip to content

Commit d01a968

Browse files
committed
wallet: update stored witness in AddToWallet
Replace witness-stripped wallet transactions with full transactions; this can happen when upgrading from a pre-segwit wallet to a segwit- aware wallet.
1 parent ce66586 commit d01a968

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/wallet/wallet.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,15 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
914914
wtx.fFromMe = wtxIn.fFromMe;
915915
fUpdated = true;
916916
}
917+
// If we have a witness-stripped version of this transaction, and we
918+
// see a new version with a witness, then we must be upgrading a pre-segwit
919+
// wallet. Store the new version of the transaction with the witness,
920+
// as the stripped-version must be invalid.
921+
// TODO: Store all versions of the transaction, instead of just one.
922+
if (wtxIn.tx->HasWitness() && !wtx.tx->HasWitness()) {
923+
wtx.SetTx(wtxIn.tx);
924+
fUpdated = true;
925+
}
917926
}
918927

919928
//// debug print

0 commit comments

Comments
 (0)