mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-06 17:27:59 +00:00
fix flow type errors (#811)
This commit is contained in:
committed by
Elliot Lee
parent
2469fb2307
commit
f90617eac4
20
src/api.js
20
src/api.js
@@ -76,6 +76,18 @@ class RestrictedConnection extends common.Connection {
|
||||
}
|
||||
|
||||
class RippleAPI extends EventEmitter {
|
||||
|
||||
_feeCushion: number;
|
||||
connection: RestrictedConnection;
|
||||
|
||||
// these are exposed only for use by unit tests; they are not part of the API.
|
||||
static _PRIVATE = {
|
||||
validate: common.validate,
|
||||
RangeSet: require('./common/rangeset').RangeSet,
|
||||
ledgerUtils: require('./ledger/utils'),
|
||||
schemaValidator: require('./common/schema-validator')
|
||||
};
|
||||
|
||||
constructor(options: APIOptions = {}) {
|
||||
common.validate.apiOptions(options)
|
||||
super()
|
||||
@@ -146,14 +158,6 @@ _.assign(RippleAPI.prototype, {
|
||||
errors
|
||||
})
|
||||
|
||||
// these are exposed only for use by unit tests; they are not part of the API
|
||||
RippleAPI._PRIVATE = {
|
||||
validate: common.validate,
|
||||
RangeSet: require('./common/rangeset').RangeSet,
|
||||
ledgerUtils: require('./ledger/utils'),
|
||||
schemaValidator: require('./common/schema-validator')
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
RippleAPI
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
'use strict' // eslint-disable-line strict
|
||||
const _ = require('lodash')
|
||||
const assert = require('assert')
|
||||
const ranges = Symbol()
|
||||
|
||||
function mergeIntervals(intervals: Array<[number, number]>) {
|
||||
const stack = [[-Infinity, -Infinity]]
|
||||
@@ -19,22 +18,25 @@ function mergeIntervals(intervals: Array<[number, number]>) {
|
||||
}
|
||||
|
||||
class RangeSet {
|
||||
|
||||
ranges: Array<[number, number]>;
|
||||
|
||||
constructor() {
|
||||
this.reset()
|
||||
}
|
||||
|
||||
reset() {
|
||||
this[ranges] = []
|
||||
this.ranges = []
|
||||
}
|
||||
|
||||
serialize() {
|
||||
return this[ranges].map(range =>
|
||||
return this.ranges.map(range =>
|
||||
range[0].toString() + '-' + range[1].toString()).join(',')
|
||||
}
|
||||
|
||||
addRange(start: number, end: number) {
|
||||
assert(start <= end, 'invalid range')
|
||||
this[ranges] = mergeIntervals(this[ranges].concat([[start, end]]))
|
||||
this.ranges = mergeIntervals(this.ranges.concat([[start, end]]))
|
||||
}
|
||||
|
||||
addValue(value: number) {
|
||||
@@ -50,7 +52,7 @@ class RangeSet {
|
||||
}
|
||||
|
||||
containsRange(start: number, end: number) {
|
||||
return _.some(this[ranges], range => range[0] <= start && range[1] >= end)
|
||||
return _.some(this.ranges, range => range[0] <= start && range[1] >= end)
|
||||
}
|
||||
|
||||
containsValue(value: number) {
|
||||
|
||||
@@ -27,6 +27,7 @@ function toRippledAmount(amount: Amount): RippledAmount {
|
||||
if (amount.currency === 'XRP') {
|
||||
return xrpToDrops(amount.value)
|
||||
}
|
||||
// $FlowFixMe: amount.issuer is not a Amount type property. Safe to remove?
|
||||
return {
|
||||
currency: amount.currency,
|
||||
issuer: amount.counterparty ? amount.counterparty :
|
||||
|
||||
@@ -38,7 +38,7 @@ type GetOrderbook = {
|
||||
function getBookOffers(connection: Connection, account: string,
|
||||
ledgerVersion?: number, limit?: number, takerGets: Issue,
|
||||
takerPays: Issue
|
||||
): Promise {
|
||||
): Promise<Object[]> {
|
||||
return connection.request(utils.renameCounterpartyToIssuerInOrder({
|
||||
command: 'book_offers',
|
||||
taker_gets: takerGets,
|
||||
|
||||
@@ -11,7 +11,7 @@ type GetOrders = Array<Order>
|
||||
|
||||
function requestAccountOffers(connection: Connection, address: string,
|
||||
ledgerVersion: number, marker: string, limit: number
|
||||
): Promise {
|
||||
): Promise<Object> {
|
||||
return connection.request({
|
||||
command: 'account_offers',
|
||||
account: address,
|
||||
|
||||
@@ -54,7 +54,7 @@ function parseTransaction(tx: Object): Object {
|
||||
'feeUpdate': parseFeeUpdate,
|
||||
'amendment': parseAmendment
|
||||
}
|
||||
const parser = mapping[type]
|
||||
const parser: Function = (mapping: Object)[type]
|
||||
assert(parser !== undefined, 'Unrecognized transaction type')
|
||||
const specification = parser(tx)
|
||||
const outcome = utils.parseOutcome(tx)
|
||||
|
||||
@@ -6,7 +6,7 @@ const utils = require('../utils')
|
||||
const BigNumber = require('bignumber.js')
|
||||
const parseAmount = require('./amount')
|
||||
|
||||
import type {Amount} from '../common/types.js'
|
||||
import type {Amount} from '../../common/types.js'
|
||||
|
||||
function adjustQualityForXRP(
|
||||
quality: string, takerGetsCurrency: string, takerPaysCurrency: string
|
||||
@@ -51,7 +51,7 @@ function removeEmptyCounterpartyInOrderbookChanges(orderbookChanges) {
|
||||
})
|
||||
}
|
||||
|
||||
function isPartialPayment(tx) {
|
||||
function isPartialPayment(tx: Object) {
|
||||
return (tx.Flags & utils.common.txFlags.Payment.PartialPayment) !== 0
|
||||
}
|
||||
|
||||
|
||||
@@ -13,14 +13,16 @@ import type {GetPaths, PathFind, RippledPathsResponse, PathFindRequest}
|
||||
from './pathfind-types.js'
|
||||
|
||||
|
||||
function addParams(request: PathFindRequest, result: RippledPathsResponse) {
|
||||
function addParams(request: PathFindRequest, result: RippledPathsResponse
|
||||
): RippledPathsResponse {
|
||||
return _.defaults(_.assign({}, result, {
|
||||
source_account: request.source_account,
|
||||
source_currencies: request.source_currencies
|
||||
}), {destination_amount: request.destination_amount})
|
||||
}
|
||||
|
||||
function requestPathFind(connection: Connection, pathfind: PathFind): Promise {
|
||||
function requestPathFind(connection: Connection, pathfind: PathFind
|
||||
): Promise<RippledPathsResponse> {
|
||||
const destinationAmount = _.assign({value: -1}, pathfind.destination.amount)
|
||||
const request: PathFindRequest = {
|
||||
command: 'ripple_path_find',
|
||||
@@ -76,7 +78,7 @@ function isRippledIOUAmount(amount: RippledAmount) {
|
||||
|
||||
function conditionallyAddDirectXRPPath(connection: Connection, address: string,
|
||||
paths: RippledPathsResponse
|
||||
): Promise {
|
||||
): Promise<RippledPathsResponse> {
|
||||
if (isRippledIOUAmount(paths.destination_amount)
|
||||
|| !_.includes(paths.destination_currencies, 'XRP')) {
|
||||
return Promise.resolve(paths)
|
||||
|
||||
@@ -22,7 +22,7 @@ function clamp(value: number, min: number, max: number): number {
|
||||
|
||||
function getXRPBalance(connection: Connection, address: string,
|
||||
ledgerVersion?: number
|
||||
): Promise<number> {
|
||||
): Promise<string> {
|
||||
const request = {
|
||||
command: 'account_info',
|
||||
account: address,
|
||||
@@ -34,7 +34,7 @@ function getXRPBalance(connection: Connection, address: string,
|
||||
|
||||
// If the marker is omitted from a response, you have reached the end
|
||||
function getRecursiveRecur(getter: Getter, marker?: string, limit: number
|
||||
): Promise {
|
||||
): Promise<Array<any>> {
|
||||
return getter(marker, limit).then(data => {
|
||||
const remaining = limit - data.results.length
|
||||
if (remaining > 0 && data.marker !== undefined) {
|
||||
@@ -46,7 +46,7 @@ function getRecursiveRecur(getter: Getter, marker?: string, limit: number
|
||||
})
|
||||
}
|
||||
|
||||
function getRecursive(getter: Getter, limit?: number): Promise {
|
||||
function getRecursive(getter: Getter, limit?: number): Promise<Array<any>> {
|
||||
return getRecursiveRecur(getter, undefined, limit || Infinity)
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ function isPendingLedgerVersion(connection: Connection,
|
||||
}
|
||||
|
||||
function ensureLedgerVersion(options: Object
|
||||
): Promise<number> {
|
||||
): Promise<Object> {
|
||||
if (Boolean(options) && options.ledgerVersion !== undefined &&
|
||||
options.ledgerVersion !== null
|
||||
) {
|
||||
|
||||
@@ -19,7 +19,7 @@ type PaymentChannelClaim = {
|
||||
function createPaymentChannelClaimTransaction(account: string,
|
||||
claim: PaymentChannelClaim
|
||||
): Object {
|
||||
const txJSON = {
|
||||
const txJSON: Object = {
|
||||
Account: account,
|
||||
TransactionType: 'PaymentChannelClaim',
|
||||
Channel: claim.channel,
|
||||
|
||||
@@ -13,7 +13,7 @@ type PaymentChannelFund = {
|
||||
function createPaymentChannelFundTransaction(account: string,
|
||||
fund: PaymentChannelFund
|
||||
): Object {
|
||||
const txJSON = {
|
||||
const txJSON: Object = {
|
||||
Account: account,
|
||||
TransactionType: 'PaymentChannelFund',
|
||||
Channel: fund.channel,
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
/* @flow */
|
||||
'use strict' // eslint-disable-line strict
|
||||
|
||||
type SettingPasswordSpent = {
|
||||
passwordSpent?: boolean,
|
||||
}
|
||||
type SettingRequireDestinationTag = {
|
||||
requireDestinationTag?: boolean,
|
||||
}
|
||||
type SettingRequireAuthorization = {
|
||||
requireAuthorization?: boolean,
|
||||
}
|
||||
type SettingDisallowIncomingXRP = {
|
||||
disallowIncomingXRP?: boolean,
|
||||
}
|
||||
type SettingDisableMasterKey = {
|
||||
disableMasterKey?: boolean,
|
||||
}
|
||||
type SettingEnableTransactionIDTracking = {
|
||||
enableTransactionIDTracking?: boolean,
|
||||
}
|
||||
type SettingNoFreeze = {
|
||||
noFreeze?: boolean,
|
||||
}
|
||||
type SettingGlobalFreeze = {
|
||||
globalFreeze?: boolean,
|
||||
}
|
||||
type SettingDefaultRipple = {
|
||||
defaultRipple?: boolean,
|
||||
}
|
||||
type SettingEmailHash = {
|
||||
emailHash?: ?string,
|
||||
}
|
||||
type SettingMessageKey = {
|
||||
messageKey?: string,
|
||||
}
|
||||
type SettingDomain = {
|
||||
domain?: string,
|
||||
}
|
||||
type SettingTransferRate = {
|
||||
transferRate?: ?number,
|
||||
}
|
||||
type SettingRegularKey = {
|
||||
regularKey?: string
|
||||
}
|
||||
|
||||
export type Settings = SettingRegularKey |
|
||||
SettingTransferRate | SettingDomain | SettingMessageKey |
|
||||
SettingEmailHash | SettingDefaultRipple |
|
||||
SettingGlobalFreeze | SettingNoFreeze | SettingEnableTransactionIDTracking |
|
||||
SettingDisableMasterKey | SettingDisallowIncomingXRP |
|
||||
SettingRequireAuthorization | SettingRequireDestinationTag |
|
||||
SettingPasswordSpent
|
||||
@@ -8,17 +8,36 @@ const validate = utils.common.validate
|
||||
const AccountFlagIndices = utils.common.constants.AccountFlagIndices
|
||||
const AccountFields = utils.common.constants.AccountFields
|
||||
import type {Instructions, Prepare} from './types.js'
|
||||
import type {Settings} from './settings-types.js'
|
||||
|
||||
type Settings = {
|
||||
passwordSpent?: boolean,
|
||||
requireDestinationTag?: boolean,
|
||||
requireAuthorization?: boolean,
|
||||
disallowIncomingXRP?: boolean,
|
||||
disableMasterKey?: boolean,
|
||||
enableTransactionIDTracking?: boolean,
|
||||
noFreeze?: boolean,
|
||||
globalFreeze?: boolean,
|
||||
defaultRipple?: boolean,
|
||||
emailHash?: ?string,
|
||||
messageKey?: string,
|
||||
domain?: string,
|
||||
transferRate?: ?number,
|
||||
regularKey?: string,
|
||||
signers?: {
|
||||
threshold?: number,
|
||||
weights: {address: string, weight: number}[],
|
||||
},
|
||||
}
|
||||
|
||||
// Emptry string passed to setting will clear it
|
||||
const CLEAR_SETTING = null
|
||||
|
||||
|
||||
function setTransactionFlags(txJSON: Object, values: Settings) {
|
||||
const keys = Object.keys(values)
|
||||
assert(keys.length === 1, 'ERROR: can only set one setting per transaction')
|
||||
const flagName = keys[0]
|
||||
const value = values[flagName]
|
||||
const value = (values: Object)[flagName]
|
||||
const index = AccountFlagIndices[flagName]
|
||||
if (index !== undefined) {
|
||||
if (value) {
|
||||
|
||||
Reference in New Issue
Block a user