diff --git a/lib/account.d.ts b/lib/account.d.ts index 969cfc7289..ffaf785f71 100644 --- a/lib/account.d.ts +++ b/lib/account.d.ts @@ -35,6 +35,7 @@ export declare class Account { * @returns {Promise} */ state(): Promise; + private printLogsAndFailures; private printLogs; /** * @param txHash The transaction hash to retry diff --git a/lib/account.js b/lib/account.js index 8624f38490..4952676f0a 100644 --- a/lib/account.js +++ b/lib/account.js @@ -52,9 +52,18 @@ class Account { await this.ready; return this._state; } - printLogs(contractId, logs) { + printLogsAndFailures(contractId, results) { + for (const result of results) { + console.log(`Receipt${result.receiptIds.length > 1 ? 's' : ''}: ${result.receiptIds.join(', ')}`); + this.printLogs(contractId, result.logs, '\t'); + if (result.failure) { + console.warn(`\tFailure [${contractId}]: ${result.failure}`); + } + } + } + printLogs(contractId, logs, prefix) { for (const log of logs) { - console.log(`[${contractId}]: ${log}`); + console.log(`${prefix}Log [${contractId}]: ${log}`); } } /** @@ -103,15 +112,18 @@ class Account { throw error; } } - const flatLogs = [result.transaction_outcome, ...result.receipts_outcome].reduce((acc, it) => acc.concat(it.outcome.logs), []); - this.printLogs(signedTx.transaction.receiverId, flatLogs); - // Find all failures in receipts, print out all except last which is handled later. - const receiptFailures = result.receipts_outcome.filter(o => typeof o.outcome.status === 'object' && typeof o.outcome.status.Failure === 'object').map(o => o.outcome.status.Failure); - if (receiptFailures.length > 1) { - for (let i = 0; i < receiptFailures.length - 1; i++) { - console.warn('Receipt failure: ', rpc_errors_1.parseRpcError(receiptFailures[i])); + const flatLogs = [result.transaction_outcome, ...result.receipts_outcome].reduce((acc, it) => { + if (it.outcome.logs.length || typeof it.outcome.status.Failure != 'undefined') { + return acc.concat({ + 'receiptIds': it.outcome.receipt_ids, + 'logs': it.outcome.logs, + 'failure': typeof it.outcome.status.Failure != 'undefined' ? rpc_errors_1.parseRpcError(it.outcome.status.Failure) : null + }); } - } + else + return acc; + }, []); + this.printLogsAndFailures(signedTx.transaction.receiverId, flatLogs); if (typeof result.status === 'object' && typeof result.status.Failure === 'object') { // if error data has error_message and error_type properties, we consider that node returned an error in the old format if (result.status.Failure.error_message && result.status.Failure.error_type) {