UNPKG

@kadena/kadena-cli

Version:

Kadena CLI tool to interact with the Kadena blockchain (manage keys, transactions, etc.)

106 lines 3.98 kB
import { log } from '../../../utils/logger.js'; import { createTable } from '../../../utils/table.js'; const formatLength = 80; const displaySeparator = () => { log.info(log.color.green('-'.padEnd(formatLength, '-'))); }; export async function printTx(transactions) { var _a; const table = createTable({ head: ['Filename', 'Signed'], }); if (transactions.length === 0) { log.info('No transactions found'); return; } for (const transaction of transactions) { table.push([ (_a = transaction.fileName) !== null && _a !== void 0 ? _a : 'N/A', transaction.signed === true ? 'Yes' : 'No', ]); } log.output(table.toString(), transactions); } export function txDisplayTransaction(data, files, header = '', baseIndent = 2) { if (header !== '') { displaySeparator(); log.info(` ${log.color.black(header.padEnd(formatLength - 2))}`); displaySeparator(); } if (data === undefined || data.transactions === undefined || data.transactions.length === 0) { log.info('Transaction '.repeat(baseIndent) + log.color.green('null')); return; } data.transactions.forEach((item, i) => { displayCustomTransactionInfo({ fileName: files[i], transactionHash: item.transaction.hash, }, baseIndent); log.info('\n'); if (item.response) { log.info(log.color.black(`${' '.repeat(baseIndent)}Response:`)); displayTransactionResponse(item.response, baseIndent + 2); } log.info('\n'); displayTransactionDetails(item.details, baseIndent); log.info('\n'); displayTransactionCommand(item.transaction, baseIndent); displaySeparator(); }); } export function displayCustomTransactionInfo( // eslint-disable-next-line @typescript-eslint/no-explicit-any info, indentLevel) { log.info(log.color.green(`${' '.repeat(indentLevel)}Transaction info:`)); printObject(info, indentLevel + 2); } function displayTransactionDetails(details, indentLevel) { log.info(log.color.black(`${' '.repeat(indentLevel)}Details:`)); printObject(details, indentLevel + 2); } export function displayTransactionResponse(response, indentLevel) { log.info(log.color.black(`${' '.repeat(indentLevel)}Response:`)); printObject(response, indentLevel + 2); } export function displayTransactionCommand(transaction, indentLevel) { log.info(log.color.black(`${' '.repeat(indentLevel)}Transaction Command:`)); printObject(transaction, indentLevel + 2); } function printObject( // eslint-disable-next-line @typescript-eslint/no-explicit-any obj, indentLevel) { const indentString = ' '.repeat(indentLevel); if (typeof obj !== 'object' || obj === null) { log.info(`${indentString}${obj}`); return; } if (Array.isArray(obj)) { obj.forEach((item, index) => { log.info(`${indentString}[${index}]:`); printObject(item, indentLevel + 2); }); } else { Object.entries(obj).forEach(([key, value]) => { const formattedKey = `${key}:`.padStart(key.length + indentLevel + 2); if (typeof value === 'object' && value !== null) { log.info(log.color.black(formattedKey)); printObject(value, indentLevel + 2); } else { const formattedValue = value !== null && value !== undefined ? value.toString() : 'null'; let color = log.color.green; if (key === 'status') { color = value === 'failure' ? log.color.red : log.color.green; } else if (key === 'message') { color = log.color.yellow; } log.info(`${formattedKey} ${color(formattedValue)}`); } }); } } //# sourceMappingURL=txDisplayHelper.js.map