Skip to content

Commit 2a4f3ed

Browse files
authored
Merge pull request #20 from openSVM/copilot/fix-19
Implement comprehensive C++ SDK for SVM-Pay
2 parents 6a34768 + 1786450 commit 2a4f3ed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+8579
-3
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ SVM-Pay is a payment solution for SVM networks (Solana, Sonic SVM, Eclipse, s00n
1414
- **Cross-Network Compatibility**: Support for Solana, Sonic SVM, Eclipse, and s00n networks
1515
- **Simple Integration**: One-click integration for developers
1616
- **Comprehensive SDK**: JavaScript/TypeScript SDK with React, Vue, and Angular components
17+
- **C++ SDK**: Native C++ SDK for high-performance applications and system integration
1718
- **Assembly-BPF SDK**: Low-level BPF program development with Assembly and LLVM IR abstractions
1819
- **Mobile Support**: iOS and Android SDK for mobile applications
1920
- **No Fees**: SVM-Pay itself charges no fees (only standard network transaction fees apply)
@@ -27,6 +28,7 @@ SVM-Pay is a payment solution for SVM networks (Solana, Sonic SVM, Eclipse, s00n
2728
- [Assembly-BPF SDK](docs/assembly-bpf/README.md)
2829
- [Architecture](docs/architecture.md)
2930
- [Security Recommendations](docs/security-recommendations.md)
31+
- [C++ SDK](cpp-sdk/README.md)
3032
- [Examples](examples/)
3133
- [CLI Integration](CLI-INTEGRATION.md)
3234

@@ -194,6 +196,42 @@ export class AppComponent {
194196
}
195197
```
196198

199+
## C++ SDK
200+
201+
SVM-Pay includes a comprehensive C++ SDK for high-performance applications and system integration:
202+
203+
```cpp
204+
#include <svm-pay/svm_pay.hpp>
205+
206+
// Initialize SDK
207+
svm_pay::initialize_sdk();
208+
209+
// Create client
210+
svm_pay::Client client(svm_pay::SVMNetwork::SOLANA);
211+
212+
// Create payment URL
213+
std::string url = client.create_transfer_url("recipient_address", "1.5", {
214+
{"label", "Coffee Shop"},
215+
{"message", "Payment for coffee"}
216+
});
217+
218+
// Parse payment URL
219+
auto request = client.parse_url(url);
220+
221+
// Generate reference ID
222+
std::string ref = client.generate_reference();
223+
```
224+
225+
**Features:**
226+
- Cross-platform support (Windows, Linux, macOS)
227+
- Asynchronous network operations
228+
- Secure reference generation with OpenSSL
229+
- Complete URL scheme support
230+
- CMake build system with package management
231+
- Comprehensive test suite and examples
232+
233+
See [C++ SDK Documentation](cpp-sdk/README.md) for detailed installation and usage instructions.
234+
197235
## Demo Applications
198236
199237
SVM-Pay includes several demo applications to showcase its functionality:

cpp-sdk/.gitignore

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Build directories
2+
build/
3+
build-*/
4+
out/
5+
6+
# CMake generated files
7+
CMakeCache.txt
8+
CMakeFiles/
9+
cmake_install.cmake
10+
Makefile
11+
*.cmake
12+
13+
# Compiled Object files
14+
*.o
15+
*.obj
16+
17+
# Compiled Dynamic libraries
18+
*.so
19+
*.dylib
20+
*.dll
21+
22+
# Compiled Static libraries
23+
*.a
24+
*.lib
25+
26+
# Executables
27+
*.exe
28+
*.out
29+
*.app
30+
31+
# Debug files
32+
*.dSYM/
33+
*.pdb
34+
35+
# IDE files
36+
.vscode/
37+
.idea/
38+
*.user
39+
*.pro.user*
40+
41+
# Temporary files
42+
*~
43+
*.swp
44+
*.swo
45+
.DS_Store
46+
Thumbs.db
47+
48+
# Testing
49+
CTestTestfile.cmake
50+
Testing/
51+
52+
# Package files
53+
*.tar.gz
54+
*.zip
55+
*.deb
56+
*.rpm
57+
58+
# Documentation build
59+
docs/_build/
60+
docs/html/
61+
docs/latex/
62+
63+
# Coverage files
64+
*.gcno
65+
*.gcov
66+
*.gcda
67+
coverage.info
68+
coverage/
69+
70+
# Static analysis
71+
cppcheck-build-dir/
72+
73+
# Clang tools
74+
compile_commands.json

cpp-sdk/BUILD.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# SVM-Pay C++ SDK Build Instructions
2+
3+
This directory contains a comprehensive C++ SDK for SVM-Pay, providing payment solutions for SVM networks.
4+
5+
## Quick Build
6+
7+
### Using System Dependencies (Linux/macOS)
8+
9+
```bash
10+
# Install dependencies
11+
sudo apt-get install libcurl4-openssl-dev libssl-dev libgtest-dev # Ubuntu/Debian
12+
brew install curl openssl googletest # macOS
13+
14+
# Build
15+
mkdir build && cd build
16+
cmake ..
17+
make -j4
18+
19+
# Run examples
20+
./examples/basic_payment
21+
./examples/url_parsing
22+
```
23+
24+
### Using vcpkg (Windows/Cross-platform)
25+
26+
```bash
27+
# Install vcpkg if not already installed
28+
git clone https://github.com/Microsoft/vcpkg.git
29+
cd vcpkg && ./bootstrap-vcpkg.sh
30+
31+
# Build with vcpkg
32+
mkdir build && cd build
33+
cmake .. -DCMAKE_TOOLCHAIN_FILE=/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake
34+
make -j4
35+
```
36+
37+
## Features Included
38+
39+
**Complete URL Scheme Support** - Parse and create payment URLs for all SVM networks
40+
**Secure Reference Generation** - Cryptographically secure reference IDs using OpenSSL
41+
**Multi-Network Support** - Solana, Sonic, Eclipse, and s00n networks
42+
**Async Network Operations** - Future-based asynchronous network adapter interface
43+
**Type Safety** - Modern C++17 with strong typing
44+
**Cross-Platform** - CMake build system supporting Windows, Linux, and macOS
45+
**Well Tested** - Comprehensive unit tests included
46+
**Examples** - Multiple working examples demonstrating all features
47+
**Documentation** - Complete API reference and usage guide
48+
49+
## API Overview
50+
51+
```cpp
52+
#include <svm-pay/svm_pay.hpp>
53+
54+
// Initialize SDK
55+
svm_pay::initialize_sdk();
56+
57+
// Create client
58+
svm_pay::Client client(svm_pay::SVMNetwork::SOLANA);
59+
60+
// Create payment URL
61+
std::string url = client.create_transfer_url("recipient_address", "1.5", {
62+
{"label", "Coffee Shop"},
63+
{"message", "Payment for coffee"}
64+
});
65+
66+
// Parse payment URL
67+
auto request = client.parse_url(url);
68+
69+
// Generate reference ID
70+
std::string ref = client.generate_reference();
71+
```
72+
73+
See the full [README.md](README.md) for complete documentation and examples.

cpp-sdk/CMakeLists.txt

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
project(svm-pay-cpp VERSION 1.0.0 LANGUAGES CXX)
3+
4+
# Set C++ standard
5+
set(CMAKE_CXX_STANDARD 17)
6+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
7+
8+
# Set build type if not specified
9+
if(NOT CMAKE_BUILD_TYPE)
10+
set(CMAKE_BUILD_TYPE Release)
11+
endif()
12+
13+
# Compiler-specific options
14+
if(MSVC)
15+
add_compile_options(/W4)
16+
else()
17+
add_compile_options(-Wall -Wextra -Wpedantic)
18+
endif()
19+
20+
# Find required packages
21+
find_package(CURL REQUIRED)
22+
find_package(OpenSSL REQUIRED)
23+
24+
# Option to build tests
25+
option(BUILD_TESTS "Build test suite" ON)
26+
27+
# Option to build examples
28+
option(BUILD_EXAMPLES "Build examples" ON)
29+
30+
# Include directories
31+
include_directories(include)
32+
33+
# Source files
34+
set(SOURCES
35+
src/core/types.cpp
36+
src/core/url_scheme.cpp
37+
src/core/reference.cpp
38+
src/network/adapter.cpp
39+
src/network/solana.cpp
40+
src/network/curl_initializer.cpp
41+
src/client.cpp
42+
src/svm_pay.cpp
43+
)
44+
45+
# Header files for installation
46+
set(HEADERS
47+
include/svm-pay/svm_pay.hpp
48+
include/svm-pay/client.hpp
49+
include/svm-pay/core/types.hpp
50+
include/svm-pay/core/url_scheme.hpp
51+
include/svm-pay/core/reference.hpp
52+
include/svm-pay/core/exceptions.hpp
53+
include/svm-pay/network/adapter.hpp
54+
include/svm-pay/network/solana.hpp
55+
include/svm-pay/network/curl_initializer.hpp
56+
)
57+
58+
# Create library
59+
add_library(svm-pay ${SOURCES})
60+
61+
# Link libraries
62+
target_link_libraries(svm-pay
63+
CURL::libcurl
64+
OpenSSL::SSL
65+
OpenSSL::Crypto
66+
)
67+
68+
# Set library properties
69+
set_target_properties(svm-pay PROPERTIES
70+
VERSION ${PROJECT_VERSION}
71+
SOVERSION 1
72+
)
73+
74+
# Install targets
75+
install(TARGETS svm-pay
76+
EXPORT svm-pay-targets
77+
LIBRARY DESTINATION lib
78+
ARCHIVE DESTINATION lib
79+
RUNTIME DESTINATION bin
80+
)
81+
82+
install(DIRECTORY include/svm-pay
83+
DESTINATION include
84+
)
85+
86+
# Export targets
87+
install(EXPORT svm-pay-targets
88+
FILE svm-pay-targets.cmake
89+
DESTINATION lib/cmake/svm-pay
90+
)
91+
92+
# Build tests if enabled
93+
if(BUILD_TESTS)
94+
enable_testing()
95+
add_subdirectory(tests)
96+
endif()
97+
98+
# Build examples if enabled
99+
if(BUILD_EXAMPLES)
100+
add_subdirectory(examples)
101+
endif()
102+
103+
# Package configuration
104+
include(CMakePackageConfigHelpers)
105+
106+
configure_package_config_file(
107+
cmake/svm-pay-config.cmake.in
108+
"${CMAKE_CURRENT_BINARY_DIR}/svm-pay-config.cmake"
109+
INSTALL_DESTINATION lib/cmake/svm-pay
110+
)
111+
112+
write_basic_package_version_file(
113+
"${CMAKE_CURRENT_BINARY_DIR}/svm-pay-config-version.cmake"
114+
VERSION ${PROJECT_VERSION}
115+
COMPATIBILITY SameMajorVersion
116+
)
117+
118+
install(FILES
119+
"${CMAKE_CURRENT_BINARY_DIR}/svm-pay-config.cmake"
120+
"${CMAKE_CURRENT_BINARY_DIR}/svm-pay-config-version.cmake"
121+
DESTINATION lib/cmake/svm-pay
122+
)

0 commit comments

Comments
 (0)