Skip to content

Commit 2a109a3

Browse files
committed
realtime update wallet
1 parent 840e0f8 commit 2a109a3

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

BDKSwiftExampleWallet/Service/BDKSyncService/KyotoService.swift

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ final class KyotoService: BDKSyncService {
132132

133133
private func startNode() async throws {
134134
node?.run()
135-
printLogs()
135+
getNextLog()
136136
updateWarn()
137137
try await updateWallet()
138138
startRealTimeWalletUpdate()
@@ -142,44 +142,42 @@ final class KyotoService: BDKSyncService {
142142
private func updateWallet() async throws -> Bool {
143143
guard let update = await self.client?.update() else {
144144
isScanRunning = false
145-
print("Nothing to update")
146145
return false
147146
}
148147
try self.wallet?.applyUpdate(update: update)
149148
let _ = try self.wallet?.persist(connection: self.connection ?? Connection.loadConnection())
150-
print("######### walletUpdated")
151149
isScanRunning = false
152150
return true
153151
}
154152

155153
private func startRealTimeWalletUpdate() {
156-
print(#function)
157154
Task {
158155
while true {
159-
print("Updating: \(Date())")
160-
if let update = await client?.update() {
161-
do {
162-
try wallet?.applyUpdate(update: update)
156+
do {
157+
if try await updateWallet() {
163158
NotificationCenter.default.post(name: .walletDidUpdate, object: nil)
164-
print("Updated wallet")
165-
} catch {
166-
print(error)
167159
}
168-
} else {
169-
print("Nothing to update")
160+
} catch {
161+
print(error)
170162
}
163+
// if let update = await client?.update() {
164+
// do {
165+
// try wallet?.applyUpdate(update: update)
166+
// NotificationCenter.default.post(name: .walletDidUpdate, object: nil)
167+
// } catch {
168+
// print(error)
169+
// }
170+
// }
171171
}
172172
}
173173
}
174174

175-
private func printLogs() {
175+
private func getNextLog() {
176176
Task {
177177
while true {
178178
if let log = try? await self.client?.nextLog() {
179-
print("\(log)")
180179
switch log {
181180
case .connectionsMet:
182-
print("######### connected")
183181
self.isConnected = true
184182
case .progress(let progress):
185183
if let fullScanProgress = self.fullScanProgress {
@@ -200,7 +198,6 @@ final class KyotoService: BDKSyncService {
200198
if let warn = try? await self.client?.nextWarning() {
201199
switch warn {
202200
case .needConnections:
203-
print("######### disconnected")
204201
self.isConnected = false
205202
default:
206203
#if DEBUG

0 commit comments

Comments
 (0)