mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-06 17:27:59 +00:00
convert common.js modules to new standard esm module syntax (#815)
This commit is contained in:
committed by
Elliot Lee
parent
7ece43e2e2
commit
7e5b9948a8
@@ -1,9 +1,10 @@
|
||||
/* @flow */
|
||||
'use strict' // eslint-disable-line strict
|
||||
const utils = require('./utils')
|
||||
const flags = require('./flags').orderFlags
|
||||
const parseAmount = require('./amount')
|
||||
const BigNumber = require('bignumber.js')
|
||||
|
||||
import BigNumber from 'bignumber.js'
|
||||
import parseAmount from './amount'
|
||||
import {parseTimestamp, adjustQualityForXRP} from './utils'
|
||||
import {removeUndefined} from '../../common'
|
||||
import {orderFlags} from './flags'
|
||||
|
||||
// TODO: remove this function once rippled provides quality directly
|
||||
function computeQuality(takerGets, takerPays) {
|
||||
@@ -14,7 +15,7 @@ function computeQuality(takerGets, takerPays) {
|
||||
// rippled 'account_offers' returns a different format for orders than 'tx'
|
||||
// the flags are also different
|
||||
function parseAccountOrder(address: string, order: Object): Object {
|
||||
const direction = (order.flags & flags.Sell) === 0 ? 'buy' : 'sell'
|
||||
const direction = (order.flags & orderFlags.Sell) === 0 ? 'buy' : 'sell'
|
||||
const takerGetsAmount = parseAmount(order.taker_gets)
|
||||
const takerPaysAmount = parseAmount(order.taker_pays)
|
||||
const quantity = (direction === 'buy') ? takerPaysAmount : takerGetsAmount
|
||||
@@ -22,17 +23,17 @@ function parseAccountOrder(address: string, order: Object): Object {
|
||||
|
||||
// note: immediateOrCancel and fillOrKill orders cannot enter the order book
|
||||
// so we can omit those flags here
|
||||
const specification = utils.removeUndefined({
|
||||
const specification = removeUndefined({
|
||||
direction: direction,
|
||||
quantity: quantity,
|
||||
totalPrice: totalPrice,
|
||||
passive: ((order.flags & flags.Passive) !== 0) || undefined,
|
||||
passive: ((order.flags & orderFlags.Passive) !== 0) || undefined,
|
||||
// rippled currently does not provide "expiration" in account_offers
|
||||
expirationTime: utils.parseTimestamp(order.expiration)
|
||||
expirationTime: parseTimestamp(order.expiration)
|
||||
})
|
||||
|
||||
const makerExchangeRate = order.quality ?
|
||||
utils.adjustQualityForXRP(order.quality.toString(),
|
||||
adjustQualityForXRP(order.quality.toString(),
|
||||
takerGetsAmount.currency, takerPaysAmount.currency) :
|
||||
computeQuality(takerGetsAmount, takerPaysAmount)
|
||||
const properties = {
|
||||
@@ -44,4 +45,4 @@ function parseAccountOrder(address: string, order: Object): Object {
|
||||
return {specification, properties}
|
||||
}
|
||||
|
||||
module.exports = parseAccountOrder
|
||||
export default parseAccountOrder
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/* @flow */
|
||||
'use strict' // eslint-disable-line strict
|
||||
const utils = require('./utils')
|
||||
|
||||
import {parseQuality} from './utils'
|
||||
import {removeUndefined} from '../../common'
|
||||
|
||||
type Trustline = {
|
||||
account: string, limit: number, currency: string, quality_in: ?number,
|
||||
@@ -20,18 +21,18 @@ type AccountTrustline = {
|
||||
// rippled 'account_lines' returns a different format for
|
||||
// trustlines than 'tx'
|
||||
function parseAccountTrustline(trustline: Trustline): AccountTrustline {
|
||||
const specification = utils.removeUndefined({
|
||||
const specification = removeUndefined({
|
||||
limit: trustline.limit,
|
||||
currency: trustline.currency,
|
||||
counterparty: trustline.account,
|
||||
qualityIn: utils.parseQuality(trustline.quality_in) || undefined,
|
||||
qualityOut: utils.parseQuality(trustline.quality_out) || undefined,
|
||||
qualityIn: parseQuality(trustline.quality_in) || undefined,
|
||||
qualityOut: parseQuality(trustline.quality_out) || undefined,
|
||||
ripplingDisabled: trustline.no_ripple || undefined,
|
||||
frozen: trustline.freeze || undefined,
|
||||
authorized: trustline.authorized || undefined
|
||||
})
|
||||
// rippled doesn't provide the counterparty's qualities
|
||||
const counterparty = utils.removeUndefined({
|
||||
const counterparty = removeUndefined({
|
||||
limit: trustline.limit_peer,
|
||||
ripplingDisabled: trustline.no_ripple_peer || undefined,
|
||||
frozen: trustline.freeze_peer || undefined,
|
||||
@@ -43,4 +44,4 @@ function parseAccountTrustline(trustline: Trustline): AccountTrustline {
|
||||
return {specification, counterparty, state}
|
||||
}
|
||||
|
||||
module.exports = parseAccountTrustline
|
||||
export default parseAccountTrustline
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
'use strict' // eslint-disable-line strict
|
||||
|
||||
|
||||
function parseAmendment(tx: Object) {
|
||||
return {
|
||||
@@ -6,4 +6,4 @@ function parseAmendment(tx: Object) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = parseAmendment
|
||||
export default parseAmendment
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/* @flow */
|
||||
'use strict' // eslint-disable-line strict
|
||||
const utils = require('../utils')
|
||||
import type {Amount, RippledAmount} from '../../common/types.js'
|
||||
|
||||
import * as common from '../../common'
|
||||
import type {Amount, RippledAmount} from '../../common/types'
|
||||
|
||||
|
||||
function parseAmount(amount: RippledAmount): Amount {
|
||||
if (typeof amount === 'string') {
|
||||
return {
|
||||
currency: 'XRP',
|
||||
value: utils.common.dropsToXrp(amount)
|
||||
value: common.dropsToXrp(amount)
|
||||
}
|
||||
}
|
||||
return {
|
||||
@@ -18,4 +18,4 @@ function parseAmount(amount: RippledAmount): Amount {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = parseAmount
|
||||
export default parseAmount
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* @flow */
|
||||
'use strict' // eslint-disable-line strict
|
||||
const assert = require('assert')
|
||||
|
||||
import assert from 'assert'
|
||||
|
||||
function parseOrderCancellation(tx: Object): Object {
|
||||
assert(tx.TransactionType === 'OfferCancel')
|
||||
@@ -9,4 +9,4 @@ function parseOrderCancellation(tx: Object): Object {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = parseOrderCancellation
|
||||
export default parseOrderCancellation
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
/* @flow */
|
||||
'use strict' // eslint-disable-line strict
|
||||
const assert = require('assert')
|
||||
const utils = require('./utils')
|
||||
|
||||
import assert from 'assert'
|
||||
import {parseMemos} from './utils'
|
||||
import {removeUndefined} from '../../common'
|
||||
|
||||
function parseEscrowCancellation(tx: Object): Object {
|
||||
assert(tx.TransactionType === 'EscrowCancel')
|
||||
|
||||
return utils.removeUndefined({
|
||||
memos: utils.parseMemos(tx),
|
||||
return removeUndefined({
|
||||
memos: parseMemos(tx),
|
||||
owner: tx.Owner,
|
||||
escrowSequence: tx.OfferSequence
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = parseEscrowCancellation
|
||||
export default parseEscrowCancellation
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
/* @flow */
|
||||
'use strict' // eslint-disable-line strict
|
||||
const assert = require('assert')
|
||||
const utils = require('./utils')
|
||||
const parseAmount = require('./amount')
|
||||
|
||||
import assert from 'assert'
|
||||
import parseAmount from './amount'
|
||||
import {parseTimestamp, parseMemos} from './utils'
|
||||
import {removeUndefined} from '../../common'
|
||||
|
||||
function parseEscrowCreation(tx: Object): Object {
|
||||
assert(tx.TransactionType === 'EscrowCreate')
|
||||
|
||||
return utils.removeUndefined({
|
||||
return removeUndefined({
|
||||
amount: parseAmount(tx.Amount).value,
|
||||
destination: tx.Destination,
|
||||
memos: utils.parseMemos(tx),
|
||||
memos: parseMemos(tx),
|
||||
condition: tx.Condition,
|
||||
allowCancelAfter: utils.parseTimestamp(tx.CancelAfter),
|
||||
allowExecuteAfter: utils.parseTimestamp(tx.FinishAfter),
|
||||
allowCancelAfter: parseTimestamp(tx.CancelAfter),
|
||||
allowExecuteAfter: parseTimestamp(tx.FinishAfter),
|
||||
sourceTag: tx.SourceTag,
|
||||
destinationTag: tx.DestinationTag
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = parseEscrowCreation
|
||||
export default parseEscrowCreation
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
/* @flow */
|
||||
'use strict' // eslint-disable-line strict
|
||||
const assert = require('assert')
|
||||
const utils = require('./utils')
|
||||
|
||||
import assert from 'assert'
|
||||
import {parseMemos} from './utils'
|
||||
import {removeUndefined} from '../../common'
|
||||
|
||||
function parseEscrowExecution(tx: Object): Object {
|
||||
assert(tx.TransactionType === 'EscrowFinish')
|
||||
|
||||
return utils.removeUndefined({
|
||||
memos: utils.parseMemos(tx),
|
||||
return removeUndefined({
|
||||
memos: parseMemos(tx),
|
||||
owner: tx.Owner,
|
||||
escrowSequence: tx.OfferSequence,
|
||||
condition: tx.Condition,
|
||||
@@ -15,4 +16,4 @@ function parseEscrowExecution(tx: Object): Object {
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = parseEscrowExecution
|
||||
export default parseEscrowExecution
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict' // eslint-disable-line strict
|
||||
const BigNumber = require('bignumber.js')
|
||||
const {dropsToXrp} = require('./utils')
|
||||
|
||||
import BigNumber from 'bignumber.js'
|
||||
import {dropsToXrp} from '../../common'
|
||||
|
||||
function parseFeeUpdate(tx: Object) {
|
||||
const baseFeeDrops = (new BigNumber(tx.BaseFee, 16)).toString()
|
||||
@@ -12,4 +12,4 @@ function parseFeeUpdate(tx: Object) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = parseFeeUpdate
|
||||
export default parseFeeUpdate
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
/* @flow */
|
||||
'use strict' // eslint-disable-line strict
|
||||
const _ = require('lodash')
|
||||
const BigNumber = require('bignumber.js')
|
||||
const AccountFields = require('./utils').constants.AccountFields
|
||||
|
||||
import * as _ from 'lodash'
|
||||
import BigNumber from 'bignumber.js'
|
||||
import {constants} from '../../common'
|
||||
const AccountFields = constants.AccountFields
|
||||
|
||||
function parseField(info, value) {
|
||||
if (info.encoding === 'hex' && !info.length) { // e.g. "domain"
|
||||
@@ -49,4 +50,4 @@ function parseFields(data: Object): Object {
|
||||
return settings
|
||||
}
|
||||
|
||||
module.exports = parseFields
|
||||
export default parseFields
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
'use strict' // eslint-disable-line strict
|
||||
|
||||
|
||||
const orderFlags = {
|
||||
Passive: 0x00010000,
|
||||
@@ -16,7 +16,7 @@ const trustlineFlags = {
|
||||
HighFreeze: 0x00800000
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
export {
|
||||
orderFlags,
|
||||
trustlineFlags
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/* @flow */
|
||||
'use strict' // eslint-disable-line strict
|
||||
const _ = require('lodash')
|
||||
const {removeUndefined, rippleTimeToISO8601} = require('./utils')
|
||||
const parseTransaction = require('./transaction')
|
||||
import type {GetLedger} from '../types.js'
|
||||
|
||||
import * as _ from 'lodash'
|
||||
import {removeUndefined, rippleTimeToISO8601} from '../../common'
|
||||
import parseTransaction from './transaction'
|
||||
import type {GetLedger} from '../types'
|
||||
|
||||
function parseTransactionWrapper(ledgerVersion, tx) {
|
||||
const transaction = _.assign({}, _.omit(tx, 'metaData'), {
|
||||
@@ -60,4 +60,4 @@ function parseLedger(ledger: Object): GetLedger {
|
||||
))
|
||||
}
|
||||
|
||||
module.exports = parseLedger
|
||||
export default parseLedger
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
/* @flow */
|
||||
'use strict' // eslint-disable-line strict
|
||||
const assert = require('assert')
|
||||
const utils = require('./utils')
|
||||
const parseAmount = require('./amount')
|
||||
const flags = utils.txFlags.OfferCreate
|
||||
|
||||
import assert from 'assert'
|
||||
import {parseTimestamp} from './utils'
|
||||
import parseAmount from './amount'
|
||||
import {removeUndefined, txFlags} from '../../common'
|
||||
const flags = txFlags.OfferCreate
|
||||
|
||||
function parseOrder(tx: Object): Object {
|
||||
assert(tx.TransactionType === 'OfferCreate')
|
||||
@@ -14,7 +15,7 @@ function parseOrder(tx: Object): Object {
|
||||
const quantity = (direction === 'buy') ? takerPaysAmount : takerGetsAmount
|
||||
const totalPrice = (direction === 'buy') ? takerGetsAmount : takerPaysAmount
|
||||
|
||||
return utils.removeUndefined({
|
||||
return removeUndefined({
|
||||
direction: direction,
|
||||
quantity: quantity,
|
||||
totalPrice: totalPrice,
|
||||
@@ -22,8 +23,8 @@ function parseOrder(tx: Object): Object {
|
||||
immediateOrCancel: ((tx.Flags & flags.ImmediateOrCancel) !== 0)
|
||||
|| undefined,
|
||||
fillOrKill: ((tx.Flags & flags.FillOrKill) !== 0) || undefined,
|
||||
expirationTime: utils.parseTimestamp(tx.Expiration)
|
||||
expirationTime: parseTimestamp(tx.Expiration)
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = parseOrder
|
||||
export default parseOrder
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
/* @flow */
|
||||
'use strict' // eslint-disable-line strict
|
||||
const _ = require('lodash')
|
||||
const utils = require('./utils')
|
||||
const flags = require('./flags').orderFlags
|
||||
const parseAmount = require('./amount')
|
||||
|
||||
import * as _ from 'lodash'
|
||||
import {parseTimestamp, adjustQualityForXRP} from './utils'
|
||||
import {removeUndefined} from '../../common'
|
||||
|
||||
import {orderFlags} from './flags'
|
||||
import parseAmount from './amount'
|
||||
|
||||
function parseOrderbookOrder(order: Object): Object {
|
||||
const direction = (order.Flags & flags.Sell) === 0 ? 'buy' : 'sell'
|
||||
const direction = (order.Flags & orderFlags.Sell) === 0 ? 'buy' : 'sell'
|
||||
const takerGetsAmount = parseAmount(order.TakerGets)
|
||||
const takerPaysAmount = parseAmount(order.TakerPays)
|
||||
const quantity = (direction === 'buy') ? takerPaysAmount : takerGetsAmount
|
||||
@@ -14,18 +16,18 @@ function parseOrderbookOrder(order: Object): Object {
|
||||
|
||||
// note: immediateOrCancel and fillOrKill orders cannot enter the order book
|
||||
// so we can omit those flags here
|
||||
const specification = utils.removeUndefined({
|
||||
const specification = removeUndefined({
|
||||
direction: direction,
|
||||
quantity: quantity,
|
||||
totalPrice: totalPrice,
|
||||
passive: ((order.Flags & flags.Passive) !== 0) || undefined,
|
||||
expirationTime: utils.parseTimestamp(order.Expiration)
|
||||
passive: ((order.Flags & orderFlags.Passive) !== 0) || undefined,
|
||||
expirationTime: parseTimestamp(order.Expiration)
|
||||
})
|
||||
|
||||
const properties = {
|
||||
maker: order.Account,
|
||||
sequence: order.Sequence,
|
||||
makerExchangeRate: utils.adjustQualityForXRP(order.quality,
|
||||
makerExchangeRate: adjustQualityForXRP(order.quality,
|
||||
takerGetsAmount.currency, takerPaysAmount.currency)
|
||||
}
|
||||
|
||||
@@ -33,12 +35,12 @@ function parseOrderbookOrder(order: Object): Object {
|
||||
parseAmount(order.taker_gets_funded) : undefined
|
||||
const takerPaysFunded = order.taker_pays_funded ?
|
||||
parseAmount(order.taker_pays_funded) : undefined
|
||||
const available = utils.removeUndefined({
|
||||
const available = removeUndefined({
|
||||
fundedAmount: takerGetsFunded,
|
||||
priceOfFundedAmount: takerPaysFunded
|
||||
})
|
||||
const state = _.isEmpty(available) ? undefined : available
|
||||
return utils.removeUndefined({specification, properties, state})
|
||||
return removeUndefined({specification, properties, state})
|
||||
}
|
||||
|
||||
module.exports = parseOrderbookOrder
|
||||
export default parseOrderbookOrder
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/* @flow */
|
||||
'use strict' // eslint-disable-line strict
|
||||
const _ = require('lodash')
|
||||
const parseAmount = require('./amount')
|
||||
import type {Amount, RippledAmount} from '../../common/types.js'
|
||||
import type {GetPaths, RippledPathsResponse} from '../pathfind-types.js'
|
||||
|
||||
import * as _ from 'lodash'
|
||||
import parseAmount from './amount'
|
||||
import type {Amount, RippledAmount} from '../../common/types'
|
||||
import type {GetPaths, RippledPathsResponse} from '../pathfind-types'
|
||||
|
||||
function parsePaths(paths) {
|
||||
return paths.map(steps => steps.map(step =>
|
||||
@@ -48,4 +48,4 @@ function parsePathfind(pathfindResult: RippledPathsResponse): GetPaths {
|
||||
sourceAddress, destinationAddress, destinationAmount))
|
||||
}
|
||||
|
||||
module.exports = parsePathfind
|
||||
export default parsePathfind
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/* @flow */
|
||||
'use strict' // eslint-disable-line strict
|
||||
const assert = require('assert')
|
||||
const utils = require('./utils')
|
||||
const parseAmount = require('./amount')
|
||||
const claimFlags = utils.txFlags.PaymentChannelClaim
|
||||
|
||||
import assert from 'assert'
|
||||
import {removeUndefined, txFlags} from '../../common'
|
||||
import parseAmount from './amount'
|
||||
const claimFlags = txFlags.PaymentChannelClaim
|
||||
|
||||
function parsePaymentChannelClaim(tx: Object): Object {
|
||||
assert(tx.TransactionType === 'PaymentChannelClaim')
|
||||
|
||||
return utils.removeUndefined({
|
||||
return removeUndefined({
|
||||
channel: tx.Channel,
|
||||
balance: tx.Balance && parseAmount(tx.Balance).value,
|
||||
amount: tx.Amount && parseAmount(tx.Amount).value,
|
||||
@@ -19,4 +19,4 @@ function parsePaymentChannelClaim(tx: Object): Object {
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = parsePaymentChannelClaim
|
||||
export default parsePaymentChannelClaim
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
/* @flow */
|
||||
'use strict' // eslint-disable-line strict
|
||||
const assert = require('assert')
|
||||
const utils = require('./utils')
|
||||
const parseAmount = require('./amount')
|
||||
|
||||
import assert from 'assert'
|
||||
import {parseTimestamp} from './utils'
|
||||
import {removeUndefined} from '../../common'
|
||||
import parseAmount from './amount'
|
||||
|
||||
function parsePaymentChannelCreate(tx: Object): Object {
|
||||
assert(tx.TransactionType === 'PaymentChannelCreate')
|
||||
|
||||
return utils.removeUndefined({
|
||||
return removeUndefined({
|
||||
amount: parseAmount(tx.Amount).value,
|
||||
destination: tx.Destination,
|
||||
settleDelay: tx.SettleDelay,
|
||||
publicKey: tx.PublicKey,
|
||||
cancelAfter: tx.CancelAfter && utils.parseTimestamp(tx.CancelAfter),
|
||||
cancelAfter: tx.CancelAfter && parseTimestamp(tx.CancelAfter),
|
||||
sourceTag: tx.SourceTag,
|
||||
destinationTag: tx.DestinationTag
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = parsePaymentChannelCreate
|
||||
export default parsePaymentChannelCreate
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
/* @flow */
|
||||
'use strict' // eslint-disable-line strict
|
||||
const assert = require('assert')
|
||||
const utils = require('./utils')
|
||||
const parseAmount = require('./amount')
|
||||
|
||||
import assert from 'assert'
|
||||
import {parseTimestamp} from './utils'
|
||||
import {removeUndefined} from '../../common'
|
||||
import parseAmount from './amount'
|
||||
|
||||
function parsePaymentChannelFund(tx: Object): Object {
|
||||
assert(tx.TransactionType === 'PaymentChannelFund')
|
||||
|
||||
return utils.removeUndefined({
|
||||
return removeUndefined({
|
||||
channel: tx.Channel,
|
||||
amount: parseAmount(tx.Amount).value,
|
||||
expiration: tx.Expiration && utils.parseTimestamp(tx.Expiration)
|
||||
expiration: tx.Expiration && parseTimestamp(tx.Expiration)
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = parsePaymentChannelFund
|
||||
export default parsePaymentChannelFund
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/* @flow */
|
||||
'use strict' // eslint-disable-line strict
|
||||
const utils = require('./utils')
|
||||
|
||||
import {parseTimestamp} from './utils'
|
||||
import {removeUndefined, dropsToXrp} from '../../common'
|
||||
|
||||
type PaymentChannelResponse = {
|
||||
account: string,
|
||||
@@ -17,15 +18,15 @@ type PaymentChannelResponse = {
|
||||
}
|
||||
|
||||
function parsePaymentChannel(data: Object): PaymentChannelResponse {
|
||||
return utils.removeUndefined({
|
||||
return removeUndefined({
|
||||
account: data.Account,
|
||||
amount: utils.dropsToXrp(data.Amount),
|
||||
balance: utils.dropsToXrp(data.Balance),
|
||||
amount: dropsToXrp(data.Amount),
|
||||
balance: dropsToXrp(data.Balance),
|
||||
destination: data.Destination,
|
||||
publicKey: data.PublicKey,
|
||||
settleDelay: data.SettleDelay,
|
||||
expiration: utils.parseTimestamp(data.Expiration),
|
||||
cancelAfter: utils.parseTimestamp(data.CancelAfter),
|
||||
expiration: parseTimestamp(data.Expiration),
|
||||
cancelAfter: parseTimestamp(data.CancelAfter),
|
||||
sourceTag: data.SourceTag,
|
||||
destinationTag: data.DestinationTag,
|
||||
previousAffectingTransactionID: data.PreviousTxnID,
|
||||
@@ -33,4 +34,4 @@ function parsePaymentChannel(data: Object): PaymentChannelResponse {
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = parsePaymentChannel
|
||||
export default parsePaymentChannel
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
/* @flow */
|
||||
'use strict' // eslint-disable-line strict
|
||||
const _ = require('lodash')
|
||||
const assert = require('assert')
|
||||
const utils = require('./utils')
|
||||
const parseAmount = require('./amount')
|
||||
const txFlags = utils.txFlags
|
||||
|
||||
import * as _ from 'lodash'
|
||||
import assert from 'assert'
|
||||
import * as utils from './utils'
|
||||
import {txFlags, removeUndefined} from '../../common'
|
||||
import parseAmount from './amount'
|
||||
|
||||
function isNoDirectRipple(tx) {
|
||||
return (tx.Flags & txFlags.Payment.NoRippleDirect) !== 0
|
||||
@@ -35,9 +35,9 @@ function parsePayment(tx: Object): Object {
|
||||
tag: tx.DestinationTag
|
||||
}
|
||||
|
||||
return utils.removeUndefined({
|
||||
source: utils.removeUndefined(source),
|
||||
destination: utils.removeUndefined(destination),
|
||||
return removeUndefined({
|
||||
source: removeUndefined(source),
|
||||
destination: removeUndefined(destination),
|
||||
memos: utils.parseMemos(tx),
|
||||
invoiceID: tx.InvoiceID,
|
||||
paths: tx.Paths ? JSON.stringify(tx.Paths) : undefined,
|
||||
@@ -47,4 +47,4 @@ function parsePayment(tx: Object): Object {
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = parsePayment
|
||||
export default parsePayment
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
/* @flow */
|
||||
'use strict' // eslint-disable-line strict
|
||||
const _ = require('lodash')
|
||||
const assert = require('assert')
|
||||
const AccountFlags = require('./utils').constants.AccountFlags
|
||||
const parseFields = require('./fields')
|
||||
|
||||
import * as _ from 'lodash'
|
||||
import assert from 'assert'
|
||||
import {constants} from '../../common'
|
||||
const AccountFlags = constants.AccountFlags
|
||||
import parseFields from './fields'
|
||||
|
||||
function getAccountRootModifiedNode(tx: Object) {
|
||||
const modifiedNodes = tx.meta.AffectedNodes.filter(node =>
|
||||
@@ -58,4 +59,4 @@ function parseSettings(tx: Object) {
|
||||
return _.assign({}, parseFlags(tx), parseFields(tx))
|
||||
}
|
||||
|
||||
module.exports = parseSettings
|
||||
export default parseSettings
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
/* @flow */
|
||||
'use strict' // eslint-disable-line strict
|
||||
const assert = require('assert')
|
||||
const utils = require('./utils')
|
||||
const parsePayment = require('./payment')
|
||||
const parseTrustline = require('./trustline')
|
||||
const parseOrder = require('./order')
|
||||
const parseOrderCancellation = require('./cancellation')
|
||||
const parseSettings = require('./settings')
|
||||
const parseEscrowCreation = require('./escrow-creation')
|
||||
const parseEscrowExecution = require('./escrow-execution')
|
||||
const parseEscrowCancellation = require('./escrow-cancellation')
|
||||
const parsePaymentChannelCreate = require('./payment-channel-create')
|
||||
const parsePaymentChannelFund = require('./payment-channel-fund')
|
||||
const parsePaymentChannelClaim = require('./payment-channel-claim')
|
||||
const parseFeeUpdate = require('./fee-update')
|
||||
const parseAmendment = require('./amendment')
|
||||
|
||||
import assert from 'assert'
|
||||
import {parseOutcome} from './utils'
|
||||
import {removeUndefined} from '../../common'
|
||||
import parsePayment from './payment'
|
||||
import parseTrustline from './trustline'
|
||||
import parseOrder from './order'
|
||||
import parseOrderCancellation from './cancellation'
|
||||
import parseSettings from './settings'
|
||||
import parseEscrowCreation from './escrow-creation'
|
||||
import parseEscrowExecution from './escrow-execution'
|
||||
import parseEscrowCancellation from './escrow-cancellation'
|
||||
import parsePaymentChannelCreate from './payment-channel-create'
|
||||
import parsePaymentChannelFund from './payment-channel-fund'
|
||||
import parsePaymentChannelClaim from './payment-channel-claim'
|
||||
import parseFeeUpdate from './fee-update'
|
||||
import parseAmendment from './amendment'
|
||||
|
||||
function parseTransactionType(type) {
|
||||
const mapping = {
|
||||
@@ -57,15 +58,15 @@ function parseTransaction(tx: Object): Object {
|
||||
const parser: Function = (mapping: Object)[type]
|
||||
assert(parser !== undefined, 'Unrecognized transaction type')
|
||||
const specification = parser(tx)
|
||||
const outcome = utils.parseOutcome(tx)
|
||||
return utils.removeUndefined({
|
||||
const outcome = parseOutcome(tx)
|
||||
return removeUndefined({
|
||||
type: type,
|
||||
address: tx.Account,
|
||||
sequence: tx.Sequence,
|
||||
id: tx.hash,
|
||||
specification: utils.removeUndefined(specification),
|
||||
outcome: outcome ? utils.removeUndefined(outcome) : undefined
|
||||
specification: removeUndefined(specification),
|
||||
outcome: outcome ? removeUndefined(outcome) : undefined
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = parseTransaction
|
||||
export default parseTransaction
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
/* @flow */
|
||||
'use strict' // eslint-disable-line strict
|
||||
const assert = require('assert')
|
||||
const utils = require('./utils')
|
||||
const flags = utils.txFlags.TrustSet
|
||||
|
||||
import assert from 'assert'
|
||||
import {parseQuality} from './utils'
|
||||
import {txFlags, removeUndefined} from '../../common'
|
||||
const flags = txFlags.TrustSet
|
||||
|
||||
function parseFlag(flagsValue, trueValue, falseValue) {
|
||||
if (flagsValue & trueValue) {
|
||||
@@ -17,12 +18,12 @@ function parseFlag(flagsValue, trueValue, falseValue) {
|
||||
function parseTrustline(tx: Object): Object {
|
||||
assert(tx.TransactionType === 'TrustSet')
|
||||
|
||||
return utils.removeUndefined({
|
||||
return removeUndefined({
|
||||
limit: tx.LimitAmount.value,
|
||||
currency: tx.LimitAmount.currency,
|
||||
counterparty: tx.LimitAmount.issuer,
|
||||
qualityIn: utils.parseQuality(tx.QualityIn),
|
||||
qualityOut: utils.parseQuality(tx.QualityOut),
|
||||
qualityIn: parseQuality(tx.QualityIn),
|
||||
qualityOut: parseQuality(tx.QualityOut),
|
||||
ripplingDisabled: parseFlag(
|
||||
tx.Flags, flags.SetNoRipple, flags.ClearNoRipple),
|
||||
frozen: parseFlag(tx.Flags, flags.SetFreeze, flags.ClearFreeze),
|
||||
@@ -30,4 +31,4 @@ function parseTrustline(tx: Object): Object {
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = parseTrustline
|
||||
export default parseTrustline
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/* @flow */
|
||||
'use strict' // eslint-disable-line strict
|
||||
const _ = require('lodash')
|
||||
const transactionParser = require('ripple-lib-transactionparser')
|
||||
const utils = require('../utils')
|
||||
const BigNumber = require('bignumber.js')
|
||||
const parseAmount = require('./amount')
|
||||
|
||||
import type {Amount} from '../../common/types.js'
|
||||
import * as _ from 'lodash'
|
||||
import transactionParser from 'ripple-lib-transactionparser'
|
||||
import BigNumber from 'bignumber.js'
|
||||
import * as common from '../../common'
|
||||
import parseAmount from './amount'
|
||||
|
||||
import type {Amount} from '../../common/types'
|
||||
|
||||
function adjustQualityForXRP(
|
||||
quality: string, takerGetsCurrency: string, takerPaysCurrency: string
|
||||
@@ -28,7 +28,7 @@ function parseQuality(quality: ?number) {
|
||||
}
|
||||
|
||||
function parseTimestamp(rippleTime: number): string | void {
|
||||
return rippleTime ? utils.common.rippleTimeToISO8601(rippleTime) : undefined
|
||||
return rippleTime ? common.rippleTimeToISO8601(rippleTime) : undefined
|
||||
}
|
||||
|
||||
function removeEmptyCounterparty(amount) {
|
||||
@@ -52,7 +52,7 @@ function removeEmptyCounterpartyInOrderbookChanges(orderbookChanges) {
|
||||
}
|
||||
|
||||
function isPartialPayment(tx: Object) {
|
||||
return (tx.Flags & utils.common.txFlags.Payment.PartialPayment) !== 0
|
||||
return (tx.Flags & common.txFlags.Payment.PartialPayment) !== 0
|
||||
}
|
||||
|
||||
function parseDeliveredAmount(tx: Object): Amount | void {
|
||||
@@ -105,10 +105,10 @@ function parseOutcome(tx: Object): ?Object {
|
||||
removeEmptyCounterpartyInBalanceChanges(balanceChanges)
|
||||
removeEmptyCounterpartyInOrderbookChanges(orderbookChanges)
|
||||
|
||||
return utils.common.removeUndefined({
|
||||
return common.removeUndefined({
|
||||
result: tx.meta.TransactionResult,
|
||||
timestamp: parseTimestamp(tx.date),
|
||||
fee: utils.common.dropsToXrp(tx.Fee),
|
||||
fee: common.dropsToXrp(tx.Fee),
|
||||
balanceChanges: balanceChanges,
|
||||
orderbookChanges: orderbookChanges,
|
||||
ledgerVersion: tx.ledger_index,
|
||||
@@ -126,7 +126,7 @@ function parseMemos(tx: Object): ?Array<Object> {
|
||||
return undefined
|
||||
}
|
||||
return tx.Memos.map(m => {
|
||||
return utils.common.removeUndefined({
|
||||
return common.removeUndefined({
|
||||
type: m.Memo.parsed_memo_type || hexToString(m.Memo.MemoType),
|
||||
format: m.Memo.parsed_memo_format || hexToString(m.Memo.MemoFormat),
|
||||
data: m.Memo.parsed_memo_data || hexToString(m.Memo.MemoData)
|
||||
@@ -134,17 +134,12 @@ function parseMemos(tx: Object): ?Array<Object> {
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
export {
|
||||
parseQuality,
|
||||
parseOutcome,
|
||||
parseMemos,
|
||||
hexToString,
|
||||
parseTimestamp,
|
||||
adjustQualityForXRP,
|
||||
isPartialPayment,
|
||||
dropsToXrp: utils.common.dropsToXrp,
|
||||
constants: utils.common.constants,
|
||||
txFlags: utils.common.txFlags,
|
||||
removeUndefined: utils.common.removeUndefined,
|
||||
rippleTimeToISO8601: utils.common.rippleTimeToISO8601
|
||||
isPartialPayment
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user