From 0d1b44ce2ce0c7372759b37c772bb9b21e9ed9d3 Mon Sep 17 00:00:00 2001 From: Borja Castellano Date: Mon, 13 Apr 2026 16:54:01 -0700 Subject: [PATCH] add wrappers for the missing TransactionRecord fields in the swift-sdk --- .../KeyWallet/TransactionRecord.swift | 124 ++++++++++++++++-- 1 file changed, 114 insertions(+), 10 deletions(-) diff --git a/packages/swift-sdk/Sources/SwiftDashSDK/KeyWallet/TransactionRecord.swift b/packages/swift-sdk/Sources/SwiftDashSDK/KeyWallet/TransactionRecord.swift index 8ca9513c76d..b6bd2aad67c 100644 --- a/packages/swift-sdk/Sources/SwiftDashSDK/KeyWallet/TransactionRecord.swift +++ b/packages/swift-sdk/Sources/SwiftDashSDK/KeyWallet/TransactionRecord.swift @@ -1,28 +1,132 @@ import Foundation import DashSDKFFI -// This struct is not mapping all fields of FFITransactionRecord -// for the lack of wrappers +public enum TransactionType { + case standard + case coinJoin + case providerRegistration + case providerUpdateRegister + case providerUpdateService + case providerUpdateRevocation + case assetLock + case assetUnlock + case coinbase + case ignored + + init(ffi: FFITransactionType) { + switch ffi { + case FFI_TRANSACTION_TYPE_STANDARD: self = .standard + case FFI_TRANSACTION_TYPE_COIN_JOIN: self = .coinJoin + case FFI_TRANSACTION_TYPE_PROVIDER_REGISTRATION: self = .providerRegistration + case FFI_TRANSACTION_TYPE_PROVIDER_UPDATE_REGISTRAR: self = .providerUpdateRegister + case FFI_TRANSACTION_TYPE_PROVIDER_UPDATE_SERVICE: self = .providerUpdateService + case FFI_TRANSACTION_TYPE_PROVIDER_UPDATE_REVOCATION: self = .providerUpdateRevocation + case FFI_TRANSACTION_TYPE_ASSET_LOCK: self = .assetLock + case FFI_TRANSACTION_TYPE_ASSET_UNLOCK: self = .assetUnlock + case FFI_TRANSACTION_TYPE_COINBASE: self = .coinbase + case FFI_TRANSACTION_TYPE_IGNORED: self = .ignored + default: fatalError("Unknown FFITransactionType value: \(ffi)") + } + } +} + +public enum TransactionDirection { + case incoming + case outgoing + case internalDir + case coinjoin + + init(ffi: FFITransactionDirection) { + switch ffi { + case FFI_TRANSACTION_DIRECTION_INCOMING: self = .incoming + case FFI_TRANSACTION_DIRECTION_OUTGOING: self = .outgoing + case FFI_TRANSACTION_DIRECTION_INTERNAL: self = .internalDir + case FFI_TRANSACTION_DIRECTION_COIN_JOIN: self = .coinjoin + default: fatalError("Unknown FFITransactionDirection value: \(ffi)") + } + } +} + +public struct InputDetail { + public let index: UInt32 + public let value: UInt64 + public let address: String + + public init(ffi: FFIInputDetail) { + self.index = ffi.index + self.value = ffi.value + self.address = ffi.address != nil + ? String(cString: ffi.address) + : "" + } +} + +public enum OutputRole { + case received + case change + case sent + case unspendable + + init(ffi: FFIOutputRole) { + switch ffi { + case FFI_OUTPUT_ROLE_RECEIVED: self = .received + case FFI_OUTPUT_ROLE_CHANGE: self = .change + case FFI_OUTPUT_ROLE_SENT: self = .sent + case FFI_OUTPUT_ROLE_UNSPENDABLE: self = .unspendable + default: fatalError("Unknown FFIOutputRole value: \(ffi)") + } + } +} + +public struct OutputDetail { + public let index: UInt32 + public let role: OutputRole + + public init(ffi: FFIOutputDetail) { + self.index = ffi.index + self.role = OutputRole(ffi: ffi.role) + } +} + public struct NotOwnedTransactionRecord { - let txid: Data - let net_amount: Int64 - let context: TransactionContext - let fee: UInt64 - let tx_data: Data - let label: String? + public let txid: Data + public let netAmount: Int64 + public let context: TransactionContext + public let transactionType: TransactionType + public let direction: TransactionDirection + public let fee: UInt64 + public let inputDetails: [InputDetail] + public let outputDetails: [OutputDetail] + public let txData: Data + public let label: String? public init(handle: UnsafePointer) { let p = handle.pointee self.txid = withUnsafeBytes(of: p.txid) { Data($0) } - self.net_amount = p.net_amount + self.netAmount = p.net_amount self.fee = p.fee - self.tx_data = p.tx_data != nil + self.txData = p.tx_data != nil ? Data(bytes: p.tx_data, count: p.tx_len) : Data() self.label = p.label != nil ? String(cString: p.label) : nil + self.context = TransactionContext(ffi: p.context) + self.transactionType = TransactionType(ffi: p.transaction_type) + self.direction = TransactionDirection(ffi: p.direction) + + self.inputDetails = p.input_details != nil + ? (0..