@paimaexample/bitcoin-core 0.3.109

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.
Files changed (2) hide show
  1. package/index.js +94 -0
  2. package/package.json +9 -0
package/index.js ADDED
@@ -0,0 +1,94 @@
1
+ import BinWrapper from '@xhmikosr/bin-wrapper';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { execFile } from 'node:child_process';
5
+ import fs from 'node:fs';
6
+ import os from 'node:os';
7
+
8
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
9
+
10
+ const version = '28.1';
11
+ const base = `https://bitcoin.org/bin/bitcoin-core-${version}`;
12
+ const dest = path.join(__dirname, 'vendor');
13
+
14
+ const bin = new BinWrapper()
15
+ .src(`${base}/bitcoin-${version}-x86_64-linux-gnu.tar.gz`, 'linux', 'x64')
16
+ .src(`${base}/bitcoin-${version}-aarch64-linux-gnu.tar.gz`, 'linux', 'arm64')
17
+ .src(`${base}/bitcoin-${version}-arm64-apple-darwin.tar.gz`, 'darwin', 'arm64')
18
+ .src(`${base}/bitcoin-${version}-x86_64-apple-darwin.tar.gz`, 'darwin', 'x64')
19
+ .dest(dest)
20
+ .use('bin/bitcoind');
21
+
22
+ export default bin;
23
+
24
+ const DEFAULT_CONFIG = `
25
+ server=1
26
+ regtest=1
27
+ fallbackfee=0.00001
28
+ txindex=1
29
+
30
+ [regtest]
31
+ rpcuser=dev
32
+ rpcpassword=devpassword
33
+ rpcport=18443
34
+ port=18334
35
+ fallbackfee=0.00001
36
+ `;
37
+
38
+ export async function run(options = {}) {
39
+ const { config, dataDir, verbose = false } = options;
40
+
41
+ await bin.run(['--version']);
42
+
43
+ const dataDirPath = dataDir || fs.mkdtempSync(path.join(os.tmpdir(), 'bitcoin-core-'));
44
+
45
+ if (!fs.existsSync(dataDirPath)) {
46
+ fs.mkdirSync(dataDirPath, { recursive: true });
47
+ }
48
+
49
+ const configPath = config || path.join(dataDirPath, 'bitcoin.conf');
50
+
51
+ if (!config) {
52
+ fs.writeFileSync(configPath, DEFAULT_CONFIG.trim());
53
+ }
54
+
55
+ const args = [`-datadir=${dataDirPath}`, `-conf=${configPath}`];
56
+ const child = execFile(bin.path(), args);
57
+
58
+ if (verbose) {
59
+ child.stdout.on('data', (data) => {
60
+ console.log(`bitcoind stdout: ${data}`);
61
+ });
62
+ }
63
+
64
+ child.stderr.on('data', (data) => {
65
+ console.error(`bitcoind stderr: ${data}`);
66
+ });
67
+ child.on('close', (code) => {
68
+ if (code !== 0) {
69
+ console.log(`bitcoind exited with code ${code}`);
70
+ }
71
+ });
72
+
73
+ return {
74
+ child,
75
+ dataDir: dataDirPath,
76
+ configPath,
77
+ stop: () => child.kill(),
78
+ };
79
+ }
80
+
81
+ if (import.meta.main) {
82
+ const cliArgs = process.argv.slice(2);
83
+ const verbose = cliArgs.includes("--verbose");
84
+
85
+ (async () => {
86
+ try {
87
+ console.log("Starting Bitcoin Core regtest...");
88
+ await run({ verbose });
89
+ } catch (error) {
90
+ console.error("Failed to start Bitcoin Core:", error);
91
+ process.exit(1);
92
+ }
93
+ })();
94
+ }
package/package.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "@paimaexample/bitcoin-core",
3
+ "version": "0.3.109",
4
+ "type": "module",
5
+ "main": "./index.js",
6
+ "dependencies": {
7
+ "@xhmikosr/bin-wrapper": "^5.0.0"
8
+ }
9
+ }