From e50c2db5d4a33865b1a839d024167ddbb45f2a29 Mon Sep 17 00:00:00 2001 From: Rubens Date: Thu, 27 Jun 2024 13:54:25 -0300 Subject: [PATCH 1/2] Fix app Demo --- .../Sources/Adapters/BaseAdapter.swift | 22 +++++++++++++++---- .../Sources/Adapters/BitcoinAdapter.swift | 8 ++++++- iOS Example/Sources/Core/Manager.swift | 14 +++++++++--- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/iOS Example/Sources/Adapters/BaseAdapter.swift b/iOS Example/Sources/Adapters/BaseAdapter.swift index 476fcbc5..e9681c5a 100644 --- a/iOS Example/Sources/Adapters/BaseAdapter.swift +++ b/iOS Example/Sources/Adapters/BaseAdapter.swift @@ -137,11 +137,24 @@ extension BaseAdapter { func send(to address: String, memo: String? = nil, amount: Decimal, sortType: TransactionDataSortType, unspentOutputs: [UnspentOutputInfo]? = nil, pluginData: [UInt8: IPluginData] = [:]) throws { let satoshiAmount = convertToSatoshi(value: amount) - _ = try abstractKit.send(to: address, memo: memo, value: satoshiAmount, feeRate: feeRate, sortType: sortType, rbfEnabled: false, unspentOutputs: unspentOutputs, pluginData: pluginData) + let params = SendParameters(address: address, + value: satoshiAmount, + feeRate: feeRate, + sortType: sortType, + rbfEnabled: false, + memo: memo, + unspentOutputs: unspentOutputs, + pluginData: pluginData) + _ = try abstractKit.send(params: params) } func availableBalance(for address: String?, memo: String? = nil, unspentOutputs: [UnspentOutputInfo]? = nil, pluginData: [UInt8: IPluginData] = [:]) -> Decimal { - let amount = (try? abstractKit.maxSpendableValue(toAddress: address, memo: memo, feeRate: feeRate, unspentOutputs: unspentOutputs, pluginData: pluginData)) ?? 0 + let amount = (try? abstractKit.maxSpendableValue(params: .init(address: address, + feeRate: feeRate, + memo: memo, + unspentOutputs: unspentOutputs, + pluginData: pluginData))) ?? .zero +// let amount = (try? abstractKit.maxSpendableValue(toAddress: address, memo: memo, feeRate: feeRate, unspentOutputs: unspentOutputs, pluginData: pluginData)) ?? 0 return Decimal(amount) / coinRate } @@ -154,13 +167,14 @@ extension BaseAdapter { } func minSpendableAmount(for address: String?) throws -> Decimal { - try Decimal(abstractKit.minSpendableValue(toAddress: address)) / coinRate + let amount = Decimal(try abstractKit.minSpendableValue(params: .init(address: address))) + return amount / coinRate } func fee(for value: Decimal, memo: String?, address: String?, pluginData: [UInt8: IPluginData] = [:]) -> Decimal { do { let amount = convertToSatoshi(value: value) - let sendInfo = try abstractKit.sendInfo(for: amount, memo: memo, feeRate: feeRate, unspentOutputs: nil) + let sendInfo = try abstractKit.sendInfo(params: .init(value: amount, feeRate: feeRate, memo: memo, unspentOutputs: nil)) return Decimal(sendInfo.fee) / coinRate } catch { return 0 diff --git a/iOS Example/Sources/Adapters/BitcoinAdapter.swift b/iOS Example/Sources/Adapters/BitcoinAdapter.swift index 0703bd04..29a11ccf 100644 --- a/iOS Example/Sources/Adapters/BitcoinAdapter.swift +++ b/iOS Example/Sources/Adapters/BitcoinAdapter.swift @@ -13,7 +13,13 @@ class BitcoinAdapter: BaseAdapter { fatalError("Cant create BitcoinSeed") } - bitcoinKit = try! Kit(seed: seed, purpose: purpose, walletId: "walletId", syncMode: syncMode, networkType: networkType, confirmationsThreshold: 1, logger: logger.scoped(with: "BitcoinKit")) + bitcoinKit = try! Kit(seed: seed, + purpose: purpose, + walletId: "walletId", + syncMode: syncMode, + networkType: networkType, + confirmationsThreshold: 1, + logger: logger.scoped(with: "BitcoinKit")) super.init(name: "Bitcoin", coinCode: "BTC", abstractKit: bitcoinKit) bitcoinKit.delegate = self diff --git a/iOS Example/Sources/Core/Manager.swift b/iOS Example/Sources/Core/Manager.swift index 836a8d7a..b77bdc5e 100644 --- a/iOS Example/Sources/Core/Manager.swift +++ b/iOS Example/Sources/Core/Manager.swift @@ -6,7 +6,7 @@ import HsToolKit class Manager { static let shared = Manager() - private static let syncModes: [BitcoinCore.SyncMode] = [.full, .api] + private static let syncModes: [BitcoinCore.SyncMode] = [.full, .api, .blockchair] private let restoreDataKey = "restore_data" private let syncModeKey = "syncMode" @@ -43,11 +43,19 @@ class Manager { let words = restoreData.components(separatedBy: .whitespacesAndNewlines) if words.count > 1 { - adapter = BitcoinAdapter(words: words, purpose: configuration.purpose, testMode: configuration.testNet, syncMode: syncMode, logger: logger) + adapter = BitcoinAdapter(words: words, + purpose: configuration.purpose, + testMode: configuration.testNet, + syncMode: syncMode, + logger: logger) } else { do { _ = try HDExtendedKey(extendedKey: restoreData) - adapter = BitcoinAdapter(extendedKey: restoreData, purpose: configuration.purpose, testMode: configuration.testNet, syncMode: syncMode, logger: logger) + adapter = BitcoinAdapter(extendedKey: restoreData, + purpose: configuration.purpose, + testMode: configuration.testNet, + syncMode: syncMode, + logger: logger) } catch { adapter = nil } From 2010635f8954d26fbd9a3fcd8307504e4693e563 Mon Sep 17 00:00:00 2001 From: Rubens Date: Tue, 2 Jul 2024 09:12:33 -0300 Subject: [PATCH 2/2] Removed invalid changes and comments --- iOS Example/Sources/Adapters/BaseAdapter.swift | 1 - iOS Example/Sources/Core/Manager.swift | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/iOS Example/Sources/Adapters/BaseAdapter.swift b/iOS Example/Sources/Adapters/BaseAdapter.swift index e9681c5a..fe3afd02 100644 --- a/iOS Example/Sources/Adapters/BaseAdapter.swift +++ b/iOS Example/Sources/Adapters/BaseAdapter.swift @@ -154,7 +154,6 @@ extension BaseAdapter { memo: memo, unspentOutputs: unspentOutputs, pluginData: pluginData))) ?? .zero -// let amount = (try? abstractKit.maxSpendableValue(toAddress: address, memo: memo, feeRate: feeRate, unspentOutputs: unspentOutputs, pluginData: pluginData)) ?? 0 return Decimal(amount) / coinRate } diff --git a/iOS Example/Sources/Core/Manager.swift b/iOS Example/Sources/Core/Manager.swift index b77bdc5e..09e8f028 100644 --- a/iOS Example/Sources/Core/Manager.swift +++ b/iOS Example/Sources/Core/Manager.swift @@ -6,7 +6,7 @@ import HsToolKit class Manager { static let shared = Manager() - private static let syncModes: [BitcoinCore.SyncMode] = [.full, .api, .blockchair] + private static let syncModes: [BitcoinCore.SyncMode] = [.full, .api] private let restoreDataKey = "restore_data" private let syncModeKey = "syncMode"