@dignetwork/chia-block-listener 0.1.17 → 0.1.19
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 +74 -0
- package/.github/workflows/release.yml +227 -0
- package/Cargo.toml +19 -14
- package/README.md +514 -0
- package/crate/chia-block-listener-napi/Cargo.toml +23 -0
- package/crate/chia-block-listener-napi/src/block_parser_napi.rs +259 -0
- package/{src → crate/chia-block-listener-napi/src}/dns_discovery_napi.rs +17 -38
- package/crate/chia-block-listener-napi/src/event_emitter.rs +582 -0
- package/crate/chia-block-listener-napi/src/lib.rs +30 -0
- package/{src → crate/chia-block-listener-napi/src}/peer_pool_napi.rs +122 -48
- package/crate/chia-generator-parser/Cargo.toml +1 -5
- package/crate/chia-generator-parser/examples/basic_usage.rs +2 -2
- package/crate/chia-generator-parser/src/lib.rs +7 -0
- package/crate/chia-generator-parser/src/parser.rs +148 -26
- package/crate/chia-generator-parser/src/types.rs +23 -3
- package/crate/{dns-discovery → dig-dns-discovery}/Cargo.toml +17 -15
- package/crate/{dns-discovery → dig-dns-discovery}/README.md +150 -150
- package/crate/{dns-discovery → dig-dns-discovery}/examples/discover_peers.rs +8 -9
- package/crate/{dns-discovery → dig-dns-discovery}/package-lock.json +2382 -2382
- package/crate/{dns-discovery → dig-dns-discovery}/src/lib.rs +10 -10
- package/examples/block-parser-example.mjs +55 -0
- package/index.d.ts +49 -5
- package/index.js +2 -1
- 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 +11 -11
- package/src/block_listener.rs +268 -0
- package/src/dns_discovery.rs +66 -0
- package/src/error.rs +0 -6
- package/src/lib.rs +12 -14
- package/src/peer.rs +47 -21
- package/src/peer_pool.rs +326 -104
- package/src/protocol.rs +5 -6
- package/src/types.rs +83 -0
- package/.github/workflows/CI.yml +0 -340
- package/crate/chia-generator-parser/examples/production_test.rs +0 -147
- package/src/event_emitter.rs +0 -848
- /package/{build.rs → crate/chia-block-listener-napi/build.rs} +0 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ main ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ main ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
rust-checks:
|
|
11
|
+
name: Rust checks (fmt, clippy)
|
|
12
|
+
runs-on: ubuntu-22.04
|
|
13
|
+
steps:
|
|
14
|
+
- name: Checkout
|
|
15
|
+
uses: actions/checkout@v4
|
|
16
|
+
|
|
17
|
+
- name: Setup Rust
|
|
18
|
+
uses: dtolnay/rust-toolchain@stable
|
|
19
|
+
|
|
20
|
+
- name: Cache cargo
|
|
21
|
+
uses: actions/cache@v4
|
|
22
|
+
with:
|
|
23
|
+
path: |
|
|
24
|
+
~/.cargo/registry
|
|
25
|
+
~/.cargo/git
|
|
26
|
+
target
|
|
27
|
+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
|
28
|
+
|
|
29
|
+
- name: Format check
|
|
30
|
+
run: cargo fmt --all -- --check
|
|
31
|
+
|
|
32
|
+
- name: Clippy
|
|
33
|
+
run: cargo clippy --workspace --all-targets -- -D warnings
|
|
34
|
+
|
|
35
|
+
build:
|
|
36
|
+
name: Build (${{ matrix.os }})
|
|
37
|
+
needs: rust-checks
|
|
38
|
+
runs-on: ${{ matrix.os }}
|
|
39
|
+
strategy:
|
|
40
|
+
fail-fast: false
|
|
41
|
+
matrix:
|
|
42
|
+
os: [ubuntu-22.04, macos-14, windows-latest]
|
|
43
|
+
steps:
|
|
44
|
+
- name: Checkout
|
|
45
|
+
uses: actions/checkout@v4
|
|
46
|
+
|
|
47
|
+
- name: Setup Node.js
|
|
48
|
+
uses: actions/setup-node@v4
|
|
49
|
+
with:
|
|
50
|
+
node-version: 22
|
|
51
|
+
|
|
52
|
+
- name: Setup Rust
|
|
53
|
+
uses: dtolnay/rust-toolchain@stable
|
|
54
|
+
|
|
55
|
+
- name: Cache cargo
|
|
56
|
+
uses: actions/cache@v4
|
|
57
|
+
with:
|
|
58
|
+
path: |
|
|
59
|
+
~/.cargo/registry
|
|
60
|
+
~/.cargo/git
|
|
61
|
+
target
|
|
62
|
+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
|
63
|
+
|
|
64
|
+
- name: Install yarn
|
|
65
|
+
run: corepack enable && corepack prepare yarn@1.22.22 --activate
|
|
66
|
+
|
|
67
|
+
- name: Install @napi-rs/cli
|
|
68
|
+
run: yarn global add @napi-rs/cli@^2.18.4
|
|
69
|
+
|
|
70
|
+
- name: Install deps
|
|
71
|
+
run: yarn install --frozen-lockfile
|
|
72
|
+
|
|
73
|
+
- name: Build NAPI addon
|
|
74
|
+
run: yarn build
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
publish-crates:
|
|
10
|
+
name: Publish crates to crates.io
|
|
11
|
+
runs-on: ubuntu-22.04
|
|
12
|
+
steps:
|
|
13
|
+
- name: Checkout
|
|
14
|
+
uses: actions/checkout@v4
|
|
15
|
+
|
|
16
|
+
- name: Setup Rust
|
|
17
|
+
uses: dtolnay/rust-toolchain@stable
|
|
18
|
+
with:
|
|
19
|
+
components: rustfmt, clippy
|
|
20
|
+
|
|
21
|
+
- name: Cache cargo
|
|
22
|
+
uses: actions/cache@v4
|
|
23
|
+
with:
|
|
24
|
+
path: |
|
|
25
|
+
~/.cargo/registry
|
|
26
|
+
~/.cargo/git
|
|
27
|
+
target
|
|
28
|
+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
|
29
|
+
|
|
30
|
+
- name: Install curl + python3
|
|
31
|
+
run: |
|
|
32
|
+
sudo apt-get update
|
|
33
|
+
sudo apt-get install -y curl python3
|
|
34
|
+
|
|
35
|
+
# Enforce the same quality gates as CI for the crates you publish.
|
|
36
|
+
- name: Rust fmt check (published crates)
|
|
37
|
+
run: cargo fmt --all -- --check
|
|
38
|
+
|
|
39
|
+
- name: Rust clippy (published crates)
|
|
40
|
+
run: |
|
|
41
|
+
cargo clippy \
|
|
42
|
+
-p dig-dns-discovery \
|
|
43
|
+
-p chia-generator-parser \
|
|
44
|
+
-p chia-block-listener \
|
|
45
|
+
--all-targets \
|
|
46
|
+
-- -D warnings
|
|
47
|
+
|
|
48
|
+
- name: Cargo login
|
|
49
|
+
env:
|
|
50
|
+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
|
|
51
|
+
run: cargo login "$CARGO_REGISTRY_TOKEN"
|
|
52
|
+
|
|
53
|
+
- name: Publish dig-dns-discovery (dry-run + if needed)
|
|
54
|
+
env:
|
|
55
|
+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
|
|
56
|
+
working-directory: ./crate/dig-dns-discovery
|
|
57
|
+
shell: bash
|
|
58
|
+
run: |
|
|
59
|
+
set -euo pipefail
|
|
60
|
+
CRATE="dig-dns-discovery"
|
|
61
|
+
VER="$(cargo metadata --no-deps --format-version 1 | python3 -c 'import sys, json; print(json.load(sys.stdin)["packages"][0]["version"])')"
|
|
62
|
+
echo "Crate: ${CRATE} Version: ${VER}"
|
|
63
|
+
|
|
64
|
+
# Validate publish packaging/build without uploading
|
|
65
|
+
cargo publish --dry-run
|
|
66
|
+
|
|
67
|
+
CODE="$(curl -s -o /dev/null -w "%{http_code}" "https://crates.io/api/v1/crates/${CRATE}/${VER}" || true)"
|
|
68
|
+
if [ "$CODE" = "200" ]; then
|
|
69
|
+
echo "Already published: ${CRATE} ${VER} (skipping upload)."
|
|
70
|
+
exit 0
|
|
71
|
+
fi
|
|
72
|
+
|
|
73
|
+
cargo publish --no-verify
|
|
74
|
+
|
|
75
|
+
- name: Publish chia-generator-parser (dry-run + if needed)
|
|
76
|
+
env:
|
|
77
|
+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
|
|
78
|
+
working-directory: ./crate/chia-generator-parser
|
|
79
|
+
shell: bash
|
|
80
|
+
run: |
|
|
81
|
+
set -euo pipefail
|
|
82
|
+
CRATE="chia-generator-parser"
|
|
83
|
+
VER="$(cargo metadata --no-deps --format-version 1 | python3 -c 'import sys, json; print(json.load(sys.stdin)["packages"][0]["version"])')"
|
|
84
|
+
echo "Crate: ${CRATE} Version: ${VER}"
|
|
85
|
+
|
|
86
|
+
cargo publish --dry-run
|
|
87
|
+
|
|
88
|
+
CODE="$(curl -s -o /dev/null -w "%{http_code}" "https://crates.io/api/v1/crates/${CRATE}/${VER}" || true)"
|
|
89
|
+
if [ "$CODE" = "200" ]; then
|
|
90
|
+
echo "Already published: ${CRATE} ${VER} (skipping upload)."
|
|
91
|
+
exit 0
|
|
92
|
+
fi
|
|
93
|
+
|
|
94
|
+
cargo publish --no-verify
|
|
95
|
+
|
|
96
|
+
# Reduce flakiness: ensure the dependency versions are visible before publishing chia-block-listener.
|
|
97
|
+
- name: Wait for crates.io visibility (dig-dns-discovery + chia-generator-parser)
|
|
98
|
+
shell: bash
|
|
99
|
+
run: |
|
|
100
|
+
set -euo pipefail
|
|
101
|
+
DIG_VER="$(cargo metadata --no-deps --format-version 1 | python3 -c 'import sys, json; print(json.load(sys.stdin)["packages"][0]["version"])')"
|
|
102
|
+
PAR_VER="$(cargo metadata --no-deps --format-version 1 | python3 -c 'import sys, json; print(json.load(sys.stdin)["packages"][0]["version"])')"
|
|
103
|
+
|
|
104
|
+
check() {
|
|
105
|
+
local crate="$1" ver="$2"
|
|
106
|
+
curl -s -o /dev/null -w "%{http_code}" "https://crates.io/api/v1/crates/${crate}/${ver}" || true
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
for i in {1..24}; do
|
|
110
|
+
A="$(check dig-dns-discovery "$DIG_VER")"
|
|
111
|
+
B="$(check chia-generator-parser "$PAR_VER")"
|
|
112
|
+
if [ "$A" = "200" ] && [ "$B" = "200" ]; then
|
|
113
|
+
echo "Deps visible on crates.io."
|
|
114
|
+
exit 0
|
|
115
|
+
fi
|
|
116
|
+
echo "Waiting for crates.io visibility... (${i}/24)"
|
|
117
|
+
sleep 5
|
|
118
|
+
done
|
|
119
|
+
|
|
120
|
+
echo "Timed out waiting for dependency crates to be visible on crates.io."
|
|
121
|
+
exit 1
|
|
122
|
+
|
|
123
|
+
- name: Publish chia-block-listener (dry-run + if needed)
|
|
124
|
+
env:
|
|
125
|
+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
|
|
126
|
+
working-directory: .
|
|
127
|
+
shell: bash
|
|
128
|
+
run: |
|
|
129
|
+
set -euo pipefail
|
|
130
|
+
CRATE="chia-block-listener"
|
|
131
|
+
VER="$(cargo metadata --no-deps --format-version 1 | python3 -c 'import sys, json; print(json.load(sys.stdin)["packages"][0]["version"])')"
|
|
132
|
+
echo "Crate: ${CRATE} Version: ${VER}"
|
|
133
|
+
|
|
134
|
+
cargo publish --dry-run
|
|
135
|
+
|
|
136
|
+
CODE="$(curl -s -o /dev/null -w "%{http_code}" "https://crates.io/api/v1/crates/${CRATE}/${VER}" || true)"
|
|
137
|
+
if [ "$CODE" = "200" ]; then
|
|
138
|
+
echo "Already published: ${CRATE} ${VER} (skipping upload)."
|
|
139
|
+
exit 0
|
|
140
|
+
fi
|
|
141
|
+
|
|
142
|
+
cargo publish --no-verify
|
|
143
|
+
|
|
144
|
+
build:
|
|
145
|
+
name: Build binaries (${{ matrix.os }})
|
|
146
|
+
needs: publish-crates
|
|
147
|
+
runs-on: ${{ matrix.os }}
|
|
148
|
+
strategy:
|
|
149
|
+
fail-fast: false
|
|
150
|
+
matrix:
|
|
151
|
+
os: [ubuntu-22.04, macos-14, windows-latest]
|
|
152
|
+
steps:
|
|
153
|
+
- uses: actions/checkout@v4
|
|
154
|
+
|
|
155
|
+
- name: Setup Node.js
|
|
156
|
+
uses: actions/setup-node@v4
|
|
157
|
+
with:
|
|
158
|
+
node-version: 22
|
|
159
|
+
|
|
160
|
+
- name: Setup Rust
|
|
161
|
+
uses: dtolnay/rust-toolchain@stable
|
|
162
|
+
|
|
163
|
+
- name: Cache cargo
|
|
164
|
+
uses: actions/cache@v4
|
|
165
|
+
with:
|
|
166
|
+
path: |
|
|
167
|
+
~/.cargo/registry
|
|
168
|
+
~/.cargo/git
|
|
169
|
+
target
|
|
170
|
+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
|
171
|
+
|
|
172
|
+
- name: Install yarn
|
|
173
|
+
run: corepack enable && corepack prepare yarn@1.22.22 --activate
|
|
174
|
+
|
|
175
|
+
- name: Install @napi-rs/cli
|
|
176
|
+
run: yarn global add @napi-rs/cli@^2.18.4
|
|
177
|
+
|
|
178
|
+
- name: Install deps
|
|
179
|
+
run: yarn install --frozen-lockfile
|
|
180
|
+
|
|
181
|
+
- name: Build artifacts
|
|
182
|
+
run: yarn build
|
|
183
|
+
|
|
184
|
+
- name: Upload artifact
|
|
185
|
+
uses: actions/upload-artifact@v4
|
|
186
|
+
with:
|
|
187
|
+
name: artifacts-${{ runner.os }}
|
|
188
|
+
path: |
|
|
189
|
+
./*.node
|
|
190
|
+
npm/**/package.json
|
|
191
|
+
npm/**/*.node
|
|
192
|
+
|
|
193
|
+
publish:
|
|
194
|
+
name: Publish to npm
|
|
195
|
+
needs: [ publish-crates, build ]
|
|
196
|
+
runs-on: ubuntu-22.04
|
|
197
|
+
steps:
|
|
198
|
+
- uses: actions/checkout@v4
|
|
199
|
+
|
|
200
|
+
- name: Setup Node.js
|
|
201
|
+
uses: actions/setup-node@v4
|
|
202
|
+
with:
|
|
203
|
+
node-version: 22
|
|
204
|
+
registry-url: "https://registry.npmjs.org"
|
|
205
|
+
|
|
206
|
+
- name: Install yarn
|
|
207
|
+
run: corepack enable && corepack prepare yarn@1.22.22 --activate
|
|
208
|
+
|
|
209
|
+
- name: Install deps
|
|
210
|
+
run: yarn install --frozen-lockfile
|
|
211
|
+
|
|
212
|
+
- name: Download artifacts
|
|
213
|
+
uses: actions/download-artifact@v4
|
|
214
|
+
with:
|
|
215
|
+
path: artifacts
|
|
216
|
+
merge-multiple: true
|
|
217
|
+
|
|
218
|
+
- name: Install yarn
|
|
219
|
+
run: corepack enable && corepack prepare yarn@1.22.22 --activate
|
|
220
|
+
|
|
221
|
+
- name: Install deps
|
|
222
|
+
run: yarn install --frozen-lockfile
|
|
223
|
+
|
|
224
|
+
- name: Publish main npm package
|
|
225
|
+
env:
|
|
226
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
227
|
+
run: npm publish --access public
|
package/Cargo.toml
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "chia-block-listener"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.2.0"
|
|
4
4
|
edition = "2021"
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
crate-type = ["cdylib"]
|
|
5
|
+
description = "Event driven listener and messaging interface for Chia blockchain peers"
|
|
6
|
+
license = "Apache-2.0" # or "MIT" / "MIT OR Apache-2.0" etc.
|
|
8
7
|
|
|
9
8
|
[dependencies]
|
|
10
|
-
# NAPI-rs for Node.js bindings
|
|
11
|
-
napi = { version = "2", features = ["napi9", "tokio_rt", "async"] }
|
|
12
|
-
napi-derive = "2"
|
|
13
9
|
|
|
14
10
|
# Async runtime
|
|
15
11
|
tokio = { version = "1", features = ["full"] }
|
|
16
12
|
futures-util = "0.3"
|
|
13
|
+
tokio-util = "0.7"
|
|
17
14
|
|
|
18
15
|
# Chia-related dependencies
|
|
19
16
|
chia-protocol = "0.26"
|
|
@@ -26,6 +23,7 @@ native-tls = { version = "0.2", features = ["vendored"] }
|
|
|
26
23
|
|
|
27
24
|
# Serialization
|
|
28
25
|
serde = { version = "1", features = ["derive"] }
|
|
26
|
+
hex = "0.4"
|
|
29
27
|
|
|
30
28
|
# Utilities
|
|
31
29
|
thiserror = "1"
|
|
@@ -33,13 +31,20 @@ tracing = "0.1"
|
|
|
33
31
|
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
|
34
32
|
sha2 = "0.10"
|
|
35
33
|
dirs = "5"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
chia-generator-parser = { path = "./crate/chia-generator-parser" }
|
|
39
|
-
dns-discovery = { path = "./crate/dns-discovery" }
|
|
40
|
-
|
|
41
|
-
[build-dependencies]
|
|
42
|
-
napi-build = "2"
|
|
34
|
+
dig-dns-discovery = { workspace = true }
|
|
35
|
+
chia-generator-parser = { workspace = true}
|
|
43
36
|
|
|
44
37
|
[profile.release]
|
|
45
38
|
lto = true
|
|
39
|
+
|
|
40
|
+
[workspace]
|
|
41
|
+
members = [
|
|
42
|
+
".",
|
|
43
|
+
"crate/chia-generator-parser",
|
|
44
|
+
"crate/dig-dns-discovery",
|
|
45
|
+
"crate/chia-block-listener-napi",
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
[workspace.dependencies]
|
|
49
|
+
dig-dns-discovery = { path = "crate/dig-dns-discovery", version = "0.2.0" }
|
|
50
|
+
chia-generator-parser = { path = "crate/chia-generator-parser", version = "0.2.0" }
|