Skip to content

Commit 594df8c

Browse files
authored
v2.3.0 (#31)
2 parents 5e36901 + 9c8171f commit 594df8c

File tree

8 files changed

+69
-11
lines changed

8 files changed

+69
-11
lines changed

bin/adamant.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import prompt from '../prompt/index.js';
1212
import { log } from '../utils/log.js';
1313
import config from '../utils/config.js';
1414

15-
import packageInfo from '../package.json' assert { type: 'json' };
15+
import { packageInfo } from '../utils/package.js';
16+
17+
import installInitCommand from './init.js';
1618

1719
import installAccountCommands from '../lib/account.js';
1820
import installGetCommands from '../lib/get.js';
@@ -78,6 +80,7 @@ installSendCommands(program);
7880
installRpcServerCommands(program);
7981
installDelegateCommands(program);
8082
installVoteCommands(program);
83+
installInitCommand(program);
8184

8285
const client = program.command('client');
8386

bin/init.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import fs from 'fs';
2+
import path from 'path';
3+
import { fileURLToPath } from 'url';
4+
5+
import { configFileName, configDirPath } from '../utils/config.js';
6+
7+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
8+
9+
export default (program) => {
10+
program
11+
.command('init')
12+
.description(
13+
`Copies default config file into the given path directory or inside ${configDirPath}`,
14+
)
15+
.argument('[path]', 'directory path to copy config into')
16+
.action(async (targetDirectory = configDirPath) => {
17+
if (!fs.existsSync(targetDirectory)) {
18+
fs.mkdirSync(targetDirectory, { recursive: true });
19+
}
20+
21+
const defaultConfigPath = path.join(__dirname, '../config.default.jsonc');
22+
const targetFilePath = path.resolve(targetDirectory, configFileName);
23+
24+
if (fs.existsSync(targetFilePath)) {
25+
console.error(
26+
`Error: The file ${configFileName} already exists in '${targetDirectory}'. Please remove or rename it.`,
27+
);
28+
return;
29+
}
30+
31+
fs.copyFile(defaultConfigPath, targetFilePath, (error) => {
32+
if (error) {
33+
console.error('Error copying the config file:', error);
34+
} else {
35+
console.log(
36+
`Config was successfully initialized in ${targetFilePath}`,
37+
);
38+
console.log('Edit it using the following command:');
39+
console.log(` nano '${targetFilePath}'`);
40+
}
41+
});
42+
});
43+
};

lib/api/send.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { MessageType } from 'adamant-api';
2+
13
import api from '../../utils/api.js';
24
import config from '../../utils/config.js';
35
import { requiredParam } from '../../utils/validate.js';
@@ -28,14 +30,14 @@ export async function sendMessage(
2830
amountString = '',
2931
passphrase,
3032
) {
31-
const messageType = 'basic';
33+
const messageType = MessageType.Chat;
3234
const isAmountInADM = amountString.includes('ADM');
3335
const amount = parseFloat(amountString, 10);
3436

3537
const messageStr =
3638
typeof message === 'object' ? JSON.stringify(message) : message;
3739

38-
const res = await sendMessage(
40+
const res = await api.sendMessage(
3941
passphrase || config.passphrase,
4042
address,
4143
messageStr,
@@ -52,7 +54,7 @@ export async function sendRich(
5254
json = requiredParam('json'),
5355
passphrase,
5456
) {
55-
const messageType = 'rich';
57+
const messageType = MessageType.Rich;
5658
const message =
5759
typeof json === 'object' ? JSON.stringify(json) : prepareJSON(json);
5860

@@ -71,7 +73,7 @@ export async function sendSignal(
7173
json = requiredParam('json'),
7274
passphrase,
7375
) {
74-
const messageType = 'signal';
76+
const messageType = MessageType.Signal;
7577
const message =
7678
typeof json === 'object' ? JSON.stringify(json) : prepareJSON(json);
7779

lib/rpc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as api from './api/index.js';
44
import * as log from '../utils/log.js';
55
import config from '../utils/config.js';
66

7-
import packageInfo from '../package.json' assert { type: 'json' };
7+
import { packageInfo } from '../utils/package.js';
88

99
/**
1010
* Safe callback and error handling

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "adamant-console",
3-
"version": "2.2.0",
3+
"version": "2.3.0",
44
"description": "Console API and JSON-RPC for interacting with ADAMANT Blockchain",
55
"main": "lib/api/index.js",
66
"type": "module",

prompt/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import readline from 'readline';
22
import History from './history.js';
3-
import packageInfo from '../package.json' assert { type: 'json' };
3+
import { packageInfo } from '../utils/package.js';
44

55
export default (callback) => {
66
const rl = readline.createInterface({

utils/config.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ import chalk from 'chalk';
1111

1212
import * as log from './log.js';
1313

14+
const homeDir = os.homedir();
15+
1416
const configPathName = '.adm';
15-
const configFileName = process.env.ADM_CONFIG_FILENAME || 'config.jsonc';
1617

17-
const homeDir = os.homedir();
18-
const configDirPath =
18+
export const configFileName = process.env.ADM_CONFIG_FILENAME || 'config.jsonc';
19+
export const configDirPath =
1920
process.env.ADM_CONFIG_PATH || `${homeDir}/${configPathName}`;
2021

2122
const configFilePath = path.normalize(`${configDirPath}/${configFileName}`);

utils/package.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import fs from 'fs';
2+
import path from 'path';
3+
import { fileURLToPath } from 'url';
4+
5+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
6+
7+
export const packageInfo = JSON.parse(
8+
fs.readFileSync(path.join(__dirname, '../package.json'), 'utf8'),
9+
);

0 commit comments

Comments
 (0)