@dignetwork/chia-block-listener 0.1.4
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 +283 -0
- package/.yarnrc.yml +1 -0
- package/.yarnrc.yml.bak +3 -0
- package/Cargo.toml +44 -0
- package/LICENSE +21 -0
- package/README.md +387 -0
- package/build.rs +5 -0
- package/examples/example-disconnect.js +108 -0
- package/examples/example-get-block-by-height.js +368 -0
- package/examples/example-historical-blocks.js +162 -0
- package/examples/example-sync.js +240 -0
- package/examples/example-with-discovery.js +209 -0
- package/examples/example.js +77 -0
- package/index.d.ts +18 -0
- package/index.js +316 -0
- package/npm/darwin-arm64/README.md +3 -0
- package/npm/darwin-arm64/package.json +22 -0
- package/npm/darwin-x64/README.md +3 -0
- package/npm/darwin-x64/package.json +22 -0
- package/npm/linux-arm64-gnu/README.md +3 -0
- package/npm/linux-arm64-gnu/package.json +22 -0
- package/npm/linux-x64-gnu/README.md +3 -0
- package/npm/linux-x64-gnu/package.json +22 -0
- package/npm/win32-x64-msvc/README.md +3 -0
- package/npm/win32-x64-msvc/package.json +22 -0
- package/package.json +63 -0
- package/src/error.rs +31 -0
- package/src/event_emitter.rs +1310 -0
- package/src/lib.rs +19 -0
- package/src/peer.rs +394 -0
- package/src/protocol.rs +117 -0
- package/src/tls.rs +54 -0
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
env:
|
|
3
|
+
DEBUG: napi:*
|
|
4
|
+
APP_NAME: chia-block-listener
|
|
5
|
+
MACOSX_DEPLOYMENT_TARGET: '10.13'
|
|
6
|
+
permissions:
|
|
7
|
+
contents: write
|
|
8
|
+
id-token: write
|
|
9
|
+
on:
|
|
10
|
+
push:
|
|
11
|
+
branches:
|
|
12
|
+
- main
|
|
13
|
+
tags-ignore:
|
|
14
|
+
- '**'
|
|
15
|
+
paths-ignore:
|
|
16
|
+
- '**/*.md'
|
|
17
|
+
- LICENSE
|
|
18
|
+
- '**/*.gitignore'
|
|
19
|
+
- .editorconfig
|
|
20
|
+
- docs/**
|
|
21
|
+
pull_request:
|
|
22
|
+
branches:
|
|
23
|
+
- '**'
|
|
24
|
+
|
|
25
|
+
jobs:
|
|
26
|
+
rust-checks:
|
|
27
|
+
runs-on: ubuntu-latest
|
|
28
|
+
steps:
|
|
29
|
+
- name: Checkout
|
|
30
|
+
uses: actions/checkout@v4
|
|
31
|
+
|
|
32
|
+
- name: Setup Rust
|
|
33
|
+
uses: dtolnay/rust-toolchain@stable
|
|
34
|
+
with:
|
|
35
|
+
toolchain: stable
|
|
36
|
+
|
|
37
|
+
- name: Clippy
|
|
38
|
+
run: cargo clippy --workspace --all-features --all-targets
|
|
39
|
+
|
|
40
|
+
- name: Unused dependencies
|
|
41
|
+
run: |
|
|
42
|
+
cargo install cargo-machete --locked
|
|
43
|
+
cargo machete
|
|
44
|
+
|
|
45
|
+
- name: Fmt
|
|
46
|
+
run: cargo fmt --all -- --files-with-diff --check
|
|
47
|
+
|
|
48
|
+
build:
|
|
49
|
+
needs: rust-checks
|
|
50
|
+
strategy:
|
|
51
|
+
fail-fast: false
|
|
52
|
+
matrix:
|
|
53
|
+
settings:
|
|
54
|
+
- host: macos-latest
|
|
55
|
+
target: x86_64-apple-darwin
|
|
56
|
+
build: npm run build -- --target x86_64-apple-darwin
|
|
57
|
+
- host: windows-latest
|
|
58
|
+
build: npm run build -- --target x86_64-pc-windows-msvc
|
|
59
|
+
target: x86_64-pc-windows-msvc
|
|
60
|
+
- host: ubuntu-latest
|
|
61
|
+
target: x86_64-unknown-linux-gnu
|
|
62
|
+
build: |
|
|
63
|
+
set -e &&
|
|
64
|
+
npm run build -- --target x86_64-unknown-linux-gnu &&
|
|
65
|
+
strip *.node
|
|
66
|
+
- host: macos-latest
|
|
67
|
+
target: aarch64-apple-darwin
|
|
68
|
+
build: npm run build -- --target aarch64-apple-darwin
|
|
69
|
+
- host: ubuntu-latest
|
|
70
|
+
target: aarch64-unknown-linux-gnu
|
|
71
|
+
setup: |
|
|
72
|
+
sudo apt-get update
|
|
73
|
+
sudo apt-get install -y gcc-aarch64-linux-gnu
|
|
74
|
+
build: |
|
|
75
|
+
set -e &&
|
|
76
|
+
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
|
|
79
|
+
runs-on: ${{ matrix.settings.host }}
|
|
80
|
+
steps:
|
|
81
|
+
- uses: actions/checkout@v4
|
|
82
|
+
- name: Setup node
|
|
83
|
+
uses: actions/setup-node@v4
|
|
84
|
+
with:
|
|
85
|
+
node-version: 20
|
|
86
|
+
cache: npm
|
|
87
|
+
- name: Install
|
|
88
|
+
uses: dtolnay/rust-toolchain@stable
|
|
89
|
+
with:
|
|
90
|
+
toolchain: stable
|
|
91
|
+
targets: ${{ matrix.settings.target }}
|
|
92
|
+
- name: Cache cargo
|
|
93
|
+
uses: actions/cache@v4
|
|
94
|
+
with:
|
|
95
|
+
path: |
|
|
96
|
+
~/.cargo/registry/index/
|
|
97
|
+
~/.cargo/registry/cache/
|
|
98
|
+
~/.cargo/git/db/
|
|
99
|
+
.cargo-cache
|
|
100
|
+
target/
|
|
101
|
+
key: ${{ matrix.settings.target }}-cargo-${{ matrix.settings.host }}
|
|
102
|
+
- uses: goto-bus-stop/setup-zig@v2
|
|
103
|
+
if: ${{ matrix.settings.target == 'armv7-unknown-linux-gnueabihf' || matrix.settings.target == 'armv7-unknown-linux-musleabihf' }}
|
|
104
|
+
with:
|
|
105
|
+
version: 0.13.0
|
|
106
|
+
- name: Setup toolchain
|
|
107
|
+
run: ${{ matrix.settings.setup }}
|
|
108
|
+
if: ${{ matrix.settings.setup }}
|
|
109
|
+
shell: bash
|
|
110
|
+
- name: Install dependencies
|
|
111
|
+
run: npm ci
|
|
112
|
+
- name: Setup node x86
|
|
113
|
+
uses: actions/setup-node@v4
|
|
114
|
+
if: matrix.settings.target == 'i686-pc-windows-msvc'
|
|
115
|
+
with:
|
|
116
|
+
node-version: 20
|
|
117
|
+
cache: npm
|
|
118
|
+
architecture: x86
|
|
119
|
+
- name: Setup toolchain
|
|
120
|
+
run: ${{ matrix.settings.setup }}
|
|
121
|
+
if: ${{ matrix.settings.setup }}
|
|
122
|
+
shell: bash
|
|
123
|
+
- name: Build
|
|
124
|
+
run: ${{ matrix.settings.build }}
|
|
125
|
+
shell: bash
|
|
126
|
+
- name: Upload artifact
|
|
127
|
+
uses: actions/upload-artifact@v4
|
|
128
|
+
with:
|
|
129
|
+
name: bindings-${{ matrix.settings.target }}
|
|
130
|
+
path: ${{ env.APP_NAME }}.*.node
|
|
131
|
+
if-no-files-found: error
|
|
132
|
+
|
|
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
|
|
170
|
+
|
|
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
|
|
201
|
+
|
|
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
|
|
239
|
+
|
|
240
|
+
publish:
|
|
241
|
+
name: Publish
|
|
242
|
+
runs-on: ubuntu-latest
|
|
243
|
+
needs:
|
|
244
|
+
- 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
|
|
249
|
+
steps:
|
|
250
|
+
- uses: actions/checkout@v4
|
|
251
|
+
- name: Setup node
|
|
252
|
+
uses: actions/setup-node@v4
|
|
253
|
+
with:
|
|
254
|
+
node-version: 20
|
|
255
|
+
cache: npm
|
|
256
|
+
- name: Install dependencies
|
|
257
|
+
run: npm ci
|
|
258
|
+
- name: Download all artifacts
|
|
259
|
+
uses: actions/download-artifact@v4
|
|
260
|
+
with:
|
|
261
|
+
path: artifacts
|
|
262
|
+
- name: Move artifacts
|
|
263
|
+
run: npm run artifacts
|
|
264
|
+
- name: List packages
|
|
265
|
+
run: ls -R ./npm
|
|
266
|
+
shell: bash
|
|
267
|
+
- name: Publish
|
|
268
|
+
run: |
|
|
269
|
+
npm config set provenance true
|
|
270
|
+
if git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$";
|
|
271
|
+
then
|
|
272
|
+
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
|
|
273
|
+
npm publish --access public
|
|
274
|
+
elif git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+";
|
|
275
|
+
then
|
|
276
|
+
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
|
|
277
|
+
npm publish --tag next --access public
|
|
278
|
+
else
|
|
279
|
+
echo "Not a release, skipping publish"
|
|
280
|
+
fi
|
|
281
|
+
env:
|
|
282
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
283
|
+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/.yarnrc.yml
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
nodeLinker: node-modules
|
package/.yarnrc.yml.bak
ADDED
package/Cargo.toml
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "chia-block-listener"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2021"
|
|
5
|
+
|
|
6
|
+
[lib]
|
|
7
|
+
crate-type = ["cdylib"]
|
|
8
|
+
|
|
9
|
+
[dependencies]
|
|
10
|
+
# NAPI-rs for Node.js bindings
|
|
11
|
+
napi = { version = "2", features = ["napi9", "tokio_rt", "async"] }
|
|
12
|
+
napi-derive = "2"
|
|
13
|
+
|
|
14
|
+
# Async runtime
|
|
15
|
+
tokio = { version = "1", features = ["full"] }
|
|
16
|
+
futures-util = "0.3"
|
|
17
|
+
|
|
18
|
+
# Chia-related dependencies
|
|
19
|
+
chia-protocol = "0.26"
|
|
20
|
+
chia-traits = "0.26"
|
|
21
|
+
chia-ssl = "0.26"
|
|
22
|
+
clvmr = "0.14.0"
|
|
23
|
+
clvm-traits = "0.26"
|
|
24
|
+
|
|
25
|
+
# Networking
|
|
26
|
+
tokio-tungstenite = { version = "0.24", features = ["native-tls"] }
|
|
27
|
+
native-tls = { version = "0.2", features = ["vendored"] }
|
|
28
|
+
|
|
29
|
+
# Serialization
|
|
30
|
+
serde = { version = "1", features = ["derive"] }
|
|
31
|
+
hex = "0.4"
|
|
32
|
+
|
|
33
|
+
# Utilities
|
|
34
|
+
thiserror = "1"
|
|
35
|
+
tracing = "0.1"
|
|
36
|
+
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
|
37
|
+
sha2 = "0.10"
|
|
38
|
+
dirs = "5"
|
|
39
|
+
|
|
40
|
+
[build-dependencies]
|
|
41
|
+
napi-build = "2"
|
|
42
|
+
|
|
43
|
+
[profile.release]
|
|
44
|
+
lto = true
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Your Name
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|