@@ -326,6 +326,7 @@ module Program =
326
326
| TestPaymentPassword
327
327
| TestSeedPassphrase
328
328
| WipeWallet
329
+ | TransferFundsFromWalletUsingMenmonic
329
330
330
331
let rec TestPaymentPassword () =
331
332
let password = UserInteraction.AskPassword false
@@ -348,13 +349,103 @@ module Program =
348
349
Account.WipeAll()
349
350
else
350
351
()
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 -> ()
351
441
352
442
let WalletOptions (): unit =
353
443
let rec AskWalletOption (): GenericWalletOption =
354
444
Console.WriteLine " 0. Cancel, go back"
355
445
Console.WriteLine " 1. Check you still remember your payment password"
356
446
Console.WriteLine " 2. Check you still remember your secret recovery phrase"
357
447
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)"
358
449
Console.Write " Choose an option from the ones above: "
359
450
let optIntroduced = Console.ReadLine ()
360
451
match UInt32.TryParse optIntroduced with
@@ -365,6 +456,7 @@ module Program =
365
456
| 1 u -> GenericWalletOption.TestPaymentPassword
366
457
| 2 u -> GenericWalletOption.TestSeedPassphrase
367
458
| 3 u -> GenericWalletOption.WipeWallet
459
+ | 4 u -> GenericWalletOption.TransferFundsFromWalletUsingMenmonic
368
460
| _ -> AskWalletOption()
369
461
370
462
let walletOption = AskWalletOption()
@@ -377,6 +469,8 @@ module Program =
377
469
Console.WriteLine " Success!"
378
470
| GenericWalletOption.WipeWallet ->
379
471
WipeWallet()
472
+ | GenericWalletOption.TransferFundsFromWalletUsingMenmonic ->
473
+ TransferFundsFromWalletUsingMenmonic()
380
474
| _ -> ()
381
475
382
476
let rec PerformOperation ( numActiveAccounts : uint32 ) ( numHotAccounts : uint32 ) =
0 commit comments