@dignetwork/chia-block-listener 0.1.7 → 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/.github/workflows/CI.yml +36 -6
- package/.yarnrc.yml +1 -1
- package/README.md +23 -25
- package/crate/chia-generator-parser/src/parser.rs +39 -8
- package/examples/coin-monitor.js +54 -1
- package/index.d.ts +0 -16
- package/npm/darwin-arm64/package.json +1 -1
- package/npm/darwin-x64/package.json +1 -1
- package/npm/linux-arm64-gnu/package.json +1 -1
- package/npm/linux-x64-gnu/package.json +1 -1
- package/npm/win32-x64-msvc/package.json +1 -1
- package/package.json +9 -6
- package/scripts/post-build.js +15 -1
- package/src/event_emitter.rs +40 -38
package/.github/workflows/CI.yml
CHANGED
|
@@ -193,7 +193,7 @@ jobs:
|
|
|
193
193
|
node:
|
|
194
194
|
- '20'
|
|
195
195
|
- '22'
|
|
196
|
-
runs-on: ubuntu-
|
|
196
|
+
runs-on: ubuntu-24.04
|
|
197
197
|
steps:
|
|
198
198
|
- uses: actions/checkout@v4
|
|
199
199
|
- name: Setup node
|
|
@@ -252,18 +252,48 @@ jobs:
|
|
|
252
252
|
uses: addnab/docker-run-action@v3
|
|
253
253
|
with:
|
|
254
254
|
image: ubuntu:24.04
|
|
255
|
-
options: '--platform linux/arm64 -v ${{ github.workspace }}:/
|
|
255
|
+
options: '--platform linux/arm64 -v ${{ github.workspace }}:/workspace -w /workspace'
|
|
256
256
|
run: |
|
|
257
257
|
set -e
|
|
258
|
+
export DEBIAN_FRONTEND=noninteractive
|
|
258
259
|
apt-get update
|
|
259
|
-
apt-get install -y curl
|
|
260
|
-
|
|
261
|
-
|
|
260
|
+
apt-get install -y curl ca-certificates xz-utils
|
|
261
|
+
|
|
262
|
+
# Install Node.js using a different approach - download pre-built binary directly
|
|
263
|
+
NODE_VERSION="${{ matrix.node }}"
|
|
264
|
+
case "$NODE_VERSION" in
|
|
265
|
+
"20")
|
|
266
|
+
FULL_VERSION="20.18.0"
|
|
267
|
+
;;
|
|
268
|
+
"22")
|
|
269
|
+
FULL_VERSION="22.11.0" # Use slightly older version of 22 for stability
|
|
270
|
+
;;
|
|
271
|
+
*)
|
|
272
|
+
echo "Unsupported Node version: $NODE_VERSION"
|
|
273
|
+
exit 1
|
|
274
|
+
;;
|
|
275
|
+
esac
|
|
276
|
+
|
|
277
|
+
# Download and install Node.js binary
|
|
278
|
+
cd /tmp
|
|
279
|
+
curl -fsSL "https://nodejs.org/dist/v${FULL_VERSION}/node-v${FULL_VERSION}-linux-arm64.tar.xz" -o node.tar.xz
|
|
280
|
+
tar -xf node.tar.xz
|
|
281
|
+
cp -r "node-v${FULL_VERSION}-linux-arm64"/* /usr/local/
|
|
282
|
+
rm -rf node.tar.xz "node-v${FULL_VERSION}-linux-arm64"
|
|
283
|
+
|
|
284
|
+
# Return to workspace
|
|
285
|
+
cd /workspace
|
|
286
|
+
|
|
287
|
+
# Verify we're in the right directory and have the required files
|
|
288
|
+
pwd
|
|
289
|
+
ls -la
|
|
290
|
+
echo "Looking for package-lock.json:"
|
|
291
|
+
ls -la package-lock.json || echo "package-lock.json not found"
|
|
292
|
+
|
|
262
293
|
node --version
|
|
263
294
|
npm --version
|
|
264
295
|
npm ci
|
|
265
296
|
npm test
|
|
266
|
-
ls -la
|
|
267
297
|
|
|
268
298
|
publish:
|
|
269
299
|
name: Publish
|
package/.yarnrc.yml
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
nodeLinker: node-modules
|
|
1
|
+
nodeLinker: node-modules
|
package/README.md
CHANGED
|
@@ -33,11 +33,11 @@ const listener = new ChiaBlockListener()
|
|
|
33
33
|
// Listen for block events
|
|
34
34
|
listener.on('blockReceived', (block) => {
|
|
35
35
|
console.log(`New block received: ${block.height}`)
|
|
36
|
-
console.log(`Header hash: ${block.
|
|
36
|
+
console.log(`Header hash: ${block.header_hash}`)
|
|
37
37
|
console.log(`Timestamp: ${new Date(block.timestamp * 1000)}`)
|
|
38
|
-
console.log(`Coin additions: ${block.
|
|
39
|
-
console.log(`Coin removals: ${block.
|
|
40
|
-
console.log(`Coin spends: ${block.
|
|
38
|
+
console.log(`Coin additions: ${block.coin_additions.length}`)
|
|
39
|
+
console.log(`Coin removals: ${block.coin_removals.length}`)
|
|
40
|
+
console.log(`Coin spends: ${block.coin_spends.length}`)
|
|
41
41
|
})
|
|
42
42
|
|
|
43
43
|
// Listen for peer connection events
|
|
@@ -155,11 +155,11 @@ Fired when a peer connection is lost.
|
|
|
155
155
|
|
|
156
156
|
```typescript
|
|
157
157
|
interface BlockReceivedEvent {
|
|
158
|
-
peerId: string //
|
|
159
|
-
height: number
|
|
160
|
-
weight: string
|
|
158
|
+
peerId: string // IP address of the peer that sent this block
|
|
159
|
+
height: number // Block height
|
|
160
|
+
weight: string // Block weight as string
|
|
161
161
|
headerHash: string // Block header hash (hex)
|
|
162
|
-
timestamp: number
|
|
162
|
+
timestamp: number // Block timestamp (Unix time)
|
|
163
163
|
coinAdditions: CoinRecord[] // New coins created in this block
|
|
164
164
|
coinRemovals: CoinRecord[] // Coins spent in this block
|
|
165
165
|
coinSpends: CoinSpend[] // Detailed spend information
|
|
@@ -173,9 +173,9 @@ interface BlockReceivedEvent {
|
|
|
173
173
|
|
|
174
174
|
```typescript
|
|
175
175
|
interface PeerConnectedEvent {
|
|
176
|
-
peerId: string //
|
|
177
|
-
host: string
|
|
178
|
-
port: number
|
|
176
|
+
peerId: string // Peer IP address
|
|
177
|
+
host: string // Peer hostname/IP
|
|
178
|
+
port: number // Peer port number
|
|
179
179
|
}
|
|
180
180
|
```
|
|
181
181
|
|
|
@@ -183,7 +183,7 @@ interface PeerConnectedEvent {
|
|
|
183
183
|
|
|
184
184
|
```typescript
|
|
185
185
|
interface PeerDisconnectedEvent {
|
|
186
|
-
peerId: string
|
|
186
|
+
peerId: string // Peer IP address
|
|
187
187
|
host: string // Peer hostname/IP
|
|
188
188
|
port: number // Peer port number
|
|
189
189
|
message?: string // Optional disconnection reason
|
|
@@ -195,8 +195,8 @@ interface PeerDisconnectedEvent {
|
|
|
195
195
|
```typescript
|
|
196
196
|
interface CoinRecord {
|
|
197
197
|
parentCoinInfo: string // Parent coin ID (hex)
|
|
198
|
-
puzzleHash: string
|
|
199
|
-
amount: string
|
|
198
|
+
puzzleHash: string // Puzzle hash (hex)
|
|
199
|
+
amount: string // Coin amount as string
|
|
200
200
|
}
|
|
201
201
|
```
|
|
202
202
|
|
|
@@ -204,12 +204,10 @@ interface CoinRecord {
|
|
|
204
204
|
|
|
205
205
|
```typescript
|
|
206
206
|
interface CoinSpend {
|
|
207
|
-
coin: CoinRecord
|
|
207
|
+
coin: CoinRecord // The coin being spent
|
|
208
208
|
puzzleReveal: string // CLVM puzzle bytecode (hex)
|
|
209
|
-
solution: string
|
|
210
|
-
|
|
211
|
-
parsingMethod: string // Method used to parse the spend
|
|
212
|
-
offset: number // Offset in the generator bytecode
|
|
209
|
+
solution: string // CLVM solution bytecode (hex)
|
|
210
|
+
offset: number // Offset in the generator bytecode
|
|
213
211
|
}
|
|
214
212
|
```
|
|
215
213
|
|
|
@@ -238,14 +236,14 @@ listener.on('blockReceived', (block: BlockReceivedEvent) => {
|
|
|
238
236
|
console.log(`Block ${block.height} from peer ${block.peerId}`)
|
|
239
237
|
|
|
240
238
|
// Process coin additions
|
|
241
|
-
block.
|
|
239
|
+
block.coin_additions.forEach((coin: CoinRecord) => {
|
|
242
240
|
console.log(`New coin: ${coin.amount} mojos`)
|
|
243
241
|
})
|
|
244
242
|
|
|
245
243
|
// Process coin spends
|
|
246
|
-
block.
|
|
244
|
+
block.coin_spends.forEach((spend: CoinSpend) => {
|
|
247
245
|
console.log(`Spend: ${spend.coin.amount} mojos`)
|
|
248
|
-
console.log(`Puzzle: ${spend.
|
|
246
|
+
console.log(`Puzzle: ${spend.puzzle_reveal}`)
|
|
249
247
|
console.log(`Solution: ${spend.solution}`)
|
|
250
248
|
})
|
|
251
249
|
})
|
|
@@ -269,7 +267,7 @@ const testnetPeer = listener.addPeer('testnet-node.chia.net', 58444, 'testnet')
|
|
|
269
267
|
async function getHistoricalBlocks() {
|
|
270
268
|
try {
|
|
271
269
|
const block = listener.getBlockByHeight(mainnetPeer, 1000000)
|
|
272
|
-
console.log(`Block 1000000 hash: ${block.
|
|
270
|
+
console.log(`Block 1000000 hash: ${block.header_hash}`)
|
|
273
271
|
|
|
274
272
|
const blocks = listener.getBlocksRange(mainnetPeer, 1000000, 1000010)
|
|
275
273
|
console.log(`Retrieved ${blocks.length} blocks`)
|
|
@@ -292,8 +290,8 @@ console.log('Available events:', eventTypes)
|
|
|
292
290
|
listener.on('blockReceived', (block) => {
|
|
293
291
|
const targetPuzzleHash = '0x1234...' // Your puzzle hash
|
|
294
292
|
|
|
295
|
-
block.
|
|
296
|
-
if (spend.coin.
|
|
293
|
+
block.coin_spends.forEach((spend) => {
|
|
294
|
+
if (spend.coin.puzzle_hash === targetPuzzleHash) {
|
|
297
295
|
console.log('Found spend for our puzzle!')
|
|
298
296
|
console.log('Amount:', spend.coin.amount)
|
|
299
297
|
console.log('Solution:', spend.solution)
|
|
@@ -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
|
-
|
|
310
|
-
|
|
311
|
-
|
|
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
|
-
|
|
328
|
-
|
|
329
|
-
|
|
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:
|
|
334
|
-
puzzle_hash:
|
|
364
|
+
parent_coin_info: parent_hex,
|
|
365
|
+
puzzle_hash: puzzle_hash_hex,
|
|
335
366
|
amount,
|
|
336
367
|
};
|
|
337
368
|
|
package/examples/coin-monitor.js
CHANGED
|
@@ -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 =
|
|
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
|
});
|
package/index.d.ts
CHANGED
|
@@ -42,8 +42,6 @@ export interface CoinSpend {
|
|
|
42
42
|
coin: CoinRecord
|
|
43
43
|
puzzleReveal: string
|
|
44
44
|
solution: string
|
|
45
|
-
realData: boolean
|
|
46
|
-
parsingMethod: string
|
|
47
45
|
offset: number
|
|
48
46
|
}
|
|
49
47
|
export declare function initTracing(): void
|
|
@@ -53,21 +51,7 @@ export declare class ChiaBlockListener {
|
|
|
53
51
|
disconnectPeer(peerId: string): boolean
|
|
54
52
|
disconnectAllPeers(): void
|
|
55
53
|
getConnectedPeers(): Array<string>
|
|
56
|
-
// Typed event method overloads
|
|
57
|
-
|
|
58
|
-
on(event: 'blockReceived', callback: (event: BlockReceivedEvent) => void): void
|
|
59
|
-
|
|
60
|
-
on(event: 'peerConnected', callback: (event: PeerConnectedEvent) => void): void
|
|
61
|
-
|
|
62
|
-
on(event: 'peerDisconnected', callback: (event: PeerDisconnectedEvent) => void): void
|
|
63
|
-
|
|
64
54
|
on(event: string, callback: (...args: any[]) => any): void
|
|
65
|
-
off(event: 'blockReceived', callback: (event: BlockReceivedEvent) => void): void
|
|
66
|
-
|
|
67
|
-
off(event: 'peerConnected', callback: (event: PeerConnectedEvent) => void): void
|
|
68
|
-
|
|
69
|
-
off(event: 'peerDisconnected', callback: (event: PeerDisconnectedEvent) => void): void
|
|
70
|
-
|
|
71
55
|
off(event: string, callback: (...args: any[]) => any): void
|
|
72
56
|
getBlockByHeight(peerId: string, height: number): BlockReceivedEvent
|
|
73
57
|
getBlocksRange(peerId: string, startHeight: number, endHeight: number): Array<BlockReceivedEvent>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dignetwork/chia-block-listener",
|
|
3
|
-
"version": "0.1.
|
|
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.
|
|
62
|
-
"@dignetwork/chia-block-listener-darwin-x64": "0.1.
|
|
63
|
-
"@dignetwork/chia-block-listener-linux-x64-gnu": "0.1.
|
|
64
|
-
"@dignetwork/chia-block-listener-darwin-arm64": "0.1.
|
|
65
|
-
"@dignetwork/chia-block-listener-linux-arm64-gnu": "0.1.
|
|
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
|
}
|
package/scripts/post-build.js
CHANGED
|
@@ -3,11 +3,25 @@ const path = require('path');
|
|
|
3
3
|
|
|
4
4
|
const indexDtsPath = path.join(__dirname, '..', 'index.d.ts');
|
|
5
5
|
|
|
6
|
-
function
|
|
6
|
+
function fixFieldNames() {
|
|
7
7
|
try {
|
|
8
8
|
// Read the auto-generated index.d.ts file
|
|
9
9
|
let content = fs.readFileSync(indexDtsPath, 'utf8');
|
|
10
10
|
|
|
11
|
+
console.log('✅ Field names should now be camelCase from NAPI js_name attributes');
|
|
12
|
+
return content;
|
|
13
|
+
|
|
14
|
+
} catch (error) {
|
|
15
|
+
console.error('❌ Error fixing field names:', error.message);
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function addTypedOverloads() {
|
|
21
|
+
try {
|
|
22
|
+
// Read the auto-generated index.d.ts file (or use fixed content from field name correction)
|
|
23
|
+
let content = fixFieldNames();
|
|
24
|
+
|
|
11
25
|
// Check if typed overloads are already present (avoid duplicates)
|
|
12
26
|
if (content.includes('Typed event method overloads')) {
|
|
13
27
|
console.log('✅ Typed event method overloads already present in index.d.ts');
|
package/src/event_emitter.rs
CHANGED
|
@@ -83,6 +83,7 @@ enum PeerEventType {
|
|
|
83
83
|
#[napi(object)]
|
|
84
84
|
#[derive(Clone)]
|
|
85
85
|
pub struct PeerConnectedEvent {
|
|
86
|
+
#[napi(js_name = "peerId")]
|
|
86
87
|
pub peer_id: String,
|
|
87
88
|
pub host: String,
|
|
88
89
|
pub port: u32,
|
|
@@ -92,6 +93,7 @@ pub struct PeerConnectedEvent {
|
|
|
92
93
|
#[napi(object)]
|
|
93
94
|
#[derive(Clone)]
|
|
94
95
|
pub struct PeerDisconnectedEvent {
|
|
96
|
+
#[napi(js_name = "peerId")]
|
|
95
97
|
pub peer_id: String,
|
|
96
98
|
pub host: String,
|
|
97
99
|
pub port: u32,
|
|
@@ -102,23 +104,33 @@ pub struct PeerDisconnectedEvent {
|
|
|
102
104
|
#[napi(object)]
|
|
103
105
|
#[derive(Clone)]
|
|
104
106
|
pub struct BlockReceivedEvent {
|
|
107
|
+
#[napi(js_name = "peerId")]
|
|
105
108
|
pub peer_id: String,
|
|
106
109
|
pub height: u32,
|
|
107
110
|
pub weight: String,
|
|
111
|
+
#[napi(js_name = "headerHash")]
|
|
108
112
|
pub header_hash: String,
|
|
109
113
|
pub timestamp: u32,
|
|
114
|
+
#[napi(js_name = "coinAdditions")]
|
|
110
115
|
pub coin_additions: Vec<CoinRecord>,
|
|
116
|
+
#[napi(js_name = "coinRemovals")]
|
|
111
117
|
pub coin_removals: Vec<CoinRecord>,
|
|
118
|
+
#[napi(js_name = "coinSpends")]
|
|
112
119
|
pub coin_spends: Vec<CoinSpend>,
|
|
120
|
+
#[napi(js_name = "coinCreations")]
|
|
113
121
|
pub coin_creations: Vec<CoinRecord>,
|
|
122
|
+
#[napi(js_name = "hasTransactionsGenerator")]
|
|
114
123
|
pub has_transactions_generator: bool,
|
|
124
|
+
#[napi(js_name = "generatorSize")]
|
|
115
125
|
pub generator_size: u32,
|
|
116
126
|
}
|
|
117
127
|
|
|
118
128
|
#[napi(object)]
|
|
119
129
|
#[derive(Clone)]
|
|
120
130
|
pub struct CoinRecord {
|
|
131
|
+
#[napi(js_name = "parentCoinInfo")]
|
|
121
132
|
pub parent_coin_info: String,
|
|
133
|
+
#[napi(js_name = "puzzleHash")]
|
|
122
134
|
pub puzzle_hash: String,
|
|
123
135
|
pub amount: String,
|
|
124
136
|
}
|
|
@@ -127,10 +139,9 @@ pub struct CoinRecord {
|
|
|
127
139
|
#[derive(Clone)]
|
|
128
140
|
pub struct CoinSpend {
|
|
129
141
|
pub coin: CoinRecord,
|
|
142
|
+
#[napi(js_name = "puzzleReveal")]
|
|
130
143
|
pub puzzle_reveal: String,
|
|
131
144
|
pub solution: String,
|
|
132
|
-
pub real_data: bool,
|
|
133
|
-
pub parsing_method: String,
|
|
134
145
|
pub offset: u32,
|
|
135
146
|
}
|
|
136
147
|
|
|
@@ -241,7 +252,7 @@ impl ChiaBlockListener {
|
|
|
241
252
|
|
|
242
253
|
let peer_id = rt.block_on(async {
|
|
243
254
|
let mut guard = inner.write().await;
|
|
244
|
-
let peer_id =
|
|
255
|
+
let peer_id = host.clone();
|
|
245
256
|
|
|
246
257
|
guard.peers.insert(
|
|
247
258
|
peer_id.clone(),
|
|
@@ -331,7 +342,7 @@ impl ChiaBlockListener {
|
|
|
331
342
|
obj.set_named_property("height", ctx.env.create_uint32(event.height)?)?;
|
|
332
343
|
obj.set_named_property("weight", ctx.env.create_string(&event.weight)?)?;
|
|
333
344
|
obj.set_named_property(
|
|
334
|
-
"
|
|
345
|
+
"headerHash",
|
|
335
346
|
ctx.env.create_string(&event.header_hash)?,
|
|
336
347
|
)?;
|
|
337
348
|
obj.set_named_property("timestamp", ctx.env.create_uint32(event.timestamp)?)?;
|
|
@@ -343,11 +354,11 @@ impl ChiaBlockListener {
|
|
|
343
354
|
for (i, coin) in event.coin_additions.iter().enumerate() {
|
|
344
355
|
let mut coin_obj = ctx.env.create_object()?;
|
|
345
356
|
coin_obj.set_named_property(
|
|
346
|
-
"
|
|
357
|
+
"parentCoinInfo",
|
|
347
358
|
ctx.env.create_string(&coin.parent_coin_info)?,
|
|
348
359
|
)?;
|
|
349
360
|
coin_obj.set_named_property(
|
|
350
|
-
"
|
|
361
|
+
"puzzleHash",
|
|
351
362
|
ctx.env.create_string(&coin.puzzle_hash)?,
|
|
352
363
|
)?;
|
|
353
364
|
coin_obj.set_named_property(
|
|
@@ -356,7 +367,7 @@ impl ChiaBlockListener {
|
|
|
356
367
|
)?;
|
|
357
368
|
additions_array.set_element(i as u32, coin_obj)?;
|
|
358
369
|
}
|
|
359
|
-
obj.set_named_property("
|
|
370
|
+
obj.set_named_property("coinAdditions", additions_array)?;
|
|
360
371
|
|
|
361
372
|
// Coin removals array
|
|
362
373
|
let mut removals_array = ctx
|
|
@@ -365,11 +376,11 @@ impl ChiaBlockListener {
|
|
|
365
376
|
for (i, coin) in event.coin_removals.iter().enumerate() {
|
|
366
377
|
let mut coin_obj = ctx.env.create_object()?;
|
|
367
378
|
coin_obj.set_named_property(
|
|
368
|
-
"
|
|
379
|
+
"parentCoinInfo",
|
|
369
380
|
ctx.env.create_string(&coin.parent_coin_info)?,
|
|
370
381
|
)?;
|
|
371
382
|
coin_obj.set_named_property(
|
|
372
|
-
"
|
|
383
|
+
"puzzleHash",
|
|
373
384
|
ctx.env.create_string(&coin.puzzle_hash)?,
|
|
374
385
|
)?;
|
|
375
386
|
coin_obj.set_named_property(
|
|
@@ -378,7 +389,7 @@ impl ChiaBlockListener {
|
|
|
378
389
|
)?;
|
|
379
390
|
removals_array.set_element(i as u32, coin_obj)?;
|
|
380
391
|
}
|
|
381
|
-
obj.set_named_property("
|
|
392
|
+
obj.set_named_property("coinRemovals", removals_array)?;
|
|
382
393
|
|
|
383
394
|
// Coin spends array
|
|
384
395
|
let mut spends_array =
|
|
@@ -389,11 +400,11 @@ impl ChiaBlockListener {
|
|
|
389
400
|
// Create coin object
|
|
390
401
|
let mut coin_obj = ctx.env.create_object()?;
|
|
391
402
|
coin_obj.set_named_property(
|
|
392
|
-
"
|
|
403
|
+
"parentCoinInfo",
|
|
393
404
|
ctx.env.create_string(&spend.coin.parent_coin_info)?,
|
|
394
405
|
)?;
|
|
395
406
|
coin_obj.set_named_property(
|
|
396
|
-
"
|
|
407
|
+
"puzzleHash",
|
|
397
408
|
ctx.env.create_string(&spend.coin.puzzle_hash)?,
|
|
398
409
|
)?;
|
|
399
410
|
coin_obj.set_named_property(
|
|
@@ -403,27 +414,20 @@ impl ChiaBlockListener {
|
|
|
403
414
|
spend_obj.set_named_property("coin", coin_obj)?;
|
|
404
415
|
|
|
405
416
|
spend_obj.set_named_property(
|
|
406
|
-
"
|
|
417
|
+
"puzzleReveal",
|
|
407
418
|
ctx.env.create_string(&spend.puzzle_reveal)?,
|
|
408
419
|
)?;
|
|
409
420
|
spend_obj.set_named_property(
|
|
410
421
|
"solution",
|
|
411
422
|
ctx.env.create_string(&spend.solution)?,
|
|
412
423
|
)?;
|
|
413
|
-
|
|
414
|
-
"real_data",
|
|
415
|
-
ctx.env.get_boolean(spend.real_data)?,
|
|
416
|
-
)?;
|
|
417
|
-
spend_obj.set_named_property(
|
|
418
|
-
"parsing_method",
|
|
419
|
-
ctx.env.create_string(&spend.parsing_method)?,
|
|
420
|
-
)?;
|
|
424
|
+
|
|
421
425
|
spend_obj
|
|
422
426
|
.set_named_property("offset", ctx.env.create_uint32(spend.offset)?)?;
|
|
423
427
|
|
|
424
428
|
spends_array.set_element(i as u32, spend_obj)?;
|
|
425
429
|
}
|
|
426
|
-
obj.set_named_property("
|
|
430
|
+
obj.set_named_property("coinSpends", spends_array)?;
|
|
427
431
|
|
|
428
432
|
// Coin creations array
|
|
429
433
|
let mut creations_array = ctx
|
|
@@ -432,25 +436,25 @@ impl ChiaBlockListener {
|
|
|
432
436
|
for (i, coin) in event.coin_creations.iter().enumerate() {
|
|
433
437
|
let mut coin_obj = ctx.env.create_object()?;
|
|
434
438
|
coin_obj.set_named_property(
|
|
435
|
-
"
|
|
439
|
+
"parentCoinInfo",
|
|
436
440
|
ctx.env.create_string(&coin.parent_coin_info)?,
|
|
437
441
|
)?;
|
|
438
442
|
coin_obj.set_named_property(
|
|
439
|
-
"
|
|
443
|
+
"puzzleHash",
|
|
440
444
|
ctx.env.create_string(&coin.puzzle_hash)?,
|
|
441
445
|
)?;
|
|
442
446
|
coin_obj
|
|
443
447
|
.set_named_property("amount", ctx.env.create_string(&coin.amount)?)?;
|
|
444
448
|
creations_array.set_element(i as u32, coin_obj)?;
|
|
445
449
|
}
|
|
446
|
-
obj.set_named_property("
|
|
450
|
+
obj.set_named_property("coinCreations", creations_array)?;
|
|
447
451
|
|
|
448
452
|
obj.set_named_property(
|
|
449
|
-
"
|
|
453
|
+
"hasTransactionsGenerator",
|
|
450
454
|
ctx.env.get_boolean(event.has_transactions_generator)?,
|
|
451
455
|
)?;
|
|
452
456
|
obj.set_named_property(
|
|
453
|
-
"
|
|
457
|
+
"generatorSize",
|
|
454
458
|
ctx.env.create_uint32(event.generator_size)?,
|
|
455
459
|
)?;
|
|
456
460
|
|
|
@@ -703,14 +707,14 @@ impl ChiaBlockListener {
|
|
|
703
707
|
peer_id,
|
|
704
708
|
height: parsed_block.height,
|
|
705
709
|
weight: parsed_block.weight.clone(),
|
|
706
|
-
header_hash:
|
|
710
|
+
header_hash: parsed_block.header_hash.clone(),
|
|
707
711
|
timestamp: parsed_block.timestamp.unwrap_or(0),
|
|
708
712
|
coin_additions: parsed_block
|
|
709
713
|
.coin_additions
|
|
710
714
|
.iter()
|
|
711
715
|
.map(|coin| CoinRecord {
|
|
712
|
-
parent_coin_info:
|
|
713
|
-
puzzle_hash:
|
|
716
|
+
parent_coin_info: coin.parent_coin_info.clone(),
|
|
717
|
+
puzzle_hash: coin.puzzle_hash.clone(),
|
|
714
718
|
amount: coin.amount.to_string(),
|
|
715
719
|
})
|
|
716
720
|
.collect(),
|
|
@@ -718,8 +722,8 @@ impl ChiaBlockListener {
|
|
|
718
722
|
.coin_removals
|
|
719
723
|
.iter()
|
|
720
724
|
.map(|coin| CoinRecord {
|
|
721
|
-
parent_coin_info:
|
|
722
|
-
puzzle_hash:
|
|
725
|
+
parent_coin_info: coin.parent_coin_info.clone(),
|
|
726
|
+
puzzle_hash: coin.puzzle_hash.clone(),
|
|
723
727
|
amount: coin.amount.to_string(),
|
|
724
728
|
})
|
|
725
729
|
.collect(),
|
|
@@ -728,14 +732,12 @@ impl ChiaBlockListener {
|
|
|
728
732
|
.iter()
|
|
729
733
|
.map(|spend| CoinSpend {
|
|
730
734
|
coin: CoinRecord {
|
|
731
|
-
parent_coin_info:
|
|
732
|
-
puzzle_hash:
|
|
735
|
+
parent_coin_info: spend.coin.parent_coin_info.clone(),
|
|
736
|
+
puzzle_hash: spend.coin.puzzle_hash.clone(),
|
|
733
737
|
amount: spend.coin.amount.to_string(),
|
|
734
738
|
},
|
|
735
739
|
puzzle_reveal: hex::encode(&spend.puzzle_reveal),
|
|
736
740
|
solution: hex::encode(&spend.solution),
|
|
737
|
-
real_data: spend.real_data,
|
|
738
|
-
parsing_method: spend.parsing_method.clone(),
|
|
739
741
|
offset: spend.offset,
|
|
740
742
|
})
|
|
741
743
|
.collect(),
|
|
@@ -743,8 +745,8 @@ impl ChiaBlockListener {
|
|
|
743
745
|
.coin_creations
|
|
744
746
|
.iter()
|
|
745
747
|
.map(|coin| CoinRecord {
|
|
746
|
-
parent_coin_info:
|
|
747
|
-
puzzle_hash:
|
|
748
|
+
parent_coin_info: coin.parent_coin_info.clone(),
|
|
749
|
+
puzzle_hash: coin.puzzle_hash.clone(),
|
|
748
750
|
amount: coin.amount.to_string(),
|
|
749
751
|
})
|
|
750
752
|
.collect(),
|