Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 176 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
# Contributing to Programming Bitcoin

Thank you for your interest in contributing to this project! This is an educational implementation of Bitcoin cryptography in Rust.

## Getting Started

1. Fork the repository
2. Clone your fork: `git clone https://github.com/YOUR_USERNAME/programming_bitcoin.git`
3. Create a branch: `git checkout -b feature/your-feature-name`
4. Make your changes
5. Run tests: `cargo test`
6. Format code: `cargo fmt`
7. Run clippy: `cargo clippy`
8. Commit your changes: `git commit -am 'Add some feature'`
9. Push to the branch: `git push origin feature/your-feature-name`
10. Create a Pull Request

## Development Setup

### Prerequisites
- Rust 1.70+ (install via [rustup](https://rustup.rs/))
- Git

### Building
```bash
cargo build
```

### Running Tests
```bash
# Run all tests
cargo test

# Run specific chapter tests
cargo test --test ch01_finite_fields_tests
cargo test --test ch02_elliptic_curves_tests
cargo test --test ch03_bitcoin_crypto_tests
cargo test --test ch04_serialization_tests

# Run a specific test
cargo test test_field_element_creation

# Run with output
cargo test -- --nocapture
```

### Code Quality

Before submitting a PR, ensure:

1. **All tests pass:**
```bash
cargo test
```

2. **Code is formatted:**
```bash
cargo fmt
```

3. **No clippy warnings:**
```bash
cargo clippy -- -D warnings
```

4. **Documentation builds:**
```bash
cargo doc --no-deps
```

## Project Structure

```
src/
├── ch01_finite_fields/ # Finite field arithmetic
├── ch02_elliptic_curves/ # Basic elliptic curve operations
├── ch03_ecc/ # Bitcoin's secp256k1 curve
└── ch04_serialization/ # Bitcoin serialization formats

tests/
├── ch01_finite_fields_tests.rs
├── ch02_elliptic_curves_tests.rs
├── ch03_bitcoin_crypto_tests.rs
└── ch04_serialization_tests.rs
```

## Coding Guidelines

### Style
- Follow Rust standard style (enforced by `rustfmt`)
- Use meaningful variable names
- Add comments for complex algorithms
- Keep functions focused and small

### Testing
- Write tests for new functionality
- Maintain or improve code coverage
- Test edge cases and error conditions
- Use descriptive test names: `test_<what>_<scenario>`

### Documentation
- Add doc comments for public APIs
- Include examples in doc comments when helpful
- Update README.md if adding new features

### Commits
- Write clear, descriptive commit messages
- Use present tense ("Add feature" not "Added feature")
- Reference issues when applicable (#123)

## Types of Contributions

### Bug Reports
- Use GitHub Issues
- Include steps to reproduce
- Provide expected vs actual behavior
- Include Rust version and OS

### Feature Requests
- Use GitHub Issues
- Explain the use case
- Describe the proposed solution
- Consider alternatives

### Code Contributions
- Follow the development setup above
- Ensure all checks pass
- Update tests and documentation
- Keep PRs focused on a single concern

### Documentation
- Fix typos and improve clarity
- Add examples
- Improve README or inline docs

## Pull Request Process

1. **Update tests** - Add or update tests for your changes
2. **Update documentation** - Update README.md, doc comments, etc.
3. **Run checks locally** - Ensure tests, fmt, and clippy pass
4. **Create PR** - Provide a clear description of changes
5. **Address feedback** - Respond to review comments
6. **Wait for CI** - All GitHub Actions must pass

## Code Review

All submissions require review. We use GitHub pull requests for this purpose.

Reviewers will check:
- Code quality and style
- Test coverage
- Documentation
- Performance implications
- Security considerations

## Questions?

Feel free to:
- Open an issue for questions
- Start a discussion
- Reach out to maintainers

## License

By contributing, you agree that your contributions will be licensed under the same license as the project (see LICENSE file).

## Learning Resources

This project follows the book "Programming Bitcoin" by Jimmy Song:
- [Programming Bitcoin](https://programmingbitcoin.com/)
- [Bitcoin Wiki](https://en.bitcoin.it/)
- [secp256k1 specification](https://www.secg.org/sec2-v2.pdf)

## Code of Conduct

Be respectful, inclusive, and constructive. This is a learning project - questions and mistakes are welcome!
159 changes: 159 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
name: CI

on:
push:
branches: [ main, master, develop ]
pull_request:
branches: [ main, master, develop ]

env:
CARGO_TERM_COLOR: always

jobs:
test:
name: Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
rust: [stable, beta]
steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}

- name: Cache cargo registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo index
uses: actions/cache@v4
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo build
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}

- name: Run tests
run: cargo test --verbose

- name: Run tests (release mode)
run: cargo test --release --verbose

fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt

- name: Check formatting
run: cargo fmt --all -- --check

clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: clippy

- name: Cache cargo registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo index
uses: actions/cache@v4
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo build
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}

- name: Run clippy
run: cargo clippy --all-targets --all-features -- -D warnings

build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable

- name: Cache cargo registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo index
uses: actions/cache@v4
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo build
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}

- name: Build
run: cargo build --verbose

- name: Build (release)
run: cargo build --release --verbose

doc:
name: Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable

- name: Cache cargo registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo index
uses: actions/cache@v4
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo build
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}

- name: Check documentation
run: cargo doc --no-deps --document-private-items
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
/target
.github/workflows/coverage.yml
.github/workflows/dependency-review.yml
.github/workflows/release.yml
.github/workflows/security-audit.yml
.github/workflows/README.md
Loading
Loading