Description
This pull request introduces an external tool for generating RPC client code based on the Bitcoin Core RPC schema. The tool is implemented in Python using Jinja2 templates and can generate code for both C++ and Python clients. In addition, unit tests have been added to verify that the generator produces the expected output given a sample schema.
Changes Included
contrib/codegen/generate_client.py
A script that retrieves the latest RPC schema (via bitcoin-cli) and renders language- specific templates.contrib/codegen/templates/
cpp_client.jinja2
– Template for generating a C++ RPC client header.python_client.jinja2
– Template for generating a Python RPC client.
contrib/codegen/tests/test_generate_client.py
Unit tests to ensure the code generator works as expected for both C++ and Python output.
Rationale
This tool provides a convenient way for developers to automatically update external client
libraries when the RPC schema changes. It improves maintainability by reducing manual
effort and potential errors. As a non-core developer utility, it is placed under the
contrib/
directory to keep it separate from the core runtime.
Testing and Verification
- The generated client code for both C++ and Python has been compiled (for C++) and run in a test harness.
- Unit tests verify that, given a sample schema, the output contains the expected method declarations and syntax.
- The tool automatically retrieves the latest schema using the
bitcoin-cli schema
RPC.
Please see the accompanying README in contrib/codegen/
for detailed usage instructions.