feat(key-wallet-ffi): one-shot transaction decode to (address, amount) structs#870
Conversation
…) structs Port the transaction-decode FFI from dashpay/platform#3981 (rs-platform-wallet-ffi/src/tx_decode.rs) into key-wallet-ffi, so wallet-less Core-chain decoding lives next to the library that owns the types. `transaction_decode` consensus-decodes raw tx bytes into `DecodedTransactionFFI` — per-input `(prev_txid, prev_vout, best-effort sender address)` and per-output `(address, value_duffs, scriptPubKey)` — in one struct-out call; `decoded_transaction_free` releases it. Adapted from the platform version to this crate's conventions: bool return with an `FFIError` out-parameter instead of a result struct, and `dash_network::ffi::FFINetwork`. Struct names are kept verbatim so the Swift wrapper migration stays a re-point. Closes #869 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 51 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds a public FFI transaction decoder that deserializes raw Dash transactions, exposes inputs and outputs with derived addresses and scripts, and provides cleanup for allocated memory. Tests cover decoding, error handling, network rendering, and ownership behavior. ChangesTransaction decode FFI
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant transaction_decode
participant DashcoreTransaction
participant decoded_transaction_free
Caller->>transaction_decode: raw transaction bytes and network
transaction_decode->>DashcoreTransaction: consensus deserialize
DashcoreTransaction-->>transaction_decode: decoded transaction fields
transaction_decode-->>Caller: DecodedTransactionFFI
Caller->>decoded_transaction_free: decoded transaction pointer
decoded_transaction_free-->>Caller: allocations released
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #870 +/- ##
==========================================
+ Coverage 73.69% 73.91% +0.22%
==========================================
Files 324 325 +1
Lines 73434 73775 +341
==========================================
+ Hits 54117 54534 +417
+ Misses 19317 19241 -76
|
Pre-commit fixes: regenerate FFI_API.md for the new transaction_decode / decoded_transaction_free entries, and "unparseable" -> "unparsable" per the typos hook. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Reviewed |
…let-ffi The transaction-decode FFI added by this PR was upstreamed into rust-dashcore's key-wallet-ffi (dashpay/rust-dashcore#870), where it belongs: it is pure Core-chain functionality with no platform-wallet involvement. Bump the rust-dashcore pin to that merge commit (one commit, additive only), delete the platform-side copy from rs-platform-wallet-ffi, and re-point the thin Swift wrapper at key-wallet-ffi's transaction_decode / decoded_transaction_free using the FFIError + bool house convention. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Closes #869
Ports the transaction-decode FFI from dashpay/platform#3981 (
rs-platform-wallet-ffi/src/tx_decode.rs) intokey-wallet-ffi, per the layering rule in the issue: wallet-less Core-chain FFI utilities belong next to the library that owns their types.What's added
New module
key-wallet-ffi/src/tx_decode.rs:DecodedTransactionFFI { txid[32], inputs*, inputs_count, outputs*, outputs_count }DecodedTxInputFFI { prev_txid[32], prev_vout, address* }DecodedTxOutputFFI { address*, value_duffs, script_pubkey*, script_pubkey_len }transaction_decode(tx_bytes, tx_bytes_len, network, out_decoded, error) -> bool— one-shot struct-out decode; rejects trailing bytes after a valid transactiondecoded_transaction_free(decoded)— releases the whole tree; safe on nullSemantics carried over unchanged from the platform implementation:
addressfromAddress::from_script; null for non-standard scripts (OP_RETURN, bare multisig, …).addressis best-effort recovery from P2PKH-shaped scriptSigs (exactly two pushes: DER-shaped sig then 33/65-byte pubkey) and is unauthenticated — display/matching hint only; the aggressive doc warnings are kept.txid/prev_txidin consensus (internal) byte order; hosts reverse for explorer display.Adaptations to key-wallet-ffi conventions
boolreturn +*mut FFIErrorout-parameter (this crate'scheck_ptr!/unwrap_or_return!macros) instead of the platform crate'sPlatformWalletFFIResult. Deserialization failures surface asFFIErrorCode::InvalidInputvia the existingFrom<consensus::encode::Error>mapping.dash_network::ffi::FFINetwork.platform_wallet_prefix (transaction_decode,decoded_transaction_free), matching this crate'stransaction_*naming. Struct names are kept verbatim (DecodedTransactionFFI,DecodedTxInputFFI,DecodedTxOutputFFI) so the Swift-wrapper migration is a re-point, not a rewrite.dashcoredev-dependency gains thetest-utilsfeature for theAddress::dummy/Transaction::dummyfixtures the ported tests use.Tests
All 13 tests from the platform PR ported: output address/value/script decoding, OP_RETURN → null address, P2PKH input-address recovery plus its negative cases (coinbase, non-P2PKH scriptSig, P2SH redeem-script collision, non-DER first push), network switching, trailing-garbage and garbage-byte rejection with out-param nulling, raw C-layout pointer walk, null/empty input rejection, and free-on-null.
cargo test -p key-wallet-ffi: 226 lib tests + integration tests, all passingcargo clippy -p key-wallet-ffi --all-features --all-targets: clean🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes