Skip to content

Commit

Permalink
Convert getAccountTransactions
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Clark committed Jun 18, 2015
1 parent ff6ac03 commit 8f37438
Show file tree
Hide file tree
Showing 21 changed files with 510 additions and 225 deletions.
4 changes: 3 additions & 1 deletion .flowconfig
@@ -1,9 +1,11 @@
[ignore]
.*/src/.*
.*/src/api/.*
.*/src/core/.*
.*/dist/.*
.*/test/fixtures/.*

[include]
./node_modules/

[libs]

Expand Down
1 change: 1 addition & 0 deletions src/api/api.js
Expand Up @@ -40,6 +40,7 @@ RippleAPI.prototype = {
getOrderBook: orders.getOrderBook,
getSettings: settings.getSettings,
getTransaction: transactions.getTransaction,
getAccountTransactions: transactions.getAccountTransactions,
getNotification: notifications.getNotification,
getNotifications: notifications.getNotifications,

Expand Down
9 changes: 7 additions & 2 deletions src/api/ledger/parse/amount.js
@@ -1,7 +1,12 @@
/* @flow */
'use strict';
const utils = require('./utils');

function parseAmount(amount) {
/*:: type Amount = string | {currency: string, issuer: string, value: string} */
/*:: type XRPAmount = {currency: string, value: string} */
/*:: type IOUAmount = {currency: string, value: string, counterparty: string} */
/*:: type Output = XRPAmount | IOUAmount */
function parseAmount(amount: Amount): Output {
if (typeof amount === 'string') {
return {
currency: 'XRP',
Expand All @@ -11,7 +16,7 @@ function parseAmount(amount) {
return {
currency: amount.currency,
value: amount.value,
counterparty: amount.issuer || amount.counterparty
counterparty: amount.issuer
};
}

Expand Down
3 changes: 2 additions & 1 deletion src/api/ledger/parse/cancellation.js
@@ -1,7 +1,8 @@
/* @flow */
'use strict';
const assert = require('assert');

function parseOrderCancellation(tx) {
function parseOrderCancellation(tx: Object): Object {
assert(tx.TransactionType === 'OfferCancel');
return {
orderSequence: tx.OfferSequence
Expand Down
3 changes: 2 additions & 1 deletion src/api/ledger/parse/fields.js
@@ -1,3 +1,4 @@
/* @flow */
'use strict';
const AccountFields = require('./utils').constants.AccountFields;

Expand All @@ -8,7 +9,7 @@ function parseField(info, value) {
return value;
}

function parseFields(data) {
function parseFields(data: Object): Object {
const settings = {};
for (const fieldName in AccountFields) {
const fieldValue = data[fieldName];
Expand Down
1 change: 1 addition & 0 deletions src/api/ledger/parse/notification.js
@@ -1,3 +1,4 @@
/* @flow */
/* eslint-disable valid-jsdoc */
'use strict';
const ripple = require('../utils').common.core;
Expand Down
3 changes: 2 additions & 1 deletion src/api/ledger/parse/order.js
@@ -1,10 +1,11 @@
/* @flow */
'use strict';
const assert = require('assert');
const utils = require('./utils');
const parseAmount = require('./amount');
const flags = utils.core.Transaction.flags.OfferCreate;

function parseOrder(tx) {
function parseOrder(tx: Object): Object {
assert(tx.TransactionType === 'OfferCreate');

const direction = (tx.Flags & flags.Sell) === 0 ? 'buy' : 'sell';
Expand Down
4 changes: 3 additions & 1 deletion src/api/ledger/parse/pathfind.js
@@ -1,7 +1,9 @@
/* @flow */
'use strict';
const parseAmount = require('./amount');

function parsePathfind(sourceAddress, destinationAmount, pathfindResult) {
function parsePathfind(sourceAddress: string,
destinationAmount: Object, pathfindResult: Object): Object {
return pathfindResult.alternatives.map(function(alternative) {
return {
source: {
Expand Down
3 changes: 2 additions & 1 deletion src/api/ledger/parse/payment.js
@@ -1,3 +1,4 @@
/* @flow */
'use strict';
const assert = require('assert');
const utils = require('./utils');
Expand All @@ -19,7 +20,7 @@ function parsePaymentMemos(tx) {
return tx.Memos.map((m) => m.Memo);
}

function parsePayment(tx) {
function parsePayment(tx: Object): Object {
assert(tx.TransactionType === 'Payment');

const source = {
Expand Down
3 changes: 2 additions & 1 deletion src/api/ledger/parse/settings.js
@@ -1,3 +1,4 @@
/* @flow */
'use strict';
const _ = require('lodash');
const assert = require('assert');
Expand All @@ -8,7 +9,7 @@ function getName(flagNumber) {
return _.findKey(AccountSetFlags, (v) => v === flagNumber);
}

function parseSettings(tx) {
function parseSettings(tx: Object) {
const txType = tx.TransactionType;
assert(txType === 'AccountSet' || txType === 'SetRegularKey');
const settings = {};
Expand Down
3 changes: 2 additions & 1 deletion src/api/ledger/parse/transaction.js
@@ -1,3 +1,4 @@
/* @flow */
'use strict';
const assert = require('assert');
const utils = require('./utils');
Expand All @@ -19,7 +20,7 @@ function parseTransactionType(type) {
return mapping[type] || null;
}

function parseTransaction(tx) {
function parseTransaction(tx: Object): ?Object {
const type = parseTransactionType(tx.TransactionType);
const mapping = {
'payment': parsePayment,
Expand Down
9 changes: 5 additions & 4 deletions src/api/ledger/parse/trustline.js
@@ -1,9 +1,10 @@
/* @flow */
'use strict';
const assert = require('assert');
const utils = require('./utils');
const flags = utils.core.Transaction.flags.TrustSet;

function parseTrustline(tx) {
function parseTrustline(tx: Object): Object {
assert(tx.TransactionType === 'TrustSet');

return {
Expand All @@ -12,9 +13,9 @@ function parseTrustline(tx) {
counterparty: tx.LimitAmount.issuer,
qualityIn: tx.QualityIn,
qualityOut: tx.QualityOut,
allowRippling: tx.Flags & flags.NoRipple === 0,
frozen: tx.Flags & flags.SetFreeze !== 0,
authorized: tx.Flags & flags.SetAuth !== 0
allowRippling: (tx.Flags & flags.NoRipple) === 0,
frozen: (tx.Flags & flags.SetFreeze) !== 0,
authorized: (tx.Flags & flags.SetAuth) !== 0
};
}

Expand Down
8 changes: 5 additions & 3 deletions src/api/ledger/parse/utils.js
@@ -1,18 +1,19 @@
/* @flow */
'use strict';
const _ = require('lodash');
const transactionParser = require('ripple-lib-transactionparser');
const toTimestamp = require('../../../core/utils').toTimestamp;
const utils = require('../utils');

function parseTimestamp(tx) {
function parseTimestamp(tx: {date: string}): string | void {
return tx.date ? (new Date(toTimestamp(tx.date))).toISOString() : undefined;
}

function removeUndefined(obj) {
function removeUndefined(obj: ?Object): ?Object {
return obj ? _.omit(obj, _.isUndefined) : obj;
}

function parseOutcome(tx) {
function parseOutcome(tx: Object): ?Object {
if (!tx.validated) {
return undefined;
}
Expand All @@ -27,6 +28,7 @@ function parseOutcome(tx) {
balanceChanges: balanceChanges,
orderbookChanges: orderbookChanges,
ledgerVersion: tx.ledger_index,
indexInLedger: tx.meta.TransactionIndex,
sequence: tx.Sequence
};
}
Expand Down

0 comments on commit 8f37438

Please sign in to comment.