How taiguz/react-blockchain works
Project type and purpose
• This is a single‐page web application built with React and TypeScript.
File structure
• Top‐level files:
• package.json, tsconfig.json → build & dependency configuration
• public/ → static assets (index.html, manifest, robots.txt)
• src/ → application source
• src/class/ → pure domain logic classes
• Block/index.ts & types.ts → Block model, hash generation, attributes (index, timestamp, previousHash, nonce, someData)
• BlockChain/index.ts & types.ts → Blockchain model, integrity check, chain array, addBlock, mineBlock
• src/components/ → React UI components
• Main → container for the whole app, holds state of chain & difficulty
• Block → renders a single block’s properties
• Miner → UI for entering “someData,” selecting difficulty, running mining, displaying real‐time hash trials/time elapsed
• src/index.tsx → application entry point, renders <Main />
README for additional insights
• Confirms use of crypto-js for SHA-256 hashing
• Describes core features: dynamic difficulty, proof‐of‐work mining routine, chain integrity validation, UI demo with hash sampling
a. Main components:
• Browser/User Interface (React SPA)
• React Components: Main, Block, Miner
• Blockchain Engine: Block class, BlockChain class
• External Library: crypto-js (SHA-256)
b. Relationships and data flows:
1. User interacts with Miner component (inputs data & difficulty)
2. Miner invokes BlockChain.mineBlock(someData, difficulty)
3. BlockChain uses Block.generateHash() (crypto-js SHA-256) in a loop, emits hash samples/events
4. Miner component subscribes to hash‐trial events to update the UI (hash stream + timer)
5. On finding a valid nonce, Miner calls BlockChain.addBlock(newBlock)
6. Main component updates its state (list of blocks) and re‐renders Block list
c. Architectural patterns / principles:
• Component‐based UI with unidirectional data flow (React state lifting)
• Separation of concerns: Presentation (React) vs Domain Logic (TypeScript classes)
• Event‐driven updates (callbacks or observables for hash sampling)
• No backend – fully client‐side, in‐memory blockchain simulation
d. Relevant technologies:
• React + ReactDOM
• TypeScript
• crypto-js (SHA-256)
• Webpack (via create-react-app implied)