@alephium/web3 0.0.3 → 0.1.0-rc.0
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/.editorconfig +13 -0
- package/.eslintignore +2 -0
- package/.eslintrc.json +21 -0
- package/README.md +2 -2
- package/contracts/add.ral +7 -3
- package/contracts/greeter.ral +3 -1
- package/contracts/greeter_interface.ral +3 -0
- package/contracts/greeter_main.ral +9 -0
- package/contracts/main.ral +3 -5
- package/dev/user.conf +8 -4
- package/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/scripts/check-versions.d.ts +1 -0
- package/dist/scripts/check-versions.js +39 -0
- package/dist/{cli → scripts}/create-project.d.ts +0 -0
- package/dist/scripts/create-project.js +124 -0
- package/dist/scripts/header.d.ts +0 -0
- package/dist/scripts/header.js +18 -0
- package/dist/scripts/rename-gitignore.d.ts +1 -0
- package/dist/scripts/rename-gitignore.js +24 -0
- package/dist/scripts/start-devnet.d.ts +1 -0
- package/dist/scripts/start-devnet.js +131 -0
- package/dist/scripts/stop-devnet.d.ts +1 -0
- package/dist/scripts/stop-devnet.js +32 -0
- package/dist/{api → src/api}/api-alephium.d.ts +287 -168
- package/dist/{api → src/api}/api-alephium.js +497 -115
- package/dist/{api → src/api}/api-explorer.d.ts +117 -19
- package/dist/{api → src/api}/api-explorer.js +206 -46
- package/dist/src/api/index.d.ts +10 -0
- package/dist/src/api/index.js +55 -0
- package/dist/{lib → src}/constants.d.ts +0 -0
- package/dist/{lib → src}/constants.js +0 -0
- package/dist/src/contract/contract.d.ts +182 -0
- package/dist/src/contract/contract.js +760 -0
- package/dist/src/contract/events.d.ts +29 -0
- package/dist/src/contract/events.js +77 -0
- package/dist/src/contract/index.d.ts +3 -0
- package/dist/src/contract/index.js +32 -0
- package/dist/src/contract/ralph.d.ts +12 -0
- package/dist/src/contract/ralph.js +362 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.js +34 -0
- package/dist/src/signer/index.d.ts +2 -0
- package/dist/src/signer/index.js +31 -0
- package/dist/src/signer/node-wallet.d.ts +13 -0
- package/dist/src/signer/node-wallet.js +60 -0
- package/dist/src/signer/signer.d.ts +143 -0
- package/dist/src/signer/signer.js +184 -0
- package/dist/src/test/index.d.ts +7 -0
- package/dist/src/test/index.js +41 -0
- package/dist/src/test/privatekey-wallet.d.ts +12 -0
- package/dist/src/test/privatekey-wallet.js +68 -0
- package/dist/{lib → src/utils}/address.d.ts +0 -0
- package/dist/{lib → src/utils}/address.js +1 -1
- package/dist/{lib → src/utils}/bs58.d.ts +2 -2
- package/dist/{lib → src/utils}/bs58.js +3 -1
- package/dist/{lib → src/utils}/djb2.d.ts +0 -0
- package/dist/{lib → src/utils}/djb2.js +1 -1
- package/dist/src/utils/index.d.ts +6 -0
- package/dist/src/utils/index.js +35 -0
- package/dist/{lib → src/utils}/password-crypto.d.ts +0 -0
- package/dist/{lib → src/utils}/password-crypto.js +8 -7
- package/dist/src/utils/transaction.d.ts +2 -0
- package/dist/src/utils/transaction.js +58 -0
- package/dist/src/utils/utils.d.ts +30 -0
- package/dist/{lib → src/utils}/utils.js +83 -19
- package/gitignore +5 -4
- package/package.json +56 -40
- package/scripts/create-project.ts +136 -0
- package/scripts/header.js +17 -0
- package/scripts/start-devnet.js +3 -3
- package/src/api/api-alephium.ts +2323 -0
- package/src/api/api-explorer.ts +808 -0
- package/src/api/index.ts +35 -0
- package/src/constants.ts +20 -0
- package/src/contract/contract.ts +1014 -0
- package/src/contract/events.ts +102 -0
- package/src/contract/index.ts +21 -0
- package/src/contract/ralph.test.ts +178 -0
- package/src/contract/ralph.ts +362 -0
- package/src/fixtures/address.json +36 -0
- package/src/fixtures/balance.json +9 -0
- package/src/fixtures/self-clique.json +19 -0
- package/src/fixtures/transaction.json +13 -0
- package/src/fixtures/transactions.json +179 -0
- package/src/index.ts +24 -0
- package/src/signer/fixtures/genesis.json +26 -0
- package/src/signer/fixtures/wallets.json +26 -0
- package/src/signer/index.ts +20 -0
- package/src/signer/node-wallet.ts +74 -0
- package/src/signer/signer.ts +313 -0
- package/src/test/index.ts +32 -0
- package/src/test/privatekey-wallet.ts +58 -0
- package/src/utils/address.test.ts +47 -0
- package/src/utils/address.ts +39 -0
- package/src/utils/bs58.ts +26 -0
- package/src/utils/djb2.test.ts +35 -0
- package/src/utils/djb2.ts +25 -0
- package/src/utils/index.ts +24 -0
- package/src/utils/password-crypto.test.ts +27 -0
- package/src/utils/password-crypto.ts +77 -0
- package/src/utils/transaction.test.ts +50 -0
- package/src/utils/transaction.ts +39 -0
- package/src/utils/utils.test.ts +160 -0
- package/src/utils/utils.ts +209 -0
- package/templates/{README.md → base/README.md} +4 -4
- package/templates/base/package.json +35 -0
- package/templates/base/src/greeter.ts +41 -0
- package/templates/base/tsconfig.json +19 -0
- package/templates/react/README.md +34 -0
- package/templates/react/config-overrides.js +18 -0
- package/templates/react/package.json +66 -0
- package/templates/react/src/App.tsx +42 -0
- package/templates/react/src/artifacts/greeter.ral.json +26 -0
- package/templates/react/src/artifacts/greeter_main.ral.json +22 -0
- package/templates/shared/.eslintrc.json +12 -0
- package/templates/shared/scripts/header.js +0 -0
- package/test/contract.test.ts +161 -0
- package/test/events.test.ts +139 -0
- package/webpack.config.js +1 -1
- package/contracts/greeter-main.ral +0 -8
- package/dist/cli/create-project.js +0 -87
- package/dist/lib/clique.d.ts +0 -23
- package/dist/lib/clique.js +0 -149
- package/dist/lib/contract.d.ts +0 -152
- package/dist/lib/contract.js +0 -711
- package/dist/lib/explorer.d.ts +0 -8
- package/dist/lib/explorer.js +0 -46
- package/dist/lib/index.d.ts +0 -12
- package/dist/lib/index.js +0 -60
- package/dist/lib/node.d.ts +0 -10
- package/dist/lib/node.js +0 -64
- package/dist/lib/numbers.d.ts +0 -7
- package/dist/lib/numbers.js +0 -128
- package/dist/lib/signer.d.ts +0 -17
- package/dist/lib/signer.js +0 -70
- package/dist/lib/storage-browser.d.ts +0 -9
- package/dist/lib/storage-browser.js +0 -52
- package/dist/lib/storage-node.d.ts +0 -9
- package/dist/lib/storage-node.js +0 -65
- package/dist/lib/utils.d.ts +0 -11
- package/dist/lib/wallet.d.ts +0 -30
- package/dist/lib/wallet.js +0 -142
- package/templates/package.json +0 -29
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright 2018 - 2022 The Alephium Authors
|
|
4
|
+
This file is part of the alephium project.
|
|
5
|
+
|
|
6
|
+
The library is free software: you can redistribute it and/or modify
|
|
7
|
+
it under the terms of the GNU Lesser General Public License as published by
|
|
8
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
(at your option) any later version.
|
|
10
|
+
|
|
11
|
+
The library is distributed in the hope that it will be useful,
|
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
GNU Lesser General Public License for more details.
|
|
15
|
+
|
|
16
|
+
You should have received a copy of the GNU Lesser General Public License
|
|
17
|
+
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
*/
|
|
19
|
+
const fetch = require('cross-fetch');
|
|
20
|
+
const process = require('process');
|
|
21
|
+
async function extractNodeVersionFromExplorer(explorerVersion) {
|
|
22
|
+
const url = `https://raw.githubusercontent.com/alephium/explorer-backend/v${explorerVersion}/project/Dependencies.scala`;
|
|
23
|
+
const response = await (await fetch(url)).text();
|
|
24
|
+
const regex = /val common = "[^"]+"/;
|
|
25
|
+
const matched = regex.exec(response)[0];
|
|
26
|
+
return matched.split('"')[1];
|
|
27
|
+
}
|
|
28
|
+
async function main() {
|
|
29
|
+
const nodeVersionConfigured = process.argv[2];
|
|
30
|
+
const explorerVersionConfigured = process.argv[3];
|
|
31
|
+
const nodeVersionExpected = await extractNodeVersionFromExplorer(explorerVersionConfigured);
|
|
32
|
+
if (nodeVersionExpected != nodeVersionConfigured) {
|
|
33
|
+
console.log(`Invalid node version: the configured explorer-backend version (${explorerVersionConfigured}) expects node ${nodeVersionExpected}.`);
|
|
34
|
+
console.log(`Instead, the configured node version is ${nodeVersionConfigured}`);
|
|
35
|
+
console.log('Please, check that the configured node and explorer-backend versions in the package.json are correct.');
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
main();
|
|
File without changes
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/*
|
|
4
|
+
Copyright 2018 - 2022 The Alephium Authors
|
|
5
|
+
This file is part of the alephium project.
|
|
6
|
+
|
|
7
|
+
The library is free software: you can redistribute it and/or modify
|
|
8
|
+
it under the terms of the GNU Lesser General Public License as published by
|
|
9
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
10
|
+
(at your option) any later version.
|
|
11
|
+
|
|
12
|
+
The library is distributed in the hope that it will be useful,
|
|
13
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
GNU Lesser General Public License for more details.
|
|
16
|
+
|
|
17
|
+
You should have received a copy of the GNU Lesser General Public License
|
|
18
|
+
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
19
|
+
*/
|
|
20
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
21
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
25
|
+
const process_1 = __importDefault(require("process"));
|
|
26
|
+
const path_1 = __importDefault(require("path"));
|
|
27
|
+
const find_up_1 = __importDefault(require("find-up"));
|
|
28
|
+
const child_process_1 = require("child_process");
|
|
29
|
+
const commander_1 = __importDefault(require("commander"));
|
|
30
|
+
function getPackageRoot() {
|
|
31
|
+
const packageJsonPath = find_up_1.default.sync('package.json', { cwd: path_1.default.dirname(__filename) });
|
|
32
|
+
if (packageJsonPath) {
|
|
33
|
+
return path_1.default.dirname(packageJsonPath);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
throw new Error('Cannot find `package.json`');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function extractProjectType(projectType) {
|
|
40
|
+
if (typeof projectType === 'undefined') {
|
|
41
|
+
return 'base';
|
|
42
|
+
}
|
|
43
|
+
else if (['base', 'react'].includes(projectType)) {
|
|
44
|
+
return projectType;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
console.log(`Invalid project type: ${projectType}, expect: base or react`);
|
|
48
|
+
process_1.default.exit(1);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function extractProjectRoot() {
|
|
52
|
+
const projectRoot = path_1.default.join(projectParent, projectName);
|
|
53
|
+
if (fs_extra_1.default.existsSync(projectRoot)) {
|
|
54
|
+
console.log(`Project ${projectName} already exists. Try a different name.`);
|
|
55
|
+
console.log();
|
|
56
|
+
process_1.default.exit(1);
|
|
57
|
+
}
|
|
58
|
+
return projectRoot;
|
|
59
|
+
}
|
|
60
|
+
function copy(dir, files) {
|
|
61
|
+
const packageDevDir = path_1.default.join(packageRoot, dir);
|
|
62
|
+
const projectDevDir = path_1.default.join(projectRoot, dir);
|
|
63
|
+
if (!fs_extra_1.default.existsSync(projectDevDir)) {
|
|
64
|
+
fs_extra_1.default.mkdirSync(projectDevDir);
|
|
65
|
+
}
|
|
66
|
+
for (const file of files) {
|
|
67
|
+
fs_extra_1.default.copyFileSync(path_1.default.join(packageDevDir, file), path_1.default.join(projectDevDir, file));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function prepareShared(packageRoot, projectRoot) {
|
|
71
|
+
console.log('Copying files');
|
|
72
|
+
console.log(` from ${packageRoot}`);
|
|
73
|
+
console.log(` to ${projectRoot}`);
|
|
74
|
+
console.log('...');
|
|
75
|
+
fs_extra_1.default.copySync(path_1.default.join(packageRoot, 'templates/shared'), projectRoot);
|
|
76
|
+
copy('', ['.editorconfig', '.eslintignore', '.gitattributes', 'LICENSE']);
|
|
77
|
+
copy('dev', ['user.conf']);
|
|
78
|
+
copy('scripts', ['start-devnet.js', 'stop-devnet.js']);
|
|
79
|
+
if (fs_extra_1.default.existsSync(path_1.default.join(packageRoot, 'gitignore'))) {
|
|
80
|
+
fs_extra_1.default.copySync(path_1.default.join(packageRoot, 'gitignore'), path_1.default.join(projectRoot, '.gitignore'));
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
fs_extra_1.default.copySync(path_1.default.join(packageRoot, '.gitignore'), path_1.default.join(projectRoot, '.gitignore'));
|
|
84
|
+
}
|
|
85
|
+
console.log();
|
|
86
|
+
}
|
|
87
|
+
function prepareBase(packageRoot, projectRoot) {
|
|
88
|
+
prepareShared(packageRoot, projectRoot);
|
|
89
|
+
copy('contracts', ['greeter.ral', 'greeter_interface.ral', 'greeter_main.ral']);
|
|
90
|
+
fs_extra_1.default.copySync(path_1.default.join(packageRoot, 'templates/base'), projectRoot);
|
|
91
|
+
}
|
|
92
|
+
function prepareReact(packageRoot, projectRoot, projectName) {
|
|
93
|
+
console.log('Creating the React app');
|
|
94
|
+
(0, child_process_1.execSync)(`npx create-react-app ${projectName} --template typescript`);
|
|
95
|
+
prepareShared(packageRoot, projectRoot);
|
|
96
|
+
fs_extra_1.default.copySync(path_1.default.join(packageRoot, 'templates/react'), projectRoot);
|
|
97
|
+
console.log('Initialize the project');
|
|
98
|
+
(0, child_process_1.execSync)('npm install --save-dev react-app-rewired crypto-browserify stream-browserify buffer process eslint-config-prettier eslint-plugin-header eslint-plugin-prettier eslint-plugin-react', { cwd: projectRoot });
|
|
99
|
+
(0, child_process_1.execSync)('npm install && npm run prettier', { cwd: projectRoot });
|
|
100
|
+
console.log();
|
|
101
|
+
}
|
|
102
|
+
const program = new commander_1.default.Command('Create sample project')
|
|
103
|
+
.arguments('<project-directory>')
|
|
104
|
+
.option('-t, --template <path-to-template>', 'specify a template for the project: either base or react')
|
|
105
|
+
.parse(process_1.default.argv);
|
|
106
|
+
const projectName = program.processedArgs[0];
|
|
107
|
+
const projectType = program.opts()['template'];
|
|
108
|
+
const packageRoot = getPackageRoot();
|
|
109
|
+
const projectParent = process_1.default.cwd();
|
|
110
|
+
const projectRoot = extractProjectRoot();
|
|
111
|
+
switch (extractProjectType(projectType)) {
|
|
112
|
+
case 'base':
|
|
113
|
+
prepareBase(packageRoot, projectRoot);
|
|
114
|
+
break;
|
|
115
|
+
case 'react':
|
|
116
|
+
prepareReact(packageRoot, projectRoot, projectName);
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
console.log('✅ Done.');
|
|
120
|
+
console.log();
|
|
121
|
+
console.log('✨ Project is initialized!');
|
|
122
|
+
console.log();
|
|
123
|
+
console.log(`Next step: checkout the readme under <${projectName}>`);
|
|
124
|
+
console.log();
|
|
File without changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright 2018 - 2022 The Alephium Authors
|
|
4
|
+
This file is part of the alephium project.
|
|
5
|
+
|
|
6
|
+
The library is free software: you can redistribute it and/or modify
|
|
7
|
+
it under the terms of the GNU Lesser General Public License as published by
|
|
8
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
(at your option) any later version.
|
|
10
|
+
|
|
11
|
+
The library is distributed in the hope that it will be useful,
|
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
GNU Lesser General Public License for more details.
|
|
15
|
+
|
|
16
|
+
You should have received a copy of the GNU Lesser General Public License
|
|
17
|
+
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright 2018 - 2022 The Alephium Authors
|
|
4
|
+
This file is part of the alephium project.
|
|
5
|
+
|
|
6
|
+
The library is free software: you can redistribute it and/or modify
|
|
7
|
+
it under the terms of the GNU Lesser General Public License as published by
|
|
8
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
(at your option) any later version.
|
|
10
|
+
|
|
11
|
+
The library is distributed in the hope that it will be useful,
|
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
GNU Lesser General Public License for more details.
|
|
15
|
+
|
|
16
|
+
You should have received a copy of the GNU Lesser General Public License
|
|
17
|
+
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
*/
|
|
19
|
+
const { rename } = require('fs');
|
|
20
|
+
rename(process.argv[2], process.argv[3], function (error) {
|
|
21
|
+
if (error)
|
|
22
|
+
console.log(error);
|
|
23
|
+
console.log(`Renamed ${process.argv[2]} to ${process.argv[3]}.`);
|
|
24
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright 2018 - 2022 The Alephium Authors
|
|
4
|
+
This file is part of the alephium project.
|
|
5
|
+
|
|
6
|
+
The library is free software: you can redistribute it and/or modify
|
|
7
|
+
it under the terms of the GNU Lesser General Public License as published by
|
|
8
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
(at your option) any later version.
|
|
10
|
+
|
|
11
|
+
The library is distributed in the hope that it will be useful,
|
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
GNU Lesser General Public License for more details.
|
|
15
|
+
|
|
16
|
+
You should have received a copy of the GNU Lesser General Public License
|
|
17
|
+
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
*/
|
|
19
|
+
const fs = require('fs');
|
|
20
|
+
const process = require('process');
|
|
21
|
+
const path = require('path');
|
|
22
|
+
const fetch = require('cross-fetch');
|
|
23
|
+
const spawn = require('child_process').spawn;
|
|
24
|
+
async function _downloadFullNode(tag, fileName) {
|
|
25
|
+
const url = `https://github.com/alephium/alephium/releases/download/v${tag}/alephium-${tag}.jar`;
|
|
26
|
+
const res0 = await fetch(url);
|
|
27
|
+
const fileUrl = res0.url;
|
|
28
|
+
const res1 = await fetch(fileUrl);
|
|
29
|
+
await new Promise((resolve) => {
|
|
30
|
+
console.log(`Downloading jar file to: ${fileName}`);
|
|
31
|
+
const file = fs.createWriteStream(fileName);
|
|
32
|
+
res1.body.pipe(file);
|
|
33
|
+
file.on('finish', function () {
|
|
34
|
+
resolve();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
async function downloadFullNode(tag, devDir, jarFile) {
|
|
39
|
+
if (!fs.existsSync(devDir)) {
|
|
40
|
+
fs.mkdirSync(devDir);
|
|
41
|
+
}
|
|
42
|
+
const jarExisted = fs.existsSync(jarFile);
|
|
43
|
+
if (!jarExisted) {
|
|
44
|
+
await _downloadFullNode(tag, jarFile);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function launchDevnet(devDir, jarFile) {
|
|
48
|
+
const pidFile = devDir + path.sep + 'alephium.pid';
|
|
49
|
+
try {
|
|
50
|
+
const pid = parseInt(fs.readFileSync(pidFile).toString());
|
|
51
|
+
if (pid) {
|
|
52
|
+
console.log(`Clearing the running devnet: ${pid}`);
|
|
53
|
+
process.kill(pid);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
console.log(`Error in clearing the running devnet: ${e}`);
|
|
58
|
+
}
|
|
59
|
+
fs.rmSync(devDir + path.sep + 'logs', { recursive: true, force: true });
|
|
60
|
+
fs.rmSync(devDir + path.sep + 'network-4', { recursive: true, force: true });
|
|
61
|
+
const p = spawn('java', ['-jar', jarFile], {
|
|
62
|
+
detached: true,
|
|
63
|
+
stdio: 'ignore',
|
|
64
|
+
env: { ...process.env, ALEPHIUM_HOME: devDir, ALEPHIUM_ENABLE_DEBUG_LOGGING: 'true' }
|
|
65
|
+
});
|
|
66
|
+
p.unref();
|
|
67
|
+
console.log(`Devnet is launching with pid: ${p.pid}`);
|
|
68
|
+
fs.writeFileSync(devDir + path.sep + 'alephium.pid', p.pid.toString(), { falg: 'w' });
|
|
69
|
+
}
|
|
70
|
+
const testWallet = 'alephium-web3-test-only-wallet';
|
|
71
|
+
const password = 'alph';
|
|
72
|
+
const mnemonic = 'vault alarm sad mass witness property virus style good flower rice alpha viable evidence run glare pretty scout evil judge enroll refuse another lava';
|
|
73
|
+
async function prepareWallet() {
|
|
74
|
+
const wallets = await fetch('http://127.0.0.1:22973/wallets', { method: 'Get' }).then((res) => res.json());
|
|
75
|
+
if (wallets.find((wallet) => wallet.walletName === testWallet)) {
|
|
76
|
+
unlockWallet();
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
createWallet();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async function createWallet() {
|
|
83
|
+
console.log('Create the test wallet');
|
|
84
|
+
await fetch('http://127.0.0.1:22973/wallets', {
|
|
85
|
+
method: 'Put',
|
|
86
|
+
body: `{"password":"${password}","mnemonic":"${mnemonic}","walletName":"${testWallet}"}`
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
async function unlockWallet() {
|
|
90
|
+
console.log('Unlock the test wallet');
|
|
91
|
+
await fetch('http://127.0.0.1:22973/wallets/alephium-web3-test-only-wallet/unlock', {
|
|
92
|
+
method: 'POST',
|
|
93
|
+
body: '{ "password": "alph" }'
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
function timeout(ms) {
|
|
97
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
98
|
+
}
|
|
99
|
+
async function wait() {
|
|
100
|
+
console.log('...');
|
|
101
|
+
try {
|
|
102
|
+
const res = await fetch('http://127.0.0.1:22973/infos/node', { method: 'Get' });
|
|
103
|
+
if (res.status != 200) {
|
|
104
|
+
await timeout(1000);
|
|
105
|
+
await wait();
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
console.log('Devnet is ready');
|
|
109
|
+
await timeout(1000);
|
|
110
|
+
new Promise((resolve) => {
|
|
111
|
+
resolve();
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
catch (err) {
|
|
116
|
+
await timeout(1000);
|
|
117
|
+
await wait();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
async function main() {
|
|
121
|
+
const tag = process.argv[2];
|
|
122
|
+
console.log(`Full node version: ${tag}`);
|
|
123
|
+
const devDir = path.resolve(process.cwd() + path.sep + 'dev');
|
|
124
|
+
const jarFile = `${devDir}${path.sep}alephium-${tag}.jar`;
|
|
125
|
+
console.log(`Dev folder: ${devDir}`);
|
|
126
|
+
await downloadFullNode(tag, devDir, jarFile);
|
|
127
|
+
launchDevnet(devDir, jarFile);
|
|
128
|
+
await wait();
|
|
129
|
+
await prepareWallet();
|
|
130
|
+
}
|
|
131
|
+
main();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright 2018 - 2022 The Alephium Authors
|
|
4
|
+
This file is part of the alephium project.
|
|
5
|
+
|
|
6
|
+
The library is free software: you can redistribute it and/or modify
|
|
7
|
+
it under the terms of the GNU Lesser General Public License as published by
|
|
8
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
(at your option) any later version.
|
|
10
|
+
|
|
11
|
+
The library is distributed in the hope that it will be useful,
|
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
GNU Lesser General Public License for more details.
|
|
15
|
+
|
|
16
|
+
You should have received a copy of the GNU Lesser General Public License
|
|
17
|
+
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
*/
|
|
19
|
+
const fs = require('fs');
|
|
20
|
+
const process = require('process');
|
|
21
|
+
const path = require('path');
|
|
22
|
+
const pidFile = process.cwd() + path.sep + 'dev' + path.sep + 'alephium.pid';
|
|
23
|
+
try {
|
|
24
|
+
const pid = parseInt(fs.readFileSync(pidFile).toString());
|
|
25
|
+
if (pid) {
|
|
26
|
+
console.log(`Stopping the running devnet: ${pid}`);
|
|
27
|
+
process.kill(pid);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
console.log(`Error in stopping the running devnet: ${e}`);
|
|
32
|
+
}
|