Skip to content

Commit 275afc1

Browse files
authored
Merge pull request #83 from AElfProject/feature/createNFTToken
Feature/create nft token
2 parents 8094480 + 216df17 commit 275afc1

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aelf-command",
3-
"version": "0.1.47-beta.9",
3+
"version": "0.1.47-beta.10",
44
"description": "A CLI tools for AElf",
55
"main": "src/index.js",
66
"type": "module",

src/utils/utils.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import chalk from 'chalk';
44
import path from 'path';
55
import { v4 as uuid } from 'uuid';
66
import fs from 'fs';
7+
import { fileURLToPath } from 'url';
78
import _camelCase from 'camelcase';
89
import inquirer from 'inquirer';
910
import { plainLogger } from './myLogger.js';
10-
import * as protobuf from '@aelfqueen/protobufjs';
11+
import protobuf from '@aelfqueen/protobufjs';
12+
const { load } = protobuf;
1113

1214
/**
1315
* @typedef {import('ora').Ora} Ora
@@ -269,17 +271,18 @@ function isSpecialParameters(inputType) {
269271
);
270272
}
271273

272-
async function getParamValue(type, fieldName) {
274+
async function getParamValue(type, fieldName, rule) {
273275
let prompts = PROTO_TYPE_PROMPT_TYPE[type] || PROTO_TYPE_PROMPT_TYPE.default;
274276
const fieldNameWithoutDot = fieldName.replace('.', '');
275277
prompts = {
276278
...prompts,
277279
name: fieldNameWithoutDot,
278280
message: `Enter the required param <${fieldName}>:`
279281
};
280-
281282
const promptValue = (await inquirer.prompt(prompts))[fieldNameWithoutDot];
282-
283+
if (rule === 'repeated') {
284+
prompts.transformFunc = v => JSON.parse(v.replace(/'/g, '"'));
285+
}
283286
let value = parseJSON(await prompts.transformFunc(promptValue));
284287
if (typeof value === 'string' && isFilePath(value)) {
285288
const filePath = path.resolve(process.cwd(), value);
@@ -367,7 +370,7 @@ async function getParams(method) {
367370
}
368371
paramValue = innerResult;
369372
} else {
370-
paramValue = await getParamValue(type, fieldName);
373+
paramValue = await getParamValue(type, fieldName, rule);
371374
}
372375
result[fieldName] = parseJSON(paramValue);
373376
}
@@ -419,7 +422,16 @@ async function deserializeLogs(aelf, logs = []) {
419422
if (!logs || logs.length === 0) {
420423
return null;
421424
}
422-
const Root = await protobuf.load('./src/protobuf/virtual_transaction.proto');
425+
let dirname;
426+
try {
427+
// for test as we cannot use import.meta.url in Jest
428+
dirname = __dirname;
429+
} catch {
430+
const __filename = fileURLToPath(import.meta.url);
431+
dirname = path.dirname(__filename);
432+
}
433+
const filePath = path.resolve(dirname, '../package.json');
434+
const Root = await load(path.resolve(dirname, '../protobuf/virtual_transaction.proto'));
423435
let results = await Promise.all(logs.map(v => getProto(aelf, v.Address)));
424436
results = results.map((proto, index) => {
425437
const { Name, NonIndexed, Indexed = [] } = logs[index];

0 commit comments

Comments
 (0)