Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend/UtxoCoin: support native-segwit with cold storage #254

Merged
merged 5 commits into from
Feb 21, 2024

Conversation

knocte
Copy link
Member

@knocte knocte commented Feb 12, 2024

This change also reduces a bit of primitive obsession (i.e. string vs BitcoinAddress) to make the code less "stringly-typed" lol.

This should have been done in [1] but was an oversight on my part when reviewing.

[1] #211

@knocte knocte force-pushed the wip/nativeSegwitWithColdStorage branch 14 times, most recently from edfdfa0 to 5496a91 Compare February 12, 2024 14:51
@knocte
Copy link
Member Author

knocte commented Feb 12, 2024

@aarani this is ready for review now, can you have a very quick look?

Copy link
Contributor

@aarani aarani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So many ToString() 🤢 but overall LGTM!

@knocte
Copy link
Member Author

knocte commented Feb 13, 2024

"Many ToString() instances" is much better (or rather, less worse) than "Many : string return types". Do you understand?

@knocte
Copy link
Member Author

knocte commented Feb 13, 2024

Actually there's 3 things missing in this PR:

  1. A first commit (to be placed before the 2 existing ones) that converts nestedSegwit readOnly accounts to nativeSegwit readOnly accounts (so that users don't need to re-setup manually).
  2. Rename OriginMainAddress to OriginDefaultAddress, cause I don't want the word "Main" to be conflated with "Mainnet".
  3. Add exception details (e.g. stacktraces) of the problems I got, in the commit titled "Backend/UtxoCoin: support nativeSegwit+coldStorage" and in the commit to be done mentioned in (1) above.

I'll work on the above today.

@knocte knocte force-pushed the wip/nativeSegwitWithColdStorage branch 11 times, most recently from 0f4db61 to dc2850f Compare February 18, 2024 11:59
@knocte knocte requested a review from aarani February 18, 2024 14:54
@knocte knocte force-pushed the wip/nativeSegwitWithColdStorage branch from 7945891 to 4354e22 Compare February 19, 2024 07:22
This fixes the following crash when trying to broadcast a signed
transaction from your cold-storage device:

```
unknown origin account
   at GWallet.Backend.UtxoCoin.Account.GetSignedTransactionDetails[T](String rawTransaction, Currency currency) in
/Users/knocte/Documents/Code/geewalletMASTERclean/src/GWallet.Backend/UtxoCoin/UtxoCoinAccount.fs:line 728
   at GWallet.Backend.Account.GetSignedTransactionDetails[T](SignedTransaction`1 signedTransaction) in /Users/knocte/Documents/Code/geewalletMASTERclean/src/GWallet.Backend/Account.fs:line 793
   at Program.BroadcastPayment() in /Users/knocte/Documents/Code/geewalletMASTERclean/src/GWallet.Frontend.Console/Program.fs:line 82
   at Program.PerformOperation(UInt32 numActiveAccounts, UInt32 numHotAccounts) in /Users/knocte/Documents/Code/geewalletMASTERclean/src/GWallet.Frontend.Console/Program.fs:line 398
   at Program.ProgramMainLoop[a]() in /Users/knocte/Documents/Code/geewalletMASTERclean/src/GWallet.Frontend.Console/Program.fs:line 481
   at Program.NormalStartWithNoParameters() in /Users/knocte/Documents/Code/geewalletMASTERclean/src/GWallet.Frontend.Console/Program.fs:line 493
```

This change also reduces a bit of primitive obsession (i.e.
string vs BitcoinAddress) to make the code less "stringly-typed"
lol.

This should have been done in [1] but was an oversight on my
part when reviewing.

[1] #211
This way, if a version of geewallet that is too old to have
native segwit support (or disabled by default) tries to
deserialize a transaction proposal, it will error out
complaining about version mismatch instead of crashing with a
weird error.

This commit also tweaks the version comparison, to make sure
the VersionMismatch exception is actually raised, and caught
by the Frontend (Console, for now).
Their public addresses would then start showing their native
segwit address (that starts with "bc1") instead of the nested
segwit one. This way they don't need to re-scan the QR code
from the coldstorage device. If we don't do this, if you tried
to sign-off the transaction on your native-segwit-ready cold
storage device, you would get this error:

```
Introduce a file name to load the unsigned transaction: testCold.json
Error: The transaction doesn't correspond to any of the accounts in the wallet.

Press any key to continue...
```

In case you're wondering if there's any risk that this causes
irrecoverable funds when you use this with a coldstorage
device that you haven't upgraded yet to NativeSegwit: this
could not happen since the JSON format is different, and then
deserialization would fail, advising the user to upgrade.
@knocte knocte force-pushed the wip/nativeSegwitWithColdStorage branch from ddc8142 to 2d6dccc Compare February 19, 2024 15:27
For performance reasons, we don't want to execute migrations
everytime we need to iterate over the accounts.
@knocte knocte force-pushed the wip/nativeSegwitWithColdStorage branch from 02990d0 to beabb57 Compare February 21, 2024 15:12
@knocte knocte merged commit 0e210fe into master Feb 21, 2024
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants