diff --git a/packages/swift-sdk/Sources/SwiftDashSDK/Core/SPV/SPVEventHandler.swift b/packages/swift-sdk/Sources/SwiftDashSDK/Core/SPV/SPVEventHandler.swift index 2436392b3ca..23b32bd563e 100644 --- a/packages/swift-sdk/Sources/SwiftDashSDK/Core/SPV/SPVEventHandler.swift +++ b/packages/swift-sdk/Sources/SwiftDashSDK/Core/SPV/SPVEventHandler.swift @@ -488,6 +488,12 @@ public protocol SPVWalletEventsHandler: AnyObject { _ record: NotOwnedTransactionRecord ) + func onTransactionStatusChanged( + _ walletId: String, + _ txId: Data, + _ status: TransactionContext + ) + func onBalanceUpdated( _ walletId: String, _ spendable: UInt64, @@ -503,7 +509,7 @@ extension SPVWalletEventsHandler { public func intoFFIWalletEventCallbacks() -> FFIWalletEventCallbacks { FFIWalletEventCallbacks( on_transaction_received: onSpvTransactionReceivedCallbackC, - on_transaction_status_changed: nil, + on_transaction_status_changed: onSpvTransactionStatusChangedCallbackC, on_balance_updated: onSpvBalanceUpdatedCallbackC, user_data: Unmanaged.passUnretained(self).toOpaque() ) @@ -538,6 +544,30 @@ private func onSpvTransactionReceivedCallbackC( ) } +private func onSpvTransactionStatusChangedCallbackC( + walletIdPtr: UnsafePointer?, + txIdPtr: UnsafePointer?, + status: FFITransactionContext, + userData: UnsafeMutableRawPointer? +) { + let handler = rawPtrIntoSpvWalletEventsHandler(userData) + + guard let walletIdPtr else { + assertionFailure("TransactionStatusChanged walletId pointer is nil") + return + } + + let txId = bytePtrIntoData(txIdPtr, 32) + let walletId = String(cString: walletIdPtr) + let status = TransactionContext(ffi: status) + + handler.onTransactionStatusChanged( + walletId, + txId, + status + ) +} + private func onSpvBalanceUpdatedCallbackC( walletIdPtr: UnsafePointer?, spendable: UInt64, @@ -584,6 +614,12 @@ private final class DummySPVWalletEventsHandler: SPVWalletEventsHandler { _: NotOwnedTransactionRecord, ) {} + func onTransactionStatusChanged( + _ walletId: String, + _ txId: Data, + _ status: TransactionContext + ) {} + func onBalanceUpdated( _: String, _: UInt64, diff --git a/packages/swift-sdk/Sources/SwiftDashSDK/Core/Services/WalletService.swift b/packages/swift-sdk/Sources/SwiftDashSDK/Core/Services/WalletService.swift index f2f2d179047..82a27027d25 100644 --- a/packages/swift-sdk/Sources/SwiftDashSDK/Core/Services/WalletService.swift +++ b/packages/swift-sdk/Sources/SwiftDashSDK/Core/Services/WalletService.swift @@ -375,6 +375,12 @@ public class WalletService: ObservableObject { _ record: NotOwnedTransactionRecord ) {} + func onTransactionStatusChanged( + _ walletId: String, + _ txId: Data, + _ status: TransactionContext + ) {} + func onBalanceUpdated( _ walletId: String, _ spendable: UInt64,