Skip to content

Commit 48a0ec8

Browse files
committed
txdetails+helpers
1 parent 6aaa5e4 commit 48a0ec8

File tree

6 files changed

+73
-4
lines changed

6 files changed

+73
-4
lines changed

BDKSwiftExampleWallet.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
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 */; };
6262
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 */; };
6365
AE7839FD2AB4E18D005F0CBA /* AmountView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE7839FC2AB4E18D005F0CBA /* AmountView.swift */; };
6466
AE783A012AB4E5E1005F0CBA /* BuildTransactionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE783A002AB4E5E1005F0CBA /* BuildTransactionView.swift */; };
6567
AE783A032AB4ECC2005F0CBA /* AddressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE783A022AB4ECC2005F0CBA /* AddressView.swift */; };
@@ -163,6 +165,8 @@
163165
AE6716002A9AC089005C193F /* KeyServiceError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyServiceError.swift; sourceTree = "<group>"; };
164166
AE6F34D72AA6C1800087E700 /* Network+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Network+Extensions.swift"; sourceTree = "<group>"; };
165167
AE6F34D92AA6C1E00087E700 /* Balance+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Balance+Extensions.swift"; sourceTree = "<group>"; };
168+
AE7323982DF9BF9700D9BAE2 /* TxDetails+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TxDetails+Extensions.swift"; sourceTree = "<group>"; };
169+
AE73239A2DF9C00F00D9BAE2 /* TxId+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TxId+Extensions.swift"; sourceTree = "<group>"; };
166170
AE7839FC2AB4E18D005F0CBA /* AmountView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AmountView.swift; sourceTree = "<group>"; };
167171
AE783A002AB4E5E1005F0CBA /* BuildTransactionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BuildTransactionView.swift; sourceTree = "<group>"; };
168172
AE783A022AB4ECC2005F0CBA /* AddressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddressView.swift; sourceTree = "<group>"; };
@@ -568,6 +572,8 @@
568572
AE91CEEC2C0FDB70000AAD20 /* SentAndReceivedValues+Extensions.swift */,
569573
AE91CEEE2C0FDBC7000AAD20 /* CanonicalTx+Extensions.swift */,
570574
AEEA0E3F2DEF80B600C83255 /* Outpoint+Extensions.swift */,
575+
AE7323982DF9BF9700D9BAE2 /* TxDetails+Extensions.swift */,
576+
AE73239A2DF9C00F00D9BAE2 /* TxId+Extensions.swift */,
571577
);
572578
path = "BDK+Extensions";
573579
sourceTree = "<group>";
@@ -734,6 +740,7 @@
734740
AE2ADD742B61E8F500C2A823 /* SettingsView.swift in Sources */,
735741
AE2381AF2C605B1D00F6B00C /* ActivityListViewModel.swift in Sources */,
736742
AE6F34D82AA6C1800087E700 /* Network+Extensions.swift in Sources */,
743+
AE73239B2DF9C00F00D9BAE2 /* TxId+Extensions.swift in Sources */,
737744
AE1390C72A7DB0AF0098127A /* KeyService.swift in Sources */,
738745
AED4CC0A2A1D297600CE1831 /* BDKService.swift in Sources */,
739746
AED4CC102A1D522100CE1831 /* WalletView.swift in Sources */,
@@ -762,6 +769,7 @@
762769
AE34DDAE2B6B320F00F04AD4 /* WalletRecoveryViewModel.swift in Sources */,
763770
AE0C30F92A804B65008F1EAE /* OnboardingViewModel.swift in Sources */,
764771
AE3902A42A3B4CD900BEC318 /* HomeView.swift in Sources */,
772+
AE7323992DF9BF9700D9BAE2 /* TxDetails+Extensions.swift in Sources */,
765773
AE0C30FD2A804BC1008F1EAE /* ReceiveViewModel.swift in Sources */,
766774
);
767775
runOnlyForDeploymentPostprocessing = 0;

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/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: 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 Foundation
9+
import BitcoinDevKit
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 Foundation
9+
import BitcoinDevKit
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+
}

BDKSwiftExampleWallet/Service/BDK Service/BDKService.swift

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,14 @@ private class BDKService {
412412
let values = wallet.sentAndReceived(tx: tx)
413413
return values
414414
}
415+
416+
func txDetails(txid: Txid) throws -> TxDetails? {
417+
guard let wallet = self.wallet else {
418+
throw WalletError.walletNotFound
419+
}
420+
let txDetails = wallet.txDetails(txid: txid)
421+
return txDetails
422+
}
415423
}
416424

417425
extension BDKService {
@@ -440,6 +448,7 @@ struct BDKClient {
440448
let calculateFee: (Transaction) throws -> Amount
441449
let calculateFeeRate: (Transaction) throws -> UInt64
442450
let sentAndReceived: (Transaction) throws -> SentAndReceivedValues
451+
let txDetails: (Txid) throws -> TxDetails?
443452
let buildTransaction: (String, UInt64, UInt64) throws -> Psbt
444453
let getBackupInfo: () throws -> BackupInfo
445454
let needsFullScan: () -> Bool
@@ -479,6 +488,7 @@ extension BDKClient {
479488
calculateFee: { tx in try BDKService.shared.calculateFee(tx: tx) },
480489
calculateFeeRate: { tx in try BDKService.shared.calculateFeeRate(tx: tx) },
481490
sentAndReceived: { tx in try BDKService.shared.sentAndReceived(tx: tx) },
491+
txDetails: { txid in try BDKService.shared.txDetails(txid: txid) },
482492
buildTransaction: { (address, amount, feeRate) in
483493
try BDKService.shared.buildTransaction(
484494
address: address,
@@ -527,14 +537,15 @@ extension BDKClient {
527537
fullScanWithInspector: { _ in },
528538
getAddress: { "tb1pd8jmenqpe7rz2mavfdx7uc8pj7vskxv4rl6avxlqsw2u8u7d4gfs97durt" },
529539
send: { _, _, _ in },
530-
calculateFee: { _ in Amount.fromSat(satoshi: UInt64(615)) },
531-
calculateFeeRate: { _ in return UInt64(6.15) },
540+
calculateFee: { _ in Amount.mock },
541+
calculateFeeRate: { _ in UInt64(6.15) },
532542
sentAndReceived: { _ in
533543
return SentAndReceivedValues(
534-
sent: Amount.fromSat(satoshi: UInt64(20000)),
535-
received: Amount.fromSat(satoshi: UInt64(210))
544+
sent: .mock,
545+
received: .mock
536546
)
537547
},
548+
txDetails: { _ in .mock },
538549
buildTransaction: { _, _, _ in
539550
let pb64 = """
540551
cHNidP8BAIkBAAAAAeaWcxp4/+xSRJ2rhkpUJ+jQclqocoyuJ/ulSZEgEkaoAQAAAAD+////Ak/cDgAAAAAAIlEgqxShDO8ifAouGyRHTFxWnTjpY69Cssr3IoNQvMYOKG/OVgAAAAAAACJRIGnlvMwBz4Ylb6xLTe5g4ZeZCxmVH/XWG+CDlcPzzaoT8qoGAAABAStAQg8AAAAAACJRIFGGvSoLWt3hRAIwYa8KEyawiFTXoOCVWFxYtSofZuAsIRZ2b8YiEpzexWYGt8B5EqLM8BE4qxJY3pkiGw/8zOZGYxkAvh7sj1YAAIABAACAAAAAgAAAAAAEAAAAARcgdm/GIhKc3sVmBrfAeRKizPAROKsSWN6ZIhsP/MzmRmMAAQUge7cvJMsJmR56NzObGOGkm8vNqaAIJdnBXLZD2PvrinIhB3u3LyTLCZkeejczmxjhpJvLzamgCCXZwVy2Q9j764pyGQC+HuyPVgAAgAEAAIAAAACAAQAAAAYAAAAAAQUgtIFPrI2EW/+PJiAmYdmux88p0KgeAxDFLMoeQoS66hIhB7SBT6yNhFv/jyYgJmHZrsfPKdCoHgMQxSzKHkKEuuoSGQC+HuyPVgAAgAEAAIAAAACAAAAAAAIAAAAA

0 commit comments

Comments
 (0)