@paimaexample/npm-midnight-indexer 0.3.19 → 0.3.21
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/README.md +57 -23
- package/binary.js +28 -21
- package/index.js +18 -5
- package/package.json +1 -1
- package/run_midnight_indexer.js +9 -5
package/README.md
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
# Midnight Indexer
|
|
2
2
|
|
|
3
|
-
A Node.js package that downloads and runs the
|
|
3
|
+
A Node.js package that downloads and runs the
|
|
4
|
+
[Midnight](https://midnight.network) Indexer. The indexer requires a running
|
|
5
|
+
Midnight Node to function properly.
|
|
4
6
|
|
|
5
7
|
## Overview
|
|
6
8
|
|
|
7
9
|
This package provides flexible execution options for the Midnight Indexer:
|
|
8
10
|
|
|
9
11
|
- **Docker mode**: Runs the indexer in a Docker container (recommended)
|
|
10
|
-
- **Binary mode**: Downloads and runs the native binary locally (Linux
|
|
12
|
+
- **Binary mode**: Downloads and runs the native binary locally (Linux, Windows,
|
|
13
|
+
macOS arm64)
|
|
11
14
|
|
|
12
15
|
### Platform Support
|
|
13
16
|
|
|
14
17
|
| Platform | Docker | Binary |
|
|
15
|
-
|
|
16
|
-
| macOS | ✅ Yes |
|
|
18
|
+
| -------- | ------ | ------ |
|
|
19
|
+
| macOS | ✅ Yes | ✅ Yes |
|
|
17
20
|
| Linux | ✅ Yes | ✅ Yes |
|
|
18
|
-
| Windows | ❌ No |
|
|
19
|
-
|
|
20
|
-
> **Note**: On macOS, only Docker execution is supported. Binary execution will automatically fall back to Docker or show an error.
|
|
21
|
+
| Windows | ❌ No | ✅ Yes |
|
|
21
22
|
|
|
22
23
|
## Installation
|
|
23
24
|
|
|
@@ -28,12 +29,15 @@ npm install npm-midnight-indexer
|
|
|
28
29
|
## Prerequisites
|
|
29
30
|
|
|
30
31
|
### For Docker Mode
|
|
32
|
+
|
|
31
33
|
- Docker installed and running
|
|
32
34
|
- `APP__INFRA__SECRET` environment variable (required)
|
|
33
35
|
|
|
34
36
|
### For Binary Mode
|
|
35
|
-
|
|
36
|
-
-
|
|
37
|
+
|
|
38
|
+
- Supported platform (Linux/macOS ARM64)
|
|
39
|
+
- Local Midnight Node and Proof Server running on standard ports. But they can
|
|
40
|
+
be set using env variables
|
|
37
41
|
- `APP__INFRA__SECRET` environment variable (required)
|
|
38
42
|
|
|
39
43
|
## Usage
|
|
@@ -45,8 +49,9 @@ node index.js [options] [args...]
|
|
|
45
49
|
```
|
|
46
50
|
|
|
47
51
|
**Options:**
|
|
52
|
+
|
|
48
53
|
- `--docker` - Force Docker execution
|
|
49
|
-
- `--binary` - Force binary execution (
|
|
54
|
+
- `--binary` - Force binary execution (available on Linux, Windows, macOS arm64)
|
|
50
55
|
- `--help` - Show help information
|
|
51
56
|
|
|
52
57
|
**Examples:**
|
|
@@ -55,7 +60,7 @@ node index.js [options] [args...]
|
|
|
55
60
|
# Force Docker usage
|
|
56
61
|
APP__INFRA__SECRET=mysecret node index.js --docker
|
|
57
62
|
|
|
58
|
-
# Force binary usage (Linux/Windows
|
|
63
|
+
# Force binary usage (Linux/Windows/macOS arm64)
|
|
59
64
|
APP__INFRA__SECRET=mysecret node index.js --binary
|
|
60
65
|
|
|
61
66
|
# Interactive mode - prompts for Docker vs binary choice
|
|
@@ -67,16 +72,17 @@ node index.js --help
|
|
|
67
72
|
|
|
68
73
|
## Environment Variables
|
|
69
74
|
|
|
70
|
-
The indexer supports several environment variables with different defaults based
|
|
75
|
+
The indexer supports several environment variables with different defaults based
|
|
76
|
+
on execution mode:
|
|
71
77
|
|
|
72
|
-
| Variable
|
|
73
|
-
|
|
74
|
-
| `APP__INFRA__SECRET`
|
|
75
|
-
| `LEDGER_NETWORK_ID`
|
|
76
|
-
| `SUBSTRATE_NODE_WS_URL`
|
|
77
|
-
| `FEATURES_WALLET_ENABLED`
|
|
78
|
-
| `APP__INFRA__PROOF_SERVER__URL` | No
|
|
79
|
-
| `APP__INFRA__NODE__URL`
|
|
78
|
+
| Variable | Required | Docker Default | Binary Default | Description |
|
|
79
|
+
| ------------------------------- | -------- | -------------------------- | ----------------------- | ------------------------------ |
|
|
80
|
+
| `APP__INFRA__SECRET` | Yes | - | - | Secret key for the application |
|
|
81
|
+
| `LEDGER_NETWORK_ID` | No | `Undeployed` | `Undeployed` | Ledger network identifier |
|
|
82
|
+
| `SUBSTRATE_NODE_WS_URL` | No | `ws://node:9944` | `ws://localhost:9944` | Substrate node WebSocket URL |
|
|
83
|
+
| `FEATURES_WALLET_ENABLED` | No | `true` | `true` | Enable wallet features |
|
|
84
|
+
| `APP__INFRA__PROOF_SERVER__URL` | No | `http://proof-server:6300` | `http://localhost:6300` | Proof server URL |
|
|
85
|
+
| `APP__INFRA__NODE__URL` | No | `ws://node:9944` | `ws://localhost:9944` | Node WebSocket URL |
|
|
80
86
|
|
|
81
87
|
### Environment Variable Examples
|
|
82
88
|
|
|
@@ -129,31 +135,57 @@ When using binary mode, the indexer:
|
|
|
129
135
|
2. **Uses localhost URLs** for all service connections
|
|
130
136
|
3. **Runs natively** on the host system
|
|
131
137
|
|
|
138
|
+
## Path Resolution
|
|
139
|
+
|
|
140
|
+
The indexer relies on two user-supplied file paths and **both are interpreted
|
|
141
|
+
relative to the process’s current working directory (CWD)** when they are not
|
|
142
|
+
absolute:
|
|
143
|
+
|
|
144
|
+
| Configuration location | Purpose | If relative, resolved against |
|
|
145
|
+
| ---------------------------------- | -------------------------------------------- | ------------------------------------------------------------------------- |
|
|
146
|
+
| `CONFIG_FILE` environment variable | Location of the YAML config file | The directory you launch `node index.js …` from (or the Docker `WORKDIR`) |
|
|
147
|
+
| `infra.storage.cnn_url` in YAML | SQLite database used by the standalone build | The CWD at runtime of the indexer process |
|
|
148
|
+
|
|
149
|
+
### Practical tips
|
|
150
|
+
|
|
151
|
+
1. Prefer absolute paths when you need to be explicit.
|
|
152
|
+
2. In **binary mode** this package sets the CWD to the bundled
|
|
153
|
+
`indexer-standalone` folder, so a default `cnn_url: "./indexer.sqlite"` ends
|
|
154
|
+
up next to the binary.
|
|
155
|
+
3. In **Docker mode** the image’s `WORKDIR` is `/opt/indexer-standalone`.
|
|
156
|
+
Bind-mount volumes accordingly if you want the database file somewhere else.
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
132
160
|
### Supported Binary Platforms
|
|
133
161
|
|
|
134
162
|
- Linux ARM64 (`linux-arm64`)
|
|
135
163
|
- Linux AMD64 (`linux-amd64`)
|
|
136
|
-
- macOS ARM64 (`macos-arm64`)
|
|
164
|
+
- macOS ARM64 (`macos-arm64`)
|
|
137
165
|
|
|
138
166
|
## Troubleshooting
|
|
139
167
|
|
|
140
168
|
### Common Issues
|
|
141
169
|
|
|
142
170
|
**"Docker is not installed or not available"**
|
|
171
|
+
|
|
143
172
|
- Install Docker Desktop or Docker Engine
|
|
144
173
|
- Ensure Docker is running
|
|
145
174
|
- Check Docker is accessible from command line: `docker --version`
|
|
146
175
|
|
|
147
176
|
**"APP__INFRA__SECRET environment variable is required"**
|
|
177
|
+
|
|
148
178
|
- Set the secret: `export APP__INFRA__SECRET=your_secret_here`
|
|
149
179
|
- Or pass inline: `APP__INFRA__SECRET=your_secret node index.js --docker`
|
|
150
180
|
- Required for both Docker and binary execution modes
|
|
151
181
|
|
|
152
|
-
**"Binary execution is
|
|
182
|
+
**"Binary execution is only supported on macOS ARM64"**
|
|
183
|
+
|
|
153
184
|
- Use `--docker` flag or run without flags to use Docker automatically
|
|
154
185
|
- Install Docker if not already installed
|
|
155
186
|
|
|
156
187
|
**"Failed to start midnight-indexer"**
|
|
188
|
+
|
|
157
189
|
- Check if ports 8088, 6300, 9944 are available
|
|
158
190
|
- Verify Midnight Node is running and accessible
|
|
159
191
|
- Check environment variables are correctly set
|
|
@@ -161,6 +193,7 @@ When using binary mode, the indexer:
|
|
|
161
193
|
### Logs and Debugging
|
|
162
194
|
|
|
163
195
|
The indexer outputs detailed logs including:
|
|
196
|
+
|
|
164
197
|
- Download progress for binaries
|
|
165
198
|
- Docker pull progress
|
|
166
199
|
- Process IDs and status
|
|
@@ -200,6 +233,7 @@ ISC
|
|
|
200
233
|
## Support
|
|
201
234
|
|
|
202
235
|
For issues related to:
|
|
236
|
+
|
|
203
237
|
- **This package**: Open an issue in the repository
|
|
204
238
|
- **Midnight Protocol**: Visit [midnight.network](https://midnight.network)
|
|
205
239
|
- **Docker**: Check [Docker documentation](https://docs.docker.com/)
|
|
@@ -208,4 +242,4 @@ For issues related to:
|
|
|
208
242
|
|
|
209
243
|
- [Midnight Network](https://midnight.network)
|
|
210
244
|
- [Docker Hub - Midnight Indexer](https://hub.docker.com/r/midnightntwrk/indexer-standalone)
|
|
211
|
-
- [Node.js](https://nodejs.org/)
|
|
245
|
+
- [Node.js](https://nodejs.org/)
|
package/binary.js
CHANGED
|
@@ -5,14 +5,12 @@ const extract = require("extract-zip");
|
|
|
5
5
|
const path = require("path");
|
|
6
6
|
|
|
7
7
|
function getPlatform() {
|
|
8
|
-
|
|
8
|
+
const platform = os.platform();
|
|
9
9
|
const arch = os.arch();
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
if (platform === "darwin") {
|
|
12
12
|
// For macOS, return the full platform-arch combination
|
|
13
|
-
if (arch === "
|
|
14
|
-
return "macos-arm64";
|
|
15
|
-
} else if (arch === "x64") {
|
|
13
|
+
if (arch === "x64") {
|
|
16
14
|
return "macos-amd64"; // Will not be in supportedPlatforms, so will fall back to Docker
|
|
17
15
|
} else {
|
|
18
16
|
return `macos-${arch}`;
|
|
@@ -20,41 +18,36 @@ function getPlatform() {
|
|
|
20
18
|
} else {
|
|
21
19
|
// For Linux and other platforms, only arch is needed
|
|
22
20
|
if (arch === "x64") {
|
|
23
|
-
return
|
|
21
|
+
return `${platform}-amd64`;
|
|
24
22
|
}
|
|
25
|
-
return arch
|
|
23
|
+
return `${platform}-${arch}`;
|
|
26
24
|
}
|
|
27
25
|
}
|
|
28
26
|
|
|
29
27
|
function getBinaryUrl() {
|
|
30
28
|
const platform = getPlatform();
|
|
31
29
|
const supportedPlatforms = require("./package.json").supportedPlatforms;
|
|
32
|
-
|
|
33
30
|
// Check if platform is supported
|
|
34
31
|
if (!supportedPlatforms.includes(platform)) {
|
|
35
32
|
throw new Error(`Unsupported platform: ${platform}`);
|
|
36
33
|
}
|
|
37
|
-
|
|
38
|
-
// Special handling for macOS platforms
|
|
39
|
-
if (platform.startsWith("macos")) {
|
|
40
|
-
return `https://paima-midnight.nyc3.cdn.digitaloceanspaces.com/binaries/indexer-standalone-${platform}.zip`;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// For Linux and other platforms, use the existing pattern
|
|
44
34
|
return `https://paima-midnight.nyc3.cdn.digitaloceanspaces.com/binaries/indexer-standalone-${platform}.zip`;
|
|
45
35
|
}
|
|
46
36
|
|
|
47
37
|
async function downloadAndSaveBinary() {
|
|
48
38
|
const url = getBinaryUrl();
|
|
49
39
|
try {
|
|
40
|
+
console.error(`Downloading... ${url}`);
|
|
50
41
|
const response = await axios.get(url, { responseType: "stream" });
|
|
51
|
-
const writer = fs.createWriteStream(
|
|
52
|
-
|
|
42
|
+
const writer = fs.createWriteStream(
|
|
43
|
+
path.join(__dirname, "indexer-standalone.zip"),
|
|
44
|
+
);
|
|
45
|
+
|
|
53
46
|
response.data.pipe(writer);
|
|
54
|
-
|
|
47
|
+
|
|
55
48
|
return new Promise((resolve, reject) => {
|
|
56
|
-
writer.on(
|
|
57
|
-
writer.on(
|
|
49
|
+
writer.on("finish", resolve);
|
|
50
|
+
writer.on("error", reject);
|
|
58
51
|
});
|
|
59
52
|
} catch (error) {
|
|
60
53
|
console.error("Error downloading binary:", error);
|
|
@@ -67,6 +60,19 @@ async function unzipBinary() {
|
|
|
67
60
|
dir: path.join(__dirname, "indexer-standalone"),
|
|
68
61
|
});
|
|
69
62
|
fs.unlinkSync(path.join(__dirname, "indexer-standalone.zip"));
|
|
63
|
+
|
|
64
|
+
const platform = getPlatform();
|
|
65
|
+
const parts = platform.split("-");
|
|
66
|
+
if (parts[0] === "linux") {
|
|
67
|
+
fs.chmodSync(
|
|
68
|
+
path.join(
|
|
69
|
+
__dirname,
|
|
70
|
+
"indexer-standalone",
|
|
71
|
+
`indexer-standalone-${platform}`,
|
|
72
|
+
),
|
|
73
|
+
0o755,
|
|
74
|
+
);
|
|
75
|
+
}
|
|
70
76
|
}
|
|
71
77
|
|
|
72
78
|
async function binary() {
|
|
@@ -76,4 +82,5 @@ async function binary() {
|
|
|
76
82
|
|
|
77
83
|
module.exports = {
|
|
78
84
|
binary,
|
|
79
|
-
|
|
85
|
+
getPlatform,
|
|
86
|
+
};
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { binary } = require("./binary");
|
|
1
|
+
const { binary, getPlatform } = require("./binary");
|
|
2
2
|
const { runMidnightIndexer } = require("./run_midnight_indexer");
|
|
3
3
|
const { checkIfDockerExists, pullDockerImage, runDockerContainer } = require(
|
|
4
4
|
"./docker",
|
|
@@ -9,8 +9,13 @@ const readline = require("readline");
|
|
|
9
9
|
const os = require("os");
|
|
10
10
|
|
|
11
11
|
function checkIfBinaryExists() {
|
|
12
|
+
const platform = getPlatform();
|
|
13
|
+
const parts = platform.split("-");
|
|
14
|
+
const binaryName = (parts[0] === "linux")
|
|
15
|
+
? `indexer-standalone-${platform}`
|
|
16
|
+
: `indexer-standalone`;
|
|
12
17
|
return fs.existsSync(
|
|
13
|
-
path.join(__dirname, "indexer-standalone",
|
|
18
|
+
path.join(__dirname, "indexer-standalone", binaryName),
|
|
14
19
|
);
|
|
15
20
|
}
|
|
16
21
|
|
|
@@ -29,7 +34,9 @@ function isBinarySupported() {
|
|
|
29
34
|
if (platform === "darwin") {
|
|
30
35
|
platformString = arch === "x64" ? "macos-amd64" : `macos-${arch}`;
|
|
31
36
|
} else {
|
|
32
|
-
platformString = arch === "x64"
|
|
37
|
+
platformString = arch === "x64"
|
|
38
|
+
? `${platform}-amd64`
|
|
39
|
+
: `${platform}-${arch}`;
|
|
33
40
|
}
|
|
34
41
|
|
|
35
42
|
return supportedPlatforms.includes(platformString);
|
|
@@ -227,7 +234,10 @@ async function main(args) {
|
|
|
227
234
|
if (flags.useBinary) {
|
|
228
235
|
if (!isBinarySupported()) {
|
|
229
236
|
console.error(
|
|
230
|
-
"Error: Binary execution is not supported on this platform"
|
|
237
|
+
"Error: Binary execution is not supported on this platform for: " +
|
|
238
|
+
os.platform() +
|
|
239
|
+
" " +
|
|
240
|
+
os.arch(),
|
|
231
241
|
);
|
|
232
242
|
console.log(
|
|
233
243
|
"Please use --docker flag instead, or run without flags to use Docker automatically",
|
|
@@ -245,7 +255,10 @@ async function main(args) {
|
|
|
245
255
|
if (!binarySupported) {
|
|
246
256
|
if (!dockerAvailable) {
|
|
247
257
|
console.error(
|
|
248
|
-
"Error: Binary execution is not supported on this platform and Docker is not installed or available"
|
|
258
|
+
"Error: Binary execution is not supported on this platform and Docker is not installed or available. For: " +
|
|
259
|
+
os.platform() +
|
|
260
|
+
" " +
|
|
261
|
+
os.arch(),
|
|
249
262
|
);
|
|
250
263
|
console.log(
|
|
251
264
|
"Please install Docker or ensure your platform is supported for binary execution",
|
package/package.json
CHANGED
package/run_midnight_indexer.js
CHANGED
|
@@ -2,7 +2,7 @@ const { spawn } = require("child_process");
|
|
|
2
2
|
const path = require("path");
|
|
3
3
|
const fs = require("fs");
|
|
4
4
|
const yaml = require("js-yaml");
|
|
5
|
-
|
|
5
|
+
const { getPlatform } = require("./binary");
|
|
6
6
|
/**
|
|
7
7
|
* Resolves the SQLite database path using the midnight-indexer configuration rules
|
|
8
8
|
* @param {Object} env - Environment variables
|
|
@@ -50,10 +50,9 @@ function resolveSqlitePath(env, workingDir) {
|
|
|
50
50
|
|
|
51
51
|
console.log(`Found SQLite path from config file: ${cnnUrl}`);
|
|
52
52
|
|
|
53
|
-
// If the path is relative,
|
|
53
|
+
// If the path is relative, resolve it against the binary working directory (indexer-standalone)
|
|
54
54
|
if (!path.isAbsolute(cnnUrl)) {
|
|
55
|
-
const
|
|
56
|
-
const resolvedPath = path.resolve(configDir, cnnUrl);
|
|
55
|
+
const resolvedPath = path.resolve(workingDir, cnnUrl);
|
|
57
56
|
console.log(`Resolved relative path to: ${resolvedPath}`);
|
|
58
57
|
return resolvedPath;
|
|
59
58
|
}
|
|
@@ -111,10 +110,15 @@ function handleCleanFlag(env, workingDir) {
|
|
|
111
110
|
* @returns {ChildProcess} The spawned child process
|
|
112
111
|
*/
|
|
113
112
|
function runMidnightIndexer(env = process.env, args = []) {
|
|
113
|
+
const platform = getPlatform();
|
|
114
|
+
const parts = platform.split("-");
|
|
115
|
+
const binaryName = (parts[0] === "linux")
|
|
116
|
+
? `indexer-standalone-${platform}`
|
|
117
|
+
: "indexer-standalone";
|
|
114
118
|
const binaryPath = path.join(
|
|
115
119
|
__dirname,
|
|
116
120
|
"indexer-standalone",
|
|
117
|
-
|
|
121
|
+
binaryName,
|
|
118
122
|
);
|
|
119
123
|
const workingDir = path.join(__dirname, "indexer-standalone");
|
|
120
124
|
|