Conversation
The conditional `rust_type.contains("TxOut")` was used to decide whether
to add `use bitcoin::TxOut`. That check matched any type name containing
the substring "TxOut", including types like `GetTxOutSetInfoBlock_info` or
other IR names that share the token but do not reference `bitcoin::TxOut`.
That caused unnecessary imports and potential confusion.
This commit narrows the check to `rust_type == "bitcoin::TxOut" ||
rust_type.contains("bitcoin::TxOut")`, mirroring the pattern used for
`bitcoin::Transaction` and `bitcoin::Amount`. The import is now only
added when the resolved Rust type actually uses the bitcoin crate type.
The `generate_type_alias` function previously defaulted all unrecognised IR type names to `String`. Common Bitcoin Core scalar types such as `amount`, `BlockHash`, and `Txid` deserve proper Rust types for type safety and API ergonomics. This commit adds a normalized match that maps these names (case- insensitive) to `bitcoin::Amount`, `bitcoin::BlockHash`, and `bitcoin::Txid`. The left-hand side of the generated alias uses `sanitize_type_name_for_rust`, so both `blockhash` and `BlockHash` produce valid PascalCase identifiers. Consumers now receive strongly typed values instead of string fallbacks for these core RPC types.
When collecting nested types from IR TypeDefs, we previously only parsed the type name string and extracted CamelCase words. Type names that include separators such as `/` (e.g. `GetRawAddrManBucket/position`) were split incorrectly, losing the composite structure. This commit adds an early branch that, when the TypeDef has a non-empty, non-generic name starting with an uppercase letter, inserts the sanitized full name into `nested_types` before the existing word-based parsing. The `collect_nested_types` call remains to handle generic Rust-like type strings. The change ensures that adapter-introduced or IR-defined composite types are correctly registered for codegen, so downstream consumers get proper struct definitions instead of missing types.
Some IR type definitions encode arrays as objects with `protocol_type: "array"` and a single nested element field. This pattern is used by decodepsbt-style responses where the JSON shape is an object but the semantic type is an array of named structs. Previously these fell through to `serde_json::Value`, losing type information. This commit adds a branch that detects the one-field object with a one-field inner object and maps to `Vec<ElemType>` when the innermost element has a concrete IR name (e.g. DecodepsbtInput, DecodepsbtOutput). Consumers can now deserialize these fields into strongly typed vectors instead of generic JSON values, improving ergonomics and compile-time safety.
Object-typed IR definitions with a non-empty, non-generic name (e.g. DecodePsbtTx) previously fell through to `serde_json::Value` via the field_name match. This commit adds an early return that maps such types to their sanitized IR name, so nested structs defined in the IR propagate into the generated response types. The change complements the protocol_type array handling: when the IR defines a named nested type, consumers now receive a proper Rust struct reference instead of generic JSON, enabling typed access and better documentation without manual deserialization.
Second pass collects nested types from resolved Rust strings for each result field. Add scalar alias tests for bitcoin Amount, BlockHash, and Txid.
`sanitize_type_name_for_rust` maps the IR substring `Lastprocessedblock` to `Last_Processed_Block` before PascalCase, so nested types become `LastProcessedBlock` instead of a single glued segment. Adds `processed` to `METHOD_WORDS` for method-name splitting and a unit test for `GetBalancesLastprocessedblock`.
A test is added to assert that DecodePsbtMusig2Pubnonces is named correctly
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds stronger typings