Convert getOrders and add unit test

This commit is contained in:
Chris Clark
2015-06-25 14:03:25 -07:00
parent 3960b4e11f
commit 84bc7dd4aa
14 changed files with 661 additions and 146 deletions

View File

@@ -1,27 +1,11 @@
/* @flow */
'use strict';
const assert = require('assert');
const utils = require('./utils');
const parseAmount = require('./amount');
const flags = utils.core.Transaction.flags.OfferCreate;
const parseOrderBase = require('./order-base');
function parseOrder(tx: Object): Object {
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
};
return parseOrderBase(tx.TakerGets, tx.TakerPays, tx.Flags);
}
module.exports = parseOrder;