From 0719850094ef57efb89a9f16c94dd40ec6f6e2b9 Mon Sep 17 00:00:00 2001 From: Xiaozhe Yao Date: Sat, 13 Sep 2025 06:39:09 +0200 Subject: [PATCH 01/12] wip: wallet for identifying node owners --- CLAUDE.md | 158 + apps/web/README-CONSOLE.md | 146 + apps/web/app/layout.tsx | 5 +- apps/web/app/page.tsx | 28 +- apps/web/components/animated-globe.tsx | 6 +- apps/web/components/dashboard.tsx | 357 + apps/web/components/hero.tsx | 13 +- apps/web/components/navbar/navbar.tsx | 2 + apps/web/components/ui/button.tsx | 6 +- apps/web/components/wallet-connect.tsx | 63 + apps/web/lib/web3-provider.tsx | 29 + apps/web/next.config.ts | 12 +- apps/web/package-lock.json | 15066 ++++++++++++++++------- apps/web/package.json | 7 +- src/entry/cmd/wallet.go | 77 + src/internal/server/server.go | 7 + src/internal/wallet/wallet.go | 152 + tokens/.gitignore | 2 +- tokens/Cargo.lock | 51 +- tokens/programs/tokens/Cargo.toml | 7 +- tokens/programs/tokens/src/lib.rs | 1 + 21 files changed, 11824 insertions(+), 4371 deletions(-) create mode 100644 CLAUDE.md create mode 100644 apps/web/README-CONSOLE.md create mode 100644 apps/web/components/dashboard.tsx create mode 100644 apps/web/components/wallet-connect.tsx create mode 100644 apps/web/lib/web3-provider.tsx create mode 100644 src/entry/cmd/wallet.go create mode 100644 src/internal/wallet/wallet.go diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..b2de674 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,158 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## Project Overview + +The Open Compute Framework (OCF) is a decentralized computing platform that combines LibP2P-based peer-to-peer networking with Web3 blockchain integration. The platform enables distributed compute services with token-based incentives and modern web interfaces. + +## Architecture Overview + +### Core Components + +1. **Backend (Go)** - `src/`: LibP2P-based decentralized compute fabric + - Implements CRDT-backed service registry and peer discovery + - HTTP gateway (port 8092) and P2P HTTP over LibP2P + - Multi-modal operation: standalone, local, and networked modes + +2. **Frontend (Next.js)** - `apps/web/`: Modern React web application + - Web3 wallet integration with wagmi and ethers + - Responsive UI with Radix UI and Tailwind CSS + - TypeScript with strict configuration + +3. **Blockchain (Solana)** - `tokens/`: Token economics and incentives + - Anchor framework for Solana smart contracts + - Rust-based token implementation + +4. **Documentation (Astro)** - `docs/`: Comprehensive project documentation + - Starlight theme with professional styling + +## Development Commands + +### Backend (Go) + +From the `src/` directory: + +```bash +# Build and development +make build # Build all applications +make build-debug # Build with debugging capabilities +make build-release # Build release binaries (no debug info) +make run # Build and execute all applications + +# Testing and quality +make test # Run tests with coverage +make lint # Run linters (golangci-lint) +make check # Run both tests and linters + +# Release management +make patch # Release new patch version +make minor # Release new minor version +make major # Release new major version +``` + +### Frontend (Next.js) + +From the `apps/web/` directory: + +```bash +npm run dev # Start development server +npm run build # Build for production +npm run start # Start production server +npm run lint # Run ESLint +``` + +### Blockchain (Solana/Anchor) + +From the `tokens/` directory: + +```bash +npm run lint # Check code formatting +npm run lint:fix # Fix code formatting +yarn run ts-mocha # Run TypeScript tests +``` + +### Documentation (Astro) + +From the `docs/` directory: + +```bash +npm run dev # Start development server +npm run build # Build documentation +npm run preview # Preview built site +``` + +## Key Technical Details + +### Backend Architecture + +- **LibP2P Networking**: TCP, WebSocket, and QUIC transports +- **CRDT Registry**: Conflict-free replicated data types for distributed state +- **Service Discovery**: Identity-based service registration and routing +- **Multi-Transport**: HTTP gateway and P2P HTTP over LibP2P + +### Routing Models + +1. **Direct Service**: Forward to locally registered services +2. **Global Service**: Route to matching providers by identity groups +3. **P2P Forwarding**: Direct peer-to-peer communication + +### Frontend Integration + +- **Web3 Stack**: wagmi v2.16.9, ethers v6.15.0, web3modal +- **State Management**: TanStack Query for data fetching +- **UI Components**: Radix UI with Tailwind CSS +- **Type Safety**: Strict TypeScript configuration + +### Blockchain Integration + +- **Solana Program ID**: `xTRCFBHAfjepfKNStvWQ7xmHwFS7aJ85oufa1BoXedL` +- **Anchor Framework**: Rust smart contract development +- **Token Economics**: Platform incentive mechanisms + +## Important Build Information + +### Go Backend + +- **Version**: Go 1.23.0 required +- **Build Output**: `build/` directory +- **Linting**: golangci-lint v1.61.0 +- **Testing**: gotestsum v0.4.2 with coverage reports + +### Multi-Architecture Support + +- **AMD64**: Default build target +- **ARM64**: Available via `make arm` target +- **Release Builds**: Stripped binaries in `build/release/` + +### Environment Variables + +Key build-time environment variables: +- `AUTH_URL`, `AUTH_CLIENT_ID`, `AUTH_CLIENT_SECRET` +- `SENTRY_DSN` for error tracking +- `VERBOSE=1` for verbose build output + +## Development Workflow + +1. **Backend Changes**: Work in `src/`, use `make build && make run` for testing +2. **Frontend Changes**: Work in `apps/web/`, use `npm run dev` for hot reload +3. **Blockchain Changes**: Work in `tokens/`, use Anchor tooling for deployment +4. **Documentation**: Work in `docs/`, use Astro dev server for preview + +## Code Style and Conventions + +### Go Backend +- Follow standard Go formatting and conventions +- Use golangci-lint for code quality +- Comprehensive test coverage with gotestsum + +### Frontend +- TypeScript strict mode enabled +- ESLint configuration for code quality +- Tailwind CSS utility classes for styling +- Radix UI components for accessibility + +### Blockchain +- Rust smart contracts with Anchor framework +- TypeScript tests for contract verification +- Prettier formatting for JavaScript/TypeScript files \ No newline at end of file diff --git a/apps/web/README-CONSOLE.md b/apps/web/README-CONSOLE.md new file mode 100644 index 0000000..d52c475 --- /dev/null +++ b/apps/web/README-CONSOLE.md @@ -0,0 +1,146 @@ +# OCF Web Console + +A decentralized computing web console built on Next.js 15 with wallet authentication and machine management capabilities. + +## Features + +- **Wallet Authentication**: Connect with MetaMask, WalletConnect, and other Web3 wallets +- **Machine Management**: View connected computing resources and their status +- **API Key Management**: Generate and manage API keys for programmatic access +- **Real-time Status**: Monitor machine health, resource usage, and served models +- **Multi-chain Support**: Works with Ethereum, Polygon, Arbitrum, and Optimism +- **Responsive Design**: Built with Tailwind CSS and shadcn/ui components + +## Setup Instructions + +### 1. Install Dependencies + +```bash +npm install +``` + +### 2. Environment Configuration + +Create a `.env.local` file in the root directory: + +```env +NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=your_walletconnect_project_id_here +NEXT_PUBLIC_API_BASE_URL=http://localhost:3000/api +``` + +To get a WalletConnect Project ID: +1. Visit [WalletConnect Cloud](https://cloud.walletconnect.com/) +2. Create a new project +3. Copy the Project ID + +### 3. Run the Development Server + +```bash +npm run dev +``` + +The application will be available at `http://localhost:3001` + +## How It Works + +### Authentication Flow +1. User clicks "Connect Wallet" in the navbar +2. Web3Modal opens with wallet options +3. User connects their wallet (MetaMask, WalletConnect, etc.) +4. Application switches to dashboard view + +### Dashboard Features +- **User Profile**: Shows wallet address, ENS name (if available), and balance +- **Statistics**: Overview of total machines, active models, API keys, and requests +- **Machine Status**: Real-time status of connected computing resources +- **API Management**: Generate and manage API keys for accessing the OCF network + +### API Endpoints + +#### Get Machines +``` +GET /api/machines?walletAddress=0x... +``` + +#### Get API Keys +``` +GET /api/api-keys?walletAddress=0x... +``` + +#### Generate API Key +``` +POST /api/api-keys +{ + "walletAddress": "0x...", + "name": "API Key Name" +} +``` + +## Project Structure + +``` +apps/web/ +├── app/ +│ ├── api/ +│ │ ├── machines/ +│ │ └── api-keys/ +│ ├── layout.tsx +│ └── page.tsx +├── components/ +│ ├── dashboard.tsx +│ ├── wallet-connect.tsx +│ ├── ui/ +│ └── navbar/ +├── lib/ +│ ├── web3-provider.tsx +│ └── utils.ts +└── package.json +``` + +## Tech Stack + +- **Frontend**: Next.js 15, React 19, TypeScript +- **Styling**: Tailwind CSS, shadcn/ui +- **Web3**: Wagmi, Ethers.js, Web3Modal +- **State Management**: React Query +- **Authentication**: WalletConnect, MetaMask + +## Development + +### Available Scripts + +```bash +npm run dev # Start development server +npm run build # Build for production +npm run start # Start production server +npm run lint # Run ESLint +``` + +### Building for Production + +```bash +npm run build +npm start +``` + +## Future Enhancements + +- Real-time machine status updates with WebSockets +- Machine registration and management +- Detailed usage analytics and billing +- Model deployment and management +- Advanced API key permissions and rate limiting +- Mobile app integration +- Multi-user support with role-based access control + +## Contributing + +1. Fork the repository +2. Create a feature branch +3. Make your changes +4. Add tests if applicable +5. Submit a pull request + +## License + +This project is part of the Open Compute Framework and is licensed under the MIT License. \ No newline at end of file diff --git a/apps/web/app/layout.tsx b/apps/web/app/layout.tsx index 63eebdd..2c28597 100644 --- a/apps/web/app/layout.tsx +++ b/apps/web/app/layout.tsx @@ -2,6 +2,7 @@ import type { Metadata } from "next"; import { Geist } from "next/font/google"; import "./globals.css"; import { ThemeProvider } from "next-themes"; +import { Web3Provider } from "@/lib/web3-provider"; const geistSans = Geist({ variable: "--font-geist-sans", @@ -101,7 +102,9 @@ export default function RootLayout({ - {children} + + {children} + diff --git a/apps/web/app/page.tsx b/apps/web/app/page.tsx index 96cb452..85c6d03 100644 --- a/apps/web/app/page.tsx +++ b/apps/web/app/page.tsx @@ -1,21 +1,19 @@ -import FAQ from "@/components/faq"; -import Features from "@/components/features"; -import Footer from "@/components/footer"; -import Hero from "@/components/hero"; -import { Navbar } from "@/components/navbar"; -import Testimonial from "@/components/testimonial"; -import CodeExample from "@/components/code-example"; +'use client' + +import { useAccount } from 'wagmi' +import Hero from '@/components/hero' +import { Dashboard } from '@/components/dashboard' export default function Home() { + const { isConnected } = useAccount() + + if (isConnected) { + return + } + return ( <> - - - - - -