gui icon indicating copy to clipboard operation
gui copied to clipboard

wallet: Detect `DuplicateAddress` earlier

Open hebasto opened this issue 3 years ago • 3 comments

This PR makes check for DuplicateAddress error easier and earlier.

hebasto avatar May 29 '22 17:05 hebasto

which requires the wallet to be locked

Do you mean "unlocking" using WalletModel::UnlockContext?

Inside SendCoinsDialog ::PrepareSendText, before calling WalletModel::prepareTransaction, we are looping over all the entries to load up the recipients list --> Line 257 of SendCoinsDialog.

Would it make logic a bit messier?

hebasto avatar May 30 '22 08:05 hebasto

Do you mean "unlocking" using WalletModel::UnlockContext?

Yeah. I skipped the first two letters.

Would it make logic a bit messier?

I think that the current logic is messy actually. We are already validating all the recipients' data there. Check this out: https://github.com/furszy/bitcoin/commit/6115d09946b2fa3b25d005f748a5f9a0992c973b . I made the code flow cleaner there.

Before creating the recipient and adding it to the temporal recipients vector, we call to SendCoinsEntry::validate, which validates the address and the amount (failing if the address is invalid, or the amount is 0 or dust). So, when we are inside WalletModel:: prepareTransaction, we already know whether the address and/or the amount are valid or not. Those checks are duplicated.

I reworked the area a bit here (stopped after few commits to not enter in a long rabbit hole): https://github.com/furszy/bitcoin/commits/220529-dupaddr

Feel free to cherry-pick any of those commits if you like them, all yours :). Maybe we could team up to get deeper over this rabbit hole in follow-up PRs.

furszy avatar May 30 '22 14:05 furszy

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

No conflicts as of last run.

DrahtBot avatar Jun 12 '22 21:06 DrahtBot

Going to leave this PR up for grabs.

cc @furszy

hebasto avatar Oct 24 '22 10:10 hebasto