Skip to content

Commit

Permalink
v2.3.0 (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
martiliones authored Mar 29, 2024
2 parents 5e36901 + 9c8171f commit 594df8c
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 11 deletions.
5 changes: 4 additions & 1 deletion bin/adamant.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import prompt from '../prompt/index.js';
import { log } from '../utils/log.js';
import config from '../utils/config.js';

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

import installInitCommand from './init.js';

import installAccountCommands from '../lib/account.js';
import installGetCommands from '../lib/get.js';
Expand Down Expand Up @@ -78,6 +80,7 @@ installSendCommands(program);
installRpcServerCommands(program);
installDelegateCommands(program);
installVoteCommands(program);
installInitCommand(program);

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

Expand Down
43 changes: 43 additions & 0 deletions bin/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';

import { configFileName, configDirPath } from '../utils/config.js';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

export default (program) => {
program
.command('init')
.description(
`Copies default config file into the given path directory or inside ${configDirPath}`,
)
.argument('[path]', 'directory path to copy config into')
.action(async (targetDirectory = configDirPath) => {
if (!fs.existsSync(targetDirectory)) {
fs.mkdirSync(targetDirectory, { recursive: true });
}

const defaultConfigPath = path.join(__dirname, '../config.default.jsonc');
const targetFilePath = path.resolve(targetDirectory, configFileName);

if (fs.existsSync(targetFilePath)) {
console.error(
`Error: The file ${configFileName} already exists in '${targetDirectory}'. Please remove or rename it.`,
);
return;
}

fs.copyFile(defaultConfigPath, targetFilePath, (error) => {
if (error) {
console.error('Error copying the config file:', error);
} else {
console.log(
`Config was successfully initialized in ${targetFilePath}`,
);
console.log('Edit it using the following command:');
console.log(` nano '${targetFilePath}'`);
}
});
});
};
10 changes: 6 additions & 4 deletions lib/api/send.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { MessageType } from 'adamant-api';

import api from '../../utils/api.js';
import config from '../../utils/config.js';
import { requiredParam } from '../../utils/validate.js';
Expand Down Expand Up @@ -28,14 +30,14 @@ export async function sendMessage(
amountString = '',
passphrase,
) {
const messageType = 'basic';
const messageType = MessageType.Chat;
const isAmountInADM = amountString.includes('ADM');
const amount = parseFloat(amountString, 10);

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

const res = await sendMessage(
const res = await api.sendMessage(
passphrase || config.passphrase,
address,
messageStr,
Expand All @@ -52,7 +54,7 @@ export async function sendRich(
json = requiredParam('json'),
passphrase,
) {
const messageType = 'rich';
const messageType = MessageType.Rich;
const message =
typeof json === 'object' ? JSON.stringify(json) : prepareJSON(json);

Expand All @@ -71,7 +73,7 @@ export async function sendSignal(
json = requiredParam('json'),
passphrase,
) {
const messageType = 'signal';
const messageType = MessageType.Signal;
const message =
typeof json === 'object' ? JSON.stringify(json) : prepareJSON(json);

Expand Down
2 changes: 1 addition & 1 deletion lib/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as api from './api/index.js';
import * as log from '../utils/log.js';
import config from '../utils/config.js';

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

/**
* Safe callback and error handling
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "adamant-console",
"version": "2.2.0",
"version": "2.3.0",
"description": "Console API and JSON-RPC for interacting with ADAMANT Blockchain",
"main": "lib/api/index.js",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion prompt/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import readline from 'readline';
import History from './history.js';
import packageInfo from '../package.json' assert { type: 'json' };
import { packageInfo } from '../utils/package.js';

export default (callback) => {
const rl = readline.createInterface({
Expand Down
7 changes: 4 additions & 3 deletions utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import chalk from 'chalk';

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

const homeDir = os.homedir();

const configPathName = '.adm';
const configFileName = process.env.ADM_CONFIG_FILENAME || 'config.jsonc';

const homeDir = os.homedir();
const configDirPath =
export const configFileName = process.env.ADM_CONFIG_FILENAME || 'config.jsonc';
export const configDirPath =
process.env.ADM_CONFIG_PATH || `${homeDir}/${configPathName}`;

const configFilePath = path.normalize(`${configDirPath}/${configFileName}`);
Expand Down
9 changes: 9 additions & 0 deletions utils/package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

export const packageInfo = JSON.parse(
fs.readFileSync(path.join(__dirname, '../package.json'), 'utf8'),
);

0 comments on commit 594df8c

Please sign in to comment.