@dignetwork/chia-block-listener 0.1.4 → 0.1.7

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 (45) hide show
  1. package/.github/workflows/CI.yml +143 -116
  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/README.md +288 -242
  17. package/__test__/index.test.mjs +29 -0
  18. package/crate/chia-generator-parser/Cargo.toml +34 -0
  19. package/crate/chia-generator-parser/README.md +244 -0
  20. package/crate/chia-generator-parser/examples/basic_usage.rs +73 -0
  21. package/crate/chia-generator-parser/examples/production_test.rs +147 -0
  22. package/crate/chia-generator-parser/src/error.rs +27 -0
  23. package/crate/chia-generator-parser/src/lib.rs +7 -0
  24. package/crate/chia-generator-parser/src/parser.rs +508 -0
  25. package/crate/chia-generator-parser/src/types.rs +255 -0
  26. package/examples/coin-monitor.js +195 -0
  27. package/index.d.ts +62 -6
  28. package/index.js +2 -1
  29. package/npm/darwin-arm64/package.json +1 -1
  30. package/npm/darwin-x64/package.json +1 -1
  31. package/npm/linux-arm64-gnu/package.json +1 -1
  32. package/npm/linux-x64-gnu/package.json +1 -1
  33. package/npm/win32-x64-msvc/package.json +1 -1
  34. package/package.json +12 -8
  35. package/scripts/bump-version.js +108 -0
  36. package/scripts/post-build.js +61 -0
  37. package/src/event_emitter.rs +274 -745
  38. package/src/peer.rs +59 -8
  39. package/tsconfig.json +20 -0
  40. package/examples/example-disconnect.js +0 -108
  41. package/examples/example-get-block-by-height.js +0 -368
  42. package/examples/example-historical-blocks.js +0 -162
  43. package/examples/example-sync.js +0 -240
  44. package/examples/example-with-discovery.js +0 -209
  45. package/examples/example.js +0 -77
@@ -53,19 +53,20 @@ jobs:
53
53
  settings:
54
54
  - host: macos-latest
55
55
  target: x86_64-apple-darwin
56
- build: npm run build -- --target x86_64-apple-darwin
56
+ build: npm run build -- --target x86_64-apple-darwin && node scripts/post-build.js
57
57
  - host: windows-latest
58
- build: npm run build -- --target x86_64-pc-windows-msvc
58
+ build: npm run build -- --target x86_64-pc-windows-msvc && node scripts/post-build.js
59
59
  target: x86_64-pc-windows-msvc
60
60
  - host: ubuntu-latest
61
61
  target: x86_64-unknown-linux-gnu
62
62
  build: |
63
63
  set -e &&
64
64
  npm run build -- --target x86_64-unknown-linux-gnu &&
65
+ node scripts/post-build.js &&
65
66
  strip *.node
66
67
  - host: macos-latest
67
68
  target: aarch64-apple-darwin
68
- build: npm run build -- --target aarch64-apple-darwin
69
+ build: npm run build -- --target aarch64-apple-darwin && node scripts/post-build.js
69
70
  - host: ubuntu-latest
70
71
  target: aarch64-unknown-linux-gnu
71
72
  setup: |
@@ -74,15 +75,16 @@ jobs:
74
75
  build: |
75
76
  set -e &&
76
77
  export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc &&
77
- npm run build -- --target aarch64-unknown-linux-gnu
78
- name: stable - ${{ matrix.settings.target }} - node@20
78
+ npm run build -- --target aarch64-unknown-linux-gnu &&
79
+ node scripts/post-build.js
80
+ name: stable - ${{ matrix.settings.target }} - node@22
79
81
  runs-on: ${{ matrix.settings.host }}
80
82
  steps:
81
83
  - uses: actions/checkout@v4
82
84
  - name: Setup node
83
85
  uses: actions/setup-node@v4
84
86
  with:
85
- node-version: 20
87
+ node-version: 22
86
88
  cache: npm
87
89
  - name: Install
88
90
  uses: dtolnay/rust-toolchain@stable
@@ -113,7 +115,7 @@ jobs:
113
115
  uses: actions/setup-node@v4
114
116
  if: matrix.settings.target == 'i686-pc-windows-msvc'
115
117
  with:
116
- node-version: 20
118
+ node-version: 22
117
119
  cache: npm
118
120
  architecture: x86
119
121
  - name: Setup toolchain
@@ -123,6 +125,18 @@ jobs:
123
125
  - name: Build
124
126
  run: ${{ matrix.settings.build }}
125
127
  shell: bash
128
+ - name: List files after build
129
+ run: |
130
+ echo "=== Current directory contents ==="
131
+ ls -la
132
+ echo "=== Looking for .node files ==="
133
+ find . -name "*.node" -type f
134
+ echo "=== Looking for files matching pattern ==="
135
+ ls -la ${{ env.APP_NAME }}.*.node || echo "No files match the pattern"
136
+ echo "=== Environment variables ==="
137
+ echo "APP_NAME: ${{ env.APP_NAME }}"
138
+ echo "Target: ${{ matrix.settings.target }}"
139
+ shell: bash
126
140
  - name: Upload artifact
127
141
  uses: actions/upload-artifact@v4
128
142
  with:
@@ -130,128 +144,141 @@ jobs:
130
144
  path: ${{ env.APP_NAME }}.*.node
131
145
  if-no-files-found: error
132
146
 
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
147
+ test-macOS-windows-binding:
148
+ name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}
149
+ needs:
150
+ - build
151
+ strategy:
152
+ fail-fast: false
153
+ matrix:
154
+ settings:
155
+ - host: macos-latest
156
+ target: x86_64-apple-darwin
157
+ - host: windows-latest
158
+ target: x86_64-pc-windows-msvc
159
+ node:
160
+ - '20'
161
+ - '22'
162
+ runs-on: ${{ matrix.settings.host }}
163
+ steps:
164
+ - uses: actions/checkout@v4
165
+ - name: Setup node
166
+ uses: actions/setup-node@v4
167
+ with:
168
+ node-version: ${{ matrix.node }}
169
+ cache: npm
170
+ architecture: x64
171
+ - name: Install dependencies
172
+ run: npm ci
173
+ - name: Download artifacts
174
+ uses: actions/download-artifact@v4
175
+ with:
176
+ name: bindings-${{ matrix.settings.target }}
177
+ path: .
178
+ - name: Move artifacts
179
+ run: npm run artifacts
180
+ - name: List packages
181
+ run: ls -R .
182
+ shell: bash
183
+ - name: Test bindings
184
+ run: npm test
170
185
 
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
186
+ test-linux-x64-gnu-binding:
187
+ name: Test bindings on Linux-x64-gnu - node@${{ matrix.node }}
188
+ needs:
189
+ - build
190
+ strategy:
191
+ fail-fast: false
192
+ matrix:
193
+ node:
194
+ - '20'
195
+ - '22'
196
+ runs-on: ubuntu-latest
197
+ steps:
198
+ - uses: actions/checkout@v4
199
+ - name: Setup node
200
+ uses: actions/setup-node@v4
201
+ with:
202
+ node-version: ${{ matrix.node }}
203
+ cache: npm
204
+ - name: Install dependencies
205
+ run: npm ci
206
+ - name: Download artifacts
207
+ uses: actions/download-artifact@v4
208
+ with:
209
+ name: bindings-x86_64-unknown-linux-gnu
210
+ path: .
211
+ - name: Install dependencies
212
+ run: npm ci
213
+ - name: Move artifacts
214
+ run: npm run artifacts
215
+ - name: List packages
216
+ run: ls -R .
217
+ shell: bash
218
+ - name: Test bindings
219
+ run: npm test
201
220
 
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
221
+ test-linux-aarch64-gnu-binding:
222
+ name: Test bindings on aarch64-unknown-linux-gnu - node@${{ matrix.node }}
223
+ needs:
224
+ - build
225
+ strategy:
226
+ fail-fast: false
227
+ matrix:
228
+ node:
229
+ - '20'
230
+ - '22'
231
+ runs-on: ubuntu-latest
232
+ steps:
233
+ - uses: actions/checkout@v4
234
+ - name: Download artifacts
235
+ uses: actions/download-artifact@v4
236
+ with:
237
+ name: bindings-aarch64-unknown-linux-gnu
238
+ path: .
239
+ - name: Install dependencies
240
+ run: npm ci
241
+ - name: Move artifacts
242
+ run: npm run artifacts
243
+ - name: List packages
244
+ run: ls -R .
245
+ shell: bash
246
+ - name: Set up QEMU
247
+ uses: docker/setup-qemu-action@v3
248
+ with:
249
+ platforms: arm64
250
+ - run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
251
+ - name: Setup and run tests
252
+ uses: addnab/docker-run-action@v3
253
+ with:
254
+ image: ubuntu:24.04
255
+ options: '--platform linux/arm64 -v ${{ github.workspace }}:/build -w /build'
256
+ run: |
257
+ set -e
258
+ apt-get update
259
+ apt-get install -y curl
260
+ curl -fsSL https://deb.nodesource.com/setup_${{ matrix.node }}.x | bash -
261
+ apt-get install -y nodejs
262
+ node --version
263
+ npm --version
264
+ npm ci
265
+ npm test
266
+ ls -la
239
267
 
240
268
  publish:
241
269
  name: Publish
242
270
  runs-on: ubuntu-latest
243
271
  needs:
244
272
  - 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
273
+ - test-macOS-windows-binding
274
+ - test-linux-x64-gnu-binding
275
+ - test-linux-aarch64-gnu-binding
249
276
  steps:
250
277
  - uses: actions/checkout@v4
251
278
  - name: Setup node
252
279
  uses: actions/setup-node@v4
253
280
  with:
254
- node-version: 20
281
+ node-version: 22
255
282
  cache: npm
256
283
  - name: Install dependencies
257
284
  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