Skip to content

Commit 3aadfd0

Browse files
committed
refactor: extract to a new files actors WalletFullScanScriptInspector and WalletSyncScriptInspector
1 parent 4c1a73e commit 3aadfd0

File tree

4 files changed

+75
-42
lines changed

4 files changed

+75
-42
lines changed

BDKSwiftExampleWallet.xcodeproj/project.pbxproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
/* Begin PBXBuildFile section */
1010
774586B52DB7B2BC00A631E1 /* BalanceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 774586B42DB7B2BC00A631E1 /* BalanceView.swift */; };
11+
779E70872DB9C98A006E22D3 /* WalletSyncScriptInspector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 779E70862DB9C98A006E22D3 /* WalletSyncScriptInspector.swift */; };
12+
779E70892DB9C9AB006E22D3 /* WalletFullScanScriptInspector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 779E70882DB9C9AB006E22D3 /* WalletFullScanScriptInspector.swift */; };
1113
77F0FDC92DA9A93D00B30E4F /* Connection+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F0FDC82DA9A93700B30E4F /* Connection+Extensions.swift */; };
1214
A733D6D02A81113000F333B4 /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = A733D6CF2A81113000F333B4 /* Localizable.xcstrings */; };
1315
A73F7A362A3B778E00B87FC6 /* Int+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A73F7A352A3B778E00B87FC6 /* Int+Extensions.swift */; };
@@ -110,6 +112,8 @@
110112

111113
/* Begin PBXFileReference section */
112114
774586B42DB7B2BC00A631E1 /* BalanceView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BalanceView.swift; sourceTree = "<group>"; };
115+
779E70862DB9C98A006E22D3 /* WalletSyncScriptInspector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletSyncScriptInspector.swift; sourceTree = "<group>"; };
116+
779E70882DB9C9AB006E22D3 /* WalletFullScanScriptInspector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletFullScanScriptInspector.swift; sourceTree = "<group>"; };
113117
77F0FDC82DA9A93700B30E4F /* Connection+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Connection+Extensions.swift"; sourceTree = "<group>"; };
114118
A733D6CF2A81113000F333B4 /* Localizable.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = Localizable.xcstrings; sourceTree = "<group>"; };
115119
A73F7A352A3B778E00B87FC6 /* Int+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Int+Extensions.swift"; sourceTree = "<group>"; };
@@ -222,6 +226,15 @@
222226
/* End PBXFrameworksBuildPhase section */
223227

224228
/* Begin PBXGroup section */
229+
779E70832DB9C94C006E22D3 /* Actor */ = {
230+
isa = PBXGroup;
231+
children = (
232+
779E70862DB9C98A006E22D3 /* WalletSyncScriptInspector.swift */,
233+
779E70882DB9C9AB006E22D3 /* WalletFullScanScriptInspector.swift */,
234+
);
235+
path = Actor;
236+
sourceTree = "<group>";
237+
};
225238
A7FBCE392A72944C007C960E /* Resources */ = {
226239
isa = PBXGroup;
227240
children = (
@@ -414,6 +427,7 @@
414427
AE1C34222A424440008F807A /* App */,
415428
AE7F670A2A7451B600CED561 /* Model */,
416429
AE1C341F2A424415008F807A /* View */,
430+
779E70832DB9C94C006E22D3 /* Actor */,
417431
AE0C31002A804C05008F1EAE /* View Model */,
418432
AEB905C52A7EECD900CD0337 /* Service */,
419433
AE1C341E2A42440A008F807A /* Extensions */,
@@ -708,7 +722,9 @@
708722
AED4CC102A1D522100CE1831 /* WalletView.swift in Sources */,
709723
AE7F67092A7451AA00CED561 /* Price.swift in Sources */,
710724
AE184EFC2BFE52C800374362 /* Amount+Extensions.swift in Sources */,
725+
779E70892DB9C9AB006E22D3 /* WalletFullScanScriptInspector.swift in Sources */,
711726
AE2381B12C60690900F6B00C /* LocalOutput+Extensions.swift in Sources */,
727+
779E70872DB9C98A006E22D3 /* WalletSyncScriptInspector.swift in Sources */,
712728
AE7F67072A744CE200CED561 /* Double+Extensions.swift in Sources */,
713729
A73F7A362A3B778E00B87FC6 /* Int+Extensions.swift in Sources */,
714730
AE7839FD2AB4E18D005F0CBA /* AmountView.swift in Sources */,
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// WalletFullScanScriptInspector.swift
3+
// BDKSwiftExampleWallet
4+
//
5+
// Created by Rubens Machion on 23/04/25.
6+
//
7+
8+
import BitcoinDevKit
9+
10+
actor WalletFullScanScriptInspector: @preconcurrency FullScanScriptInspector {
11+
private let updateProgress: @Sendable (UInt64) -> Void
12+
private var inspectedCount: UInt64 = 0
13+
14+
init(updateProgress: @escaping @Sendable (UInt64) -> Void) {
15+
self.updateProgress = updateProgress
16+
}
17+
18+
func inspect(keychain: KeychainKind, index: UInt32, script: Script) {
19+
inspectedCount += 1
20+
updateProgress(inspectedCount)
21+
}
22+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// WalletSyncScriptInspector.swift
3+
// BDKSwiftExampleWallet
4+
//
5+
// Created by Rubens Machion on 23/04/25.
6+
//
7+
8+
import BitcoinDevKit
9+
import Foundation
10+
11+
actor WalletSyncScriptInspector: @preconcurrency SyncScriptInspector {
12+
private let updateProgress: @Sendable (UInt64, UInt64) -> Void
13+
private var inspectedCount: UInt64 = 0
14+
private var totalCount: UInt64 = 0
15+
16+
init(updateProgress: @escaping @Sendable (UInt64, UInt64) -> Void) {
17+
self.updateProgress = updateProgress
18+
}
19+
20+
func inspect(script: Script, total: UInt64) {
21+
totalCount = total
22+
inspectedCount += 1
23+
24+
let delay: TimeInterval =
25+
if total <= 5 {
26+
0.2
27+
} else if total < 10 {
28+
0.15
29+
} else if total < 20 {
30+
0.1
31+
} else {
32+
0
33+
}
34+
Thread.sleep(forTimeInterval: delay)
35+
updateProgress(inspectedCount, totalCount)
36+
}
37+
}

BDKSwiftExampleWallet/View Model/WalletViewModel.swift

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -163,45 +163,3 @@ class WalletViewModel {
163163
}
164164
}
165165
}
166-
167-
actor WalletSyncScriptInspector: @preconcurrency SyncScriptInspector {
168-
private let updateProgress: @Sendable (UInt64, UInt64) -> Void
169-
private var inspectedCount: UInt64 = 0
170-
private var totalCount: UInt64 = 0
171-
172-
init(updateProgress: @escaping @Sendable (UInt64, UInt64) -> Void) {
173-
self.updateProgress = updateProgress
174-
}
175-
176-
func inspect(script: Script, total: UInt64) {
177-
totalCount = total
178-
inspectedCount += 1
179-
180-
let delay: TimeInterval =
181-
if total <= 5 {
182-
0.2
183-
} else if total < 10 {
184-
0.15
185-
} else if total < 20 {
186-
0.1
187-
} else {
188-
0
189-
}
190-
Thread.sleep(forTimeInterval: delay)
191-
updateProgress(inspectedCount, totalCount)
192-
}
193-
}
194-
195-
actor WalletFullScanScriptInspector: @preconcurrency FullScanScriptInspector {
196-
private let updateProgress: @Sendable (UInt64) -> Void
197-
private var inspectedCount: UInt64 = 0
198-
199-
init(updateProgress: @escaping @Sendable (UInt64) -> Void) {
200-
self.updateProgress = updateProgress
201-
}
202-
203-
func inspect(keychain: KeychainKind, index: UInt32, script: Script) {
204-
inspectedCount += 1
205-
updateProgress(inspectedCount)
206-
}
207-
}

0 commit comments

Comments
 (0)