@dignetwork/chia-block-listener 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/.github/workflows/CI.yml +137 -112
  2. package/.knowledge/context.md +48 -0
  3. package/.knowledge/critical_missing_implementation.md +90 -0
  4. package/.knowledge/gaps.md +22 -0
  5. package/.knowledge/implementation_audit.md +98 -0
  6. package/.knowledge/incomplete.md +32 -0
  7. package/.knowledge/proj_index.md +58 -0
  8. package/.knowledge/ref_index.md +37 -0
  9. package/.knowledge/reference/architecture_refactor.md +163 -0
  10. package/.knowledge/reference/block_parsing.md +169 -0
  11. package/.knowledge/reference/clvm_execution.md +203 -0
  12. package/.knowledge/reference/missing_generator_execution.md +116 -0
  13. package/.knowledge/reference/transaction_generators.md +34 -0
  14. package/.knowledge/tasks.md +24 -0
  15. package/Cargo.toml +3 -2
  16. package/__test__/index.test.mjs +29 -0
  17. package/crate/chia-generator-parser/Cargo.toml +34 -0
  18. package/crate/chia-generator-parser/README.md +244 -0
  19. package/crate/chia-generator-parser/examples/basic_usage.rs +73 -0
  20. package/crate/chia-generator-parser/examples/production_test.rs +147 -0
  21. package/crate/chia-generator-parser/src/error.rs +27 -0
  22. package/crate/chia-generator-parser/src/lib.rs +7 -0
  23. package/crate/chia-generator-parser/src/parser.rs +508 -0
  24. package/crate/chia-generator-parser/src/types.rs +255 -0
  25. package/examples/coin-monitor.js +195 -0
  26. package/index.d.ts +62 -6
  27. package/index.js +2 -1
  28. package/npm/darwin-arm64/package.json +1 -1
  29. package/npm/darwin-x64/package.json +1 -1
  30. package/npm/linux-arm64-gnu/package.json +1 -1
  31. package/npm/linux-x64-gnu/package.json +1 -1
  32. package/npm/win32-x64-msvc/package.json +1 -1
  33. package/package.json +12 -8
  34. package/scripts/bump-version.js +108 -0
  35. package/scripts/post-build.js +61 -0
  36. package/src/event_emitter.rs +274 -745
  37. package/src/peer.rs +59 -8
  38. package/tsconfig.json +20 -0
  39. package/examples/example-disconnect.js +0 -108
  40. package/examples/example-get-block-by-height.js +0 -368
  41. package/examples/example-historical-blocks.js +0 -162
  42. package/examples/example-sync.js +0 -240
  43. package/examples/example-with-discovery.js +0 -209
  44. package/examples/example.js +0 -77
@@ -75,14 +75,14 @@ jobs:
75
75
  set -e &&
76
76
  export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc &&
77
77
  npm run build -- --target aarch64-unknown-linux-gnu
78
- name: stable - ${{ matrix.settings.target }} - node@20
78
+ name: stable - ${{ matrix.settings.target }} - node@22
79
79
  runs-on: ${{ matrix.settings.host }}
80
80
  steps:
81
81
  - uses: actions/checkout@v4
82
82
  - name: Setup node
83
83
  uses: actions/setup-node@v4
84
84
  with:
85
- node-version: 20
85
+ node-version: 22
86
86
  cache: npm
87
87
  - name: Install
88
88
  uses: dtolnay/rust-toolchain@stable
@@ -113,7 +113,7 @@ jobs:
113
113
  uses: actions/setup-node@v4
114
114
  if: matrix.settings.target == 'i686-pc-windows-msvc'
115
115
  with:
116
- node-version: 20
116
+ node-version: 22
117
117
  cache: npm
118
118
  architecture: x86
119
119
  - name: Setup toolchain
@@ -123,6 +123,18 @@ jobs:
123
123
  - name: Build
124
124
  run: ${{ matrix.settings.build }}
125
125
  shell: bash
126
+ - name: List files after build
127
+ run: |
128
+ echo "=== Current directory contents ==="
129
+ ls -la
130
+ echo "=== Looking for .node files ==="
131
+ find . -name "*.node" -type f
132
+ echo "=== Looking for files matching pattern ==="
133
+ ls -la ${{ env.APP_NAME }}.*.node || echo "No files match the pattern"
134
+ echo "=== Environment variables ==="
135
+ echo "APP_NAME: ${{ env.APP_NAME }}"
136
+ echo "Target: ${{ matrix.settings.target }}"
137
+ shell: bash
126
138
  - name: Upload artifact
127
139
  uses: actions/upload-artifact@v4
128
140
  with:
@@ -130,128 +142,141 @@ jobs:
130
142
  path: ${{ env.APP_NAME }}.*.node
131
143
  if-no-files-found: error
132
144
 
133
- # TODO: Re-enable tests after builds are working
134
- # test-macOS-windows-binding:
135
- # name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}
136
- # needs:
137
- # - build
138
- # strategy:
139
- # fail-fast: false
140
- # matrix:
141
- # settings:
142
- # - host: macos-latest
143
- # target: x86_64-apple-darwin
144
- # - host: windows-latest
145
- # target: x86_64-pc-windows-msvc
146
- # node:
147
- # - '18'
148
- # - '20'
149
- # runs-on: ${{ matrix.settings.host }}
150
- # steps:
151
- # - uses: actions/checkout@v4
152
- # - name: Setup node
153
- # uses: actions/setup-node@v4
154
- # with:
155
- # node-version: ${{ matrix.node }}
156
- # cache: npm
157
- # architecture: x64
158
- # - name: Install dependencies
159
- # run: npm ci
160
- # - name: Download artifacts
161
- # uses: actions/download-artifact@v4
162
- # with:
163
- # name: bindings-${{ matrix.settings.target }}
164
- # path: .
165
- # - name: List packages
166
- # run: ls -R .
167
- # shell: bash
168
- # - name: Test bindings
169
- # run: npm test
145
+ test-macOS-windows-binding:
146
+ name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}
147
+ needs:
148
+ - build
149
+ strategy:
150
+ fail-fast: false
151
+ matrix:
152
+ settings:
153
+ - host: macos-latest
154
+ target: x86_64-apple-darwin
155
+ - host: windows-latest
156
+ target: x86_64-pc-windows-msvc
157
+ node:
158
+ - '20'
159
+ - '22'
160
+ runs-on: ${{ matrix.settings.host }}
161
+ steps:
162
+ - uses: actions/checkout@v4
163
+ - name: Setup node
164
+ uses: actions/setup-node@v4
165
+ with:
166
+ node-version: ${{ matrix.node }}
167
+ cache: npm
168
+ architecture: x64
169
+ - name: Install dependencies
170
+ run: npm ci
171
+ - name: Download artifacts
172
+ uses: actions/download-artifact@v4
173
+ with:
174
+ name: bindings-${{ matrix.settings.target }}
175
+ path: .
176
+ - name: Move artifacts
177
+ run: npm run artifacts
178
+ - name: List packages
179
+ run: ls -R .
180
+ shell: bash
181
+ - name: Test bindings
182
+ run: npm test
170
183
 
171
- # test-linux-x64-gnu-binding:
172
- # name: Test bindings on Linux-x64-gnu - node@${{ matrix.node }}
173
- # needs:
174
- # - build
175
- # strategy:
176
- # fail-fast: false
177
- # matrix:
178
- # node:
179
- # - '18'
180
- # - '20'
181
- # runs-on: ubuntu-latest
182
- # steps:
183
- # - uses: actions/checkout@v4
184
- # - name: Setup node
185
- # uses: actions/setup-node@v4
186
- # with:
187
- # node-version: ${{ matrix.node }}
188
- # cache: npm
189
- # - name: Install dependencies
190
- # run: npm ci
191
- # - name: Download artifacts
192
- # uses: actions/download-artifact@v4
193
- # with:
194
- # name: bindings-x86_64-unknown-linux-gnu
195
- # path: .
196
- # - name: List packages
197
- # run: ls -R .
198
- # shell: bash
199
- # - name: Test bindings
200
- # run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-slim npm test
184
+ test-linux-x64-gnu-binding:
185
+ name: Test bindings on Linux-x64-gnu - node@${{ matrix.node }}
186
+ needs:
187
+ - build
188
+ strategy:
189
+ fail-fast: false
190
+ matrix:
191
+ node:
192
+ - '20'
193
+ - '22'
194
+ runs-on: ubuntu-latest
195
+ steps:
196
+ - uses: actions/checkout@v4
197
+ - name: Setup node
198
+ uses: actions/setup-node@v4
199
+ with:
200
+ node-version: ${{ matrix.node }}
201
+ cache: npm
202
+ - name: Install dependencies
203
+ run: npm ci
204
+ - name: Download artifacts
205
+ uses: actions/download-artifact@v4
206
+ with:
207
+ name: bindings-x86_64-unknown-linux-gnu
208
+ path: .
209
+ - name: Install dependencies
210
+ run: npm ci
211
+ - name: Move artifacts
212
+ run: npm run artifacts
213
+ - name: List packages
214
+ run: ls -R .
215
+ shell: bash
216
+ - name: Test bindings
217
+ run: npm test
201
218
 
202
- # test-linux-aarch64-gnu-binding:
203
- # name: Test bindings on aarch64-unknown-linux-gnu - node@${{ matrix.node }}
204
- # needs:
205
- # - build
206
- # strategy:
207
- # fail-fast: false
208
- # matrix:
209
- # node:
210
- # - '18'
211
- # - '20'
212
- # runs-on: ubuntu-latest
213
- # steps:
214
- # - uses: actions/checkout@v4
215
- # - name: Download artifacts
216
- # uses: actions/download-artifact@v4
217
- # with:
218
- # name: bindings-aarch64-unknown-linux-gnu
219
- # path: .
220
- # - name: List packages
221
- # run: ls -R .
222
- # shell: bash
223
- # - name: Install dependencies
224
- # run: npm ci
225
- # - name: Set up QEMU
226
- # uses: docker/setup-qemu-action@v3
227
- # with:
228
- # platforms: arm64
229
- # - run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
230
- # - name: Setup and run tests
231
- # uses: addnab/docker-run-action@v3
232
- # with:
233
- # image: node:${{ matrix.node }}-slim
234
- # options: '--platform linux/arm64 -v ${{ github.workspace }}:/build -w /build'
235
- # run: |
236
- # set -e
237
- # npm test
238
- # ls -la
219
+ test-linux-aarch64-gnu-binding:
220
+ name: Test bindings on aarch64-unknown-linux-gnu - node@${{ matrix.node }}
221
+ needs:
222
+ - build
223
+ strategy:
224
+ fail-fast: false
225
+ matrix:
226
+ node:
227
+ - '20'
228
+ - '22'
229
+ runs-on: ubuntu-latest
230
+ steps:
231
+ - uses: actions/checkout@v4
232
+ - name: Download artifacts
233
+ uses: actions/download-artifact@v4
234
+ with:
235
+ name: bindings-aarch64-unknown-linux-gnu
236
+ path: .
237
+ - name: Install dependencies
238
+ run: npm ci
239
+ - name: Move artifacts
240
+ run: npm run artifacts
241
+ - name: List packages
242
+ run: ls -R .
243
+ shell: bash
244
+ - name: Set up QEMU
245
+ uses: docker/setup-qemu-action@v3
246
+ with:
247
+ platforms: arm64
248
+ - run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
249
+ - name: Setup and run tests
250
+ uses: addnab/docker-run-action@v3
251
+ with:
252
+ image: ubuntu:24.04
253
+ options: '--platform linux/arm64 -v ${{ github.workspace }}:/build -w /build'
254
+ run: |
255
+ set -e
256
+ apt-get update
257
+ apt-get install -y curl
258
+ curl -fsSL https://deb.nodesource.com/setup_${{ matrix.node }}.x | bash -
259
+ apt-get install -y nodejs
260
+ node --version
261
+ npm --version
262
+ npm ci
263
+ npm test
264
+ ls -la
239
265
 
240
266
  publish:
241
267
  name: Publish
242
268
  runs-on: ubuntu-latest
243
269
  needs:
244
270
  - build
245
- # TODO: Re-enable test dependencies after tests are working
246
- # - test-macOS-windows-binding
247
- # - test-linux-x64-gnu-binding
248
- # - test-linux-aarch64-gnu-binding
271
+ - test-macOS-windows-binding
272
+ - test-linux-x64-gnu-binding
273
+ - test-linux-aarch64-gnu-binding
249
274
  steps:
250
275
  - uses: actions/checkout@v4
251
276
  - name: Setup node
252
277
  uses: actions/setup-node@v4
253
278
  with:
254
- node-version: 20
279
+ node-version: 22
255
280
  cache: npm
256
281
  - name: Install dependencies
257
282
  run: npm ci
@@ -0,0 +1,48 @@
1
+ # Chia Block Listener Project Context
2
+
3
+ ## Current State
4
+ - Rust-based WebSocket client connecting to Chia full nodes
5
+ - Uses NAPI for Node.js bindings
6
+ - Integrated chia-generator-parser crate for block parsing
7
+ - Can monitor real-time blocks but coin_spends extraction not working
8
+
9
+ ## Architecture
10
+ - `src/peer.rs`: WebSocket connection and block handling
11
+ - `src/event_emitter.rs`: NAPI bindings and JS event system
12
+ - `crate/chia-generator-parser/`: Block parsing using chia-protocol types
13
+ - Direct integration with chia-protocol crate (v0.26.0)
14
+
15
+ ## Recent Progress
16
+ - Successfully refactored to use chia-protocol types directly
17
+ - Eliminated manual byte parsing and redundant serialization
18
+ - Built and tested with real network connections
19
+ - Created real-time block monitor (coin-monitor.js)
20
+ - **FIXED: Implemented full CLVM execution using chia-consensus**
21
+ - **FIXED: TypeScript definitions now include all event types**
22
+
23
+ ## Completed Implementations
24
+ - Full CLVM execution using run_block_generator2 for coin extraction
25
+ - Real puzzle reveals and solutions from generator bytecode
26
+ - Proper TypeScript event type definitions with constants
27
+ - Event interfaces for PeerConnected, PeerDisconnected, BlockReceived
28
+ - Removed generatorBytecode from block events (not needed)
29
+ - Log file streaming for coin-monitor.js
30
+ - Removed processTransactionGenerator method (replaced by chia-generator-parser)
31
+ - Changed peer IDs from numeric to IP:port strings for better identification
32
+ - Added typed event emitters with full TypeScript support via post-build script
33
+ - Removed redundant Block type - all APIs now use BlockReceivedEvent consistently
34
+
35
+ ## Dependencies
36
+ - chia-protocol = "0.26.0"
37
+ - chia-traits = "0.26.0"
38
+ - chia-ssl = "0.26.0"
39
+ - chia-consensus = "0.26.0" (for CLVM execution)
40
+ - chia-bls = "0.26.0" (for signature handling)
41
+ - clvmr = "0.8.0" (for low-level CLVM operations)
42
+ - clvm-utils = "0.26.0" (for tree hashing)
43
+ - hex = "0.4" (for hex encoding/decoding)
44
+
45
+ ## Testing
46
+ - example-get-block-by-height.js: Requests specific blocks
47
+ - coin-monitor.js: Monitors real-time blocks
48
+ - Both show generator_bytecode but empty coin_spends
@@ -0,0 +1,90 @@
1
+ # Critical Missing Implementation: process_generator_for_coins
2
+
3
+ ## Current State ❌
4
+ The `process_generator_for_coins` function in `parser.rs` uses placeholder pattern matching instead of proper CLVM execution.
5
+
6
+ ## Required Implementation
7
+
8
+ ### 1. Add chia_rs dependency
9
+ ```toml
10
+ chia_rs = "0.11.0" # or appropriate version
11
+ ```
12
+
13
+ ### 2. Use run_block_generator2
14
+ ```rust
15
+ use chia_rs::{run_block_generator2, SpendBundleConditions};
16
+
17
+ fn process_generator_for_coins(
18
+ &self,
19
+ generator_bytes: &[u8],
20
+ block_refs: &[u32], // generator references
21
+ max_cost: u64,
22
+ height: u32,
23
+ ) -> Result<(Vec<CoinInfo>, Vec<CoinSpendInfo>, Vec<CoinInfo>)> {
24
+ // Call run_block_generator2 to execute the generator
25
+ let (err, conds) = run_block_generator2(
26
+ generator_bytes,
27
+ block_refs,
28
+ max_cost,
29
+ flags,
30
+ None, // aggregated_signature
31
+ None, // bls_cache
32
+ &constants,
33
+ );
34
+
35
+ if let Some(error) = err {
36
+ return Err(GeneratorParserError::GeneratorError(error));
37
+ }
38
+
39
+ let conditions = conds.ok_or(GeneratorParserError::NoConditions)?;
40
+
41
+ // Extract coins from SpendBundleConditions
42
+ let mut coin_removals = Vec::new();
43
+ let mut coin_additions = Vec::new();
44
+ let mut coin_spends = Vec::new();
45
+
46
+ // Process each spend
47
+ for spend in conditions.spends {
48
+ // Each spend removes the coin being spent
49
+ coin_removals.push(CoinInfo::from(spend.coin));
50
+
51
+ // Process CREATE_COIN conditions (opcode 51)
52
+ for condition in spend.conditions {
53
+ if condition.opcode == 51 { // CREATE_COIN
54
+ let new_coin = Coin::new(
55
+ spend.coin.coin_id(), // parent
56
+ condition.puzzle_hash,
57
+ condition.amount,
58
+ );
59
+ coin_additions.push(CoinInfo::from(new_coin));
60
+ }
61
+ }
62
+
63
+ // Build coin spend info
64
+ coin_spends.push(CoinSpendInfo {
65
+ coin: spend.coin,
66
+ puzzle_reveal: spend.puzzle_reveal,
67
+ solution: spend.solution,
68
+ // ... other fields
69
+ });
70
+ }
71
+
72
+ Ok((coin_removals, coin_spends, coin_additions))
73
+ }
74
+ ```
75
+
76
+ ### 3. Key Points
77
+ - SpendBundleConditions contains all spends from the generator
78
+ - Each spend has:
79
+ - The coin being spent (removal)
80
+ - Conditions including CREATE_COIN (additions)
81
+ - Puzzle reveal and solution
82
+ - Must handle generator references for compressed blocks
83
+ - Must pass proper constants and flags
84
+
85
+ ### 4. Missing Dependencies
86
+ Without proper CLVM execution via run_block_generator2:
87
+ - Cannot extract accurate coin data
88
+ - Cannot validate transactions
89
+ - Cannot build functional block explorers or wallets
90
+ - Will report incorrect blockchain state
@@ -0,0 +1,22 @@
1
+ # Known Implementation Gaps
2
+
3
+ ## Critical CLVM Execution Gap (PARTIALLY ADDRESSED)
4
+ - **Issue**: Using pattern matching instead of proper CLVM execution
5
+ - **Current**: Pattern matching extracts puzzle reveals and solutions from bytecode
6
+ - **Missing**: Cannot extract CREATE_COIN conditions or handle block references
7
+ - **Impact**: Will miss coins created by transactions and compressed blocks
8
+ - **Required**: Full integration with chia-consensus run_block_generator2
9
+ - **Blocker**: chia-consensus module paths not publicly exposed
10
+ - **Status**: Documented with workaround implemented
11
+
12
+ ## Compressed Block References (UNRESOLVED)
13
+ - **Issue**: Cannot handle blocks that reference previous generators
14
+ - **Impact**: Many blocks will fail to parse completely
15
+ - **Required**: Generator reference resolution system
16
+ - **Status**: Placeholder returns empty results
17
+
18
+ ## Real-time Block Coin Spend Extraction (RESOLVED)
19
+ - **Issue**: coin_spends array is empty even when generator_bytecode is present
20
+ - **Resolution**: parse_block() now calls process_generator_for_coins
21
+ - **Current**: Pattern matching extracts basic coin spends
22
+ - **Limitation**: Missing CREATE_COIN conditions
@@ -0,0 +1,98 @@
1
+ # Implementation Audit: chia-generator-parser vs Python full_node
2
+
3
+ ## Executive Summary
4
+
5
+ After comparing the Rust implementation with the Python full_node code, there are **3 critical issues** and **1 minor issue** that prevent this from being production-ready.
6
+
7
+ ## Critical Issues
8
+
9
+ ### 1. ❌ Generator Execution Not Implemented (`process_generator_for_coins`)
10
+ **Location**: `crate/chia-generator-parser/src/parser.rs:296-365`
11
+ **Issue**: Uses placeholder pattern matching instead of proper CLVM execution
12
+ **Required**: Must use `run_block_generator2` from chia_rs to:
13
+ - Execute the generator with proper block references
14
+ - Extract SpendBundleConditions
15
+ - Get accurate coin removals, additions, and spends
16
+
17
+ **Python Reference**: `mempool.py:539`
18
+ ```python
19
+ err, conds = run_block_generator2(
20
+ block_program,
21
+ [], # generator refs
22
+ constants.MAX_BLOCK_COST_CLVM,
23
+ flags,
24
+ spend_bundle.aggregated_signature,
25
+ None,
26
+ constants,
27
+ )
28
+ ```
29
+
30
+ ### 2. ❌ No Coin Spend Details Extraction
31
+ **Issue**: Current implementation cannot extract:
32
+ - Puzzle reveals for each spend
33
+ - Solutions for each spend
34
+ - Accurate parent-child relationships
35
+ - Conditions from each spend
36
+
37
+ **Required**: After running generator, need to parse SpendBundleConditions to extract:
38
+ - Individual coin spends with full data
39
+ - CREATE_COIN conditions (opcode 51) for coin additions
40
+ - All spent coins for removals
41
+
42
+ ### 3. ❌ No Generator Reference Support
43
+ **Issue**: Blocks can reference previous generators to save space
44
+ **Current**: Generator refs are parsed but not used
45
+ **Required**: When executing generator, must provide referenced generators from previous blocks
46
+
47
+ ## Minor Issue
48
+
49
+ ### 4. ⚠️ Header Block Creation Incomplete (`header_block_from_block`)
50
+ **Location**: `crate/chia-generator-parser/src/parser.rs:653-668`
51
+ **Issue**: Returns original block instead of creating proper header
52
+ **Required**:
53
+ - Extract fields up to (but not including) transactions_info
54
+ - Create BIP158 filter if requested
55
+ - Serialize with filter + optional transactions_info
56
+
57
+ **Note**: This is less critical as it's mainly for network protocol optimization
58
+
59
+ ## Implemented Correctly ✅
60
+
61
+ 1. **Block Parsing**: All skip functions correctly match Python
62
+ 2. **Field Extraction**: Height, weight, timestamp, reward claims all correct
63
+ 3. **Generator Extraction**: `extract_generator_from_block` matches Python exactly
64
+ 4. **Block Info**: `parse_block_info` correctly extracts GeneratorBlockInfo
65
+ 5. **Height/TX Status**: `get_height_and_tx_status_from_block` correct
66
+
67
+ ## Production Readiness Assessment
68
+
69
+ **Current State**: NOT production ready
70
+ **Reason**: Cannot accurately extract coins from blocks with generators
71
+
72
+ ### Required for Production:
73
+
74
+ 1. **Add chia_rs dependency** or implement custom `run_block_generator2`
75
+ 2. **Implement proper generator execution** with:
76
+ - Block reference loading
77
+ - Consensus constants
78
+ - Proper flags (MEMPOOL_MODE, etc.)
79
+ 3. **Parse SpendBundleConditions** to extract:
80
+ - Coin removals (spent coins)
81
+ - Coin additions (from CREATE_COIN)
82
+ - Full spend details
83
+ 4. **Handle generator references** for compressed blocks
84
+
85
+ ### Optional Improvements:
86
+
87
+ 1. Complete `header_block_from_block` for protocol compatibility
88
+ 2. Add signature validation support
89
+ 3. Add cost tracking and limits
90
+
91
+ ## Recommendation
92
+
93
+ The block parsing infrastructure is solid, but without proper CLVM execution, this cannot be used in production. The current pattern matching approach will:
94
+ - Miss most coins
95
+ - Report incorrect coin data
96
+ - Fail on compressed generators with references
97
+
98
+ **Action**: Either integrate chia_rs properly or implement a custom CLVM executor before production use.
@@ -0,0 +1,32 @@
1
+ # Incomplete Implementations
2
+
3
+ ## ~~CLVM Transaction Generator Parsing~~ ✅ FIXED
4
+ - **File**: `src/event_emitter.rs`
5
+ - **Function**: `execute_transaction_generator`
6
+ - **Lines**: ~1030-1080
7
+ - **Type**: ~~Incorrect implementation~~ ✅ FIXED
8
+ - **Issue**: ~~Using wrong parsing approach, should use `node_from_bytes`~~ ✅ FIXED
9
+ - **Priority**: ~~High~~ ✅ COMPLETED
10
+ - **Solution Applied**: Now uses `clvmr::serde::node_from_bytes` and proper CLVM execution
11
+
12
+ ## Code Cleanup Needed
13
+ - **File**: `src/event_emitter.rs`
14
+ - **Functions**: Multiple unused fallback parsing methods
15
+ - **Lines**: Various (1384+, 1999+, etc.)
16
+ - **Type**: Dead code after successful fix
17
+ - **Issue**: Unused pattern matching and alternative parsing methods
18
+ - **Priority**: Low (cleanup)
19
+
20
+ ## Unused Imports
21
+ - **File**: `src/event_emitter.rs`
22
+ - **Lines**: Various import statements
23
+ - **Type**: Unused imports causing build warnings
24
+ - **Issue**: 19 warning messages about unused imports
25
+ - **Priority**: Low (cleanup)
26
+
27
+ ## Testing and Validation
28
+ - **File**: `examples/coin-monitor.js`
29
+ - **Function**: Real-world testing of CLVM parsing
30
+ - **Type**: Validation needed
31
+ - **Issue**: Need to confirm the fix works with actual transaction generators
32
+ - **Priority**: Medium (validation)
@@ -0,0 +1,58 @@
1
+ # Project Architecture Index
2
+
3
+ ## Module Structure
4
+
5
+ ### Core Components
6
+ - `src/event_emitter.rs` - Main NAPI interface and event system
7
+ - ChiaBlockListener class
8
+ - Event handling (on/off methods)
9
+ - Peer management (addPeer, disconnectPeer, etc.)
10
+ - Block retrieval APIs
11
+
12
+ - `src/peer.rs` - WebSocket peer connection management
13
+ - Connection handling
14
+ - Block listening
15
+ - Handshake protocol
16
+
17
+ - `src/protocol.rs` - Chia protocol implementation
18
+ - Message types
19
+ - Handshake structures
20
+
21
+ ### Parser Module (`crate/chia-generator-parser/`)
22
+ - `src/parser.rs` - Block parsing with CLVM execution
23
+ - Uses chia-consensus for generator execution
24
+ - Extracts coin spends with puzzle reveals/solutions
25
+ - Handles CREATE_COIN conditions
26
+
27
+ ### TypeScript Integration
28
+ - `index.d.ts` - Auto-generated TypeScript definitions
29
+ - Enhanced with typed event overloads via post-build script
30
+ - Full IntelliSense support for event handlers
31
+
32
+ - `scripts/post-build.js` - Adds typed event method overloads
33
+ - Runs automatically after build
34
+ - Provides type-safe event handling
35
+
36
+ ## Key Interfaces
37
+
38
+ ### Events
39
+ - `BlockReceivedEvent` - Contains peerId + all block data
40
+ - `PeerConnectedEvent` - peerId, host, port
41
+ - `PeerDisconnectedEvent` - peerId, host, port, optional message
42
+
43
+ ### Data Types
44
+ - `BlockReceivedEvent` - Used everywhere for consistency (includes peerId)
45
+ - `CoinRecord` - Parent info, puzzle hash, amount
46
+ - `CoinSpend` - Full spend with puzzle reveal and solution
47
+
48
+ ## Event System
49
+ ```typescript
50
+ // Typed event handlers
51
+ listener.on('blockReceived', (event: BlockReceivedEvent) => { });
52
+ listener.on('peerConnected', (event: PeerConnectedEvent) => { });
53
+ listener.on('peerDisconnected', (event: PeerDisconnectedEvent) => { });
54
+ ```
55
+
56
+ ## Peer Identification
57
+ - Peer IDs are now `"IP:port"` strings (e.g., `"192.168.1.100:8444"`)
58
+ - Makes peer identification clearer in logs and events