Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@krrish-sehgal
Copy link
Contributor

@krrish-sehgal krrish-sehgal commented May 20, 2025

fixes a part of : #4227
This PR adds :

  1. the remaining ord-api file that was left when the instance was shut down
  2. the metadatainfo for solana bacon
  3. setup script if we wanna deploy a solana token again in one go.

Summary by CodeRabbit

  • New Features
    • Introduced an API server to facilitate sending "bacon tokens" on Bitcoin mainnet and regtest networks via the Ordinal protocol, with endpoints for batch transactions and regtest operations.
    • Added a metadata file for the "Bacon" token, including its name, symbol, description, and logo.
    • Provided a setup script to automate the creation of a Solana development environment using Docker, including Solana CLI and Rust installation.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 20, 2025

Walkthrough

New 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

File(s) Change Summary
BACON/ord-server/ord-api.py Added a Flask API server with endpoints for sending "bacon tokens" on Bitcoin mainnet and regtest using the Ordinal protocol.
BACON/sol-bacon/metadata.json Added JSON metadata describing the "Bacon" token, including name, symbol, description, and image URL.
BACON/sol-bacon/setup-solana-bacon.sh Added Bash script to automate Docker-based Solana development environment setup, including Rust and Solana CLI installation.

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
Loading
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
Loading

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit 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.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit 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 Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Commit Unit Tests in branch sol-bacon
  • Post Copyable Unit Tests in Comment

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 standard

The 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:

  1. Documentation about which Solana token standard this metadata follows (e.g., SPL Token, Metaplex NFT)
  2. 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 name

The 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 Dockerfile

The Dockerfile follows a decent structure but could benefit from these improvements:

  1. Running as a non-root user for better security
  2. Using multi-stage builds to reduce image size
  3. Setting a specific version for Rust and Solana CLI instead of using the latest version for predictable builds
  4. 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 practices

The Docker build and run commands could benefit from:

  1. Using the TOKEN_NAME variable in the image tag for consistency
  2. Adding error handling to verify Docker commands complete successfully
  3. Adding container labels for better identification
  4. 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 validation

The 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

📥 Commits

Reviewing files that changed from the base of the PR and between 18dc915 and 7a00f8b.

⛔ Files ignored due to path filters (1)
  • BACON/sol-bacon/bacon-sol.jpeg is 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)

@DonnieBLT DonnieBLT merged commit c4a4821 into OWASP-BLT:main Jun 25, 2025
13 of 14 checks passed
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.

2 participants