How garynvu/blockchain-go works
Project type and purpose
• This is a standalone, full‐node blockchain implementation written in Go.
• It provides a CLI interface for mining blocks, creating and signing transactions, and querying the ledger.
• The core functionality lives in the blockchain package; wallet management is in wallet; the executable glue is in cli and main.go.
File structure
• Top‐level:
• main.go – entry point that initializes the node and dispatches CLI commands
• cli/cli.go – command‐line parsing and user interactions
• blockchain/ – core chain data structures (block.go, transaction.go, etc.), proof‐of‐work (proof.go), chain management (blockchain.go)
• wallet/ – wallet/keypair generation (wallet.go), persistence (wallets.go), and helpers (utils.go)
• tmp/ – persistent storage directory for block data files and wallet datastore
• Configuration and dependency manifests: go.mod, go.sum.
Extract insights from the README
• Purpose: “Creation of a blockchain with Golang”
a. Main components
1. CLI Layer
• Parses user commands (createwallet, getbalance, send, mine, printchain)
2. Application Layer (main)
• Bootstraps the CLI and wires together blockchain and wallet modules
3. Blockchain Core
• Block and Transaction models
• Blockchain manager (chain of blocks, UTXO set)
• Proof‐of‐Work engine
4. Wallet Manager
• Keypair generation
• Wallet datastore
• Transaction signing
5. Persistence Layer
• Block storage (LSM‐style SSTables and value logs under tmp/blocks/)
• Wallet file (tmp/wallets.data)
b. Relationships and interactions
• CLI → calls → Application Layer
• Application Layer → invokes → Wallet Manager (for address creation/signing)
• Application Layer → invokes → Blockchain Core (for ledger queries, mining, broadcasting txs)
• Blockchain Core ↔ Persistence Layer (read/write blocks & UTXO data)
• Wallet Manager ↔ Persistence Layer (store/load wallets)
c. Architectural patterns & principles
• Layered architecture: separation between CLI, domain logic (blockchain & wallet), and storage
• Single‐node design (no networking layer yet)
• Modular Go packages for testability and separation of concerns
d. Key technologies
• Go modules (go.mod)
• File‐based storage (custom SST/VLOG files under tmp/)
• Standard Go crypto libraries (for hashing, signatures)
• CLI parsing (built-in flag or custom)
Additional detail
• For the transaction flow:
• CLI “send” command → wallet signs transaction → blockchain verifies and appends to new block.