Skip to content

Commit c4fac22

Browse files
fix(key-wallet-ffi): extract asset lock builder into key-wallet (#604)
Moves the asset lock transaction building logic out of the FFI layer into a dedicated `asset_lock_builder` module in key-wallet. The FFI function is now a thin bridge that converts types and delegates to `build_asset_lock_transaction()`. The new builder: - Lives in key-wallet/src/wallet/managed_wallet_info/asset_lock_builder.rs - Handles credit output setup, coin selection, key derivation, signing - Returns AssetLockResult with transaction, fee, output_index, private_key - Is testable without FFI and reusable from any Rust consumer Also adds `TransactionBuilder::add_raw_output(TxOut)` for adding pre-built outputs (needed for credit outputs before coin selection). Closes #602 Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 09f03e0 commit c4fac22

File tree

6 files changed

+466
-294
lines changed

6 files changed

+466
-294
lines changed

key-wallet-ffi/FFI_API.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,14 +1285,14 @@ This function dereferences a raw pointer to FFIWallet. The caller must ensure th
12851285
#### `wallet_build_and_sign_asset_lock_transaction`
12861286

12871287
```c
1288-
wallet_build_and_sign_asset_lock_transaction(manager: *const FFIWalletManager, wallet: *const FFIWallet, account_index: u32, funding_type: FFIAssetLockFundingType, identity_index: u32, credit_output_scripts: *const *const u8, credit_output_script_lens: *const usize, credit_output_amounts: *const u64, credit_outputs_count: usize, fee_per_kb: u64, fee_out: *mut u64, tx_bytes_out: *mut *mut u8, tx_len_out: *mut usize, output_index_out: *mut u32, private_key_out: *mut [u8; 32], error: *mut FFIError,) -> bool
1288+
wallet_build_and_sign_asset_lock_transaction(manager: *const FFIWalletManager, wallet: *const FFIWallet, account_index: u32, funding_types: *const FFIAssetLockFundingType, identity_indices: *const u32, credit_output_scripts: *const *const u8, credit_output_script_lens: *const usize, credit_output_amounts: *const u64, credit_outputs_count: usize, fee_per_kb: u64, fee_out: *mut u64, tx_bytes_out: *mut *mut u8, tx_len_out: *mut usize, private_keys_out: *mut [u8; 32], error: *mut FFIError,) -> bool
12891289
```
12901290

12911291
**Description:**
1292-
Build and sign an asset lock transaction for Core to Platform transfers. Creates a special transaction (type 8) with `AssetLockPayload` that locks Dash for Platform credits. Uses the wallet's UTXOs for funding and derives a one-time private key from the specified funding account type. # Parameters - `funding_type`: Which funding account to derive the one-time key from (registration, top-up, invitation, etc.) - `identity_index`: For `IdentityTopUp` funding type, the registration index of the identity being topped up. Ignored for other funding types. # Safety - All pointer parameters must be valid and non-null - `credit_output_scripts` must point to an array of `credit_outputs_count` byte-array pointers - `credit_output_script_lens` must point to an array of `credit_outputs_count` lengths - `credit_output_amounts` must point to an array of `credit_outputs_count` amounts - Caller must free `tx_bytes_out` with `transaction_bytes_free`
1292+
Build and sign an asset lock transaction for Core to Platform transfers. Creates a special transaction (type 8) with `AssetLockPayload` that locks Dash for Platform credits. Derives one unique private key per credit output from the specified funding account types. # Parameters - `funding_types`: Array of `credit_outputs_count` funding account types, one per credit output (registration, top-up, invitation, etc.) - `identity_indices`: Array of `credit_outputs_count` identity indices. Only used for `IdentityTopUp` entries; ignored for other funding types. - `private_keys_out`: Caller-allocated array of `credit_outputs_count` × 32-byte buffers. On success, each `private_keys_out[i]` receives the one-time private key corresponding to `credit_output_scripts[i]`. # Safety - All pointer parameters must be valid and non-null - All parallel arrays must have at least `credit_outputs_count` elements - `private_keys_out` must point to an array of `credit_outputs_count` × `[u8; 32]` buffers - Caller must free `tx_bytes_out` with `transaction_bytes_free`
12931293

12941294
**Safety:**
1295-
- All pointer parameters must be valid and non-null - `credit_output_scripts` must point to an array of `credit_outputs_count` byte-array pointers - `credit_output_script_lens` must point to an array of `credit_outputs_count` lengths - `credit_output_amounts` must point to an array of `credit_outputs_count` amounts - Caller must free `tx_bytes_out` with `transaction_bytes_free`
1295+
- All pointer parameters must be valid and non-null - All parallel arrays must have at least `credit_outputs_count` elements - `private_keys_out` must point to an array of `credit_outputs_count` × `[u8; 32]` buffers - Caller must free `tx_bytes_out` with `transaction_bytes_free`
12961296

12971297
**Module:** `transaction`
12981298

0 commit comments

Comments
 (0)