mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-21 04:35:49 +00:00
Use ripple-lib-value package and update ripple-lib-transactionparser dependency
This commit is contained in:
14
npm-shrinkwrap.json
generated
14
npm-shrinkwrap.json
generated
@@ -153,14 +153,12 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ripple-lib-transactionparser": {
|
"ripple-lib-transactionparser": {
|
||||||
"version": "0.5.0",
|
"version": "0.5.1",
|
||||||
"resolved": "https://registry.npmjs.org/ripple-lib-transactionparser/-/ripple-lib-transactionparser-0.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/ripple-lib-transactionparser/-/ripple-lib-transactionparser-0.5.1.tgz"
|
||||||
"dependencies": {
|
},
|
||||||
"bignumber.js": {
|
"ripple-lib-value": {
|
||||||
"version": "1.4.1",
|
"version": "0.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-1.4.1.tgz"
|
"resolved": "https://registry.npmjs.org/ripple-lib-value/-/ripple-lib-value-0.1.0.tgz"
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"sjcl-codec": {
|
"sjcl-codec": {
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
|
|||||||
@@ -28,7 +28,8 @@
|
|||||||
"lru-cache": "~2.5.0",
|
"lru-cache": "~2.5.0",
|
||||||
"ripple-address-codec": "^1.6.0",
|
"ripple-address-codec": "^1.6.0",
|
||||||
"ripple-keypairs": "^0.9.0",
|
"ripple-keypairs": "^0.9.0",
|
||||||
"ripple-lib-transactionparser": "^0.5.0",
|
"ripple-lib-transactionparser": "^0.5.1",
|
||||||
|
"ripple-lib-value": "0.1.0",
|
||||||
"sjcl-codec": "0.1.0",
|
"sjcl-codec": "0.1.0",
|
||||||
"ws": "~0.7.1"
|
"ws": "~0.7.1"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
},
|
},
|
||||||
"quantity": {"$ref": "balance"},
|
"quantity": {"$ref": "balance"},
|
||||||
"totalPrice": {"$ref": "balance"},
|
"totalPrice": {"$ref": "balance"},
|
||||||
|
"makerExchangeRate": {"$ref": "value"},
|
||||||
"sequence": {"$ref": "sequence"},
|
"sequence": {"$ref": "sequence"},
|
||||||
"status": {"enum": ["created", "open", "closed", "canceled"]}
|
"status": {"enum": ["created", "open", "closed", "canceled"]}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -8,15 +8,15 @@ const extend = require('extend');
|
|||||||
const utils = require('./utils');
|
const utils = require('./utils');
|
||||||
const UInt160 = require('./uint160').UInt160;
|
const UInt160 = require('./uint160').UInt160;
|
||||||
const Currency = require('./currency').Currency;
|
const Currency = require('./currency').Currency;
|
||||||
const Value = require('./value').Value;
|
const {XRPValue, IOUValue} = require('ripple-lib-value');
|
||||||
const IOUValue = require('./iouvalue').IOUValue;
|
|
||||||
const XRPValue = require('./xrpvalue').XRPValue;
|
type Value = XRPValue | IOUValue;
|
||||||
|
|
||||||
function Amount(value = new XRPValue(NaN)) {
|
function Amount(value = new XRPValue(NaN)) {
|
||||||
// Json format:
|
// Json format:
|
||||||
// integer : XRP
|
// integer : XRP
|
||||||
// { 'value' : ..., 'currency' : ..., 'issuer' : ...}
|
// { 'value' : ..., 'currency' : ..., 'issuer' : ...}
|
||||||
assert(value instanceof Value);
|
assert(value instanceof XRPValue || value instanceof IOUValue);
|
||||||
|
|
||||||
this._value = value;
|
this._value = value;
|
||||||
this._is_native = true; // Default to XRP. Only valid if value is not NaN.
|
this._is_native = true; // Default to XRP. Only valid if value is not NaN.
|
||||||
@@ -625,7 +625,8 @@ function(quality, counterCurrency, counterIssuer, opts) {
|
|||||||
}
|
}
|
||||||
if (this._is_native) {
|
if (this._is_native) {
|
||||||
this._set_value(
|
this._set_value(
|
||||||
new XRPValue(nativeAdjusted.round(6, Value.getBNRoundDown()).toString()));
|
new XRPValue(nativeAdjusted.round(6, XRPValue.getBNRoundDown())
|
||||||
|
.toString()));
|
||||||
} else {
|
} else {
|
||||||
this._set_value(nativeAdjusted);
|
this._set_value(nativeAdjusted);
|
||||||
}
|
}
|
||||||
@@ -723,7 +724,7 @@ Amount.prototype.parse_native = function(j) {
|
|||||||
// Requires _currency to be set!
|
// Requires _currency to be set!
|
||||||
Amount.prototype.parse_value = function(j) {
|
Amount.prototype.parse_value = function(j) {
|
||||||
this._is_native = false;
|
this._is_native = false;
|
||||||
const newValue = new IOUValue(j, Value.getBNRoundDown());
|
const newValue = new IOUValue(j, IOUValue.getBNRoundDown());
|
||||||
this._set_value(newValue);
|
this._set_value(newValue);
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ exports.TransactionQueue = require('./transactionqueue').TransactionQueue;
|
|||||||
exports.convertBase = require('./baseconverter');
|
exports.convertBase = require('./baseconverter');
|
||||||
|
|
||||||
exports._test = {
|
exports._test = {
|
||||||
IOUValue: require('./iouvalue').IOUValue,
|
|
||||||
Log: require('./log'),
|
Log: require('./log'),
|
||||||
PathFind: require('./pathfind').PathFind,
|
PathFind: require('./pathfind').PathFind,
|
||||||
TransactionManager: require('./transactionmanager').TransactionManager,
|
TransactionManager: require('./transactionmanager').TransactionManager,
|
||||||
|
|||||||
@@ -1,56 +0,0 @@
|
|||||||
/* @flow */
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const Value = require('./value').Value;
|
|
||||||
const XRPValue = require('./xrpvalue').XRPValue;
|
|
||||||
const GlobalBigNumber = require('bignumber.js');
|
|
||||||
const BigNumber = GlobalBigNumber.another({
|
|
||||||
ROUNDING_MODE: GlobalBigNumber.ROUND_HALF_UP,
|
|
||||||
DECIMAL_PLACES: 40
|
|
||||||
});
|
|
||||||
const rippleUnits = new BigNumber(1e6);
|
|
||||||
|
|
||||||
class IOUValue extends Value {
|
|
||||||
|
|
||||||
constructor(value: string | BigNumber, roundingMode: ?number = null,
|
|
||||||
base: ?number = null) {
|
|
||||||
|
|
||||||
super(new BigNumber(value, base).toDigits(16, roundingMode));
|
|
||||||
}
|
|
||||||
|
|
||||||
multiply(multiplicand: Value) {
|
|
||||||
if (multiplicand instanceof XRPValue) {
|
|
||||||
return super.multiply(
|
|
||||||
new IOUValue(
|
|
||||||
multiplicand._value.times(rippleUnits)));
|
|
||||||
}
|
|
||||||
return super.multiply(multiplicand);
|
|
||||||
}
|
|
||||||
|
|
||||||
divide(divisor: Value) {
|
|
||||||
if (divisor instanceof XRPValue) {
|
|
||||||
return super.divide(
|
|
||||||
new IOUValue(divisor._value.times(rippleUnits)));
|
|
||||||
}
|
|
||||||
return super.divide(divisor);
|
|
||||||
}
|
|
||||||
|
|
||||||
negate() {
|
|
||||||
return new IOUValue(this._value.neg());
|
|
||||||
}
|
|
||||||
|
|
||||||
_canonicalize(value) {
|
|
||||||
if (value.isNaN()) {
|
|
||||||
throw new Error('Invalid result');
|
|
||||||
}
|
|
||||||
return new IOUValue(value.toPrecision(16));
|
|
||||||
}
|
|
||||||
|
|
||||||
equals(comparator) {
|
|
||||||
return (comparator instanceof IOUValue)
|
|
||||||
&& this._value.equals(comparator._value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.IOUValue = IOUValue;
|
|
||||||
@@ -22,7 +22,7 @@ const Currency = require('./currency').Currency;
|
|||||||
const AutobridgeCalculator = require('./autobridgecalculator');
|
const AutobridgeCalculator = require('./autobridgecalculator');
|
||||||
const OrderBookUtils = require('./orderbookutils');
|
const OrderBookUtils = require('./orderbookutils');
|
||||||
const log = require('./log').internal.sub('orderbook');
|
const log = require('./log').internal.sub('orderbook');
|
||||||
const IOUValue = require('./iouvalue').IOUValue;
|
const {IOUValue} = require('ripple-lib-value');
|
||||||
|
|
||||||
function _sortOffers(a, b) {
|
function _sortOffers(a, b) {
|
||||||
const aQuality = OrderBookUtils.getOfferQuality(a, this._currencyGets);
|
const aQuality = OrderBookUtils.getOfferQuality(a, this._currencyGets);
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ const Types = require('./serializedtypes');
|
|||||||
const Amount = require('./amount').Amount;
|
const Amount = require('./amount').Amount;
|
||||||
const Currency = require('./currency').Currency;
|
const Currency = require('./currency').Currency;
|
||||||
const UInt160 = require('./uint160').UInt160;
|
const UInt160 = require('./uint160').UInt160;
|
||||||
const IOUValue = require('./iouvalue').IOUValue;
|
const {IOUValue} = require('ripple-lib-value');
|
||||||
const OrderBookUtils = {};
|
const OrderBookUtils = {};
|
||||||
|
|
||||||
function assertValidNumber(number, message) {
|
function assertValidNumber(number, message) {
|
||||||
|
|||||||
@@ -1,109 +0,0 @@
|
|||||||
/* @flow */
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const GlobalBigNumber = require('bignumber.js');
|
|
||||||
|
|
||||||
const BigNumber = GlobalBigNumber.another({
|
|
||||||
ROUNDING_MODE: GlobalBigNumber.ROUND_HALF_UP,
|
|
||||||
DECIMAL_PLACES: 40
|
|
||||||
});
|
|
||||||
|
|
||||||
const assert = require('assert');
|
|
||||||
|
|
||||||
class Value {
|
|
||||||
|
|
||||||
constructor(value: string | BigNumber) {
|
|
||||||
if (this.constructor === 'Value') {
|
|
||||||
throw new Error(
|
|
||||||
'Cannot instantiate Value directly, it is an abstract base class');
|
|
||||||
}
|
|
||||||
this._value = new BigNumber(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
static getBNRoundDown() {
|
|
||||||
return BigNumber.ROUND_DOWN;
|
|
||||||
}
|
|
||||||
|
|
||||||
abs() {
|
|
||||||
const result = this._value.abs();
|
|
||||||
return this._canonicalize(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
add(addend: Value) {
|
|
||||||
assert(this.constructor === addend.constructor);
|
|
||||||
const result = this._value.plus(addend._value);
|
|
||||||
return this._canonicalize(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
subtract(subtrahend: Value) {
|
|
||||||
assert(this.constructor === subtrahend.constructor);
|
|
||||||
const result = this._value.minus(subtrahend._value);
|
|
||||||
return this._canonicalize(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
multiply(multiplicand: Value) {
|
|
||||||
const result = this._value.times(multiplicand._value);
|
|
||||||
return this._canonicalize(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
divide(divisor: Value) {
|
|
||||||
if (divisor.isZero()) {
|
|
||||||
throw new Error('divide by zero');
|
|
||||||
}
|
|
||||||
const result = this._value.dividedBy(divisor._value);
|
|
||||||
return this._canonicalize(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
invert() {
|
|
||||||
const result = (new BigNumber(this._value)).toPower(-1);
|
|
||||||
return this._canonicalize(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
round(decimalPlaces: number, roundingMode: number) {
|
|
||||||
const result = this._value.round(decimalPlaces, roundingMode);
|
|
||||||
return this._canonicalize(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
toFixed(decimalPlaces: number, roundingMode: number) {
|
|
||||||
return this._value.toFixed(decimalPlaces, roundingMode);
|
|
||||||
}
|
|
||||||
|
|
||||||
getExponent() {
|
|
||||||
return this._value.e;
|
|
||||||
}
|
|
||||||
|
|
||||||
isNaN() {
|
|
||||||
return this._value.isNaN();
|
|
||||||
}
|
|
||||||
|
|
||||||
isZero() {
|
|
||||||
return this._value.isZero();
|
|
||||||
}
|
|
||||||
|
|
||||||
isNegative() {
|
|
||||||
return this._value.isNegative();
|
|
||||||
}
|
|
||||||
|
|
||||||
toString() {
|
|
||||||
return this._value.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
greaterThan(comparator: Value) {
|
|
||||||
assert(this.constructor === comparator.constructor);
|
|
||||||
return this._value.greaterThan(comparator._value);
|
|
||||||
}
|
|
||||||
|
|
||||||
lessThan(comparator: Value) {
|
|
||||||
assert(this.constructor === comparator.constructor);
|
|
||||||
return this._value.lessThan(comparator._value);
|
|
||||||
}
|
|
||||||
|
|
||||||
comparedTo(comparator: Value) {
|
|
||||||
assert(this.constructor === comparator.constructor);
|
|
||||||
return this._value.comparedTo(comparator._value);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.Value = Value;
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
/* @flow */
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const GlobalBigNumber = require('bignumber.js');
|
|
||||||
const BigNumber = GlobalBigNumber.another({
|
|
||||||
ROUNDING_MODE: GlobalBigNumber.ROUND_HALF_UP,
|
|
||||||
DECIMAL_PLACES: 40
|
|
||||||
});
|
|
||||||
|
|
||||||
const Value = require('./value').Value;
|
|
||||||
const rippleUnits = new BigNumber(1e6);
|
|
||||||
|
|
||||||
class XRPValue extends Value {
|
|
||||||
|
|
||||||
constructor(value: string | BigNumber) {
|
|
||||||
super(value);
|
|
||||||
if (this._value.dp() > 6) {
|
|
||||||
throw new Error(
|
|
||||||
'Value has more than 6 digits of precision past the decimal point, '
|
|
||||||
+ 'an IOUValue may be being cast to an XRPValue'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
multiply(multiplicand: Value) {
|
|
||||||
if (multiplicand instanceof XRPValue) {
|
|
||||||
return super.multiply(
|
|
||||||
new XRPValue(multiplicand._value.times(rippleUnits)));
|
|
||||||
}
|
|
||||||
return super.multiply(multiplicand);
|
|
||||||
}
|
|
||||||
|
|
||||||
divide(divisor: Value) {
|
|
||||||
if (divisor instanceof XRPValue) {
|
|
||||||
return super.divide(
|
|
||||||
new XRPValue(divisor._value.times(rippleUnits)));
|
|
||||||
}
|
|
||||||
return super.divide(divisor);
|
|
||||||
}
|
|
||||||
|
|
||||||
negate() {
|
|
||||||
return new XRPValue(this._value.neg());
|
|
||||||
}
|
|
||||||
|
|
||||||
_canonicalize(value) {
|
|
||||||
if (value.isNaN()) {
|
|
||||||
throw new Error('Invalid result');
|
|
||||||
}
|
|
||||||
return new XRPValue(value.round(6, BigNumber.ROUND_DOWN));
|
|
||||||
}
|
|
||||||
|
|
||||||
equals(comparator) {
|
|
||||||
return (comparator instanceof XRPValue)
|
|
||||||
&& this._value.equals(comparator._value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.XRPValue = XRPValue;
|
|
||||||
@@ -31,6 +31,7 @@
|
|||||||
"currency": "XRP",
|
"currency": "XRP",
|
||||||
"value": "0"
|
"value": "0"
|
||||||
},
|
},
|
||||||
|
"makerExchangeRate": "1185000",
|
||||||
"sequence": 465,
|
"sequence": 465,
|
||||||
"status": "canceled"
|
"status": "canceled"
|
||||||
}
|
}
|
||||||
@@ -39,4 +40,4 @@
|
|||||||
"ledgerVersion": 14661789,
|
"ledgerVersion": 14661789,
|
||||||
"indexInLedger": 4
|
"indexInLedger": 4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,7 @@
|
|||||||
"currency": "XRP",
|
"currency": "XRP",
|
||||||
"value": "0.0002"
|
"value": "0.0002"
|
||||||
},
|
},
|
||||||
|
"makerExchangeRate": "1185000",
|
||||||
"sequence": 465,
|
"sequence": 465,
|
||||||
"status": "created"
|
"status": "created"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,6 +75,7 @@
|
|||||||
"counterparty": "rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo",
|
"counterparty": "rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo",
|
||||||
"value": "-0.001002"
|
"value": "-0.001002"
|
||||||
},
|
},
|
||||||
|
"makerExchangeRate": "1099",
|
||||||
"sequence": 58,
|
"sequence": 58,
|
||||||
"status": "open"
|
"status": "open"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,6 +81,7 @@
|
|||||||
"counterparty": "rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo",
|
"counterparty": "rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo",
|
||||||
"value": "-0.001002"
|
"value": "-0.001002"
|
||||||
},
|
},
|
||||||
|
"makerExchangeRate": "1099",
|
||||||
"sequence": 58,
|
"sequence": 58,
|
||||||
"status": "open"
|
"status": "open"
|
||||||
}
|
}
|
||||||
@@ -172,6 +173,7 @@
|
|||||||
"counterparty": "rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo",
|
"counterparty": "rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo",
|
||||||
"value": "-0.001002"
|
"value": "-0.001002"
|
||||||
},
|
},
|
||||||
|
"makerExchangeRate": "1099",
|
||||||
"sequence": 58,
|
"sequence": 58,
|
||||||
"status": "open"
|
"status": "open"
|
||||||
}
|
}
|
||||||
|
|||||||
2
test/fixtures/orderbook.js
vendored
2
test/fixtures/orderbook.js
vendored
@@ -7,7 +7,7 @@ const addresses = require('./addresses');
|
|||||||
const Meta = require('ripple-lib').Meta;
|
const Meta = require('ripple-lib').Meta;
|
||||||
const SerializedObject = require('ripple-lib').SerializedObject;
|
const SerializedObject = require('ripple-lib').SerializedObject;
|
||||||
const Types = require('ripple-lib').types;
|
const Types = require('ripple-lib').types;
|
||||||
const IOUValue = require('ripple-lib')._test.IOUValue;
|
const IOUValue = require('ripple-lib-value').IOUValue;
|
||||||
|
|
||||||
module.exports.FIAT_BALANCE = '10';
|
module.exports.FIAT_BALANCE = '10';
|
||||||
module.exports.NATIVE_BALANCE = '55';
|
module.exports.NATIVE_BALANCE = '55';
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ const Remote = require('ripple-lib').Remote;
|
|||||||
const Currency = require('ripple-lib').Currency;
|
const Currency = require('ripple-lib').Currency;
|
||||||
const addresses = require('./fixtures/addresses');
|
const addresses = require('./fixtures/addresses');
|
||||||
const fixtures = require('./fixtures/orderbook');
|
const fixtures = require('./fixtures/orderbook');
|
||||||
const IOUValue = require('ripple-lib')._test.IOUValue;
|
const IOUValue = require('ripple-lib-value').IOUValue;
|
||||||
|
|
||||||
describe('OrderBook Autobridging', function() {
|
describe('OrderBook Autobridging', function() {
|
||||||
this.timeout(0);
|
this.timeout(0);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ const Amount = require('ripple-lib').Amount;
|
|||||||
const Meta = require('ripple-lib').Meta;
|
const Meta = require('ripple-lib').Meta;
|
||||||
const addresses = require('./fixtures/addresses');
|
const addresses = require('./fixtures/addresses');
|
||||||
const fixtures = require('./fixtures/orderbook');
|
const fixtures = require('./fixtures/orderbook');
|
||||||
const IOUValue = require('ripple-lib')._test.IOUValue;
|
const IOUValue = require('ripple-lib-value').IOUValue;
|
||||||
|
|
||||||
describe('OrderBook', function() {
|
describe('OrderBook', function() {
|
||||||
this.timeout(0);
|
this.timeout(0);
|
||||||
|
|||||||
Reference in New Issue
Block a user