@dignetwork/chia-block-listener 0.1.8 → 0.1.9

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.
package/.yarnrc.yml CHANGED
@@ -1 +1 @@
1
- nodeLinker: node-modules
1
+ nodeLinker: node-modules
@@ -306,9 +306,23 @@ impl BlockParser {
306
306
  ) -> Option<CoinSpendInfo> {
307
307
  // Extract parent coin info
308
308
  let parent_bytes = self.extract_parent_coin_info(allocator, coin_spend)?;
309
- let mut parent_arr = [0u8; 32];
310
- parent_arr.copy_from_slice(&parent_bytes);
311
- let parent_coin_info = Bytes32::new(parent_arr);
309
+ info!("šŸ” DEBUG: parent_bytes length = {}", parent_bytes.len());
310
+
311
+ if parent_bytes.len() != 32 {
312
+ info!(
313
+ "āŒ ERROR: parent_bytes wrong length: {} bytes (expected 32)",
314
+ parent_bytes.len()
315
+ );
316
+ return None;
317
+ }
318
+
319
+ // parent_bytes is already Vec<u8> with 32 bytes, just hex encode it directly
320
+ let parent_hex = hex::encode(&parent_bytes);
321
+ info!(
322
+ "šŸ” DEBUG: parent_coin_info hex = {} (length: {})",
323
+ parent_hex,
324
+ parent_hex.len()
325
+ );
312
326
 
313
327
  // Extract puzzle, amount, and solution
314
328
  let rest1 = rest(allocator, coin_spend).ok()?;
@@ -324,14 +338,31 @@ impl BlockParser {
324
338
 
325
339
  // Calculate puzzle hash
326
340
  let puzzle_hash_vec = tree_hash(allocator, puzzle);
327
- let mut puzzle_hash_arr = [0u8; 32];
328
- puzzle_hash_arr.copy_from_slice(&puzzle_hash_vec);
329
- let puzzle_hash = Bytes32::new(puzzle_hash_arr);
341
+ info!(
342
+ "šŸ” DEBUG: tree_hash returned {} bytes",
343
+ puzzle_hash_vec.len()
344
+ );
345
+
346
+ if puzzle_hash_vec.len() != 32 {
347
+ info!(
348
+ "āŒ ERROR: tree_hash returned wrong length: {} bytes (expected 32)",
349
+ puzzle_hash_vec.len()
350
+ );
351
+ return None;
352
+ }
353
+
354
+ // tree_hash returns Vec<u8> with 32 bytes, just hex encode it directly
355
+ let puzzle_hash_hex = hex::encode(&puzzle_hash_vec);
356
+ info!(
357
+ "šŸ” DEBUG: puzzle_hash hex = {} (length: {})",
358
+ puzzle_hash_hex,
359
+ puzzle_hash_hex.len()
360
+ );
330
361
 
331
362
  // Create coin info
332
363
  let coin_info = CoinInfo {
333
- parent_coin_info: hex::encode(&parent_coin_info),
334
- puzzle_hash: hex::encode(&puzzle_hash),
364
+ parent_coin_info: parent_hex,
365
+ puzzle_hash: puzzle_hash_hex,
335
366
  amount,
336
367
  };
337
368
 
@@ -2,6 +2,8 @@ const { ChiaBlockListener, initTracing } = require('../index.js');
2
2
  const dns = require('dns').promises;
3
3
  const fs = require('fs');
4
4
  const path = require('path');
5
+ const dig = require('@dignetwork/datalayer-driver');
6
+
5
7
 
6
8
  // Create log file with timestamp
7
9
  const logFileName = `coin-monitor-${new Date().toISOString().replace(/:/g, '-').split('.')[0]}.log`;
@@ -110,7 +112,7 @@ function formatAddress(host, port, family) {
110
112
  }
111
113
 
112
114
  // Try to connect to peers until one succeeds
113
- async function connectToAnyPeer(listener, networkId = 'mainnet', maxAttempts = 10) {
115
+ async function connectToAnyPeer(listener, networkId = 'mainnet', maxAttempts = 20) {
114
116
  const peers = await discoverPeers(networkId);
115
117
 
116
118
  console.log(`šŸ”Œ Attempting to connect to peers (max ${maxAttempts} attempts)...`);
@@ -154,6 +156,57 @@ async function main() {
154
156
  // Log every block as it's received
155
157
  listener.on('blockReceived', (event) => {
156
158
  console.log('\nšŸ“¦ Real-time Block Event:');
159
+ console.log(`Block Height: ${event.height}, Timestamp: ${event.timestamp}`);
160
+ console.log(`Coin Additions: ${event.coinAdditions.length}, Coin Removals: ${event.coinRemovals.length}`);
161
+ console.log(`Coin Spends: ${event.coinSpends.length}, Coin Creations: ${event.coinCreations.length}`);
162
+
163
+ // Extract and log puzzle hashes from coin spends
164
+ if (event.coinSpends && event.coinSpends.length > 0) {
165
+ const puzzleHashes = event.coinSpends.map(spend => spend.coin.puzzleHash);
166
+ console.log('\n🧩 Puzzle Hashes from Coin Spends:');
167
+ console.log(`Found ${puzzleHashes.length} puzzle hashes:`);
168
+ puzzleHashes.forEach((hash, index) => {
169
+ console.log(` ${index + 1}. ${hash} (length: ${hash.length} chars, expected: 64)`);
170
+
171
+ // Only try to convert to address if it's the right length
172
+ if (hash.length === 64) {
173
+ try {
174
+ const address = dig.puzzleHashToAddress(Buffer.from(hash, 'hex'), 'xch');
175
+ console.log(` Address: ${address}`);
176
+ } catch (e) {
177
+ console.log(` Address conversion failed: ${e.message}`);
178
+ }
179
+ } else {
180
+ console.log(` āŒ Invalid puzzle hash length (should be 64 hex chars for 32 bytes)`);
181
+ }
182
+ });
183
+
184
+ // Also log unique puzzle hashes
185
+ const uniquePuzzleHashes = [...new Set(puzzleHashes)];
186
+ if (uniquePuzzleHashes.length !== puzzleHashes.length) {
187
+ console.log(`\nšŸ” Unique Puzzle Hashes (${uniquePuzzleHashes.length} unique):`);
188
+ uniquePuzzleHashes.forEach((hash, index) => {
189
+ console.log(` ${index + 1}. ${hash} (length: ${hash.length} chars)`);
190
+
191
+ // Only try to convert to address if it's the right length
192
+ if (hash.length === 64) {
193
+ try {
194
+ const address = dig.puzzleHashToAddress(Buffer.from(hash, 'hex'), 'xch');
195
+ console.log(` Address: ${address}`);
196
+ } catch (e) {
197
+ console.log(` Address conversion failed: ${e.message}`);
198
+ }
199
+ } else {
200
+ console.log(` āŒ Invalid puzzle hash length`);
201
+ }
202
+ });
203
+ }
204
+ } else {
205
+ console.log('\n🧩 No coin spends found in this block');
206
+ }
207
+
208
+ // Full block details for debugging (can be commented out if too verbose)
209
+ console.log('\nšŸ“‹ Full Block Details:');
157
210
  console.log(JSON.stringify(event, null, 2));
158
211
  console.log('\n' + '='.repeat(80) + '\n');
159
212
  });
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dignetwork/chia-block-listener-darwin-arm64",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/DIG-Network/chia-block-listener"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dignetwork/chia-block-listener-darwin-x64",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/DIG-Network/chia-block-listener"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dignetwork/chia-block-listener-linux-arm64-gnu",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/DIG-Network/chia-block-listener"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dignetwork/chia-block-listener-linux-x64-gnu",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/DIG-Network/chia-block-listener"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dignetwork/chia-block-listener-win32-x64-msvc",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/DIG-Network/chia-block-listener"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dignetwork/chia-block-listener",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "repository": {
@@ -57,11 +57,14 @@
57
57
  "update:images": "echo 'šŸ’” Tip: Update your CI images to use newer Rust versions that support edition2024'"
58
58
  },
59
59
  "packageManager": "yarn@1.22.22",
60
+ "dependencies": {
61
+ "@dignetwork/datalayer-driver": "^0.1.35"
62
+ },
60
63
  "optionalDependencies": {
61
- "@dignetwork/chia-block-listener-win32-x64-msvc": "0.1.8",
62
- "@dignetwork/chia-block-listener-darwin-x64": "0.1.8",
63
- "@dignetwork/chia-block-listener-linux-x64-gnu": "0.1.8",
64
- "@dignetwork/chia-block-listener-darwin-arm64": "0.1.8",
65
- "@dignetwork/chia-block-listener-linux-arm64-gnu": "0.1.8"
64
+ "@dignetwork/chia-block-listener-win32-x64-msvc": "0.1.9",
65
+ "@dignetwork/chia-block-listener-darwin-x64": "0.1.9",
66
+ "@dignetwork/chia-block-listener-linux-x64-gnu": "0.1.9",
67
+ "@dignetwork/chia-block-listener-darwin-arm64": "0.1.9",
68
+ "@dignetwork/chia-block-listener-linux-arm64-gnu": "0.1.9"
66
69
  }
67
70
  }
@@ -707,14 +707,14 @@ impl ChiaBlockListener {
707
707
  peer_id,
708
708
  height: parsed_block.height,
709
709
  weight: parsed_block.weight.clone(),
710
- header_hash: hex::encode(&parsed_block.header_hash),
710
+ header_hash: parsed_block.header_hash.clone(),
711
711
  timestamp: parsed_block.timestamp.unwrap_or(0),
712
712
  coin_additions: parsed_block
713
713
  .coin_additions
714
714
  .iter()
715
715
  .map(|coin| CoinRecord {
716
- parent_coin_info: hex::encode(&coin.parent_coin_info),
717
- puzzle_hash: hex::encode(&coin.puzzle_hash),
716
+ parent_coin_info: coin.parent_coin_info.clone(),
717
+ puzzle_hash: coin.puzzle_hash.clone(),
718
718
  amount: coin.amount.to_string(),
719
719
  })
720
720
  .collect(),
@@ -722,8 +722,8 @@ impl ChiaBlockListener {
722
722
  .coin_removals
723
723
  .iter()
724
724
  .map(|coin| CoinRecord {
725
- parent_coin_info: hex::encode(&coin.parent_coin_info),
726
- puzzle_hash: hex::encode(&coin.puzzle_hash),
725
+ parent_coin_info: coin.parent_coin_info.clone(),
726
+ puzzle_hash: coin.puzzle_hash.clone(),
727
727
  amount: coin.amount.to_string(),
728
728
  })
729
729
  .collect(),
@@ -732,8 +732,8 @@ impl ChiaBlockListener {
732
732
  .iter()
733
733
  .map(|spend| CoinSpend {
734
734
  coin: CoinRecord {
735
- parent_coin_info: hex::encode(&spend.coin.parent_coin_info),
736
- puzzle_hash: hex::encode(&spend.coin.puzzle_hash),
735
+ parent_coin_info: spend.coin.parent_coin_info.clone(),
736
+ puzzle_hash: spend.coin.puzzle_hash.clone(),
737
737
  amount: spend.coin.amount.to_string(),
738
738
  },
739
739
  puzzle_reveal: hex::encode(&spend.puzzle_reveal),
@@ -745,8 +745,8 @@ impl ChiaBlockListener {
745
745
  .coin_creations
746
746
  .iter()
747
747
  .map(|coin| CoinRecord {
748
- parent_coin_info: hex::encode(&coin.parent_coin_info),
749
- puzzle_hash: hex::encode(&coin.puzzle_hash),
748
+ parent_coin_info: coin.parent_coin_info.clone(),
749
+ puzzle_hash: coin.puzzle_hash.clone(),
750
750
  amount: coin.amount.to_string(),
751
751
  })
752
752
  .collect(),