mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-24 06:05:51 +00:00
Rewrite transaction parser and add unit test for getTransaction
This commit is contained in:
26
src/api/ledger/parse/order.js
Normal file
26
src/api/ledger/parse/order.js
Normal file
@@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
const assert = require('assert');
|
||||
const utils = require('./utils');
|
||||
const parseAmount = require('./amount');
|
||||
const flags = utils.core.Transaction.flags.OfferCreate;
|
||||
|
||||
function parseOrder(tx) {
|
||||
assert(tx.TransactionType === 'OfferCreate');
|
||||
|
||||
const direction = (tx.Flags & flags.Sell) === 0 ? 'buy' : 'sell';
|
||||
const takerGets = parseAmount(tx.TakerGets);
|
||||
const takerPays = parseAmount(tx.TakerPays);
|
||||
const quantity = (direction === 'buy') ? takerPays : takerGets;
|
||||
const totalPrice = (direction === 'buy') ? takerGets : takerPays;
|
||||
|
||||
return {
|
||||
direction: direction,
|
||||
quantity: quantity,
|
||||
totalPrice: totalPrice,
|
||||
passive: (tx.Flags & flags.Passive) !== 0,
|
||||
immediateOrCancel: (tx.Flags & flags.ImmediateOrCancel) !== 0,
|
||||
fillOrKill: (tx.Flags & flags.FillOrKill) !== 0
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = parseOrder;
|
||||
Reference in New Issue
Block a user