Skip to content

Commit 8f0f18e

Browse files
committed
refactor: use Wtxid as the key in the map
1 parent eaff22b commit 8f0f18e

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

BDKSwiftExampleWallet/Service/BDK Service/BDKService.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ final class BDKService {
110110
private(set) var network: Network
111111
private var blockchainURL: String
112112
internal private(set) var wallet: Wallet?
113-
private var kyotoPendingTxs: [String: Txid] = [:]
113+
private var kyotoPendingTxs: [Wtxid: Txid] = [:]
114114
private let kyotoPendingTxQueue = DispatchQueue(label: "bdk.service.kyoto.pending")
115115

116116
init(keyClient: KeyClient = .live) {
@@ -594,17 +594,16 @@ final class BDKService {
594594
}
595595

596596
private func trackKyotoBroadcast(_ transaction: Transaction) {
597-
let wtxidData = transaction.computeWtxid().serialize()
598-
let wtxidHex = [UInt8](wtxidData).hexString.lowercased()
597+
let wtxid = transaction.computeWtxid()
599598
let txid = transaction.computeTxid()
600599
kyotoPendingTxQueue.sync {
601-
kyotoPendingTxs[wtxidHex] = txid
600+
kyotoPendingTxs[wtxid] = txid
602601
}
603602
}
604603

605-
private func takeKyotoTx(for wtxidHex: String) -> Txid? {
604+
private func takeKyotoTx(for wtxid: Wtxid) -> Txid? {
606605
kyotoPendingTxQueue.sync {
607-
kyotoPendingTxs.removeValue(forKey: wtxidHex.lowercased())
606+
kyotoPendingTxs.removeValue(forKey: wtxid)
608607
}
609608
}
610609

@@ -615,7 +614,8 @@ final class BDKService {
615614
}
616615

617616
func handleKyotoRejectedTransaction(wtxidHex: String) {
618-
guard let txid = takeKyotoTx(for: wtxidHex) else { return }
617+
guard let wtxid = try? Wtxid.fromString(hex: wtxidHex.lowercased()) else { return }
618+
guard let txid = takeKyotoTx(for: wtxid) else { return }
619619
guard let wallet = self.wallet else { return }
620620
let evictedTx = EvictedTx(
621621
txid: txid,

0 commit comments

Comments
 (0)