Skip to content

Commit

Permalink
Merge pull request #83 from AElfProject/feature/createNFTToken
Browse files Browse the repository at this point in the history
Feature/create nft token
  • Loading branch information
hzz780 authored Aug 6, 2024
2 parents 8094480 + 216df17 commit 275afc1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aelf-command",
"version": "0.1.47-beta.9",
"version": "0.1.47-beta.10",
"description": "A CLI tools for AElf",
"main": "src/index.js",
"type": "module",
Expand Down
24 changes: 18 additions & 6 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import chalk from 'chalk';
import path from 'path';
import { v4 as uuid } from 'uuid';
import fs from 'fs';
import { fileURLToPath } from 'url';
import _camelCase from 'camelcase';
import inquirer from 'inquirer';
import { plainLogger } from './myLogger.js';
import * as protobuf from '@aelfqueen/protobufjs';
import protobuf from '@aelfqueen/protobufjs';
const { load } = protobuf;

/**
* @typedef {import('ora').Ora} Ora
Expand Down Expand Up @@ -269,17 +271,18 @@ function isSpecialParameters(inputType) {
);
}

async function getParamValue(type, fieldName) {
async function getParamValue(type, fieldName, rule) {
let prompts = PROTO_TYPE_PROMPT_TYPE[type] || PROTO_TYPE_PROMPT_TYPE.default;
const fieldNameWithoutDot = fieldName.replace('.', '');
prompts = {
...prompts,
name: fieldNameWithoutDot,
message: `Enter the required param <${fieldName}>:`
};

const promptValue = (await inquirer.prompt(prompts))[fieldNameWithoutDot];

if (rule === 'repeated') {
prompts.transformFunc = v => JSON.parse(v.replace(/'/g, '"'));
}
let value = parseJSON(await prompts.transformFunc(promptValue));
if (typeof value === 'string' && isFilePath(value)) {
const filePath = path.resolve(process.cwd(), value);
Expand Down Expand Up @@ -367,7 +370,7 @@ async function getParams(method) {
}
paramValue = innerResult;
} else {
paramValue = await getParamValue(type, fieldName);
paramValue = await getParamValue(type, fieldName, rule);
}
result[fieldName] = parseJSON(paramValue);
}
Expand Down Expand Up @@ -419,7 +422,16 @@ async function deserializeLogs(aelf, logs = []) {
if (!logs || logs.length === 0) {
return null;
}
const Root = await protobuf.load('./src/protobuf/virtual_transaction.proto');
let dirname;
try {
// for test as we cannot use import.meta.url in Jest
dirname = __dirname;
} catch {
const __filename = fileURLToPath(import.meta.url);
dirname = path.dirname(__filename);
}
const filePath = path.resolve(dirname, '../package.json');
const Root = await load(path.resolve(dirname, '../protobuf/virtual_transaction.proto'));
let results = await Promise.all(logs.map(v => getProto(aelf, v.Address)));
results = results.map((proto, index) => {
const { Name, NonIndexed, Indexed = [] } = logs[index];
Expand Down

0 comments on commit 275afc1

Please sign in to comment.