-
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
Open
ZocoLini
wants to merge
1
commit into
v3.1-dev
Choose a base branch
from
chore/transaction-record-fields
base: v3.1-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+114
−10
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
124 changes: 114 additions & 10 deletions
124
packages/swift-sdk/Sources/SwiftDashSDK/KeyWallet/TransactionRecord.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| 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 | ||
|
|
||
| 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]) | ||
| } | ||
| : [] | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.