How blockstream/gdk works
Based on your project’s file structure and README, the Green C/C++ SDK is a cross-platform, cross-language library designed for Blockstream Green wallets. It uses a modular, multi-language approach (primarily C/C++ core with Rust subprojects, and wrappers for Java, Python, and Swift) and an advanced, multi-platform build and deployment system (using CMake, Docker, and extensive build scripts).
Main Components
• Core SDK (C/C++ Library):
• Represented by files in the “src” directory (e.g., core functionality like session management, signing, transaction utilities, caching, network handling, etc.).
• Language Bindings/ Wrappers:
• SWIG-based wrappers located in “src/swig_java” for Java and “src/swig_python” for Python.
• Swift wrapper under “src/swift/GreenGDK” for Swift integration.
• Rust Subcomponents:
• Multiple Rust subprojects under “subprojects/gdk_rust” such as:
▫ “gdk_rust/gdk_common”: Handles common backend functionality.
▫ “gdk_rust/gdk_electrum”: Provides Electrum-specific functionalities.
▫ “gdk_rust/gdk_pin_client” and “gdk_rust/gdk_registry”: Additional capabilities (e.g., PIN handling, asset registry).
• These components are a critical pillar supporting parts of the SDK’s core logic.
• Build System:
• CMake configuration files (root-level CMakeLists.txt, “src/CMakeLists.txt”, and extensive CMake profiles & modules under “cmake”).
• Build scripts in “tools” for compiling dependencies, building the SDK, and cleaning.
• Docker configurations in “docker” that help provide reproducible build environments across platforms.
• Testing and CI:
• Test cases under “tests” and CI config files like “.gitlab-ci.yml” for continuous integration.
• Documentation:
• Managed in “docs” and the README links to ReadTheDocs for API documentation.
Relationships and Data Flow
• The Core SDK (C/C++ implementation) is the central component.
• Language bindings (Java, Python, Swift) interact with the core library via SWIG-generated interfaces or direct wrapper calls.
• Rust subprojects provide additional low-level and performance-critical functionalities. They are integrated and accessed by the C/C++ layer.
• The build system (CMake and build scripts) ties everything together. It is responsible for compiling both the core and the various language bindings while leveraging platform-specific profiles (from “cmake/profiles”) to target multiple architectures (Android, iOS, Windows, etc.).
• Docker images encapsulate the build environment ensuring consistency, and are integrated with the CI system (GitLab CI configuration) for automated builds.
• Testing frameworks interact with both the core functionalities and the language bindings to verify integrity.
Architectural Patterns and Design Principles
• Modularity: The SDK is broken into core functionality, multiple bindings, and separate Rust components.
• Cross-platform and cross-language design: Different wrappers and build profiles enable support for many platforms.
• Separation of Concerns: Clear boundaries are present between the core library, its build/deployment systems, and the language-specific bindings.
• Extensibility: The use of SWIG and modular subprojects (especially in Rust) provides points where additional features can be integrated in the future.
Relevant Technologies, Frameworks, and Libraries
• C/C++ for the core implementation.
• CMake as the primary build system with numerous build profiles.
• Docker for containerized builds and dependency management.
• Rust for several submodules using Cargo for building.
• SWIG for generating Java and Python bindings.
• GitLab CI for continuous integration.
• Platform-specific tools (Android NDK, platform-specific dependencies, etc.) as defined in the README.