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

@@ -10,7 +10,7 @@ const getAccountTransactions = require('./ledger/transactions');
const getTrustlines = require('./ledger/trustlines'); const getTrustlines = require('./ledger/trustlines');
const getBalances = require('./ledger/balances'); const getBalances = require('./ledger/balances');
// const getPathFind = require('./ledger/pathfind'); // const getPathFind = require('./ledger/pathfind');
// const getOrders = require('./ledger/orders'); const getOrders = require('./ledger/orders');
// const getOrderBook = require('./ledger/orderbook'); // const getOrderBook = require('./ledger/orderbook');
const getSettings = require('./ledger/settings'); const getSettings = require('./ledger/settings');
const preparePayment = require('./transaction/payment'); const preparePayment = require('./transaction/payment');
@@ -38,7 +38,7 @@ RippleAPI.prototype = {
getTrustlines, getTrustlines,
getBalances, getBalances,
// getPathFind, // getPathFind,
// getOrders, getOrders,
// getOrderBook, // getOrderBook,
getSettings, getSettings,

View File

@@ -1,119 +1,37 @@
/* eslint-disable valid-jsdoc */
'use strict'; 'use strict';
const _ = require('lodash'); const _ = require('lodash');
const utils = require('./utils'); const utils = require('./utils');
const ripple = utils.common.core;
const validate = utils.common.validate; const validate = utils.common.validate;
const composeAsync = utils.common.composeAsync;
const parseAccountOrder = require('./parse/account-order');
const DefaultPageLimit = 200; function requestAccountOffers(remote, address, ledgerVersion, options,
marker, limit, callback) {
/** remote.requestAccountOffers({
* Get orders from the ripple network account: address,
* marker: marker,
* @query limit: limit,
* @param {String} [request.query.limit] ledger: ledgerVersion
* - Set a limit to the number of results returned },
* @param {String} [request.query.marker] composeAsync((data) => ({
* - Used to paginate results marker: data.marker,
* @param {String} [request.query.ledger] results: data.offers.map(parseAccountOrder)
* - The ledger index to query against }), callback));
* - (required if request.query.marker is present) }
*
* @url
* @param {RippleAddress} request.params.account
* - The ripple address to query orders
*
*/
function getOrders(account, options, callback) {
const self = this;
function getAccountOrders(account, options, callback) {
validate.address(account); validate.address(account);
validate.options(options); validate.options(options);
function getAccountOrders(prevResult) { const defaultLimit = 100;
const isAggregate = options.limit === undefined; const limit = options.limit || defaultLimit;
if (prevResult && (!isAggregate || !prevResult.marker)) { const ledgerVersion = options.ledgerVersion
return Promise.resolve(prevResult); || this.remote.getLedgerSequence();
} const getter = _.partial(requestAccountOffers, this.remote, account,
ledgerVersion, options);
const promise = new Promise(function(resolve, reject) { utils.getRecursive(getter, limit,
let accountOrdersRequest; composeAsync((orders) => _.sortBy(orders, (order) => order.state.sequence),
let marker; callback));
let ledger;
let limit;
if (prevResult) {
marker = prevResult.marker;
limit = prevResult.limit;
ledger = prevResult.ledger_index;
} else {
marker = options.marker;
limit = options.limit || DefaultPageLimit;
ledger = utils.parseLedger(options.ledger);
}
accountOrdersRequest = self.remote.requestAccountOffers({
account: account,
marker: marker,
limit: limit,
ledger: ledger
});
accountOrdersRequest.once('error', reject);
accountOrdersRequest.once('success', function(nextResult) {
nextResult.offers = prevResult ?
nextResult.offers.concat(prevResult.offers) : nextResult.offers;
resolve(nextResult);
});
accountOrdersRequest.request();
});
return promise.then(getAccountOrders);
}
function getParsedOrders(offers) {
return _.reduce(offers, function(orders, off) {
const sequence = off.seq;
const type = off.flags & ripple.Remote.flags.offer.Sell ? 'sell' : 'buy';
const passive = (off.flags & ripple.Remote.flags.offer.Passive) !== 0;
const taker_gets = utils.parseCurrencyAmount(off.taker_gets);
const taker_pays = utils.parseCurrencyAmount(off.taker_pays);
orders.push({
type: type,
taker_gets: taker_gets,
taker_pays: taker_pays,
sequence: sequence,
passive: passive
});
return orders;
}, []);
}
function respondWithOrders(result) {
const promise = new Promise(function(resolve) {
const orders = {};
if (result.marker) {
orders.marker = result.marker;
}
orders.limit = result.limit;
orders.ledger = result.ledger_index;
orders.validated = result.validated;
orders.orders = getParsedOrders(result.offers);
resolve(callback(null, orders));
});
return promise;
}
getAccountOrders()
.then(respondWithOrders)
.catch(callback);
} }
module.exports = getOrders; module.exports = getAccountOrders;

View File

@@ -0,0 +1,14 @@
'use strict';
const parseOrderBase = require('./order-base');
// rippled 'account_offers' returns a different format for orders than 'tx'
function parseAccountOrder(order) {
const specification = parseOrderBase(
order.taker_gets, order.taker_pays, order.flags);
const state = {
sequence: order.seq
};
return {specification, state};
}
module.exports = parseAccountOrder;

View File

@@ -0,0 +1,27 @@
/* @flow */
'use strict';
const utils = require('./utils');
const parseAmount = require('./amount');
const orderFlags = utils.core.Transaction.flags.OfferCreate;
/*:: type Amount = string | {currency: string, issuer: string, value: string} */
function parseOrder(takerGets: Amount, takerPays: Amount, flags: number):
Object {
const direction = (flags & orderFlags.Sell) === 0 ? 'buy' : 'sell';
const takerGetsAmount = parseAmount(takerGets);
const takerPaysAmount = parseAmount(takerPays);
const quantity = (direction === 'buy') ? takerPaysAmount : takerGetsAmount;
const totalPrice = (direction === 'buy') ? takerGetsAmount : takerPaysAmount;
return utils.removeUndefined({
direction: direction,
quantity: quantity,
totalPrice: totalPrice,
passive: ((flags & orderFlags.Passive) !== 0) || undefined,
immediateOrCancel: ((flags & orderFlags.ImmediateOrCancel) !== 0)
|| undefined,
fillOrKill: ((flags & orderFlags.FillOrKill) !== 0) || undefined
});
}
module.exports = parseOrder;

View File

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

View File

@@ -35,15 +35,15 @@ function parsePayment(tx: Object): Object {
tag: tx.DestinationTag tag: tx.DestinationTag
}; };
return { return utils.removeUndefined({
source: utils.removeUndefined(source), source: utils.removeUndefined(source),
destination: utils.removeUndefined(destination), destination: utils.removeUndefined(destination),
memos: parsePaymentMemos(tx), memos: parsePaymentMemos(tx),
invoiceID: tx.InvoiceID, invoiceID: tx.InvoiceID,
paths: JSON.stringify(tx.Paths || []), paths: tx.Paths ? JSON.stringify(tx.Paths) : undefined,
allowPartialPayment: isPartialPayment(tx), allowPartialPayment: isPartialPayment(tx) || undefined,
noDirectRipple: isNoDirectRipple(tx) noDirectRipple: isNoDirectRipple(tx) || undefined
}; });
} }
module.exports = parsePayment; module.exports = parsePayment;

View File

@@ -20,7 +20,7 @@ function parseTransactionType(type) {
return mapping[type] || null; return mapping[type] || null;
} }
function parseTransaction(tx: Object): ?Object { function parseTransaction(tx: Object): Object {
const type = parseTransactionType(tx.TransactionType); const type = parseTransactionType(tx.TransactionType);
const mapping = { const mapping = {
'payment': parsePayment, 'payment': parsePayment,
@@ -32,11 +32,12 @@ function parseTransaction(tx: Object): ?Object {
const parser = mapping[type]; const parser = mapping[type];
assert(parser !== undefined, 'Unrecognized transaction type'); assert(parser !== undefined, 'Unrecognized transaction type');
const specification = parser(tx); const specification = parser(tx);
const outcome = utils.parseOutcome(tx);
return utils.removeUndefined({ return utils.removeUndefined({
type: type, type: type,
address: tx.Account, address: tx.Account,
specification: utils.removeUndefined(specification), specification: utils.removeUndefined(specification),
outcome: utils.removeUndefined(utils.parseOutcome(tx)) outcome: outcome ? utils.removeUndefined(outcome) : undefined
}); });
} }

View File

@@ -9,8 +9,8 @@ function parseTimestamp(tx: {date: string}): string | void {
return tx.date ? (new Date(toTimestamp(tx.date))).toISOString() : undefined; return tx.date ? (new Date(toTimestamp(tx.date))).toISOString() : undefined;
} }
function removeUndefined(obj: ?Object): ?Object { function removeUndefined(obj: Object): Object {
return obj ? _.omit(obj, _.isUndefined) : obj; return _.omit(obj, _.isUndefined);
} }
function removeEmptyCounterparty(amount) { function removeEmptyCounterparty(amount) {

View File

@@ -27,6 +27,7 @@ const accountTransactionsResponse =
const trustlinesResponse = require('./fixtures/trustlines-response'); const trustlinesResponse = require('./fixtures/trustlines-response');
const walletResponse = require('./fixtures/wallet.json'); const walletResponse = require('./fixtures/wallet.json');
const getSettingsResponse = require('./fixtures/get-settings-response'); const getSettingsResponse = require('./fixtures/get-settings-response');
const getOrdersResponse = require('./fixtures/get-orders-response');
function checkResult(expected, done, error, response) { function checkResult(expected, done, error, response) {
if (error) { if (error) {
@@ -131,4 +132,9 @@ describe('RippleAPI', function() {
_.partial(checkResult, getSettingsResponse, done)); _.partial(checkResult, getSettingsResponse, done));
}); });
it('getOrders', function(done) {
this.api.getOrders(address, {},
_.partial(checkResult, getOrdersResponse, done));
});
}); });

View File

@@ -18,9 +18,7 @@
"counterparty": "rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM" "counterparty": "rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM"
} }
}, },
"paths": "[[{\"currency\":\"USD\",\"issuer\":\"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo\",\"type\":48,\"type_hex\":\"0000000000000030\"},{\"account\":\"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo\",\"currency\":\"USD\",\"issuer\":\"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo\",\"type\":49,\"type_hex\":\"0000000000000031\"}]]", "paths": "[[{\"currency\":\"USD\",\"issuer\":\"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo\",\"type\":48,\"type_hex\":\"0000000000000030\"},{\"account\":\"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo\",\"currency\":\"USD\",\"issuer\":\"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo\",\"type\":49,\"type_hex\":\"0000000000000031\"}]]"
"allowPartialPayment": false,
"noDirectRipple": false
}, },
"outcome": { "outcome": {
"result": "tesSUCCESS", "result": "tesSUCCESS",
@@ -104,9 +102,7 @@
"counterparty": "rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM" "counterparty": "rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM"
} }
}, },
"paths": "[[{\"currency\":\"USD\",\"issuer\":\"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo\",\"type\":48,\"type_hex\":\"0000000000000030\"},{\"account\":\"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo\",\"currency\":\"USD\",\"issuer\":\"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo\",\"type\":49,\"type_hex\":\"0000000000000031\"}]]", "paths": "[[{\"currency\":\"USD\",\"issuer\":\"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo\",\"type\":48,\"type_hex\":\"0000000000000030\"},{\"account\":\"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo\",\"currency\":\"USD\",\"issuer\":\"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo\",\"type\":49,\"type_hex\":\"0000000000000031\"}]]"
"allowPartialPayment": false,
"noDirectRipple": false
}, },
"outcome": { "outcome": {
"result": "tesSUCCESS", "result": "tesSUCCESS",

255
test/fixtures/acct-offers-response.js vendored Normal file
View File

@@ -0,0 +1,255 @@
'use strict';
const _ = require('lodash');
const addresses = require('./addresses');
module.exports = function(request, options={}) {
_.defaults(options, {
account: addresses.ACCOUNT,
validated: true
});
return JSON.stringify({
'id': request.id,
'result': {
'account': options.account,
'marker': options.marker,
'limit': options.limit,
'ledger_index': options.ledger,
'offers': [
{
'flags': 131072,
'seq': 719930,
'taker_gets': {
'currency': 'EUR',
'issuer': 'rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q',
'value': '17.70155237781915'
},
'taker_pays': {
'currency': 'USD',
'issuer': 'rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q',
'value': '1122.990930900328'
}
},
{
'flags': 0,
'seq': 757002,
'taker_gets': {
'currency': 'USD',
'issuer': 'rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q',
'value': '18.46856867857617'
},
'taker_pays': {
'currency': 'USD',
'issuer': 'rpDMez6pm6dBve2TJsmDpv7Yae6V5Pyvy2',
'value': '19.50899530491766'
}
},
{
'flags': 0,
'seq': 756999,
'taker_gets': {
'currency': 'USD',
'issuer': 'rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q',
'value': '19.11697137482289'
},
'taker_pays': {
'currency': 'EUR',
'issuer': 'rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q',
'value': '750'
}
},
{
'flags': 0,
'seq': 757003,
'taker_gets': {
'currency': 'USD',
'issuer': 'rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q',
'value': '14.40727807030772'
},
'taker_pays': {
'currency': 'USD',
'issuer': 'rpDMez6pm6dBve2TJsmDpv7Yae6V5Pyvy2',
'value': '1445.796633544794'
}
},
{
'flags': 0,
'seq': 782148,
'taker_gets': {
'currency': 'NZD',
'issuer': 'rsP3mgGb2tcYUrxiLFiHJiQXhsziegtwBc',
'value': '9.178557969538755'
},
'taker_pays': {
'currency': 'USD',
'issuer': 'rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q',
'value': '750'
}
},
{
'flags': 0,
'seq': 787368,
'taker_gets': {
'currency': 'USD',
'issuer': 'rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q',
'value': '9.94768291869523'
},
'taker_pays': {
'currency': 'USD',
'issuer': 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B',
'value': '500'
}
},
{
'flags': 0,
'seq': 787408,
'taker_gets': {
'currency': 'USD',
'issuer': 'rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q',
'value': '9.994805759894176'
},
'taker_pays': {
'currency': 'USD',
'issuer': 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B',
'value': '10000'
}
},
{
'flags': 0,
'seq': 803438,
'taker_gets': {
'currency': 'USD',
'issuer': 'rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q',
'value': '11.67691646304319'
},
'taker_pays': {
'currency': 'MXN',
'issuer': 'rG6FZ31hDHN1K5Dkbma3PSB5uVCuVVRzfn',
'value': '15834.53653918684'
}
},
{
'flags': 0,
'seq': 807858,
'taker_gets': {
'currency': 'XAU',
'issuer': 'r9Dr5xwkeLegBeXq6ujinjSBLQzQ1zQGjH',
'value': '0.03206299605333101'
},
'taker_pays': {
'currency': 'USD',
'issuer': 'r9Dr5xwkeLegBeXq6ujinjSBLQzQ1zQGjH',
'value': '3968.240250979598'
}
},
{
'flags': 0,
'seq': 807896,
'taker_gets': {
'currency': 'XAU',
'issuer': 'r9Dr5xwkeLegBeXq6ujinjSBLQzQ1zQGjH',
'value': '0.03347459066593226'
},
'taker_pays': {
'currency': 'USD',
'issuer': 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B',
'value': '4139.022125516302'
}
},
{
'flags': 0,
'seq': 814018,
'taker_gets': {
'currency': 'NZD',
'issuer': 'rsP3mgGb2tcYUrxiLFiHJiQXhsziegtwBc',
'value': '6.840555705'
},
'taker_pays': '115760190000'
},
{
'flags': 0,
'seq': 827522,
'taker_gets': {
'currency': 'EUR',
'issuer': 'rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q',
'value': '14.40843766044656'
},
'taker_pays': {
'currency': 'USD',
'issuer': 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B',
'value': '902.4050961259154'
}
},
{
'flags': 0,
'seq': 833592,
'taker_gets': {
'currency': 'XAG',
'issuer': 'r9Dr5xwkeLegBeXq6ujinjSBLQzQ1zQGjH',
'value': '1.128432823485991'
},
'taker_pays': {
'currency': 'USD',
'issuer': 'r9Dr5xwkeLegBeXq6ujinjSBLQzQ1zQGjH',
'value': '1814.887131319799'
}
},
{
'flags': 0,
'seq': 833591,
'taker_gets': {
'currency': 'XAG',
'issuer': 'r9Dr5xwkeLegBeXq6ujinjSBLQzQ1zQGjH',
'value': '1.128432823485989'
},
'taker_pays': {
'currency': 'USD',
'issuer': 'r9Dr5xwkeLegBeXq6ujinjSBLQzQ1zQGjH',
'value': '181.4887131319798'
}
},
{
'flags': 0,
'seq': 838954,
'taker_gets': {
'currency': 'XAG',
'issuer': 'r9Dr5xwkeLegBeXq6ujinjSBLQzQ1zQGjH',
'value': '0.7283371225235964'
},
'taker_pays': {
'currency': 'USD',
'issuer': 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B',
'value': '118.6872603846736'
}
},
{
'flags': 0,
'seq': 843730,
'taker_gets': '2229229447',
'taker_pays': {
'currency': 'XAU',
'issuer': 'r9Dr5xwkeLegBeXq6ujinjSBLQzQ1zQGjH',
'value': '1'
}
},
{
'flags': 0,
'seq': 844068,
'taker_gets': {
'currency': 'USD',
'issuer': 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B',
'value': '17.77537376072202'
},
'taker_pays': {
'currency': 'EUR',
'issuer': 'rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q',
'value': '750'
}
}
],
'validated': options.validated
},
'status': 'success',
'type': 'response'
});
};

307
test/fixtures/get-orders-response.json vendored Normal file
View File

@@ -0,0 +1,307 @@
[
{
"specification": {
"direction": "buy",
"quantity": {
"currency": "USD",
"value": "1122.990930900328",
"counterparty": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q"
},
"totalPrice": {
"currency": "EUR",
"value": "17.70155237781915",
"counterparty": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q"
},
"immediateOrCancel": true
},
"state": {
"sequence": 719930
}
},
{
"specification": {
"direction": "buy",
"quantity": {
"currency": "EUR",
"value": "750",
"counterparty": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q"
},
"totalPrice": {
"currency": "USD",
"value": "19.11697137482289",
"counterparty": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q"
}
},
"state": {
"sequence": 756999
}
},
{
"specification": {
"direction": "buy",
"quantity": {
"currency": "USD",
"value": "19.50899530491766",
"counterparty": "rpDMez6pm6dBve2TJsmDpv7Yae6V5Pyvy2"
},
"totalPrice": {
"currency": "USD",
"value": "18.46856867857617",
"counterparty": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q"
}
},
"state": {
"sequence": 757002
}
},
{
"specification": {
"direction": "buy",
"quantity": {
"currency": "USD",
"value": "1445.796633544794",
"counterparty": "rpDMez6pm6dBve2TJsmDpv7Yae6V5Pyvy2"
},
"totalPrice": {
"currency": "USD",
"value": "14.40727807030772",
"counterparty": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q"
}
},
"state": {
"sequence": 757003
}
},
{
"specification": {
"direction": "buy",
"quantity": {
"currency": "USD",
"value": "750",
"counterparty": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q"
},
"totalPrice": {
"currency": "NZD",
"value": "9.178557969538755",
"counterparty": "rsP3mgGb2tcYUrxiLFiHJiQXhsziegtwBc"
}
},
"state": {
"sequence": 782148
}
},
{
"specification": {
"direction": "buy",
"quantity": {
"currency": "USD",
"value": "500",
"counterparty": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"
},
"totalPrice": {
"currency": "USD",
"value": "9.94768291869523",
"counterparty": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q"
}
},
"state": {
"sequence": 787368
}
},
{
"specification": {
"direction": "buy",
"quantity": {
"currency": "USD",
"value": "10000",
"counterparty": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"
},
"totalPrice": {
"currency": "USD",
"value": "9.994805759894176",
"counterparty": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q"
}
},
"state": {
"sequence": 787408
}
},
{
"specification": {
"direction": "buy",
"quantity": {
"currency": "MXN",
"value": "15834.53653918684",
"counterparty": "rG6FZ31hDHN1K5Dkbma3PSB5uVCuVVRzfn"
},
"totalPrice": {
"currency": "USD",
"value": "11.67691646304319",
"counterparty": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q"
}
},
"state": {
"sequence": 803438
}
},
{
"specification": {
"direction": "buy",
"quantity": {
"currency": "USD",
"value": "3968.240250979598",
"counterparty": "r9Dr5xwkeLegBeXq6ujinjSBLQzQ1zQGjH"
},
"totalPrice": {
"currency": "XAU",
"value": "0.03206299605333101",
"counterparty": "r9Dr5xwkeLegBeXq6ujinjSBLQzQ1zQGjH"
}
},
"state": {
"sequence": 807858
}
},
{
"specification": {
"direction": "buy",
"quantity": {
"currency": "USD",
"value": "4139.022125516302",
"counterparty": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"
},
"totalPrice": {
"currency": "XAU",
"value": "0.03347459066593226",
"counterparty": "r9Dr5xwkeLegBeXq6ujinjSBLQzQ1zQGjH"
}
},
"state": {
"sequence": 807896
}
},
{
"specification": {
"direction": "buy",
"quantity": {
"currency": "XRP",
"value": "115760.19"
},
"totalPrice": {
"currency": "NZD",
"value": "6.840555705",
"counterparty": "rsP3mgGb2tcYUrxiLFiHJiQXhsziegtwBc"
}
},
"state": {
"sequence": 814018
}
},
{
"specification": {
"direction": "buy",
"quantity": {
"currency": "USD",
"value": "902.4050961259154",
"counterparty": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"
},
"totalPrice": {
"currency": "EUR",
"value": "14.40843766044656",
"counterparty": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q"
}
},
"state": {
"sequence": 827522
}
},
{
"specification": {
"direction": "buy",
"quantity": {
"currency": "USD",
"value": "181.4887131319798",
"counterparty": "r9Dr5xwkeLegBeXq6ujinjSBLQzQ1zQGjH"
},
"totalPrice": {
"currency": "XAG",
"value": "1.128432823485989",
"counterparty": "r9Dr5xwkeLegBeXq6ujinjSBLQzQ1zQGjH"
}
},
"state": {
"sequence": 833591
}
},
{
"specification": {
"direction": "buy",
"quantity": {
"currency": "USD",
"value": "1814.887131319799",
"counterparty": "r9Dr5xwkeLegBeXq6ujinjSBLQzQ1zQGjH"
},
"totalPrice": {
"currency": "XAG",
"value": "1.128432823485991",
"counterparty": "r9Dr5xwkeLegBeXq6ujinjSBLQzQ1zQGjH"
}
},
"state": {
"sequence": 833592
}
},
{
"specification": {
"direction": "buy",
"quantity": {
"currency": "USD",
"value": "118.6872603846736",
"counterparty": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"
},
"totalPrice": {
"currency": "XAG",
"value": "0.7283371225235964",
"counterparty": "r9Dr5xwkeLegBeXq6ujinjSBLQzQ1zQGjH"
}
},
"state": {
"sequence": 838954
}
},
{
"specification": {
"direction": "buy",
"quantity": {
"currency": "XAU",
"value": "1",
"counterparty": "r9Dr5xwkeLegBeXq6ujinjSBLQzQ1zQGjH"
},
"totalPrice": {
"currency": "XRP",
"value": "2229.229447"
}
},
"state": {
"sequence": 843730
}
},
{
"specification": {
"direction": "buy",
"quantity": {
"currency": "EUR",
"value": "750",
"counterparty": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q"
},
"totalPrice": {
"currency": "USD",
"value": "17.77537376072202",
"counterparty": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"
}
},
"state": {
"sequence": 844068
}
}
]

View File

@@ -17,9 +17,7 @@
"counterparty": "rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM" "counterparty": "rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM"
} }
}, },
"paths": "[[{\"currency\":\"USD\",\"issuer\":\"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo\",\"type\":48,\"type_hex\":\"0000000000000030\"},{\"account\":\"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo\",\"currency\":\"USD\",\"issuer\":\"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo\",\"type\":49,\"type_hex\":\"0000000000000031\"}]]", "paths": "[[{\"currency\":\"USD\",\"issuer\":\"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo\",\"type\":48,\"type_hex\":\"0000000000000030\"},{\"account\":\"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo\",\"currency\":\"USD\",\"issuer\":\"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo\",\"type\":49,\"type_hex\":\"0000000000000031\"}]]"
"allowPartialPayment": false,
"noDirectRipple": false
}, },
"outcome": { "outcome": {
"result": "tesSUCCESS", "result": "tesSUCCESS",

View File

@@ -6,6 +6,7 @@ const EventEmitter2 = require('eventemitter2').EventEmitter2;
const fixtures = require('./fixtures/mock'); const fixtures = require('./fixtures/mock');
const addresses = require('./fixtures/addresses'); const addresses = require('./fixtures/addresses');
const hashes = require('./fixtures/hashes'); const hashes = require('./fixtures/hashes');
const accountOffersResponse = require('./fixtures/acct-offers-response');
module.exports = function(port) { module.exports = function(port) {
const mock = new WebSocketServer({port: port}); const mock = new WebSocketServer({port: port});
@@ -120,5 +121,13 @@ module.exports = function(port) {
} }
}); });
mock.on('request_account_offers', function(request, conn) {
if (request.account === addresses.ACCOUNT) {
conn.send(accountOffersResponse(request));
} else {
assert(false, 'Unrecognized account address: ' + request.account);
}
});
return mock; return mock;
}; };