Skip to content

Commit 7c2c2f9

Browse files
authored
spm: bdk-ffi 2.0
1 parent dc057ad commit 7c2c2f9

27 files changed

+275
-160
lines changed

BDKSwiftExampleWallet.xcodeproj/project.pbxproj

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
AE6716012A9AC089005C193F /* KeyServiceError.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE6716002A9AC089005C193F /* KeyServiceError.swift */; };
6060
AE6F34D82AA6C1800087E700 /* Network+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE6F34D72AA6C1800087E700 /* Network+Extensions.swift */; };
6161
AE6F34DA2AA6C1E00087E700 /* Balance+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE6F34D92AA6C1E00087E700 /* Balance+Extensions.swift */; };
62+
AE7053262DE79AA30091DD78 /* BitcoinDevKit in Frameworks */ = {isa = PBXBuildFile; productRef = AE7053252DE79AA30091DD78 /* BitcoinDevKit */; };
63+
AE7323992DF9BF9700D9BAE2 /* TxDetails+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE7323982DF9BF9700D9BAE2 /* TxDetails+Extensions.swift */; };
64+
AE73239B2DF9C00F00D9BAE2 /* TxId+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE73239A2DF9C00F00D9BAE2 /* TxId+Extensions.swift */; };
6265
AE7839FD2AB4E18D005F0CBA /* AmountView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE7839FC2AB4E18D005F0CBA /* AmountView.swift */; };
6366
AE783A012AB4E5E1005F0CBA /* BuildTransactionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE783A002AB4E5E1005F0CBA /* BuildTransactionView.swift */; };
6467
AE783A032AB4ECC2005F0CBA /* AddressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE783A022AB4ECC2005F0CBA /* AddressView.swift */; };
@@ -77,6 +80,7 @@
7780
AE91CEED2C0FDB70000AAD20 /* SentAndReceivedValues+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE91CEEC2C0FDB70000AAD20 /* SentAndReceivedValues+Extensions.swift */; };
7881
AE91CEEF2C0FDBC7000AAD20 /* CanonicalTx+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE91CEEE2C0FDBC7000AAD20 /* CanonicalTx+Extensions.swift */; };
7982
AE96F6622A424C400055623C /* BDKSwiftExampleWalletReceiveViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE96F6612A424C400055623C /* BDKSwiftExampleWalletReceiveViewModelTests.swift */; };
83+
AEA0A6272E297203008A525B /* BitcoinDevKit in Frameworks */ = {isa = PBXBuildFile; productRef = AEA0A6262E297203008A525B /* BitcoinDevKit */; };
8084
AEAB03112ABDDB86000C9528 /* FeeViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEAB03102ABDDB86000C9528 /* FeeViewModel.swift */; };
8185
AEAB03132ABDDBF4000C9528 /* AmountViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEAB03122ABDDBF4000C9528 /* AmountViewModel.swift */; };
8286
AEAF83B62B7BD4D10019B23B /* CodeScanner in Frameworks */ = {isa = PBXBuildFile; productRef = AEAF83B52B7BD4D10019B23B /* CodeScanner */; };
@@ -99,6 +103,7 @@
99103
AEE6C74C2ABCB3E200442ADD /* Transaction+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE6C74B2ABCB3E200442ADD /* Transaction+Extensions.swift */; };
100104
AEE6C74F2ABCBA4600442ADD /* WalletSyncState.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE6C74E2ABCBA4600442ADD /* WalletSyncState.swift */; };
101105
AEE83A492C07F54B00834468 /* BitcoinDevKit in Frameworks */ = {isa = PBXBuildFile; productRef = AEE83A482C07F54B00834468 /* BitcoinDevKit */; };
106+
AEEA0E402DEF80B600C83255 /* Outpoint+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEEA0E3F2DEF80B600C83255 /* Outpoint+Extensions.swift */; };
102107
/* End PBXBuildFile section */
103108

104109
/* Begin PBXContainerItemProxy section */
@@ -161,6 +166,8 @@
161166
AE6716002A9AC089005C193F /* KeyServiceError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyServiceError.swift; sourceTree = "<group>"; };
162167
AE6F34D72AA6C1800087E700 /* Network+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Network+Extensions.swift"; sourceTree = "<group>"; };
163168
AE6F34D92AA6C1E00087E700 /* Balance+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Balance+Extensions.swift"; sourceTree = "<group>"; };
169+
AE7323982DF9BF9700D9BAE2 /* TxDetails+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TxDetails+Extensions.swift"; sourceTree = "<group>"; };
170+
AE73239A2DF9C00F00D9BAE2 /* TxId+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TxId+Extensions.swift"; sourceTree = "<group>"; };
164171
AE7839FC2AB4E18D005F0CBA /* AmountView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AmountView.swift; sourceTree = "<group>"; };
165172
AE783A002AB4E5E1005F0CBA /* BuildTransactionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BuildTransactionView.swift; sourceTree = "<group>"; };
166173
AE783A022AB4ECC2005F0CBA /* AddressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddressView.swift; sourceTree = "<group>"; };
@@ -197,14 +204,17 @@
197204
AED79FC42A97D47D00FD3C7D /* BDKSwiftExampleWalletSendViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BDKSwiftExampleWalletSendViewModelTests.swift; sourceTree = "<group>"; };
198205
AEE6C74B2ABCB3E200442ADD /* Transaction+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Transaction+Extensions.swift"; sourceTree = "<group>"; };
199206
AEE6C74E2ABCBA4600442ADD /* WalletSyncState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletSyncState.swift; sourceTree = "<group>"; };
207+
AEEA0E3F2DEF80B600C83255 /* Outpoint+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Outpoint+Extensions.swift"; sourceTree = "<group>"; };
200208
/* End PBXFileReference section */
201209

202210
/* Begin PBXFrameworksBuildPhase section */
203211
AE4984752A1BBBD6009951E2 /* Frameworks */ = {
204212
isa = PBXFrameworksBuildPhase;
205213
buildActionMask = 2147483647;
206214
files = (
215+
AE7053262DE79AA30091DD78 /* BitcoinDevKit in Frameworks */,
207216
AE2DD83F2D6FEF3600E5F212 /* BitcoinDevKit in Frameworks */,
217+
AEA0A6272E297203008A525B /* BitcoinDevKit in Frameworks */,
208218
AE187D782C9BB3B50081D0C3 /* BitcoinDevKit in Frameworks */,
209219
AE29ED0F2BBE2E7100EB9C4F /* BitcoinDevKit in Frameworks */,
210220
AEAF83B62B7BD4D10019B23B /* CodeScanner in Frameworks */,
@@ -563,6 +573,9 @@
563573
AE184EFB2BFE52C800374362 /* Amount+Extensions.swift */,
564574
AE91CEEC2C0FDB70000AAD20 /* SentAndReceivedValues+Extensions.swift */,
565575
AE91CEEE2C0FDBC7000AAD20 /* CanonicalTx+Extensions.swift */,
576+
AEEA0E3F2DEF80B600C83255 /* Outpoint+Extensions.swift */,
577+
AE7323982DF9BF9700D9BAE2 /* TxDetails+Extensions.swift */,
578+
AE73239A2DF9C00F00D9BAE2 /* TxId+Extensions.swift */,
566579
);
567580
path = "BDK+Extensions";
568581
sourceTree = "<group>";
@@ -595,6 +608,8 @@
595608
AE2DD8382D6FE9B000E5F212 /* BitcoinDevKit */,
596609
AE2DD83B2D6FEC3100E5F212 /* BitcoinDevKit */,
597610
AE2DD83E2D6FEF3600E5F212 /* BitcoinDevKit */,
611+
AE7053252DE79AA30091DD78 /* BitcoinDevKit */,
612+
AEA0A6262E297203008A525B /* BitcoinDevKit */,
598613
);
599614
productName = BDKSwiftExampleWallet;
600615
productReference = AE4984782A1BBBD6009951E2 /* BDKSwiftExampleWallet.app */;
@@ -652,7 +667,7 @@
652667
AE7D5A0C2A7EE62200EAC8CE /* XCRemoteSwiftPackageReference "KeychainAccess" */,
653668
AEB735D12B2CC4B900F99DBB /* XCRemoteSwiftPackageReference "BitcoinUI" */,
654669
AEAF83B42B7BD4D10019B23B /* XCRemoteSwiftPackageReference "CodeScanner" */,
655-
AEA2DEF12D70F8840067C0EB /* XCRemoteSwiftPackageReference "bdk-swift" */,
670+
AEA0A6252E297203008A525B /* XCRemoteSwiftPackageReference "bdk-swift" */,
656671
);
657672
productRefGroup = AE4984792A1BBBD6009951E2 /* Products */;
658673
projectDirPath = "";
@@ -728,12 +743,14 @@
728743
AE2ADD742B61E8F500C2A823 /* SettingsView.swift in Sources */,
729744
AE2381AF2C605B1D00F6B00C /* ActivityListViewModel.swift in Sources */,
730745
AE6F34D82AA6C1800087E700 /* Network+Extensions.swift in Sources */,
746+
AE73239B2DF9C00F00D9BAE2 /* TxId+Extensions.swift in Sources */,
731747
AE1390C72A7DB0AF0098127A /* KeyService.swift in Sources */,
732748
AED4CC0A2A1D297600CE1831 /* BDKService.swift in Sources */,
733749
AED4CC102A1D522100CE1831 /* WalletView.swift in Sources */,
734750
AE7F67092A7451AA00CED561 /* Price.swift in Sources */,
735751
AE184EFC2BFE52C800374362 /* Amount+Extensions.swift in Sources */,
736752
779E70892DB9C9AB006E22D3 /* WalletFullScanScriptInspector.swift in Sources */,
753+
AEEA0E402DEF80B600C83255 /* Outpoint+Extensions.swift in Sources */,
737754
AE2381B12C60690900F6B00C /* LocalOutput+Extensions.swift in Sources */,
738755
779E70872DB9C98A006E22D3 /* WalletSyncScriptInspector.swift in Sources */,
739756
AE7F67072A744CE200CED561 /* Double+Extensions.swift in Sources */,
@@ -755,6 +772,7 @@
755772
AE34DDAE2B6B320F00F04AD4 /* WalletRecoveryViewModel.swift in Sources */,
756773
AE0C30F92A804B65008F1EAE /* OnboardingViewModel.swift in Sources */,
757774
AE3902A42A3B4CD900BEC318 /* HomeView.swift in Sources */,
775+
AE7323992DF9BF9700D9BAE2 /* TxDetails+Extensions.swift in Sources */,
758776
AE0C30FD2A804BC1008F1EAE /* ReceiveViewModel.swift in Sources */,
759777
);
760778
runOnlyForDeploymentPostprocessing = 0;
@@ -1063,12 +1081,12 @@
10631081
version = 4.2.2;
10641082
};
10651083
};
1066-
AEA2DEF12D70F8840067C0EB /* XCRemoteSwiftPackageReference "bdk-swift" */ = {
1084+
AEA0A6252E297203008A525B /* XCRemoteSwiftPackageReference "bdk-swift" */ = {
10671085
isa = XCRemoteSwiftPackageReference;
10681086
repositoryURL = "https://github.com/bitcoindevkit/bdk-swift";
10691087
requirement = {
10701088
kind = exactVersion;
1071-
version = 1.2.0;
1089+
version = 2.0.0;
10721090
};
10731091
};
10741092
AEAF83B42B7BD4D10019B23B /* XCRemoteSwiftPackageReference "CodeScanner" */ = {
@@ -1118,11 +1136,20 @@
11181136
isa = XCSwiftPackageProductDependency;
11191137
productName = BitcoinDevKit;
11201138
};
1139+
AE7053252DE79AA30091DD78 /* BitcoinDevKit */ = {
1140+
isa = XCSwiftPackageProductDependency;
1141+
productName = BitcoinDevKit;
1142+
};
11211143
AE7D5A0D2A7EE62200EAC8CE /* KeychainAccess */ = {
11221144
isa = XCSwiftPackageProductDependency;
11231145
package = AE7D5A0C2A7EE62200EAC8CE /* XCRemoteSwiftPackageReference "KeychainAccess" */;
11241146
productName = KeychainAccess;
11251147
};
1148+
AEA0A6262E297203008A525B /* BitcoinDevKit */ = {
1149+
isa = XCSwiftPackageProductDependency;
1150+
package = AEA0A6252E297203008A525B /* XCRemoteSwiftPackageReference "bdk-swift" */;
1151+
productName = BitcoinDevKit;
1152+
};
11261153
AEAF83B52B7BD4D10019B23B /* CodeScanner */ = {
11271154
isa = XCSwiftPackageProductDependency;
11281155
package = AEAF83B42B7BD4D10019B23B /* XCRemoteSwiftPackageReference "CodeScanner" */;

BDKSwiftExampleWallet/Extensions/BDK+Extensions/Amount+Extensions.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ extension Amount: @retroactive Equatable {
1313
return lhs.toSat() == rhs.toSat()
1414
}
1515
}
16+
17+
extension Amount {
18+
static let mock = Amount.fromSat(satoshi: 100_000)
19+
}

BDKSwiftExampleWallet/Extensions/BDK+Extensions/CanonicalTx+Extensions.swift

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,27 @@ extension CanonicalTx {
1616
confirmationBlockTime: .init(
1717
blockId: .init(
1818
height: UInt32(12),
19-
hash: "hash"
19+
// hash: try! BlockHash.fromBytes(
20+
// bytes: Data([
21+
// 0xc1, 0xf9, 0xfe, 0x0d, 0x7f, 0x97, 0xc6, 0x49,
22+
// 0x0f, 0x83, 0x60, 0xcf, 0x71, 0xbb, 0xef, 0x15,
23+
// 0x1f, 0x2e, 0x73, 0x30, 0x2b, 0xd0, 0x6f, 0x16,
24+
// 0x90, 0xd6, 0x40, 0xb9, 0x6f, 0xb9, 0x44, 0x57,
25+
// ])
26+
// )
27+
hash: try! BlockHash.fromString(hex: String.mockHashHex)
2028
),
2129
confirmationTime: UInt64(21)
2230
),
23-
transitively: "c1f9fe0d7f97c6490f8360cf71bbef151f2e73302bd06f1690d640b96fb94457"
31+
// transitively: try! Txid.fromBytes(
32+
// bytes: Data([
33+
// 0xc1, 0xf9, 0xfe, 0x0d, 0x7f, 0x97, 0xc6, 0x49,
34+
// 0x0f, 0x83, 0x60, 0xcf, 0x71, 0xbb, 0xef, 0x15,
35+
// 0x1f, 0x2e, 0x73, 0x30, 0x2b, 0xd0, 0x6f, 0x16,
36+
// 0x90, 0xd6, 0x40, 0xb9, 0x6f, 0xb9, 0x44, 0x57,
37+
// ])
38+
// )
39+
transitively: try! Txid.fromString(hex: String.mockHashHex)
2440
)
2541
)
2642
}

BDKSwiftExampleWallet/Extensions/BDK+Extensions/ChainPosition+Extensions.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@ extension ChainPosition {
3232
}
3333
}
3434
}
35+
36+
extension ChainPosition {
37+
static let mock = ChainPosition.unconfirmed(timestamp: nil)
38+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import BitcoinDevKit
22
import Foundation
33

4-
extension Connection {
5-
static func createConnection() throws -> Connection {
4+
extension Persister {
5+
static func createConnection() throws -> Persister {
66
let documentsDirectoryURL = URL.documentsDirectory
77
let walletDataDirectoryURL = documentsDirectoryURL.appendingPathComponent("wallet_data")
88

@@ -14,7 +14,7 @@ extension Connection {
1414
try FileManager.default.removeOldFlatFileIfNeeded(at: documentsDirectoryURL)
1515
let persistenceBackendPath = walletDataDirectoryURL.appendingPathComponent("wallet.sqlite")
1616
.path
17-
let connection = try Connection(path: persistenceBackendPath)
18-
return connection
17+
let persister = try Persister.newSqlite(path: persistenceBackendPath)
18+
return persister
1919
}
2020
}

BDKSwiftExampleWallet/Extensions/BDK+Extensions/LocalOutput+Extensions.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,26 @@
66
//
77

88
import BitcoinDevKit
9+
import Foundation
910

1011
//#if DEBUG
1112
extension LocalOutput {
1213
static var mock = LocalOutput(
1314
outpoint: OutPoint(
14-
txid: "txid",
15+
// txid: try! Txid.fromBytes(
16+
// bytes: Data([
17+
// 0xc1, 0xf9, 0xfe, 0x0d, 0x7f, 0x97, 0xc6, 0x49,
18+
// 0x0f, 0x83, 0x60, 0xcf, 0x71, 0xbb, 0xef, 0x15,
19+
// 0x1f, 0x2e, 0x73, 0x30, 0x2b, 0xd0, 0x6f, 0x16,
20+
// 0x90, 0xd6, 0x40, 0xb9, 0x6f, 0xb9, 0x44, 0x57,
21+
// ])
22+
// ),
23+
txid: try! Txid.fromString(hex: String.mockHashHex),
1524
vout: UInt32(1)
1625
),
1726
txout: TxOut(
18-
value: UInt64(1),
19-
scriptPubkey: Script(rawOutputScript: [UInt8(1)])
27+
value: .fromSat(satoshi: 1),
28+
scriptPubkey: Script.init(rawOutputScript: Data([0x51]))
2029
),
2130
keychain: .external,
2231
isSpent: false,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// Outpoint+Extensions.swift
3+
// BDKSwiftExampleWallet
4+
//
5+
// Created by Matthew Ramsden on 6/3/25.
6+
//
7+
8+
import BitcoinDevKit
9+
import Foundation
10+
11+
extension OutPoint: Hashable {
12+
public static func == (lhs: OutPoint, rhs: OutPoint) -> Bool {
13+
lhs.txid == rhs.txid && lhs.vout == rhs.vout
14+
}
15+
16+
public func hash(into hasher: inout Hasher) {
17+
hasher.combine(txid)
18+
hasher.combine(vout)
19+
}
20+
}

BDKSwiftExampleWallet/Extensions/BDK+Extensions/Transaction+Extensions.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@
66
//
77

88
import BitcoinDevKit
9+
import Foundation
910

1011
extension Transaction {
1112
var transactionID: String {
12-
return self.computeTxid()
13+
return "\(self.computeTxid())"
1314
}
1415
}
1516

1617
//#if DEBUG
1718
extension Transaction {
1819
static var mock = try? Transaction(
19-
transactionBytes: String.mockTransactionHex.hexStringToByteArray()
20+
transactionBytes: Data(String.mockTransactionHex.hexStringToByteArray())
2021
)
2122
}
2223
//#endif
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// TxDetails+Extensions.swift
3+
// BDKSwiftExampleWallet
4+
//
5+
// Created by Matthew Ramsden on 6/11/25.
6+
//
7+
8+
import BitcoinDevKit
9+
import Foundation
10+
11+
extension TxDetails {
12+
static let mock = TxDetails(
13+
txid: .mock!,
14+
sent: .mock,
15+
received: .mock,
16+
fee: nil,
17+
feeRate: nil,
18+
balanceDelta: Int64(0),
19+
chainPosition: .mock,
20+
tx: .mock!
21+
)
22+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// TxId+Extensions.swift
3+
// BDKSwiftExampleWallet
4+
//
5+
// Created by Matthew Ramsden on 6/11/25.
6+
//
7+
8+
import BitcoinDevKit
9+
import Foundation
10+
11+
extension Txid {
12+
static let mock = try? Txid.fromBytes(
13+
bytes: Data([
14+
0xc1, 0xf9, 0xfe, 0x0d, 0x7f, 0x97, 0xc6, 0x49,
15+
0x0f, 0x83, 0x60, 0xcf, 0x71, 0xbb, 0xef, 0x15,
16+
0x1f, 0x2e, 0x73, 0x30, 0x2b, 0xd0, 0x6f, 0x16,
17+
0x90, 0xd6, 0x40, 0xb9, 0x6f, 0xb9, 0x44, 0x57,
18+
])
19+
)
20+
}

0 commit comments

Comments
 (0)