Skip to content

Commit 59e039e

Browse files
committed
fix: using concrete type for EsploraService and Kyoto
1 parent 0540621 commit 59e039e

21 files changed

+276
-159
lines changed

BDKSwiftExampleWallet.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
779E70872DB9C98A006E22D3 /* WalletSyncScriptInspector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 779E70862DB9C98A006E22D3 /* WalletSyncScriptInspector.swift */; };
1212
779E70892DB9C9AB006E22D3 /* WalletFullScanScriptInspector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 779E70882DB9C9AB006E22D3 /* WalletFullScanScriptInspector.swift */; };
1313
77AD9F062DBB031D00182E65 /* ActivityHomeHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77AD9F052DBB031D00182E65 /* ActivityHomeHeaderView.swift */; };
14+
77DB13092DEBB4AC004B735D /* BDKClient+Kyoto.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77DB13082DEBB4A9004B735D /* BDKClient+Kyoto.swift */; };
15+
77DB130B2DEBB553004B735D /* BDKClient+Esplora.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77DB130A2DEBB550004B735D /* BDKClient+Esplora.swift */; };
1416
77F0FDC92DA9A93D00B30E4F /* Connection+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F0FDC82DA9A93700B30E4F /* Connection+Extensions.swift */; };
1517
77F6A9E32DE247B2003568F0 /* BDKSyncService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F6A9E22DE247AD003568F0 /* BDKSyncService.swift */; };
1618
77F6A9E52DE24841003568F0 /* URL+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F6A9E42DE24837003568F0 /* URL+Extensions.swift */; };
@@ -121,6 +123,8 @@
121123
779E70862DB9C98A006E22D3 /* WalletSyncScriptInspector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletSyncScriptInspector.swift; sourceTree = "<group>"; };
122124
779E70882DB9C9AB006E22D3 /* WalletFullScanScriptInspector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletFullScanScriptInspector.swift; sourceTree = "<group>"; };
123125
77AD9F052DBB031D00182E65 /* ActivityHomeHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActivityHomeHeaderView.swift; sourceTree = "<group>"; };
126+
77DB13082DEBB4A9004B735D /* BDKClient+Kyoto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BDKClient+Kyoto.swift"; sourceTree = "<group>"; };
127+
77DB130A2DEBB550004B735D /* BDKClient+Esplora.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BDKClient+Esplora.swift"; sourceTree = "<group>"; };
124128
77F0FDC82DA9A93700B30E4F /* Connection+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Connection+Extensions.swift"; sourceTree = "<group>"; };
125129
77F6A9E22DE247AD003568F0 /* BDKSyncService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BDKSyncService.swift; sourceTree = "<group>"; };
126130
77F6A9E42DE24837003568F0 /* URL+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "URL+Extensions.swift"; sourceTree = "<group>"; };
@@ -333,6 +337,8 @@
333337
AE1C34212A424434008F807A /* BDK Service */ = {
334338
isa = PBXGroup;
335339
children = (
340+
77DB130A2DEBB550004B735D /* BDKClient+Esplora.swift */,
341+
77DB13082DEBB4A9004B735D /* BDKClient+Kyoto.swift */,
336342
AED4CC092A1D297600CE1831 /* BDKService.swift */,
337343
AE79538F2A2D5B4400CCB277 /* BDKSwiftExampleWalletError.swift */,
338344
);
@@ -772,9 +778,11 @@
772778
AE6716012A9AC089005C193F /* KeyServiceError.swift in Sources */,
773779
77AD9F062DBB031D00182E65 /* ActivityHomeHeaderView.swift in Sources */,
774780
AE0C30FB2A804B95008F1EAE /* WalletViewModel.swift in Sources */,
781+
77DB130B2DEBB553004B735D /* BDKClient+Esplora.swift in Sources */,
775782
77F6A9EB2DE5072E003568F0 /* AppStorageUtil.swift in Sources */,
776783
AE49847C2A1BBBD6009951E2 /* BDKSwiftExampleWalletApp.swift in Sources */,
777784
AE6715FF2A9AC066005C193F /* FeeServiceError.swift in Sources */,
785+
77DB13092DEBB4AC004B735D /* BDKClient+Kyoto.swift in Sources */,
778786
AE2381AD2C60578500F6B00C /* ActivityListView.swift in Sources */,
779787
AE2381B32C60877600F6B00C /* LocalOutputListView.swift in Sources */,
780788
AE783A052AB4F51F005F0CBA /* String+Extensions.swift in Sources */,

BDKSwiftExampleWallet/App/BDKSwiftExampleWalletApp.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,20 @@ struct BDKSwiftExampleWalletApp: App {
2020
if value != nil && !isOnboarding {
2121
HomeView(
2222
viewModel: .init(
23-
bdkClient: .live
23+
bdkClient: .esplora
2424
),
2525
navigationPath: $navigationPath
2626
)
2727
} else {
2828
OnboardingView(
2929
viewModel: .init(
30-
bdkClient: .live
30+
bdkClient: .esplora
3131
)
3232
)
3333
}
3434
}
3535
.onChange(of: isOnboarding) { oldValue, newValue in
36-
BDKClient.live.setNeedsFullScan(true)
36+
BDKClient.esplora.setNeedsFullScan(true)
3737
navigationPath = NavigationPath()
3838
}
3939
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
//
2+
// BDKClient+Esplora.swift
3+
// BDKSwiftExampleWallet
4+
//
5+
// Created by Rubens Machion on 31/05/25.
6+
//
7+
8+
extension BDKClient {
9+
static let esplora = Self(
10+
loadWallet: {
11+
try EsploraService.shared.loadWallet()
12+
},
13+
deleteWallet: {
14+
try EsploraService.shared.deleteWallet()
15+
},
16+
createWalletFromSeed: { words in
17+
try EsploraService.shared.createWallet(params: words)
18+
},
19+
createWalletFromDescriptor: { descriptor in
20+
try EsploraService.shared.createWallet(params: descriptor)
21+
},
22+
createWalletFromXPub: { xpub in
23+
try EsploraService.shared.createWallet(params: xpub)
24+
},
25+
getBalance: {
26+
try EsploraService.shared.getBalance()
27+
},
28+
transactions: {
29+
try EsploraService.shared.getTransactions()
30+
},
31+
listUnspent: {
32+
try EsploraService.shared.listUnspent()
33+
},
34+
syncScanWithSyncScanProgress: { progress in
35+
try await EsploraService.shared.startSync(progress: progress)
36+
},
37+
fullScanWithFullScanProgress: { progress in
38+
try await EsploraService.shared.startFullScan(progress: progress)
39+
},
40+
getAddress: {
41+
try EsploraService.shared.getAddress()
42+
},
43+
send: { (address, amount, feeRate) in
44+
Task {
45+
try await EsploraService.shared.send(address: address, amount: amount, feeRate: feeRate)
46+
}
47+
},
48+
calculateFee: { tx in
49+
try EsploraService.shared.calculateFee(tx: tx)
50+
},
51+
calculateFeeRate: { tx in
52+
try EsploraService.shared.calculateFeeRate(tx: tx)
53+
},
54+
sentAndReceived: { tx in
55+
try EsploraService.shared.sentAndReceived(tx: tx)
56+
},
57+
buildTransaction: { (address, amount, feeRate) in
58+
try EsploraService.shared.buildTransaction(address: address, amount: amount, feeRate: feeRate)
59+
},
60+
getBackupInfo: {
61+
try BDKService.shared.getBackupInfo()
62+
},
63+
needsFullScan: {
64+
BDKService.shared.needsFullScanOfWallet()
65+
},
66+
setNeedsFullScan: { value in
67+
BDKService.shared.setNeedsFullScan(value)
68+
},
69+
getNetwork: {
70+
BDKService.shared.network
71+
},
72+
getEsploraURL: {
73+
BDKService.shared.esploraURL
74+
},
75+
updateNetwork: { newNetwork in
76+
BDKService.shared.updateNetwork(newNetwork)
77+
},
78+
updateEsploraURL: { newURL in
79+
BDKService.shared.updateEsploraURL(newURL)
80+
},
81+
stop: {
82+
try await EsploraService.shared.stopService()
83+
},
84+
upateSyncMode: { mode in
85+
BDKService.shared.updateSyncMode(mode)
86+
},
87+
getSyncMode: {
88+
BDKService.shared.getSyncMode()
89+
}
90+
)
91+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
//
2+
// BDKClient+.swift
3+
// BDKSwiftExampleWallet
4+
//
5+
// Created by Rubens Machion on 31/05/25.
6+
//
7+
8+
extension BDKClient {
9+
static let kyoto = Self(
10+
loadWallet: {
11+
try KyotoService.shared.loadWallet()
12+
},
13+
deleteWallet: {
14+
try KyotoService.shared.deleteWallet()
15+
},
16+
createWalletFromSeed: { words in
17+
try KyotoService.shared.createWallet(params: words)
18+
},
19+
createWalletFromDescriptor: { descriptor in
20+
try KyotoService.shared.createWallet(params: descriptor)
21+
},
22+
createWalletFromXPub: { xpub in
23+
try KyotoService.shared.createWallet(params: xpub)
24+
},
25+
getBalance: {
26+
try KyotoService.shared.getBalance()
27+
},
28+
transactions: {
29+
try KyotoService.shared.getTransactions()
30+
},
31+
listUnspent: {
32+
try KyotoService.shared.listUnspent()
33+
},
34+
syncScanWithSyncScanProgress: { progress in
35+
try await KyotoService.shared.startSync(progress: progress)
36+
},
37+
fullScanWithFullScanProgress: { progress in
38+
try await KyotoService.shared.startFullScan(progress: progress)
39+
},
40+
getAddress: {
41+
try KyotoService.shared.getAddress()
42+
},
43+
send: { (address, amount, feeRate) in
44+
Task {
45+
try await KyotoService.shared.send(address: address, amount: amount, feeRate: feeRate)
46+
}
47+
},
48+
calculateFee: { tx in
49+
try KyotoService.shared.calculateFee(tx: tx)
50+
},
51+
calculateFeeRate: { tx in
52+
try KyotoService.shared.calculateFeeRate(tx: tx)
53+
},
54+
sentAndReceived: { tx in
55+
try KyotoService.shared.sentAndReceived(tx: tx)
56+
},
57+
buildTransaction: { (address, amount, feeRate) in
58+
try KyotoService.shared.buildTransaction(address: address, amount: amount, feeRate: feeRate)
59+
},
60+
getBackupInfo: {
61+
try BDKService.shared.getBackupInfo()
62+
},
63+
needsFullScan: {
64+
BDKService.shared.needsFullScanOfWallet()
65+
},
66+
setNeedsFullScan: { value in
67+
BDKService.shared.setNeedsFullScan(value)
68+
},
69+
getNetwork: {
70+
BDKService.shared.network
71+
},
72+
getEsploraURL: {
73+
BDKService.shared.esploraURL
74+
},
75+
updateNetwork: { newNetwork in
76+
BDKService.shared.updateNetwork(newNetwork)
77+
},
78+
updateEsploraURL: { newURL in
79+
BDKService.shared.updateEsploraURL(newURL)
80+
},
81+
stop: {
82+
try await KyotoService.shared.stopService()
83+
},
84+
upateSyncMode: { mode in
85+
BDKService.shared.updateSyncMode(mode)
86+
},
87+
getSyncMode: {
88+
BDKService.shared.getSyncMode()
89+
}
90+
)
91+
}

0 commit comments

Comments
 (0)