Skip to content

30.2.11#26

Merged
nervana21 merged 12 commits intomainfrom
30.2.11
Mar 19, 2026
Merged

30.2.11#26
nervana21 merged 12 commits intomainfrom
30.2.11

Conversation

@nervana21
Copy link
Owner

Adds stronger typings

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
@nervana21 nervana21 merged commit becd505 into main Mar 19, 2026
7 checks passed
@nervana21 nervana21 deleted the 30.2.11 branch March 19, 2026 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant