-
-
Notifications
You must be signed in to change notification settings - Fork 313
add: ord-api and solana setup #4288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughNew functionality is introduced for both Bitcoin and Solana blockchains. A Flask-based API server is added to handle "bacon token" transactions using the Ordinal protocol on Bitcoin. For Solana, a metadata JSON file for the "Bacon" token and a Bash script to set up a Solana development environment in Docker are included. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant FlaskAPI
participant OrdBinary
Client->>FlaskAPI: POST /mainnet/send-bacon-tokens (YAML, fee_rate, dry_run)
FlaskAPI->>FlaskAPI: Validate input, write YAML to temp file
FlaskAPI->>OrdBinary: Run 'ord' with RPC credentials and wallet info
OrdBinary-->>FlaskAPI: Output or error
FlaskAPI-->>Client: JSON response
Client->>FlaskAPI: POST /regtest/send-bacon-tokens (num_users, fee_rate)
FlaskAPI->>FlaskAPI: Validate input, generate YAML batch file
FlaskAPI->>OrdBinary: Run 'ord' with regtest credentials
OrdBinary-->>FlaskAPI: Output (txid) or error
FlaskAPI-->>Client: JSON response
sequenceDiagram
participant User
participant SetupScript
participant Docker
participant Container
User->>SetupScript: Run setup-solana-bacon.sh
SetupScript->>Docker: Build Docker image (heysolana)
SetupScript->>Docker: Run container with mounted volumes
Docker->>Container: Start environment (Rust, Solana CLI installed)
User->>Container: (Manual) Run Solana CLI commands
Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Note ⚡️ Faster reviews with cachingCodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure ✨ Finishing Touches
🧪 Generate Unit Tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 6
🧹 Nitpick comments (5)
BACON/sol-bacon/metadata.json (1)
1-6: Token metadata looks good, but consider specifying the token standardThe metadata JSON structure is valid and includes the essential fields (name, symbol, description, image) with the IPFS link correctly formatted. The use of Pinata for IPFS hosting is a good practice for decentralized storage.
Consider adding:
- Documentation about which Solana token standard this metadata follows (e.g., SPL Token, Metaplex NFT)
- Additional optional fields like "decimals" if this is an SPL token
BACON/sol-bacon/setup-solana-bacon.sh (3)
3-4: Customize the default token nameThe TOKEN_NAME variable is currently set to "your-token-name" which appears to be a placeholder. Consider setting it to "bacon" or "sol-bacon" to align with the project name and metadata file.
- TOKEN_NAME="your-token-name" + TOKEN_NAME="sol-bacon"
13-50: Consider Docker security best practices in the DockerfileThe Dockerfile follows a decent structure but could benefit from these improvements:
- Running as a non-root user for better security
- Using multi-stage builds to reduce image size
- Setting a specific version for Rust and Solana CLI instead of using the latest version for predictable builds
- Adding HEALTHCHECK instruction to verify the container is working properly
Here's a sample improvement:
# Use a lightweight base image FROM debian:bullseye-slim # Set non-interactive frontend for apt ENV DEBIAN_FRONTEND=noninteractive # Install required dependencies and Rust RUN apt-get update && apt-get install -y \ curl build-essential libssl-dev pkg-config nano \ && curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \ && apt-get clean && rm -rf /var/lib/apt/lists/* # Add Rust to PATH ENV PATH="/root/.cargo/bin:$PATH" # Verify Rust installation RUN rustc --version # Install Solana CLI RUN curl -sSfL https://release.anza.xyz/stable/install | sh \ && echo 'export PATH="$HOME/.local/share/solana/install/active_release/bin:$PATH"' >> ~/.bashrc # Add Solana CLI to PATH ENV PATH="/root/.local/share/solana/install/active_release/bin:$PATH" # Verify Solana CLI installation RUN solana --version # Set up Solana config for Devnet RUN solana config set -ud # Set working directory WORKDIR /solana-token +# Create non-root user +RUN useradd -m solanauser +USER solanauser + # Default command to run a shell CMD ["/bin/bash"]
52-59: Enhance Docker build and run commands with better practicesThe Docker build and run commands could benefit from:
- Using the TOKEN_NAME variable in the image tag for consistency
- Adding error handling to verify Docker commands complete successfully
- Adding container labels for better identification
- Setting resource limits
# Build Docker image -docker build -t heysolana . +docker build -t "solana-${TOKEN_NAME}" \ + --label "project=${TOKEN_NAME}" \ + --label "version=1.0" \ + . || { echo "Docker build failed"; exit 1; } # Run Docker container interactively docker run -it --rm \ -v "$(pwd)":/solana-token \ -v "$(pwd)/solana-data":/root/.config/solana \ - heysolana + --name "solana-${TOKEN_NAME}-container" \ + --memory="2g" \ + --cpus="2" \ + "solana-${TOKEN_NAME}" || { echo "Docker run failed"; exit 1; }BACON/ord-server/ord-api.py (1)
1-7: Consider adding proper docstrings and input validationThe file lacks proper documentation and doesn't implement robust input validation.
Add descriptive docstrings and implement a validation helper function:
import os import subprocess import yaml from dotenv import load_dotenv from flask import Flask, jsonify, request +from marshmallow import Schema, fields, validate, ValidationError + +""" +Flask API for sending bacon tokens on Bitcoin networks using the Ordinal protocol. + +This API provides endpoints for sending tokens on both mainnet and regtest networks. +It uses the ord binary to perform wallet split operations with batch transactions. +""" + +class MainnetTokenRequestSchema(Schema): + """Schema for validating mainnet token requests.""" + yaml_content = fields.String(required=True) + fee_rate = fields.Float(required=True, validate=validate.Range(min=1.0)) + dry_run = fields.Boolean(missing=False) + +class RegtestTokenRequestSchema(Schema): + """Schema for validating regtest token requests.""" + num_users = fields.Integer(required=True, validate=validate.Range(min=1, max=100)) + fee_rate = fields.Float(required=True, validate=validate.Range(min=1.0)) + +def validate_request(schema_class): + """Decorator for validating request data against a schema.""" + def decorator(func): + def wrapper(*args, **kwargs): + schema = schema_class() + try: + validated_data = schema.load(request.json) + return func(validated_data, *args, **kwargs) + except ValidationError as err: + return jsonify({"success": False, "error": err.messages}), 400 + wrapper.__name__ = func.__name__ + return wrapper + return decorator
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Knowledge Base: Disabled due to Reviews > Disable Knowledge Base setting
⛔ Files ignored due to path filters (1)
BACON/sol-bacon/bacon-sol.jpegis excluded by!**/*.jpeg
📒 Files selected for processing (3)
BACON/ord-server/ord-api.py(1 hunks)BACON/sol-bacon/metadata.json(1 hunks)BACON/sol-bacon/setup-solana-bacon.sh(1 hunks)
🧰 Additional context used
🪛 ast-grep (0.38.1)
BACON/ord-server/ord-api.py
[warning] 118-118: Running flask app with host 0.0.0.0 could expose the server publicly.
Context: app.run(host="0.0.0.0", port=int(os.getenv("FLASK_PORT", 9002)))
Note: [CWE-668]: Exposure of Resource to Wrong Sphere [OWASP A01:2021]: Broken Access Control [REFERENCES]
https://owasp.org/Top10/A01_2021-Broken_Access_Control
(avoid_app_run_with_bad_host-python)
🪛 GitHub Check: CodeQL
BACON/ord-server/ord-api.py
[failure] 73-73: Uncontrolled command line
This command line depends on a user-provided value.
[failure] 111-111: Uncontrolled command line
This command line depends on a user-provided value.
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: Run Tests
- GitHub Check: Analyze (python)
- GitHub Check: docker-test
- GitHub Check: Analyze (javascript-typescript)
fixes a part of : #4227
This PR adds :
Summary by CodeRabbit