diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index 9db10e9..168acd0 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ docker-compose.yaml /bin/ /signet-1/ /dev/ +/result \ No newline at end of file diff --git a/NIX-README.md b/NIX-README.md new file mode 100644 index 0000000..f6412c8 --- /dev/null +++ b/NIX-README.md @@ -0,0 +1,172 @@ +# Blindbit Oracle Nix Flake + +This Nix flake provides a complete build and development environment for the Blindbit Oracle - a Silent Payments indexing server for Bitcoin. + +## Supported Platforms + +- **macOS ARM64** (`aarch64-darwin`) +- **Linux x86_64** (`x86_64-linux`) +- **Linux ARM64** (`aarch64-linux`) + +## Quick Start + +### Building and Running + +```bash +# Build the application +nix build + +# Run the application +nix run + +# Enter development shell +nix develop +``` + +### Development Environment + +The development shell includes: +- Go 1.24 +- just (task runner) +- golangci-lint for code quality +- delve for debugging +- git + +```bash +nix develop +``` + +Upon entering the development shell, you'll see available commands and next steps. + +## Available Commands (via Just) + +Once in the development environment, use `just` for common tasks: + +### Core Commands +- `just build` - Build the application +- `just run` - Start the server with development config +- `just test` - Run tests + +### Development Commands +- `just init` - Setup default config file (run this first) +- `just show-config` - Display current configuration +- `just check` - Run tests and linting + +### Additional Commands +- `just test-verbose` - Run tests with verbose output +- `just test-coverage` - Run tests with coverage reporting +- `just lint` - Run golangci-lint +- `just fmt` - Format Go code +- `just clean` - Clean build artifacts +- `just clean-config` - Remove config file +- `just help` - Show all available commands + +## Configuration + +### Initial Setup + +```bash +# Enter development environment +nix develop + +# Initialize configuration (creates ~/.blindbit-oracle/blindbit.toml) +just init + +# View current configuration +just show-config +``` + +### Configuration Options + +The configuration file (`~/.blindbit-oracle/blindbit.toml`) supports these options: + +```toml +# Server host and port +host = "127.0.0.1:8000" # Use "0.0.0.0:8000" for external access + +# Bitcoin network +chain = "signet" # Options: "main", "testnet", "signet", "regtest" + +# Bitcoin RPC connection +rpc_endpoint = "http://127.0.0.1:18443" # Adjust port for your network +rpc_user = "your-rpc-user" # Required unless using cookie_path +rpc_pass = "your-rpc-password" # Required unless using cookie_path +cookie_path = "" # Alternative to user/pass auth + +# Sync settings +sync_start_height = 1 # Starting block height (>= 1) +max_parallel_tweak_computations = 4 # Should match CPU cores +max_parallel_requests = 4 # Limited by Bitcoin RPC capacity + +# Index configuration +tweaks_only = 0 # Generate only tweaks (0 or 1) +tweaks_full_basic = 1 # Basic tweak index (0 or 1) +tweaks_full_with_dust_filter = 0 # Full index with dust filtering (0 or 1) +tweaks_cut_through_with_dust_filter = 0 # Cut-through with dust filtering (0 or 1) +``` + +### Network-Specific RPC Endpoints + +- **mainnet**: `http://127.0.0.1:8332` +- **testnet**: `http://127.0.0.1:18332` +- **signet**: `http://127.0.0.1:38332` +- **regtest**: `http://127.0.0.1:18443` + +## Development Workflow + +```bash +# 1. Enter development environment +nix develop + +# 2. Initialize configuration +just init + +# 3. Edit configuration as needed +# Edit ~/.blindbit-oracle/blindbit.toml + +# 4. Build and test +just dev + +# 5. Run the server +just run +``` + +## Troubleshooting + +### Common Issues + +1. **Configuration not found:** + ```bash + just init # Creates ~/.blindbit-oracle/blindbit.toml + ``` + +2. **Connection refused to Bitcoin RPC:** + - Check `rpc_endpoint` matches your Bitcoin node + - Verify `rpc_user` and `rpc_pass` or `cookie_path` + - Ensure Bitcoin RPC is enabled (`server=1` in bitcoin.conf) + +3. **Build issues:** + ```bash + just clean # Clean build artifacts + just build # Rebuild + ``` + +### Getting Help + +```bash +just help # Show available commands +just --list # List all recipes +nix develop # Enter shell with helpful startup message +``` + +## Contributing + +When modifying the project: + +1. Enter development environment: `nix develop` +2. Make changes +3. Run quality checks: `just check` +4. Test your changes: `just test` +5. Build: `just build` + +The Nix flake automatically manages Go dependencies and provides a consistent development environment across all supported platforms. diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..8877c42 --- /dev/null +++ b/flake.nix @@ -0,0 +1,67 @@ +{ + description = "Blindbit Oracle - Silent Payments indexing server"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachSystem [ "aarch64-darwin" "x86_64-linux" "aarch64-linux" ] (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + in { + packages.default = pkgs.buildGoModule { + pname = "blindbit-oracle"; + version = "0.1.0"; + src = ./.; + subPackages = [ "src" ]; + vendorHash = "sha256-Y2HtkegrGiDdgLDmgFY4gQ27JONT1oNv3Mgpu9gzB6s="; + + nativeBuildInputs = [ pkgs.just ]; + + # Use justfile for building + buildPhase = '' + runHook preBuild + just build + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + mkdir -p $out/bin + cp blindbit-oracle $out/bin/ + runHook postInstall + ''; + }; + + devShells.default = pkgs.mkShell { + buildInputs = with pkgs; [ + go_1_24 + just + golangci-lint + delve + git + ]; + + # Set environment variables inside mkShell + GOFLAGS = "-buildvcs=false"; + + shellHook = '' + echo "Blindbit Oracle development environment" + echo "Go version: $(go version)" + echo "" + echo "Available commands:" + echo " just help - Show available tasks" + echo " just build - Build the application" + echo " just run - Run with development config" + echo " just test - Run tests" + echo "" + echo "" + echo "To get started use:" + echo " just init - Initialize ~/.blindbit-oracle" + echo "" + ''; + }; + }); +} \ No newline at end of file diff --git a/justfile b/justfile new file mode 100644 index 0000000..e060eaf --- /dev/null +++ b/justfile @@ -0,0 +1,95 @@ +# Blindbit Oracle Justfile +# Default recipe (runs when you just type `just`) +default: + @just build + +init: + #!/usr/bin/env sh + if [ ! -d ~/.blindbit-oracle ]; then + mkdir -p ~/.blindbit-oracle + cp blindbit.example.toml ~/.blindbit-oracle/blindbit.toml + echo "Created ~/.blindbit-oracle/ and copied config file" + else + echo "Directory ~/.blindbit-oracle already exists, skipping init" + fi + +# Build the application +build: + go build -o blindbit-oracle ./src + +# Run the application with development config +run: + go run ./src + +# Run tests +test: + go test ./... + +# Run tests with verbose output +test-verbose: + go test -v ./... + +# Run tests with coverage +test-coverage: + go test -cover ./... + +# Clean build artifacts +clean: + rm -f blindbit-oracle + +clean-config: + rm -rf ~/.blindbit-oracle/blindbit.toml + +# Run linter +lint: + golangci-lint run + +# Format code +fmt: + go fmt ./... + +# Run all checks (test, lint, format) +check: test lint + @echo "All checks passed!" + +# Development workflow: format, test, build +dev: fmt test build + @echo "Development build complete!" + +# Show current configuration +show-config: + #!/usr/bin/env sh + if [ -f ~/.blindbit-oracle/blindbit.toml ]; then + cat ~/.blindbit-oracle/blindbit.toml + else + echo "Config file not found at ~/.blindbit-oracle/blindbit.toml" + echo "Run 'just init' to create it" + fi + +# Docker commands +docker-build: + docker build -t blindbit-oracle . + +docker-run: + docker run -p 8000:8000 -v $(pwd)/data:/data blindbit-oracle + +# Nix Docker +nix-docker: + nix build .#docker + docker load < result + +# Help with common tasks +help: + @echo "Blindbit Oracle Development Commands:" + @echo "" + @echo "Core commands:" + @echo " just build - Build the application" + @echo " just test - Run tests" + @echo " just run - Start server" + @echo "" + @echo "Development:" + @echo " just init - Setup default config file (Start here)" + @echo " just check - Run tests and linting" + @echo " just show-config - Display current configuration" + @echo "" + @echo "Use 'just --list' to see all available commands" diff --git a/src/core/block_test.go b/src/core/block_test.go index 96e7404..f03e952 100644 --- a/src/core/block_test.go +++ b/src/core/block_test.go @@ -10,7 +10,7 @@ import ( func TestBlockAnalysis(t *testing.T) { var block types.Block - err := testhelpers.LoadBlockFromFile("/Users/setorblagogee/dev/sp-test-dir/block-716120.json", &block) + err := testhelpers.LoadAndUnmarshalBlockFromFile("../test_data/block_833000.json", &block) if err != nil { log.Fatalln(err) } diff --git a/src/core/tweak_test.go b/src/core/tweak_test.go index 07af18d..000db2b 100644 --- a/src/core/tweak_test.go +++ b/src/core/tweak_test.go @@ -6,18 +6,12 @@ import ( "SilentPaymentAppBackend/src/testhelpers" "encoding/hex" "log" - "os" "testing" ) var b833000 types.Block func init() { - common.DebugLogger = log.New(os.Stdout, "[DEBUG] ", log.Ldate|log.Lmicroseconds|log.Lshortfile|log.Lmsgprefix) - common.InfoLogger = log.New(os.Stdout, "[INFO] ", log.Ldate|log.Lmicroseconds|log.Lshortfile|log.Lmsgprefix) - common.WarningLogger = log.New(os.Stdout, "[WARNING] ", log.Ldate|log.Lmicroseconds|log.Lshortfile|log.Lmsgprefix) - common.ErrorLogger = log.New(os.Stdout, "[ERROR] ", log.Ldate|log.Lmicroseconds|log.Lshortfile|log.Lmsgprefix) - err := testhelpers.LoadAndUnmarshalBlockFromFile("../test_data/block_833000.json", &b833000) if err != nil { log.Fatalln(err)