Skip to content

Commit c1755cb

Browse files
author
Michael Taylor
committed
0.1.8
1 parent 6fb3358 commit c1755cb

11 files changed

Lines changed: 78 additions & 79 deletions

File tree

.github/workflows/CI.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,13 @@ jobs:
251251
- name: Setup and run tests
252252
uses: addnab/docker-run-action@v3
253253
with:
254-
image: ubuntu:24.04
254+
image: debian:bookworm
255255
options: '--platform linux/arm64 -v ${{ github.workspace }}:/build -w /build'
256256
run: |
257257
set -e
258+
export DEBIAN_FRONTEND=noninteractive
258259
apt-get update
259-
apt-get install -y curl
260+
apt-get install -y curl ca-certificates gnupg
260261
curl -fsSL https://deb.nodesource.com/setup_${{ matrix.node }}.x | bash -
261262
apt-get install -y nodejs
262263
node --version

README.md

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ const listener = new ChiaBlockListener()
3333
// Listen for block events
3434
listener.on('blockReceived', (block) => {
3535
console.log(`New block received: ${block.height}`)
36-
console.log(`Header hash: ${block.headerHash}`)
36+
console.log(`Header hash: ${block.header_hash}`)
3737
console.log(`Timestamp: ${new Date(block.timestamp * 1000)}`)
38-
console.log(`Coin additions: ${block.coinAdditions.length}`)
39-
console.log(`Coin removals: ${block.coinRemovals.length}`)
40-
console.log(`Coin spends: ${block.coinSpends.length}`)
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}`)
4141
})
4242

4343
// Listen for peer connection events
@@ -155,11 +155,11 @@ Fired when a peer connection is lost.
155155

156156
```typescript
157157
interface BlockReceivedEvent {
158-
peerId: string // ID of the peer that sent this block
159-
height: number // Block height
160-
weight: string // Block weight as 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
161161
headerHash: string // Block header hash (hex)
162-
timestamp: number // Block timestamp (Unix time)
162+
timestamp: number // Block timestamp (Unix time)
163163
coinAdditions: CoinRecord[] // New coins created in this block
164164
coinRemovals: CoinRecord[] // Coins spent in this block
165165
coinSpends: CoinSpend[] // Detailed spend information
@@ -173,17 +173,17 @@ interface BlockReceivedEvent {
173173

174174
```typescript
175175
interface PeerConnectedEvent {
176-
peerId: string // Unique peer identifier
177-
host: string // Peer hostname/IP
178-
port: number // Peer port number
176+
peerId: string // Peer IP address
177+
host: string // Peer hostname/IP
178+
port: number // Peer port number
179179
}
180180
```
181181

182182
#### `PeerDisconnectedEvent`
183183

184184
```typescript
185185
interface PeerDisconnectedEvent {
186-
peerId: string // Unique peer identifier
186+
peerId: string // Peer IP address
187187
host: string // Peer hostname/IP
188188
port: number // Peer port number
189189
message?: string // Optional disconnection reason
@@ -195,21 +195,19 @@ interface PeerDisconnectedEvent {
195195
```typescript
196196
interface CoinRecord {
197197
parentCoinInfo: string // Parent coin ID (hex)
198-
puzzleHash: string // Puzzle hash (hex)
199-
amount: string // Coin amount as string
198+
puzzleHash: string // Puzzle hash (hex)
199+
amount: string // Coin amount as string
200200
}
201201
```
202202

203203
#### `CoinSpend`
204204

205205
```typescript
206206
interface CoinSpend {
207-
coin: CoinRecord // The coin being spent
207+
coin: CoinRecord // The coin being spent
208208
puzzleReveal: string // CLVM puzzle bytecode (hex)
209-
solution: string // CLVM solution bytecode (hex)
210-
realData: boolean // Whether this is real spend data
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
213211
}
214212
```
215213

@@ -238,14 +236,14 @@ listener.on('blockReceived', (block: BlockReceivedEvent) => {
238236
console.log(`Block ${block.height} from peer ${block.peerId}`)
239237

240238
// Process coin additions
241-
block.coinAdditions.forEach((coin: CoinRecord) => {
239+
block.coin_additions.forEach((coin: CoinRecord) => {
242240
console.log(`New coin: ${coin.amount} mojos`)
243241
})
244242

245243
// Process coin spends
246-
block.coinSpends.forEach((spend: CoinSpend) => {
244+
block.coin_spends.forEach((spend: CoinSpend) => {
247245
console.log(`Spend: ${spend.coin.amount} mojos`)
248-
console.log(`Puzzle: ${spend.puzzleReveal}`)
246+
console.log(`Puzzle: ${spend.puzzle_reveal}`)
249247
console.log(`Solution: ${spend.solution}`)
250248
})
251249
})
@@ -269,7 +267,7 @@ const testnetPeer = listener.addPeer('testnet-node.chia.net', 58444, 'testnet')
269267
async function getHistoricalBlocks() {
270268
try {
271269
const block = listener.getBlockByHeight(mainnetPeer, 1000000)
272-
console.log(`Block 1000000 hash: ${block.headerHash}`)
270+
console.log(`Block 1000000 hash: ${block.header_hash}`)
273271

274272
const blocks = listener.getBlocksRange(mainnetPeer, 1000000, 1000010)
275273
console.log(`Retrieved ${blocks.length} blocks`)
@@ -292,8 +290,8 @@ console.log('Available events:', eventTypes)
292290
listener.on('blockReceived', (block) => {
293291
const targetPuzzleHash = '0x1234...' // Your puzzle hash
294292

295-
block.coinSpends.forEach((spend) => {
296-
if (spend.coin.puzzleHash === targetPuzzleHash) {
293+
block.coin_spends.forEach((spend) => {
294+
if (spend.coin.puzzle_hash === targetPuzzleHash) {
297295
console.log('Found spend for our puzzle!')
298296
console.log('Amount:', spend.coin.amount)
299297
console.log('Solution:', spend.solution)

index.d.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ export interface CoinSpend {
4242
coin: CoinRecord
4343
puzzleReveal: string
4444
solution: string
45-
realData: boolean
46-
parsingMethod: string
4745
offset: number
4846
}
4947
export declare function initTracing(): void
@@ -53,21 +51,7 @@ export declare class ChiaBlockListener {
5351
disconnectPeer(peerId: string): boolean
5452
disconnectAllPeers(): void
5553
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-
6454
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-
7155
off(event: string, callback: (...args: any[]) => any): void
7256
getBlockByHeight(peerId: string, height: number): BlockReceivedEvent
7357
getBlocksRange(peerId: string, startHeight: number, endHeight: number): Array<BlockReceivedEvent>

npm/darwin-arm64/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dignetwork/chia-block-listener-darwin-arm64",
3-
"version": "0.1.7",
3+
"version": "0.1.8",
44
"repository": {
55
"type": "git",
66
"url": "https://github.com/DIG-Network/chia-block-listener"

npm/darwin-x64/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dignetwork/chia-block-listener-darwin-x64",
3-
"version": "0.1.7",
3+
"version": "0.1.8",
44
"repository": {
55
"type": "git",
66
"url": "https://github.com/DIG-Network/chia-block-listener"

npm/linux-arm64-gnu/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dignetwork/chia-block-listener-linux-arm64-gnu",
3-
"version": "0.1.7",
3+
"version": "0.1.8",
44
"repository": {
55
"type": "git",
66
"url": "https://github.com/DIG-Network/chia-block-listener"

npm/linux-x64-gnu/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dignetwork/chia-block-listener-linux-x64-gnu",
3-
"version": "0.1.7",
3+
"version": "0.1.8",
44
"repository": {
55
"type": "git",
66
"url": "https://github.com/DIG-Network/chia-block-listener"

npm/win32-x64-msvc/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dignetwork/chia-block-listener-win32-x64-msvc",
3-
"version": "0.1.7",
3+
"version": "0.1.8",
44
"repository": {
55
"type": "git",
66
"url": "https://github.com/DIG-Network/chia-block-listener"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dignetwork/chia-block-listener",
3-
"version": "0.1.7",
3+
"version": "0.1.8",
44
"main": "index.js",
55
"types": "index.d.ts",
66
"repository": {

scripts/post-build.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,25 @@ const path = require('path');
33

44
const indexDtsPath = path.join(__dirname, '..', 'index.d.ts');
55

6-
function addTypedOverloads() {
6+
function fixFieldNames() {
77
try {
88
// Read the auto-generated index.d.ts file
99
let content = fs.readFileSync(indexDtsPath, 'utf8');
1010

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+
1125
// Check if typed overloads are already present (avoid duplicates)
1226
if (content.includes('Typed event method overloads')) {
1327
console.log('✅ Typed event method overloads already present in index.d.ts');

0 commit comments

Comments
 (0)