eliminate dry code

This commit is contained in:
0xmuralik 2023-03-27 18:14:42 +05:30
parent 8ebb80beed
commit 0c0eb79fa3
26 changed files with 81 additions and 149 deletions

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert'; import assert from 'assert';
import { Account, Registry } from '@cerc-io/laconic-sdk'; import { Account, Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo } from '../../../util'; import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
export const command = 'get'; export const command = 'get';
@ -24,9 +24,5 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId); const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const result = await registry.getAccounts([address]); const result = await registry.getAccounts([address]);
if (argv.output=="json"){ queryOutput(result,argv.output);
console.log(JSON.stringify(result, undefined, 2));
} else {
console.log(result)
}
} }

View File

@ -5,7 +5,7 @@ import { Account, createBid, Registry } from '@cerc-io/laconic-sdk';
import { ensureDir } from 'fs-extra'; import { ensureDir } from 'fs-extra';
import fs from 'fs'; import fs from 'fs';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../../util'; import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../../util';
const OUT_DIR = 'out'; const OUT_DIR = 'out';
@ -44,11 +44,6 @@ export const handler = async (argv: Arguments) => {
const result = await registry.commitBid({ auctionId, commitHash }, privateKey, fee); const result = await registry.commitBid({ auctionId, commitHash }, privateKey, fee);
const revealFile = `{"reveal_file":"${revealFilePath}"}` const revealFile = `{"reveal_file":"${revealFilePath}"}`
console.log(argv.verbose ? JSON.stringify(result, undefined, 2)+ JSON.stringify(JSON.parse(revealFile)) : JSON.stringify(JSON.parse(revealFile)));
if (argv.output=="json"){ txOutput(result,revealFile,argv.output,argv.verbose)
console.log(argv.verbose ? JSON.stringify(result, undefined, 2)+"\n"+JSON.stringify(JSON.parse(revealFile)) : JSON.stringify(JSON.parse(revealFile)));
} else {
console.log(argv.verbose ? result+"\n"+revealFile:revealFile)
}
} }

View File

@ -4,7 +4,7 @@ import path from 'path';
import { Registry } from '@cerc-io/laconic-sdk'; import { Registry } from '@cerc-io/laconic-sdk';
import fs from 'fs'; import fs from 'fs';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../../util'; import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../../util';
export const command = 'reveal [auction-id] [file-path]'; export const command = 'reveal [auction-id] [file-path]';
@ -30,9 +30,5 @@ export const handler = async (argv: Arguments) => {
const result = await registry.revealBid({ auctionId, reveal: reveal.toString('hex') }, privateKey, fee); const result = await registry.revealBid({ auctionId, reveal: reveal.toString('hex') }, privateKey, fee);
const success = `{"success":${result.code==0}}` const success = `{"success":${result.code==0}}`
if (argv.output=="json"){ txOutput(result,success,argv.output,argv.verbose)
console.log(argv.verbose ? JSON.stringify(result, undefined, 2) : JSON.stringify(JSON.parse(success)));
} else {
console.log(argv.verbose ? result : success);
}
} }

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert'; import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk'; import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo } from '../../../util'; import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
export const command = 'get [id]'; export const command = 'get [id]';
@ -21,9 +21,5 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId); const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const result = await registry.getAuctionsByIds([id as string]); const result = await registry.getAuctionsByIds([id as string]);
if (argv.output=="json"){ queryOutput(result,argv.output)
console.log(JSON.stringify(result, undefined, 2));
} else {
console.log(result)
}
} }

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert'; import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk'; import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../../util'; import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../../util';
export const command = 'set [name] [bond-id]'; export const command = 'set [name] [bond-id]';
@ -25,9 +25,6 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig); const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.setAuthorityBond({ name, bondId }, privateKey, fee); const result = await registry.setAuthorityBond({ name, bondId }, privateKey, fee);
const success = `{"success":${result.code==0}}` const success = `{"success":${result.code==0}}`
if (argv.output=="json"){
console.log(argv.verbose ? JSON.stringify(result, undefined, 2) : JSON.stringify(JSON.parse(success))); txOutput(result,success,argv.output,argv.verbose)
} else {
console.log(argv.verbose ? result : success);
}
} }

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert'; import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk'; import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util'; import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../util';
export const command = 'reserve [name]'; export const command = 'reserve [name]';
@ -32,9 +32,5 @@ export const handler = async (argv: Arguments) => {
const result = await registry.reserveAuthority({ name, owner }, privateKey, fee); const result = await registry.reserveAuthority({ name, owner }, privateKey, fee);
const success = `{"success":${result.code==0}}` const success = `{"success":${result.code==0}}`
if (argv.output=="json"){ txOutput(result,success,argv.output,argv.verbose)
console.log(argv.verbose ? JSON.stringify(result, undefined, 2) : JSON.stringify(JSON.parse(success)));
} else {
console.log(argv.verbose ? result : success);
}
} }

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert'; import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk'; import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo } from '../../../util'; import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
export const command = 'whois [name]'; export const command = 'whois [name]';
@ -21,9 +21,5 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId); const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const result = await registry.lookupAuthorities([name], true); const result = await registry.lookupAuthorities([name], true);
if (argv.output=="json"){ queryOutput(result,argv.output)
console.log(JSON.stringify(result, undefined, 2));
} else {
console.log(result)
}
} }

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert'; import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk'; import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util'; import { getConfig, getConnectionInfo, getGasAndFees ,txOutput} from '../../../util';
export const command = 'associate'; export const command = 'associate';
@ -31,9 +31,6 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig); const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.associateBond({ recordId: id, bondId }, privateKey, fee); const result = await registry.associateBond({ recordId: id, bondId }, privateKey, fee);
const success = `{"success":${result.code==0}}` const success = `{"success":${result.code==0}}`
if (argv.output=="json"){ txOutput(result,success,argv.output,argv.verbose)
console.log(argv.verbose ? JSON.stringify(result, undefined, 2) : JSON.stringify(JSON.parse(success)));
} else {
console.log(argv.verbose ? result : success);
}
} }

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert'; import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk'; import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util'; import { getConfig, getConnectionInfo, getGasAndFees,txOutput } from '../../../util';
export const command = 'cancel'; export const command = 'cancel';
@ -23,9 +23,6 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig); const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.cancelBond({ id }, privateKey, fee); const result = await registry.cancelBond({ id }, privateKey, fee);
const success = `{"success":${result.code==0}}` const success = `{"success":${result.code==0}}`
if (argv.output=="json"){ txOutput(result,success,argv.output,argv.verbose)
console.log(argv.verbose ? JSON.stringify(result, undefined, 2) : JSON.stringify(JSON.parse(success)));
} else {
console.log(argv.verbose ? result : success);
}
} }

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert'; import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk'; import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util'; import { getConfig, getConnectionInfo, getGasAndFees ,txOutput} from '../../../util';
export const command = 'create'; export const command = 'create';
@ -38,9 +38,6 @@ export const handler = async (argv: Arguments) => {
const result = await registry.createBond({ denom, amount }, privateKey, fee); const result = await registry.createBond({ denom, amount }, privateKey, fee);
const jsonString=`{"bondId":"${bondId}"}` const jsonString=`{"bondId":"${bondId}"}`
if (argv.output=="json"){ txOutput(result,jsonString,argv.output,argv.verbose)
console.log(argv.verbose ? JSON.stringify(result, undefined, 2) : JSON.stringify(JSON.parse(jsonString)));
} else {
console.log(argv.verbose ? result : jsonString);
}
} }

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert'; import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk'; import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util'; import { getConfig, getConnectionInfo, getGasAndFees ,txOutput} from '../../../util';
export const command = 'dissociate'; export const command = 'dissociate';
@ -23,9 +23,6 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig); const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.dissociateBond({ recordId: id }, privateKey, fee); const result = await registry.dissociateBond({ recordId: id }, privateKey, fee);
const success = `{"success":${result.code==0}}` const success = `{"success":${result.code==0}}`
if (argv.output=="json"){ txOutput(result,success,argv.output,argv.verbose)
console.log(argv.verbose ? JSON.stringify(result, undefined, 2) : JSON.stringify(JSON.parse(success)));
} else {
console.log(argv.verbose ? result : success);
}
} }

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert'; import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk'; import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo } from '../../../util'; import { getConfig, getConnectionInfo ,queryOutput} from '../../../util';
export const command = 'get'; export const command = 'get';
@ -22,9 +22,5 @@ export const handler = async (argv: Arguments) => {
const result = await registry.getBondsByIds([id as string]); const result = await registry.getBondsByIds([id as string]);
if (argv.output=="json"){ queryOutput(result,argv.output)
console.log(JSON.stringify(result, undefined, 2));
} else {
console.log(result)
}
} }

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert'; import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk'; import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo } from '../../../util'; import { getConfig, getConnectionInfo ,queryOutput} from '../../../util';
export const command = 'list'; export const command = 'list';
@ -26,9 +26,5 @@ export const handler = async (argv: Arguments) => {
const { owner } = argv; const { owner } = argv;
const result = await registry.queryBonds({ owner }); const result = await registry.queryBonds({ owner });
if (argv.output=="json"){ queryOutput(result,argv.output)
console.log(JSON.stringify(result, undefined, 2));
} else {
console.log(result)
}
} }

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert'; import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk'; import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../../util'; import { getConfig, getConnectionInfo, getGasAndFees,txOutput } from '../../../../util';
export const command = 'dissociate'; export const command = 'dissociate';
@ -29,9 +29,6 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig); const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.dissociateRecords({ bondId }, privateKey, fee); const result = await registry.dissociateRecords({ bondId }, privateKey, fee);
const success = `{"success":${result.code==0}}` const success = `{"success":${result.code==0}}`
if (argv.output=="json"){ txOutput(result,success,argv.output,argv.verbose)
console.log(argv.verbose ? JSON.stringify(result, undefined, 2) : JSON.stringify(JSON.parse(success)));
} else {
console.log(argv.verbose ? result : success);
}
} }

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert'; import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk'; import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../../util'; import { getConfig, getConnectionInfo, getGasAndFees ,txOutput} from '../../../../util';
export const command = 'reassociate'; export const command = 'reassociate';
@ -34,9 +34,6 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig); const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.reassociateRecords({ oldBondId, newBondId }, privateKey, fee); const result = await registry.reassociateRecords({ oldBondId, newBondId }, privateKey, fee);
const success = `{"success":${result.code==0}}` const success = `{"success":${result.code==0}}`
if (argv.output=="json"){ txOutput(result,success,argv.output,argv.verbose)
console.log(argv.verbose ? JSON.stringify(result, undefined, 2) : JSON.stringify(JSON.parse(success)));
} else {
console.log(argv.verbose ? result : success);
}
} }

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert'; import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk'; import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util'; import { getConfig, getConnectionInfo, getGasAndFees ,txOutput} from '../../../util';
import { isNil } from 'lodash'; import { isNil } from 'lodash';
export const command = 'refill'; export const command = 'refill';
@ -38,9 +38,6 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig); const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.refillBond({ id, denom, amount }, privateKey, fee); const result = await registry.refillBond({ id, denom, amount }, privateKey, fee);
const success = `{"success":${result.code==0}}` const success = `{"success":${result.code==0}}`
if (argv.output=="json"){ txOutput(result,success,argv.output,argv.verbose)
console.log(argv.verbose ? JSON.stringify(result, undefined, 2) : JSON.stringify(JSON.parse(success)));
} else {
console.log(argv.verbose ? result : success);
}
} }

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert'; import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk'; import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util'; import { getConfig, getConnectionInfo, getGasAndFees,txOutput } from '../../../util';
export const command = 'withdraw'; export const command = 'withdraw';
@ -37,9 +37,6 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig); const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.withdrawBond({ id, denom, amount }, privateKey, fee); const result = await registry.withdrawBond({ id, denom, amount }, privateKey, fee);
const success = `{"success":${result.code==0}}` const success = `{"success":${result.code==0}}`
if (argv.output=="json"){ txOutput(result,success,argv.output,argv.verbose)
console.log(argv.verbose ? JSON.stringify(result, undefined, 2) : JSON.stringify(JSON.parse(success)));
} else {
console.log(argv.verbose ? result : success);
}
} }

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert'; import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk'; import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util'; import { getConfig, getConnectionInfo, getGasAndFees ,txOutput} from '../../../util';
export const command = 'delete [name]'; export const command = 'delete [name]';
@ -24,9 +24,6 @@ export const handler = async (argv: Arguments) => {
const result = await registry.deleteName({ crn: name }, privateKey, fee); const result = await registry.deleteName({ crn: name }, privateKey, fee);
const success = `{"success":${result.code==0}}` const success = `{"success":${result.code==0}}`
if (argv.output=="json"){ txOutput(result,success,argv.output,argv.verbose)
console.log(argv.verbose ? JSON.stringify(result, undefined, 2) : JSON.stringify(JSON.parse(success)));
} else {
console.log(argv.verbose ? result : success);
}
} }

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert'; import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk'; import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo } from '../../../util'; import { getConfig, getConnectionInfo ,queryOutput} from '../../../util';
export const command = 'lookup [name]'; export const command = 'lookup [name]';
@ -27,9 +27,5 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId); const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const result = await registry.lookupNames([name], argv.history as boolean); const result = await registry.lookupNames([name], argv.history as boolean);
if (argv.output=="json"){ queryOutput(result,argv.output)
console.log(JSON.stringify(result, undefined, 2));
} else {
console.log(result)
}
} }

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert'; import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk'; import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo } from '../../../util'; import { getConfig, getConnectionInfo,txOutput } from '../../../util';
export const command = 'resolve [name]'; export const command = 'resolve [name]';
@ -22,9 +22,6 @@ export const handler = async (argv: Arguments) => {
const result = await registry.resolveNames([name]); const result = await registry.resolveNames([name]);
const success = `{"success":${result.code==0}}` const success = `{"success":${result.code==0}}`
if (argv.output=="json"){ txOutput(result,success,argv.output,argv.verbose)
console.log(argv.verbose ? JSON.stringify(result, undefined, 2) : JSON.stringify(JSON.parse(success)));
} else {
console.log(argv.verbose ? result : success);
}
} }

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert'; import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk'; import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util'; import { getConfig, getConnectionInfo, getGasAndFees,txOutput } from '../../../util';
export const command = 'set [name] [id]'; export const command = 'set [name] [id]';
@ -26,9 +26,6 @@ export const handler = async (argv: Arguments) => {
const result = await registry.setName({ crn: name, cid: id }, privateKey, fee); const result = await registry.setName({ crn: name, cid: id }, privateKey, fee);
const success = `{"success":${result.code==0}}` const success = `{"success":${result.code==0}}`
if (argv.output=="json"){ txOutput(result,success,argv.output,argv.verbose)
console.log(argv.verbose ? JSON.stringify(result, undefined, 2) : JSON.stringify(JSON.parse(success)));
} else {
console.log(argv.verbose ? result : success);
}
} }

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert'; import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk'; import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo } from '../../../util'; import { getConfig, getConnectionInfo ,queryOutput} from '../../../util';
export const command = 'get'; export const command = 'get';
@ -21,9 +21,5 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId); const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const result = await registry.getRecordsByIds([id as string]); const result = await registry.getRecordsByIds([id as string]);
if (argv.output=="json"){ queryOutput(result,argv.output)
console.log(JSON.stringify(result, undefined, 2));
} else {
console.log(result)
}
} }

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert'; import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk'; import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo } from '../../../util'; import { getConfig, getConnectionInfo ,queryOutput} from '../../../util';
export const command = 'list'; export const command = 'list';
@ -36,9 +36,5 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId); const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const result = await registry.queryRecords({ bondId, type, name }, all as boolean); const result = await registry.queryRecords({ bondId, type, name }, all as boolean);
if (argv.output=="json"){ queryOutput(result,argv.output)
console.log(JSON.stringify(result, undefined, 2));
} else {
console.log(result)
}
} }

View File

@ -5,7 +5,7 @@ import yaml from 'js-yaml';
import fs from 'fs'; import fs from 'fs';
import { Registry } from '@cerc-io/laconic-sdk'; import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getGasAndFees, getConnectionInfo } from '../../../util'; import { getConfig, getGasAndFees, getConnectionInfo, txOutput } from '../../../util';
export const command = 'publish'; export const command = 'publish';
@ -40,9 +40,5 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig); const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.setRecord({ privateKey: userKey, record, bondId }, txKey as string, fee); const result = await registry.setRecord({ privateKey: userKey, record, bondId }, txKey as string, fee);
if (argv.output=="json"){ txOutput(result,JSON.stringify(result.data,undefined,2),argv.output,argv.verbose)
console.log(argv.verbose ? JSON.stringify(result, undefined, 2) : JSON.stringify(result.data,undefined,2));
} else {
console.log(argv.verbose ? result : result.data);
}
} }

View File

@ -1,3 +1,4 @@
export * from './fees'; export * from './fees';
export * from './config'; export * from './config';
export * from './common'; export * from './common';
export * from './output';

16
src/util/output.ts Normal file
View File

@ -0,0 +1,16 @@
export const txOutput = (result:any,msg:string,output:unknown,verbose:unknown) => {
if (output=="json"){
console.log(verbose ? JSON.parse(JSON.stringify(result)) : JSON.parse(msg));
} else {
console.log(verbose ? JSON.stringify(result,undefined,2) : msg);
}
};
export const queryOutput = (result: any, output: unknown) => {
if (output=="json"){
console.log(JSON.parse(JSON.stringify(result)));
} else {
console.log(JSON.stringify(result,undefined,2));
}
}