-
Notifications
You must be signed in to change notification settings - Fork 56
feat(sdk): expose OP_RETURN, output-order and change-to-VIN0 controls #4286
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
Changes from 4 commits
6f70092
8370b6a
c3ffb89
310deeb
a1db38d
b3f2801
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 |
|---|---|---|
|
|
@@ -68,6 +68,26 @@ public final class FinalizedCoreTransaction { | |
| } | ||
|
|
||
| func takeForAbandon() throws -> Handle { try takeForBroadcast() } | ||
|
|
||
| /// Consensus-serialized signed transaction bytes (copied out) without | ||
| /// consuming the ownership token. | ||
| public func serializedData() throws -> Data { | ||
| guard nativeHandle != 0 else { | ||
| throw PlatformWalletError.unknown("FinalizedCoreTransaction already consumed") | ||
| } | ||
|
|
||
| var bytesPtr: UnsafeMutablePointer<UInt8>? = nil | ||
| var bytesLen: UInt = 0 | ||
| try core_wallet_signed_transaction_v2_bytes(nativeHandle, &bytesPtr, &bytesLen).check() | ||
|
|
||
| guard let bytesPtr, bytesLen > 0 else { | ||
| throw PlatformWalletError.unknown( | ||
| "FFI returned success but finalized transaction bytes were empty" | ||
| ) | ||
| } | ||
| defer { platform_wallet_bytes_free(bytesPtr, bytesLen) } | ||
| return Data(bytes: bytesPtr, count: Int(bytesLen)) | ||
| } | ||
| } | ||
|
|
||
| /// A built, signed Core transaction whose funding UTXOs are reserved, awaiting | ||
|
|
@@ -266,6 +286,20 @@ public final class CoreTransactionBuilder { | |
| return self | ||
| } | ||
|
|
||
| /// Add a zero-value OP_RETURN output carrying `data` for a MAYACHAIN-style | ||
| /// deposit. See https://docs.mayaprotocol.com/mayachain-dev-docs/concepts/sending-transactions | ||
| @discardableResult | ||
| public func addOpReturn(_ data: Data) throws -> CoreTransactionBuilder { | ||
| try data.withUnsafeBytes { buf in | ||
| try core_wallet_tx_builder_add_op_return( | ||
| handle, | ||
| buf.baseAddress?.assumingMemoryBound(to: UInt8.self), | ||
| UInt(data.count) | ||
| ).check() | ||
| } | ||
| return self | ||
| } | ||
|
|
||
| @discardableResult | ||
| public func setChangeAddress(_ address: String) throws -> CoreTransactionBuilder { | ||
| let c = strdup(address) | ||
|
|
@@ -274,6 +308,22 @@ public final class CoreTransactionBuilder { | |
| return self | ||
| } | ||
|
|
||
| /// Preserve outputs in insertion order for a MAYACHAIN-style deposit. | ||
| /// See https://docs.mayaprotocol.com/mayachain-dev-docs/concepts/sending-transactions | ||
| @discardableResult | ||
| public func preserveOutputOrder() throws -> CoreTransactionBuilder { | ||
| try core_wallet_tx_builder_preserve_output_order(handle).check() | ||
| return self | ||
| } | ||
|
|
||
| /// Route change to the first selected input address (VIN0) for a MAYACHAIN-style deposit. | ||
| /// See https://docs.mayaprotocol.com/mayachain-dev-docs/concepts/sending-transactions | ||
| @discardableResult | ||
| public func changeToFirstInput() throws -> CoreTransactionBuilder { | ||
| try core_wallet_tx_builder_change_to_first_input(handle).check() | ||
| return self | ||
|
Comment on lines
292
to
+324
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: Guard the new Swift setters after Rust consumes the builder
source: ['codex'] |
||
| } | ||
|
|
||
| @discardableResult | ||
| public func setFeeRate(satPerKb: UInt64) throws -> CoreTransactionBuilder { | ||
| try core_wallet_tx_builder_set_fee_rate(handle, satPerKb).check() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 Nitpick: Declare ownership of serialized byte buffers in the C ABI
core_wallet_signed_transaction_v2_bytesreturns an allocation created withBox::into_raw, but its cbindgen-visible documentation does not state that the caller takes ownership or must release the pointer usingplatform_wallet_bytes_freewith the returned length. The current Swift wrapper correctly copies and frees it, but direct C and future binding consumers cannot infer the allocator/deallocator contract and may leak the buffer or incorrectly call the platform allocator'sfree().source: ['codex']