Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,12 @@ public protocol SPVWalletEventsHandler: AnyObject {
_ record: NotOwnedTransactionRecord
)

func onTransactionStatusChanged(
_ walletId: String,
_ txId: Data,
_ status: TransactionContext
)

func onBalanceUpdated(
_ walletId: String,
_ spendable: UInt64,
Expand All @@ -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()
)
Expand Down Expand Up @@ -538,6 +544,30 @@ private func onSpvTransactionReceivedCallbackC(
)
}

private func onSpvTransactionStatusChangedCallbackC(
walletIdPtr: UnsafePointer<CChar>?,
txIdPtr: UnsafePointer<Byte32>?,
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
)
}
Comment thread
ZocoLini marked this conversation as resolved.

private func onSpvBalanceUpdatedCallbackC(
walletIdPtr: UnsafePointer<CChar>?,
spendable: UInt64,
Expand Down Expand Up @@ -584,6 +614,12 @@ private final class DummySPVWalletEventsHandler: SPVWalletEventsHandler {
_: NotOwnedTransactionRecord,
) {}

func onTransactionStatusChanged(
_ walletId: String,
_ txId: Data,
_ status: TransactionContext
) {}

func onBalanceUpdated(
_: String,
_: UInt64,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,12 @@ public class WalletService: ObservableObject {
_ record: NotOwnedTransactionRecord
) {}

func onTransactionStatusChanged(
_ walletId: String,
_ txId: Data,
_ status: TransactionContext
) {}

func onBalanceUpdated(
_ walletId: String,
_ spendable: UInt64,
Expand Down
Loading