Skip to content
This repository has been archived by the owner on Oct 28, 2022. It is now read-only.

Proposal: Make HD Wallet injectable #606

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion BitcoinCore/Classes/Core/BitcoinCoreBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class BitcoinCoreBuilder {
private var blockHeaderHasher: IHasher?
private var blockValidator: IBlockValidator?
private var transactionInfoConverter: ITransactionInfoConverter?
private var hdWallet: IHDWallet?

// parameters with default values
private var confirmationsThreshold = 6
Expand Down Expand Up @@ -94,6 +95,11 @@ public class BitcoinCoreBuilder {
return self
}

public func set(hdWallet: IHDWallet?) -> BitcoinCoreBuilder {
self.hdWallet = hdWallet
return self
}

public func set(initialSyncApi: ISyncTransactionApi?) -> BitcoinCoreBuilder {
self.initialSyncApi = initialSyncApi
return self
Expand Down Expand Up @@ -142,7 +148,7 @@ public class BitcoinCoreBuilder {

let reachabilityManager = ReachabilityManager()

let hdWallet = HDWallet(seed: seed, coinType: network.coinType, xPrivKey: network.xPrivKey, xPubKey: network.xPubKey, gapLimit: 20, purpose: bip.purpose)
var hdWallet = self.hdWallet ?? HDWallet(seed: seed, coinType: network.coinType, xPrivKey: network.xPrivKey, xPubKey: network.xPubKey, gapLimit: 20, purpose: bip.purpose)

let networkMessageParser = NetworkMessageParser(magic: network.magic)
let networkMessageSerializer = NetworkMessageSerializer(magic: network.magic)
Expand Down
5 changes: 3 additions & 2 deletions BitcoinKit/Classes/Core/Kit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Kit: AbstractKit {
}
}

public init(seed: Data, bip: Bip, walletId: String, syncMode: BitcoinCore.SyncMode = .api, networkType: NetworkType = .mainNet, confirmationsThreshold: Int = 6, logger: Logger?) throws {
public init(seed: Data, bip: Bip, walletId: String, syncMode: BitcoinCore.SyncMode = .api, networkType: NetworkType = .mainNet, confirmationsThreshold: Int = 6, hdWallet: IHDWallet?, logger: Logger?) throws {
let network: INetwork
let logger = logger ?? Logger(minLogLevel: .verbose)

Expand Down Expand Up @@ -67,7 +67,7 @@ public class Kit: AbstractKit {
blockValidatorSet.add(blockValidator: blockValidatorChain)

let hodler = HodlerPlugin(addressConverter: bitcoinCoreBuilder.addressConverter, blockMedianTimeHelper: BlockMedianTimeHelper(storage: storage), publicKeyStorage: storage)

let bitcoinCore = try bitcoinCoreBuilder
.set(network: network)
.set(initialSyncApi: initialSyncApi)
Expand All @@ -80,6 +80,7 @@ public class Kit: AbstractKit {
.set(syncMode: syncMode)
.set(storage: storage)
.set(blockValidator: blockValidatorSet)
.set(hdWallet: hdWallet)
.add(plugin: hodler)
.build()

Expand Down