mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-21 12:45:50 +00:00
Rewrite transaction parser and add unit test for getTransaction
This commit is contained in:
40
src/api/ledger/parse/utils.js
Normal file
40
src/api/ledger/parse/utils.js
Normal file
@@ -0,0 +1,40 @@
|
||||
'use strict';
|
||||
const _ = require('lodash');
|
||||
const transactionParser = require('ripple-lib-transactionparser');
|
||||
const toTimestamp = require('../../../core/utils').toTimestamp;
|
||||
const utils = require('../utils');
|
||||
|
||||
function parseTimestamp(tx) {
|
||||
return tx.date ? (new Date(toTimestamp(tx.date))).toISOString() : undefined;
|
||||
}
|
||||
|
||||
function removeUndefined(obj) {
|
||||
return obj ? _.omit(obj, _.isUndefined) : obj;
|
||||
}
|
||||
|
||||
function parseOutcome(tx) {
|
||||
if (!tx.validated) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const balanceChanges = transactionParser.parseBalanceChanges(tx.meta);
|
||||
const orderbookChanges = transactionParser.parseOrderBookChanges(tx.meta);
|
||||
|
||||
return {
|
||||
result: tx.meta.TransactionResult,
|
||||
timestamp: parseTimestamp(tx),
|
||||
fee: utils.common.dropsToXrp(tx.Fee),
|
||||
balanceChanges: balanceChanges,
|
||||
orderbookChanges: orderbookChanges,
|
||||
ledgerVersion: tx.ledger_index,
|
||||
sequence: tx.Sequence
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
parseOutcome,
|
||||
removeUndefined,
|
||||
dropsToXrp: utils.common.dropsToXrp,
|
||||
constants: utils.common.constants,
|
||||
core: utils.common.core
|
||||
};
|
||||
Reference in New Issue
Block a user