nblockchain / geewallet

geewallet is a non-custodial, minimalistic & pragmatist opensource crossplatform lightweight brainwallet to hold the most important cryptoassets in the same application with ease & peace of mind
MIT License
61 stars 37 forks source link

BIP-39 import #285

Open webwarrior-ws opened 1 month ago

webwarrior-ws commented 1 month ago

Implement the import in the backend using NBitcoin (BIP84 derivation path), with option to sweep the funds to a bitcoin account of geewallet with a transaction.

knocte commented 1 month ago

Still receiving this exception when testing:

Write the account number (or 0 to cancel): 1
System.Exception: Currency BTC not ether based and not UTXO either? not supported, report this bug (estimatefee)
   at GWallet.Backend.Account.EstimateFee@212-20.Invoke(Unit unitVar) in /Users/knocte/Documents/Code/geewalletMASTERclean/src/GWallet.Backend/Account.fs:line 221
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult](AsyncActivation`1 ctxt, TResult result1, FSharpFunc`2 part2) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 510
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 112
--- End of stack trace from previous location ---
   at Microsoft.FSharp.Control.AsyncResult`1.Commit() in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 454
   at Microsoft.FSharp.Control.AsyncPrimitives.QueueAsyncAndWaitForResultSynchronously[a](CancellationToken token, FSharpAsync`1 computation, FSharpOption`1 timeout) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 1139
   at Microsoft.FSharp.Control.AsyncPrimitives.RunSynchronously[T](CancellationToken cancellationToken, FSharpAsync`1 computation, FSharpOption`1 timeout) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 1166
   at Microsoft.FSharp.Control.FSharpAsync.RunSynchronously[T](FSharpAsync`1 computation, FSharpOption`1 timeout, FSharpOption`1 cancellationToken) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 1515
   at GWallet.Frontend.Console.UserInteraction.AskFee(IAccount account, TransferAmount amount, String destination) in /Users/knocte/Documents/Code/geewalletMASTERclean/src/GWallet.Frontend.Console/UserInteraction.fs:line 608
   at GWallet.Frontend.Console.Program.TransferFundsFromWalletUsingMenmonic() in /Users/knocte/Documents/Code/geewalletMASTERclean/src/GWallet.Frontend.Console/Program.fs:line 408
   at GWallet.Frontend.Console.Program.WalletOptions() in /Users/knocte/Documents/Code/geewalletMASTERclean/src/GWallet.Frontend.Console/Program.fs:line 448
   at GWallet.Frontend.Console.Program.PerformOperation(UInt32 numActiveAccounts, UInt32 numHotAccounts) in /Users/knocte/Documents/Code/geewalletMASTERclean/src/GWallet.Frontend.Console/Program.fs:line 487
   at GWallet.Frontend.Console.Program.ProgramMainLoop[a]() in /Users/knocte/Documents/Code/geewalletMASTERclean/src/GWallet.Frontend.Console/Program.fs:line 564
   at GWallet.Frontend.Console.Program.NormalStartWithNoParameters() in /Users/knocte/Documents/Code/geewalletMASTERclean/src/GWallet.Frontend.Console/Program.fs:line 576
knocte commented 1 month ago

Another crash:

System.Exception: account 33deiowdoijdeiwjoiddeiowjodijew(BTC) not found in config, or more than one with same public address?
   at Microsoft.FSharp.Core.PrintfModule.PrintFormatToStringThenFail@1448.Invoke(String message)
   at GWallet.Frontend.Console.UserInteraction.DisplayAccountStatuses@386-14.Invoke(Currency arg20)
   at GWallet.Frontend.Console.UserInteraction.DisplayAccountStatuses@380-12.Invoke(Unit unitVar) in /Users/knocte/Documents/Code/geewalletMASTERclean/src/GWallet.Frontend.Console/UserInteraction.fs:line 386
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult](AsyncActivation`1 ctxt, TResult result1, FSharpFunc`2 part2) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 510
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 112
--- End of stack trace from previous location ---
   at Microsoft.FSharp.Control.AsyncResult`1.Commit() in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 454
   at Microsoft.FSharp.Control.AsyncPrimitives.QueueAsyncAndWaitForResultSynchronously[a](CancellationToken token, FSharpAsync`1 computation, FSharpOption`1 timeout) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 1139
   at Microsoft.FSharp.Control.AsyncPrimitives.RunSynchronously[T](CancellationToken cancellationToken, FSharpAsync`1 computation, FSharpOption`1 timeout) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 1166
   at Microsoft.FSharp.Control.FSharpAsync.RunSynchronously[T](FSharpAsync`1 computation, FSharpOption`1 timeout, FSharpOption`1 cancellationToken) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 1515
   at GWallet.Frontend.Console.Program.chooseAccount@375.Invoke(Unit unitVar0) in /Users/knocte/Documents/Code/geewalletMASTERclean/src/GWallet.Frontend.Console/Program.fs:line 386
   at GWallet.Frontend.Console.Program.TransferFundsFromWalletUsingMenmonic() in /Users/knocte/Documents/Code/geewalletMASTERclean/src/GWallet.Frontend.Console/Program.fs:line 406
   at GWallet.Frontend.Console.Program.WalletOptions() in /Users/knocte/Documents/Code/geewalletMASTERclean/src/GWallet.Frontend.Console/Program.fs:line 450
   at GWallet.Frontend.Console.Program.PerformOperation(UInt32 numActiveAccounts, UInt32 numHotAccounts) in /Users/knocte/Documents/Code/geewalletMASTERclean/src/GWallet.Frontend.Console/Program.fs:line 489
   at GWallet.Frontend.Console.Program.ProgramMainLoop[a]() in /Users/knocte/Documents/Code/geewalletMASTERclean/src/GWallet.Frontend.Console/Program.fs:line 566
   at GWallet.Frontend.Console.Program.NormalStartWithNoParameters() in /Users/knocte/Documents/Code/geewalletMASTERclean/src/GWallet.Frontend.Console/Program.fs:line 578

Please take in account the above address of mine corresponds to a READONLY account of mine.

webwarrior-ws commented 1 month ago

@knocte So we can't reuse DisplayAccountStatuses function. Easiest fix would be to make GetAccountBalance internal instead of private and use it together with DisplayAccountStatus to display account.

webwarrior-ws commented 1 month ago

Or maybe list only normal (not readonly) accounts?

knocte commented 1 month ago

Easiest fix would be to make GetAccountBalance internal instead of private and use it together with DisplayAccountStatus to display account.

Sounds good

knocte commented 1 month ago

After sending the transaction, please add an invokation to the function that prints "Press any key to continue..." (like we do when we send normal transactions).

knocte commented 1 month ago

One last thing to do here: after sending the transaction to recover the funds, convert the ImportedAccount to an ArchivedAccount and save it to disk. This way, geewallet will warn the user if more funds arrive to it in the future.

knocte commented 1 month ago

This PR has 5 commits. The first one has CI red, so I think the most logical thing to do is squash the 1st one with the 2nd, to avoid that red CI status, and because those two commits are basically working on the same thing. Later, I would also squash commits 3 and 4. So, in the end, this PR can have 3 commits only.

knocte commented 1 month ago

@webwarrior-ws nit: before showing the possible accounts where to send the funds to, please add a Console.WriteLine invokation that informs the user about the address where the funds are.

webwarrior-ws commented 1 month ago

@webwarrior-ws nit: before showing the possible accounts where to send the funds to, please add a Console.WriteLine invokation that informs the user about the address where the funds are.

@knocte done