@@ -4,10 +4,12 @@ import chalk from 'chalk';
44import path from 'path' ;
55import { v4 as uuid } from 'uuid' ;
66import fs from 'fs' ;
7+ import { fileURLToPath } from 'url' ;
78import _camelCase from 'camelcase' ;
89import inquirer from 'inquirer' ;
910import { 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