@@ -326,6 +326,7 @@ module Program =
326326 | TestPaymentPassword
327327 | TestSeedPassphrase
328328 | WipeWallet
329+ | TransferFundsFromWalletUsingMenmonic
329330
330331 let rec TestPaymentPassword () =
331332 let password = UserInteraction.AskPassword false
@@ -348,13 +349,103 @@ module Program =
348349 Account.WipeAll()
349350 else
350351 ()
352+
353+ let TransferFundsFromWalletUsingMenmonic () =
354+ let rec askForMnemonic () : UtxoCoin.EphemeralUtxoAccount =
355+ Console.WriteLine " Enter mnemonic seed phrase (12, 15, 18, 21 or 24 words):"
356+ let mnemonic = Console.ReadLine()
357+ try
358+ Account.CreateEphemeralAccountFromSeedMenmonic mnemonic
359+ with
360+ | :? FormatException as exn ->
361+ printfn " Error reading mnemonic seed phrase: %s " exn.Message
362+ askForMnemonic()
363+
364+ let importedAccount = askForMnemonic()
365+ let currency = BTC
366+
367+ let maybeTotalBalance , maybeUsdValue = UserInteraction.GetAccountBalance importedAccount |> Async.RunSynchronously
368+ match maybeTotalBalance with
369+ | NotFresh _ ->
370+ Console.WriteLine " Could not retrieve balance"
371+ UserInteraction.PressAnyKeyToContinue()
372+ | Fresh 0.0 m ->
373+ Console.WriteLine " Balance on imported account is zero. No funds to transfer."
374+ UserInteraction.PressAnyKeyToContinue()
375+ | Fresh balance ->
376+ printfn
377+ " Balance on imported account: %s BTC (%s )"
378+ ( balance.ToString())
379+ ( UserInteraction.BalanceInUsdString balance maybeUsdValue)
380+
381+ let rec chooseAccount () =
382+ Console.WriteLine " Choose account to send funds to:"
383+ Console.WriteLine()
384+ let allAccounts = Account.GetAllActiveAccounts() |> Seq.toList
385+ let btcAccounts = allAccounts |> List.filter ( fun acc -> acc.Currency = currency)
386+
387+ match btcAccounts with
388+ | [ singleAccount ] -> Some singleAccount
389+ | [] -> failwith " No BTC accounts found"
390+ | _ ->
391+ allAccounts |> Seq.iteri ( fun i account ->
392+ if account.Currency = currency then
393+ let balance , maybeUsdValue =
394+ UserInteraction.GetAccountBalance account
395+ |> Async.RunSynchronously
396+ UserInteraction.DisplayAccountStatus ( i + 1 ) account balance maybeUsdValue
397+ |> Seq.iter Console.WriteLine
398+ )
399+
400+ Console.Write( " Write the account number (or 0 to cancel): " )
401+ let accountNumber = Console.ReadLine()
402+ match Int32.TryParse( accountNumber) with
403+ | false , _ -> chooseAccount()
404+ | true , 0 -> None
405+ | true , accountParsed ->
406+ let theAccountChosen =
407+ try
408+ let selectedAccount = allAccounts.[ accountParsed - 1 ]
409+ if selectedAccount.Currency = BTC then
410+ Some selectedAccount
411+ else
412+ chooseAccount()
413+ with
414+ | _ -> chooseAccount()
415+ theAccountChosen
416+
417+ match chooseAccount() with
418+ | Some targetAccount ->
419+ let destination = targetAccount.PublicAddress
420+ let transferAmount = TransferAmount( balance, balance, currency) // send all funds
421+ let maybeFee = UserInteraction.AskFee importedAccount transferAmount destination
422+ match maybeFee with
423+ | None -> ()
424+ | Some( fee) ->
425+ let txId =
426+ Account.SweepArchivedFunds
427+ importedAccount
428+ balance
429+ targetAccount
430+ fee
431+ false
432+ |> Async.RunSynchronously
433+ let uri = BlockExplorer.GetTransaction currency txId
434+ printfn " Transaction successful:\n %s " ( uri.ToString())
435+ Console.WriteLine()
436+ printf " Archiving imported account..."
437+ Account.ConvertEphemeralAccountToArchivedAccount importedAccount currency
438+ printfn " done"
439+ UserInteraction.PressAnyKeyToContinue()
440+ | None -> ()
351441
352442 let WalletOptions (): unit =
353443 let rec AskWalletOption (): GenericWalletOption =
354444 Console.WriteLine " 0. Cancel, go back"
355445 Console.WriteLine " 1. Check you still remember your payment password"
356446 Console.WriteLine " 2. Check you still remember your secret recovery phrase"
357447 Console.WriteLine " 3. Wipe your current wallet, in order to start from scratch"
448+ Console.WriteLine " 4. Transfer all funds from another wallet (given mnemonic code)"
358449 Console.Write " Choose an option from the ones above: "
359450 let optIntroduced = Console.ReadLine ()
360451 match UInt32.TryParse optIntroduced with
@@ -365,6 +456,7 @@ module Program =
365456 | 1 u -> GenericWalletOption.TestPaymentPassword
366457 | 2 u -> GenericWalletOption.TestSeedPassphrase
367458 | 3 u -> GenericWalletOption.WipeWallet
459+ | 4 u -> GenericWalletOption.TransferFundsFromWalletUsingMenmonic
368460 | _ -> AskWalletOption()
369461
370462 let walletOption = AskWalletOption()
@@ -377,6 +469,8 @@ module Program =
377469 Console.WriteLine " Success!"
378470 | GenericWalletOption.WipeWallet ->
379471 WipeWallet()
472+ | GenericWalletOption.TransferFundsFromWalletUsingMenmonic ->
473+ TransferFundsFromWalletUsingMenmonic()
380474 | _ -> ()
381475
382476 let rec PerformOperation ( numActiveAccounts : uint32 ) ( numHotAccounts : uint32 ) =
0 commit comments