-
Notifications
You must be signed in to change notification settings - Fork 12
feat: kyoto #315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: kyoto #315
Changes from 5 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
2a912c8
wip: working i think
reez 8718349
fix(untested): show block height immediately
reez c967bd6
refactor: broadcast sync
reez 381d36c
refactor: remove log parsing
reez 6e4c2d0
Revert "refactor: remove log parsing"
reez 4b7c354
`This does not throw`
reez 99b85ae
`Why is this here`
reez 08e6b12
use `Info::NewChainHeight`
reez 3c4ed6f
Covered by `Info::SuccessfulHandshake`
reez b4db0ae
This is a warning condition `Warning::NeedConnections`
reez a97544c
set the progress to 20 percent after startup
reez 2e251d4
fix: progress calculation
reez 9f7ebfa
ui: progressview (bar) increase width
reez 364c28d
misc: comment
reez de50f90
ui: hide fullscan button in settingsview (if kyoto)
reez 92c4670
fix: auto-refresh wallet when new block height
reez e82c6cc
fix: block height font size once synced
reez c15e6e6
ui: always show latest height
reez b9d59e9
fix: kyoto could get into .notStarted state
reez 20fb312
ui: dont show green checkmark for kyoto (already have connected green…
reez 2fb7143
fix: restrict kyoto to signet
reez 303aeb4
ui: load previous transaction state when app restart
reez 2877b4b
fix: progress percent in walletviewmodel
reez b2be622
fix: client progress values are different
reez 072c513
fix: network switch because of kyoto forced network signet
reez e8c9eb6
fix: regression from 2fb7143a203662386b6aa235579f26824ceb80f5
reez 6673a1a
fix: make sure kyoto tasks killed when switching networks
reez 6e7c631
fix: esplora percent progress
reez 460da00
chore: temporary logging for kyoto due to not getting info from peer …
reez 9062dc4
chore: more temp logging because not getting peer info today
reez 19be079
chore: temp log making sure data dir is ok for peer info
reez 466fa26
chore: temp logging nextlog
reez 862f3f1
misc: remove onion
reez c1977a0
ui: show connected if progress or height
reez ada2f0a
fix: infrequent but persistent issue with ui state
reez 9976389
fix: infrequent but persistent issue with ui state (part 2)
reez b85d9de
fix: block height not showing on sync sometimes for kyoto
reez e31d484
ui: fine tune connected state by adding gray state
reez 286c39b
misc: remove print
reez bc35d67
format
reez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
176 changes: 176 additions & 0 deletions
176
BDKSwiftExampleWallet/Extensions/BDK+Extensions/CbfClient+Extensions.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
// | ||
// CbfClient+Extensions.swift | ||
// BDKSwiftExampleWallet | ||
// | ||
// Created by Matthew Ramsden on 7/30/25. | ||
// | ||
|
||
import BitcoinDevKit | ||
import Foundation | ||
|
||
extension CbfClient { | ||
static func createComponents(wallet: Wallet) -> (client: CbfClient, node: CbfNode) { | ||
do { | ||
let components = try CbfBuilder() | ||
.logLevel(logLevel: .debug) | ||
.scanType(scanType: .sync) | ||
.dataDir(dataDir: Constants.Config.Kyoto.dbPath) | ||
.peers(peers: Constants.Networks.Signet.Regular.kyotoPeers) | ||
.build(wallet: wallet) | ||
Task { | ||
do { | ||
try await components.node.run() | ||
} catch { | ||
// Kyoto: Failed to start node | ||
} | ||
} | ||
|
||
components.client.startBackgroundMonitoring() | ||
|
||
return (client: components.client, node: components.node) | ||
} catch { | ||
fatalError("Failed to create CBF components: \(error)") | ||
} | ||
} | ||
|
||
func startBackgroundMonitoring() { | ||
Task { | ||
var isConnected = false | ||
while true { | ||
if let log = try? await self.nextLog() { | ||
// Parse specific sync stage messages | ||
if log.contains("Attempting to load headers from the database") { | ||
reez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
await MainActor.run { | ||
NotificationCenter.default.post( | ||
name: NSNotification.Name("KyotoProgressUpdate"), | ||
object: nil, | ||
userInfo: ["progress": Float(0.2)] | ||
) | ||
} | ||
} else if log.contains("]: headers") { | ||
reez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
await MainActor.run { | ||
NotificationCenter.default.post( | ||
name: NSNotification.Name("KyotoProgressUpdate"), | ||
object: nil, | ||
userInfo: ["progress": Float(0.4)] | ||
) | ||
} | ||
} else if log.contains("Chain updated") { | ||
reez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let components = log.components(separatedBy: " ") | ||
if components.count >= 4, | ||
components[0] == "Chain" && components[1] == "updated", | ||
let height = UInt32(components[2]) | ||
{ | ||
await MainActor.run { | ||
NotificationCenter.default.post( | ||
name: NSNotification.Name("KyotoChainHeightUpdate"), | ||
object: nil, | ||
userInfo: ["height": height] | ||
) | ||
} | ||
} | ||
|
||
if !isConnected { | ||
reez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
isConnected = true | ||
await MainActor.run { | ||
NotificationCenter.default.post( | ||
name: NSNotification.Name("KyotoConnectionUpdate"), | ||
object: nil, | ||
userInfo: ["connected": true] | ||
) | ||
} | ||
} | ||
} | ||
|
||
if log.contains("Established an encrypted connection") && !isConnected { | ||
reez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
isConnected = true | ||
await MainActor.run { | ||
NotificationCenter.default.post( | ||
name: NSNotification.Name("KyotoConnectionUpdate"), | ||
object: nil, | ||
userInfo: ["connected": true] | ||
) | ||
} | ||
} | ||
|
||
if log.contains("Need connections") && isConnected { | ||
reez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
isConnected = false | ||
await MainActor.run { | ||
NotificationCenter.default.post( | ||
name: NSNotification.Name("KyotoConnectionUpdate"), | ||
object: nil, | ||
userInfo: ["connected": false] | ||
) | ||
} | ||
} | ||
} | ||
try? await Task.sleep(nanoseconds: 100_000_000) | ||
reez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
Task { | ||
var hasEstablishedConnection = false | ||
while true { | ||
if let info = try? await self.nextInfo() { | ||
switch info { | ||
case let .progress(progress): | ||
await MainActor.run { | ||
NotificationCenter.default.post( | ||
name: NSNotification.Name("KyotoProgressUpdate"), | ||
object: nil, | ||
userInfo: ["progress": progress] | ||
) | ||
} | ||
case let .newChainHeight(height): | ||
await MainActor.run { | ||
NotificationCenter.default.post( | ||
name: NSNotification.Name("KyotoChainHeightUpdate"), | ||
object: nil, | ||
userInfo: ["height": height] | ||
) | ||
|
||
if !hasEstablishedConnection { | ||
hasEstablishedConnection = true | ||
NotificationCenter.default.post( | ||
name: NSNotification.Name("KyotoConnectionUpdate"), | ||
object: nil, | ||
userInfo: ["connected": true] | ||
) | ||
} | ||
} | ||
case .connectionsMet: | ||
await MainActor.run { | ||
hasEstablishedConnection = true | ||
NotificationCenter.default.post( | ||
name: NSNotification.Name("KyotoConnectionUpdate"), | ||
object: nil, | ||
userInfo: ["connected": true] | ||
) | ||
} | ||
default: | ||
break | ||
} | ||
} | ||
} | ||
} | ||
|
||
Task { | ||
while true { | ||
if let warning = try? await self.nextWarning() { | ||
reez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
switch warning { | ||
case .needConnections: | ||
await MainActor.run { | ||
NotificationCenter.default.post( | ||
name: NSNotification.Name("KyotoConnectionUpdate"), | ||
object: nil, | ||
userInfo: ["connected": false] | ||
) | ||
} | ||
default: | ||
break | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.