-
Notifications
You must be signed in to change notification settings - Fork 53
chore(swift-sdk): add wrappers for the missing TransactionRecord fields in the swift-sdk #3488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v3.1-dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -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 | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+62
to
+67
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Suggestion:
💡 Suggested change
Suggested change
source: ['claude', 'codex'] 🤖 Fix this with AI agents |
||||||||||||||||||||||||||||||||||||
| 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)") | ||||||||||||||||||||||||||||||||||||
|
ZocoLini marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| public struct OutputDetail { | ||||||||||||||||||||||||||||||||||||
| public let index: UInt32 | ||||||||||||||||||||||||||||||||||||
| public let role: OutputRole | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+23
to
+83
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Blocking: Unknown FFI enum values now crash transaction decoding
source: ['claude', 'codex'] 🤖 Fix this with AI agents |
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| public init(ffi: FFIOutputDetail) { | ||||||||||||||||||||||||||||||||||||
| self.index = ffi.index | ||||||||||||||||||||||||||||||||||||
| self.role = OutputRole(ffi: ffi.role) | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
coderabbitai[bot] marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| 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<FFITransactionRecord>) { | ||||||||||||||||||||||||||||||||||||
| 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..<p.input_details_count).map { i in | ||||||||||||||||||||||||||||||||||||
| InputDetail(ffi: p.input_details[i]) | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| : [] | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| self.outputDetails = p.output_details != nil | ||||||||||||||||||||||||||||||||||||
| ? (0..<p.output_details_count).map { i in | ||||||||||||||||||||||||||||||||||||
| OutputDetail(ffi: p.output_details[i]) | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| : [] | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.