From 07eae0c4be873ad5b807fd215c75a64f677eb6a3 Mon Sep 17 00:00:00 2001 From: webwarrior Date: Mon, 22 Jul 2024 13:16:00 +0200 Subject: [PATCH] WIP: make ImportedAccount implement IUtxoAccount In order to avoid error when calling EstimateFee: ``` System.Exception: Currency BTC not ether based and not UTXO either? not supported, report this bug (estimatefee) ``` --- src/GWallet.Backend/UtxoCoin/ImportedAccount.fs | 11 ++++++----- src/GWallet.Backend/UtxoCoin/UtxoCoinAccount.fs | 6 ------ 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/GWallet.Backend/UtxoCoin/ImportedAccount.fs b/src/GWallet.Backend/UtxoCoin/ImportedAccount.fs index 735278253..9c20de674 100644 --- a/src/GWallet.Backend/UtxoCoin/ImportedAccount.fs +++ b/src/GWallet.Backend/UtxoCoin/ImportedAccount.fs @@ -7,26 +7,27 @@ open NBitcoin type ImportedAccount(mnemonic: string) = let rootKey = Mnemonic(mnemonic).DeriveExtKey().Derive(KeyPath("m/84'/0'/0'")) let firstReceivingAddressKey = rootKey.Derive(0u).Derive(0u) - let firstReceivingAddressPubKey = firstReceivingAddressKey.GetPublicKey().ToHex() + let firstReceivingAddressPubKey = firstReceivingAddressKey.GetPublicKey() let publicAddress = firstReceivingAddressKey.GetPublicKey().GetAddress(ScriptPubKeyType.Segwit, Network.Main).ToString() - interface IAccount with + interface IUtxoAccount with member self.Currency = Currency.BTC member self.PublicAddress = publicAddress + member self.PublicKey = firstReceivingAddressPubKey member self.GetTotalBalance() = async { let! maybeBalance = Account.GetShowableBalanceAndImminentIncomingPayment - (Account.GetIUtxoAccount self firstReceivingAddressPubKey) + self ServerSelectionMode.Fast None return maybeBalance |> Option.map (fun (balance, _) -> balance) } member self.SendFunds (destinationAccount: IAccount) (amount: TransferAmount) = - Account.SendPaymentFromImportedAccount - (Account.GetIUtxoAccount self firstReceivingAddressPubKey) + Account.SendPaymentFromImportedAccount + self destinationAccount.PublicAddress amount firstReceivingAddressKey.PrivateKey diff --git a/src/GWallet.Backend/UtxoCoin/UtxoCoinAccount.fs b/src/GWallet.Backend/UtxoCoin/UtxoCoinAccount.fs index dcae7df32..f3cb2c58e 100644 --- a/src/GWallet.Backend/UtxoCoin/UtxoCoinAccount.fs +++ b/src/GWallet.Backend/UtxoCoin/UtxoCoinAccount.fs @@ -534,12 +534,6 @@ module Account = let finalTransaction = SignTransaction account txMetadata destination amount password BroadcastRawTransaction baseAccount.Currency finalTransaction ignoreHigherMinerFeeThanAmount - - let internal GetIUtxoAccount (account: IAccount) (publicKey: UtxoPublicKey) = - { new IUtxoAccount with - member self.Currency = account.Currency - member self.PublicAddress = account.PublicAddress - member self.PublicKey = PubKey(publicKey) } let internal SendPaymentFromImportedAccount (account: IUtxoAccount) (destination: string)