Skip to content

Commit

Permalink
WIP: make ImportedAccount implement IUtxoAccount
Browse files Browse the repository at this point in the history
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)
```
  • Loading branch information
webwarrior-ws committed Jul 22, 2024
1 parent c77936a commit 07eae0c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
11 changes: 6 additions & 5 deletions src/GWallet.Backend/UtxoCoin/ImportedAccount.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 0 additions & 6 deletions src/GWallet.Backend/UtxoCoin/UtxoCoinAccount.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 07eae0c

Please sign in to comment.