Open danielnordh opened 1 year ago
To create a Wallet, you need:
let databaseconfig ...
let network ...
let descriptor ...
// to init
let wallet = try Wallet.init(descriptor: descriptor, changeDescriptor: changeDescriptor, network: network, databaseConfig: databaseConfig)
To get balance (should happen after every sync):
self.wallet!.getBalance()
To get transactions (should happen after every sync):
self.wallet!.listTransactions()
To sync:
let url = ...
let electrumConfig = ElectrumConfig(url: url!, socks5: nil, retry: ELECTRUM_RETRY, timeout: nil, stopGap: ELECTRUM_STOPGAP)
let blockchainConfig = BlockchainConfig.electrum(config: electrumConfig)
let blockchain = try Blockchain(config: blockchainConfig)
// to sync
try wallet.sync(blockchain: blockchain, progress: nil)
To send:
let psbt = try TxBuilder().addRecipient(address: recipient, amount: amount).feeRate(satPerVbyte: feeRate).finish(wallet: self.wallet!)
let success = try self.wallet!.sign(psbt: psbt)
let blockchainConfig = self.blockchainConfig(network: self.network, syncSource: self.syncSource)
let blockchain = try Blockchain(config: blockchainConfig)
try blockchain.broadcast(psbt: psbt)
Proposed minimal interface:
public class BDKManager: ObservableObject {
@Published public var wallet: Wallet
@Published public var balance: Balance?
@Published public var transactions: [TransactionDetails]?
private var blockchain: Blockchain
// Sync the loaded wallet once
public func sync() {
... (also updates Balance and Transactions)
}
// Send an amount of bitcoin (in sats) to a recipient, optional feeRate
public func sendBitcoin(recipient: String, amount: UInt64, feeRate: Float) -> Bool {
...
}
}
Or should this not be part of bdk-swift at all, maybe just be a reference class?
👀
I have moved this discussion to bdk-ffi: https://github.com/bitcoindevkit/bdk-ffi/issues/266
Instead of creating a 'fat' BDKManager class, what is the most minimal version of SwiftUI syntactic sugar we could add to BitcoinDevKit itself? This could either be done directly in the only file at the moment, or as a separate file for clarity.
What does every SwiftUI wallet developer need?
To support these, you need to create / keep references to: