mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-06 17:27:59 +00:00
Add flow type checking
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
/* @flow */
|
||||
'use strict';
|
||||
const _ = require('lodash');
|
||||
const utils = require('./utils');
|
||||
@@ -34,9 +35,9 @@ function createOrderTransaction(account, order) {
|
||||
const _order = renameCounterpartyToIssuerInOrder(order);
|
||||
const transaction = new ripple.Transaction();
|
||||
const takerPays = _order.taker_pays.currency !== 'XRP'
|
||||
? _order.taker_pays : utils.xrpToDrops(_order.taker_pays.value);
|
||||
? _order.taker_pays : utils.common.xrpToDrops(_order.taker_pays.value);
|
||||
const takerGets = _order.taker_gets.currency !== 'XRP'
|
||||
? _order.taker_gets : utils.xrpToDrops(_order.taker_gets.value);
|
||||
? _order.taker_gets : utils.common.xrpToDrops(_order.taker_gets.value);
|
||||
|
||||
transaction.offerCreate(account, ripple.Amount.from_json(takerPays),
|
||||
ripple.Amount.from_json(takerGets));
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* @flow */
|
||||
'use strict';
|
||||
const utils = require('./utils');
|
||||
const validate = utils.common.validate;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* @flow */
|
||||
/* eslint-disable valid-jsdoc */
|
||||
'use strict';
|
||||
const BigNumber = require('bignumber.js');
|
||||
@@ -77,7 +78,7 @@ function createPaymentTransaction(account, payment) {
|
||||
.plus(payment.source.slippage || 0).toString();
|
||||
|
||||
if (payment.source_amount.currency === 'XRP') {
|
||||
transaction.sendMax(utils.xrpToDrops(maxValue));
|
||||
transaction.sendMax(utils.common.utils.xrpToDrops(maxValue));
|
||||
} else {
|
||||
transaction.sendMax({
|
||||
value: maxValue,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* @flow */
|
||||
/* eslint-disable valid-jsdoc */
|
||||
'use strict';
|
||||
const _ = require('lodash');
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* @flow */
|
||||
'use strict';
|
||||
const utils = require('./utils');
|
||||
const ripple = utils.common.core;
|
||||
@@ -37,7 +38,7 @@ function hashJSON(txJSON, prefix) {
|
||||
return hashSerialization(serialize(txJSON), prefix);
|
||||
}
|
||||
|
||||
function signingHash(txJSON, isTestNet) {
|
||||
function signingHash(txJSON, isTestNet=false) {
|
||||
return hashJSON(txJSON, isTestNet ? HASH_TX_SIGN_TESTNET : HASH_TX_SIGN);
|
||||
}
|
||||
|
||||
@@ -46,11 +47,14 @@ function computeSignature(txJSON, keypair) {
|
||||
return ripple.sjcl.codec.hex.fromBits(signature).toUpperCase();
|
||||
}
|
||||
|
||||
function sign(txJSON, secret) {
|
||||
/*:: type TxJSON = {Account: string; SigningPubKey: string,
|
||||
TxnSignature: string};
|
||||
type Signed = {tx_blob: string; hash: string}; */
|
||||
function sign(txJSON: TxJSON, secret: string): Signed {
|
||||
validate.txJSON(txJSON);
|
||||
validate.addressAndSecret({address: txJSON.Account, secret: secret});
|
||||
|
||||
const keypair = getKeyPair(txJSON.Acccount, secret);
|
||||
const keypair = getKeyPair(txJSON.Account, secret);
|
||||
if (txJSON.SigningPubKey === undefined) {
|
||||
txJSON.SigningPubKey = getPublicKeyHex(keypair);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
/* @flow */
|
||||
'use strict';
|
||||
const utils = require('./utils');
|
||||
const ripple = utils.common.core;
|
||||
const validate = utils.common.validate;
|
||||
|
||||
function submit(tx_blob, callback) {
|
||||
/*:: type Callback = (err: any, data: any) => void */
|
||||
function submit(tx_blob: string, callback: Callback): void {
|
||||
validate.blob(tx_blob);
|
||||
const request = new ripple.Request(this.remote, 'submit');
|
||||
request.message.tx_blob = tx_blob;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* @flow */
|
||||
'use strict';
|
||||
const utils = require('./utils');
|
||||
const ripple = utils.common.core;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* @flow */
|
||||
/* eslint-disable valid-jsdoc */
|
||||
'use strict';
|
||||
const BigNumber = require('bignumber.js');
|
||||
@@ -18,7 +19,8 @@ const common = require('../common');
|
||||
*
|
||||
* @returns undefined
|
||||
*/
|
||||
function setTransactionBitFlags(transaction, options) {
|
||||
/*:: type FlagOptions = {flags: any; input: any; clear_setting?: string} */
|
||||
function setTransactionBitFlags(transaction: any, options: FlagOptions): void {
|
||||
for (let flagName in options.flags) {
|
||||
const flag = options.flags[flagName];
|
||||
|
||||
@@ -46,7 +48,9 @@ function getFeeDrops(remote) {
|
||||
return remote.feeTx(feeUnits).to_text();
|
||||
}
|
||||
|
||||
function createTxJSON(transaction, remote, instructions, callback) {
|
||||
/*:: type Callback = (err: typeof Error, data: {tx_json: any}) => void */
|
||||
function createTxJSON(transaction: any, remote: any,
|
||||
instructions: any, callback: Callback): void {
|
||||
common.validate.instructions(instructions);
|
||||
|
||||
transaction.complete();
|
||||
@@ -85,12 +89,12 @@ function createTxJSON(transaction, remote, instructions, callback) {
|
||||
}
|
||||
}
|
||||
|
||||
function wrapCatch(asyncFunction) {
|
||||
function wrapCatch(asyncFunction: any): any {
|
||||
return function() {
|
||||
const callback = arguments[arguments.length - 1];
|
||||
try {
|
||||
asyncFunction.apply(this, arguments);
|
||||
} catch (error) {
|
||||
const callback = arguments[arguments.length - 1];
|
||||
callback(error);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user