@airmoney-degn/airmoney-cli 0.16.2 → 0.18.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/dist/cli/create.js +48 -58
- package/dist/cli/dapp.js +97 -0
- package/dist/cli/demo.js +34 -28
- package/dist/cli/setup.js +21 -11
- package/dist/cli/upload.js +70 -63
- package/dist/cli/wallet.js +46 -30
- package/dist/config.json +1 -1
- package/dist/index.js +26 -11
- package/dist/service/airmoney/AirmoneyService.js +3 -2
- package/dist/service/dapp/DappService.js +162 -0
- package/dist/service/log/LogService.js +85 -0
- package/dist/service/port/PortManager.js +5 -4
- package/dist/service/serve/ServeOrchestrator.js +2 -1
- package/dist/service/simulator/BaseSimulatorService.js +5 -4
- package/dist/util/cryptoProcess.js +22 -21
- package/dist/util/env.js +44 -0
- package/dist/util/format.js +74 -0
- package/dist/util/metadata.js +3 -2
- package/dist/util/network.js +43 -0
- package/dist/util/tarball.js +6 -5
- package/package.json +3 -2
package/dist/cli/create.js
CHANGED
|
@@ -38,41 +38,27 @@ const fs = __importStar(require("fs"));
|
|
|
38
38
|
const path = __importStar(require("path"));
|
|
39
39
|
const types_1 = require("../types");
|
|
40
40
|
const child_process_1 = require("child_process");
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
// if (!ignoreEnvValidation) {
|
|
58
|
-
// console.log(`Using .env user: ${userId}`);
|
|
59
|
-
// }
|
|
60
|
-
const folderName = locationFolder || name;
|
|
61
|
-
const projectPath = path.join(process.cwd(), folderName);
|
|
62
|
-
if (template) {
|
|
63
|
-
console.log('cloning project');
|
|
64
|
-
(0, child_process_1.execSync)(`git clone --separate-git-dir=$(mktemp -u) https://github.com/Air-Money/airmoney-dapp-quickstart ${folderName}`);
|
|
65
|
-
if (fs.lstatSync(path.join(projectPath, '.git')).isDirectory()) {
|
|
66
|
-
fs.rmdirSync(path.join(projectPath, '.git'));
|
|
41
|
+
const LogService_1 = require("../service/log/LogService");
|
|
42
|
+
async function createCommand({ name, template, locationFolder, quiet, }) {
|
|
43
|
+
try {
|
|
44
|
+
const identifier = `com.degn.${name}`;
|
|
45
|
+
(0, LogService_1.log)(`Initializing project: ${name}`).white();
|
|
46
|
+
const folderName = locationFolder || name;
|
|
47
|
+
const projectPath = path.join(process.cwd(), folderName);
|
|
48
|
+
if (template) {
|
|
49
|
+
(0, LogService_1.log)('cloning project').white();
|
|
50
|
+
(0, child_process_1.execSync)(`git clone --separate-git-dir=$(mktemp -u) https://github.com/Air-Money/airmoney-dapp-quickstart ${folderName}`);
|
|
51
|
+
if (fs.lstatSync(path.join(projectPath, '.git')).isDirectory()) {
|
|
52
|
+
fs.rmdirSync(path.join(projectPath, '.git'));
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
fs.rmSync(path.join(projectPath, '.git'));
|
|
56
|
+
}
|
|
67
57
|
}
|
|
68
58
|
else {
|
|
69
|
-
fs.
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
else {
|
|
73
|
-
fs.mkdirSync(projectPath, { recursive: true });
|
|
74
|
-
// replicate Rust logic
|
|
75
|
-
const indexHtml = `
|
|
59
|
+
fs.mkdirSync(projectPath, { recursive: true });
|
|
60
|
+
// replicate Rust logic
|
|
61
|
+
const indexHtml = `
|
|
76
62
|
<html>
|
|
77
63
|
<head>
|
|
78
64
|
<title>Sample ${name}</title>
|
|
@@ -82,32 +68,36 @@ async function createCommand({ name, template, locationFolder, quiet,
|
|
|
82
68
|
</body>
|
|
83
69
|
</html>
|
|
84
70
|
`.trim();
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
// metadata
|
|
93
|
-
const pkg = (0, types_1.createPackage)(name, identifier);
|
|
94
|
-
const metaStr = JSON.stringify(pkg, null, 2);
|
|
95
|
-
fs.writeFileSync(path.join(projectPath, 'metadata.json'), metaStr, 'utf8');
|
|
96
|
-
console.log(`Project '${name}' created successfully.`);
|
|
97
|
-
if (!quiet) {
|
|
98
|
-
console.log(`\nNext steps:`);
|
|
99
|
-
console.log(` cd ${name}`);
|
|
100
|
-
if (template) {
|
|
101
|
-
console.log(' npm install');
|
|
102
|
-
console.log('\n- Development mode:');
|
|
103
|
-
console.log(' npm run dev');
|
|
104
|
-
console.log(' airmoney-cli serve -u http://localhost:5173');
|
|
105
|
-
console.log('\n- Production build:');
|
|
106
|
-
console.log(' npm run build');
|
|
107
|
-
console.log(' airmoney-cli serve -f dist');
|
|
71
|
+
fs.writeFileSync(path.join(projectPath, 'index.html'), indexHtml, 'utf8');
|
|
72
|
+
// assets
|
|
73
|
+
const assetsDir = path.join(projectPath, 'assets');
|
|
74
|
+
fs.mkdirSync(assetsDir, { recursive: true });
|
|
75
|
+
fs.writeFileSync(path.join(assetsDir, 'main.js'), '// sample main.js\n', 'utf8');
|
|
76
|
+
fs.writeFileSync(path.join(assetsDir, 'style.css'), '/* sample style.css */\n', 'utf8');
|
|
108
77
|
}
|
|
109
|
-
|
|
110
|
-
|
|
78
|
+
// metadata
|
|
79
|
+
const pkg = (0, types_1.createPackage)(name, identifier);
|
|
80
|
+
const metaStr = JSON.stringify(pkg, null, 2);
|
|
81
|
+
fs.writeFileSync(path.join(projectPath, 'metadata.json'), metaStr, 'utf8');
|
|
82
|
+
(0, LogService_1.log)(`Project '${name}' created successfully.`).green();
|
|
83
|
+
if (!quiet) {
|
|
84
|
+
(0, LogService_1.log)(`\nNext steps:`).white();
|
|
85
|
+
(0, LogService_1.log)(` cd ${name}`).white();
|
|
86
|
+
if (template) {
|
|
87
|
+
(0, LogService_1.log)(' npm install').white();
|
|
88
|
+
(0, LogService_1.log)('\n- Development mode:').white();
|
|
89
|
+
(0, LogService_1.log)(' npm run dev').white();
|
|
90
|
+
(0, LogService_1.log)(' airmoney-cli serve -u http://localhost:5173').white();
|
|
91
|
+
(0, LogService_1.log)('\n- Production build:').white();
|
|
92
|
+
(0, LogService_1.log)(' npm run build').white();
|
|
93
|
+
(0, LogService_1.log)(' airmoney-cli serve -f dist').white();
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
(0, LogService_1.log)(' airmoney-cli serve').white();
|
|
97
|
+
}
|
|
111
98
|
}
|
|
112
99
|
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
(0, LogService_1.log)(`${err instanceof Error ? err.message : String(err)}`).red();
|
|
102
|
+
}
|
|
113
103
|
}
|
package/dist/cli/dapp.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dappStatusCommand = dappStatusCommand;
|
|
4
|
+
const env_1 = require("../util/env");
|
|
5
|
+
const format_1 = require("../util/format");
|
|
6
|
+
const LogService_1 = require("../service/log/LogService");
|
|
7
|
+
const DappService_1 = require("../service/dapp/DappService");
|
|
8
|
+
async function dappStatusCommand() {
|
|
9
|
+
try {
|
|
10
|
+
const { userId, apiKey, rpc } = (0, env_1.validateCredential)();
|
|
11
|
+
(0, LogService_1.log)(`User: ${(0, format_1.shortenString)(userId)}`).white();
|
|
12
|
+
(0, LogService_1.log)(`Network: ${rpc || ''}`).white();
|
|
13
|
+
const dappService = new DappService_1.DappService(userId, apiKey, rpc);
|
|
14
|
+
await dappService.validateApiKey();
|
|
15
|
+
// Fetch dapp list
|
|
16
|
+
const dapps = await dappService.fetchDappList();
|
|
17
|
+
if (dapps.length === 0) {
|
|
18
|
+
(0, LogService_1.log)('You have not registered any dapps yet').green();
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
(0, LogService_1.log)(`Found ${dapps.length} dapp(s)`).green();
|
|
22
|
+
// Fetch details for each dapp
|
|
23
|
+
for (let i = 0; i < dapps.length; i++) {
|
|
24
|
+
const dappName = dapps[i];
|
|
25
|
+
// log(`\nDapp ${i + 1}: ${dappName}`)
|
|
26
|
+
// .bold()
|
|
27
|
+
// .white();
|
|
28
|
+
// log('─'.repeat(80)).white();
|
|
29
|
+
try {
|
|
30
|
+
// Fetch versions/builds with metadata
|
|
31
|
+
const buildsWithMeta = await dappService.fetchDappDetails(dappName);
|
|
32
|
+
if (buildsWithMeta.length === 0) {
|
|
33
|
+
(0, LogService_1.log)(' No builds found for this dapp').italic().white();
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
// Define column widths (Status needs to be wider to accommodate "Waiting", "Pending", etc.)
|
|
37
|
+
const widths = [20, 10, 15, 20, 15, 16, 15];
|
|
38
|
+
const headers = [
|
|
39
|
+
'Name',
|
|
40
|
+
'Version',
|
|
41
|
+
'Author',
|
|
42
|
+
'Identifier',
|
|
43
|
+
'Maintainer',
|
|
44
|
+
'Digest',
|
|
45
|
+
'Status',
|
|
46
|
+
];
|
|
47
|
+
// Print table header
|
|
48
|
+
// log('').white();
|
|
49
|
+
(0, format_1.printTableRow)(headers, widths, true);
|
|
50
|
+
(0, format_1.printSeparator)(widths);
|
|
51
|
+
// Print table rows
|
|
52
|
+
buildsWithMeta.forEach(build => {
|
|
53
|
+
const digest = build.package_digest || 'N/A';
|
|
54
|
+
const shortenedDigest = (0, format_1.shortenString)(digest);
|
|
55
|
+
// Color code status
|
|
56
|
+
const status = build.status || 'N/A';
|
|
57
|
+
let statusText = status;
|
|
58
|
+
let statusColor = '';
|
|
59
|
+
let statusReset = '';
|
|
60
|
+
if (status === 'Active') {
|
|
61
|
+
statusColor = '\x1b[32m'; // Green
|
|
62
|
+
statusReset = '\x1b[0m';
|
|
63
|
+
}
|
|
64
|
+
else if (status === 'Pending') {
|
|
65
|
+
statusColor = '\x1b[33m'; // Yellow
|
|
66
|
+
statusReset = '\x1b[0m';
|
|
67
|
+
}
|
|
68
|
+
else if (status === 'Waiting') {
|
|
69
|
+
statusColor = '\x1b[36m'; // Cyan
|
|
70
|
+
statusReset = '\x1b[0m';
|
|
71
|
+
}
|
|
72
|
+
else if (status === 'Rejected') {
|
|
73
|
+
statusColor = '\x1b[31m'; // Red
|
|
74
|
+
statusReset = '\x1b[0m';
|
|
75
|
+
}
|
|
76
|
+
const row = [
|
|
77
|
+
build.name || 'N/A',
|
|
78
|
+
build.version || 'N/A',
|
|
79
|
+
build.author || 'N/A',
|
|
80
|
+
build.identifier || 'N/A',
|
|
81
|
+
build.maintainer || 'N/A',
|
|
82
|
+
shortenedDigest,
|
|
83
|
+
statusColor + statusText + statusReset,
|
|
84
|
+
];
|
|
85
|
+
(0, format_1.printTableRow)(row, widths);
|
|
86
|
+
});
|
|
87
|
+
// log('').white();
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
(0, LogService_1.log)(`Error fetching versions: ${err instanceof Error ? err.message : String(err)}`).red();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
(0, LogService_1.log)(`${err instanceof Error ? err.message : String(err)}`).red();
|
|
96
|
+
}
|
|
97
|
+
}
|
package/dist/cli/demo.js
CHANGED
|
@@ -38,35 +38,41 @@ const path = __importStar(require("path"));
|
|
|
38
38
|
const child_process_1 = require("child_process");
|
|
39
39
|
const create_1 = require("./create");
|
|
40
40
|
const serve_1 = require("./serve");
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const folderName = appPath || projectName;
|
|
44
|
-
const projectPath = path.join(process.cwd(), folderName);
|
|
45
|
-
await (0, create_1.createCommand)({
|
|
46
|
-
name: projectName,
|
|
47
|
-
template: true,
|
|
48
|
-
locationFolder: appPath,
|
|
49
|
-
quiet: true,
|
|
50
|
-
// ignoreEnvValidation: true,
|
|
51
|
-
});
|
|
41
|
+
const LogService_1 = require("../service/log/LogService");
|
|
42
|
+
async function demoCommand({ name = "degn-demo", appPath }) {
|
|
52
43
|
try {
|
|
53
|
-
|
|
54
|
-
|
|
44
|
+
const projectName = name;
|
|
45
|
+
const folderName = appPath || projectName;
|
|
46
|
+
const projectPath = path.join(process.cwd(), folderName);
|
|
47
|
+
await (0, create_1.createCommand)({
|
|
48
|
+
name: projectName,
|
|
49
|
+
template: true,
|
|
50
|
+
locationFolder: appPath,
|
|
51
|
+
quiet: true,
|
|
52
|
+
// ignoreEnvValidation: true,
|
|
53
|
+
});
|
|
54
|
+
try {
|
|
55
|
+
(0, LogService_1.log)('Installing dependencies...').white();
|
|
56
|
+
(0, child_process_1.execSync)('npm install', { cwd: projectPath, stdio: 'inherit' });
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
(0, LogService_1.log)('Failed to install dependencies').red();
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
(0, LogService_1.log)('Starting dev server...').white();
|
|
63
|
+
const devProc = (0, child_process_1.spawn)('npm', ['run', 'dev'], {
|
|
64
|
+
cwd: projectPath,
|
|
65
|
+
stdio: 'inherit',
|
|
66
|
+
shell: process.platform === 'win32',
|
|
67
|
+
});
|
|
68
|
+
devProc.on('error', err => {
|
|
69
|
+
(0, LogService_1.log)(`Failed to start dev server: ${err}`).red();
|
|
70
|
+
});
|
|
71
|
+
// Give the dev server a moment to boot; default Vite port is 5173
|
|
72
|
+
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
73
|
+
await (0, serve_1.serveCommand)({ noBrowser: false, locationFolder: undefined, appUrl: 'http://localhost:5173' });
|
|
55
74
|
}
|
|
56
|
-
catch (
|
|
57
|
-
|
|
58
|
-
return;
|
|
75
|
+
catch (err) {
|
|
76
|
+
(0, LogService_1.log)(`${err instanceof Error ? err.message : String(err)}`).red();
|
|
59
77
|
}
|
|
60
|
-
console.log('Starting dev server...');
|
|
61
|
-
const devProc = (0, child_process_1.spawn)('npm', ['run', 'dev'], {
|
|
62
|
-
cwd: projectPath,
|
|
63
|
-
stdio: 'inherit',
|
|
64
|
-
shell: process.platform === 'win32',
|
|
65
|
-
});
|
|
66
|
-
devProc.on('error', err => {
|
|
67
|
-
console.error('Failed to start dev server:', err);
|
|
68
|
-
});
|
|
69
|
-
// Give the dev server a moment to boot; default Vite port is 5173
|
|
70
|
-
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
71
|
-
await (0, serve_1.serveCommand)({ noBrowser: false, locationFolder: undefined, appUrl: 'http://localhost:5173' });
|
|
72
78
|
}
|
package/dist/cli/setup.js
CHANGED
|
@@ -37,20 +37,30 @@ exports.setupCommand = setupCommand;
|
|
|
37
37
|
const fs = __importStar(require("fs"));
|
|
38
38
|
const path = __importStar(require("path"));
|
|
39
39
|
const env_1 = require("../util/env");
|
|
40
|
+
const LogService_1 = require("../service/log/LogService");
|
|
40
41
|
async function setupCommand({ network, userId, apiKey, }) {
|
|
41
|
-
const dir = (0, env_1.configDir)();
|
|
42
|
-
if (!dir)
|
|
43
|
-
return;
|
|
44
|
-
// ensure directory
|
|
45
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
46
|
-
const envPath = path.join(dir, '.env');
|
|
47
42
|
try {
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
const dir = (0, env_1.configDir)();
|
|
44
|
+
if (!dir)
|
|
45
|
+
return;
|
|
46
|
+
// ensure directory
|
|
47
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
48
|
+
const envPath = path.join(dir, '.env');
|
|
49
|
+
try {
|
|
50
|
+
let envContent = `DEVELOPER_ADDRESS=${userId}\nAPI_KEY=${apiKey}\n`;
|
|
51
|
+
if (network) {
|
|
52
|
+
envContent += `RPC=${network}\n`;
|
|
53
|
+
}
|
|
54
|
+
fs.writeFileSync(envPath, envContent, 'utf8');
|
|
55
|
+
(0, LogService_1.log)(`.env created at ${envPath}`).white();
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
(0, LogService_1.log)(`error when writing .env to ${envPath}`).red();
|
|
59
|
+
(0, LogService_1.log)(String(err)).red();
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
50
62
|
}
|
|
51
63
|
catch (err) {
|
|
52
|
-
|
|
53
|
-
console.error(err);
|
|
54
|
-
process.exit(1);
|
|
64
|
+
(0, LogService_1.log)(`${err instanceof Error ? err.message : String(err)}`).red();
|
|
55
65
|
}
|
|
56
66
|
}
|
package/dist/cli/upload.js
CHANGED
|
@@ -42,76 +42,83 @@ const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
|
42
42
|
const md5_1 = __importDefault(require("md5")); // default import fixes TS call
|
|
43
43
|
const metadata_1 = require("../util/metadata");
|
|
44
44
|
const tarball_1 = require("../util/tarball");
|
|
45
|
+
const network_1 = require("../util/network");
|
|
46
|
+
const env_1 = require("../util/env");
|
|
47
|
+
const LogService_1 = require("../service/log/LogService");
|
|
45
48
|
const path_1 = __importDefault(require("path"));
|
|
46
49
|
async function uploadCommand({ network, locationFolder, buttonImages, }) {
|
|
47
|
-
console.log('Loading metadata...');
|
|
48
|
-
const userId = process.env.DEVELOPER_ADDRESS || '';
|
|
49
|
-
const apiKey = process.env.API_KEY || '';
|
|
50
|
-
console.log('User ID:', userId);
|
|
51
|
-
if (!userId || !apiKey) {
|
|
52
|
-
console.error("Missing user or API key from env. Did you run 'airmoney-cli setup'?");
|
|
53
|
-
process.exit(1);
|
|
54
|
-
}
|
|
55
|
-
let projectPath = process.cwd();
|
|
56
|
-
if (locationFolder != undefined) {
|
|
57
|
-
projectPath = path_1.default.join(projectPath, locationFolder);
|
|
58
|
-
}
|
|
59
|
-
if (buttonImages === undefined) {
|
|
60
|
-
buttonImages = 'assets';
|
|
61
|
-
}
|
|
62
|
-
console.log(buttonImages);
|
|
63
|
-
const meta = (0, metadata_1.loadMetadata)();
|
|
64
|
-
if (!meta) {
|
|
65
|
-
console.error('No metadata.json found. Aborting.');
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
const pkgName = (0, metadata_1.getPackageName)(meta);
|
|
69
|
-
console.log(`Packing ${pkgName}...`);
|
|
70
|
-
await (0, tarball_1.packProject)(meta, projectPath, buttonImages);
|
|
71
|
-
const pkgPath = path_1.default.join(process.cwd(), pkgName);
|
|
72
|
-
// read tar
|
|
73
|
-
const fileBuffer = fs.readFileSync(pkgPath);
|
|
74
|
-
const fileHash = (0, md5_1.default)(fileBuffer);
|
|
75
|
-
console.log('Package Hash:', fileHash);
|
|
76
|
-
console.log('Publishing package to DEGN Dapp Store...');
|
|
77
|
-
// encode base64
|
|
78
|
-
const encoded = Buffer.from(fileBuffer).toString('base64');
|
|
79
|
-
// In Rust, we do a JSON-RPC call. Let's replicate:
|
|
80
|
-
const metaJson = JSON.stringify(meta);
|
|
81
|
-
const body = JSON.stringify({
|
|
82
|
-
jsonrpc: '2.0',
|
|
83
|
-
id: 1,
|
|
84
|
-
method: 'uploadPackage',
|
|
85
|
-
params: [userId, apiKey, metaJson, encoded],
|
|
86
|
-
});
|
|
87
50
|
try {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
else {
|
|
105
|
-
console.error('Error uploding package');
|
|
106
|
-
if (json.error.code == -32602) {
|
|
107
|
-
console.error('invalid api key, please visit https://dash-devnet.air.fun/ and setup env with the new key');
|
|
51
|
+
if ((0, network_1.validateNetwork)(network)) {
|
|
52
|
+
(0, LogService_1.log)('Loading metadata...').white();
|
|
53
|
+
const credentials = (0, env_1.validateCredential)();
|
|
54
|
+
const { userId, apiKey } = credentials;
|
|
55
|
+
(0, LogService_1.log)(`User ID: ${userId}`).white();
|
|
56
|
+
let projectPath = process.cwd();
|
|
57
|
+
if (locationFolder != undefined) {
|
|
58
|
+
projectPath = path_1.default.join(projectPath, locationFolder);
|
|
59
|
+
}
|
|
60
|
+
if (buttonImages === undefined) {
|
|
61
|
+
buttonImages = 'assets';
|
|
62
|
+
}
|
|
63
|
+
(0, LogService_1.log)(buttonImages).white();
|
|
64
|
+
const meta = (0, metadata_1.loadMetadata)();
|
|
65
|
+
if (!meta) {
|
|
66
|
+
(0, LogService_1.log)('No metadata.json found. Aborting.').red();
|
|
108
67
|
return;
|
|
109
68
|
}
|
|
110
|
-
|
|
111
|
-
|
|
69
|
+
const pkgName = (0, metadata_1.getPackageName)(meta);
|
|
70
|
+
(0, LogService_1.log)(`Packing ${pkgName}...`).white();
|
|
71
|
+
await (0, tarball_1.packProject)(meta, projectPath, buttonImages);
|
|
72
|
+
const pkgPath = path_1.default.join(process.cwd(), pkgName);
|
|
73
|
+
// read tar
|
|
74
|
+
const fileBuffer = fs.readFileSync(pkgPath);
|
|
75
|
+
const fileHash = (0, md5_1.default)(fileBuffer);
|
|
76
|
+
(0, LogService_1.log)(`Package Hash: ${fileHash}`).white();
|
|
77
|
+
(0, LogService_1.log)('Publishing package to DEGN Dapp Store...').white();
|
|
78
|
+
// encode base64
|
|
79
|
+
const encoded = Buffer.from(fileBuffer).toString('base64');
|
|
80
|
+
// In Rust, we do a JSON-RPC call. Let's replicate:
|
|
81
|
+
const metaJson = JSON.stringify(meta);
|
|
82
|
+
const body = JSON.stringify({
|
|
83
|
+
jsonrpc: '2.0',
|
|
84
|
+
id: 1,
|
|
85
|
+
method: 'uploadPackage',
|
|
86
|
+
params: [userId, apiKey, metaJson, encoded],
|
|
87
|
+
});
|
|
88
|
+
try {
|
|
89
|
+
const rpcUrl = (0, network_1.networkToRpcUrl)(network);
|
|
90
|
+
const res = await (0, node_fetch_1.default)(rpcUrl, {
|
|
91
|
+
method: 'POST',
|
|
92
|
+
body,
|
|
93
|
+
headers: {
|
|
94
|
+
'Content-Type': 'application/json',
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
if (!res.ok) {
|
|
98
|
+
(0, LogService_1.log)(`Error uploading package: ${await res.text()}`).red();
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const json = await res.json();
|
|
102
|
+
if (json.result === true) {
|
|
103
|
+
(0, LogService_1.log)('Package uploaded successfully').green();
|
|
104
|
+
(0, LogService_1.log)('Open : https://dash-devnet.air.fun/').white();
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
(0, LogService_1.log)('Error uploding package').red();
|
|
108
|
+
if (json.error.code == -32602) {
|
|
109
|
+
(0, LogService_1.log)('invalid api key, please visit https://dash-devnet.air.fun/ and setup env with the new key').red();
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
(0, LogService_1.log)('unknow error, please contact support').red();
|
|
113
|
+
(0, LogService_1.log)(JSON.stringify(json.error)).red();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
catch (err) {
|
|
117
|
+
(0, LogService_1.log)(`Error: ${err}`).red();
|
|
118
|
+
}
|
|
112
119
|
}
|
|
113
120
|
}
|
|
114
121
|
catch (err) {
|
|
115
|
-
|
|
122
|
+
(0, LogService_1.log)(`${err instanceof Error ? err.message : String(err)}`).red();
|
|
116
123
|
}
|
|
117
124
|
}
|
package/dist/cli/wallet.js
CHANGED
|
@@ -51,16 +51,22 @@ const ethers_1 = require("ethers");
|
|
|
51
51
|
const bs58 = __importStar(require("bs58"));
|
|
52
52
|
const web3_js_1 = require("@solana/web3.js");
|
|
53
53
|
const cryptoProcess_1 = require("../util/cryptoProcess");
|
|
54
|
+
const LogService_1 = require("../service/log/LogService");
|
|
54
55
|
async function deleteWallet(address, chainName) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
56
|
+
try {
|
|
57
|
+
const config = (0, env_1.configDir)();
|
|
58
|
+
const walletPath = path_1.default.join(config, chainName);
|
|
59
|
+
const files = (0, fs_1.readdirSync)(walletPath).filter(file => file == address + '.json');
|
|
60
|
+
if (files.length == 0) {
|
|
61
|
+
(0, LogService_1.log)('Wallet not found').white();
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const walletFile = path_1.default.join(walletPath, files[0]);
|
|
65
|
+
(0, fs_1.rmSync)(walletFile);
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
(0, LogService_1.log)(`${err instanceof Error ? err.message : String(err)}`).red();
|
|
69
|
+
}
|
|
64
70
|
}
|
|
65
71
|
async function listWallet(chainName) {
|
|
66
72
|
try {
|
|
@@ -78,22 +84,27 @@ async function listWallet(chainName) {
|
|
|
78
84
|
});
|
|
79
85
|
// Display wallets
|
|
80
86
|
wallets.wallets.forEach((address) => {
|
|
81
|
-
|
|
87
|
+
(0, LogService_1.log)(address).white();
|
|
82
88
|
});
|
|
83
89
|
return wallets;
|
|
84
90
|
}
|
|
85
91
|
catch (error) {
|
|
86
|
-
|
|
92
|
+
(0, LogService_1.log)(`Failed to list wallets: ${error instanceof Error ? error.message : String(error)}`).red();
|
|
87
93
|
throw error;
|
|
88
94
|
}
|
|
89
95
|
}
|
|
90
96
|
async function importWalletSk(PrivateKey, chainName) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
97
|
+
try {
|
|
98
|
+
(0, cryptoProcess_1.ensureWalletDirectory)(chainName);
|
|
99
|
+
if (chainName == 'evm') {
|
|
100
|
+
await importEvmWallet(PrivateKey);
|
|
101
|
+
}
|
|
102
|
+
else if (chainName == 'svm') {
|
|
103
|
+
await importSvmWallet(PrivateKey);
|
|
104
|
+
}
|
|
94
105
|
}
|
|
95
|
-
|
|
96
|
-
|
|
106
|
+
catch (err) {
|
|
107
|
+
(0, LogService_1.log)(`${err instanceof Error ? err.message : String(err)}`).red();
|
|
97
108
|
}
|
|
98
109
|
}
|
|
99
110
|
async function importEvmWallet(PrivateKey) {
|
|
@@ -117,17 +128,22 @@ async function importSvmWallet(privateKey) {
|
|
|
117
128
|
}, null, 2));
|
|
118
129
|
}
|
|
119
130
|
async function exportWalletSk(address, chainName) {
|
|
120
|
-
const walletPath = (0, cryptoProcess_1.ensureWalletDirectory)(chainName);
|
|
121
|
-
let walletFile;
|
|
122
131
|
try {
|
|
123
|
-
|
|
132
|
+
const walletPath = (0, cryptoProcess_1.ensureWalletDirectory)(chainName);
|
|
133
|
+
let walletFile;
|
|
134
|
+
try {
|
|
135
|
+
walletFile = (0, fs_1.readFileSync)(path_1.default.join(walletPath, address + '.json'));
|
|
136
|
+
}
|
|
137
|
+
catch (e) {
|
|
138
|
+
(0, LogService_1.log)('Wallet not found').white();
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const wallet = JSON.parse(walletFile.toString());
|
|
142
|
+
(0, LogService_1.log)(wallet.private_key).white();
|
|
124
143
|
}
|
|
125
|
-
catch (
|
|
126
|
-
|
|
127
|
-
return;
|
|
144
|
+
catch (err) {
|
|
145
|
+
(0, LogService_1.log)(`${err instanceof Error ? err.message : String(err)}`).red();
|
|
128
146
|
}
|
|
129
|
-
const wallet = JSON.parse(walletFile.toString());
|
|
130
|
-
console.log(wallet.private_key);
|
|
131
147
|
}
|
|
132
148
|
async function generateWallet(chainName) {
|
|
133
149
|
try {
|
|
@@ -143,11 +159,11 @@ async function generateWallet(chainName) {
|
|
|
143
159
|
throw new Error(`Unsupported chain: ${chainName}`);
|
|
144
160
|
}
|
|
145
161
|
});
|
|
146
|
-
|
|
162
|
+
(0, LogService_1.log)(`Generated ${chainName} wallet: ${walletData.address}`).green();
|
|
147
163
|
return walletData;
|
|
148
164
|
}
|
|
149
165
|
catch (error) {
|
|
150
|
-
|
|
166
|
+
(0, LogService_1.log)(`Failed to generate wallet: ${error instanceof Error ? error.message : String(error)}`).red();
|
|
151
167
|
throw error;
|
|
152
168
|
}
|
|
153
169
|
}
|
|
@@ -165,10 +181,10 @@ async function setDefaultWallet(address, chainName) {
|
|
|
165
181
|
throw new Error(`Unsupported chain: ${chainName}`);
|
|
166
182
|
}
|
|
167
183
|
});
|
|
168
|
-
|
|
184
|
+
(0, LogService_1.log)(`Set ${chainName} default wallet to: ${address}`).green();
|
|
169
185
|
}
|
|
170
186
|
catch (error) {
|
|
171
|
-
|
|
187
|
+
(0, LogService_1.log)(`Failed to set default wallet: ${error instanceof Error ? error.message : String(error)}`).red();
|
|
172
188
|
throw error;
|
|
173
189
|
}
|
|
174
190
|
}
|
|
@@ -186,11 +202,11 @@ async function getDefaultWallet(chainName) {
|
|
|
186
202
|
throw new Error(`Unsupported chain: ${chainName}`);
|
|
187
203
|
}
|
|
188
204
|
});
|
|
189
|
-
|
|
205
|
+
(0, LogService_1.log)(`Default ${chainName} wallet: ${walletData.address}`).white();
|
|
190
206
|
return walletData;
|
|
191
207
|
}
|
|
192
208
|
catch (error) {
|
|
193
|
-
|
|
209
|
+
(0, LogService_1.log)(`Failed to get default wallet: ${error instanceof Error ? error.message : String(error)}`).red();
|
|
194
210
|
throw error;
|
|
195
211
|
}
|
|
196
212
|
}
|
package/dist/config.json
CHANGED