mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-28 08:05:51 +00:00
Convert getAccountTransactions
This commit is contained in:
@@ -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',
|
||||
@@ -11,7 +16,7 @@ function parseAmount(amount) {
|
||||
return {
|
||||
currency: amount.currency,
|
||||
value: amount.value,
|
||||
counterparty: amount.issuer || amount.counterparty
|
||||
counterparty: amount.issuer
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* @flow */
|
||||
'use strict';
|
||||
const AccountFields = require('./utils').constants.AccountFields;
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* @flow */
|
||||
/* eslint-disable valid-jsdoc */
|
||||
'use strict';
|
||||
const ripple = require('../utils').common.core;
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* @flow */
|
||||
'use strict';
|
||||
const assert = require('assert');
|
||||
const utils = require('./utils');
|
||||
@@ -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 = {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* @flow */
|
||||
'use strict';
|
||||
const _ = require('lodash');
|
||||
const assert = require('assert');
|
||||
@@ -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 = {};
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* @flow */
|
||||
'use strict';
|
||||
const assert = require('assert');
|
||||
const utils = require('./utils');
|
||||
@@ -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,
|
||||
|
||||
@@ -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 {
|
||||
@@ -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
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -27,6 +28,7 @@ function parseOutcome(tx) {
|
||||
balanceChanges: balanceChanges,
|
||||
orderbookChanges: orderbookChanges,
|
||||
ledgerVersion: tx.ledger_index,
|
||||
indexInLedger: tx.meta.TransactionIndex,
|
||||
sequence: tx.Sequence
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user