mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-06 13:55:49 +00:00
Compare commits
99 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
994a6d5e76 | ||
|
|
3db72716b4 | ||
|
|
6d39e072f8 | ||
|
|
b7d636d157 | ||
|
|
e8ac4f3d40 | ||
|
|
ae2ccd9887 | ||
|
|
4fff85096c | ||
|
|
b4d8684740 | ||
|
|
d3fb4b6260 | ||
|
|
19eaedf50d | ||
|
|
c56e6a6c08 | ||
|
|
01ecfb0a07 | ||
|
|
e1630e1693 | ||
|
|
526d87c1fc | ||
|
|
8204f6c648 | ||
|
|
5979ff6197 | ||
|
|
d22828b222 | ||
|
|
7e5b9948a8 | ||
|
|
7ece43e2e2 | ||
|
|
f90617eac4 | ||
|
|
2469fb2307 | ||
|
|
a051e6fd71 | ||
|
|
cabe029861 | ||
|
|
1ac4ad2076 | ||
|
|
44119ddf2d | ||
|
|
567036f382 | ||
|
|
27aa0247e7 | ||
|
|
0fc10b302f | ||
|
|
0bc51a869d | ||
|
|
a3dff0dcf7 | ||
|
|
048fc7ce71 | ||
|
|
6265e81afb | ||
|
|
38ca96a938 | ||
|
|
8ed5f764fa | ||
|
|
227ea82a29 | ||
|
|
0e2a5e36c6 | ||
|
|
332b656860 | ||
|
|
0230b963c1 | ||
|
|
48e2ea9ff2 | ||
|
|
b6f1394c61 | ||
|
|
560e43b1a6 | ||
|
|
cc1ab7ae97 | ||
|
|
4886561f7d | ||
|
|
658d8a182e | ||
|
|
2a90f9b134 | ||
|
|
f42dafd304 | ||
|
|
ec2100094a | ||
|
|
ecd6347859 | ||
|
|
ab17b19ff0 | ||
|
|
a9e5ac6290 | ||
|
|
4974f73f26 | ||
|
|
e6d71471e2 | ||
|
|
50db68dff7 | ||
|
|
c8eb5b6a70 | ||
|
|
c61a15e4f3 | ||
|
|
c151ff2d66 | ||
|
|
393b2f9d78 | ||
|
|
bf36cf03d6 | ||
|
|
d3332e0db9 | ||
|
|
ed62b20645 | ||
|
|
5f2c5e27f1 | ||
|
|
ff702b85e2 | ||
|
|
f91eb68556 | ||
|
|
469fefee92 | ||
|
|
de47263087 | ||
|
|
3b9679a673 | ||
|
|
f175966816 | ||
|
|
f1f5364d07 | ||
|
|
1b8b0c76ac | ||
|
|
1a8096ab18 | ||
|
|
f177771c67 | ||
|
|
081fcbfa32 | ||
|
|
0a5e4e2155 | ||
|
|
19eb88a00e | ||
|
|
c8f2967de0 | ||
|
|
b5564330f6 | ||
|
|
43ccb83f73 | ||
|
|
e2d92126c0 | ||
|
|
8c8eef45d5 | ||
|
|
a574e1158a | ||
|
|
af687a6aed | ||
|
|
016e82ab5d | ||
|
|
f300a412d7 | ||
|
|
75e2249cf3 | ||
|
|
1942bcb971 | ||
|
|
9393adf66f | ||
|
|
917aae9bf3 | ||
|
|
da36457d5c | ||
|
|
15a0ededc8 | ||
|
|
68d7864f93 | ||
|
|
1eddbf995f | ||
|
|
592385ac73 | ||
|
|
56d626f5b1 | ||
|
|
7a14300409 | ||
|
|
30fa8d658e | ||
|
|
c0101cb5e7 | ||
|
|
fd640cd65e | ||
|
|
11528eff92 | ||
|
|
3c9175459d |
3
.babelrc
3
.babelrc
@@ -1,4 +1,3 @@
|
|||||||
{
|
{
|
||||||
"presets": ["es2015", "stage-1"],
|
"presets": ["es2015", "stage-1", "flow"]
|
||||||
"plugins": ["syntax-flow", "transform-flow-strip-types"]
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,8 @@
|
|||||||
[ignore]
|
[ignore]
|
||||||
.*/ripple-lib/src/.*
|
|
||||||
.*/ripple-lib/dist/.*
|
.*/ripple-lib/dist/.*
|
||||||
.*/ripple-lib/test/fixtures/.*
|
.*/ripple-lib/test/fixtures/.*
|
||||||
.*/node_modules/flow-bin/.*
|
|
||||||
.*/node_modules/webpack/.*
|
|
||||||
.*/node_modules/babel-core/.*
|
|
||||||
.*/node_modules/babel-eslint/.*
|
|
||||||
.*/node_modules/babel-preset-es2015/.*
|
|
||||||
.*/node_modules/babel-preset-stage-1/.*
|
|
||||||
.*/node_modules/babel-register/.*
|
|
||||||
|
|
||||||
[include]
|
[include]
|
||||||
./node_modules/
|
|
||||||
|
|
||||||
[libs]
|
[libs]
|
||||||
|
|
||||||
|
|||||||
10
.gitignore
vendored
10
.gitignore
vendored
@@ -51,13 +51,13 @@ test/config.js
|
|||||||
# Ignore npm-debug
|
# Ignore npm-debug
|
||||||
npm-debug.log
|
npm-debug.log
|
||||||
|
|
||||||
# Ignore dist folder, build for bower
|
# Ignore dist folder, built from tsc
|
||||||
dist/
|
dist/
|
||||||
|
|
||||||
# Ignore flow output directory
|
|
||||||
out/
|
|
||||||
|
|
||||||
# Ignore perf test cache
|
# Ignore perf test cache
|
||||||
scripts/cache
|
scripts/cache
|
||||||
|
|
||||||
eslintrc
|
.eslintrc
|
||||||
|
|
||||||
|
# nyc (istanbul)
|
||||||
|
.nyc_output
|
||||||
|
|||||||
10
.nycrc
Normal file
10
.nycrc
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"include": ["src/**/*.ts"],
|
||||||
|
"exclude": ["src/**/*.d.ts"],
|
||||||
|
"extension": [".ts"],
|
||||||
|
"require": ["ts-node/register"],
|
||||||
|
"reporter": ["text-summary", "html"],
|
||||||
|
"sourceMap": true,
|
||||||
|
"instrument": true,
|
||||||
|
"cache": true
|
||||||
|
}
|
||||||
73
Gulpfile.js
73
Gulpfile.js
@@ -1,21 +1,22 @@
|
|||||||
/* eslint-disable no-var, no-param-reassign */
|
/* eslint-disable no-var, no-param-reassign */
|
||||||
/* these eslint rules are disabled because gulp does not support babel yet */
|
/* these eslint rules are disabled because gulp does not support babel yet */
|
||||||
'use strict';
|
'use strict';
|
||||||
var _ = require('lodash');
|
const _ = require('lodash');
|
||||||
var gulp = require('gulp');
|
const fs = require('fs');
|
||||||
var uglify = require('gulp-uglify');
|
const path = require('path');
|
||||||
var rename = require('gulp-rename');
|
const assert = require('assert');
|
||||||
var webpack = require('webpack');
|
const gulp = require('gulp');
|
||||||
var bump = require('gulp-bump');
|
const rename = require('gulp-rename');
|
||||||
var argv = require('yargs').argv;
|
const webpack = require('webpack');
|
||||||
var assert = require('assert');
|
const bump = require('gulp-bump');
|
||||||
var fs = require('fs');
|
const argv = require('yargs').argv;
|
||||||
|
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
|
||||||
|
|
||||||
var pkg = require('./package.json');
|
var pkg = require('./package.json');
|
||||||
|
|
||||||
var uglifyOptions = {
|
var uglifyOptions = {
|
||||||
mangle: {
|
mangle: {
|
||||||
except: ['_', 'RippleError', 'RippledError', 'UnexpectedError',
|
reserved: ['_', 'RippleError', 'RippledError', 'UnexpectedError',
|
||||||
'LedgerVersionError', 'ConnectionError', 'NotConnectedError',
|
'LedgerVersionError', 'ConnectionError', 'NotConnectedError',
|
||||||
'DisconnectedError', 'TimeoutError', 'ResponseFormatError',
|
'DisconnectedError', 'TimeoutError', 'ResponseFormatError',
|
||||||
'ValidationError', 'NotFoundError', 'MissingLedgerHistoryError',
|
'ValidationError', 'NotFoundError', 'MissingLedgerHistoryError',
|
||||||
@@ -24,17 +25,17 @@ var uglifyOptions = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function webpackConfig(extension, overrides) {
|
function getWebpackConfig(extension, overrides) {
|
||||||
overrides = overrides || {};
|
overrides = overrides || {};
|
||||||
var defaults = {
|
let defaults = {
|
||||||
cache: true,
|
cache: true,
|
||||||
externals: [{
|
externals: [{
|
||||||
'lodash': '_'
|
'lodash': '_'
|
||||||
}],
|
}],
|
||||||
entry: './src/index.js',
|
entry: './src/index.ts',
|
||||||
output: {
|
output: {
|
||||||
library: 'ripple',
|
library: 'ripple',
|
||||||
path: './build/',
|
path: path.join(__dirname, 'build/'),
|
||||||
filename: ['ripple-', extension].join(pkg.version)
|
filename: ['ripple-', extension].join(pkg.version)
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
@@ -44,18 +45,21 @@ function webpackConfig(extension, overrides) {
|
|||||||
'./setup-api-web')
|
'./setup-api-web')
|
||||||
],
|
],
|
||||||
module: {
|
module: {
|
||||||
loaders: [{
|
rules: [{
|
||||||
test: /jayson/,
|
test: /jayson/,
|
||||||
loader: 'null'
|
use: 'null',
|
||||||
}, {
|
}, {
|
||||||
test: /\.js$/,
|
test: /\.ts$/,
|
||||||
exclude: [/node_modules/],
|
use: 'ts-loader',
|
||||||
loader: 'babel-loader'
|
exclude: /node_modules/,
|
||||||
}, {
|
}, {
|
||||||
test: /\.json/,
|
test: /\.json/,
|
||||||
loader: 'json-loader'
|
use: 'json-loader',
|
||||||
}]
|
}]
|
||||||
}
|
},
|
||||||
|
resolve: {
|
||||||
|
extensions: [ '.ts', '.js' ]
|
||||||
|
},
|
||||||
};
|
};
|
||||||
return _.assign({}, defaults, overrides);
|
return _.assign({}, defaults, overrides);
|
||||||
}
|
}
|
||||||
@@ -78,7 +82,7 @@ function webpackConfigForWebTest(testFileName, path) {
|
|||||||
filename: match[1] + '-test.js'
|
filename: match[1] + '-test.js'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return webpackConfig('.js', configOverrides);
|
return getWebpackConfig('.js', configOverrides);
|
||||||
}
|
}
|
||||||
|
|
||||||
gulp.task('build-tests', function(callback) {
|
gulp.task('build-tests', function(callback) {
|
||||||
@@ -112,30 +116,29 @@ function createBuildLink(callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gulp.task('build', function(callback) {
|
gulp.task('build', function(callback) {
|
||||||
webpack(webpackConfig('.js'), createBuildLink(callback));
|
webpack(getWebpackConfig('.js'), createBuildLink(callback));
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('build-min', ['build'], function() {
|
gulp.task('build-min', function(callback) {
|
||||||
return gulp.src(['./build/ripple-', '.js'].join(pkg.version))
|
const webpackConfig = getWebpackConfig('-min.js');
|
||||||
.pipe(uglify(uglifyOptions))
|
webpackConfig.plugins.push(new UglifyJsPlugin({uglifyOptions}));
|
||||||
.pipe(rename(['ripple-', '-min.js'].join(pkg.version)))
|
webpack(webpackConfig, function() {
|
||||||
.pipe(gulp.dest('./build/'))
|
|
||||||
.on('end', function() {
|
|
||||||
createLink('./build/ripple-' + pkg.version + '-min.js',
|
createLink('./build/ripple-' + pkg.version + '-min.js',
|
||||||
'./build/ripple-latest-min.js');
|
'./build/ripple-latest-min.js');
|
||||||
|
callback();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('build-debug', function(callback) {
|
gulp.task('build-debug', function(callback) {
|
||||||
var configOverrides = {debug: true, devtool: 'eval'};
|
const webpackConfig = getWebpackConfig('-debug.js', {devtool: 'eval'});
|
||||||
webpack(webpackConfig('-debug.js', configOverrides), callback);
|
webpackConfig.plugins.unshift(new webpack.LoaderOptionsPlugin({debug: true}));
|
||||||
|
webpack(webpackConfig, callback);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a WebPack external for a given unavailable module which replaces
|
* Generate a WebPack external for a given unavailable module which replaces
|
||||||
* that module's constructor with an error-thrower
|
* that module's constructor with an error-thrower
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function buildUseError(cons) {
|
function buildUseError(cons) {
|
||||||
return ('var {<CONS>:function(){throw new Error('
|
return ('var {<CONS>:function(){throw new Error('
|
||||||
+ '"Class is unavailable in this build: <CONS>")}}')
|
+ '"Class is unavailable in this build: <CONS>")}}')
|
||||||
@@ -145,7 +148,7 @@ function buildUseError(cons) {
|
|||||||
gulp.task('build-core', function(callback) {
|
gulp.task('build-core', function(callback) {
|
||||||
var configOverrides = {
|
var configOverrides = {
|
||||||
cache: false,
|
cache: false,
|
||||||
entry: './src/remote.js',
|
entry: './src/remote.ts',
|
||||||
externals: [{
|
externals: [{
|
||||||
'./transaction': buildUseError('Transaction'),
|
'./transaction': buildUseError('Transaction'),
|
||||||
'./orderbook': buildUseError('OrderBook'),
|
'./orderbook': buildUseError('OrderBook'),
|
||||||
@@ -153,10 +156,10 @@ gulp.task('build-core', function(callback) {
|
|||||||
'./serializedobject': buildUseError('SerializedObject')
|
'./serializedobject': buildUseError('SerializedObject')
|
||||||
}],
|
}],
|
||||||
plugins: [
|
plugins: [
|
||||||
new webpack.optimize.UglifyJsPlugin()
|
new UglifyJsPlugin()
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
webpack(webpackConfig('-core.js', configOverrides), callback);
|
webpack(getWebpackConfig('-core.js', configOverrides), callback);
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('bower-build', ['build'], function() {
|
gulp.task('bower-build', ['build'], function() {
|
||||||
|
|||||||
349
HISTORY.md
349
HISTORY.md
@@ -1,59 +1,115 @@
|
|||||||
##0.16.5
|
# ripple-lib Release History
|
||||||
**Changes**
|
|
||||||
|
## 0.18.0 (2018-01-25)
|
||||||
|
|
||||||
|
+ [Convert from Flow to TypeScript](https://github.com/ripple/ripple-lib/pull/816)
|
||||||
|
+ [Use ES Module syntax](https://github.com/ripple/ripple-lib/pull/815) (Babel still compiles these to common.js modules for
|
||||||
|
distribution)
|
||||||
|
+ Docs: [Improve escrow creation example/test](https://github.com/ripple/ripple-lib/pull/820)
|
||||||
|
+ [Fix type errors](https://github.com/ripple/ripple-lib/pull/811)
|
||||||
|
+ [Fix lint errors](https://github.com/ripple/ripple-lib/pull/813)
|
||||||
|
|
||||||
|
The SHA-256 checksums for the browser version of this release can be found below.
|
||||||
|
```
|
||||||
|
% shasum -a 256 *
|
||||||
|
c97e2c820863b51f9ca8c98714406afb7cb4ba6d10c7dab5443c8c8579878665 ripple-0.18.0-debug.js
|
||||||
|
9f2b69045979b76735f436c4aa3e010d195e0407de5ac9c96289b8724c35da66 ripple-0.18.0-min.js
|
||||||
|
500db0411fe66e9550a07ee42229641afd7f544481c0cdddfcc87cccdb9f070f ripple-0.18.0.js
|
||||||
|
```
|
||||||
|
|
||||||
|
## 0.17.9 (2017-11-14)
|
||||||
|
|
||||||
|
+ [Update ws dependency to 3.3.1](https://github.com/ripple/ripple-lib/pull/804)
|
||||||
|
+ [Remove unnecessary polyfills](https://github.com/ripple/ripple-lib/pull/807)
|
||||||
|
+ Fix lint errors ([#786](https://github.com/ripple/ripple-lib/pull/786), [#808](https://github.com/ripple/ripple-lib/pull/808))
|
||||||
|
+ [Update ripple-keypairs dependency to 0.10.1](https://github.com/ripple/ripple-lib/pull/805)
|
||||||
|
|
||||||
|
The SHA-256 checksums for the browser version of this release can be found below.
|
||||||
|
```
|
||||||
|
% shasum -a 256 *
|
||||||
|
b52f251eedac2509d72093eab1e8dba0d0f4a9fe6a28ec1cc90853cfb0fd7110 ripple-0.17.9-debug.js
|
||||||
|
d577a2bbdbdf7535c5365a1c52a2a31989d1b966e30abcba65c87133a536b9dc ripple-0.17.9-min.js
|
||||||
|
ff4c3002842fac72ec2ebbd081e9594b0de6050d4d051a8fd6c06adb9a351488 ripple-0.17.9.js
|
||||||
|
```
|
||||||
|
|
||||||
|
The SHA-1 checksums for the browser version of this release can be found below.
|
||||||
|
```
|
||||||
|
% shasum *
|
||||||
|
e1995afc34aef6accd269cfccc55a45619618a41 ripple-0.17.9-debug.js
|
||||||
|
e6ad9a9c111ab696f5637bfa372d80999e5ae362 ripple-0.17.9-min.js
|
||||||
|
4866494ec5f9095cc34bea142f1e2b8ac5f7fbf8 ripple-0.17.9.js
|
||||||
|
```
|
||||||
|
|
||||||
|
## 0.17.8 (2017-11-06)
|
||||||
|
|
||||||
|
+ Fix: Freezing in Safari 10.1 (updated bignumber.js) (closes #762)
|
||||||
|
+ [Fix: `getSettings` should include signers](https://github.com/ripple/ripple-lib/commit/2a90f9b134e168937dceb7da283d63734eac9e7c)
|
||||||
|
+ Update for Node 6
|
||||||
|
+ Update lodash dependency
|
||||||
|
+ Migrate to yarn
|
||||||
|
|
||||||
|
## 0.17.7 (2017-05-08)
|
||||||
|
|
||||||
|
+ Replace AJV with jsonschema
|
||||||
|
|
||||||
|
## 0.16.5 (2016-01-21)
|
||||||
|
|
||||||
+ [Filter insufficient source funds paths from pathfind results](https://github.com/ripple/ripple-lib/pull/688)
|
+ [Filter insufficient source funds paths from pathfind results](https://github.com/ripple/ripple-lib/pull/688)
|
||||||
|
|
||||||
##0.16.4
|
## 0.16.4
|
||||||
**Changes**
|
|
||||||
+ [Update ws to 1.0.1](https://github.com/ripple/ripple-lib/pull/682)
|
|
||||||
|
|
||||||
##0.16.2
|
+ [Update `ws` to 1.0.1](https://github.com/ripple/ripple-lib/pull/682)
|
||||||
**Changes**
|
|
||||||
+ [Bump ripple-binary-codec dependency version to 0.1.1 to fix issue with computeLedgerHash for transactions with DeliverMin]
|
## 0.16.2
|
||||||
|
|
||||||
|
+ Bump `ripple-binary-codec` dependency version to 0.1.1 to fix issue with `computeLedgerHash` for transactions with `DeliverMin`
|
||||||
|
|
||||||
|
## 0.16.1
|
||||||
|
|
||||||
##0.16.1
|
|
||||||
**Changes**
|
|
||||||
+ [FIX: Use assert not assert-diff](https://github.com/ripple/ripple-lib/commit/f6ebe325193e7208c5ee8d8e84a7504714f0009e)
|
+ [FIX: Use assert not assert-diff](https://github.com/ripple/ripple-lib/commit/f6ebe325193e7208c5ee8d8e84a7504714f0009e)
|
||||||
|
|
||||||
##0.16.0
|
## 0.16.0
|
||||||
**Breaking Changes**
|
|
||||||
+ [Fix types of XRP values in getServerInfo response](https://github.com/ripple/ripple-lib/commit/99d08065e4bda3dda6ae1f183adbd11abc70a9b7)
|
|
||||||
+ [Change error event format and fix crash due to error event on webscocket](https://github.com/ripple/ripple-lib/commit/9cd72595f0efc062d77b9d625695d6030c524cc6)
|
|
||||||
|
|
||||||
**Changes**
|
__BREAKING CHANGES__
|
||||||
+ [Fix generateAddress docs and add error event listener to boilerplate](https://github.com/ripple/ripple-lib/commit/809d981987a2890fac3a73a40a05c598b9040334)
|
+ [Fix types of XRP values in `getServerInfo` response](https://github.com/ripple/ripple-lib/commit/99d08065e4bda3dda6ae1f183adbd11abc70a9b7)
|
||||||
+ [Allow setting maxLedgerVersion to null to specify no maximum](https://github.com/ripple/ripple-lib/commit/82613e7e8b360d1ae1552eab4559ab4763c06d7e)
|
+ [Change error event format and fix crash due to error event on websocket](https://github.com/ripple/ripple-lib/commit/9cd72595f0efc062d77b9d625695d6030c524cc6)
|
||||||
|
|
||||||
|
__OTHER CHANGES__
|
||||||
|
+ [Fix `generateAddress` docs and add error event listener to boilerplate](https://github.com/ripple/ripple-lib/commit/809d981987a2890fac3a73a40a05c598b9040334)
|
||||||
|
+ [Allow setting `maxLedgerVersion` to `null` to specify no maximum](https://github.com/ripple/ripple-lib/commit/82613e7e8b360d1ae1552eab4559ab4763c06d7e)
|
||||||
+ [Add support for client certificates](https://github.com/ripple/ripple-lib/commit/5f5e48e4140345d166b8c1a3ee0847b0d9e2d893)
|
+ [Add support for client certificates](https://github.com/ripple/ripple-lib/commit/5f5e48e4140345d166b8c1a3ee0847b0d9e2d893)
|
||||||
+ [getFee returns a string not float](https://github.com/ripple/ripple-lib/commit/7bf2da6014c87e164542e69356efeaabb575a157)
|
+ [`getFee` returns a string not a float](https://github.com/ripple/ripple-lib/commit/7bf2da6014c87e164542e69356efeaabb575a157)
|
||||||
+ [Fix parsing of quality for getTrustlines](https://github.com/ripple/ripple-lib/commit/86ff315ef2a39dfdc2ce97e0e1c4aa73f04e363b)
|
+ [Fix parsing of quality for `getTrustlines`](https://github.com/ripple/ripple-lib/commit/86ff315ef2a39dfdc2ce97e0e1c4aa73f04e363b)
|
||||||
+ [Fix DeliverMin value when specifying minAmount](Fix DeliverMin value when specifying minAmount)
|
+ Fix `DeliverMin` value when specifying `minAmount`
|
||||||
+ [http server example](https://github.com/ripple/ripple-lib/commit/76866ab901ea46a2dd73181605e0f7f4220043d4)
|
+ [http server example](https://github.com/ripple/ripple-lib/commit/76866ab901ea46a2dd73181605e0f7f4220043d4)
|
||||||
|
|
||||||
|
## 0.15.2
|
||||||
|
|
||||||
##0.15.2
|
|
||||||
**Changes**
|
|
||||||
+ [Fix support for proxy credentials in proxy URL and fix error when there are more than 10 outstanding requests](https://github.com/ripple/ripple-lib/commit/0990ad4a6f1d59ca9d2cb859b4e2d71693f3fc4b)
|
+ [Fix support for proxy credentials in proxy URL and fix error when there are more than 10 outstanding requests](https://github.com/ripple/ripple-lib/commit/0990ad4a6f1d59ca9d2cb859b4e2d71693f3fc4b)
|
||||||
|
|
||||||
##0.15.1
|
## 0.15.1
|
||||||
**Changes**
|
|
||||||
+ [Fix babel-polyfill require](https://github.com/ripple/ripple-lib/commit/062148674c3b1293ab82c28e25615ddd530339fa)
|
|
||||||
+ [Fix samples](https://github.com/ripple/ripple-lib/commit/5d5cf868a2ddb1b1cd40e4a4f0a782d0066c2055)
|
|
||||||
+ [add unit tests for RippleAPIBroadcast](https://github.com/ripple/ripple-lib/commit/ddf8fe5b1a9c750490dca98fb9ffaaf8017f87e0)
|
|
||||||
|
|
||||||
##0.15.0
|
+ [Fix `babel-polyfill` require](https://github.com/ripple/ripple-lib/commit/062148674c3b1293ab82c28e25615ddd530339fa)
|
||||||
**Breaking Changes**
|
+ [Fix samples](https://github.com/ripple/ripple-lib/commit/5d5cf868a2ddb1b1cd40e4a4f0a782d0066c2055)
|
||||||
|
+ [Add unit tests for `RippleAPIBroadcast`](https://github.com/ripple/ripple-lib/commit/ddf8fe5b1a9c750490dca98fb9ffaaf8017f87e0)
|
||||||
|
|
||||||
|
## 0.15.0
|
||||||
|
|
||||||
|
__BREAKING CHANGES__
|
||||||
+ ["servers" parameter changed to single "server"](https://github.com/ripple/ripple-lib/commit/7061e9afe46f0682254d098adeff3dd7157521a1)
|
+ ["servers" parameter changed to single "server"](https://github.com/ripple/ripple-lib/commit/7061e9afe46f0682254d098adeff3dd7157521a1)
|
||||||
|
|
||||||
**Changes**
|
__OTHER CHANGES__
|
||||||
+ [fix handling memos in prepareSettings](https://github.com/ripple/ripple-lib/commit/c9704137b7b538e8dbf31c483bcdcf2dcfd7cd75)
|
+ [Fix handling memos in `prepareSettings`](https://github.com/ripple/ripple-lib/commit/c9704137b7b538e8dbf31c483bcdcf2dcfd7cd75)
|
||||||
+ [Docs: SusPay warnings, offline mode, and other tweaks](https://github.com/ripple/ripple-lib/commit/4b4fc36ebd93f1360781a65f2869bd2c4f0a5093)
|
+ [Docs: SusPay warnings, offline mode, and other tweaks](https://github.com/ripple/ripple-lib/commit/4b4fc36ebd93f1360781a65f2869bd2c4f0a5093)
|
||||||
+ [Fix prepareOrderCancellation documentation](https://github.com/ripple/ripple-lib/commit/5e720891f579fd73d43c64e5ec519d9121023c10)
|
+ [Fix prepareOrderCancellation documentation](https://github.com/ripple/ripple-lib/commit/5e720891f579fd73d43c64e5ec519d9121023c10)
|
||||||
|
|
||||||
##0.14.0
|
## 0.14.0
|
||||||
**Breaking Changes**
|
|
||||||
+ [prepareOrderCancellation now takes orderCancellation specification](https://github.com/ripple/ripple-lib/commit/7f33d8a71e56289e5a5e0ead1c74f75ebcde72bc)
|
__BREAKING CHANGES__
|
||||||
|
+ [`prepareOrderCancellation` now takes orderCancellation specification](https://github.com/ripple/ripple-lib/commit/7f33d8a71e56289e5a5e0ead1c74f75ebcde72bc)
|
||||||
+ [Rename "ledgerClosed" event to "ledger" and change format](https://github.com/ripple/ripple-lib/commit/8a3d4a64db5fbf560ebf87dc62e0212513c5e18a)
|
+ [Rename "ledgerClosed" event to "ledger" and change format](https://github.com/ripple/ripple-lib/commit/8a3d4a64db5fbf560ebf87dc62e0212513c5e18a)
|
||||||
|
|
||||||
**Changes**
|
__OTHER CHANGES__
|
||||||
+ [Fix proxy support and add support for proxy authorization](https://github.com/ripple/ripple-lib/commit/14b840f3feca758e0384b746c94e36d8bf59b8c2)
|
+ [Fix proxy support and add support for proxy authorization](https://github.com/ripple/ripple-lib/commit/14b840f3feca758e0384b746c94e36d8bf59b8c2)
|
||||||
+ [Fix trace option](https://github.com/ripple/ripple-lib/commit/af620755c53556c55eed12de4b0013ef5a349ce2)
|
+ [Fix trace option](https://github.com/ripple/ripple-lib/commit/af620755c53556c55eed12de4b0013ef5a349ce2)
|
||||||
+ [Allow memos on all transaction types](https://github.com/ripple/ripple-lib/commit/b5081344da8e66fbd3a5113cc3313325ef72a494)
|
+ [Allow memos on all transaction types](https://github.com/ripple/ripple-lib/commit/b5081344da8e66fbd3a5113cc3313325ef72a494)
|
||||||
@@ -62,26 +118,24 @@
|
|||||||
+ [Docs: revised introductory material](https://github.com/ripple/ripple-lib/commit/ef2515507dbd3c6a426ab5b31332a1bdf72d5b2d)
|
+ [Docs: revised introductory material](https://github.com/ripple/ripple-lib/commit/ef2515507dbd3c6a426ab5b31332a1bdf72d5b2d)
|
||||||
+ [boost coverage to almost 100%](https://github.com/ripple/ripple-lib/commit/995606b1e6f3643af34d9fd442ccd31f320b03eb)
|
+ [boost coverage to almost 100%](https://github.com/ripple/ripple-lib/commit/995606b1e6f3643af34d9fd442ccd31f320b03eb)
|
||||||
|
|
||||||
##0.13.2
|
## 0.13.2
|
||||||
|
|
||||||
**Changes**
|
|
||||||
+ [Fix: Specify send_max when pathfinding with a source amount](https://github.com/ripple/ripple-lib/commit/75142139184625c8b9fcc480b1825d9985337813)
|
+ [Fix: Specify send_max when pathfinding with a source amount](https://github.com/ripple/ripple-lib/commit/75142139184625c8b9fcc480b1825d9985337813)
|
||||||
|
|
||||||
##0.13.1
|
## 0.13.1
|
||||||
+ [Add documentation for API events](https://github.com/ripple/ripple-lib/commit/25d1ac0c5f95cad32ea4ceebb))
|
|
||||||
|
|
||||||
**Changes**
|
+ [Add documentation for API events](https://github.com/ripple/ripple-lib/commit/25d1ac0c5f95cad32ea4ceebb)
|
||||||
+ [Fix: Add babel-polyfill](https://github.com/ripple/ripple-lib/commit/8a53abc32f6ec6c7d50cd182492d6fb511b86704)
|
+ [Fix: Add babel-polyfill](https://github.com/ripple/ripple-lib/commit/8a53abc32f6ec6c7d50cd182492d6fb511b86704)
|
||||||
+ [Fix: Bump version on ripple-hashes](https://github.com/ripple/ripple-lib/commit/12e5765c64aea31b3c2fb65ff989cf01e6368f58)
|
+ [Fix: Bump version on ripple-hashes](https://github.com/ripple/ripple-lib/commit/12e5765c64aea31b3c2fb65ff989cf01e6368f58)
|
||||||
|
|
||||||
##0.13.0
|
## 0.13.0
|
||||||
|
|
||||||
**Breaking Changes**
|
__BREAKING CHANGES__
|
||||||
+ Add new RippleAPI interface and delete old API
|
+ Add new RippleAPI interface and delete old API
|
||||||
- [RippleAPI README and samples](https://github.com/ripple/ripple-lib/tree/develop/docs/samples)
|
- [RippleAPI README and samples](https://github.com/ripple/ripple-lib/tree/develop/docs/samples)
|
||||||
- [Method documentation](https://rawgit.com/ripple/ripple-lib/develop/docs/api.html)
|
- [Method documentation](https://rawgit.com/ripple/ripple-lib/develop/docs/api.html)
|
||||||
|
|
||||||
**Changes**
|
__OTHER CHANGES__
|
||||||
+ [Removed timeout method of Request and added default timeout](https://github.com/ripple/ripple-lib/commit/634fe5683a9082e57682ff7d5c4fb9483b4af818)
|
+ [Removed timeout method of Request and added default timeout](https://github.com/ripple/ripple-lib/commit/634fe5683a9082e57682ff7d5c4fb9483b4af818)
|
||||||
+ [Add Remote.closeCurrentPathFind function, so current pathfind can be properly closed](https://github.com/ripple/ripple-lib/commit/e99010f363fc7cbe7fd547d3ca5b32ea083c44e6)
|
+ [Add Remote.closeCurrentPathFind function, so current pathfind can be properly closed](https://github.com/ripple/ripple-lib/commit/e99010f363fc7cbe7fd547d3ca5b32ea083c44e6)
|
||||||
+ [Implement Balance Sheet API](https://github.com/ripple/ripple-lib/pull/579)
|
+ [Implement Balance Sheet API](https://github.com/ripple/ripple-lib/pull/579)
|
||||||
@@ -89,125 +143,85 @@
|
|||||||
+ [Fix crash due to rippled slowDown error](https://github.com/ripple/ripple-lib/commit/84838b2e9f6969b593b8462a62a6b8f516ada937)
|
+ [Fix crash due to rippled slowDown error](https://github.com/ripple/ripple-lib/commit/84838b2e9f6969b593b8462a62a6b8f516ada937)
|
||||||
+ [Fix: Emit error events and return error on pathfind](https://github.com/ripple/ripple-lib/commit/1ccbaf677631a1944eb05d90f7afc5f3690a03dd)
|
+ [Fix: Emit error events and return error on pathfind](https://github.com/ripple/ripple-lib/commit/1ccbaf677631a1944eb05d90f7afc5f3690a03dd)
|
||||||
+ [Deprecate core and remove snake case method copying](https://github.com/ripple/ripple-lib/commit/fb8dc44ec1d49bb05cd0cdbe6dd4ab211195868a)
|
+ [Deprecate core and remove snake case method copying](https://github.com/ripple/ripple-lib/commit/fb8dc44ec1d49bb05cd0cdbe6dd4ab211195868a)
|
||||||
|
|
||||||
+ [Fix RangeSet for validated_ledger as single ledger](https://github.com/ripple/ripple-lib/commit/9f9e76f8b933201651af59307135f67cfa7d60e8)
|
+ [Fix RangeSet for validated_ledger as single ledger](https://github.com/ripple/ripple-lib/commit/9f9e76f8b933201651af59307135f67cfa7d60e8)
|
||||||
+ [Fix bug where the paths would be set with an empty array](https://github.com/ripple/ripple-lib/commit/83874ec0962da311b76f2385623e51c68bc39035)
|
+ [Fix bug where the paths would be set with an empty array](https://github.com/ripple/ripple-lib/commit/83874ec0962da311b76f2385623e51c68bc39035)
|
||||||
+ [Fix reserve calculation](https://github.com/ripple/ripple-lib/commit/52879febb92d876f01f2e4d70871baa07af631fb)
|
+ [Fix reserve calculation](https://github.com/ripple/ripple-lib/commit/52879febb92d876f01f2e4d70871baa07af631fb)
|
||||||
|
|
||||||
##0.12.9
|
## 0.12.9
|
||||||
|
|
||||||
+ [OrderBook performance optimizations](https://github.com/ripple/ripple-lib/commit/3e17d91edf36745f6b6c09b0ad88971b7775f6ab)
|
+ [OrderBook performance optimizations](https://github.com/ripple/ripple-lib/commit/3e17d91edf36745f6b6c09b0ad88971b7775f6ab)
|
||||||
|
|
||||||
##0.12.7 and 0.12.8
|
## 0.12.7 and 0.12.8
|
||||||
|
|
||||||
+ [Improve performance of orderbook](https://github.com/ripple/ripple-lib/commit/c745faaaf0956ca98448a754b4fe97fb50574fc7)
|
+ [Improve performance of orderbook](https://github.com/ripple/ripple-lib/commit/c745faaaf0956ca98448a754b4fe97fb50574fc7)
|
||||||
|
|
||||||
+ [Remove Firefox warning about prototype overwrite](https://github.com/ripple/ripple-lib/commit/0c62fa21123b220b066871e1c41a3b4fe6f51885)
|
+ [Remove Firefox warning about prototype overwrite](https://github.com/ripple/ripple-lib/commit/0c62fa21123b220b066871e1c41a3b4fe6f51885)
|
||||||
|
+ [Fix compare bug in `Amount` class](https://github.com/ripple/ripple-lib/commit/806547dd154e1b0bf252e8a74ad3ac6aa8a97660)
|
||||||
|
|
||||||
+ [Fix compare bug in Amount class](https://github.com/ripple/ripple-lib/commit/806547dd154e1b0bf252e8a74ad3ac6aa8a97660)
|
## 0.12.6
|
||||||
|
|
||||||
##0.12.6
|
|
||||||
|
|
||||||
+ [Fix webpack require failure due to "./" notation](https://github.com/ripple/ripple-lib/commit/8d9746d7b10be203ee613df523c2522012ff1baf)
|
+ [Fix webpack require failure due to "./" notation](https://github.com/ripple/ripple-lib/commit/8d9746d7b10be203ee613df523c2522012ff1baf)
|
||||||
|
|
||||||
##0.12.15
|
## 0.12.15
|
||||||
|
|
||||||
+ [Add offer autobridging](https://github.com/ripple/ripple-lib/commit/c7bbce83719c1e8c6a4fae5ca850e7515db1a4a5)
|
+ [Add offer autobridging](https://github.com/ripple/ripple-lib/commit/c7bbce83719c1e8c6a4fae5ca850e7515db1a4a5)
|
||||||
|
|
||||||
+ [Prevent crash when listening for "model" events on the OrderBook class](https://github.com/ripple/ripple-lib/commit/5824c3cb7cb6bd834d6e037f69943aebf3d83351)
|
+ [Prevent crash when listening for "model" events on the OrderBook class](https://github.com/ripple/ripple-lib/commit/5824c3cb7cb6bd834d6e037f69943aebf3d83351)
|
||||||
|
|
||||||
+ [Fix empty order edgecase](https://github.com/ripple/ripple-lib/commit/64809d9ae23dc24f47accd4b4788b48f49880d3e)
|
+ [Fix empty order edgecase](https://github.com/ripple/ripple-lib/commit/64809d9ae23dc24f47accd4b4788b48f49880d3e)
|
||||||
|
|
||||||
+ [Fix AutobridgeCalculator (RT-3445)](https://github.com/ripple/ripple-lib/commit/1fff5ea6dcbcee856536df26f3b9cf1aec3c3b55)
|
+ [Fix AutobridgeCalculator (RT-3445)](https://github.com/ripple/ripple-lib/commit/1fff5ea6dcbcee856536df26f3b9cf1aec3c3b55)
|
||||||
|
|
||||||
+ [Update sjcl and delete custom ripemd160, montgomery, and jacobi](https://github.com/ripple/ripple-lib/commit/50cda426eb83599c38c0b725e1524a01fc415da2)
|
+ [Update sjcl and delete custom ripemd160, montgomery, and jacobi](https://github.com/ripple/ripple-lib/commit/50cda426eb83599c38c0b725e1524a01fc415da2)
|
||||||
|
|
||||||
+ [Fix transaction summary for transactions that fail with remoteError](https://github.com/ripple/ripple-lib/commit/5e714f6143464d7912f42537acaa553b88eaf6dc)
|
+ [Fix transaction summary for transactions that fail with remoteError](https://github.com/ripple/ripple-lib/commit/5e714f6143464d7912f42537acaa553b88eaf6dc)
|
||||||
|
|
||||||
+ [Fix serializedobject append for excessively large bytes length](https://github.com/ripple/ripple-lib/commit/e93f1ab6f4aaad347450aee75a169af0faa2121c)
|
+ [Fix serializedobject append for excessively large bytes length](https://github.com/ripple/ripple-lib/commit/e93f1ab6f4aaad347450aee75a169af0faa2121c)
|
||||||
|
|
||||||
+ [Switch to sjcl npm module](https://github.com/ripple/ripple-lib/commit/9a502580fd89ec6a9aa55f4e5847f6a4a2cb5bba)
|
+ [Switch to sjcl npm module](https://github.com/ripple/ripple-lib/commit/9a502580fd89ec6a9aa55f4e5847f6a4a2cb5bba)
|
||||||
|
|
||||||
+ [Add babel transpiler](https://github.com/ripple/ripple-lib/commit/398f8d001f758bf575b959537a17e79e4042d17b)
|
+ [Add babel transpiler](https://github.com/ripple/ripple-lib/commit/398f8d001f758bf575b959537a17e79e4042d17b)
|
||||||
|
|
||||||
+ [Remove unused float.js and wallet.js](https://github.com/ripple/ripple-lib/commit/d4a4b5f4fbbf09677a59ce81bace35c6426a2fda)
|
+ [Remove unused float.js and wallet.js](https://github.com/ripple/ripple-lib/commit/d4a4b5f4fbbf09677a59ce81bace35c6426a2fda)
|
||||||
|
|
||||||
+ [Remove config singleton to reduce global state](https://github.com/ripple/ripple-lib/commit/c655c2a20ee5d150a4b5a1b6717b9fb81f636025)
|
+ [Remove config singleton to reduce global state](https://github.com/ripple/ripple-lib/commit/c655c2a20ee5d150a4b5a1b6717b9fb81f636025)
|
||||||
|
|
||||||
##0.12.4
|
## 0.12.4
|
||||||
|
|
||||||
+ [Improve entropy security](https://github.com/ripple/ripple-lib/commit/c7ba822320880037796f57876d1abb4e525648ed)
|
+ [Improve entropy security](https://github.com/ripple/ripple-lib/commit/c7ba822320880037796f57876d1abb4e525648ed)
|
||||||
|
|
||||||
+ [Remove unused crypt.js file](https://github.com/ripple/ripple-lib/commit/1f68eba1461bca03a4d22872450d15ae5a185334)
|
+ [Remove unused crypt.js file](https://github.com/ripple/ripple-lib/commit/1f68eba1461bca03a4d22872450d15ae5a185334)
|
||||||
|
|
||||||
##0.12.3
|
## 0.12.3
|
||||||
|
|
||||||
+ [Add getLedgerSequence to Remote](https://github.com/ripple/ripple-lib/commit/d09548d04d3238fca653d482ec1d5faa7254559a)
|
+ [Add getLedgerSequence to Remote](https://github.com/ripple/ripple-lib/commit/d09548d04d3238fca653d482ec1d5faa7254559a)
|
||||||
|
|
||||||
+ [Improve randomness when generating ECDSA signatures](https://github.com/ripple/ripple-lib/commit/fe7e30b737ead6e71adfa466f5835ba546feab31)
|
+ [Improve randomness when generating ECDSA signatures](https://github.com/ripple/ripple-lib/commit/fe7e30b737ead6e71adfa466f5835ba546feab31)
|
||||||
|
|
||||||
+ [Improve SerializedObject.append performance](https://github.com/ripple/ripple-lib/commit/f7c35b118ebba549a64bcaa1a0629385ec6dbf6f)
|
+ [Improve SerializedObject.append performance](https://github.com/ripple/ripple-lib/commit/f7c35b118ebba549a64bcaa1a0629385ec6dbf6f)
|
||||||
|
|
||||||
+ [Add `Amount.scale`. Multiply an amount’s value by a scale factor](https://github.com/ripple/ripple-lib/commit/74dac97b368493056474468520f05671f458a69f)
|
+ [Add `Amount.scale`. Multiply an amount’s value by a scale factor](https://github.com/ripple/ripple-lib/commit/74dac97b368493056474468520f05671f458a69f)
|
||||||
|
|
||||||
|
## 0.12.2
|
||||||
##0.12.2
|
|
||||||
|
|
||||||
+ [Check that stack trace is available, fixes logging in browser](https://github.com/ripple/ripple-lib/commit/53cae3a66d48e88e8a6bbb96d6489ce7b9e22975)
|
+ [Check that stack trace is available, fixes logging in browser](https://github.com/ripple/ripple-lib/commit/53cae3a66d48e88e8a6bbb96d6489ce7b9e22975)
|
||||||
|
|
||||||
|
## 0.12.1
|
||||||
|
|
||||||
##0.12.1
|
__BREAKING CHANGES__
|
||||||
|
|
||||||
**Breaking Changes**
|
|
||||||
|
|
||||||
+ [Removed support for parsing native amounts in floating point format](https://github.com/ripple/ripple-lib/commit/e80cd1ff55deae9cd5b0ae85be957f86856b887e)
|
+ [Removed support for parsing native amounts in floating point format](https://github.com/ripple/ripple-lib/commit/e80cd1ff55deae9cd5b0ae85be957f86856b887e)
|
||||||
|
|
||||||
|
__OTHER CHANGES__
|
||||||
**Changes**
|
|
||||||
|
|
||||||
+ [Fix taker pays funded calculation](https://github.com/ripple/ripple-lib/commit/5af824f5cf46c7b9caa58ee0a757bf854d26c8dc)
|
+ [Fix taker pays funded calculation](https://github.com/ripple/ripple-lib/commit/5af824f5cf46c7b9caa58ee0a757bf854d26c8dc)
|
||||||
|
|
||||||
+ [Fix order funded amount calculation](https://github.com/ripple/ripple-lib/commit/b2cdb1a6aed968b1f306e8dadbd4b7ca37e5aa03)
|
+ [Fix order funded amount calculation](https://github.com/ripple/ripple-lib/commit/b2cdb1a6aed968b1f306e8dadbd4b7ca37e5aa03)
|
||||||
|
|
||||||
+ [Fix handling of quality in order book](https://github.com/ripple/ripple-lib/commit/2a5a8b498da60df738ba18d5c265f34771e8a1af)
|
+ [Fix handling of quality in order book](https://github.com/ripple/ripple-lib/commit/2a5a8b498da60df738ba18d5c265f34771e8a1af)
|
||||||
|
|
||||||
+ [Fix currency parsing of non-alphanumeric and no-currency currencies](https://github.com/ripple/ripple-lib/commit/2166bb2e88eae8d5f1aba77338f69e8a9edf6a6f)
|
+ [Fix currency parsing of non-alphanumeric and no-currency currencies](https://github.com/ripple/ripple-lib/commit/2166bb2e88eae8d5f1aba77338f69e8a9edf6a6f)
|
||||||
|
|
||||||
+ [Add Amount.strict_mode for toggling range validation](https://github.com/ripple/ripple-lib/commit/b5ed8f59a7dab1a17491618b8d9193646c314fb4)
|
+ [Add Amount.strict_mode for toggling range validation](https://github.com/ripple/ripple-lib/commit/b5ed8f59a7dab1a17491618b8d9193646c314fb4)
|
||||||
|
|
||||||
+ [Add filename and line number to log, use log.warn() for deprecations](https://github.com/ripple/ripple-lib/commit/90329d3d73f1a76675063655b407513e32dc048b)
|
+ [Add filename and line number to log, use log.warn() for deprecations](https://github.com/ripple/ripple-lib/commit/90329d3d73f1a76675063655b407513e32dc048b)
|
||||||
|
|
||||||
+ [Add GlobalFreeze and NoFreeze flags](https://github.com/ripple/ripple-lib/commit/e2ed2bdbf6f01c7d4d690c2cf0b83fba94558dd7)
|
+ [Add GlobalFreeze and NoFreeze flags](https://github.com/ripple/ripple-lib/commit/e2ed2bdbf6f01c7d4d690c2cf0b83fba94558dd7)
|
||||||
|
|
||||||
+ [Fix handling of falsy parameters in requestLedger](https://github.com/ripple/ripple-lib/commit/6023efed41b7812b3bab660a1c0dc9f0a21000b9)
|
+ [Fix handling of falsy parameters in requestLedger](https://github.com/ripple/ripple-lib/commit/6023efed41b7812b3bab660a1c0dc9f0a21000b9)
|
||||||
|
|
||||||
+ [Fix Base:decode](https://github.com/ripple/ripple-lib/commit/719f39c01c6941d9a650aa94f95617793dd53ea0)
|
+ [Fix Base:decode](https://github.com/ripple/ripple-lib/commit/719f39c01c6941d9a650aa94f95617793dd53ea0)
|
||||||
|
|
||||||
+ [Fix Amount: clone in ratio_human, product_human](https://github.com/ripple/ripple-lib/commit/19e17a8431550cf156b1ad669a19dedfe4e28e4a)
|
+ [Fix Amount: clone in ratio_human, product_human](https://github.com/ripple/ripple-lib/commit/19e17a8431550cf156b1ad669a19dedfe4e28e4a)
|
||||||
|
|
||||||
+ [Fix Amount.to_human for very small numbers](https://github.com/ripple/ripple-lib/commit/6abfa759aa09d68074ac558d96c4b126a7cd1719)
|
+ [Fix Amount.to_human for very small numbers](https://github.com/ripple/ripple-lib/commit/6abfa759aa09d68074ac558d96c4b126a7cd1719)
|
||||||
|
|
||||||
+ [Refactor base conversion](https://github.com/ripple/ripple-lib/commit/f2b63fa4a80663eb29472bc6bb1aea8159f1f205)
|
+ [Refactor base conversion](https://github.com/ripple/ripple-lib/commit/f2b63fa4a80663eb29472bc6bb1aea8159f1f205)
|
||||||
|
|
||||||
+ [Update binary transaction format](https://github.com/ripple/ripple-lib/commit/8e134918fb4c22983320a3102f955e4568bb1dfb)
|
+ [Update binary transaction format](https://github.com/ripple/ripple-lib/commit/8e134918fb4c22983320a3102f955e4568bb1dfb)
|
||||||
|
|
||||||
+ [Add DefaultRipple account flag](https://github.com/ripple/ripple-lib/commit/3e249902c4cf25b4da5e75048c84ae391be83b10)
|
+ [Add DefaultRipple account flag](https://github.com/ripple/ripple-lib/commit/3e249902c4cf25b4da5e75048c84ae391be83b10)
|
||||||
|
|
||||||
+ [Remove `Features` field requirement in `SetFee` transaction format](https://github.com/ripple/ripple-lib/commit/a20a649013646710c078d4ce1e210f87c7fe74fe)
|
+ [Remove `Features` field requirement in `SetFee` transaction format](https://github.com/ripple/ripple-lib/commit/a20a649013646710c078d4ce1e210f87c7fe74fe)
|
||||||
|
|
||||||
+ [Remove `RegularKey` field requirement in `SetRegularKey` transaction format](https://github.com/ripple/ripple-lib/commit/c275174f27877ba8f389eb4efe969feb514d6e46)
|
+ [Remove `RegularKey` field requirement in `SetRegularKey` transaction format](https://github.com/ripple/ripple-lib/commit/c275174f27877ba8f389eb4efe969feb514d6e46)
|
||||||
|
|
||||||
|
## 0.12.0
|
||||||
|
|
||||||
##0.12.0
|
__BREAKING CHANGES__
|
||||||
|
|
||||||
**Breaking Changes**
|
|
||||||
|
|
||||||
+ REMOVED Remote storage interface
|
+ REMOVED Remote storage interface
|
||||||
+ REMOVED Remote `ping` configuration
|
+ REMOVED Remote `ping` configuration
|
||||||
+ REMOVED Old/deprecated Remote server configuration (websocket_ip, websocket_port)
|
+ REMOVED Old/deprecated Remote server configuration (websocket_ip, websocket_port)
|
||||||
+ REMOVED browser `online` reconnect listener
|
+ REMOVED browser `online` reconnect listener
|
||||||
- [Cleanup, deprecations - 2833a7b6](https://github.com/ripple/ripple-lib/commit/2833a7b66e696dab427464625077f9b93092d0d5)
|
- [Cleanup, deprecations - 2833a7b6](https://github.com/ripple/ripple-lib/commit/2833a7b66e696dab427464625077f9b93092d0d5)
|
||||||
|
|
||||||
+ Remove `jsbn` and use `bignumber.js` instead for big number math
|
+ Remove `jsbn` and use `bignumber.js` instead for big number math
|
||||||
+ The `allow_nan` flag has been removed. Results for invalid amounts will always be `NaN`
|
+ The `allow_nan` flag has been removed. Results for invalid amounts will always be `NaN`
|
||||||
- [Refactor to use bignumber.js - d025b4a0](https://github.com/ripple/ripple-lib/commit/d025b4a0c3a98a6de27a1bee9573c85347bcd66b)
|
- [Refactor to use bignumber.js - d025b4a0](https://github.com/ripple/ripple-lib/commit/d025b4a0c3a98a6de27a1bee9573c85347bcd66b)
|
||||||
@@ -215,109 +229,76 @@
|
|||||||
- [Check for null in isNumber - b86790c8](https://github.com/ripple/ripple-lib/commit/b86790c8543c239a532fd7697d4652829019d385)
|
- [Check for null in isNumber - b86790c8](https://github.com/ripple/ripple-lib/commit/b86790c8543c239a532fd7697d4652829019d385)
|
||||||
- [Cleanup amount.js - d0fb291c](https://github.com/ripple/ripple-lib/commit/d0fb291c4e330193a244902156f1d74730da357d)
|
- [Cleanup amount.js - d0fb291c](https://github.com/ripple/ripple-lib/commit/d0fb291c4e330193a244902156f1d74730da357d)
|
||||||
|
|
||||||
|
__OTHER CHANGES__
|
||||||
**Changes**
|
|
||||||
|
|
||||||
+ [Add deprecation warnings to request constructors. The first argument to request constructor functions should be an object containing request properties](https://github.com/ripple/ripple-lib/commit/35d76b3520934285f80059c1badd6c522539104c)
|
+ [Add deprecation warnings to request constructors. The first argument to request constructor functions should be an object containing request properties](https://github.com/ripple/ripple-lib/commit/35d76b3520934285f80059c1badd6c522539104c)
|
||||||
|
|
||||||
+ [Fix taker_gets_funded exceeding offer.TakerGets](https://github.com/ripple/ripple-lib/commit/b19ecb4482b589d575382b7a5d0480b963383bb1)
|
+ [Fix taker_gets_funded exceeding offer.TakerGets](https://github.com/ripple/ripple-lib/commit/b19ecb4482b589d575382b7a5d0480b963383bb1)
|
||||||
|
|
||||||
+ [Fix unsymmetric memo serializing](https://github.com/ripple/ripple-lib/commit/1ed36fabdbd54f4d31078c2b0eaa3becc0fe2821)
|
+ [Fix unsymmetric memo serializing](https://github.com/ripple/ripple-lib/commit/1ed36fabdbd54f4d31078c2b0eaa3becc0fe2821)
|
||||||
|
|
||||||
+ [Fix IOU value passed to `Amount.from_json()`](https://github.com/ripple/ripple-lib/commit/fd1b64393dffb3d1819cd40b8d43df43a4db042d)
|
+ [Fix IOU value passed to `Amount.from_json()`](https://github.com/ripple/ripple-lib/commit/fd1b64393dffb3d1819cd40b8d43df43a4db042d)
|
||||||
|
|
||||||
+ [Update transaction binary parsing to account for XRP delivered amounts](https://github.com/ripple/ripple-lib/commit/35a346a674e6ee1e1e495db93700d55984efc7dd)
|
+ [Update transaction binary parsing to account for XRP delivered amounts](https://github.com/ripple/ripple-lib/commit/35a346a674e6ee1e1e495db93700d55984efc7dd)
|
||||||
|
|
||||||
+ [Bumped dependencies](https://github.com/ripple/ripple-lib/commit/f9bc7cc746b44b24b61bbe260ae2e9d9617286da)
|
+ [Bumped dependencies](https://github.com/ripple/ripple-lib/commit/f9bc7cc746b44b24b61bbe260ae2e9d9617286da)
|
||||||
|
|
||||||
|
## 0.11.0
|
||||||
|
|
||||||
##0.11.0
|
|
||||||
|
|
||||||
+ [Track the funded status of an order based on cumulative account orders](https://github.com/ripple/ripple-lib/commit/67d39737a4d5e0fcd9d9b47b9083ee00e5a9e652) and [67d3973](https://github.com/ripple/ripple-lib/commit/b6b99dde022e1e14c4797e454b1d7fca50e49482)
|
+ [Track the funded status of an order based on cumulative account orders](https://github.com/ripple/ripple-lib/commit/67d39737a4d5e0fcd9d9b47b9083ee00e5a9e652) and [67d3973](https://github.com/ripple/ripple-lib/commit/b6b99dde022e1e14c4797e454b1d7fca50e49482)
|
||||||
|
|
||||||
+ Remove blobvault client from ripple-lib, use the [`ripple-vault-client`](https://github.com/ripple/ripple-vault-client) instead [9b3d62b7](https://github.com/ripple/ripple-lib/commit/9b3d62b765c4c25beae6eb0fa57ef3a07f2581b1)
|
+ Remove blobvault client from ripple-lib, use the [`ripple-vault-client`](https://github.com/ripple/ripple-vault-client) instead [9b3d62b7](https://github.com/ripple/ripple-lib/commit/9b3d62b765c4c25beae6eb0fa57ef3a07f2581b1)
|
||||||
|
|
||||||
+ [Add support for `ledger` option in requestBookOffers](https://github.com/ripple/ripple-lib/commit/34c0677c453c409ef0a5b351959abdc176d3bacb)
|
+ [Add support for `ledger` option in requestBookOffers](https://github.com/ripple/ripple-lib/commit/34c0677c453c409ef0a5b351959abdc176d3bacb)
|
||||||
|
|
||||||
+ [Add support for `limit` option in requestBookOffers](https://github.com/ripple/ripple-lib/commit/d1d4452217c878d0b377d24830b4cd8b3162f6e0)
|
+ [Add support for `limit` option in requestBookOffers](https://github.com/ripple/ripple-lib/commit/d1d4452217c878d0b377d24830b4cd8b3162f6e0)
|
||||||
|
|
||||||
+ [Add `ledgerSelect` request constructor in `Remote`](https://github.com/ripple/ripple-lib/commit/98f40abfc3aa74dec5067a2d90002756cc8acd01)
|
+ [Add `ledgerSelect` request constructor in `Remote`](https://github.com/ripple/ripple-lib/commit/98f40abfc3aa74dec5067a2d90002756cc8acd01)
|
||||||
|
|
||||||
+ [Default to binary data for commands that accept the binary flag](https://github.com/ripple/ripple-lib/commit/7cb113fcbcfc1e3e9830a999148b3e78df3387cc)
|
+ [Default to binary data for commands that accept the binary flag](https://github.com/ripple/ripple-lib/commit/7cb113fcbcfc1e3e9830a999148b3e78df3387cc)
|
||||||
|
|
||||||
+ [Fix metadata account check](https://github.com/ripple/ripple-lib/commit/3f61598d6c87e3cc877af60e2d515f9eff73dfe1)
|
+ [Fix metadata account check](https://github.com/ripple/ripple-lib/commit/3f61598d6c87e3cc877af60e2d515f9eff73dfe1)
|
||||||
|
|
||||||
+ [Double check `tes` code before emitting `success`](https://github.com/ripple/ripple-lib/commit/97a8c874903eb7309d8f755955ac80872f670582)
|
+ [Double check `tes` code before emitting `success`](https://github.com/ripple/ripple-lib/commit/97a8c874903eb7309d8f755955ac80872f670582)
|
||||||
|
|
||||||
+ [Decrease redundancy in binary account_tx parsing](https://github.com/ripple/ripple-lib/commit/0aba638e6e7f4f6e22cb6424eed3897ebad90a5a)
|
+ [Decrease redundancy in binary account_tx parsing](https://github.com/ripple/ripple-lib/commit/0aba638e6e7f4f6e22cb6424eed3897ebad90a5a)
|
||||||
|
|
||||||
+ [Abort server connection on unrecoverable TLS error](https://github.com/ripple/ripple-lib/commit/000a2ea00c57157044aeca0fb3f24b37669b163c)
|
+ [Abort server connection on unrecoverable TLS error](https://github.com/ripple/ripple-lib/commit/000a2ea00c57157044aeca0fb3f24b37669b163c)
|
||||||
|
|
||||||
+ [Fix complete ledgers check on subscription that is not initial](https://github.com/ripple/ripple-lib/commit/89de91301e682a46dc60aaacc7ae152e8fe1b7c7)
|
+ [Fix complete ledgers check on subscription that is not initial](https://github.com/ripple/ripple-lib/commit/89de91301e682a46dc60aaacc7ae152e8fe1b7c7)
|
||||||
|
|
||||||
|
## 0.10.0
|
||||||
##0.10.0
|
|
||||||
|
|
||||||
+ [Transaction changes](https://github.com/ripple/ripple-lib/pull/221)
|
+ [Transaction changes](https://github.com/ripple/ripple-lib/pull/221)
|
||||||
|
|
||||||
+ **Important** `tef*` and `tel*` and errors will no longer be presented as
|
+ **Important** `tef*` and `tel*` and errors will no longer be presented as
|
||||||
final. Rather than considering these errors final, ripple-lib will wait until
|
final. Rather than considering these errors final, ripple-lib will wait until
|
||||||
the `LastLedgerSequence` specified in the transaction is exceeded. This makes
|
the `LastLedgerSequence` specified in the transaction is exceeded. This makes
|
||||||
failures more definitive, and ensures that no transaction will resubmit
|
failures more definitive, and ensures that no transaction will resubmit
|
||||||
indefinitely.
|
indefinitely.
|
||||||
|
|
||||||
+ A new, final tej-class error is introduced to account for transactions that
|
+ A new, final tej-class error is introduced to account for transactions that
|
||||||
are locally determined to have expired: `tejMaxLedger`.
|
are locally determined to have expired: `tejMaxLedger`.
|
||||||
|
|
||||||
+ [Allow per transaction fees to be set, `transaction.setFixedFee()`](https://github.com/ripple/ripple-lib/commit/9b22f279bcbe60ee6bcf4b7fa60a48e9c197a828)
|
+ [Allow per transaction fees to be set, `transaction.setFixedFee()`](https://github.com/ripple/ripple-lib/commit/9b22f279bcbe60ee6bcf4b7fa60a48e9c197a828)
|
||||||
|
|
||||||
+ [Improve memo support](https://github.com/ripple/ripple-lib/commit/1704ac4ae144c0ce54afad86f644c75a632080b1)
|
+ [Improve memo support](https://github.com/ripple/ripple-lib/commit/1704ac4ae144c0ce54afad86f644c75a632080b1)
|
||||||
- Add `MemoFormat` property for memo
|
- Add `MemoFormat` property for memo
|
||||||
- Enforce `MemoFormat` and `MemoType` to be valid ASCII
|
- Enforce `MemoFormat` and `MemoType` to be valid ASCII
|
||||||
- Support `text` and `json` MemoFormat
|
- Support `text` and `json` MemoFormat
|
||||||
|
+ [Update sjcl library](https://github.com/ripple/ripple-lib/commit/3204998fcb6f31d6c90532a737a4adb8a1e420f6)
|
||||||
+ [Update jscl library](https://github.com/ripple/ripple-lib/commit/3204998fcb6f31d6c90532a737a4adb8a1e420f6)
|
|
||||||
- Improved entropy by taking advantage of platform crypto
|
- Improved entropy by taking advantage of platform crypto
|
||||||
- Use jscl's k256 curve instead of altering the c256 curve with k256 configuration
|
- Use jscl's k256 curve instead of altering the c256 curve with k256 configuration
|
||||||
- **deprecated:** the c256 curve is linked to the k256 curve to provide backwards compatibility, this link will be removed in the future
|
- **Deprecated:** The c256 curve is linked to the k256 curve to provide backwards compatibility, this link will be removed in the future
|
||||||
|
|
||||||
+ [Fix empty queue check on reconnect](https://github.com/ripple/ripple-lib/commit/3c21994adcf72d1fbd87d453ceb917f9ad6df4ec)
|
+ [Fix empty queue check on reconnect](https://github.com/ripple/ripple-lib/commit/3c21994adcf72d1fbd87d453ceb917f9ad6df4ec)
|
||||||
|
|
||||||
##0.9.4
|
## 0.9.4
|
||||||
|
|
||||||
+ [Normalize offers from book_offers and transaction stream](https://github.com/ripple/ripple-lib/commit/86ed24b94cf7c8929c87db3a63e9bbea7f767e9c)
|
+ [Normalize offers from book_offers and transaction stream](https://github.com/ripple/ripple-lib/commit/86ed24b94cf7c8929c87db3a63e9bbea7f767e9c)
|
||||||
|
|
||||||
+ [Fix: Amount.to_human() precision rounding](https://github.com/ripple/ripple-lib/commit/e371cc2c3ceccb3c1cfdf18b98d80093147dd8b2)
|
+ [Fix: Amount.to_human() precision rounding](https://github.com/ripple/ripple-lib/commit/e371cc2c3ceccb3c1cfdf18b98d80093147dd8b2)
|
||||||
|
|
||||||
+ [Fix: fractional drops in funded taker_pays setter](https://github.com/ripple/ripple-lib/commit/0d7fc0a573a144caac15dd13798b23eeb1f95fb4)
|
+ [Fix: fractional drops in funded taker_pays setter](https://github.com/ripple/ripple-lib/commit/0d7fc0a573a144caac15dd13798b23eeb1f95fb4)
|
||||||
|
|
||||||
##0.9.3
|
## 0.9.3
|
||||||
|
|
||||||
+ [Change `presubmit` to emit immediately before transaction submit](https://github.com/ripple/ripple-lib/commit/7a1feaa89701bf861ab31ebd8ffdc8d8d1474e29)
|
+ [Change `presubmit` to emit immediately before transaction submit](https://github.com/ripple/ripple-lib/commit/7a1feaa89701bf861ab31ebd8ffdc8d8d1474e29)
|
||||||
|
|
||||||
+ [Add a "core" browser build of ripple-lib which has a subset of features and smaller file size](https://github.com/ripple/ripple-lib/pull/205)
|
+ [Add a "core" browser build of ripple-lib which has a subset of features and smaller file size](https://github.com/ripple/ripple-lib/pull/205)
|
||||||
|
|
||||||
+ [Update binformat with missing fields from rippled](https://github.com/ripple/ripple-lib/commit/cae980788efb00191bfd0988ed836d60cdf7a9a2)
|
+ [Update binformat with missing fields from rippled](https://github.com/ripple/ripple-lib/commit/cae980788efb00191bfd0988ed836d60cdf7a9a2)
|
||||||
|
|
||||||
+ [Wait for transaction validation before returning `tec` error](https://github.com/ripple/ripple-lib/commit/6bdd4b2670906588852fc4dda457607b4aac08e4)
|
+ [Wait for transaction validation before returning `tec` error](https://github.com/ripple/ripple-lib/commit/6bdd4b2670906588852fc4dda457607b4aac08e4)
|
||||||
|
|
||||||
+ [Change default `max_fee` on `Remote` to `1 XRP`](https://github.com/ripple/ripple-lib/commit/d6b1728c23ff85c3cc791bed6982a750641fd95f)
|
+ [Change default `max_fee` on `Remote` to `1 XRP`](https://github.com/ripple/ripple-lib/commit/d6b1728c23ff85c3cc791bed6982a750641fd95f)
|
||||||
|
|
||||||
+ [Fix: Request ledger_accept should return the Remote](https://github.com/ripple/ripple-lib/pull/209)
|
+ [Fix: Request ledger_accept should return the Remote](https://github.com/ripple/ripple-lib/pull/209)
|
||||||
|
|
||||||
##0.9.2
|
## 0.9.2
|
||||||
|
|
||||||
+ [**Breaking change**: Change accountRequest method signature](https://github.com/ripple/ripple-lib/commit/6f5d1104aa3eb440c518ec4f39e264fdce15fa15)
|
__BREAKING CHANGES__
|
||||||
|
+ [Change accountRequest method signature](https://github.com/ripple/ripple-lib/commit/6f5d1104aa3eb440c518ec4f39e264fdce15fa15)
|
||||||
|
|
||||||
|
__OTHER CHANGES__
|
||||||
+ [Add paging behavior for account requests, `account_lines` and `account_offers`](https://github.com/ripple/ripple-lib/commit/722f4e175dbbf378e51b49142d0285f87acb22d7)
|
+ [Add paging behavior for account requests, `account_lines` and `account_offers`](https://github.com/ripple/ripple-lib/commit/722f4e175dbbf378e51b49142d0285f87acb22d7)
|
||||||
|
+ [Add max_fee setter to transactions to set max fee the submitter is willing to pay](https://github.com/ripple/ripple-lib/commit/24587fab9c8ad3840d7aa345a7037b48839e09d7)
|
||||||
+ [Add max_fee setter to transactions to set max fee the submitter is willing to pay] (https://github.com/ripple/ripple-lib/commit/24587fab9c8ad3840d7aa345a7037b48839e09d7)
|
+ [Fix: cap IOU Amounts to their max and min value](https://github.com/ripple/ripple-lib/commit/f05941fbc46fdb7c6fe7ad72927af02d527ffeed)
|
||||||
|
|
||||||
+ [Fix: cap IOU Amounts to their max and min value] (https://github.com/ripple/ripple-lib/commit/f05941fbc46fdb7c6fe7ad72927af02d527ffeed)
|
|
||||||
|
|
||||||
Example on how to use paging with `account_offers`:
|
Example on how to use paging with `account_offers`:
|
||||||
```
|
```js
|
||||||
// A valid `ledger_index` or `ledger_hash` is required to provide a reliable result.
|
// A valid `ledger_index` or `ledger_hash` is required to provide a reliable result.
|
||||||
// Results can change between ledger closes, so the provided ledger will be used as base.
|
// Results can change between ledger closes, so the provided ledger will be used as base.
|
||||||
var options = {
|
var options = {
|
||||||
@@ -337,110 +318,70 @@ var request = remote.requestAccountOffers(options);
|
|||||||
|
|
||||||
[Full working example](https://github.com/geertweening/ripple-lib-scripts/blob/master/account_offers_paging.js)
|
[Full working example](https://github.com/geertweening/ripple-lib-scripts/blob/master/account_offers_paging.js)
|
||||||
|
|
||||||
|
## 0.9.1
|
||||||
##0.9.1
|
|
||||||
|
|
||||||
+ Switch account requests to use ledgerSelect rather than ledgerChoose ([278df90](https://github.com/ripple/ripple-lib/commit/278df9025a20228de22379a53c76ca12d40fa591))
|
+ Switch account requests to use ledgerSelect rather than ledgerChoose ([278df90](https://github.com/ripple/ripple-lib/commit/278df9025a20228de22379a53c76ca12d40fa591))
|
||||||
|
|
||||||
+ **Deprecated** setting `ident` and `account_index` on account requests ([278df90](https://github.com/ripple/ripple-lib/commit/278df9025a20228de22379a53c76ca12d40fa591))
|
+ **Deprecated** setting `ident` and `account_index` on account requests ([278df90](https://github.com/ripple/ripple-lib/commit/278df9025a20228de22379a53c76ca12d40fa591))
|
||||||
|
|
||||||
+ Change initial account transaction sequence to 1 ([a3c1d06](https://github.com/ripple/ripple-lib/commit/a3c1d06eba883dc84fe2bfe700e4309795c84cac))
|
+ Change initial account transaction sequence to 1 ([a3c1d06](https://github.com/ripple/ripple-lib/commit/a3c1d06eba883dc84fe2bfe700e4309795c84cac))
|
||||||
|
+ Fix: instance transaction without remote ([d3b6b81](https://github.com/ripple/ripple-lib/commit/d3b6b8127c7b01e416b400c25abf1719bdd008ca))
|
||||||
+ Fix: instance transaction withoute remote ([d3b6b81](https://github.com/ripple/ripple-lib/commit/d3b6b8127c7b01e416b400c25abf1719bdd008ca))
|
|
||||||
|
|
||||||
+ Fix: account root request ledger argument ([bc1f9f8](https://github.com/ripple/ripple-lib/commit/bc1f9f8a286b187d36ebaf552694e31e73742293))
|
+ Fix: account root request ledger argument ([bc1f9f8](https://github.com/ripple/ripple-lib/commit/bc1f9f8a286b187d36ebaf552694e31e73742293))
|
||||||
|
|
||||||
+ Fix: rsign.js local signing and example ([d3b6b81](https://github.com/ripple/ripple-lib/commit/d3b6b8127c7b01e416b400c25abf1719bdd008ca) and [f1004c6](https://github.com/ripple/ripple-lib/commit/f1004c6db2a0ce59bbabbb8f2b355a9fd9995fd8))
|
+ Fix: rsign.js local signing and example ([d3b6b81](https://github.com/ripple/ripple-lib/commit/d3b6b8127c7b01e416b400c25abf1719bdd008ca) and [f1004c6](https://github.com/ripple/ripple-lib/commit/f1004c6db2a0ce59bbabbb8f2b355a9fd9995fd8))
|
||||||
|
|
||||||
|
## 0.9.0
|
||||||
|
|
||||||
##0.9.0
|
__BREAKING CHANGES__
|
||||||
|
+ Make maxLoops in seed.get_key optional. [Example use in tests](https://github.com/ripple/ripple-lib/blob/23e473b6886c457781949c825b3ff48b3984e51f/test/seed-test.js) ([23e473b](https://github.com/ripple/ripple-lib/commit/23e473b6886c457781949c825b3ff48b3984e51f))
|
||||||
|
|
||||||
|
__OTHER CHANGES__
|
||||||
+ Add routes to the vault client for KYC attestations ([ed2da574](https://github.com/ripple/ripple-lib/commit/ed2da57475acf5e9d2cf3373858f4274832bd83f))
|
+ Add routes to the vault client for KYC attestations ([ed2da574](https://github.com/ripple/ripple-lib/commit/ed2da57475acf5e9d2cf3373858f4274832bd83f))
|
||||||
|
|
||||||
+ Currency: add `show_interest` flag to show or hide interest in `Currency.to_human()` and `Currency.to_json()` [Example use in tests](https://github.com/ripple/ripple-lib/blob/947ec3edc2e7c8f1ef097e496bf552c74366e749/test/currency-test.js#L123)
|
+ Currency: add `show_interest` flag to show or hide interest in `Currency.to_human()` and `Currency.to_json()` [Example use in tests](https://github.com/ripple/ripple-lib/blob/947ec3edc2e7c8f1ef097e496bf552c74366e749/test/currency-test.js#L123)
|
||||||
|
|
||||||
+ Configurable maxAttempts for transaction submission ([d107092](https://github.com/ripple/ripple-lib/commit/d10709254061e9e4416d2cb78b5cac1ec0d7ffa5))
|
+ Configurable maxAttempts for transaction submission ([d107092](https://github.com/ripple/ripple-lib/commit/d10709254061e9e4416d2cb78b5cac1ec0d7ffa5))
|
||||||
|
|
||||||
+ Binformat: added missing TransactionResult options ([6abed8d](https://github.com/ripple/ripple-lib/commit/6abed8dd5311765b2eb70505dadbdf5121439ca8))
|
+ Binformat: added missing TransactionResult options ([6abed8d](https://github.com/ripple/ripple-lib/commit/6abed8dd5311765b2eb70505dadbdf5121439ca8))
|
||||||
|
|
||||||
+ **Breaking change:** make maxLoops in seed.get_key optional. [Example use in tests](https://github.com/ripple/ripple-lib/blob/23e473b6886c457781949c825b3ff48b3984e51f/test/seed-test.js) ([23e473b](https://github.com/ripple/ripple-lib/commit/23e473b6886c457781949c825b3ff48b3984e51f))
|
|
||||||
|
|
||||||
+ Shrinkwrap packages for dependency locking ([2dcd5f9](2dcd5f94fbc71200eb08a5044c76ef94f7971913))
|
+ Shrinkwrap packages for dependency locking ([2dcd5f9](2dcd5f94fbc71200eb08a5044c76ef94f7971913))
|
||||||
|
|
||||||
+ Fix: Amount.to_human() precision bugs ([4be209e](https://github.com/ripple/ripple-lib/commit/4be209e286b5b209bec7bcd1212098985e15ff2f) and [7708c64](https://github.com/ripple/ripple-lib/commit/7708c64576e70ce3ac190442daceb30e4446aab7))
|
+ Fix: Amount.to_human() precision bugs ([4be209e](https://github.com/ripple/ripple-lib/commit/4be209e286b5b209bec7bcd1212098985e15ff2f) and [7708c64](https://github.com/ripple/ripple-lib/commit/7708c64576e70ce3ac190442daceb30e4446aab7))
|
||||||
|
|
||||||
+ Fix: change handling of requestLedger options ([57b7030](https://github.com/ripple/ripple-lib/commit/57b70300f5f0c7534ede118ddbb5d8762668a4f8))
|
+ Fix: change handling of requestLedger options ([57b7030](https://github.com/ripple/ripple-lib/commit/57b70300f5f0c7534ede118ddbb5d8762668a4f8))
|
||||||
|
|
||||||
|
## 0.8.2
|
||||||
##0.8.2
|
|
||||||
|
|
||||||
+ Currency: Allow mixed letters and numbers in currencies
|
+ Currency: Allow mixed letters and numbers in currencies
|
||||||
|
|
||||||
+ Deprecate account_tx map/reduce/filterg
|
+ Deprecate account_tx map/reduce/filterg
|
||||||
|
|
||||||
+ Fix: correct requestLedger arguments
|
+ Fix: correct requestLedger arguments
|
||||||
|
|
||||||
+ Fix: missing subscription on error events for some server methods
|
+ Fix: missing subscription on error events for some server methods
|
||||||
|
|
||||||
+ Fix: orderbook reset on reconnect
|
+ Fix: orderbook reset on reconnect
|
||||||
|
|
||||||
+ Fix: ripple-lib crashing. Add potential missing error handlers
|
+ Fix: ripple-lib crashing. Add potential missing error handlers
|
||||||
|
|
||||||
|
## 0.8.1
|
||||||
##0.8.1
|
|
||||||
|
|
||||||
+ Wallet: Add Wallet class that generates wallets
|
+ Wallet: Add Wallet class that generates wallets
|
||||||
|
|
||||||
+ Make npm test runnable in Windows.
|
+ Make npm test runnable in Windows.
|
||||||
|
|
||||||
+ Fix several stability issues, see merged PR's for details
|
+ Fix several stability issues, see merged PR's for details
|
||||||
|
|
||||||
+ Fix bug in Amount.to_human_full()
|
+ Fix bug in Amount.to_human_full()
|
||||||
|
|
||||||
+ Fix undefined fee states when connecting to a rippled that is syncing
|
+ Fix undefined fee states when connecting to a rippled that is syncing
|
||||||
|
|
||||||
|
## 0.8.0
|
||||||
##0.8.0
|
|
||||||
|
|
||||||
+ Orderbook: Added tracking of offer funds for determining when offers are not funded
|
+ Orderbook: Added tracking of offer funds for determining when offers are not funded
|
||||||
|
|
||||||
+ Orderbook: Added tests
|
+ Orderbook: Added tests
|
||||||
|
|
||||||
+ Orderbook: Update owner funds
|
+ Orderbook: Update owner funds
|
||||||
|
|
||||||
+ Transactions: If transaction errs with `tefALREADY`, wait until all possible submissions err with the same before emitting `error`. Fixes a client "Transaction malformed" bug.
|
+ Transactions: If transaction errs with `tefALREADY`, wait until all possible submissions err with the same before emitting `error`. Fixes a client "Transaction malformed" bug.
|
||||||
|
|
||||||
+ Transactions: Track submissions, don't bother submitting to unconnected servers
|
+ Transactions: Track submissions, don't bother submitting to unconnected servers
|
||||||
|
|
||||||
+ Request: `request.request()` now accepts an array of servers as first argument. Servers can be represented with URL, or the server object itself.
|
+ Request: `request.request()` now accepts an array of servers as first argument. Servers can be represented with URL, or the server object itself.
|
||||||
|
|
||||||
+ Request: `request.broadcast()` now returns the number of servers request was sent to
|
+ Request: `request.broadcast()` now returns the number of servers request was sent to
|
||||||
|
|
||||||
+ Server: Acquire host information from server without additional request
|
+ Server: Acquire host information from server without additional request
|
||||||
|
|
||||||
+ Amount: Add a constant for the maximum canonical value that can be expressed as a Ripple value
|
+ Amount: Add a constant for the maximum canonical value that can be expressed as a Ripple value
|
||||||
|
+ Amount: Make Constants static fields on the class, instead of a separate export
|
||||||
|
|
||||||
+ Amount: Make Constants static fields on the class, instead of a seperate export
|
## 0.7.39
|
||||||
|
|
||||||
|
|
||||||
##0.7.39
|
|
||||||
|
|
||||||
+ Improvements to multi-server support. Fixed an issue where a server's score was not reset and connections would keep dropping after being connected for a significant amount of time.
|
+ Improvements to multi-server support. Fixed an issue where a server's score was not reset and connections would keep dropping after being connected for a significant amount of time.
|
||||||
|
|
||||||
+ Improvements in order book support. Added support for currency pairs with interest bearing currencies. You can request an order book with hex, ISO code or full name for the currency.
|
+ Improvements in order book support. Added support for currency pairs with interest bearing currencies. You can request an order book with hex, ISO code or full name for the currency.
|
||||||
|
|
||||||
+ Fix value parsing for amount/currency order pairs, e.g. `Amount.from_human("XAU 12345.6789")`
|
+ Fix value parsing for amount/currency order pairs, e.g. `Amount.from_human("XAU 12345.6789")`
|
||||||
|
|
||||||
+ Improved Amount parsing from human readable string given a hex currency, e.g. `Amount.from_human("10 015841551A748AD2C1F76FF6ECB0CCCD00000000")`
|
+ Improved Amount parsing from human readable string given a hex currency, e.g. `Amount.from_human("10 015841551A748AD2C1F76FF6ECB0CCCD00000000")`
|
||||||
|
|
||||||
+ Improvements to username normalization in the vault client
|
+ Improvements to username normalization in the vault client
|
||||||
|
|
||||||
+ Add 2-factor authentication support for vault client
|
+ Add 2-factor authentication support for vault client
|
||||||
|
|
||||||
+ Removed vestiges of Grunt, switched to Gulp
|
+ Removed vestiges of Grunt, switched to Gulp
|
||||||
|
|
||||||
|
## 0.7.37
|
||||||
##0.7.37
|
|
||||||
|
|
||||||
+ **Deprecations**
|
+ **Deprecations**
|
||||||
|
|
||||||
@@ -451,11 +392,8 @@ var request = remote.requestAccountOffers(options);
|
|||||||
5. Removed `transaction.transactionManager` getter.
|
5. Removed `transaction.transactionManager` getter.
|
||||||
|
|
||||||
+ Improved multi-server support. Servers are now ranked dynamically, and transactions are broadcasted to all connected servers.
|
+ Improved multi-server support. Servers are now ranked dynamically, and transactions are broadcasted to all connected servers.
|
||||||
|
|
||||||
+ Automatically ping connected servers. Client configuration now should contain `ping: <seconds>` to specify the ping interval.
|
+ Automatically ping connected servers. Client configuration now should contain `ping: <seconds>` to specify the ping interval.
|
||||||
|
|
||||||
+ Added `transaction.lastLedger` to specify `LastLedgerSequence`. Setting it this way also ensures that the sequence is not bumped on subsequent requests.
|
+ Added `transaction.lastLedger` to specify `LastLedgerSequence`. Setting it this way also ensures that the sequence is not bumped on subsequent requests.
|
||||||
|
|
||||||
+ Added optional `remote.accountTx` binary parsing.
|
+ Added optional `remote.accountTx` binary parsing.
|
||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
@@ -464,28 +402,19 @@ var request = remote.requestAccountOffers(options);
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
+ Added full currency name support, e.g. `Currency.from_json('XRP').to_human({full_name:'Ripples'})` will return `XRP - Ripples`
|
+ Added full currency name support, e.g. `Currency.from_json('XRP').to_human({full_name:'Ripples'})` will return `XRP - Ripples`
|
||||||
|
|
||||||
+ Improved interest bearing currency support, e.g. `Currency.from_human('USD - US Dollar (2.5%pa)')`
|
+ Improved interest bearing currency support, e.g. `Currency.from_human('USD - US Dollar (2.5%pa)')`
|
||||||
|
|
||||||
+ Improve test coverage
|
+ Improve test coverage
|
||||||
|
|
||||||
+ Added blob vault client. The vault client facilitates interaction with ripple's namespace and blob vault or 3rd party blob vaults using ripple's blob vault software (https://github.com/ripple/ripple-blobvault). A list of the available functions can be found at [docs/VAULTCLIENT.md](docs/VAULTCLIENT.md)
|
+ Added blob vault client. The vault client facilitates interaction with ripple's namespace and blob vault or 3rd party blob vaults using ripple's blob vault software (https://github.com/ripple/ripple-blobvault). A list of the available functions can be found at [docs/VAULTCLIENT.md](docs/VAULTCLIENT.md)
|
||||||
|
|
||||||
|
|
||||||
##0.7.35
|
## 0.7.35
|
||||||
|
|
||||||
+ `LastLedgerSequence` is set by default on outgoing transactions. This refers to the last valid ledger index (AKA sequence) for a transaction. By default, this index is set to the current index (at submission time) plus 8. In theory, this allows ripple-lib to deterministically fail a transaction whose submission request timed out, but whose associated server continues to emit ledger_closed events.
|
+ `LastLedgerSequence` is set by default on outgoing transactions. This refers to the last valid ledger index (AKA sequence) for a transaction. By default, this index is set to the current index (at submission time) plus 8. In theory, this allows ripple-lib to deterministically fail a transaction whose submission request timed out, but whose associated server continues to emit ledger_closed events.
|
||||||
|
+ Transactions that err with `telINSUF_FEE_P` will be automatically resubmitted. This error indicates that the `Fee` supplied in the transaction submission request was inadequate. Ideally, the `Fee` is tracked by ripple-lib in real-time, and the resubmitted transaction will most likely succeed.
|
||||||
+ Transactions that err with `telINSUF_FEE_P` will be automatically resubmitted. This error indicates that the `Fee` supplied in the transaction submission request was inadquate. Ideally, the `Fee` is tracked by ripple-lib in real-time, and the resubmitted transaction will most likely succeed.
|
|
||||||
|
|
||||||
+ Added Transaction.iff(function(callback) { }). Callback expects first argument to be an Error or null, second argument is a boolean which indicates whether or not to proceed with the transaction submission. If an `iff` function is specified, it will be executed prior to every submission of the transaction (including resubmissions).
|
+ Added Transaction.iff(function(callback) { }). Callback expects first argument to be an Error or null, second argument is a boolean which indicates whether or not to proceed with the transaction submission. If an `iff` function is specified, it will be executed prior to every submission of the transaction (including resubmissions).
|
||||||
|
|
||||||
+ Transactions will now emit `presubmit` and `postsubmit` events. They will be emitted before and after a transaction is submitted, respectively.
|
+ Transactions will now emit `presubmit` and `postsubmit` events. They will be emitted before and after a transaction is submitted, respectively.
|
||||||
|
|
||||||
+ Added Transaction.summary(). Returns a summary of a transaction in semi-human-readable form. JSON-stringifiable.
|
+ Added Transaction.summary(). Returns a summary of a transaction in semi-human-readable form. JSON-stringifiable.
|
||||||
|
|
||||||
+ Remote.requestAccountTx() with `binary: true` will automatically parse transactions.
|
+ Remote.requestAccountTx() with `binary: true` will automatically parse transactions.
|
||||||
|
|
||||||
+ Added Remote.requestAccountTx filter, map, and reduce.
|
+ Added Remote.requestAccountTx filter, map, and reduce.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
@@ -513,6 +442,4 @@ var request = remote.requestAccountOffers(options);
|
|||||||
```
|
```
|
||||||
|
|
||||||
+ Added persistence hooks.
|
+ Added persistence hooks.
|
||||||
|
|
||||||
+ General performance improvements, especially for long-running processes.
|
+ General performance improvements, especially for long-running processes.
|
||||||
|
|
||||||
|
|||||||
2
LICENSE
2
LICENSE
@@ -1,3 +1,5 @@
|
|||||||
|
ISC License
|
||||||
|
|
||||||
Copyright (c) 2012-2015 Ripple Labs Inc.
|
Copyright (c) 2012-2015 Ripple Labs Inc.
|
||||||
|
|
||||||
Permission to use, copy, modify, and distribute this software for any
|
Permission to use, copy, modify, and distribute this software for any
|
||||||
|
|||||||
40
README.md
40
README.md
@@ -1,37 +1,45 @@
|
|||||||
#ripple-lib
|
# ripple-lib
|
||||||
|
|
||||||
A JavaScript API for interacting with Ripple in Node.js
|
A JavaScript API for interacting with the XRP Ledger
|
||||||
|
|
||||||
[](https://circleci.com/gh/ripple/ripple-lib/tree/develop) [](https://coveralls.io/r/ripple/ripple-lib?branch=develop)
|
[](https://circleci.com/gh/ripple/ripple-lib/tree/develop) [](https://coveralls.io/r/ripple/ripple-lib?branch=develop)
|
||||||
|
|
||||||
[](https://www.npmjs.org/package/ripple-lib)
|
[](https://www.npmjs.org/package/ripple-lib)
|
||||||
|
|
||||||
###Features
|
### Features
|
||||||
|
|
||||||
+ Connect to a rippled server in Node.js
|
+ Connect to a `rippled` server from Node.js or a web browser
|
||||||
+ Issue [rippled API](https://ripple.com/build/rippled-apis/) requests
|
+ Issue [rippled API](https://ripple.com/build/rippled-apis/) requests
|
||||||
+ Listen to events on the Ripple network (transaction, ledger, etc.)
|
+ Listen to events on the XRP Ledger (transaction, ledger, etc.)
|
||||||
+ Sign and submit transactions to the Ripple network
|
+ Sign and submit transactions to the XRP Ledger
|
||||||
|
|
||||||
##Getting Started
|
## Getting Started
|
||||||
|
|
||||||
Install `ripple-lib` using npm:
|
See also: [RippleAPI Beginners Guide](https://ripple.com/build/rippleapi-beginners-guide/)
|
||||||
|
|
||||||
|
You can use `npm`, but we recommend using `yarn` for the added assurance provided by `yarn.lock`.
|
||||||
|
|
||||||
|
+ [Yarn Installation Instructions](https://yarnpkg.com/en/docs/install)
|
||||||
|
|
||||||
|
Install `ripple-lib`:
|
||||||
```
|
```
|
||||||
$ npm install ripple-lib
|
$ yarn add ripple-lib
|
||||||
```
|
```
|
||||||
|
|
||||||
Then see the [documentation](https://github.com/ripple/ripple-lib/blob/develop/docs/index.md) and [code samples](https://github.com/ripple/ripple-lib/tree/develop/docs/samples)
|
Then see the [documentation](https://github.com/ripple/ripple-lib/blob/develop/docs/index.md) and [code samples](https://github.com/ripple/ripple-lib/tree/develop/docs/samples)
|
||||||
|
|
||||||
##Running tests
|
## Running tests
|
||||||
|
|
||||||
1. Clone the repository
|
1. Clone the repository
|
||||||
2. `cd` into the repository and install dependencies with `npm install`
|
2. `cd` into the repository and install dependencies with `yarn install`
|
||||||
3. `npm test` or `npm test --coverage` (`istanbul` will create coverage reports in coverage/lcov-report/`)
|
3. `yarn test` or `yarn test --coverage` (`istanbul` will create coverage reports in `coverage/lcov-report/`)
|
||||||
|
|
||||||
##Generating Documentation
|
## Generating Documentation
|
||||||
|
|
||||||
The continuous integration tests require that the documentation stays up-to-date. If you make changes the the JSON schemas, fixtures, or documentation sources, you must update the documentation by running `npm run docgen`.
|
The continuous integration tests require that the documentation stays up-to-date. If you make changes to the JSON schemas, fixtures, or documentation sources, you must update the documentation by running `yarn run docgen`.
|
||||||
|
|
||||||
##More Information
|
`npm` may be used instead of `yarn` in the commands above.
|
||||||
|
|
||||||
+ [Ripple Dev Portal](https://ripple.com/build/)
|
## More Information
|
||||||
|
|
||||||
|
+ [Ripple Developer Center](https://ripple.com/build/)
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
machine:
|
machine:
|
||||||
node:
|
node:
|
||||||
version: 0.12.0
|
version: 6.11.3
|
||||||
hosts:
|
hosts:
|
||||||
testripple.circleci.com: 127.0.0.1
|
testripple.circleci.com: 127.0.0.1
|
||||||
dependencies:
|
dependencies:
|
||||||
pre:
|
pre:
|
||||||
- npm -g install npm@latest-2
|
|
||||||
- wget https://s3-us-west-2.amazonaws.com/ripple-debs/rippled_0.30.1-b11-1.deb
|
- wget https://s3-us-west-2.amazonaws.com/ripple-debs/rippled_0.30.1-b11-1.deb
|
||||||
- sudo dpkg -i rippled_0.30.1-b11-1.deb
|
- sudo dpkg -i rippled_0.30.1-b11-1.deb
|
||||||
test:
|
test:
|
||||||
|
|||||||
9
custom_typings/node.d.ts
vendored
Normal file
9
custom_typings/node.d.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
/**
|
||||||
|
* This is an extension of Node's `process` object to include the browser
|
||||||
|
* property, which is added by webpack.
|
||||||
|
*/
|
||||||
|
interface AmbiguousProcess extends NodeJS.Process {
|
||||||
|
browser?: true
|
||||||
|
}
|
||||||
|
|
||||||
|
declare var process: AmbiguousProcess;
|
||||||
717
docs/index.md
717
docs/index.md
File diff suppressed because it is too large
Load Diff
@@ -1,20 +1,20 @@
|
|||||||
# Basic Types
|
# Basic Types
|
||||||
|
|
||||||
## Ripple Address
|
## Address
|
||||||
|
|
||||||
```json
|
```json
|
||||||
"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59"
|
"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59"
|
||||||
```
|
```
|
||||||
|
|
||||||
Every Ripple account has an *address*, which is a base58-encoding of a hash of the account's public key. Ripple addresses always start with the lowercase letter `r`.
|
Every XRP Ledger account has an *address*, which is a base58-encoding of a hash of the account's public key. XRP Ledger addresses always start with the lowercase letter `r`.
|
||||||
|
|
||||||
## Account Sequence Number
|
## Account Sequence Number
|
||||||
|
|
||||||
Every Ripple account has a *sequence number* that is used to keep transactions in order. Every transaction must have a sequence number. A transaction can only be executed if it has the next sequence number in order, of the account sending it. This prevents one transaction from executing twice and transactions executing out of order. The sequence number starts at `1` and increments for each transaction that the account makes.
|
Every XRP Ledger account has a *sequence number* that is used to keep transactions in order. Every transaction must have a sequence number. A transaction can only be executed if it has the next sequence number in order, of the account sending it. This prevents one transaction from executing twice and transactions executing out of order. The sequence number starts at `1` and increments for each transaction that the account makes.
|
||||||
|
|
||||||
## Currency
|
## Currency
|
||||||
|
|
||||||
Currencies are represented as either 3-character currency codes or 40-character uppercase hexadecimal strings. We recommend using uppercase [ISO 4217 Currency Codes](http://www.xe.com/iso4217.php) only. The string "XRP" is disallowed on trustlines because it is reserved for the Ripple native currency. The following characters are permitted: all uppercase and lowercase letters, digits, as well as the symbols `?`, `!`, `@`, `#`, `$`, `%`, `^`, `&`, `*`, `<`, `>`, `(`, `)`, `{`, `}`, `[`, `]`, and `|`.
|
Currencies are represented as either 3-character currency codes or 40-character uppercase hexadecimal strings. We recommend using uppercase [ISO 4217 Currency Codes](http://www.xe.com/iso4217.php) only. The string "XRP" is disallowed on trustlines because it is reserved for the XRP Ledger's native currency. The following characters are permitted: all uppercase and lowercase letters, digits, as well as the symbols `?`, `!`, `@`, `#`, `$`, `%`, `^`, `&`, `*`, `<`, `>`, `(`, `)`, `{`, `}`, `[`, `]`, and `|`.
|
||||||
|
|
||||||
## Value
|
## Value
|
||||||
A *value* is a quantity of a currency represented as a decimal string. Be careful: JavaScript's native number format does not have sufficient precision to represent all values. XRP has different precision from other currencies.
|
A *value* is a quantity of a currency represented as a decimal string. Be careful: JavaScript's native number format does not have sufficient precision to represent all values. XRP has different precision from other currencies.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
Use the following [boilerplate code](https://en.wikipedia.org/wiki/Boilerplate_code) to wrap your custom code using RippleAPI.
|
Use the following [boilerplate code](https://en.wikipedia.org/wiki/Boilerplate_code) to wrap your custom code using RippleAPI.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const {RippleAPI} = require('ripple-lib');
|
const RippleAPI = require('ripple-lib').RippleAPI;
|
||||||
|
|
||||||
const api = new RippleAPI({
|
const api = new RippleAPI({
|
||||||
server: 'wss://s1.ripple.com' // Public rippled server hosted by Ripple, Inc.
|
server: 'wss://s1.ripple.com' // Public rippled server hosted by Ripple, Inc.
|
||||||
@@ -26,9 +26,9 @@ api.connect().then(() => {
|
|||||||
}).catch(console.error);
|
}).catch(console.error);
|
||||||
```
|
```
|
||||||
|
|
||||||
RippleAPI is designed to work in [NodeJS](https://nodejs.org) (version `0.12.0` or greater) using [Babel](https://babeljs.io/) for [ECMAScript 6](https://babeljs.io/docs/learn-es2015/) support.
|
RippleAPI is designed to work in [Node.js](https://nodejs.org) version **6.11.3**. RippleAPI may work on older Node.js versions if you use [Babel](https://babeljs.io/) for [ECMAScript 6](https://babeljs.io/docs/learn-es2015/) support.
|
||||||
|
|
||||||
The code samples in this documentation are written in ES6, but `RippleAPI` will work with ES5 also. Regardless of whether you use ES5 or ES6, the methods that return promises will return [ES6-style promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
|
The code samples in this documentation are written with ECMAScript 6 (ES6) features, but `RippleAPI` also works with ECMAScript 5 (ES5). Regardless of whether you use ES5 or ES6, the methods that return Promises return [ES6-style promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
|
||||||
|
|
||||||
<aside class="notice">
|
<aside class="notice">
|
||||||
All the code snippets in this documentation assume that you have surrounded them with this boilerplate.
|
All the code snippets in this documentation assume that you have surrounded them with this boilerplate.
|
||||||
@@ -53,16 +53,10 @@ If you omit the `server` parameter, RippleAPI operates [offline](#offline-functi
|
|||||||
|
|
||||||
### Installation ###
|
### Installation ###
|
||||||
|
|
||||||
1. Install [NodeJS](https://nodejs.org) and the Node Package Manager (npm). Most Linux distros have a package for NodeJS, but make sure you have version `0.12.0` or higher.
|
1. Install [Node.js](https://nodejs.org) and [Yarn](https://yarnpkg.com/en/docs/install). Most Linux distros have a package for Node.js; check that it's the version you want.
|
||||||
2. Use npm to install [Babel](https://babeljs.io/) globally:
|
2. Use yarn to install RippleAPI:
|
||||||
`npm install -g babel-cli`
|
`yarn install ripple-lib`
|
||||||
3. Use npm to install RippleAPI:
|
|
||||||
`npm install ripple-lib`
|
|
||||||
|
|
||||||
After you have installed ripple-lib, you can create scripts using the [boilerplate](#boilerplate) and run them using babel-node:
|
After you have installed ripple-lib, you can create scripts using the [boilerplate](#boilerplate) and run them using the Node.js executable, typically named `node`:
|
||||||
`babel-node script.js`
|
|
||||||
|
|
||||||
<aside class="notice">
|
|
||||||
Instead of using babel-node in production, we recommend using Babel to transpile to ECMAScript 5 first.
|
|
||||||
</aside>
|
|
||||||
|
|
||||||
|
`node script.js`
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
`generateAddress(): {address: string, secret: string}`
|
`generateAddress(): {address: string, secret: string}`
|
||||||
|
|
||||||
Generate a new Ripple address and corresponding secret.
|
Generate a new XRP Ledger address and corresponding secret.
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
## getFee
|
## getFee
|
||||||
|
|
||||||
`getFee(): Promise<number>`
|
`getFee(): Promise<string>`
|
||||||
|
|
||||||
Returns the estimated transaction fee for the rippled server the RippleAPI instance is connected to.
|
Returns the estimated transaction fee for the rippled server the RippleAPI instance is connected to.
|
||||||
|
|
||||||
|
|||||||
26
docs/src/getPaymentChannel.md.ejs
Normal file
26
docs/src/getPaymentChannel.md.ejs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
## getPaymentChannel
|
||||||
|
|
||||||
|
`getPaymentChannel(id: string): Promise<Object>`
|
||||||
|
|
||||||
|
Returns specified payment channel.
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
<%- renderSchema('input/get-payment-channel.json') %>
|
||||||
|
|
||||||
|
### Return Value
|
||||||
|
|
||||||
|
This method returns a promise that resolves with an object with the following structure:
|
||||||
|
|
||||||
|
<%- renderSchema('output/get-payment-channel.json') %>
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const channelId =
|
||||||
|
'E30E709CF009A1F26E0E5C48F7AA1BFB79393764F15FB108BDC6E06D3CBD8415';
|
||||||
|
return api.getPaymentChannel(channelId).then(channel =>
|
||||||
|
{/* ... */});
|
||||||
|
```
|
||||||
|
|
||||||
|
<%- renderFixture('responses/get-payment-channel.json') %>
|
||||||
@@ -21,18 +21,24 @@
|
|||||||
<% include getOrderbook.md.ejs %>
|
<% include getOrderbook.md.ejs %>
|
||||||
<% include getSettings.md.ejs %>
|
<% include getSettings.md.ejs %>
|
||||||
<% include getAccountInfo.md.ejs %>
|
<% include getAccountInfo.md.ejs %>
|
||||||
|
<% include getPaymentChannel.md.ejs %>
|
||||||
<% include getLedger.md.ejs %>
|
<% include getLedger.md.ejs %>
|
||||||
<% include preparePayment.md.ejs %>
|
<% include preparePayment.md.ejs %>
|
||||||
<% include prepareTrustline.md.ejs %>
|
<% include prepareTrustline.md.ejs %>
|
||||||
<% include prepareOrder.md.ejs %>
|
<% include prepareOrder.md.ejs %>
|
||||||
<% include prepareOrderCancellation.md.ejs %>
|
<% include prepareOrderCancellation.md.ejs %>
|
||||||
<% include prepareSettings.md.ejs %>
|
<% include prepareSettings.md.ejs %>
|
||||||
<% include prepareSuspendedPaymentCreation.md.ejs %>
|
<% include prepareEscrowCreation.md.ejs %>
|
||||||
<% include prepareSuspendedPaymentCancellation.md.ejs %>
|
<% include prepareEscrowCancellation.md.ejs %>
|
||||||
<% include prepareSuspendedPaymentExecution.md.ejs %>
|
<% include prepareEscrowExecution.md.ejs %>
|
||||||
|
<% include preparePaymentChannelCreate.md.ejs %>
|
||||||
|
<% include preparePaymentChannelClaim.md.ejs %>
|
||||||
|
<% include preparePaymentChannelFund.md.ejs %>
|
||||||
<% include sign.md.ejs %>
|
<% include sign.md.ejs %>
|
||||||
<% include combine.md.ejs %>
|
<% include combine.md.ejs %>
|
||||||
<% include submit.md.ejs %>
|
<% include submit.md.ejs %>
|
||||||
<% include generateAddress.md.ejs %>
|
<% include generateAddress.md.ejs %>
|
||||||
|
<% include signPaymentChannelClaim.md.ejs %>
|
||||||
|
<% include verifyPaymentChannelClaim.md.ejs %>
|
||||||
<% include computeLedgerHash.md.ejs %>
|
<% include computeLedgerHash.md.ejs %>
|
||||||
<% include events.md.ejs %>
|
<% include events.md.ejs %>
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
# Introduction
|
# Introduction
|
||||||
|
|
||||||
RippleAPI is the official client library to the Ripple Consensus Ledger. Currently, RippleAPI is only available in JavaScript.
|
RippleAPI is the official client library to the XRP Ledger. Currently, RippleAPI is only available in JavaScript.
|
||||||
Using RippleAPI, you can:
|
Using RippleAPI, you can:
|
||||||
|
|
||||||
* [Query transactions from the network](#gettransaction)
|
* [Query transactions from the XRP Ledger history](#gettransaction)
|
||||||
* [Sign](#sign) transactions securely without connecting to any server
|
* [Sign](#sign) transactions securely without connecting to any server
|
||||||
* [Submit](#submit) transactions to the Ripple Consensus Ledger, including [Payments](#payment), [Orders](#order), [Settings changes](#settings), and [other types](#transaction-types)
|
* [Submit](#submit) transactions to the XRP Ledger, including [Payments](#payment), [Orders](#order), [Settings changes](#settings), and [other types](#transaction-types)
|
||||||
* [Generate a new Ripple Address](#generateaddress)
|
* [Generate a new XRP Ledger Address](#generateaddress)
|
||||||
* ... and [much more](#api-methods).
|
* ... and [much more](#api-methods).
|
||||||
|
|
||||||
RippleAPI only provides access to *validated*, *immutable* transaction data.
|
RippleAPI only provides access to *validated*, *immutable* transaction data.
|
||||||
|
|||||||
@@ -5,23 +5,22 @@ RippleAPI can also function without internet connectivity. This can be useful in
|
|||||||
To instantiate RippleAPI in offline mode, use the following boilerplate code:
|
To instantiate RippleAPI in offline mode, use the following boilerplate code:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const {RippleAPI} = require('ripple-lib');
|
const RippleAPI = require('ripple-lib').RippleAPI;
|
||||||
|
|
||||||
const api = new RippleAPI();
|
const api = new RippleAPI();
|
||||||
/* insert code here */
|
/* insert code here */
|
||||||
```
|
```
|
||||||
|
|
||||||
Methods that depend on the state of the Ripple Consensus Ledger are unavailable in offline mode. To prepare transactions offline, you **must** specify the `fee`, `sequence`, and `maxLedgerVersion` parameters in the [transaction instructions](#transaction-instructions). The following methods should work offline:
|
Methods that depend on the state of the XRP Ledger are unavailable in offline mode. To prepare transactions offline, you **must** specify the `fee`, `sequence`, and `maxLedgerVersion` parameters in the [transaction instructions](#transaction-instructions). You can use the following methods while offline:
|
||||||
|
|
||||||
* [preparePayment](#preparepayment)
|
* [preparePayment](#preparepayment)
|
||||||
* [prepareTrustline](#preparetrustline)
|
* [prepareTrustline](#preparetrustline)
|
||||||
* [prepareOrder](#prepareorder)
|
* [prepareOrder](#prepareorder)
|
||||||
* [prepareOrderCancellation](#prepareordercancellation)
|
* [prepareOrderCancellation](#prepareordercancellation)
|
||||||
* [prepareSettings](#preparesettings)
|
* [prepareSettings](#preparesettings)
|
||||||
* [prepareSuspendedPaymentCreation](#preparesuspendedpaymentcreation)
|
* [prepareEscrowCreation](#prepareescrowcreation)
|
||||||
* [prepareSuspendedPaymentCancellation](#preparesuspendedpaymentcancellation)
|
* [prepareEscrowCancellation](#prepareescrowcancellation)
|
||||||
* [prepareSuspendedPaymentExecution](#preparesuspendedpaymentexecution)
|
* [prepareEscrowExecution](#prepareescrowexecution)
|
||||||
* [sign](#sign)
|
* [sign](#sign)
|
||||||
* [generateAddress](#generateaddress)
|
* [generateAddress](#generateaddress)
|
||||||
* [computeLedgerHash](#computeledgerhash)
|
* [computeLedgerHash](#computeledgerhash)
|
||||||
|
|
||||||
|
|||||||
30
docs/src/prepareEscrowCancellation.md.ejs
Normal file
30
docs/src/prepareEscrowCancellation.md.ejs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
## prepareEscrowCancellation
|
||||||
|
|
||||||
|
`prepareEscrowCancellation(address: string, escrowCancellation: Object, instructions: Object): Promise<Object>`
|
||||||
|
|
||||||
|
Prepare an escrow cancellation transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit).
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
<%- renderSchema('input/prepare-escrow-cancellation.json') %>
|
||||||
|
|
||||||
|
### Return Value
|
||||||
|
|
||||||
|
This method returns a promise that resolves with an object with the following structure:
|
||||||
|
|
||||||
|
<aside class="notice">
|
||||||
|
All "prepare*" methods have the same return type.
|
||||||
|
</aside>
|
||||||
|
|
||||||
|
<%- renderSchema('output/prepare.json') %>
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59';
|
||||||
|
const escrowCancellation = <%- importFile('test/fixtures/requests/prepare-escrow-cancellation.json') %>;
|
||||||
|
return api.prepareEscrowCancellation(address, escrowCancellation).then(prepared =>
|
||||||
|
{/* ... */});
|
||||||
|
```
|
||||||
|
|
||||||
|
<%- renderFixture('responses/prepare-escrow-cancellation.json') %>
|
||||||
30
docs/src/prepareEscrowCreation.md.ejs
Normal file
30
docs/src/prepareEscrowCreation.md.ejs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
## prepareEscrowCreation
|
||||||
|
|
||||||
|
`prepareEscrowCreation(address: string, escrowCreation: Object, instructions: Object): Promise<Object>`
|
||||||
|
|
||||||
|
Prepare an escrow creation transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit).
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
<%- renderSchema('input/prepare-escrow-creation.json') %>
|
||||||
|
|
||||||
|
### Return Value
|
||||||
|
|
||||||
|
This method returns a promise that resolves with an object with the following structure:
|
||||||
|
|
||||||
|
<aside class="notice">
|
||||||
|
All "prepare*" methods have the same return type.
|
||||||
|
</aside>
|
||||||
|
|
||||||
|
<%- renderSchema('output/prepare.json') %>
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59';
|
||||||
|
const escrowCreation = <%- importFile('test/fixtures/requests/prepare-escrow-creation.json') %>;
|
||||||
|
return api.prepareEscrowCreation(address, escrowCreation).then(prepared =>
|
||||||
|
{/* ... */});
|
||||||
|
```
|
||||||
|
|
||||||
|
<%- renderFixture('responses/prepare-escrow-creation.json') %>
|
||||||
30
docs/src/prepareEscrowExecution.md.ejs
Normal file
30
docs/src/prepareEscrowExecution.md.ejs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
## prepareEscrowExecution
|
||||||
|
|
||||||
|
`prepareEscrowExecution(address: string, escrowExecution: Object, instructions: Object): Promise<Object>`
|
||||||
|
|
||||||
|
Prepare an escrow execution transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit).
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
<%- renderSchema('input/prepare-escrow-execution.json') %>
|
||||||
|
|
||||||
|
### Return Value
|
||||||
|
|
||||||
|
This method returns a promise that resolves with an object with the following structure:
|
||||||
|
|
||||||
|
<aside class="notice">
|
||||||
|
All "prepare*" methods have the same return type.
|
||||||
|
</aside>
|
||||||
|
|
||||||
|
<%- renderSchema('output/prepare.json') %>
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59';
|
||||||
|
const escrowExecution = <%- importFile('test/fixtures/requests/prepare-escrow-execution.json') %>;
|
||||||
|
return api.prepareEscrowExecution(address, escrowExecution).then(prepared =>
|
||||||
|
{/* ... */});
|
||||||
|
```
|
||||||
|
|
||||||
|
<%- renderFixture('responses/prepare-escrow-execution.json') %>
|
||||||
30
docs/src/preparePaymentChannelClaim.md.ejs
Normal file
30
docs/src/preparePaymentChannelClaim.md.ejs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
## preparePaymentChannelClaim
|
||||||
|
|
||||||
|
`preparePaymentChannelClaim(address: string, paymentChannelClaim: Object, instructions: Object): Promise<Object>`
|
||||||
|
|
||||||
|
Prepare a payment channel claim transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit).
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
<%- renderSchema('input/prepare-payment-channel-claim.json') %>
|
||||||
|
|
||||||
|
### Return Value
|
||||||
|
|
||||||
|
This method returns a promise that resolves with an object with the following structure:
|
||||||
|
|
||||||
|
<aside class="notice">
|
||||||
|
All "prepare*" methods have the same return type.
|
||||||
|
</aside>
|
||||||
|
|
||||||
|
<%- renderSchema('output/prepare.json') %>
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59';
|
||||||
|
const paymentChannelClaim = <%- importFile('test/fixtures/requests/prepare-payment-channel-claim.json') %>;
|
||||||
|
return api.preparePaymentChannelClaim(address, paymentChannelClaim).then(prepared =>
|
||||||
|
{/* ... */});
|
||||||
|
```
|
||||||
|
|
||||||
|
<%- renderFixture('responses/prepare-payment-channel-claim.json') %>
|
||||||
30
docs/src/preparePaymentChannelCreate.md.ejs
Normal file
30
docs/src/preparePaymentChannelCreate.md.ejs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
## preparePaymentChannelCreate
|
||||||
|
|
||||||
|
`preparePaymentChannelCreate(address: string, paymentChannelCreate: Object, instructions: Object): Promise<Object>`
|
||||||
|
|
||||||
|
Prepare a payment channel creation transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit).
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
<%- renderSchema('input/prepare-payment-channel-create.json') %>
|
||||||
|
|
||||||
|
### Return Value
|
||||||
|
|
||||||
|
This method returns a promise that resolves with an object with the following structure:
|
||||||
|
|
||||||
|
<aside class="notice">
|
||||||
|
All "prepare*" methods have the same return type.
|
||||||
|
</aside>
|
||||||
|
|
||||||
|
<%- renderSchema('output/prepare.json') %>
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59';
|
||||||
|
const paymentChannelCreate = <%- importFile('test/fixtures/requests/prepare-payment-channel-create.json') %>;
|
||||||
|
return api.preparePaymentChannelCreate(address, paymentChannelCreate).then(prepared =>
|
||||||
|
{/* ... */});
|
||||||
|
```
|
||||||
|
|
||||||
|
<%- renderFixture('responses/prepare-payment-channel-create.json') %>
|
||||||
30
docs/src/preparePaymentChannelFund.md.ejs
Normal file
30
docs/src/preparePaymentChannelFund.md.ejs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
## preparePaymentChannelFund
|
||||||
|
|
||||||
|
`preparePaymentChannelFund(address: string, paymentChannelFund: Object, instructions: Object): Promise<Object>`
|
||||||
|
|
||||||
|
Prepare a payment channel fund transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit).
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
<%- renderSchema('input/prepare-payment-channel-fund.json') %>
|
||||||
|
|
||||||
|
### Return Value
|
||||||
|
|
||||||
|
This method returns a promise that resolves with an object with the following structure:
|
||||||
|
|
||||||
|
<aside class="notice">
|
||||||
|
All "prepare*" methods have the same return type.
|
||||||
|
</aside>
|
||||||
|
|
||||||
|
<%- renderSchema('output/prepare.json') %>
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59';
|
||||||
|
const paymentChannelFund = <%- importFile('test/fixtures/requests/prepare-payment-channel-fund.json') %>;
|
||||||
|
return api.preparePaymentChannelFund(address, paymentChannelFund).then(prepared =>
|
||||||
|
{/* ... */});
|
||||||
|
```
|
||||||
|
|
||||||
|
<%- renderFixture('responses/prepare-payment-channel-fund.json') %>
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
## prepareSuspendedPaymentCancellation
|
|
||||||
|
|
||||||
`prepareSuspendedPaymentCancellation(address: string, suspendedPaymentCancellation: Object, instructions: Object): Promise<Object>`
|
|
||||||
|
|
||||||
Prepare a suspended payment cancellation transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit).
|
|
||||||
|
|
||||||
**Caution:** Suspended Payments are currently available on the [Ripple Test Net](https://ripple.com/build/ripple-test-net/) only.
|
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
<%- renderSchema('input/prepare-suspended-payment-cancellation.json') %>
|
|
||||||
|
|
||||||
### Return Value
|
|
||||||
|
|
||||||
This method returns a promise that resolves with an object with the following structure:
|
|
||||||
|
|
||||||
<aside class="notice">
|
|
||||||
All "prepare*" methods have the same return type.
|
|
||||||
</aside>
|
|
||||||
|
|
||||||
<%- renderSchema('output/prepare.json') %>
|
|
||||||
|
|
||||||
### Example
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59';
|
|
||||||
const suspendedPaymentCancellation = <%- importFile('test/fixtures/requests/prepare-suspended-payment-cancellation.json') %>;
|
|
||||||
return api.prepareSuspendedPaymentCancellation(address, suspendedPaymentCancellation).then(prepared =>
|
|
||||||
{/* ... */});
|
|
||||||
```
|
|
||||||
|
|
||||||
<%- renderFixture('responses/prepare-suspended-payment-cancellation.json') %>
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
## prepareSuspendedPaymentCreation
|
|
||||||
|
|
||||||
`prepareSuspendedPaymentCreation(address: string, suspendedPaymentCreation: Object, instructions: Object): Promise<Object>`
|
|
||||||
|
|
||||||
Prepare a suspended payment creation transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit).
|
|
||||||
|
|
||||||
**Caution:** Suspended Payments are currently available on the [Ripple Test Net](https://ripple.com/build/ripple-test-net/) only.
|
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
<%- renderSchema('input/prepare-suspended-payment-creation.json') %>
|
|
||||||
|
|
||||||
### Return Value
|
|
||||||
|
|
||||||
This method returns a promise that resolves with an object with the following structure:
|
|
||||||
|
|
||||||
<aside class="notice">
|
|
||||||
All "prepare*" methods have the same return type.
|
|
||||||
</aside>
|
|
||||||
|
|
||||||
<%- renderSchema('output/prepare.json') %>
|
|
||||||
|
|
||||||
### Example
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59';
|
|
||||||
const suspendedPaymentCreation = <%- importFile('test/fixtures/requests/prepare-suspended-payment-creation.json') %>;
|
|
||||||
return api.prepareSuspendedPaymentCreation(address, suspendedPaymentCreation).then(prepared =>
|
|
||||||
{/* ... */});
|
|
||||||
```
|
|
||||||
|
|
||||||
<%- renderFixture('responses/prepare-suspended-payment-creation.json') %>
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
## prepareSuspendedPaymentExecution
|
|
||||||
|
|
||||||
`prepareSuspendedPaymentExecution(address: string, suspendedPaymentExecution: Object, instructions: Object): Promise<Object>`
|
|
||||||
|
|
||||||
Prepare a suspended payment execution transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit).
|
|
||||||
|
|
||||||
**Caution:** Suspended Payments are currently available on the [Ripple Test Net](https://ripple.com/build/ripple-test-net/) only.
|
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
<%- renderSchema('input/prepare-suspended-payment-execution.json') %>
|
|
||||||
|
|
||||||
### Return Value
|
|
||||||
|
|
||||||
This method returns a promise that resolves with an object with the following structure:
|
|
||||||
|
|
||||||
<aside class="notice">
|
|
||||||
All "prepare*" methods have the same return type.
|
|
||||||
</aside>
|
|
||||||
|
|
||||||
<%- renderSchema('output/prepare.json') %>
|
|
||||||
|
|
||||||
### Example
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59';
|
|
||||||
const suspendedPaymentExecution = <%- importFile('test/fixtures/requests/prepare-suspended-payment-execution.json') %>;
|
|
||||||
return api.prepareSuspendedPaymentExecution(address, suspendedPaymentExecution).then(prepared =>
|
|
||||||
{/* ... */});
|
|
||||||
```
|
|
||||||
|
|
||||||
<%- renderFixture('responses/prepare-suspended-payment-execution.json') %>
|
|
||||||
28
docs/src/signPaymentChannelClaim.md.ejs
Normal file
28
docs/src/signPaymentChannelClaim.md.ejs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
## signPaymentChannelClaim
|
||||||
|
|
||||||
|
`signPaymentChannelClaim(channel: string, amount: string, privateKey: string): string`
|
||||||
|
|
||||||
|
Sign a payment channel claim. The signature can be submitted in a subsequent [PaymentChannelClaim](#preparepaymentchannelclaim) transaction.
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
<%- renderSchema("input/sign-payment-channel-claim.json") %>
|
||||||
|
|
||||||
|
### Return Value
|
||||||
|
|
||||||
|
This method returns a signature string:
|
||||||
|
|
||||||
|
<%- renderSchema("output/sign-payment-channel-claim.json") %>
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const channel =
|
||||||
|
'3E18C05AD40319B809520F1A136370C4075321B285217323396D6FD9EE1E9037';
|
||||||
|
const amount = '.00001';
|
||||||
|
const privateKey =
|
||||||
|
'ACCD3309DB14D1A4FC9B1DAE608031F4408C85C73EE05E035B7DC8B25840107A';
|
||||||
|
return api.signPaymentChannelClaim(channel, amount, privateKey);
|
||||||
|
```
|
||||||
|
|
||||||
|
<%- renderFixture("responses/sign-payment-channel-claim.json") %>
|
||||||
@@ -52,32 +52,62 @@ See [Transaction Types](#transaction-types) for a description.
|
|||||||
|
|
||||||
<%- renderFixture('requests/prepare-settings.json') %>
|
<%- renderFixture('requests/prepare-settings.json') %>
|
||||||
|
|
||||||
## Suspended Payment Creation
|
## Escrow Creation
|
||||||
|
|
||||||
See [Transaction Types](#transaction-types) for a description.
|
See [Transaction Types](#transaction-types) for a description.
|
||||||
|
|
||||||
<%- renderSchema('specifications/suspended-payment-creation.json') %>
|
<%- renderSchema('specifications/escrow-creation.json') %>
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
<%- renderFixture('requests/prepare-suspended-payment-creation.json') %>
|
<%- renderFixture('requests/prepare-escrow-creation.json') %>
|
||||||
|
|
||||||
## Suspended Payment Cancellation
|
## Escrow Cancellation
|
||||||
|
|
||||||
See [Transaction Types](#transaction-types) for a description.
|
See [Transaction Types](#transaction-types) for a description.
|
||||||
|
|
||||||
<%- renderSchema('specifications/suspended-payment-cancellation.json') %>
|
<%- renderSchema('specifications/escrow-cancellation.json') %>
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
<%- renderFixture('requests/prepare-suspended-payment-cancellation.json') %>
|
<%- renderFixture('requests/prepare-escrow-cancellation.json') %>
|
||||||
|
|
||||||
## Suspended Payment Execution
|
## Escrow Execution
|
||||||
|
|
||||||
See [Transaction Types](#transaction-types) for a description.
|
See [Transaction Types](#transaction-types) for a description.
|
||||||
|
|
||||||
<%- renderSchema('specifications/suspended-payment-execution.json') %>
|
<%- renderSchema('specifications/escrow-execution.json') %>
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
<%- renderFixture('requests/prepare-suspended-payment-execution.json') %>
|
<%- renderFixture('requests/prepare-escrow-execution.json') %>
|
||||||
|
|
||||||
|
## Payment Channel Create
|
||||||
|
|
||||||
|
See [Transaction Types](#transaction-types) for a description.
|
||||||
|
|
||||||
|
<%- renderSchema('specifications/payment-channel-create.json') %>
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
<%- renderFixture('requests/prepare-payment-channel-create.json') %>
|
||||||
|
|
||||||
|
## Payment Channel Fund
|
||||||
|
|
||||||
|
See [Transaction Types](#transaction-types) for a description.
|
||||||
|
|
||||||
|
<%- renderSchema('specifications/payment-channel-fund.json') %>
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
<%- renderFixture('requests/prepare-payment-channel-fund.json') %>
|
||||||
|
|
||||||
|
## Payment Channel Claim
|
||||||
|
|
||||||
|
See [Transaction Types](#transaction-types) for a description.
|
||||||
|
|
||||||
|
<%- renderSchema('specifications/payment-channel-claim.json') %>
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
<%- renderFixture('requests/prepare-payment-channel-claim.json') %>
|
||||||
|
|||||||
@@ -7,15 +7,13 @@ A transaction type is specified by the strings in the first column in the table
|
|||||||
Type | Description
|
Type | Description
|
||||||
---- | -----------
|
---- | -----------
|
||||||
[payment](#payment) | A `payment` transaction represents a transfer of value from one account to another. Depending on the [path](https://ripple.com/build/paths/) taken, additional exchanges of value may occur atomically to facilitate the payment.
|
[payment](#payment) | A `payment` transaction represents a transfer of value from one account to another. Depending on the [path](https://ripple.com/build/paths/) taken, additional exchanges of value may occur atomically to facilitate the payment.
|
||||||
[order](#order) | An `order` transaction creates a limit order. It defines an intent to exchange currencies, and creates an order in the Ripple Consensus Ledger's order book if not completely fulfilled when placed. Orders can be partially fulfilled.
|
[order](#order) | An `order` transaction creates a limit order. It defines an intent to exchange currencies, and creates an order in the XRP Ledger's order book if not completely fulfilled when placed. Orders can be partially fulfilled.
|
||||||
[orderCancellation](#order-cancellation) | An `orderCancellation` transaction cancels an order in the Ripple Consensus Ledger's order book.
|
[orderCancellation](#order-cancellation) | An `orderCancellation` transaction cancels an order in the XRP Ledger's order book.
|
||||||
[trustline](#trustline) | A `trustline` transactions creates or modifies a trust line between two accounts.
|
[trustline](#trustline) | A `trustline` transactions creates or modifies a trust line between two accounts.
|
||||||
[settings](#settings) | A `settings` transaction modifies the settings of an account in the Ripple Consensus Ledger.
|
[settings](#settings) | A `settings` transaction modifies the settings of an account in the XRP Ledger.
|
||||||
[suspendedPaymentCreation](#suspended-payment-creation) | A `suspendedPaymentCreation` transaction creates a suspended payment on the ledger, which locks XRP until a cryptographic condition is met or it expires. It is like an escrow service where the Ripple network acts as the escrow agent.
|
[escrowCreation](#escrow-creation) | An `escrowCreation` transaction creates an escrow on the ledger, which locks XRP until a cryptographic condition is met or it expires. It is like an escrow service where the XRP Ledger acts as the escrow agent.
|
||||||
[suspendedPaymentCancellation](#suspended-payment-cancellation) | A `suspendedPaymentCancellation` transaction unlocks the funds in a suspended payment and sends them back to the creator of the suspended payment, but it will only work after the suspended payment expires.
|
[escrowCancellation](#escrow-cancellation) | An `escrowCancellation` transaction unlocks the funds in an escrow and sends them back to the creator of the escrow, but it will only work after the escrow expires.
|
||||||
[suspendedPaymentExecution](#suspended-payment-execution) | A `suspendedPaymentExecution` transaction unlocks the funds in a suspended payment and sends them to the destination of the suspended payment, but it will only work if the cryptographic condition is provided.
|
[escrowExecution](#escrow-execution) | An `escrowExecution` transaction unlocks the funds in an escrow and sends them to the destination of the escrow, but it will only work if the cryptographic condition is provided.
|
||||||
|
|
||||||
The three "suspended payment" transaction types are not supported by the production Ripple peer-to-peer network at this time. They are available for testing purposes if you [configure RippleAPI](#boilerplate) to connect to the [Ripple Test Net](https://ripple.com/build/ripple-test-net/) instead.
|
|
||||||
|
|
||||||
## Transaction Flow
|
## Transaction Flow
|
||||||
|
|
||||||
@@ -27,16 +25,16 @@ Executing a transaction with `RippleAPI` requires the following four steps:
|
|||||||
* [prepareOrder](#prepareorder)
|
* [prepareOrder](#prepareorder)
|
||||||
* [prepareOrderCancellation](#prepareordercancellation)
|
* [prepareOrderCancellation](#prepareordercancellation)
|
||||||
* [prepareSettings](#preparesettings)
|
* [prepareSettings](#preparesettings)
|
||||||
* [prepareSuspendedPaymentCreation](#preparesuspendedpaymentcreation)
|
* [prepareEscrowCreation](#prepareescrowcreation)
|
||||||
* [prepareSuspendedPaymentCancellation](#preparesuspendedpaymentcancellation)
|
* [prepareEscrowCancellation](#prepareescrowcancellation)
|
||||||
* [prepareSuspendedPaymentExecution](#preparesuspendedpaymentexecution)
|
* [prepareEscrowExecution](#prepareescrowexecution)
|
||||||
2. [Sign](#sign) - Cryptographically sign the transaction locally and save the [transaction ID](#transaction-id). Signing is how the owner of an account authorizes a transaction to take place. For multisignature transactions, the `signedTransaction` fields returned by `sign` must be collected and passed to the [combine](#combine) method.
|
2. [Sign](#sign) - Cryptographically sign the transaction locally and save the [transaction ID](#transaction-id). Signing is how the owner of an account authorizes a transaction to take place. For multisignature transactions, the `signedTransaction` fields returned by `sign` must be collected and passed to the [combine](#combine) method.
|
||||||
3. [Submit](#submit) - Submit the transaction to the connected server.
|
3. [Submit](#submit) - Submit the transaction to the connected server.
|
||||||
4. Verify - Verify that the transaction got validated by querying with [getTransaction](#gettransaction). This is necessary because transactions may fail even if they were successfully submitted.
|
4. Verify - Verify that the transaction got validated by querying with [getTransaction](#gettransaction). This is necessary because transactions may fail even if they were successfully submitted.
|
||||||
|
|
||||||
## Transaction Fees
|
## Transaction Fees
|
||||||
|
|
||||||
Every transaction must destroy a small amount of XRP as a cost to send the transaction. This is also called a *transaction fee*. The transaction cost is designed to increase along with the load on the Ripple network, making it very expensive to deliberately or inadvertently overload the network.
|
Every transaction must destroy a small amount of XRP as a cost to send the transaction. This is also called a *transaction fee*. The transaction cost is designed to increase along with the load on the XRP Ledger, making it very expensive to deliberately or inadvertently overload the peer-to-peer network that powers the XRP Ledger.
|
||||||
|
|
||||||
You can choose the size of the fee you want to pay or let a default be used. You can get an estimate of the fee required to be included in the next ledger closing with the [getFee](#getfee) method.
|
You can choose the size of the fee you want to pay or let a default be used. You can get an estimate of the fee required to be included in the next ledger closing with the [getFee](#getfee) method.
|
||||||
|
|
||||||
@@ -46,7 +44,7 @@ Transaction instructions indicate how to execute a transaction, complementary wi
|
|||||||
|
|
||||||
<%- renderSchema("objects/instructions.json") %>
|
<%- renderSchema("objects/instructions.json") %>
|
||||||
|
|
||||||
We recommended that you specify a `maxLedgerVersion` so that you can quickly determine that a failed transaction will never succeeed in the future. It is impossible for a transaction to succeed after the network ledger version exceeds the transaction's `maxLedgerVersion`. If you omit `maxLedgerVersion`, the "prepare*" method automatically supplies a `maxLedgerVersion` equal to the current ledger plus 3, which it includes in the return value from the "prepare*" method.
|
We recommended that you specify a `maxLedgerVersion` so that you can quickly determine that a failed transaction will never succeeed in the future. It is impossible for a transaction to succeed after the XRP Ledger's consensus-validated ledger version exceeds the transaction's `maxLedgerVersion`. If you omit `maxLedgerVersion`, the "prepare*" method automatically supplies a `maxLedgerVersion` equal to the current ledger plus 3, which it includes in the return value from the "prepare*" method.
|
||||||
|
|
||||||
## Transaction ID
|
## Transaction ID
|
||||||
|
|
||||||
|
|||||||
31
docs/src/verifyPaymentChannelClaim.md.ejs
Normal file
31
docs/src/verifyPaymentChannelClaim.md.ejs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
## verifyPaymentChannelClaim
|
||||||
|
|
||||||
|
`verifyPaymentChannelClaim(channel: string, amount: string, signature: string, publicKey: string): boolean`
|
||||||
|
|
||||||
|
Verify a payment channel claim signature.
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
<%- renderSchema("input/verify-payment-channel-claim.json") %>
|
||||||
|
|
||||||
|
### Return Value
|
||||||
|
|
||||||
|
This method returns `true` if the claim signature is valid.
|
||||||
|
|
||||||
|
<%- renderSchema("output/verify-payment-channel-claim.json") %>
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const channel =
|
||||||
|
'3E18C05AD40319B809520F1A136370C4075321B285217323396D6FD9EE1E9037';
|
||||||
|
const amount = '.00001';
|
||||||
|
const signature = <%- importFile("test/fixtures/responses/sign-payment-channel-claim.json") %>;
|
||||||
|
const publicKey =
|
||||||
|
'02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8';
|
||||||
|
return api.verifyPaymentChannelClaim(channel, amount, signature, publicKey);
|
||||||
|
```
|
||||||
|
|
||||||
|
```json
|
||||||
|
true
|
||||||
|
```
|
||||||
4144
npm-shrinkwrap.json
generated
4144
npm-shrinkwrap.json
generated
File diff suppressed because it is too large
Load Diff
63
package.json
63
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ripple-lib",
|
"name": "ripple-lib",
|
||||||
"version": "0.17.4",
|
"version": "0.18.0",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"description": "A JavaScript API for interacting with Ripple in Node.js and the browser",
|
"description": "A JavaScript API for interacting with Ripple in Node.js and the browser",
|
||||||
"files": [
|
"files": [
|
||||||
@@ -15,65 +15,60 @@
|
|||||||
"test": "test"
|
"test": "test"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ajv": "^4.0.5",
|
"@types/lodash": "^4.14.85",
|
||||||
"ajv-i18n": "^1.2.0",
|
"@types/ws": "^3.2.0",
|
||||||
"babel-polyfill": "^6.3.14",
|
"bignumber.js": "^4.1.0",
|
||||||
"babel-runtime": "^6.3.19",
|
|
||||||
"bignumber.js": "^2.0.3",
|
|
||||||
"https-proxy-agent": "^1.0.0",
|
"https-proxy-agent": "^1.0.0",
|
||||||
"jayson": "^1.2.2",
|
"jsonschema": "^1.1.1",
|
||||||
"lodash": "^3.1.0",
|
"lodash": "^4.17.4",
|
||||||
"ripple-address-codec": "^2.0.1",
|
"ripple-address-codec": "^2.0.1",
|
||||||
"ripple-binary-codec": "^0.1.5",
|
"ripple-binary-codec": "^0.1.10",
|
||||||
"ripple-hashes": "^0.2.0",
|
"ripple-hashes": "^0.3.1",
|
||||||
"ripple-keypairs": "^0.10.0",
|
"ripple-keypairs": "^0.10.1",
|
||||||
"ripple-lib-transactionparser": "^0.6.0",
|
"ripple-lib-transactionparser": "^0.6.2",
|
||||||
"ws": "^1.0.1"
|
"ws": "^3.3.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/node": "^8.0.53",
|
||||||
"assert-diff": "^1.0.1",
|
"assert-diff": "^1.0.1",
|
||||||
"babel-cli": "^6.4.0",
|
"coveralls": "^2.13.1",
|
||||||
"babel-core": "^6.4.0",
|
|
||||||
"babel-eslint": "^6.0.4",
|
|
||||||
"babel-loader": "^6.2.1",
|
|
||||||
"babel-plugin-syntax-flow": "^6.3.13",
|
|
||||||
"babel-plugin-transform-flow-strip-types": "^6.4.0",
|
|
||||||
"babel-preset-es2015": "^6.3.13",
|
|
||||||
"babel-preset-stage-1": "^6.3.13",
|
|
||||||
"babel-register": "^6.3.13",
|
|
||||||
"coveralls": "^2.11.9",
|
|
||||||
"doctoc": "^0.15.0",
|
"doctoc": "^0.15.0",
|
||||||
"ejs": "^2.3.4",
|
"ejs": "^2.3.4",
|
||||||
"eslint": "^2.9.0",
|
|
||||||
"eventemitter2": "^0.4.14",
|
"eventemitter2": "^0.4.14",
|
||||||
"gulp": "^3.8.10",
|
"gulp": "^3.8.10",
|
||||||
"gulp-bump": "^0.1.13",
|
"gulp-bump": "^0.1.13",
|
||||||
"gulp-rename": "^1.2.0",
|
"gulp-rename": "^1.2.0",
|
||||||
"gulp-uglify": "^1.1.0",
|
|
||||||
"http-server": "^0.8.5",
|
"http-server": "^0.8.5",
|
||||||
"istanbul": "^1.1.0-alpha.1",
|
"jayson": "^1.2.2",
|
||||||
"json-loader": "^0.5.2",
|
"json-loader": "^0.5.2",
|
||||||
"json-schema-to-markdown-table": "^0.4.0",
|
"json-schema-to-markdown-table": "^0.4.0",
|
||||||
"mocha": "^2.1.0",
|
"mocha": "^2.1.0",
|
||||||
"mocha-in-sauce": "^0.0.1",
|
"mocha-in-sauce": "^0.0.1",
|
||||||
"mocha-junit-reporter": "^1.9.1",
|
"mocha-junit-reporter": "^1.9.1",
|
||||||
"null-loader": "^0.1.1",
|
"null-loader": "^0.1.1",
|
||||||
"webpack": "^1.5.3",
|
"ts-loader": "^3.2.0",
|
||||||
"yargs": "^1.3.1"
|
"nyc": "^11.3.0",
|
||||||
|
"source-map-support": "^0.5.0",
|
||||||
|
"ts-node": "^3.3.0",
|
||||||
|
"tslint": "^5.8.0",
|
||||||
|
"tslint-eslint-rules": "^4.1.1",
|
||||||
|
"typescript": "^2.6.1",
|
||||||
|
"uglifyjs-webpack-plugin": "^1.1.4",
|
||||||
|
"webpack": "^3.10.0",
|
||||||
|
"yargs": "^8.0.2"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "gulp",
|
"build": "gulp",
|
||||||
"doctoc": "doctoc docs/index.md --title '# RippleAPI Reference' --github --maxlevel 2",
|
"doctoc": "doctoc docs/index.md --title '# RippleAPI Reference' --github --maxlevel 2",
|
||||||
"docgen": "node --harmony scripts/build_docs.js",
|
"docgen": "node --harmony scripts/build_docs.js",
|
||||||
"clean": "rm -rf dist/npm && rm -rf build/flow",
|
"clean": "rm -rf dist/npm",
|
||||||
"typecheck": "babel --optional runtime --blacklist flow -d build/flow/ src/ && flow check",
|
"compile": "mkdir -p dist/npm/common && cp -r src/common/schemas dist/npm/common/ && tsc",
|
||||||
"compile": "babel -D --optional runtime -d dist/npm/ src/",
|
"watch": "tsc -w",
|
||||||
"watch": "babel -w -D --optional runtime -d dist/npm/ src/",
|
|
||||||
"compile-with-source-maps": "babel -D --optional runtime -s -t -d dist/npm/ src/",
|
"compile-with-source-maps": "babel -D --optional runtime -s -t -d dist/npm/ src/",
|
||||||
"prepublish": "npm run clean && npm run compile",
|
"prepublish": "npm run clean && npm run compile",
|
||||||
"test": "babel-node ./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha",
|
"test": "nyc mocha",
|
||||||
"coveralls": "cat ./coverage/lcov.info | coveralls",
|
"coveralls": "cat ./coverage/lcov.info | coveralls",
|
||||||
"lint": "if ! [ -f eslintrc ]; then curl -o eslintrc 'https://raw.githubusercontent.com/ripple/javascript-style-guide/es6/eslintrc'; echo 'parser: babel-eslint' >> eslintrc; fi; eslint -c eslintrc src/",
|
"lint": "tslint -p ./",
|
||||||
"perf": "./scripts/perf_test.sh",
|
"perf": "./scripts/perf_test.sh",
|
||||||
"start": "babel-node scripts/http.js",
|
"start": "babel-node scripts/http.js",
|
||||||
"sauce": "babel-node scripts/sauce-runner.js"
|
"sauce": "babel-node scripts/sauce-runner.js"
|
||||||
|
|||||||
@@ -7,29 +7,19 @@ function checkEOL {
|
|||||||
./scripts/checkeol.sh
|
./scripts/checkeol.sh
|
||||||
}
|
}
|
||||||
|
|
||||||
typecheck() {
|
|
||||||
npm install -g flow-bin
|
|
||||||
flow --version
|
|
||||||
npm run typecheck
|
|
||||||
}
|
|
||||||
|
|
||||||
lint() {
|
lint() {
|
||||||
echo "eslint $(node_modules/.bin/eslint --version)"
|
echo "tslint $(node_modules/.bin/tslint --version)"
|
||||||
npm list babel-eslint
|
yarn lint
|
||||||
REPO_URL="https://raw.githubusercontent.com/ripple/javascript-style-guide"
|
|
||||||
curl "$REPO_URL/es6/eslintrc" > ./eslintrc
|
|
||||||
echo "parser: babel-eslint" >> ./eslintrc
|
|
||||||
node_modules/.bin/eslint -c ./eslintrc $(git --no-pager diff --name-only -M100% --diff-filter=AM --relative $(git merge-base FETCH_HEAD origin/HEAD) FETCH_HEAD | grep "\.js$")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unittest() {
|
unittest() {
|
||||||
# test "src"
|
# test "src"
|
||||||
mocha test --reporter mocha-junit-reporter --reporter-options mochaFile=$CIRCLE_TEST_REPORTS/test-results.xml
|
mocha test --reporter mocha-junit-reporter --reporter-options mochaFile=$CIRCLE_TEST_REPORTS/test-results.xml
|
||||||
npm test --coverage
|
yarn test --coverage
|
||||||
npm run coveralls
|
yarn run coveralls
|
||||||
|
|
||||||
# test compiled version in "dist/npm"
|
# test compiled version in "dist/npm"
|
||||||
babel -D --optional runtime --ignore "**/node_modules/**" -d test-compiled/ test/
|
$(npm bin)/babel -D --optional runtime --ignore "**/node_modules/**" -d test-compiled/ test/
|
||||||
echo "--reporter spec --timeout 5000 --slow 500" > test-compiled/mocha.opts
|
echo "--reporter spec --timeout 5000 --slow 500" > test-compiled/mocha.opts
|
||||||
mkdir -p test-compiled/node_modules
|
mkdir -p test-compiled/node_modules
|
||||||
ln -nfs ../../dist/npm test-compiled/node_modules/ripple-api
|
ln -nfs ../../dist/npm test-compiled/node_modules/ripple-api
|
||||||
@@ -46,7 +36,7 @@ unittest() {
|
|||||||
|
|
||||||
#echo "Running tests in SauceLabs"
|
#echo "Running tests in SauceLabs"
|
||||||
#http-server &
|
#http-server &
|
||||||
#npm run sauce
|
#yarn run sauce
|
||||||
|
|
||||||
#pkill -f mocked-server.js
|
#pkill -f mocked-server.js
|
||||||
#pkill -f http-server
|
#pkill -f http-server
|
||||||
@@ -65,7 +55,7 @@ integrationtest() {
|
|||||||
|
|
||||||
doctest() {
|
doctest() {
|
||||||
mv docs/index.md docs/index.md.save
|
mv docs/index.md docs/index.md.save
|
||||||
npm run docgen
|
yarn run docgen
|
||||||
mv docs/index.md docs/index.md.test
|
mv docs/index.md docs/index.md.test
|
||||||
mv docs/index.md.save docs/index.md
|
mv docs/index.md.save docs/index.md
|
||||||
cmp docs/index.md docs/index.md.test
|
cmp docs/index.md docs/index.md.test
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const createHTTPServer = require('../src/index').createHTTPServer;
|
const createHTTPServer = require('../src/http').createHTTPServer;
|
||||||
const port = 5990;
|
const port = 5990;
|
||||||
const serverUrl = 'wss://s1.ripple.com';
|
const serverUrl = 'wss://s1.ripple.com';
|
||||||
|
|
||||||
|
|||||||
@@ -7,12 +7,12 @@ function exit_on_error {
|
|||||||
|
|
||||||
rm -rf build
|
rm -rf build
|
||||||
|
|
||||||
npm install
|
yarn install
|
||||||
gulp
|
gulp
|
||||||
npm test
|
yarn test
|
||||||
exit_on_error
|
exit_on_error
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "publish to npm"
|
echo "publish to npm"
|
||||||
npm publish
|
yarn publish
|
||||||
exit_on_error
|
exit_on_error
|
||||||
|
|||||||
@@ -7,12 +7,12 @@ function exit_on_error {
|
|||||||
|
|
||||||
rm -rf build
|
rm -rf build
|
||||||
|
|
||||||
npm install
|
yarn install
|
||||||
gulp
|
gulp
|
||||||
npm test
|
yarn test
|
||||||
exit_on_error
|
exit_on_error
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "publish rc to npm"
|
echo "publish rc to npm"
|
||||||
npm publish --tag beta
|
yarn publish --tag beta
|
||||||
exit_on_error
|
exit_on_error
|
||||||
|
|||||||
153
src/api.js
153
src/api.js
@@ -1,153 +0,0 @@
|
|||||||
/* @flow */
|
|
||||||
'use strict'; // eslint-disable-line
|
|
||||||
|
|
||||||
/* eslint-disable max-len */
|
|
||||||
// Enable core-js polyfills. This allows use of ES6/7 extensions listed here:
|
|
||||||
// https://github.com/zloirock/core-js/blob/fb0890f32dabe8d4d88a4350d1b268446127132e/shim.js#L1-L103
|
|
||||||
/* eslint-enable max-len */
|
|
||||||
|
|
||||||
// In node.js env, polyfill might be already loaded (from any npm package),
|
|
||||||
// that's why we do this check.
|
|
||||||
if (!global._babelPolyfill) {
|
|
||||||
require('babel-polyfill');
|
|
||||||
}
|
|
||||||
|
|
||||||
const _ = require('lodash');
|
|
||||||
const EventEmitter = require('events').EventEmitter;
|
|
||||||
const common = require('./common');
|
|
||||||
const server = require('./server/server');
|
|
||||||
const connect = server.connect;
|
|
||||||
const disconnect = server.disconnect;
|
|
||||||
const getServerInfo = server.getServerInfo;
|
|
||||||
const getFee = server.getFee;
|
|
||||||
const isConnected = server.isConnected;
|
|
||||||
const getLedgerVersion = server.getLedgerVersion;
|
|
||||||
const getTransaction = require('./ledger/transaction');
|
|
||||||
const getTransactions = require('./ledger/transactions');
|
|
||||||
const getTrustlines = require('./ledger/trustlines');
|
|
||||||
const getBalances = require('./ledger/balances');
|
|
||||||
const getBalanceSheet = require('./ledger/balance-sheet');
|
|
||||||
const getPaths = require('./ledger/pathfind');
|
|
||||||
const getOrders = require('./ledger/orders');
|
|
||||||
const getOrderbook = require('./ledger/orderbook');
|
|
||||||
const getSettings = require('./ledger/settings');
|
|
||||||
const getAccountInfo = require('./ledger/accountinfo');
|
|
||||||
const preparePayment = require('./transaction/payment');
|
|
||||||
const prepareTrustline = require('./transaction/trustline');
|
|
||||||
const prepareOrder = require('./transaction/order');
|
|
||||||
const prepareOrderCancellation = require('./transaction/ordercancellation');
|
|
||||||
const prepareSuspendedPaymentCreation =
|
|
||||||
require('./transaction/suspended-payment-creation');
|
|
||||||
const prepareSuspendedPaymentExecution =
|
|
||||||
require('./transaction/suspended-payment-execution');
|
|
||||||
const prepareSuspendedPaymentCancellation =
|
|
||||||
require('./transaction/suspended-payment-cancellation');
|
|
||||||
const prepareSettings = require('./transaction/settings');
|
|
||||||
const sign = require('./transaction/sign');
|
|
||||||
const combine = require('./transaction/combine');
|
|
||||||
const submit = require('./transaction/submit');
|
|
||||||
const errors = require('./common').errors;
|
|
||||||
const generateAddress =
|
|
||||||
require('./offline/generate-address').generateAddressAPI;
|
|
||||||
const computeLedgerHash = require('./offline/ledgerhash');
|
|
||||||
const getLedger = require('./ledger/ledger');
|
|
||||||
|
|
||||||
type APIOptions = {
|
|
||||||
server?: string,
|
|
||||||
feeCushion?: number,
|
|
||||||
trace?: boolean,
|
|
||||||
proxy?: string,
|
|
||||||
timeout?: number
|
|
||||||
}
|
|
||||||
|
|
||||||
// prevent access to non-validated ledger versions
|
|
||||||
class RestrictedConnection extends common.Connection {
|
|
||||||
request(request, timeout) {
|
|
||||||
const ledger_index = request.ledger_index;
|
|
||||||
if (ledger_index !== undefined && ledger_index !== 'validated') {
|
|
||||||
if (!_.isNumber(ledger_index) || ledger_index > this._ledgerVersion) {
|
|
||||||
return Promise.reject(new errors.LedgerVersionError(
|
|
||||||
`ledgerVersion ${ledger_index} is greater than server\'s ` +
|
|
||||||
`most recent validated ledger: ${this._ledgerVersion}`));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return super.request(request, timeout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class RippleAPI extends EventEmitter {
|
|
||||||
constructor(options: APIOptions = {}) {
|
|
||||||
common.validate.apiOptions(options);
|
|
||||||
super();
|
|
||||||
this._feeCushion = options.feeCushion || 1.2;
|
|
||||||
const serverURL = options.server;
|
|
||||||
if (serverURL !== undefined) {
|
|
||||||
this.connection = new RestrictedConnection(serverURL, options);
|
|
||||||
this.connection.on('ledgerClosed', message => {
|
|
||||||
this.emit('ledger', server.formatLedgerClose(message));
|
|
||||||
});
|
|
||||||
this.connection.on('error', (errorCode, errorMessage, data) => {
|
|
||||||
this.emit('error', errorCode, errorMessage, data);
|
|
||||||
});
|
|
||||||
this.connection.on('connected', () => {
|
|
||||||
this.emit('connected');
|
|
||||||
});
|
|
||||||
this.connection.on('disconnected', code => {
|
|
||||||
this.emit('disconnected', code);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// use null object pattern to provide better error message if user
|
|
||||||
// tries to call a method that requires a connection
|
|
||||||
this.connection = new RestrictedConnection(null, options);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_.assign(RippleAPI.prototype, {
|
|
||||||
connect,
|
|
||||||
disconnect,
|
|
||||||
isConnected,
|
|
||||||
getServerInfo,
|
|
||||||
getFee,
|
|
||||||
getLedgerVersion,
|
|
||||||
|
|
||||||
getTransaction,
|
|
||||||
getTransactions,
|
|
||||||
getTrustlines,
|
|
||||||
getBalances,
|
|
||||||
getBalanceSheet,
|
|
||||||
getPaths,
|
|
||||||
getOrders,
|
|
||||||
getOrderbook,
|
|
||||||
getSettings,
|
|
||||||
getAccountInfo,
|
|
||||||
getLedger,
|
|
||||||
|
|
||||||
preparePayment,
|
|
||||||
prepareTrustline,
|
|
||||||
prepareOrder,
|
|
||||||
prepareOrderCancellation,
|
|
||||||
prepareSuspendedPaymentCreation,
|
|
||||||
prepareSuspendedPaymentExecution,
|
|
||||||
prepareSuspendedPaymentCancellation,
|
|
||||||
prepareSettings,
|
|
||||||
sign,
|
|
||||||
combine,
|
|
||||||
submit,
|
|
||||||
|
|
||||||
generateAddress,
|
|
||||||
computeLedgerHash,
|
|
||||||
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
|
|
||||||
};
|
|
||||||
153
src/api.ts
Normal file
153
src/api.ts
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
import * as _ from 'lodash'
|
||||||
|
import {EventEmitter} from 'events'
|
||||||
|
import {Connection, errors, validate} from './common'
|
||||||
|
import * as server from './server/server'
|
||||||
|
const connect = server.connect
|
||||||
|
const disconnect = server.disconnect
|
||||||
|
const getServerInfo = server.getServerInfo
|
||||||
|
const getFee = server.getFee
|
||||||
|
const isConnected = server.isConnected
|
||||||
|
const getLedgerVersion = server.getLedgerVersion
|
||||||
|
import getTransaction from './ledger/transaction'
|
||||||
|
import getTransactions from './ledger/transactions'
|
||||||
|
import getTrustlines from './ledger/trustlines'
|
||||||
|
import getBalances from './ledger/balances'
|
||||||
|
import getBalanceSheet from './ledger/balance-sheet'
|
||||||
|
import getPaths from './ledger/pathfind'
|
||||||
|
import getOrders from './ledger/orders'
|
||||||
|
import getOrderbook from './ledger/orderbook'
|
||||||
|
import getSettings from './ledger/settings'
|
||||||
|
import getAccountInfo from './ledger/accountinfo'
|
||||||
|
import getPaymentChannel from './ledger/payment-channel'
|
||||||
|
import preparePayment from './transaction/payment'
|
||||||
|
import prepareTrustline from './transaction/trustline'
|
||||||
|
import prepareOrder from './transaction/order'
|
||||||
|
import prepareOrderCancellation from './transaction/ordercancellation'
|
||||||
|
import prepareEscrowCreation from './transaction/escrow-creation'
|
||||||
|
import prepareEscrowExecution from './transaction/escrow-execution'
|
||||||
|
import prepareEscrowCancellation from './transaction/escrow-cancellation'
|
||||||
|
import preparePaymentChannelCreate from './transaction/payment-channel-create'
|
||||||
|
import preparePaymentChannelFund from './transaction/payment-channel-fund'
|
||||||
|
import preparePaymentChannelClaim from './transaction/payment-channel-claim'
|
||||||
|
import prepareSettings from './transaction/settings'
|
||||||
|
import sign from './transaction/sign'
|
||||||
|
import combine from './transaction/combine'
|
||||||
|
import submit from './transaction/submit'
|
||||||
|
import {generateAddressAPI} from './offline/generate-address'
|
||||||
|
import computeLedgerHash from './offline/ledgerhash'
|
||||||
|
import signPaymentChannelClaim from './offline/sign-payment-channel-claim'
|
||||||
|
import verifyPaymentChannelClaim from './offline/verify-payment-channel-claim'
|
||||||
|
import getLedger from './ledger/ledger'
|
||||||
|
|
||||||
|
|
||||||
|
import RangeSet from './common/rangeset'
|
||||||
|
import * as ledgerUtils from './ledger/utils'
|
||||||
|
import * as schemaValidator from './common/schema-validator'
|
||||||
|
|
||||||
|
type APIOptions = {
|
||||||
|
server?: string,
|
||||||
|
feeCushion?: number,
|
||||||
|
trace?: boolean,
|
||||||
|
proxy?: string,
|
||||||
|
timeout?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
// prevent access to non-validated ledger versions
|
||||||
|
class RestrictedConnection extends Connection {
|
||||||
|
request(request: any, timeout?: number) {
|
||||||
|
const ledger_index = request.ledger_index
|
||||||
|
if (ledger_index !== undefined && ledger_index !== 'validated') {
|
||||||
|
if (!_.isNumber(ledger_index) || ledger_index > this._ledgerVersion) {
|
||||||
|
return Promise.reject(new errors.LedgerVersionError(
|
||||||
|
`ledgerVersion ${ledger_index} is greater than server\'s ` +
|
||||||
|
`most recent validated ledger: ${this._ledgerVersion}`))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return super.request(request, timeout)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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: validate,
|
||||||
|
RangeSet,
|
||||||
|
ledgerUtils,
|
||||||
|
schemaValidator
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(options: APIOptions = {}) {
|
||||||
|
super()
|
||||||
|
validate.apiOptions(options)
|
||||||
|
this._feeCushion = options.feeCushion || 1.2
|
||||||
|
const serverURL = options.server
|
||||||
|
if (serverURL !== undefined) {
|
||||||
|
this.connection = new RestrictedConnection(serverURL, options)
|
||||||
|
this.connection.on('ledgerClosed', message => {
|
||||||
|
this.emit('ledger', server.formatLedgerClose(message))
|
||||||
|
})
|
||||||
|
this.connection.on('error', (errorCode, errorMessage, data) => {
|
||||||
|
this.emit('error', errorCode, errorMessage, data)
|
||||||
|
})
|
||||||
|
this.connection.on('connected', () => {
|
||||||
|
this.emit('connected')
|
||||||
|
})
|
||||||
|
this.connection.on('disconnected', code => {
|
||||||
|
this.emit('disconnected', code)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
// use null object pattern to provide better error message if user
|
||||||
|
// tries to call a method that requires a connection
|
||||||
|
this.connection = new RestrictedConnection(null, options)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
connect = connect
|
||||||
|
disconnect = disconnect
|
||||||
|
isConnected = isConnected
|
||||||
|
getServerInfo = getServerInfo
|
||||||
|
getFee = getFee
|
||||||
|
getLedgerVersion = getLedgerVersion
|
||||||
|
|
||||||
|
getTransaction = getTransaction
|
||||||
|
getTransactions = getTransactions
|
||||||
|
getTrustlines = getTrustlines
|
||||||
|
getBalances = getBalances
|
||||||
|
getBalanceSheet = getBalanceSheet
|
||||||
|
getPaths = getPaths
|
||||||
|
getOrders = getOrders
|
||||||
|
getOrderbook = getOrderbook
|
||||||
|
getSettings = getSettings
|
||||||
|
getAccountInfo = getAccountInfo
|
||||||
|
getPaymentChannel = getPaymentChannel
|
||||||
|
getLedger = getLedger
|
||||||
|
|
||||||
|
preparePayment = preparePayment
|
||||||
|
prepareTrustline = prepareTrustline
|
||||||
|
prepareOrder = prepareOrder
|
||||||
|
prepareOrderCancellation = prepareOrderCancellation
|
||||||
|
prepareEscrowCreation = prepareEscrowCreation
|
||||||
|
prepareEscrowExecution = prepareEscrowExecution
|
||||||
|
prepareEscrowCancellation = prepareEscrowCancellation
|
||||||
|
preparePaymentChannelCreate = preparePaymentChannelCreate
|
||||||
|
preparePaymentChannelFund = preparePaymentChannelFund
|
||||||
|
preparePaymentChannelClaim = preparePaymentChannelClaim
|
||||||
|
prepareSettings = prepareSettings
|
||||||
|
sign = sign
|
||||||
|
combine = combine
|
||||||
|
submit = submit
|
||||||
|
|
||||||
|
generateAddress = generateAddressAPI
|
||||||
|
computeLedgerHash = computeLedgerHash
|
||||||
|
signPaymentChannelClaim = signPaymentChannelClaim
|
||||||
|
verifyPaymentChannelClaim = verifyPaymentChannelClaim
|
||||||
|
errors = errors
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
RippleAPI
|
||||||
|
}
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
const _ = require('lodash');
|
|
||||||
const RippleAPI = require('./api').RippleAPI;
|
|
||||||
|
|
||||||
class RippleAPIBroadcast extends RippleAPI {
|
|
||||||
constructor(servers, options) {
|
|
||||||
super(options);
|
|
||||||
this.ledgerVersion = 0;
|
|
||||||
|
|
||||||
const apis = servers.map(server => new RippleAPI(
|
|
||||||
_.assign({}, options, {server})
|
|
||||||
));
|
|
||||||
|
|
||||||
// exposed for testing
|
|
||||||
this._apis = apis;
|
|
||||||
|
|
||||||
this.getMethodNames().forEach(name => {
|
|
||||||
this[name] = function() { // eslint-disable-line no-loop-func
|
|
||||||
return Promise.race(apis.map(api => api[name].apply(api, arguments)));
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
// connection methods must be overridden to apply to all api instances
|
|
||||||
this.connect = function() {
|
|
||||||
return Promise.all(apis.map(api => api.connect()));
|
|
||||||
};
|
|
||||||
this.disconnect = function() {
|
|
||||||
return Promise.all(apis.map(api => api.disconnect()));
|
|
||||||
};
|
|
||||||
this.isConnected = function() {
|
|
||||||
return _.every(apis.map(api => api.isConnected()));
|
|
||||||
};
|
|
||||||
|
|
||||||
// synchronous methods are all passed directly to the first api instance
|
|
||||||
const defaultAPI = apis[0];
|
|
||||||
const syncMethods = ['sign', 'generateAddress', 'computeLedgerHash'];
|
|
||||||
syncMethods.forEach(name => {
|
|
||||||
this[name] = defaultAPI[name].bind(defaultAPI);
|
|
||||||
});
|
|
||||||
|
|
||||||
apis.forEach(api => {
|
|
||||||
api.on('ledger', this.onLedgerEvent.bind(this));
|
|
||||||
api.on('error', (errorCode, errorMessage, data) =>
|
|
||||||
this.emit('error', errorCode, errorMessage, data));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
onLedgerEvent(ledger) {
|
|
||||||
if (ledger.ledgerVersion > this.ledgerVersion) {
|
|
||||||
this.ledgerVersion = ledger.ledgerVersion;
|
|
||||||
this.emit('ledger', ledger);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getMethodNames() {
|
|
||||||
const methodNames = [];
|
|
||||||
for (const name in RippleAPI.prototype) {
|
|
||||||
if (RippleAPI.prototype.hasOwnProperty(name)) {
|
|
||||||
if (typeof RippleAPI.prototype[name] === 'function') {
|
|
||||||
methodNames.push(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return methodNames;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
RippleAPIBroadcast
|
|
||||||
};
|
|
||||||
73
src/broadcast.ts
Normal file
73
src/broadcast.ts
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
|
||||||
|
import * as _ from 'lodash'
|
||||||
|
import {RippleAPI} from './api'
|
||||||
|
|
||||||
|
class RippleAPIBroadcast extends RippleAPI {
|
||||||
|
|
||||||
|
// TODO: Should this default to 0, or null/undefined?
|
||||||
|
ledgerVersion: number = 0
|
||||||
|
private _apis: RippleAPI[]
|
||||||
|
|
||||||
|
constructor(servers, options) {
|
||||||
|
super(options)
|
||||||
|
|
||||||
|
const apis: RippleAPI[] = servers.map(server => new RippleAPI(
|
||||||
|
_.assign({}, options, {server})
|
||||||
|
))
|
||||||
|
|
||||||
|
// exposed for testing
|
||||||
|
this._apis = apis
|
||||||
|
|
||||||
|
this.getMethodNames().forEach(name => {
|
||||||
|
this[name] = function() { // eslint-disable-line no-loop-func
|
||||||
|
return Promise.race(apis.map(api => api[name](...arguments)))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// connection methods must be overridden to apply to all api instances
|
||||||
|
this.connect = async function() {
|
||||||
|
await Promise.all(apis.map(api => api.connect()))
|
||||||
|
}
|
||||||
|
this.disconnect = async function() {
|
||||||
|
await Promise.all(apis.map(api => api.disconnect()))
|
||||||
|
}
|
||||||
|
this.isConnected = function() {
|
||||||
|
return apis.map(api => api.isConnected()).every(Boolean)
|
||||||
|
}
|
||||||
|
|
||||||
|
// synchronous methods are all passed directly to the first api instance
|
||||||
|
const defaultAPI = apis[0]
|
||||||
|
const syncMethods = ['sign', 'generateAddress', 'computeLedgerHash']
|
||||||
|
syncMethods.forEach(name => {
|
||||||
|
this[name] = defaultAPI[name].bind(defaultAPI)
|
||||||
|
})
|
||||||
|
|
||||||
|
apis.forEach(api => {
|
||||||
|
api.on('ledger', this.onLedgerEvent.bind(this))
|
||||||
|
api.on('error', (errorCode, errorMessage, data) =>
|
||||||
|
this.emit('error', errorCode, errorMessage, data))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
onLedgerEvent(ledger) {
|
||||||
|
if (ledger.ledgerVersion > this.ledgerVersion) {
|
||||||
|
this.ledgerVersion = ledger.ledgerVersion
|
||||||
|
this.emit('ledger', ledger)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getMethodNames() {
|
||||||
|
const methodNames: string[] = []
|
||||||
|
const rippleAPI = this._apis[0]
|
||||||
|
for (const name of Object.getOwnPropertyNames(rippleAPI)) {
|
||||||
|
if (typeof rippleAPI[name] === 'function') {
|
||||||
|
methodNames.push(name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return methodNames
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
RippleAPIBroadcast
|
||||||
|
}
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
function setPrototypeOf(object, prototype) {
|
|
||||||
// Object.setPrototypeOf not supported on Internet Explorer 9
|
|
||||||
/* eslint-disable */
|
|
||||||
Object.setPrototypeOf ? Object.setPrototypeOf(object, prototype) :
|
|
||||||
object.__proto__ = prototype;
|
|
||||||
/* eslint-enable */
|
|
||||||
}
|
|
||||||
|
|
||||||
function getConstructorName(object) {
|
|
||||||
// hack for internet explorer
|
|
||||||
return process.browser ?
|
|
||||||
object.constructor.toString().match(/^function\s+([^(]*)/)[1] :
|
|
||||||
object.constructor.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
getConstructorName,
|
|
||||||
setPrototypeOf
|
|
||||||
};
|
|
||||||
20
src/common/browser-hacks.ts
Normal file
20
src/common/browser-hacks.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
|
||||||
|
function setPrototypeOf(object, prototype) {
|
||||||
|
// Object.setPrototypeOf not supported on Internet Explorer 9
|
||||||
|
Object.setPrototypeOf ? Object.setPrototypeOf(object, prototype) :
|
||||||
|
// @ts-ignore: Specifically a fallback for IE9
|
||||||
|
object.__proto__ = prototype
|
||||||
|
}
|
||||||
|
|
||||||
|
function getConstructorName(object: Object): string {
|
||||||
|
// hack for internet explorer
|
||||||
|
if (!object.constructor.name) {
|
||||||
|
return object.constructor.toString().match(/^function\s+([^(]*)/)![1]
|
||||||
|
}
|
||||||
|
return object.constructor.name
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
getConstructorName,
|
||||||
|
setPrototypeOf
|
||||||
|
}
|
||||||
@@ -1,432 +0,0 @@
|
|||||||
'use strict'; // eslint-disable-line
|
|
||||||
|
|
||||||
const _ = require('lodash');
|
|
||||||
const {EventEmitter} = require('events');
|
|
||||||
const WebSocket = require('ws');
|
|
||||||
const parseURL = require('url').parse;
|
|
||||||
const RangeSet = require('./rangeset').RangeSet;
|
|
||||||
const {RippledError, DisconnectedError, NotConnectedError,
|
|
||||||
TimeoutError, ResponseFormatError, ConnectionError,
|
|
||||||
RippledNotInitializedError} = require('./errors');
|
|
||||||
|
|
||||||
function isStreamMessageType(type) {
|
|
||||||
return type === 'ledgerClosed' ||
|
|
||||||
type === 'transaction' ||
|
|
||||||
type === 'path_find';
|
|
||||||
}
|
|
||||||
|
|
||||||
class Connection extends EventEmitter {
|
|
||||||
constructor(url, options = {}) {
|
|
||||||
super();
|
|
||||||
this.setMaxListeners(Infinity);
|
|
||||||
this._url = url;
|
|
||||||
this._trace = options.trace;
|
|
||||||
if (this._trace) {
|
|
||||||
// for easier unit testing
|
|
||||||
this._console = console;
|
|
||||||
}
|
|
||||||
this._proxyURL = options.proxy;
|
|
||||||
this._proxyAuthorization = options.proxyAuthorization;
|
|
||||||
this._authorization = options.authorization;
|
|
||||||
this._trustedCertificates = options.trustedCertificates;
|
|
||||||
this._key = options.key;
|
|
||||||
this._passphrase = options.passphrase;
|
|
||||||
this._certificate = options.certificate;
|
|
||||||
this._timeout = options.timeout || (20 * 1000);
|
|
||||||
this._isReady = false;
|
|
||||||
this._ws = null;
|
|
||||||
this._ledgerVersion = null;
|
|
||||||
this._availableLedgerVersions = new RangeSet();
|
|
||||||
this._nextRequestID = 1;
|
|
||||||
this._retry = 0;
|
|
||||||
this._retryTimer = null;
|
|
||||||
this._onOpenErrorBound = null;
|
|
||||||
this._onUnexpectedCloseBound = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
_updateLedgerVersions(data) {
|
|
||||||
this._ledgerVersion = Number(data.ledger_index);
|
|
||||||
if (data.validated_ledgers) {
|
|
||||||
this._availableLedgerVersions.reset();
|
|
||||||
this._availableLedgerVersions.parseAndAddRanges(
|
|
||||||
data.validated_ledgers);
|
|
||||||
} else {
|
|
||||||
this._availableLedgerVersions.addValue(this._ledgerVersion);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// return value is array of arguments to Connection.emit
|
|
||||||
_parseMessage(message) {
|
|
||||||
const data = JSON.parse(message);
|
|
||||||
if (data.type === 'response') {
|
|
||||||
if (!(Number.isInteger(data.id) && data.id >= 0)) {
|
|
||||||
throw new ResponseFormatError('valid id not found in response');
|
|
||||||
}
|
|
||||||
return [data.id.toString(), data];
|
|
||||||
} else if (isStreamMessageType(data.type)) {
|
|
||||||
if (data.type === 'ledgerClosed') {
|
|
||||||
this._updateLedgerVersions(data);
|
|
||||||
}
|
|
||||||
return [data.type, data];
|
|
||||||
} else if (data.type === undefined && data.error) {
|
|
||||||
return ['error', data.error, data.error_message, data]; // e.g. slowDown
|
|
||||||
}
|
|
||||||
throw new ResponseFormatError('unrecognized message type: ' + data.type);
|
|
||||||
}
|
|
||||||
|
|
||||||
_onMessage(message) {
|
|
||||||
let parameters;
|
|
||||||
if (this._trace) {
|
|
||||||
this._console.log(message);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
parameters = this._parseMessage(message);
|
|
||||||
} catch (error) {
|
|
||||||
this.emit('error', 'badMessage', error.message, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// we don't want this inside the try/catch or exceptions in listener
|
|
||||||
// will be caught
|
|
||||||
this.emit(...parameters);
|
|
||||||
}
|
|
||||||
|
|
||||||
get _state() {
|
|
||||||
return this._ws ? this._ws.readyState : WebSocket.CLOSED;
|
|
||||||
}
|
|
||||||
|
|
||||||
get _shouldBeConnected() {
|
|
||||||
return this._ws !== null;
|
|
||||||
}
|
|
||||||
|
|
||||||
isConnected() {
|
|
||||||
return this._state === WebSocket.OPEN && this._isReady;
|
|
||||||
}
|
|
||||||
|
|
||||||
_onUnexpectedClose(beforeOpen, resolve, reject, code) {
|
|
||||||
if (this._onOpenErrorBound) {
|
|
||||||
this._ws.removeListener('error', this._onOpenErrorBound);
|
|
||||||
this._onOpenErrorBound = null;
|
|
||||||
}
|
|
||||||
// just in case
|
|
||||||
this._ws.removeAllListeners('open');
|
|
||||||
this._ws = null;
|
|
||||||
this._isReady = false;
|
|
||||||
if (beforeOpen) {
|
|
||||||
// connection was closed before it was properly opened, so we must return
|
|
||||||
// error to connect's caller
|
|
||||||
this.connect().then(resolve, reject);
|
|
||||||
} else {
|
|
||||||
// if first parameter ws lib sends close code,
|
|
||||||
// but sometimes it forgots about it, so default to 1006 - CLOSE_ABNORMAL
|
|
||||||
this.emit('disconnected', code || 1006);
|
|
||||||
this._retryConnect();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_calculateTimeout(retriesCount) {
|
|
||||||
return (retriesCount < 40)
|
|
||||||
// First, for 2 seconds: 20 times per second
|
|
||||||
? (1000 / 20)
|
|
||||||
: (retriesCount < 40 + 60)
|
|
||||||
// Then, for 1 minute: once per second
|
|
||||||
? (1000)
|
|
||||||
: (retriesCount < 40 + 60 + 60)
|
|
||||||
// Then, for 10 minutes: once every 10 seconds
|
|
||||||
? (10 * 1000)
|
|
||||||
// Then: once every 30 seconds
|
|
||||||
: (30 * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
_retryConnect() {
|
|
||||||
this._retry += 1;
|
|
||||||
const retryTimeout = this._calculateTimeout(this._retry);
|
|
||||||
this._retryTimer = setTimeout(() => {
|
|
||||||
this.emit('reconnecting', this._retry);
|
|
||||||
this.connect().catch(this._retryConnect.bind(this));
|
|
||||||
}, retryTimeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
_clearReconnectTimer() {
|
|
||||||
clearTimeout(this._retryTimer);
|
|
||||||
this._retryTimer = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
_onOpen() {
|
|
||||||
if (!this._ws) {
|
|
||||||
return Promise.reject(new DisconnectedError());
|
|
||||||
}
|
|
||||||
if (this._onOpenErrorBound) {
|
|
||||||
this._ws.removeListener('error', this._onOpenErrorBound);
|
|
||||||
this._onOpenErrorBound = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const request = {
|
|
||||||
command: 'subscribe',
|
|
||||||
streams: ['ledger']
|
|
||||||
};
|
|
||||||
return this.request(request).then(data => {
|
|
||||||
if (_.isEmpty(data) || !data.ledger_index) {
|
|
||||||
// rippled instance doesn't have validated ledgers
|
|
||||||
return this._disconnect(false).then(() => {
|
|
||||||
throw new RippledNotInitializedError('Rippled not initialized');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
this._updateLedgerVersions(data);
|
|
||||||
this._rebindOnUnxpectedClose();
|
|
||||||
|
|
||||||
this._retry = 0;
|
|
||||||
this._ws.on('error', error => {
|
|
||||||
if (process.browser && error && error.type === 'error') {
|
|
||||||
// we are in browser, ignore error - `close` event will be fired
|
|
||||||
// after error
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.emit('error', 'websocket', error.message, error);
|
|
||||||
});
|
|
||||||
|
|
||||||
this._isReady = true;
|
|
||||||
this.emit('connected');
|
|
||||||
|
|
||||||
return undefined;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
_rebindOnUnxpectedClose() {
|
|
||||||
if (this._onUnexpectedCloseBound) {
|
|
||||||
this._ws.removeListener('close', this._onUnexpectedCloseBound);
|
|
||||||
}
|
|
||||||
this._onUnexpectedCloseBound =
|
|
||||||
this._onUnexpectedClose.bind(this, false, null, null);
|
|
||||||
this._ws.once('close', this._onUnexpectedCloseBound);
|
|
||||||
}
|
|
||||||
|
|
||||||
_unbindOnUnxpectedClose() {
|
|
||||||
if (this._onUnexpectedCloseBound) {
|
|
||||||
this._ws.removeListener('close', this._onUnexpectedCloseBound);
|
|
||||||
}
|
|
||||||
this._onUnexpectedCloseBound = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
_onOpenError(reject, error) {
|
|
||||||
this._onOpenErrorBound = null;
|
|
||||||
this._unbindOnUnxpectedClose();
|
|
||||||
reject(new NotConnectedError(error && error.message));
|
|
||||||
}
|
|
||||||
|
|
||||||
_createWebSocket() {
|
|
||||||
const options = {};
|
|
||||||
if (this._proxyURL !== undefined) {
|
|
||||||
const parsedURL = parseURL(this._url);
|
|
||||||
const parsedProxyURL = parseURL(this._proxyURL);
|
|
||||||
const proxyOverrides = _.omit({
|
|
||||||
secureEndpoint: (parsedURL.protocol === 'wss:'),
|
|
||||||
secureProxy: (parsedProxyURL.protocol === 'https:'),
|
|
||||||
auth: this._proxyAuthorization,
|
|
||||||
ca: this._trustedCertificates,
|
|
||||||
key: this._key,
|
|
||||||
passphrase: this._passphrase,
|
|
||||||
cert: this._certificate
|
|
||||||
}, _.isUndefined);
|
|
||||||
const proxyOptions = _.assign({}, parsedProxyURL, proxyOverrides);
|
|
||||||
let HttpsProxyAgent;
|
|
||||||
try {
|
|
||||||
HttpsProxyAgent = require('https-proxy-agent');
|
|
||||||
} catch (error) {
|
|
||||||
throw new Error('"proxy" option is not supported in the browser');
|
|
||||||
}
|
|
||||||
options.agent = new HttpsProxyAgent(proxyOptions);
|
|
||||||
}
|
|
||||||
if (this._authorization !== undefined) {
|
|
||||||
const base64 = new Buffer(this._authorization).toString('base64');
|
|
||||||
options.headers = {Authorization: `Basic ${base64}`};
|
|
||||||
}
|
|
||||||
const optionsOverrides = _.omit({
|
|
||||||
ca: this._trustedCertificates,
|
|
||||||
key: this._key,
|
|
||||||
passphrase: this._passphrase,
|
|
||||||
cert: this._certificate
|
|
||||||
}, _.isUndefined);
|
|
||||||
const websocketOptions = _.assign({}, options, optionsOverrides);
|
|
||||||
const websocket = new WebSocket(this._url, null, websocketOptions);
|
|
||||||
// we will have a listener for each outstanding request,
|
|
||||||
// so we have to raise the limit (the default is 10)
|
|
||||||
if (typeof websocket.setMaxListeners === 'function') {
|
|
||||||
websocket.setMaxListeners(Infinity);
|
|
||||||
}
|
|
||||||
return websocket;
|
|
||||||
}
|
|
||||||
|
|
||||||
connect() {
|
|
||||||
this._clearReconnectTimer();
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
if (!this._url) {
|
|
||||||
reject(new ConnectionError(
|
|
||||||
'Cannot connect because no server was specified'));
|
|
||||||
}
|
|
||||||
if (this._state === WebSocket.OPEN) {
|
|
||||||
resolve();
|
|
||||||
} else if (this._state === WebSocket.CONNECTING) {
|
|
||||||
this._ws.once('open', resolve);
|
|
||||||
} else {
|
|
||||||
this._ws = this._createWebSocket();
|
|
||||||
// when an error causes the connection to close, the close event
|
|
||||||
// should still be emitted; the "ws" documentation says: "The close
|
|
||||||
// event is also emitted when then underlying net.Socket closes the
|
|
||||||
// connection (end or close)."
|
|
||||||
// In case if there is connection error (say, server is not responding)
|
|
||||||
// we must return this error to connection's caller. After successful
|
|
||||||
// opening, we will forward all errors to main api object.
|
|
||||||
this._onOpenErrorBound = this._onOpenError.bind(this, reject);
|
|
||||||
this._ws.once('error', this._onOpenErrorBound);
|
|
||||||
this._ws.on('message', this._onMessage.bind(this));
|
|
||||||
// in browser close event can came before open event, so we must
|
|
||||||
// resolve connect's promise after reconnect in that case.
|
|
||||||
// after open event we will rebound _onUnexpectedCloseBound
|
|
||||||
// without resolve and reject functions
|
|
||||||
this._onUnexpectedCloseBound = this._onUnexpectedClose.bind(this, true,
|
|
||||||
resolve, reject);
|
|
||||||
this._ws.once('close', this._onUnexpectedCloseBound);
|
|
||||||
this._ws.once('open', () => this._onOpen().then(resolve, reject));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
disconnect() {
|
|
||||||
return this._disconnect(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
_disconnect(calledByUser) {
|
|
||||||
if (calledByUser) {
|
|
||||||
this._clearReconnectTimer();
|
|
||||||
this._retry = 0;
|
|
||||||
}
|
|
||||||
return new Promise(resolve => {
|
|
||||||
if (this._state === WebSocket.CLOSED) {
|
|
||||||
resolve();
|
|
||||||
} else if (this._state === WebSocket.CLOSING) {
|
|
||||||
this._ws.once('close', resolve);
|
|
||||||
} else {
|
|
||||||
if (this._onUnexpectedCloseBound) {
|
|
||||||
this._ws.removeListener('close', this._onUnexpectedCloseBound);
|
|
||||||
this._onUnexpectedCloseBound = null;
|
|
||||||
}
|
|
||||||
this._ws.once('close', code => {
|
|
||||||
this._ws = null;
|
|
||||||
this._isReady = false;
|
|
||||||
if (calledByUser) {
|
|
||||||
this.emit('disconnected', code || 1000); // 1000 - CLOSE_NORMAL
|
|
||||||
}
|
|
||||||
resolve();
|
|
||||||
});
|
|
||||||
this._ws.close();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
reconnect() {
|
|
||||||
return this.disconnect().then(() => this.connect());
|
|
||||||
}
|
|
||||||
|
|
||||||
_whenReady(promise) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
if (!this._shouldBeConnected) {
|
|
||||||
reject(new NotConnectedError());
|
|
||||||
} else if (this._state === WebSocket.OPEN && this._isReady) {
|
|
||||||
promise.then(resolve, reject);
|
|
||||||
} else {
|
|
||||||
this.once('connected', () => promise.then(resolve, reject));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
getLedgerVersion() {
|
|
||||||
return this._whenReady(Promise.resolve(this._ledgerVersion));
|
|
||||||
}
|
|
||||||
|
|
||||||
hasLedgerVersions(lowLedgerVersion, highLedgerVersion) {
|
|
||||||
return this._whenReady(Promise.resolve(
|
|
||||||
this._availableLedgerVersions.containsRange(
|
|
||||||
lowLedgerVersion, highLedgerVersion || this._ledgerVersion)));
|
|
||||||
}
|
|
||||||
|
|
||||||
hasLedgerVersion(ledgerVersion) {
|
|
||||||
return this.hasLedgerVersions(ledgerVersion, ledgerVersion);
|
|
||||||
}
|
|
||||||
|
|
||||||
_send(message) {
|
|
||||||
if (this._trace) {
|
|
||||||
this._console.log(message);
|
|
||||||
}
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
this._ws.send(message, undefined, (error, result) => {
|
|
||||||
if (error) {
|
|
||||||
reject(new DisconnectedError(error.message));
|
|
||||||
} else {
|
|
||||||
resolve(result);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
request(request, timeout) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
if (!this._shouldBeConnected) {
|
|
||||||
reject(new NotConnectedError());
|
|
||||||
}
|
|
||||||
|
|
||||||
let timer = null;
|
|
||||||
const self = this;
|
|
||||||
const id = this._nextRequestID;
|
|
||||||
this._nextRequestID += 1;
|
|
||||||
const eventName = id.toString();
|
|
||||||
|
|
||||||
function onDisconnect() {
|
|
||||||
clearTimeout(timer);
|
|
||||||
self.removeAllListeners(eventName);
|
|
||||||
reject(new DisconnectedError());
|
|
||||||
}
|
|
||||||
|
|
||||||
function cleanup() {
|
|
||||||
clearTimeout(timer);
|
|
||||||
self.removeAllListeners(eventName);
|
|
||||||
if (self._ws !== null) {
|
|
||||||
self._ws.removeListener('close', onDisconnect);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function _resolve(response) {
|
|
||||||
cleanup();
|
|
||||||
resolve(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
function _reject(error) {
|
|
||||||
cleanup();
|
|
||||||
reject(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.once(eventName, response => {
|
|
||||||
if (response.status === 'error') {
|
|
||||||
_reject(new RippledError(response.error));
|
|
||||||
} else if (response.status === 'success') {
|
|
||||||
_resolve(response.result);
|
|
||||||
} else {
|
|
||||||
_reject(new ResponseFormatError(
|
|
||||||
'unrecognized status: ' + response.status));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this._ws.once('close', onDisconnect);
|
|
||||||
|
|
||||||
// JSON.stringify automatically removes keys with value of 'undefined'
|
|
||||||
const message = JSON.stringify(Object.assign({}, request, {id}));
|
|
||||||
|
|
||||||
this._whenReady(this._send(message)).then(() => {
|
|
||||||
const delay = timeout || this._timeout;
|
|
||||||
timer = setTimeout(() => _reject(new TimeoutError()), delay);
|
|
||||||
}).catch(_reject);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = Connection;
|
|
||||||
475
src/common/connection.ts
Normal file
475
src/common/connection.ts
Normal file
@@ -0,0 +1,475 @@
|
|||||||
|
import * as _ from 'lodash'
|
||||||
|
import {EventEmitter} from 'events'
|
||||||
|
import {parse as parseUrl} from 'url'
|
||||||
|
import * as WebSocket from 'ws'
|
||||||
|
import RangeSet from './rangeset'
|
||||||
|
import {RippledError, DisconnectedError, NotConnectedError,
|
||||||
|
TimeoutError, ResponseFormatError, ConnectionError,
|
||||||
|
RippledNotInitializedError} from './errors'
|
||||||
|
|
||||||
|
function isStreamMessageType(type) {
|
||||||
|
return type === 'ledgerClosed' ||
|
||||||
|
type === 'transaction' ||
|
||||||
|
type === 'path_find'
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ConnectionOptions {
|
||||||
|
trace?: boolean,
|
||||||
|
proxy?: string
|
||||||
|
proxyAuthorization?: string
|
||||||
|
authorization?: string
|
||||||
|
trustedCertificates?: string[]
|
||||||
|
key?: string
|
||||||
|
passphrase?: string
|
||||||
|
certificate?: string
|
||||||
|
timeout?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
class Connection extends EventEmitter {
|
||||||
|
|
||||||
|
private _url: string
|
||||||
|
private _trace: boolean
|
||||||
|
private _console?: Console
|
||||||
|
private _proxyURL?: string
|
||||||
|
private _proxyAuthorization?: string
|
||||||
|
private _authorization?: string
|
||||||
|
private _trustedCertificates?: string[]
|
||||||
|
private _key?: string
|
||||||
|
private _passphrase?: string
|
||||||
|
private _certificate?: string
|
||||||
|
private _timeout: number
|
||||||
|
private _isReady: boolean = false
|
||||||
|
private _ws: null|WebSocket = null
|
||||||
|
protected _ledgerVersion: null|number = null
|
||||||
|
private _availableLedgerVersions = new RangeSet()
|
||||||
|
private _nextRequestID: number = 1
|
||||||
|
private _retry: number = 0
|
||||||
|
private _retryTimer: null|NodeJS.Timer = null
|
||||||
|
private _onOpenErrorBound: null| null|((...args: any[]) => void) = null
|
||||||
|
private _onUnexpectedCloseBound: null|((...args: any[]) => void) = null
|
||||||
|
private _fee_base: null|number = null
|
||||||
|
private _fee_ref: null|number = null
|
||||||
|
|
||||||
|
constructor(url, options: ConnectionOptions = {}) {
|
||||||
|
super()
|
||||||
|
this.setMaxListeners(Infinity)
|
||||||
|
this._url = url
|
||||||
|
this._trace = options.trace || false
|
||||||
|
if (this._trace) {
|
||||||
|
// for easier unit testing
|
||||||
|
this._console = console
|
||||||
|
}
|
||||||
|
this._proxyURL = options.proxy
|
||||||
|
this._proxyAuthorization = options.proxyAuthorization
|
||||||
|
this._authorization = options.authorization
|
||||||
|
this._trustedCertificates = options.trustedCertificates
|
||||||
|
this._key = options.key
|
||||||
|
this._passphrase = options.passphrase
|
||||||
|
this._certificate = options.certificate
|
||||||
|
this._timeout = options.timeout || (20 * 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
_updateLedgerVersions(data) {
|
||||||
|
this._ledgerVersion = Number(data.ledger_index)
|
||||||
|
if (data.validated_ledgers) {
|
||||||
|
this._availableLedgerVersions.reset()
|
||||||
|
this._availableLedgerVersions.parseAndAddRanges(
|
||||||
|
data.validated_ledgers)
|
||||||
|
} else {
|
||||||
|
this._availableLedgerVersions.addValue(this._ledgerVersion)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_updateFees(data) {
|
||||||
|
this._fee_base = Number(data.fee_base)
|
||||||
|
this._fee_ref = Number(data.fee_ref)
|
||||||
|
}
|
||||||
|
|
||||||
|
// return value is array of arguments to Connection.emit
|
||||||
|
_parseMessage(message): [string, Object] | ['error', string, string, Object] {
|
||||||
|
const data = JSON.parse(message)
|
||||||
|
if (data.type === 'response') {
|
||||||
|
if (!(Number.isInteger(data.id) && data.id >= 0)) {
|
||||||
|
throw new ResponseFormatError('valid id not found in response')
|
||||||
|
}
|
||||||
|
return [data.id.toString(), data]
|
||||||
|
} else if (isStreamMessageType(data.type)) {
|
||||||
|
if (data.type === 'ledgerClosed') {
|
||||||
|
this._updateLedgerVersions(data)
|
||||||
|
this._updateFees(data)
|
||||||
|
}
|
||||||
|
return [data.type, data]
|
||||||
|
} else if (data.type === undefined && data.error) {
|
||||||
|
return ['error', data.error, data.error_message, data] // e.g. slowDown
|
||||||
|
}
|
||||||
|
throw new ResponseFormatError('unrecognized message type: ' + data.type)
|
||||||
|
}
|
||||||
|
|
||||||
|
_onMessage(message) {
|
||||||
|
if (this._trace) {
|
||||||
|
this._console!.log(message)
|
||||||
|
}
|
||||||
|
let parameters
|
||||||
|
try {
|
||||||
|
parameters = this._parseMessage(message)
|
||||||
|
} catch (error) {
|
||||||
|
this.emit('error', 'badMessage', error.message, message)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// we don't want this inside the try/catch or exceptions in listener
|
||||||
|
// will be caught
|
||||||
|
this.emit.apply(this, parameters)
|
||||||
|
}
|
||||||
|
|
||||||
|
get _state() {
|
||||||
|
return this._ws ? this._ws.readyState : WebSocket.CLOSED
|
||||||
|
}
|
||||||
|
|
||||||
|
get _shouldBeConnected() {
|
||||||
|
return this._ws !== null
|
||||||
|
}
|
||||||
|
|
||||||
|
isConnected() {
|
||||||
|
return this._state === WebSocket.OPEN && this._isReady
|
||||||
|
}
|
||||||
|
|
||||||
|
_onUnexpectedClose(beforeOpen, resolve, reject, code) {
|
||||||
|
if (this._onOpenErrorBound) {
|
||||||
|
this._ws!.removeListener('error', this._onOpenErrorBound)
|
||||||
|
this._onOpenErrorBound = null
|
||||||
|
}
|
||||||
|
// just in case
|
||||||
|
this._ws!.removeAllListeners('open')
|
||||||
|
this._ws = null
|
||||||
|
this._isReady = false
|
||||||
|
if (beforeOpen) {
|
||||||
|
// connection was closed before it was properly opened, so we must return
|
||||||
|
// error to connect's caller
|
||||||
|
this.connect().then(resolve, reject)
|
||||||
|
} else {
|
||||||
|
// if first parameter ws lib sends close code,
|
||||||
|
// but sometimes it forgots about it, so default to 1006 - CLOSE_ABNORMAL
|
||||||
|
this.emit('disconnected', code || 1006)
|
||||||
|
this._retryConnect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_calculateTimeout(retriesCount) {
|
||||||
|
return (retriesCount < 40)
|
||||||
|
// First, for 2 seconds: 20 times per second
|
||||||
|
? (1000 / 20)
|
||||||
|
: (retriesCount < 40 + 60)
|
||||||
|
// Then, for 1 minute: once per second
|
||||||
|
? (1000)
|
||||||
|
: (retriesCount < 40 + 60 + 60)
|
||||||
|
// Then, for 10 minutes: once every 10 seconds
|
||||||
|
? (10 * 1000)
|
||||||
|
// Then: once every 30 seconds
|
||||||
|
: (30 * 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
_retryConnect() {
|
||||||
|
this._retry += 1
|
||||||
|
const retryTimeout = this._calculateTimeout(this._retry)
|
||||||
|
this._retryTimer = setTimeout(() => {
|
||||||
|
this.emit('reconnecting', this._retry)
|
||||||
|
this.connect().catch(this._retryConnect.bind(this))
|
||||||
|
}, retryTimeout)
|
||||||
|
}
|
||||||
|
|
||||||
|
_clearReconnectTimer() {
|
||||||
|
if (this._retryTimer !== null) {
|
||||||
|
clearTimeout(this._retryTimer)
|
||||||
|
this._retryTimer = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_onOpen() {
|
||||||
|
if (!this._ws) {
|
||||||
|
return Promise.reject(new DisconnectedError())
|
||||||
|
}
|
||||||
|
if (this._onOpenErrorBound) {
|
||||||
|
this._ws.removeListener('error', this._onOpenErrorBound)
|
||||||
|
this._onOpenErrorBound = null
|
||||||
|
}
|
||||||
|
|
||||||
|
const request = {
|
||||||
|
command: 'subscribe',
|
||||||
|
streams: ['ledger']
|
||||||
|
}
|
||||||
|
return this.request(request).then((data: any) => {
|
||||||
|
if (_.isEmpty(data) || !data.ledger_index) {
|
||||||
|
// rippled instance doesn't have validated ledgers
|
||||||
|
return this._disconnect(false).then(() => {
|
||||||
|
throw new RippledNotInitializedError('Rippled not initialized')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
this._updateLedgerVersions(data)
|
||||||
|
this._updateFees(data)
|
||||||
|
this._rebindOnUnxpectedClose()
|
||||||
|
|
||||||
|
this._retry = 0
|
||||||
|
this._ws.on('error', error => {
|
||||||
|
// TODO: "type" does not exist on official error type, safe to remove?
|
||||||
|
if (process.browser && error && (<any>error).type === 'error') {
|
||||||
|
// we are in browser, ignore error - `close` event will be fired
|
||||||
|
// after error
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.emit('error', 'websocket', error.message, error)
|
||||||
|
})
|
||||||
|
|
||||||
|
this._isReady = true
|
||||||
|
this.emit('connected')
|
||||||
|
|
||||||
|
return undefined
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
_rebindOnUnxpectedClose() {
|
||||||
|
if (this._onUnexpectedCloseBound) {
|
||||||
|
this._ws.removeListener('close', this._onUnexpectedCloseBound)
|
||||||
|
}
|
||||||
|
this._onUnexpectedCloseBound =
|
||||||
|
this._onUnexpectedClose.bind(this, false, null, null)
|
||||||
|
this._ws.once('close', this._onUnexpectedCloseBound)
|
||||||
|
}
|
||||||
|
|
||||||
|
_unbindOnUnxpectedClose() {
|
||||||
|
if (this._onUnexpectedCloseBound) {
|
||||||
|
this._ws.removeListener('close', this._onUnexpectedCloseBound)
|
||||||
|
}
|
||||||
|
this._onUnexpectedCloseBound = null
|
||||||
|
}
|
||||||
|
|
||||||
|
_onOpenError(reject, error) {
|
||||||
|
this._onOpenErrorBound = null
|
||||||
|
this._unbindOnUnxpectedClose()
|
||||||
|
reject(new NotConnectedError(error && error.message))
|
||||||
|
}
|
||||||
|
|
||||||
|
_createWebSocket(): WebSocket {
|
||||||
|
const options: WebSocket.ClientOptions = {}
|
||||||
|
if (this._proxyURL !== undefined) {
|
||||||
|
const parsedURL = parseUrl(this._url)
|
||||||
|
const parsedProxyURL = parseUrl(this._proxyURL)
|
||||||
|
const proxyOverrides = _.omitBy({
|
||||||
|
secureEndpoint: (parsedURL.protocol === 'wss:'),
|
||||||
|
secureProxy: (parsedProxyURL.protocol === 'https:'),
|
||||||
|
auth: this._proxyAuthorization,
|
||||||
|
ca: this._trustedCertificates,
|
||||||
|
key: this._key,
|
||||||
|
passphrase: this._passphrase,
|
||||||
|
cert: this._certificate
|
||||||
|
}, _.isUndefined)
|
||||||
|
const proxyOptions = _.assign({}, parsedProxyURL, proxyOverrides)
|
||||||
|
let HttpsProxyAgent
|
||||||
|
try {
|
||||||
|
HttpsProxyAgent = require('https-proxy-agent')
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error('"proxy" option is not supported in the browser')
|
||||||
|
}
|
||||||
|
options.agent = new HttpsProxyAgent(proxyOptions)
|
||||||
|
}
|
||||||
|
if (this._authorization !== undefined) {
|
||||||
|
const base64 = new Buffer(this._authorization).toString('base64')
|
||||||
|
options.headers = {Authorization: `Basic ${base64}`}
|
||||||
|
}
|
||||||
|
const optionsOverrides = _.omitBy({
|
||||||
|
ca: this._trustedCertificates,
|
||||||
|
key: this._key,
|
||||||
|
passphrase: this._passphrase,
|
||||||
|
cert: this._certificate
|
||||||
|
}, _.isUndefined)
|
||||||
|
const websocketOptions = _.assign({}, options, optionsOverrides)
|
||||||
|
const websocket = new WebSocket(this._url, null, websocketOptions)
|
||||||
|
// we will have a listener for each outstanding request,
|
||||||
|
// so we have to raise the limit (the default is 10)
|
||||||
|
if (typeof websocket.setMaxListeners === 'function') {
|
||||||
|
websocket.setMaxListeners(Infinity)
|
||||||
|
}
|
||||||
|
return websocket
|
||||||
|
}
|
||||||
|
|
||||||
|
connect() {
|
||||||
|
this._clearReconnectTimer()
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (!this._url) {
|
||||||
|
reject(new ConnectionError(
|
||||||
|
'Cannot connect because no server was specified'))
|
||||||
|
}
|
||||||
|
if (this._state === WebSocket.OPEN) {
|
||||||
|
resolve()
|
||||||
|
} else if (this._state === WebSocket.CONNECTING) {
|
||||||
|
this._ws.once('open', resolve)
|
||||||
|
} else {
|
||||||
|
this._ws = this._createWebSocket()
|
||||||
|
// when an error causes the connection to close, the close event
|
||||||
|
// should still be emitted; the "ws" documentation says: "The close
|
||||||
|
// event is also emitted when then underlying net.Socket closes the
|
||||||
|
// connection (end or close)."
|
||||||
|
// In case if there is connection error (say, server is not responding)
|
||||||
|
// we must return this error to connection's caller. After successful
|
||||||
|
// opening, we will forward all errors to main api object.
|
||||||
|
this._onOpenErrorBound = this._onOpenError.bind(this, reject)
|
||||||
|
this._ws.once('error', this._onOpenErrorBound)
|
||||||
|
this._ws.on('message', this._onMessage.bind(this))
|
||||||
|
// in browser close event can came before open event, so we must
|
||||||
|
// resolve connect's promise after reconnect in that case.
|
||||||
|
// after open event we will rebound _onUnexpectedCloseBound
|
||||||
|
// without resolve and reject functions
|
||||||
|
this._onUnexpectedCloseBound = this._onUnexpectedClose.bind(this, true,
|
||||||
|
resolve, reject)
|
||||||
|
this._ws.once('close', this._onUnexpectedCloseBound)
|
||||||
|
this._ws.once('open', () => this._onOpen().then(resolve, reject))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
disconnect() {
|
||||||
|
return this._disconnect(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
_disconnect(calledByUser) {
|
||||||
|
if (calledByUser) {
|
||||||
|
this._clearReconnectTimer()
|
||||||
|
this._retry = 0
|
||||||
|
}
|
||||||
|
return new Promise(resolve => {
|
||||||
|
if (this._state === WebSocket.CLOSED) {
|
||||||
|
resolve()
|
||||||
|
} else if (this._state === WebSocket.CLOSING) {
|
||||||
|
this._ws.once('close', resolve)
|
||||||
|
} else {
|
||||||
|
if (this._onUnexpectedCloseBound) {
|
||||||
|
this._ws.removeListener('close', this._onUnexpectedCloseBound)
|
||||||
|
this._onUnexpectedCloseBound = null
|
||||||
|
}
|
||||||
|
this._ws.once('close', code => {
|
||||||
|
this._ws = null
|
||||||
|
this._isReady = false
|
||||||
|
if (calledByUser) {
|
||||||
|
this.emit('disconnected', code || 1000) // 1000 - CLOSE_NORMAL
|
||||||
|
}
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
this._ws.close()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
reconnect() {
|
||||||
|
return this.disconnect().then(() => this.connect())
|
||||||
|
}
|
||||||
|
|
||||||
|
_whenReady<T>(promise: Promise<T>): Promise<T> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (!this._shouldBeConnected) {
|
||||||
|
reject(new NotConnectedError())
|
||||||
|
} else if (this._state === WebSocket.OPEN && this._isReady) {
|
||||||
|
promise.then(resolve, reject)
|
||||||
|
} else {
|
||||||
|
this.once('connected', () => promise.then(resolve, reject))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
getLedgerVersion(): Promise<number> {
|
||||||
|
return this._whenReady(Promise.resolve(this._ledgerVersion!))
|
||||||
|
}
|
||||||
|
|
||||||
|
hasLedgerVersions(lowLedgerVersion, highLedgerVersion): Promise<boolean> {
|
||||||
|
return this._whenReady(Promise.resolve(
|
||||||
|
this._availableLedgerVersions.containsRange(
|
||||||
|
lowLedgerVersion, highLedgerVersion || this._ledgerVersion)))
|
||||||
|
}
|
||||||
|
|
||||||
|
hasLedgerVersion(ledgerVersion): Promise<boolean> {
|
||||||
|
return this.hasLedgerVersions(ledgerVersion, ledgerVersion)
|
||||||
|
}
|
||||||
|
|
||||||
|
getFeeBase(): Promise<number> {
|
||||||
|
return this._whenReady(Promise.resolve(Number(this._fee_base)))
|
||||||
|
}
|
||||||
|
|
||||||
|
getFeeRef(): Promise<number> {
|
||||||
|
return this._whenReady(Promise.resolve(Number(this._fee_ref)))
|
||||||
|
}
|
||||||
|
|
||||||
|
_send(message: string): Promise<void> {
|
||||||
|
if (this._trace) {
|
||||||
|
this._console.log(message)
|
||||||
|
}
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this._ws.send(message, undefined, error => {
|
||||||
|
if (error) {
|
||||||
|
reject(new DisconnectedError(error.message))
|
||||||
|
} else {
|
||||||
|
resolve()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
request(request, timeout?: number): Promise<any> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (!this._shouldBeConnected) {
|
||||||
|
reject(new NotConnectedError())
|
||||||
|
}
|
||||||
|
|
||||||
|
let timer = null
|
||||||
|
const self = this
|
||||||
|
const id = this._nextRequestID
|
||||||
|
this._nextRequestID += 1
|
||||||
|
const eventName = id.toString()
|
||||||
|
|
||||||
|
function onDisconnect() {
|
||||||
|
clearTimeout(timer)
|
||||||
|
self.removeAllListeners(eventName)
|
||||||
|
reject(new DisconnectedError())
|
||||||
|
}
|
||||||
|
|
||||||
|
function cleanup() {
|
||||||
|
clearTimeout(timer)
|
||||||
|
self.removeAllListeners(eventName)
|
||||||
|
if (self._ws !== null) {
|
||||||
|
self._ws.removeListener('close', onDisconnect)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function _resolve(response) {
|
||||||
|
cleanup()
|
||||||
|
resolve(response)
|
||||||
|
}
|
||||||
|
|
||||||
|
function _reject(error) {
|
||||||
|
cleanup()
|
||||||
|
reject(error)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.once(eventName, response => {
|
||||||
|
if (response.status === 'error') {
|
||||||
|
_reject(new RippledError(response.error))
|
||||||
|
} else if (response.status === 'success') {
|
||||||
|
_resolve(response.result)
|
||||||
|
} else {
|
||||||
|
_reject(new ResponseFormatError(
|
||||||
|
'unrecognized status: ' + response.status))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
this._ws.once('close', onDisconnect)
|
||||||
|
|
||||||
|
// JSON.stringify automatically removes keys with value of 'undefined'
|
||||||
|
const message = JSON.stringify(Object.assign({}, request, {id}))
|
||||||
|
|
||||||
|
this._whenReady(this._send(message)).then(() => {
|
||||||
|
const delay = timeout || this._timeout
|
||||||
|
timer = setTimeout(() => _reject(new TimeoutError()), delay)
|
||||||
|
}).catch(_reject)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Connection
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
'use strict';
|
|
||||||
const flagIndices = require('./txflags').txFlagIndices.AccountSet;
|
import {txFlagIndices} from './txflags'
|
||||||
|
|
||||||
const accountRootFlags = {
|
const accountRootFlags = {
|
||||||
PasswordSpent: 0x00010000, // password set fee is spent
|
PasswordSpent: 0x00010000, // password set fee is spent
|
||||||
RequireDestTag: 0x00020000, // require a DestinationTag for payments
|
RequireDestTag: 0x00020000, // require a DestinationTag for payments
|
||||||
RequireAuth: 0x00040000, // require a authorization to hold IOUs
|
RequireAuth: 0x00040000, // require a authorization to hold IOUs
|
||||||
DisallowXRP: 0x00080000, // disallow sending XRP
|
DisallowXRP: 0x00080000, // disallow sending XRP
|
||||||
DisableMaster: 0x00100000, // force regular key
|
DisableMaster: 0x00100000, // force regular key
|
||||||
NoFreeze: 0x00200000, // permanently disallowed freezing trustlines
|
NoFreeze: 0x00200000, // permanently disallowed freezing trustlines
|
||||||
GlobalFreeze: 0x00400000, // trustlines globally frozen
|
GlobalFreeze: 0x00400000, // trustlines globally frozen
|
||||||
DefaultRipple: 0x00800000
|
DefaultRipple: 0x00800000
|
||||||
};
|
}
|
||||||
|
|
||||||
const AccountFlags = {
|
const AccountFlags = {
|
||||||
passwordSpent: accountRootFlags.PasswordSpent,
|
passwordSpent: accountRootFlags.PasswordSpent,
|
||||||
@@ -21,29 +21,29 @@ const AccountFlags = {
|
|||||||
noFreeze: accountRootFlags.NoFreeze,
|
noFreeze: accountRootFlags.NoFreeze,
|
||||||
globalFreeze: accountRootFlags.GlobalFreeze,
|
globalFreeze: accountRootFlags.GlobalFreeze,
|
||||||
defaultRipple: accountRootFlags.DefaultRipple
|
defaultRipple: accountRootFlags.DefaultRipple
|
||||||
};
|
}
|
||||||
|
|
||||||
const AccountFlagIndices = {
|
const AccountFlagIndices = {
|
||||||
requireDestinationTag: flagIndices.asfRequireDest,
|
requireDestinationTag: txFlagIndices.AccountSet.asfRequireDest,
|
||||||
requireAuthorization: flagIndices.asfRequireAuth,
|
requireAuthorization: txFlagIndices.AccountSet.asfRequireAuth,
|
||||||
disallowIncomingXRP: flagIndices.asfDisallowXRP,
|
disallowIncomingXRP: txFlagIndices.AccountSet.asfDisallowXRP,
|
||||||
disableMasterKey: flagIndices.asfDisableMaster,
|
disableMasterKey: txFlagIndices.AccountSet.asfDisableMaster,
|
||||||
enableTransactionIDTracking: flagIndices.asfAccountTxnID,
|
enableTransactionIDTracking: txFlagIndices.AccountSet.asfAccountTxnID,
|
||||||
noFreeze: flagIndices.asfNoFreeze,
|
noFreeze: txFlagIndices.AccountSet.asfNoFreeze,
|
||||||
globalFreeze: flagIndices.asfGlobalFreeze,
|
globalFreeze: txFlagIndices.AccountSet.asfGlobalFreeze,
|
||||||
defaultRipple: flagIndices.asfDefaultRipple
|
defaultRipple: txFlagIndices.AccountSet.asfDefaultRipple
|
||||||
};
|
}
|
||||||
|
|
||||||
const AccountFields = {
|
const AccountFields = {
|
||||||
EmailHash: {name: 'emailHash', encoding: 'hex',
|
EmailHash: {name: 'emailHash', encoding: 'hex',
|
||||||
length: 32, defaults: '0'},
|
length: 32, defaults: '0'},
|
||||||
MessageKey: {name: 'messageKey'},
|
MessageKey: {name: 'messageKey'},
|
||||||
Domain: {name: 'domain', encoding: 'hex'},
|
Domain: {name: 'domain', encoding: 'hex'},
|
||||||
TransferRate: {name: 'transferRate', defaults: 0, shift: 9}
|
TransferRate: {name: 'transferRate', defaults: 0, shift: 9}
|
||||||
};
|
}
|
||||||
|
|
||||||
module.exports = {
|
export {
|
||||||
AccountFields,
|
AccountFields,
|
||||||
AccountFlagIndices,
|
AccountFlagIndices,
|
||||||
AccountFlags
|
AccountFlags
|
||||||
};
|
}
|
||||||
@@ -1,43 +1,38 @@
|
|||||||
'use strict'; // eslint-disable-line
|
|
||||||
const util = require('util');
|
|
||||||
const browserHacks = require('./browser-hacks');
|
|
||||||
|
|
||||||
// this is needed because extending builtins doesn't work in babel 6.x
|
import {inspect} from 'util'
|
||||||
function extendableBuiltin(cls) {
|
import * as browserHacks from './browser-hacks'
|
||||||
function ExtendableBuiltin() {
|
|
||||||
cls.apply(this, arguments);
|
|
||||||
}
|
|
||||||
ExtendableBuiltin.prototype = Object.create(cls.prototype);
|
|
||||||
browserHacks.setPrototypeOf(ExtendableBuiltin, cls);
|
|
||||||
return ExtendableBuiltin;
|
|
||||||
}
|
|
||||||
|
|
||||||
class RippleError extends extendableBuiltin(Error) {
|
class RippleError extends Error {
|
||||||
constructor(message, data) {
|
|
||||||
super(message);
|
|
||||||
|
|
||||||
this.name = browserHacks.getConstructorName(this);
|
name: string
|
||||||
this.message = message;
|
message: string
|
||||||
this.data = data;
|
data?: any
|
||||||
|
|
||||||
|
constructor(message = '', data?: any) {
|
||||||
|
super(message)
|
||||||
|
|
||||||
|
this.name = browserHacks.getConstructorName(this)
|
||||||
|
this.message = message
|
||||||
|
this.data = data
|
||||||
if (Error.captureStackTrace) {
|
if (Error.captureStackTrace) {
|
||||||
Error.captureStackTrace(this, this.constructor.name);
|
Error.captureStackTrace(this, this.constructor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
toString() {
|
toString() {
|
||||||
let result = '[' + this.name + '(' + this.message;
|
let result = '[' + this.name + '(' + this.message
|
||||||
if (this.data) {
|
if (this.data) {
|
||||||
result += ', ' + util.inspect(this.data);
|
result += ', ' + inspect(this.data)
|
||||||
}
|
}
|
||||||
result += ')]';
|
result += ')]'
|
||||||
return result;
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
/* console.log in node uses util.inspect on object, and util.inspect allows
|
/* console.log in node uses util.inspect on object, and util.inspect allows
|
||||||
us to cutomize its output:
|
us to cutomize its output:
|
||||||
https://nodejs.org/api/util.html#util_custom_inspect_function_on_objects */
|
https://nodejs.org/api/util.html#util_custom_inspect_function_on_objects */
|
||||||
inspect() {
|
inspect() {
|
||||||
return this.toString();
|
return this.toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,25 +57,25 @@ class ResponseFormatError extends ConnectionError {}
|
|||||||
class ValidationError extends RippleError {}
|
class ValidationError extends RippleError {}
|
||||||
|
|
||||||
class NotFoundError extends RippleError {
|
class NotFoundError extends RippleError {
|
||||||
constructor(message) {
|
constructor(message = 'Not found') {
|
||||||
super(message || 'Not found');
|
super(message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MissingLedgerHistoryError extends RippleError {
|
class MissingLedgerHistoryError extends RippleError {
|
||||||
constructor(message) {
|
constructor(message?: string) {
|
||||||
super(message || 'Server is missing ledger history in the specified range');
|
super(message || 'Server is missing ledger history in the specified range')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PendingLedgerVersionError extends RippleError {
|
class PendingLedgerVersionError extends RippleError {
|
||||||
constructor(message) {
|
constructor(message?: string) {
|
||||||
super(message || 'maxLedgerVersion is greater than server\'s'
|
super(message || 'maxLedgerVersion is greater than server\'s most recent ' +
|
||||||
+ ' most recent validated ledger');
|
' validated ledger')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
export {
|
||||||
RippleError,
|
RippleError,
|
||||||
UnexpectedError,
|
UnexpectedError,
|
||||||
ConnectionError,
|
ConnectionError,
|
||||||
@@ -95,4 +90,4 @@ module.exports = {
|
|||||||
PendingLedgerVersionError,
|
PendingLedgerVersionError,
|
||||||
MissingLedgerHistoryError,
|
MissingLedgerHistoryError,
|
||||||
LedgerVersionError
|
LedgerVersionError
|
||||||
};
|
}
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
const utils = require('./utils');
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
Connection: require('./connection'),
|
|
||||||
constants: require('./constants'),
|
|
||||||
errors: require('./errors'),
|
|
||||||
validate: require('./validate'),
|
|
||||||
txFlags: require('./txflags').txFlags,
|
|
||||||
serverInfo: require('./serverinfo'),
|
|
||||||
dropsToXrp: utils.dropsToXrp,
|
|
||||||
xrpToDrops: utils.xrpToDrops,
|
|
||||||
toRippledAmount: utils.toRippledAmount,
|
|
||||||
generateAddress: utils.generateAddress,
|
|
||||||
generateAddressAPI: utils.generateAddressAPI,
|
|
||||||
removeUndefined: utils.removeUndefined,
|
|
||||||
convertKeysFromSnakeCaseToCamelCase:
|
|
||||||
utils.convertKeysFromSnakeCaseToCamelCase,
|
|
||||||
iso8601ToRippleTime: utils.iso8601ToRippleTime,
|
|
||||||
rippleTimeToISO8601: utils.rippleTimeToISO8601,
|
|
||||||
isValidSecret: utils.isValidSecret
|
|
||||||
};
|
|
||||||
23
src/common/index.ts
Normal file
23
src/common/index.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import * as constants from './constants'
|
||||||
|
import * as errors from './errors'
|
||||||
|
import * as validate from './validate'
|
||||||
|
import * as serverInfo from './serverinfo'
|
||||||
|
export {
|
||||||
|
constants,
|
||||||
|
errors,
|
||||||
|
validate,
|
||||||
|
serverInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
dropsToXrp,
|
||||||
|
xrpToDrops,
|
||||||
|
toRippledAmount,
|
||||||
|
removeUndefined,
|
||||||
|
convertKeysFromSnakeCaseToCamelCase,
|
||||||
|
iso8601ToRippleTime,
|
||||||
|
rippleTimeToISO8601
|
||||||
|
} from './utils'
|
||||||
|
export {default as Connection} from './connection'
|
||||||
|
export {txFlags} from './txflags'
|
||||||
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
/* @flow */
|
|
||||||
'use strict';
|
|
||||||
const _ = require('lodash');
|
|
||||||
const assert = require('assert');
|
|
||||||
const ranges = Symbol();
|
|
||||||
|
|
||||||
function mergeIntervals(intervals: Array<[number, number]>) {
|
|
||||||
const stack = [[-Infinity, -Infinity]];
|
|
||||||
_.forEach(_.sortBy(intervals, x => x[0]), interval => {
|
|
||||||
const lastInterval = stack.pop();
|
|
||||||
if (interval[0] <= lastInterval[1] + 1) {
|
|
||||||
stack.push([lastInterval[0], Math.max(interval[1], lastInterval[1])]);
|
|
||||||
} else {
|
|
||||||
stack.push(lastInterval);
|
|
||||||
stack.push(interval);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return stack.slice(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
class RangeSet {
|
|
||||||
constructor() {
|
|
||||||
this.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
reset() {
|
|
||||||
this[ranges] = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
serialize() {
|
|
||||||
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]]));
|
|
||||||
}
|
|
||||||
|
|
||||||
addValue(value: number) {
|
|
||||||
this.addRange(value, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
parseAndAddRanges(rangesString: string) {
|
|
||||||
const rangeStrings = rangesString.split(',');
|
|
||||||
_.forEach(rangeStrings, rangeString => {
|
|
||||||
const range = rangeString.split('-').map(Number);
|
|
||||||
this.addRange(range[0], range.length === 1 ? range[0] : range[1]);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
containsRange(start: number, end: number) {
|
|
||||||
return _.some(this[ranges], range => range[0] <= start && range[1] >= end);
|
|
||||||
}
|
|
||||||
|
|
||||||
containsValue(value: number) {
|
|
||||||
return this.containsRange(value, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports.RangeSet = RangeSet;
|
|
||||||
63
src/common/rangeset.ts
Normal file
63
src/common/rangeset.ts
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
import * as _ from 'lodash'
|
||||||
|
import * as assert from 'assert'
|
||||||
|
|
||||||
|
type Interval = [number, number]
|
||||||
|
|
||||||
|
function mergeIntervals(intervals: Interval[]): Interval[] {
|
||||||
|
const stack: Interval[] = [[-Infinity, -Infinity]]
|
||||||
|
_.sortBy(intervals, x => x[0]).forEach(interval => {
|
||||||
|
const lastInterval: Interval = stack.pop()!
|
||||||
|
if (interval[0] <= lastInterval[1] + 1) {
|
||||||
|
stack.push([lastInterval[0], Math.max(interval[1], lastInterval[1])])
|
||||||
|
} else {
|
||||||
|
stack.push(lastInterval)
|
||||||
|
stack.push(interval)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return stack.slice(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
class RangeSet {
|
||||||
|
|
||||||
|
ranges: Array<[number, number]>
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.reset()
|
||||||
|
}
|
||||||
|
|
||||||
|
reset() {
|
||||||
|
this.ranges = []
|
||||||
|
}
|
||||||
|
|
||||||
|
serialize() {
|
||||||
|
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]]))
|
||||||
|
}
|
||||||
|
|
||||||
|
addValue(value: number) {
|
||||||
|
this.addRange(value, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
parseAndAddRanges(rangesString: string) {
|
||||||
|
const rangeStrings = rangesString.split(',')
|
||||||
|
_.forEach(rangeStrings, rangeString => {
|
||||||
|
const range = rangeString.split('-').map(Number)
|
||||||
|
this.addRange(range[0], range.length === 1 ? range[0] : range[1])
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
containsRange(start: number, end: number) {
|
||||||
|
return _.some(this.ranges, range => range[0] <= start && range[1] >= end)
|
||||||
|
}
|
||||||
|
|
||||||
|
containsValue(value: number) {
|
||||||
|
return this.containsRange(value, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default RangeSet
|
||||||
@@ -1,12 +1,9 @@
|
|||||||
// flow is disabled for this file until support for requiring json is added:
|
import * as _ from 'lodash'
|
||||||
// https://github.com/facebook/flow/issues/167
|
import * as assert from 'assert'
|
||||||
'use strict';
|
const {Validator} = require('jsonschema')
|
||||||
const _ = require('lodash');
|
import {ValidationError} from './errors'
|
||||||
const assert = require('assert');
|
import {isValidAddress} from 'ripple-address-codec'
|
||||||
const Ajv = require('ajv');
|
import {isValidSecret} from './utils'
|
||||||
const ValidationError = require('./errors').ValidationError;
|
|
||||||
const {isValidAddress} = require('ripple-address-codec');
|
|
||||||
const {isValidSecret} = require('./utils');
|
|
||||||
|
|
||||||
function loadSchemas() {
|
function loadSchemas() {
|
||||||
// listed explicitly for webpack (instead of scanning schemas directory)
|
// listed explicitly for webpack (instead of scanning schemas directory)
|
||||||
@@ -16,11 +13,13 @@ function loadSchemas() {
|
|||||||
require('./schemas/objects/hash128.json'),
|
require('./schemas/objects/hash128.json'),
|
||||||
require('./schemas/objects/hash256.json'),
|
require('./schemas/objects/hash256.json'),
|
||||||
require('./schemas/objects/sequence.json'),
|
require('./schemas/objects/sequence.json'),
|
||||||
|
require('./schemas/objects/signature.json'),
|
||||||
require('./schemas/objects/issue.json'),
|
require('./schemas/objects/issue.json'),
|
||||||
require('./schemas/objects/ledgerversion.json'),
|
require('./schemas/objects/ledgerversion.json'),
|
||||||
require('./schemas/objects/max-adjustment.json'),
|
require('./schemas/objects/max-adjustment.json'),
|
||||||
require('./schemas/objects/memo.json'),
|
require('./schemas/objects/memo.json'),
|
||||||
require('./schemas/objects/memos.json'),
|
require('./schemas/objects/memos.json'),
|
||||||
|
require('./schemas/objects/public-key.json'),
|
||||||
require('./schemas/objects/uint32.json'),
|
require('./schemas/objects/uint32.json'),
|
||||||
require('./schemas/objects/value.json'),
|
require('./schemas/objects/value.json'),
|
||||||
require('./schemas/objects/source-adjustment.json'),
|
require('./schemas/objects/source-adjustment.json'),
|
||||||
@@ -46,21 +45,25 @@ function loadSchemas() {
|
|||||||
require('./schemas/objects/settings.json'),
|
require('./schemas/objects/settings.json'),
|
||||||
require('./schemas/specifications/settings.json'),
|
require('./schemas/specifications/settings.json'),
|
||||||
require('./schemas/specifications/payment.json'),
|
require('./schemas/specifications/payment.json'),
|
||||||
require('./schemas/specifications/suspended-payment-cancellation.json'),
|
require('./schemas/specifications/escrow-cancellation.json'),
|
||||||
require('./schemas/specifications/order-cancellation.json'),
|
require('./schemas/specifications/order-cancellation.json'),
|
||||||
require('./schemas/specifications/order.json'),
|
require('./schemas/specifications/order.json'),
|
||||||
require('./schemas/specifications/suspended-payment-execution.json'),
|
require('./schemas/specifications/escrow-execution.json'),
|
||||||
require('./schemas/specifications/suspended-payment-creation.json'),
|
require('./schemas/specifications/escrow-creation.json'),
|
||||||
|
require('./schemas/specifications/payment-channel-create.json'),
|
||||||
|
require('./schemas/specifications/payment-channel-fund.json'),
|
||||||
|
require('./schemas/specifications/payment-channel-claim.json'),
|
||||||
require('./schemas/specifications/trustline.json'),
|
require('./schemas/specifications/trustline.json'),
|
||||||
require('./schemas/output/sign.json'),
|
require('./schemas/output/sign.json'),
|
||||||
require('./schemas/output/submit.json'),
|
require('./schemas/output/submit.json'),
|
||||||
require('./schemas/output/get-account-info.json'),
|
require('./schemas/output/get-account-info.json'),
|
||||||
require('./schemas/output/get-balances.json'),
|
require('./schemas/output/get-balances.json'),
|
||||||
require('./schemas/output/get-balance-sheet'),
|
require('./schemas/output/get-balance-sheet.json'),
|
||||||
require('./schemas/output/get-ledger.json'),
|
require('./schemas/output/get-ledger.json'),
|
||||||
require('./schemas/output/get-orderbook.json'),
|
require('./schemas/output/get-orderbook.json'),
|
||||||
require('./schemas/output/get-orders.json'),
|
require('./schemas/output/get-orders.json'),
|
||||||
require('./schemas/output/order-change.json'),
|
require('./schemas/output/order-change.json'),
|
||||||
|
require('./schemas/output/get-payment-channel.json'),
|
||||||
require('./schemas/output/prepare.json'),
|
require('./schemas/output/prepare.json'),
|
||||||
require('./schemas/output/ledger-event.json'),
|
require('./schemas/output/ledger-event.json'),
|
||||||
require('./schemas/output/get-paths.json'),
|
require('./schemas/output/get-paths.json'),
|
||||||
@@ -71,12 +74,15 @@ function loadSchemas() {
|
|||||||
require('./schemas/output/get-transaction.json'),
|
require('./schemas/output/get-transaction.json'),
|
||||||
require('./schemas/output/get-transactions.json'),
|
require('./schemas/output/get-transactions.json'),
|
||||||
require('./schemas/output/get-trustlines.json'),
|
require('./schemas/output/get-trustlines.json'),
|
||||||
|
require('./schemas/output/sign-payment-channel-claim.json'),
|
||||||
|
require('./schemas/output/verify-payment-channel-claim.json'),
|
||||||
require('./schemas/input/get-balances.json'),
|
require('./schemas/input/get-balances.json'),
|
||||||
require('./schemas/input/get-balance-sheet.json'),
|
require('./schemas/input/get-balance-sheet.json'),
|
||||||
require('./schemas/input/get-ledger.json'),
|
require('./schemas/input/get-ledger.json'),
|
||||||
require('./schemas/input/get-orders.json'),
|
require('./schemas/input/get-orders.json'),
|
||||||
require('./schemas/input/get-orderbook.json'),
|
require('./schemas/input/get-orderbook.json'),
|
||||||
require('./schemas/input/get-paths.json'),
|
require('./schemas/input/get-paths.json'),
|
||||||
|
require('./schemas/input/get-payment-channel.json'),
|
||||||
require('./schemas/input/api-options.json'),
|
require('./schemas/input/api-options.json'),
|
||||||
require('./schemas/input/get-settings.json'),
|
require('./schemas/input/get-settings.json'),
|
||||||
require('./schemas/input/get-account-info.json'),
|
require('./schemas/input/get-account-info.json'),
|
||||||
@@ -88,35 +94,60 @@ function loadSchemas() {
|
|||||||
require('./schemas/input/prepare-trustline.json'),
|
require('./schemas/input/prepare-trustline.json'),
|
||||||
require('./schemas/input/prepare-order-cancellation.json'),
|
require('./schemas/input/prepare-order-cancellation.json'),
|
||||||
require('./schemas/input/prepare-settings.json'),
|
require('./schemas/input/prepare-settings.json'),
|
||||||
require('./schemas/input/prepare-suspended-payment-creation.json'),
|
require('./schemas/input/prepare-escrow-creation.json'),
|
||||||
require('./schemas/input/prepare-suspended-payment-cancellation.json'),
|
require('./schemas/input/prepare-escrow-cancellation.json'),
|
||||||
require('./schemas/input/prepare-suspended-payment-execution.json'),
|
require('./schemas/input/prepare-escrow-execution.json'),
|
||||||
require('./schemas/input/compute-ledger-hash'),
|
require('./schemas/input/prepare-payment-channel-create.json'),
|
||||||
|
require('./schemas/input/prepare-payment-channel-fund.json'),
|
||||||
|
require('./schemas/input/prepare-payment-channel-claim.json'),
|
||||||
|
require('./schemas/input/compute-ledger-hash.json'),
|
||||||
require('./schemas/input/sign.json'),
|
require('./schemas/input/sign.json'),
|
||||||
require('./schemas/input/submit.json'),
|
require('./schemas/input/submit.json'),
|
||||||
require('./schemas/input/generate-address.json'),
|
require('./schemas/input/generate-address.json'),
|
||||||
|
require('./schemas/input/sign-payment-channel-claim.json'),
|
||||||
|
require('./schemas/input/verify-payment-channel-claim.json'),
|
||||||
require('./schemas/input/combine.json')
|
require('./schemas/input/combine.json')
|
||||||
];
|
]
|
||||||
const titles = _.map(schemas, schema => schema.title);
|
const titles = schemas.map(schema => schema.title)
|
||||||
const duplicates = _.keys(_.pick(_.countBy(titles), count => count > 1));
|
const duplicates = _.keys(_.pickBy(_.countBy(titles), count => count > 1))
|
||||||
assert(duplicates.length === 0, 'Duplicate schemas for: ' + duplicates);
|
assert(duplicates.length === 0, 'Duplicate schemas for: ' + duplicates)
|
||||||
const ajv = new Ajv();
|
const validator = new Validator()
|
||||||
_.forEach(schemas, schema => ajv.addSchema(schema, schema.title));
|
// Register custom format validators that ignore undefined instances
|
||||||
ajv.addFormat('address', isValidAddress);
|
// since jsonschema will still call the format validator on a missing
|
||||||
ajv.addFormat('secret', isValidSecret);
|
// (optional) property
|
||||||
return ajv;
|
validator.customFormats.address = function(instance) {
|
||||||
|
if (instance === undefined) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return isValidAddress(instance)
|
||||||
|
}
|
||||||
|
validator.customFormats.secret = function(instance) {
|
||||||
|
if (instance === undefined) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return isValidSecret(instance)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Register under the root URI '/'
|
||||||
|
_.forEach(schemas, schema => validator.addSchema(schema, '/' + schema.title))
|
||||||
|
return validator
|
||||||
}
|
}
|
||||||
|
|
||||||
const ajv = loadSchemas();
|
const schemaValidator = loadSchemas()
|
||||||
|
|
||||||
function schemaValidate(schemaName: string, object: any): void {
|
function schemaValidate(schemaName: string, object: any): void {
|
||||||
const isValid = ajv.validate(schemaName, object);
|
// Lookup under the root URI '/'
|
||||||
if (!isValid) {
|
const schema = schemaValidator.getSchema('/' + schemaName)
|
||||||
throw new ValidationError(ajv.errorsText());
|
if (schema === undefined) {
|
||||||
|
throw new ValidationError('no schema for ' + schemaName)
|
||||||
|
}
|
||||||
|
const result = schemaValidator.validate(object, schema)
|
||||||
|
if (!result.valid) {
|
||||||
|
throw new ValidationError(result.errors.join())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
export {
|
||||||
schemaValidate,
|
schemaValidate,
|
||||||
isValidSecret
|
isValidSecret
|
||||||
};
|
}
|
||||||
14
src/common/schemas/input/get-payment-channel.json
Normal file
14
src/common/schemas/input/get-payment-channel.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"title": "getPaymentChannelParameters",
|
||||||
|
"description": "Parameters for getPaymentChannel",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"$ref": "hash256",
|
||||||
|
"description": "256-bit hexadecimal channel identifier."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"additionalProperties": false,
|
||||||
|
"required": ["id"]
|
||||||
|
}
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
{
|
{
|
||||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
"title": "prepareSuspendedPaymentCreationParameters",
|
"title": "prepareEscrowCancellationParameters",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"address": {
|
"address": {
|
||||||
"$ref": "address",
|
"$ref": "address",
|
||||||
"description": "The address of the account that is creating the transaction."
|
"description": "The address of the account that is creating the transaction."
|
||||||
},
|
},
|
||||||
"suspendedPaymentCreation": {
|
"escrowCancellation": {
|
||||||
"$ref": "suspendedPaymentCreation",
|
"$ref": "escrowCancellation",
|
||||||
"description": "The specification of the suspended payment creation to prepare."
|
"description": "The specification of the escrow cancellation to prepare."
|
||||||
},
|
},
|
||||||
"instructions": {"$ref": "instructions"}
|
"instructions": {"$ref": "instructions"}
|
||||||
},
|
},
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
"required": ["address", "suspendedPaymentCreation"]
|
"required": ["address", "escrowCancellation"]
|
||||||
}
|
}
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
{
|
{
|
||||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
"title": "prepareSuspendedPaymentExecutionParameters",
|
"title": "prepareEscrowCreationParameters",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"address": {
|
"address": {
|
||||||
"$ref": "address",
|
"$ref": "address",
|
||||||
"description": "The address of the account that is creating the transaction."
|
"description": "The address of the account that is creating the transaction."
|
||||||
},
|
},
|
||||||
"suspendedPaymentExecution": {
|
"escrowCreation": {
|
||||||
"$ref": "suspendedPaymentExecution",
|
"$ref": "escrowCreation",
|
||||||
"description": "The specification of the suspended payment execution to prepare."
|
"description": "The specification of the escrow creation to prepare."
|
||||||
},
|
},
|
||||||
"instructions": {"$ref": "instructions"}
|
"instructions": {"$ref": "instructions"}
|
||||||
},
|
},
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
"required": ["address", "suspendedPaymentExecution"]
|
"required": ["address", "escrowCreation"]
|
||||||
}
|
}
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
{
|
{
|
||||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
"title": "prepareSuspendedPaymentCancellationParameters",
|
"title": "prepareEscrowExecutionParameters",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"address": {
|
"address": {
|
||||||
"$ref": "address",
|
"$ref": "address",
|
||||||
"description": "The address of the account that is creating the transaction."
|
"description": "The address of the account that is creating the transaction."
|
||||||
},
|
},
|
||||||
"suspendedPaymentCancellation": {
|
"escrowExecution": {
|
||||||
"$ref": "suspendedPaymentCancellation",
|
"$ref": "escrowExecution",
|
||||||
"description": "The specification of the suspended payment cancellation to prepare."
|
"description": "The specification of the escrow execution to prepare."
|
||||||
},
|
},
|
||||||
"instructions": {"$ref": "instructions"}
|
"instructions": {"$ref": "instructions"}
|
||||||
},
|
},
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
"required": ["address", "suspendedPaymentCancellation"]
|
"required": ["address", "escrowExecution"]
|
||||||
}
|
}
|
||||||
18
src/common/schemas/input/prepare-payment-channel-claim.json
Normal file
18
src/common/schemas/input/prepare-payment-channel-claim.json
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"title": "preparePaymentChannelClaimParameters",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"address": {
|
||||||
|
"$ref": "address",
|
||||||
|
"description": "The address of the account that is creating the transaction."
|
||||||
|
},
|
||||||
|
"paymentChannelClaim": {
|
||||||
|
"$ref": "paymentChannelClaim",
|
||||||
|
"description": "Details of the channel and claim."
|
||||||
|
},
|
||||||
|
"instructions": {"$ref": "instructions"}
|
||||||
|
},
|
||||||
|
"additionalProperties": false,
|
||||||
|
"required": ["address", "paymentChannelClaim"]
|
||||||
|
}
|
||||||
18
src/common/schemas/input/prepare-payment-channel-create.json
Normal file
18
src/common/schemas/input/prepare-payment-channel-create.json
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"title": "preparePaymentChannelCreateParameters",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"address": {
|
||||||
|
"$ref": "address",
|
||||||
|
"description": "The address of the account that is creating the transaction."
|
||||||
|
},
|
||||||
|
"paymentChannelCreate": {
|
||||||
|
"$ref": "paymentChannelCreate",
|
||||||
|
"description": "The specification of the payment channel to create."
|
||||||
|
},
|
||||||
|
"instructions": {"$ref": "instructions"}
|
||||||
|
},
|
||||||
|
"additionalProperties": false,
|
||||||
|
"required": ["address", "paymentChannelCreate"]
|
||||||
|
}
|
||||||
18
src/common/schemas/input/prepare-payment-channel-fund.json
Normal file
18
src/common/schemas/input/prepare-payment-channel-fund.json
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"title": "preparePaymentChannelFundParameters",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"address": {
|
||||||
|
"$ref": "address",
|
||||||
|
"description": "The address of the account that is creating the transaction."
|
||||||
|
},
|
||||||
|
"paymentChannelFund": {
|
||||||
|
"$ref": "paymentChannelFund",
|
||||||
|
"description": "The channel to fund, and the details of how to fund it."
|
||||||
|
},
|
||||||
|
"instructions": {"$ref": "instructions"}
|
||||||
|
},
|
||||||
|
"additionalProperties": false,
|
||||||
|
"required": ["address", "paymentChannelFund"]
|
||||||
|
}
|
||||||
21
src/common/schemas/input/sign-payment-channel-claim.json
Normal file
21
src/common/schemas/input/sign-payment-channel-claim.json
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"title": "signPaymentChannelClaimParameters",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"channel": {
|
||||||
|
"$ref": "hash256",
|
||||||
|
"description": "256-bit hexadecimal channel identifier."
|
||||||
|
},
|
||||||
|
"amount": {
|
||||||
|
"$ref": "value",
|
||||||
|
"description": "Amount of XRP authorized by the claim."
|
||||||
|
},
|
||||||
|
"privateKey": {
|
||||||
|
"$ref": "publicKey",
|
||||||
|
"description": "The private key to sign the payment channel claim."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"additionalProperties": false,
|
||||||
|
"required": ["channel", "amount", "privateKey"]
|
||||||
|
}
|
||||||
25
src/common/schemas/input/verify-payment-channel-claim.json
Normal file
25
src/common/schemas/input/verify-payment-channel-claim.json
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"title": "verifyPaymentChannelClaimParameters",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"channel": {
|
||||||
|
"$ref": "hash256",
|
||||||
|
"description": "256-bit hexadecimal channel identifier."
|
||||||
|
},
|
||||||
|
"amount": {
|
||||||
|
"$ref": "value",
|
||||||
|
"description": "Amount of XRP authorized by the claim."
|
||||||
|
},
|
||||||
|
"signature": {
|
||||||
|
"$ref": "signature",
|
||||||
|
"description": "Signature of this claim."
|
||||||
|
},
|
||||||
|
"publicKey": {
|
||||||
|
"$ref": "publicKey",
|
||||||
|
"description": "Public key of the channel's sender"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"additionalProperties": false,
|
||||||
|
"required": ["channel", "amount", "signature", "publicKey"]
|
||||||
|
}
|
||||||
@@ -4,6 +4,6 @@
|
|||||||
"description": "A Ripple account address",
|
"description": "A Ripple account address",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"format": "address",
|
"format": "address",
|
||||||
"link": "ripple-address",
|
"link": "address",
|
||||||
"pattern": "^r[1-9A-HJ-NP-Za-km-z]{25,34}$"
|
"pattern": "^r[1-9A-HJ-NP-Za-km-z]{25,34}$"
|
||||||
}
|
}
|
||||||
|
|||||||
7
src/common/schemas/objects/public-key.json
Normal file
7
src/common/schemas/objects/public-key.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"title": "publicKey",
|
||||||
|
"description": "The hexadecimal representation of a secp256k1 or Ed25519 public key.",
|
||||||
|
"type": "string",
|
||||||
|
"pattern": "^[A-F0-9]+$"
|
||||||
|
}
|
||||||
7
src/common/schemas/objects/signature.json
Normal file
7
src/common/schemas/objects/signature.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"title": "signature",
|
||||||
|
"description": "The hexadecimal representation of a signature.",
|
||||||
|
"type": "string",
|
||||||
|
"pattern": "^[A-F0-9]+$"
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
"description": "The type of the transaction.",
|
"description": "The type of the transaction.",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": ["payment", "order", "orderCancellation", "trustline", "settings",
|
"enum": ["payment", "order", "orderCancellation", "trustline", "settings",
|
||||||
"suspendedPaymentCreation", "suspendedPaymentCancellation",
|
"escrowCreation", "escrowCancellation",
|
||||||
"suspendedPaymentExecution"]
|
"escrowExecution", "paymentChannelCreate",
|
||||||
|
"paymentChannelFund", "paymentChannelClaim"]
|
||||||
}
|
}
|
||||||
|
|||||||
67
src/common/schemas/output/get-payment-channel.json
Normal file
67
src/common/schemas/output/get-payment-channel.json
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"title": "getPaymentChannel",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"account": {
|
||||||
|
"$ref": "address",
|
||||||
|
"description": "Address that created the payment channel."
|
||||||
|
},
|
||||||
|
"destination": {
|
||||||
|
"$ref": "address",
|
||||||
|
"description": "Address to receive XRP claims against this channel."
|
||||||
|
},
|
||||||
|
"amount": {
|
||||||
|
"$ref": "value",
|
||||||
|
"description": "The total amount of XRP funded in this channel."
|
||||||
|
},
|
||||||
|
"balance": {
|
||||||
|
"$ref": "value",
|
||||||
|
"description": "The total amount of XRP delivered by this channel."
|
||||||
|
},
|
||||||
|
"settleDelay": {
|
||||||
|
"type": "number",
|
||||||
|
"description": "Amount of seconds the source address must wait before closing the channel if it has unclaimed XRP."
|
||||||
|
},
|
||||||
|
"expiration": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "date-time",
|
||||||
|
"description": "Time when this channel expires."
|
||||||
|
},
|
||||||
|
"publicKey": {
|
||||||
|
"$ref": "publicKey",
|
||||||
|
"description": "Public key of the key pair the source will use to sign claims against this channel."
|
||||||
|
},
|
||||||
|
"cancelAfter": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "date-time",
|
||||||
|
"description": "Time when this channel expires as specified at creation."
|
||||||
|
},
|
||||||
|
"sourceTag": {
|
||||||
|
"$ref": "tag",
|
||||||
|
"description": "Source tag."
|
||||||
|
},
|
||||||
|
"destinationTag": {
|
||||||
|
"$ref": "tag",
|
||||||
|
"description": "Destination tag."
|
||||||
|
},
|
||||||
|
"previousAffectingTransactionID": {
|
||||||
|
"$ref": "hash256",
|
||||||
|
"description": "Hash value representing the most recent transaction that affected this payment channel."
|
||||||
|
},
|
||||||
|
"previousAffectingTransactionLedgerVersion": {
|
||||||
|
"$ref": "ledgerVersion",
|
||||||
|
"description": "The ledger version that the transaction identified by the `previousAffectingTransactionID` was validated in."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"account",
|
||||||
|
"destination",
|
||||||
|
"amount",
|
||||||
|
"balance",
|
||||||
|
"settleDelay",
|
||||||
|
"previousAffectingTransactionID",
|
||||||
|
"previousAffectingTransactionLedgerVersion"
|
||||||
|
],
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
@@ -59,20 +59,38 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"properties": {
|
"properties": {
|
||||||
"type": {"enum": ["suspendedPaymentCreation"]},
|
"type": {"enum": ["escrowCreation"]},
|
||||||
"specification": {"$ref": "suspendedPaymentCreation"}
|
"specification": {"$ref": "escrowCreation"}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"properties": {
|
"properties": {
|
||||||
"type": {"enum": ["suspendedPaymentCancellation"]},
|
"type": {"enum": ["escrowCancellation"]},
|
||||||
"specification": {"$ref": "suspendedPaymentCancellation"}
|
"specification": {"$ref": "escrowCancellation"}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"properties": {
|
"properties": {
|
||||||
"type": {"enum": ["suspendedPaymentExecution"]},
|
"type": {"enum": ["escrowExecution"]},
|
||||||
"specification": {"$ref": "suspendedPaymentExecution"}
|
"specification": {"$ref": "escrowExecution"}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"properties": {
|
||||||
|
"type": {"enum": ["paymentChannelCreate"]},
|
||||||
|
"specification": {"$ref": "paymentChannelCreate"}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"properties": {
|
||||||
|
"type": {"enum": ["paymentChannelFund"]},
|
||||||
|
"specification": {"$ref": "paymentChannelFund"}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"properties": {
|
||||||
|
"type": {"enum": ["paymentChannelClaim"]},
|
||||||
|
"specification": {"$ref": "paymentChannelClaim"}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"title": "signPaymentChannelClaim",
|
||||||
|
"type": "string",
|
||||||
|
"$ref": "signature",
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"title": "verifyPaymentChannelClaim",
|
||||||
|
"type": "boolean",
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
19
src/common/schemas/specifications/escrow-cancellation.json
Normal file
19
src/common/schemas/specifications/escrow-cancellation.json
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"title": "escrowCancellation",
|
||||||
|
"link": "escrow-cancellation",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"memos": {"$ref": "memos"},
|
||||||
|
"owner": {
|
||||||
|
"$ref": "address",
|
||||||
|
"description": "The address of the owner of the escrow to cancel."
|
||||||
|
},
|
||||||
|
"escrowSequence": {
|
||||||
|
"$ref": "sequence",
|
||||||
|
"description": "The [account sequence number](#account-sequence-number) of the [Escrow Creation](#escrow-creation) transaction for the escrow to cancel."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": ["owner", "escrowSequence"],
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
42
src/common/schemas/specifications/escrow-creation.json
Normal file
42
src/common/schemas/specifications/escrow-creation.json
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"title": "escrowCreation",
|
||||||
|
"link": "escrow-creation",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"amount": {
|
||||||
|
"$ref": "value",
|
||||||
|
"description": "Amount of XRP for sender to escrow."
|
||||||
|
},
|
||||||
|
"destination": {
|
||||||
|
"$ref": "address",
|
||||||
|
"description": "Address to receive escrowed XRP."
|
||||||
|
},
|
||||||
|
"memos": {"$ref": "memos"},
|
||||||
|
"condition": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "A hex value representing a [PREIMAGE-SHA-256 crypto-condition](https://tools.ietf.org/html/draft-thomas-crypto-conditions-02#section-8.1). If present, `fulfillment` is required upon execution.",
|
||||||
|
"pattern": "^[A-F0-9]{0,256}$"
|
||||||
|
},
|
||||||
|
"allowCancelAfter": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "date-time",
|
||||||
|
"description": "If present, the escrow may be cancelled after this time."
|
||||||
|
},
|
||||||
|
"allowExecuteAfter": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "date-time",
|
||||||
|
"description": "If present, the escrow can not be executed before this time."
|
||||||
|
},
|
||||||
|
"sourceTag": {
|
||||||
|
"$ref": "tag",
|
||||||
|
"description": "Source tag."
|
||||||
|
},
|
||||||
|
"destinationTag": {
|
||||||
|
"$ref": "tag",
|
||||||
|
"description": "Destination tag."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": ["amount", "destination"],
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
29
src/common/schemas/specifications/escrow-execution.json
Normal file
29
src/common/schemas/specifications/escrow-execution.json
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"title": "escrowExecution",
|
||||||
|
"link": "escrow-execution",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"memos": {"$ref": "memos"},
|
||||||
|
"owner": {
|
||||||
|
"$ref": "address",
|
||||||
|
"description": "The address of the owner of the escrow to execute."
|
||||||
|
},
|
||||||
|
"escrowSequence": {
|
||||||
|
"$ref": "sequence",
|
||||||
|
"description": "The [account sequence number](#account-sequence-number) of the [Escrow Creation](#escrow-creation) transaction for the escrow to execute."
|
||||||
|
},
|
||||||
|
"condition": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "A hex value representing a [PREIMAGE-SHA-256 crypto-condition](https://tools.ietf.org/html/draft-thomas-crypto-conditions-02#section-8.1). This must match the original `condition` from the escrow creation transaction.",
|
||||||
|
"pattern": "^[A-F0-9]{0,256}$"
|
||||||
|
},
|
||||||
|
"fulfillment": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "A hex value representing the [PREIMAGE-SHA-256 crypto-condition](https://tools.ietf.org/html/draft-thomas-crypto-conditions-02#section-8.1) fulfillment for `condition`.",
|
||||||
|
"pattern": "^[A-F0-9]+$"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": ["owner", "escrowSequence"],
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
38
src/common/schemas/specifications/payment-channel-claim.json
Normal file
38
src/common/schemas/specifications/payment-channel-claim.json
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"title": "paymentChannelClaim",
|
||||||
|
"link": "payment-channel-claim",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"channel": {
|
||||||
|
"$ref": "hash256",
|
||||||
|
"description": "256-bit hexadecimal channel identifier."
|
||||||
|
},
|
||||||
|
"amount": {
|
||||||
|
"$ref": "value",
|
||||||
|
"description": "XRP balance of this channel after claim is processed."
|
||||||
|
},
|
||||||
|
"balance": {
|
||||||
|
"$ref": "value",
|
||||||
|
"description": "Amount of XRP authorized by signature."
|
||||||
|
},
|
||||||
|
"signature": {
|
||||||
|
"$ref": "signature",
|
||||||
|
"description": "Signature of this claim."
|
||||||
|
},
|
||||||
|
"publicKey": {
|
||||||
|
"$ref": "publicKey",
|
||||||
|
"description": "Public key of the channel's sender"
|
||||||
|
},
|
||||||
|
"renew": {
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "Clear the channel's expiration time."
|
||||||
|
},
|
||||||
|
"close": {
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "Request to close the channel."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": ["channel"],
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"title": "paymentChannelCreate",
|
||||||
|
"link": "payment-channel-create",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"amount": {
|
||||||
|
"$ref": "value",
|
||||||
|
"description": "Amount of XRP for sender to set aside in this channel."
|
||||||
|
},
|
||||||
|
"destination": {
|
||||||
|
"$ref": "address",
|
||||||
|
"description": "Address to receive XRP claims against this channel."
|
||||||
|
},
|
||||||
|
"settleDelay": {
|
||||||
|
"type": "number",
|
||||||
|
"description": "Amount of seconds the source address must wait before closing the channel if it has unclaimed XRP."
|
||||||
|
},
|
||||||
|
"publicKey": {
|
||||||
|
"$ref": "publicKey",
|
||||||
|
"description": "Public key of the key pair the source will use to sign claims against this channel."
|
||||||
|
},
|
||||||
|
"cancelAfter": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "date-time",
|
||||||
|
"description": "Time when this channel expires."
|
||||||
|
},
|
||||||
|
"sourceTag": {
|
||||||
|
"$ref": "tag",
|
||||||
|
"description": "Source tag."
|
||||||
|
},
|
||||||
|
"destinationTag": {
|
||||||
|
"$ref": "tag",
|
||||||
|
"description": "Destination tag."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": ["amount", "destination", "settleDelay", "publicKey"],
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
23
src/common/schemas/specifications/payment-channel-fund.json
Normal file
23
src/common/schemas/specifications/payment-channel-fund.json
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"title": "paymentChannelFund",
|
||||||
|
"link": "payment-channel-fund",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"amount": {
|
||||||
|
"$ref": "value",
|
||||||
|
"description": "Amount of XRP to fund the channel with."
|
||||||
|
},
|
||||||
|
"channel": {
|
||||||
|
"$ref": "hash256",
|
||||||
|
"description": "256-bit hexadecimal channel identifier."
|
||||||
|
},
|
||||||
|
"expiration": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "date-time",
|
||||||
|
"description": "New expiration for this channel."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": ["amount", "channel"],
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
{
|
|
||||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
||||||
"title": "suspendedPaymentCancellation",
|
|
||||||
"link": "suspended-payment-cancellation",
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"memos": {"$ref": "memos"},
|
|
||||||
"owner": {
|
|
||||||
"$ref": "address",
|
|
||||||
"description": "The address of the owner of the suspended payment to cancel."
|
|
||||||
},
|
|
||||||
"suspensionSequence": {
|
|
||||||
"$ref": "sequence",
|
|
||||||
"description": "The [account sequence number](#account-sequence-number) of the [Suspended Payment Creation](#suspended-payment-creation) transaction for the suspended payment to cancel."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": ["owner", "suspensionSequence"],
|
|
||||||
"additionalProperties": false
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
{
|
|
||||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
||||||
"title": "suspendedPaymentCreation",
|
|
||||||
"link": "suspended-payment-creation",
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"source": {
|
|
||||||
"$ref": "maxAdjustment",
|
|
||||||
"description": "Fields pertaining to the source of the payment."
|
|
||||||
},
|
|
||||||
"destination": {
|
|
||||||
"$ref": "destinationExactAdjustment",
|
|
||||||
"description": "Fields pertaining to the destination of the payment."
|
|
||||||
},
|
|
||||||
"memos": {"$ref": "memos"},
|
|
||||||
"digest": {
|
|
||||||
"$ref": "hash256",
|
|
||||||
"description": "If present, proof is required upon execution."
|
|
||||||
},
|
|
||||||
"allowCancelAfter": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "date-time",
|
|
||||||
"description": "If present, the suspended payment may be cancelled after this time."
|
|
||||||
},
|
|
||||||
"allowExecuteAfter": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "date-time",
|
|
||||||
"description": "If present, the suspended payment can not be executed before this time."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": ["source", "destination"],
|
|
||||||
"additionalProperties": false
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
{
|
|
||||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
||||||
"title": "suspendedPaymentExecution",
|
|
||||||
"link": "suspended-payment-execution",
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"memos": {"$ref": "memos"},
|
|
||||||
"owner": {
|
|
||||||
"$ref": "address",
|
|
||||||
"description": "The address of the owner of the suspended payment to execute."
|
|
||||||
},
|
|
||||||
"suspensionSequence": {
|
|
||||||
"$ref": "sequence",
|
|
||||||
"description": "The [account sequence number](#account-sequence-number) of the [Suspended Payment Creation](#suspended-payment-creation) transaction for the suspended payment to execute."
|
|
||||||
},
|
|
||||||
"method": {
|
|
||||||
"type": "integer",
|
|
||||||
"minimum": 0,
|
|
||||||
"maximum": 255,
|
|
||||||
"description": "The method for verifying the proof; only method `1` is supported."
|
|
||||||
},
|
|
||||||
"digest": {
|
|
||||||
"$ref": "hash256",
|
|
||||||
"description": "The original `digest` from the suspended payment creation transaction. This is sha256 hash of `proof` string. It is replicated here so that the relatively expensive hashing operation can be delegated to a server without ledger history and the server with ledger history only has to do a quick comparison of the old digest with the new digest."
|
|
||||||
},
|
|
||||||
"proof": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "A value that produces the digest when hashed. It must be 32 charaters long and contain only 8-bit characters.",
|
|
||||||
"pattern": "^[\\x00-\\xFF]{32}$"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": ["owner", "suspensionSequence"],
|
|
||||||
"additionalProperties": false
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
'use strict'; // eslint-disable-line
|
import * as _ from 'lodash'
|
||||||
const _ = require('lodash');
|
import {convertKeysFromSnakeCaseToCamelCase} from './utils'
|
||||||
const {convertKeysFromSnakeCaseToCamelCase} = require('./utils');
|
import Connection from './connection'
|
||||||
import type {Connection} from './connection';
|
|
||||||
|
|
||||||
export type GetServerInfoResponse = {
|
export type GetServerInfoResponse = {
|
||||||
buildVersion: string,
|
buildVersion: string,
|
||||||
@@ -34,46 +33,49 @@ export type GetServerInfoResponse = {
|
|||||||
|
|
||||||
function renameKeys(object, mapping) {
|
function renameKeys(object, mapping) {
|
||||||
_.forEach(mapping, (to, from) => {
|
_.forEach(mapping, (to, from) => {
|
||||||
object[to] = object[from];
|
object[to] = object[from]
|
||||||
delete object[from];
|
delete object[from]
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function getServerInfo(connection: Connection): Promise<GetServerInfoResponse> {
|
function getServerInfo(connection: Connection): Promise<GetServerInfoResponse> {
|
||||||
return connection.request({command: 'server_info'}).then(response => {
|
return connection.request({command: 'server_info'}).then(response => {
|
||||||
const info = convertKeysFromSnakeCaseToCamelCase(response.info);
|
const info = convertKeysFromSnakeCaseToCamelCase(response.info)
|
||||||
renameKeys(info, {hostid: 'hostID'});
|
renameKeys(info, {hostid: 'hostID'})
|
||||||
if (info.validatedLedger) {
|
if (info.validatedLedger) {
|
||||||
renameKeys(info.validatedLedger, {
|
renameKeys(info.validatedLedger, {
|
||||||
baseFeeXrp: 'baseFeeXRP',
|
baseFeeXrp: 'baseFeeXRP',
|
||||||
reserveBaseXrp: 'reserveBaseXRP',
|
reserveBaseXrp: 'reserveBaseXRP',
|
||||||
reserveIncXrp: 'reserveIncrementXRP',
|
reserveIncXrp: 'reserveIncrementXRP',
|
||||||
seq: 'ledgerVersion'
|
seq: 'ledgerVersion'
|
||||||
});
|
})
|
||||||
info.validatedLedger.baseFeeXRP =
|
info.validatedLedger.baseFeeXRP =
|
||||||
info.validatedLedger.baseFeeXRP.toString();
|
info.validatedLedger.baseFeeXRP.toString()
|
||||||
info.validatedLedger.reserveBaseXRP =
|
info.validatedLedger.reserveBaseXRP =
|
||||||
info.validatedLedger.reserveBaseXRP.toString();
|
info.validatedLedger.reserveBaseXRP.toString()
|
||||||
info.validatedLedger.reserveIncrementXRP =
|
info.validatedLedger.reserveIncrementXRP =
|
||||||
info.validatedLedger.reserveIncrementXRP.toString();
|
info.validatedLedger.reserveIncrementXRP.toString()
|
||||||
}
|
}
|
||||||
return info;
|
return info
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: This was originally annotated to return a number, but actually
|
||||||
|
// returned a toString'ed number. Should this actually be returning a number?
|
||||||
function computeFeeFromServerInfo(cushion: number,
|
function computeFeeFromServerInfo(cushion: number,
|
||||||
serverInfo: GetServerInfoResponse
|
serverInfo: GetServerInfoResponse
|
||||||
): number {
|
): string {
|
||||||
return (Number(serverInfo.validatedLedger.baseFeeXRP)
|
return (Number(serverInfo.validatedLedger.baseFeeXRP)
|
||||||
* Number(serverInfo.loadFactor) * cushion).toString();
|
* Number(serverInfo.loadFactor) * cushion).toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFee(connection: Connection, cushion: number) {
|
function getFee(connection: Connection, cushion: number): Promise<string> {
|
||||||
return getServerInfo(connection).then(
|
return getServerInfo(connection).then(serverInfo => {
|
||||||
_.partial(computeFeeFromServerInfo, cushion));
|
return computeFeeFromServerInfo(cushion, serverInfo)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
export {
|
||||||
getServerInfo,
|
getServerInfo,
|
||||||
getFee
|
getFee
|
||||||
};
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const txFlags = {
|
const txFlags = {
|
||||||
// Universal flags can apply to any transaction type
|
// Universal flags can apply to any transaction type
|
||||||
@@ -35,8 +35,13 @@ const txFlags = {
|
|||||||
NoRippleDirect: 0x00010000,
|
NoRippleDirect: 0x00010000,
|
||||||
PartialPayment: 0x00020000,
|
PartialPayment: 0x00020000,
|
||||||
LimitQuality: 0x00040000
|
LimitQuality: 0x00040000
|
||||||
|
},
|
||||||
|
|
||||||
|
PaymentChannelClaim: {
|
||||||
|
Renew: 0x00010000,
|
||||||
|
Close: 0x00020000
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
// The following are integer (as opposed to bit) flags
|
// The following are integer (as opposed to bit) flags
|
||||||
// that can be set for particular transactions in the
|
// that can be set for particular transactions in the
|
||||||
@@ -52,9 +57,9 @@ const txFlagIndices = {
|
|||||||
asfGlobalFreeze: 7,
|
asfGlobalFreeze: 7,
|
||||||
asfDefaultRipple: 8
|
asfDefaultRipple: 8
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
module.exports = {
|
export {
|
||||||
txFlags,
|
txFlags,
|
||||||
txFlagIndices
|
txFlagIndices
|
||||||
};
|
}
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
/* @flow */
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
export type RippledAmountIOU = {
|
export type RippledAmountIOU = {
|
||||||
currency: string,
|
currency: string,
|
||||||
@@ -13,6 +11,7 @@ export type RippledAmount = string | RippledAmountIOU
|
|||||||
export type Amount = {
|
export type Amount = {
|
||||||
value: string,
|
value: string,
|
||||||
currency: string,
|
currency: string,
|
||||||
|
issuer?: string,
|
||||||
counterparty?: string
|
counterparty?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,12 +20,14 @@ export type Amount = {
|
|||||||
export type LaxLaxAmount = {
|
export type LaxLaxAmount = {
|
||||||
currency: string,
|
currency: string,
|
||||||
value?: string,
|
value?: string,
|
||||||
|
issuer?: string,
|
||||||
counterparty?: string
|
counterparty?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
// A currency-counterparty pair, or just currency if it's XRP
|
// A currency-counterparty pair, or just currency if it's XRP
|
||||||
export type Issue = {
|
export type Issue = {
|
||||||
currency: string,
|
currency: string,
|
||||||
|
issuer?: string,
|
||||||
counterparty?: string
|
counterparty?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,3 +54,10 @@ export type Memo = {
|
|||||||
format?: string,
|
format?: string,
|
||||||
data?: string
|
data?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type ApiMemo = {
|
||||||
|
MemoData?: string,
|
||||||
|
MemoType?: string,
|
||||||
|
MemoFormat?: string
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,59 +1,57 @@
|
|||||||
/* @flow */
|
import * as _ from 'lodash'
|
||||||
'use strict';
|
import BigNumber from 'bignumber.js'
|
||||||
const _ = require('lodash');
|
const {deriveKeypair} = require('ripple-keypairs')
|
||||||
const BigNumber = require('bignumber.js');
|
|
||||||
const {deriveKeypair} = require('ripple-keypairs');
|
|
||||||
|
|
||||||
import type {Amount, RippledAmount} from './types.js';
|
import {Amount, RippledAmount} from './types'
|
||||||
|
|
||||||
function isValidSecret(secret: string): boolean {
|
function isValidSecret(secret: string): boolean {
|
||||||
try {
|
try {
|
||||||
deriveKeypair(secret);
|
deriveKeypair(secret)
|
||||||
return true;
|
return true
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return false;
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function dropsToXrp(drops: string): string {
|
function dropsToXrp(drops: string): string {
|
||||||
return (new BigNumber(drops)).dividedBy(1000000.0).toString();
|
return (new BigNumber(drops)).dividedBy(1000000.0).toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
function xrpToDrops(xrp: string): string {
|
function xrpToDrops(xrp: string): string {
|
||||||
return (new BigNumber(xrp)).times(1000000.0).floor().toString();
|
return (new BigNumber(xrp)).times(1000000.0).floor().toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
function toRippledAmount(amount: Amount): RippledAmount {
|
function toRippledAmount(amount: Amount): RippledAmount {
|
||||||
if (amount.currency === 'XRP') {
|
if (amount.currency === 'XRP') {
|
||||||
return xrpToDrops(amount.value);
|
return xrpToDrops(amount.value)
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
currency: amount.currency,
|
currency: amount.currency,
|
||||||
issuer: amount.counterparty ? amount.counterparty :
|
issuer: amount.counterparty ? amount.counterparty :
|
||||||
(amount.issuer ? amount.issuer : undefined),
|
(amount.issuer ? amount.issuer : undefined),
|
||||||
value: amount.value
|
value: amount.value
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function convertKeysFromSnakeCaseToCamelCase(obj: any): any {
|
function convertKeysFromSnakeCaseToCamelCase(obj: any): any {
|
||||||
if (typeof obj === 'object') {
|
if (typeof obj === 'object') {
|
||||||
let newKey;
|
let newKey
|
||||||
return _.reduce(obj, (result, value, key) => {
|
return _.reduce(obj, (result, value, key) => {
|
||||||
newKey = key;
|
newKey = key
|
||||||
// taking this out of function leads to error in PhantomJS
|
// taking this out of function leads to error in PhantomJS
|
||||||
const FINDSNAKE = /([a-zA-Z]_[a-zA-Z])/g;
|
const FINDSNAKE = /([a-zA-Z]_[a-zA-Z])/g
|
||||||
if (FINDSNAKE.test(key)) {
|
if (FINDSNAKE.test(key)) {
|
||||||
newKey = key.replace(FINDSNAKE, r => r[0] + r[2].toUpperCase());
|
newKey = key.replace(FINDSNAKE, r => r[0] + r[2].toUpperCase())
|
||||||
}
|
}
|
||||||
result[newKey] = convertKeysFromSnakeCaseToCamelCase(value);
|
result[newKey] = convertKeysFromSnakeCaseToCamelCase(value)
|
||||||
return result;
|
return result
|
||||||
}, {});
|
}, {})
|
||||||
}
|
}
|
||||||
return obj;
|
return obj
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeUndefined(obj: Object): Object {
|
function removeUndefined<T extends object>(obj: T): T {
|
||||||
return _.omit(obj, _.isUndefined);
|
return _.omitBy(obj, _.isUndefined) as T
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,7 +60,7 @@ function removeUndefined(obj: Object): Object {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function rippleToUnixTimestamp(rpepoch: number): number {
|
function rippleToUnixTimestamp(rpepoch: number): number {
|
||||||
return (rpepoch + 0x386D4380) * 1000;
|
return (rpepoch + 0x386D4380) * 1000
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -70,18 +68,18 @@ function rippleToUnixTimestamp(rpepoch: number): number {
|
|||||||
* @return {Number} seconds since ripple epoch ( 1/1/2000 GMT)
|
* @return {Number} seconds since ripple epoch ( 1/1/2000 GMT)
|
||||||
*/
|
*/
|
||||||
function unixToRippleTimestamp(timestamp: number): number {
|
function unixToRippleTimestamp(timestamp: number): number {
|
||||||
return Math.round(timestamp / 1000) - 0x386D4380;
|
return Math.round(timestamp / 1000) - 0x386D4380
|
||||||
}
|
}
|
||||||
|
|
||||||
function rippleTimeToISO8601(rippleTime: number): string {
|
function rippleTimeToISO8601(rippleTime: number): string {
|
||||||
return new Date(rippleToUnixTimestamp(rippleTime)).toISOString();
|
return new Date(rippleToUnixTimestamp(rippleTime)).toISOString()
|
||||||
}
|
}
|
||||||
|
|
||||||
function iso8601ToRippleTime(iso8601: string): number {
|
function iso8601ToRippleTime(iso8601: string): number {
|
||||||
return unixToRippleTimestamp(Date.parse(iso8601));
|
return unixToRippleTimestamp(Date.parse(iso8601))
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
export {
|
||||||
dropsToXrp,
|
dropsToXrp,
|
||||||
xrpToDrops,
|
xrpToDrops,
|
||||||
toRippledAmount,
|
toRippledAmount,
|
||||||
@@ -90,4 +88,5 @@ module.exports = {
|
|||||||
rippleTimeToISO8601,
|
rippleTimeToISO8601,
|
||||||
iso8601ToRippleTime,
|
iso8601ToRippleTime,
|
||||||
isValidSecret
|
isValidSecret
|
||||||
};
|
}
|
||||||
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
/* @flow */
|
|
||||||
'use strict';
|
|
||||||
const _ = require('lodash');
|
|
||||||
const ValidationError = require('./errors').ValidationError;
|
|
||||||
const schemaValidate = require('./schema-validator').schemaValidate;
|
|
||||||
|
|
||||||
function error(text) {
|
|
||||||
return new ValidationError(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
function validateLedgerRange(options) {
|
|
||||||
if (!_.isUndefined(options) && !_.isUndefined(options.minLedgerVersion)
|
|
||||||
&& !_.isUndefined(options.maxLedgerVersion)) {
|
|
||||||
if (Number(options.minLedgerVersion) > Number(options.maxLedgerVersion)) {
|
|
||||||
throw error('minLedgerVersion must not be greater than maxLedgerVersion');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function validateOptions(schema, instance) {
|
|
||||||
schemaValidate(schema, instance);
|
|
||||||
validateLedgerRange(instance.options);
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
getPaths: _.partial(schemaValidate, 'getPathsParameters'),
|
|
||||||
getTransactions: _.partial(validateOptions, 'getTransactionsParameters'),
|
|
||||||
getSettings: _.partial(validateOptions, 'getSettingsParameters'),
|
|
||||||
getAccountInfo: _.partial(validateOptions, 'getAccountInfoParameters'),
|
|
||||||
getTrustlines: _.partial(validateOptions, 'getTrustlinesParameters'),
|
|
||||||
getBalances: _.partial(validateOptions, 'getBalancesParameters'),
|
|
||||||
getBalanceSheet: _.partial(validateOptions, 'getBalanceSheetParameters'),
|
|
||||||
getOrders: _.partial(validateOptions, 'getOrdersParameters'),
|
|
||||||
getOrderbook: _.partial(validateOptions, 'getOrderbookParameters'),
|
|
||||||
getTransaction: _.partial(validateOptions, 'getTransactionParameters'),
|
|
||||||
getLedger: _.partial(validateOptions, 'getLedgerParameters'),
|
|
||||||
preparePayment: _.partial(schemaValidate, 'preparePaymentParameters'),
|
|
||||||
prepareOrder: _.partial(schemaValidate, 'prepareOrderParameters'),
|
|
||||||
prepareOrderCancellation:
|
|
||||||
_.partial(schemaValidate, 'prepareOrderCancellationParameters'),
|
|
||||||
prepareTrustline: _.partial(schemaValidate, 'prepareTrustlineParameters'),
|
|
||||||
prepareSettings: _.partial(schemaValidate, 'prepareSettingsParameters'),
|
|
||||||
prepareSuspendedPaymentCreation: _.partial(schemaValidate,
|
|
||||||
'prepareSuspendedPaymentCreationParameters'),
|
|
||||||
prepareSuspendedPaymentCancellation: _.partial(schemaValidate,
|
|
||||||
'prepareSuspendedPaymentCancellationParameters'),
|
|
||||||
prepareSuspendedPaymentExecution: _.partial(schemaValidate,
|
|
||||||
'prepareSuspendedPaymentExecutionParameters'),
|
|
||||||
sign: _.partial(schemaValidate, 'signParameters'),
|
|
||||||
combine: _.partial(schemaValidate, 'combineParameters'),
|
|
||||||
submit: _.partial(schemaValidate, 'submitParameters'),
|
|
||||||
computeLedgerHash: _.partial(schemaValidate, 'computeLedgerHashParameters'),
|
|
||||||
generateAddress: _.partial(schemaValidate, 'generateAddressParameters'),
|
|
||||||
apiOptions: _.partial(schemaValidate, 'api-options'),
|
|
||||||
instructions: _.partial(schemaValidate, 'instructions')
|
|
||||||
};
|
|
||||||
117
src/common/validate.ts
Normal file
117
src/common/validate.ts
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
import * as _ from 'lodash'
|
||||||
|
import {ValidationError} from './errors'
|
||||||
|
import {schemaValidate} from './schema-validator'
|
||||||
|
|
||||||
|
function error(text) {
|
||||||
|
return new ValidationError(text)
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateLedgerRange(options) {
|
||||||
|
if (!_.isUndefined(options) && !_.isUndefined(options.minLedgerVersion)
|
||||||
|
&& !_.isUndefined(options.maxLedgerVersion)) {
|
||||||
|
if (Number(options.minLedgerVersion) > Number(options.maxLedgerVersion)) {
|
||||||
|
throw error('minLedgerVersion must not be greater than maxLedgerVersion')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateOptions(schema, instance) {
|
||||||
|
schemaValidate(schema, instance)
|
||||||
|
validateLedgerRange(instance.options)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getPaths =
|
||||||
|
_.partial(schemaValidate, 'getPathsParameters')
|
||||||
|
|
||||||
|
export const getTransactions =
|
||||||
|
_.partial(validateOptions, 'getTransactionsParameters')
|
||||||
|
|
||||||
|
export const getSettings =
|
||||||
|
_.partial(validateOptions, 'getSettingsParameters')
|
||||||
|
|
||||||
|
export const getAccountInfo =
|
||||||
|
_.partial(validateOptions, 'getAccountInfoParameters')
|
||||||
|
|
||||||
|
export const getTrustlines =
|
||||||
|
_.partial(validateOptions, 'getTrustlinesParameters')
|
||||||
|
|
||||||
|
export const getBalances =
|
||||||
|
_.partial(validateOptions, 'getBalancesParameters')
|
||||||
|
|
||||||
|
export const getBalanceSheet =
|
||||||
|
_.partial(validateOptions, 'getBalanceSheetParameters')
|
||||||
|
|
||||||
|
export const getOrders =
|
||||||
|
_.partial(validateOptions, 'getOrdersParameters')
|
||||||
|
|
||||||
|
export const getOrderbook =
|
||||||
|
_.partial(validateOptions, 'getOrderbookParameters')
|
||||||
|
|
||||||
|
export const getTransaction =
|
||||||
|
_.partial(validateOptions, 'getTransactionParameters')
|
||||||
|
|
||||||
|
export const getPaymentChannel =
|
||||||
|
_.partial(validateOptions, 'getPaymentChannelParameters')
|
||||||
|
|
||||||
|
export const getLedger =
|
||||||
|
_.partial(validateOptions, 'getLedgerParameters')
|
||||||
|
|
||||||
|
export const preparePayment =
|
||||||
|
_.partial(schemaValidate, 'preparePaymentParameters')
|
||||||
|
|
||||||
|
export const prepareOrder =
|
||||||
|
_.partial(schemaValidate, 'prepareOrderParameters')
|
||||||
|
|
||||||
|
export const prepareOrderCancellation =
|
||||||
|
_.partial(schemaValidate, 'prepareOrderCancellationParameters')
|
||||||
|
|
||||||
|
export const prepareTrustline =
|
||||||
|
_.partial(schemaValidate, 'prepareTrustlineParameters')
|
||||||
|
|
||||||
|
export const prepareSettings =
|
||||||
|
_.partial(schemaValidate, 'prepareSettingsParameters')
|
||||||
|
|
||||||
|
export const prepareEscrowCreation =
|
||||||
|
_.partial(schemaValidate, 'prepareEscrowCreationParameters')
|
||||||
|
|
||||||
|
export const prepareEscrowCancellation =
|
||||||
|
_.partial(schemaValidate, 'prepareEscrowCancellationParameters')
|
||||||
|
|
||||||
|
export const prepareEscrowExecution =
|
||||||
|
_.partial(schemaValidate, 'prepareEscrowExecutionParameters')
|
||||||
|
|
||||||
|
export const preparePaymentChannelCreate =
|
||||||
|
_.partial(schemaValidate, 'preparePaymentChannelCreateParameters')
|
||||||
|
|
||||||
|
export const preparePaymentChannelFund =
|
||||||
|
_.partial(schemaValidate, 'preparePaymentChannelFundParameters')
|
||||||
|
|
||||||
|
export const preparePaymentChannelClaim =
|
||||||
|
_.partial(schemaValidate, 'preparePaymentChannelClaimParameters')
|
||||||
|
|
||||||
|
export const sign =
|
||||||
|
_.partial(schemaValidate, 'signParameters')
|
||||||
|
|
||||||
|
export const combine =
|
||||||
|
_.partial(schemaValidate, 'combineParameters')
|
||||||
|
|
||||||
|
export const submit =
|
||||||
|
_.partial(schemaValidate, 'submitParameters')
|
||||||
|
|
||||||
|
export const computeLedgerHash =
|
||||||
|
_.partial(schemaValidate, 'computeLedgerHashParameters')
|
||||||
|
|
||||||
|
export const generateAddress =
|
||||||
|
_.partial(schemaValidate, 'generateAddressParameters')
|
||||||
|
|
||||||
|
export const signPaymentChannelClaim =
|
||||||
|
_.partial(schemaValidate, 'signPaymentChannelClaimParameters')
|
||||||
|
|
||||||
|
export const verifyPaymentChannelClaim =
|
||||||
|
_.partial(schemaValidate, 'verifyPaymentChannelClaimParameters')
|
||||||
|
|
||||||
|
export const apiOptions =
|
||||||
|
_.partial(schemaValidate, 'api-options')
|
||||||
|
|
||||||
|
export const instructions =
|
||||||
|
_.partial(schemaValidate, 'instructions')
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const {EventEmitter} = require('events');
|
|
||||||
|
|
||||||
function unsused() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides `EventEmitter` interface for native browser `WebSocket`,
|
|
||||||
* same, as `ws` package provides.
|
|
||||||
*/
|
|
||||||
class WSWrapper extends EventEmitter {
|
|
||||||
constructor(url, protocols = null, websocketOptions = {}) {
|
|
||||||
super();
|
|
||||||
unsused(protocols);
|
|
||||||
unsused(websocketOptions);
|
|
||||||
this.setMaxListeners(Infinity);
|
|
||||||
|
|
||||||
this._ws = new WebSocket(url);
|
|
||||||
|
|
||||||
this._ws.onclose = () => {
|
|
||||||
this.emit('close');
|
|
||||||
};
|
|
||||||
|
|
||||||
this._ws.onopen = () => {
|
|
||||||
this.emit('open');
|
|
||||||
};
|
|
||||||
|
|
||||||
this._ws.onerror = error => {
|
|
||||||
this.emit('error', error);
|
|
||||||
};
|
|
||||||
|
|
||||||
this._ws.onmessage = message => {
|
|
||||||
this.emit('message', message.data);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
close() {
|
|
||||||
if (this.readyState === 1) {
|
|
||||||
this._ws.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
send(message) {
|
|
||||||
this._ws.send(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
get readyState() {
|
|
||||||
return this._ws.readyState;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
WSWrapper.CONNECTING = 0;
|
|
||||||
WSWrapper.OPEN = 1;
|
|
||||||
WSWrapper.CLOSING = 2;
|
|
||||||
WSWrapper.CLOSED = 3;
|
|
||||||
|
|
||||||
module.exports = WSWrapper;
|
|
||||||
|
|
||||||
67
src/common/wswrapper.ts
Normal file
67
src/common/wswrapper.ts
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
import {EventEmitter} from 'events'
|
||||||
|
|
||||||
|
// Define the global WebSocket class found on the native browser
|
||||||
|
declare class WebSocket {
|
||||||
|
onclose?: Function
|
||||||
|
onopen?: Function
|
||||||
|
onerror?: Function
|
||||||
|
onmessage?: Function
|
||||||
|
readyState: number
|
||||||
|
constructor(url: string)
|
||||||
|
close()
|
||||||
|
send(message: string)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides `EventEmitter` interface for native browser `WebSocket`,
|
||||||
|
* same, as `ws` package provides.
|
||||||
|
*/
|
||||||
|
class WSWrapper extends EventEmitter {
|
||||||
|
|
||||||
|
private _ws: WebSocket
|
||||||
|
static CONNECTING = 0
|
||||||
|
static OPEN = 1
|
||||||
|
static CLOSING = 2
|
||||||
|
static CLOSED = 3
|
||||||
|
|
||||||
|
constructor(url, _protocols: any, _websocketOptions: any) {
|
||||||
|
super()
|
||||||
|
this.setMaxListeners(Infinity)
|
||||||
|
|
||||||
|
this._ws = new WebSocket(url)
|
||||||
|
|
||||||
|
this._ws.onclose = () => {
|
||||||
|
this.emit('close')
|
||||||
|
}
|
||||||
|
|
||||||
|
this._ws.onopen = () => {
|
||||||
|
this.emit('open')
|
||||||
|
}
|
||||||
|
|
||||||
|
this._ws.onerror = error => {
|
||||||
|
this.emit('error', error)
|
||||||
|
}
|
||||||
|
|
||||||
|
this._ws.onmessage = message => {
|
||||||
|
this.emit('message', message.data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
close() {
|
||||||
|
if (this.readyState === 1) {
|
||||||
|
this._ws.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
send(message) {
|
||||||
|
this._ws.send(message)
|
||||||
|
}
|
||||||
|
|
||||||
|
get readyState() {
|
||||||
|
return this._ws.readyState
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export = WSWrapper
|
||||||
|
|
||||||
@@ -1,86 +1,84 @@
|
|||||||
/* eslint-disable new-cap */
|
/* eslint-disable new-cap */
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const assert = require('assert');
|
import * as assert from 'assert'
|
||||||
const _ = require('lodash');
|
import * as _ from 'lodash'
|
||||||
const jayson = require('jayson');
|
import jayson from 'jayson'
|
||||||
|
import {RippleAPI} from './api'
|
||||||
const RippleAPI = require('./api').RippleAPI;
|
|
||||||
|
|
||||||
|
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
function createHTTPServer(options, httpPort) {
|
function createHTTPServer(options, httpPort) {
|
||||||
const rippleAPI = new RippleAPI(options);
|
const rippleAPI = new RippleAPI(options)
|
||||||
|
|
||||||
const methodNames = _.filter(_.keys(RippleAPI.prototype), k => {
|
const methodNames = _.filter(_.keys(RippleAPI.prototype), k => {
|
||||||
return typeof RippleAPI.prototype[k] === 'function'
|
return typeof RippleAPI.prototype[k] === 'function'
|
||||||
&& k !== 'connect'
|
&& k !== 'connect'
|
||||||
&& k !== 'disconnect'
|
&& k !== 'disconnect'
|
||||||
&& k !== 'constructor'
|
&& k !== 'constructor'
|
||||||
&& k !== 'RippleAPI';
|
&& k !== 'RippleAPI'
|
||||||
});
|
})
|
||||||
|
|
||||||
function applyPromiseWithCallback(fnName, callback, args_) {
|
function applyPromiseWithCallback(fnName, callback, args_) {
|
||||||
try {
|
try {
|
||||||
let args = args_;
|
let args = args_
|
||||||
if (!_.isArray(args_)) {
|
if (!_.isArray(args_)) {
|
||||||
const fnParameters = jayson.Utils.getParameterNames(rippleAPI[fnName]);
|
const fnParameters = jayson.Utils.getParameterNames(rippleAPI[fnName])
|
||||||
args = fnParameters.map(name => args_[name]);
|
args = fnParameters.map(name => args_[name])
|
||||||
const defaultArgs = _.omit(args_, fnParameters);
|
const defaultArgs = _.omit(args_, fnParameters)
|
||||||
assert(_.size(defaultArgs) <= 1,
|
assert(_.size(defaultArgs) <= 1,
|
||||||
'Function must have no more than one default argument');
|
'Function must have no more than one default argument')
|
||||||
if (_.size(defaultArgs) > 0) {
|
if (_.size(defaultArgs) > 0) {
|
||||||
args.push(defaultArgs[_.keys(defaultArgs)[0]]);
|
args.push(defaultArgs[_.keys(defaultArgs)[0]])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Promise.resolve(rippleAPI[fnName].apply(rippleAPI, args))
|
Promise.resolve(rippleAPI[fnName](...args))
|
||||||
.then(res => callback(null, res))
|
.then(res => callback(null, res))
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
callback({code: 99, message: err.message, data: {name: err.name}});
|
callback({code: 99, message: err.message, data: {name: err.name}})
|
||||||
});
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
callback({code: 99, message: err.message, data: {name: err.name}});
|
callback({code: 99, message: err.message, data: {name: err.name}})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const methods = {};
|
const methods = {}
|
||||||
_.forEach(methodNames, fn => {
|
_.forEach(methodNames, fn => {
|
||||||
methods[fn] = jayson.Method((args, cb) => {
|
methods[fn] = jayson.Method((args, cb) => {
|
||||||
applyPromiseWithCallback(fn, cb, args);
|
applyPromiseWithCallback(fn, cb, args)
|
||||||
}, {collect: true});
|
}, {collect: true})
|
||||||
});
|
})
|
||||||
|
|
||||||
const server = jayson.server(methods);
|
const server = jayson.server(methods)
|
||||||
let httpServer = null;
|
let httpServer = null
|
||||||
|
|
||||||
return {
|
return {
|
||||||
server: server,
|
server: server,
|
||||||
start: function() {
|
start: function() {
|
||||||
if (httpServer !== null) {
|
if (httpServer !== null) {
|
||||||
return Promise.reject('Already started');
|
return Promise.reject('Already started')
|
||||||
}
|
}
|
||||||
return new Promise((resolve) => {
|
return new Promise(resolve => {
|
||||||
rippleAPI.connect().then(() => {
|
rippleAPI.connect().then(() => {
|
||||||
httpServer = server.http();
|
httpServer = server.http()
|
||||||
httpServer.listen(httpPort, resolve);
|
httpServer.listen(httpPort, resolve)
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
},
|
},
|
||||||
stop: function() {
|
stop: function() {
|
||||||
if (httpServer === null) {
|
if (httpServer === null) {
|
||||||
return Promise.reject('Not started');
|
return Promise.reject('Not started')
|
||||||
}
|
}
|
||||||
return new Promise((resolve) => {
|
return new Promise(resolve => {
|
||||||
rippleAPI.disconnect();
|
rippleAPI.disconnect()
|
||||||
httpServer.close(() => {
|
httpServer.close(() => {
|
||||||
httpServer = null;
|
httpServer = null
|
||||||
resolve();
|
resolve()
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
export {
|
||||||
createHTTPServer
|
createHTTPServer
|
||||||
};
|
}
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
RippleAPI: require('./api').RippleAPI,
|
|
||||||
// Broadcast api is experimental
|
|
||||||
RippleAPIBroadcast: require('./broadcast').RippleAPIBroadcast,
|
|
||||||
// HTTP server is experimental
|
|
||||||
createHTTPServer: require('./http').createHTTPServer
|
|
||||||
};
|
|
||||||
5
src/index.ts
Normal file
5
src/index.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
|
||||||
|
export {RippleAPI} from './api'
|
||||||
|
// Broadcast api is experimental
|
||||||
|
export {RippleAPIBroadcast} from './broadcast'
|
||||||
@@ -1,8 +1,4 @@
|
|||||||
/* @flow */
|
import {validate, removeUndefined, dropsToXrp} from '../common'
|
||||||
|
|
||||||
'use strict';
|
|
||||||
const utils = require('./utils');
|
|
||||||
const {validate, removeUndefined} = utils.common;
|
|
||||||
|
|
||||||
type AccountData = {
|
type AccountData = {
|
||||||
Sequence: number,
|
Sequence: number,
|
||||||
@@ -39,28 +35,28 @@ type AccountInfoResponse = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function formatAccountInfo(response: AccountDataResponse) {
|
function formatAccountInfo(response: AccountDataResponse) {
|
||||||
const data = response.account_data;
|
const data = response.account_data
|
||||||
return removeUndefined({
|
return removeUndefined({
|
||||||
sequence: data.Sequence,
|
sequence: data.Sequence,
|
||||||
xrpBalance: utils.common.dropsToXrp(data.Balance),
|
xrpBalance: dropsToXrp(data.Balance),
|
||||||
ownerCount: data.OwnerCount,
|
ownerCount: data.OwnerCount,
|
||||||
previousInitiatedTransactionID: data.AccountTxnID,
|
previousInitiatedTransactionID: data.AccountTxnID,
|
||||||
previousAffectingTransactionID: data.PreviousTxnID,
|
previousAffectingTransactionID: data.PreviousTxnID,
|
||||||
previousAffectingTransactionLedgerVersion: data.PreviousTxnLgrSeq
|
previousAffectingTransactionLedgerVersion: data.PreviousTxnLgrSeq
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAccountInfo(address: string, options: AccountInfoOptions = {}
|
function getAccountInfo(address: string, options: AccountInfoOptions = {}
|
||||||
): Promise<AccountInfoResponse> {
|
): Promise<AccountInfoResponse> {
|
||||||
validate.getAccountInfo({address, options});
|
validate.getAccountInfo({address, options})
|
||||||
|
|
||||||
const request = {
|
const request = {
|
||||||
command: 'account_info',
|
command: 'account_info',
|
||||||
account: address,
|
account: address,
|
||||||
ledger_index: options.ledgerVersion || 'validated'
|
ledger_index: options.ledgerVersion || 'validated'
|
||||||
};
|
}
|
||||||
|
|
||||||
return this.connection.request(request).then(formatAccountInfo);
|
return this.connection.request(request).then(formatAccountInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = getAccountInfo;
|
export default getAccountInfo
|
||||||
@@ -1,10 +1,7 @@
|
|||||||
/* @flow */
|
import * as _ from 'lodash'
|
||||||
'use strict';
|
import * as utils from './utils'
|
||||||
|
import {validate} from '../common'
|
||||||
const _ = require('lodash');
|
import {Amount} from '../common/types'
|
||||||
const utils = require('./utils');
|
|
||||||
const {validate} = utils.common;
|
|
||||||
import type {Amount} from '../common/types.js';
|
|
||||||
|
|
||||||
type BalanceSheetOptions = {
|
type BalanceSheetOptions = {
|
||||||
excludeAddresses?: Array<string>,
|
excludeAddresses?: Array<string>,
|
||||||
@@ -21,35 +18,37 @@ type GetBalanceSheet = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function formatBalanceSheet(balanceSheet): GetBalanceSheet {
|
function formatBalanceSheet(balanceSheet): GetBalanceSheet {
|
||||||
const result = {};
|
const result: GetBalanceSheet = {}
|
||||||
|
|
||||||
if (!_.isUndefined(balanceSheet.balances)) {
|
if (!_.isUndefined(balanceSheet.balances)) {
|
||||||
result.balances = [];
|
result.balances = []
|
||||||
_.forEach(balanceSheet.balances, (balances, counterparty) => {
|
_.forEach(balanceSheet.balances, (balances, counterparty) => {
|
||||||
_.forEach(balances, (balance) => {
|
_.forEach(balances, balance => {
|
||||||
result.balances.push(Object.assign({counterparty}, balance));
|
result.balances.push(Object.assign({counterparty}, balance))
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
if (!_.isUndefined(balanceSheet.assets)) {
|
if (!_.isUndefined(balanceSheet.assets)) {
|
||||||
result.assets = [];
|
result.assets = []
|
||||||
_.forEach(balanceSheet.assets, (assets, counterparty) => {
|
_.forEach(balanceSheet.assets, (assets, counterparty) => {
|
||||||
_.forEach(assets, (balance) => {
|
_.forEach(assets, balance => {
|
||||||
result.assets.push(Object.assign({counterparty}, balance));
|
result.assets.push(Object.assign({counterparty}, balance))
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
if (!_.isUndefined(balanceSheet.obligations)) {
|
if (!_.isUndefined(balanceSheet.obligations)) {
|
||||||
result.obligations = _.map(balanceSheet.obligations, (value, currency) =>
|
result.obligations = _.map(
|
||||||
({currency, value}));
|
balanceSheet.obligations as {[key: string]: string},
|
||||||
|
(value, currency) => ({currency, value})
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
function getBalanceSheet(address: string, options: BalanceSheetOptions = {}
|
function getBalanceSheet(address: string, options: BalanceSheetOptions = {}
|
||||||
): Promise<GetBalanceSheet> {
|
): Promise<GetBalanceSheet> {
|
||||||
validate.getBalanceSheet({address, options});
|
validate.getBalanceSheet({address, options})
|
||||||
|
|
||||||
return utils.ensureLedgerVersion.call(this, options).then(_options => {
|
return utils.ensureLedgerVersion.call(this, options).then(_options => {
|
||||||
const request = {
|
const request = {
|
||||||
@@ -58,10 +57,10 @@ function getBalanceSheet(address: string, options: BalanceSheetOptions = {}
|
|||||||
strict: true,
|
strict: true,
|
||||||
hotwallet: _options.excludeAddresses,
|
hotwallet: _options.excludeAddresses,
|
||||||
ledger_index: _options.ledgerVersion
|
ledger_index: _options.ledgerVersion
|
||||||
};
|
}
|
||||||
|
|
||||||
return this.connection.request(request).then(formatBalanceSheet);
|
return this.connection.request(request).then(formatBalanceSheet)
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = getBalanceSheet;
|
export default getBalanceSheet
|
||||||
@@ -1,9 +1,7 @@
|
|||||||
/* @flow */
|
import * as utils from './utils'
|
||||||
'use strict';
|
import {validate} from '../common'
|
||||||
const utils = require('./utils');
|
import {Connection} from '../common'
|
||||||
const {validate} = utils.common;
|
import {TrustlinesOptions, Trustline} from './trustlines-types'
|
||||||
import type {Connection} from '../common/connection.js';
|
|
||||||
import type {TrustlinesOptions, Trustline} from './trustlines-types.js';
|
|
||||||
|
|
||||||
|
|
||||||
type Balance = {
|
type Balance = {
|
||||||
@@ -19,38 +17,38 @@ function getTrustlineBalanceAmount(trustline: Trustline) {
|
|||||||
currency: trustline.specification.currency,
|
currency: trustline.specification.currency,
|
||||||
counterparty: trustline.specification.counterparty,
|
counterparty: trustline.specification.counterparty,
|
||||||
value: trustline.state.balance
|
value: trustline.state.balance
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatBalances(options, balances) {
|
function formatBalances(options, balances) {
|
||||||
const result = balances.trustlines.map(getTrustlineBalanceAmount);
|
const result = balances.trustlines.map(getTrustlineBalanceAmount)
|
||||||
if (!(options.counterparty ||
|
if (!(options.counterparty ||
|
||||||
(options.currency && options.currency !== 'XRP')
|
(options.currency && options.currency !== 'XRP')
|
||||||
)) {
|
)) {
|
||||||
const xrpBalance = {
|
const xrpBalance = {
|
||||||
currency: 'XRP',
|
currency: 'XRP',
|
||||||
value: balances.xrp
|
value: balances.xrp
|
||||||
};
|
}
|
||||||
result.unshift(xrpBalance);
|
result.unshift(xrpBalance)
|
||||||
}
|
}
|
||||||
if (options.limit && result.length > options.limit) {
|
if (options.limit && result.length > options.limit) {
|
||||||
const toRemove = result.length - options.limit;
|
const toRemove = result.length - options.limit
|
||||||
result.splice(-toRemove, toRemove);
|
result.splice(-toRemove, toRemove)
|
||||||
}
|
}
|
||||||
return result;
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLedgerVersionHelper(connection: Connection, optionValue?: number
|
function getLedgerVersionHelper(connection: Connection, optionValue?: number
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
if (optionValue !== undefined && optionValue !== null) {
|
if (optionValue !== undefined && optionValue !== null) {
|
||||||
return Promise.resolve(optionValue);
|
return Promise.resolve(optionValue)
|
||||||
}
|
}
|
||||||
return connection.getLedgerVersion();
|
return connection.getLedgerVersion()
|
||||||
}
|
}
|
||||||
|
|
||||||
function getBalances(address: string, options: TrustlinesOptions = {}
|
function getBalances(address: string, options: TrustlinesOptions = {}
|
||||||
): Promise<GetBalances> {
|
): Promise<GetBalances> {
|
||||||
validate.getTrustlines({address, options});
|
validate.getTrustlines({address, options})
|
||||||
|
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
getLedgerVersionHelper(this.connection, options.ledgerVersion).then(
|
getLedgerVersionHelper(this.connection, options.ledgerVersion).then(
|
||||||
@@ -58,7 +56,7 @@ function getBalances(address: string, options: TrustlinesOptions = {}
|
|||||||
utils.getXRPBalance(this.connection, address, ledgerVersion)),
|
utils.getXRPBalance(this.connection, address, ledgerVersion)),
|
||||||
this.getTrustlines(address, options)
|
this.getTrustlines(address, options)
|
||||||
]).then(results =>
|
]).then(results =>
|
||||||
formatBalances(options, {xrp: results[0], trustlines: results[1]}));
|
formatBalances(options, {xrp: results[0], trustlines: results[1]}))
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = getBalances;
|
export default getBalances
|
||||||
@@ -1,9 +1,6 @@
|
|||||||
/* @flow */
|
import {validate} from '../common'
|
||||||
'use strict';
|
import parseLedger from './parse/ledger'
|
||||||
const utils = require('./utils');
|
import {GetLedger} from './types'
|
||||||
const {validate} = utils.common;
|
|
||||||
const parseLedger = require('./parse/ledger');
|
|
||||||
import type {GetLedger} from './types.js';
|
|
||||||
|
|
||||||
type LedgerOptions = {
|
type LedgerOptions = {
|
||||||
ledgerVersion?: number,
|
ledgerVersion?: number,
|
||||||
@@ -14,7 +11,7 @@ type LedgerOptions = {
|
|||||||
|
|
||||||
|
|
||||||
function getLedger(options: LedgerOptions = {}): Promise<GetLedger> {
|
function getLedger(options: LedgerOptions = {}): Promise<GetLedger> {
|
||||||
validate.getLedger({options});
|
validate.getLedger({options})
|
||||||
|
|
||||||
const request = {
|
const request = {
|
||||||
command: 'ledger',
|
command: 'ledger',
|
||||||
@@ -22,10 +19,10 @@ function getLedger(options: LedgerOptions = {}): Promise<GetLedger> {
|
|||||||
expand: options.includeAllData,
|
expand: options.includeAllData,
|
||||||
transactions: options.includeTransactions,
|
transactions: options.includeTransactions,
|
||||||
accounts: options.includeState
|
accounts: options.includeState
|
||||||
};
|
}
|
||||||
|
|
||||||
return this.connection.request(request).then(response =>
|
return this.connection.request(request).then(response =>
|
||||||
parseLedger(response.ledger));
|
parseLedger(response.ledger))
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = getLedger;
|
export default getLedger
|
||||||
@@ -1,12 +1,10 @@
|
|||||||
/* @flow */
|
import * as _ from 'lodash'
|
||||||
'use strict';
|
import * as utils from './utils'
|
||||||
const _ = require('lodash');
|
import parseOrderbookOrder from './parse/orderbook-order'
|
||||||
const utils = require('./utils');
|
import {validate} from '../common'
|
||||||
const {validate} = utils.common;
|
import {Connection} from '../common'
|
||||||
const parseOrderbookOrder = require('./parse/orderbook-order');
|
import {OrdersOptions, OrderSpecification} from './types'
|
||||||
import type {Connection} from '../common/connection.js';
|
import {Amount, Issue} from '../common/types'
|
||||||
import type {OrdersOptions, OrderSpecification} from './types.js';
|
|
||||||
import type {Amount, Issue} from '../common/types.js';
|
|
||||||
|
|
||||||
type Orderbook = {
|
type Orderbook = {
|
||||||
base: Issue,
|
base: Issue,
|
||||||
@@ -36,41 +34,45 @@ type GetOrderbook = {
|
|||||||
// account is to specify a "perspective", which affects which unfunded offers
|
// account is to specify a "perspective", which affects which unfunded offers
|
||||||
// are returned
|
// are returned
|
||||||
function getBookOffers(connection: Connection, account: string,
|
function getBookOffers(connection: Connection, account: string,
|
||||||
ledgerVersion?: number, limit?: number, takerGets: Issue,
|
ledgerVersion: number|undefined, limit: number|undefined, takerGets: Issue,
|
||||||
takerPays: Issue
|
takerPays: Issue
|
||||||
): Promise {
|
): Promise<Object[]> {
|
||||||
return connection.request(utils.renameCounterpartyToIssuerInOrder({
|
const orderData = utils.renameCounterpartyToIssuerInOrder({
|
||||||
command: 'book_offers',
|
|
||||||
taker_gets: takerGets,
|
taker_gets: takerGets,
|
||||||
taker_pays: takerPays,
|
taker_pays: takerPays
|
||||||
|
})
|
||||||
|
return connection.request({
|
||||||
|
command: 'book_offers',
|
||||||
|
taker_gets: orderData.taker_gets,
|
||||||
|
taker_pays: orderData.taker_pays,
|
||||||
ledger_index: ledgerVersion || 'validated',
|
ledger_index: ledgerVersion || 'validated',
|
||||||
limit: limit,
|
limit: limit,
|
||||||
taker: account
|
taker: account
|
||||||
})).then(data => data.offers);
|
}).then(data => data.offers)
|
||||||
}
|
}
|
||||||
|
|
||||||
function isSameIssue(a: Amount, b: Amount) {
|
function isSameIssue(a: Amount, b: Amount) {
|
||||||
return a.currency === b.currency && a.counterparty === b.counterparty;
|
return a.currency === b.currency && a.issuer === b.issuer
|
||||||
}
|
}
|
||||||
|
|
||||||
function directionFilter(direction: string, order: OrderbookItem) {
|
function directionFilter(direction: string, order: OrderbookItem) {
|
||||||
return order.specification.direction === direction;
|
return order.specification.direction === direction
|
||||||
}
|
}
|
||||||
|
|
||||||
function flipOrder(order: OrderbookItem) {
|
function flipOrder(order: OrderbookItem) {
|
||||||
const specification = order.specification;
|
const specification = order.specification
|
||||||
const flippedSpecification = {
|
const flippedSpecification = {
|
||||||
quantity: specification.totalPrice,
|
quantity: specification.totalPrice,
|
||||||
totalPrice: specification.quantity,
|
totalPrice: specification.quantity,
|
||||||
direction: specification.direction === 'buy' ? 'sell' : 'buy'
|
direction: specification.direction === 'buy' ? 'sell' : 'buy'
|
||||||
};
|
}
|
||||||
const newSpecification = _.merge({}, specification, flippedSpecification);
|
const newSpecification = _.merge({}, specification, flippedSpecification)
|
||||||
return _.merge({}, order, {specification: newSpecification});
|
return _.merge({}, order, {specification: newSpecification})
|
||||||
}
|
}
|
||||||
|
|
||||||
function alignOrder(base: Amount, order: OrderbookItem) {
|
function alignOrder(base: Amount, order: OrderbookItem) {
|
||||||
const quantity = order.specification.quantity;
|
const quantity = order.specification.quantity
|
||||||
return isSameIssue(quantity, base) ? order : flipOrder(order);
|
return isSameIssue(quantity, base) ? order : flipOrder(order)
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatBidsAndAsks(orderbook: Orderbook, offers) {
|
function formatBidsAndAsks(orderbook: Orderbook, offers) {
|
||||||
@@ -84,24 +86,24 @@ function formatBidsAndAsks(orderbook: Orderbook, offers) {
|
|||||||
// for asks: lowest quality => lowest totalPrice/quantity => lowest price
|
// for asks: lowest quality => lowest totalPrice/quantity => lowest price
|
||||||
// for both bids and asks, lowest quality is closest to mid-market
|
// for both bids and asks, lowest quality is closest to mid-market
|
||||||
// we sort the orders so that earlier orders are closer to mid-market
|
// we sort the orders so that earlier orders are closer to mid-market
|
||||||
const orders = _.sortBy(offers, 'quality').map(parseOrderbookOrder);
|
const orders = _.sortBy(offers, 'quality').map(parseOrderbookOrder)
|
||||||
const alignedOrders = orders.map(_.partial(alignOrder, orderbook.base));
|
const alignedOrders = orders.map(_.partial(alignOrder, orderbook.base))
|
||||||
const bids = alignedOrders.filter(_.partial(directionFilter, 'buy'));
|
const bids = alignedOrders.filter(_.partial(directionFilter, 'buy'))
|
||||||
const asks = alignedOrders.filter(_.partial(directionFilter, 'sell'));
|
const asks = alignedOrders.filter(_.partial(directionFilter, 'sell'))
|
||||||
return {bids, asks};
|
return {bids, asks}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getOrderbook(address: string, orderbook: Orderbook,
|
function getOrderbook(address: string, orderbook: Orderbook,
|
||||||
options: OrdersOptions = {}
|
options: OrdersOptions = {}
|
||||||
): Promise<GetOrderbook> {
|
): Promise<GetOrderbook> {
|
||||||
validate.getOrderbook({address, orderbook, options});
|
validate.getOrderbook({address, orderbook, options})
|
||||||
|
|
||||||
const getter = _.partial(getBookOffers, this.connection, address,
|
const getter = _.partial(getBookOffers, this.connection, address,
|
||||||
options.ledgerVersion, options.limit);
|
options.ledgerVersion, options.limit)
|
||||||
const getOffers = _.partial(getter, orderbook.base, orderbook.counter);
|
const getOffers = _.partial(getter, orderbook.base, orderbook.counter)
|
||||||
const getReverseOffers = _.partial(getter, orderbook.counter, orderbook.base);
|
const getReverseOffers = _.partial(getter, orderbook.counter, orderbook.base)
|
||||||
return Promise.all([getOffers(), getReverseOffers()]).then(data =>
|
return Promise.all([getOffers(), getReverseOffers()]).then(data =>
|
||||||
formatBidsAndAsks(orderbook, _.flatten(data)));
|
formatBidsAndAsks(orderbook, _.flatten(data)))
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = getOrderbook;
|
export default getOrderbook
|
||||||
@@ -1,41 +1,37 @@
|
|||||||
/* @flow */
|
import * as _ from 'lodash'
|
||||||
'use strict';
|
import * as utils from './utils'
|
||||||
const _ = require('lodash');
|
import {validate} from '../common'
|
||||||
const utils = require('./utils');
|
import {Connection} from '../common'
|
||||||
const {validate} = utils.common;
|
import parseAccountOrder from './parse/account-order'
|
||||||
const parseAccountOrder = require('./parse/account-order');
|
import {OrdersOptions, Order} from './types'
|
||||||
import type {Connection} from '../common/connection.js';
|
|
||||||
import type {OrdersOptions, Order} from './types.js';
|
|
||||||
|
|
||||||
type GetOrders = Array<Order>
|
type GetOrders = Array<Order>
|
||||||
|
|
||||||
function requestAccountOffers(connection: Connection, address: string,
|
function requestAccountOffers(connection: Connection, address: string,
|
||||||
ledgerVersion: number, marker: string, limit: number
|
ledgerVersion: number, marker: string, limit: number
|
||||||
): Promise {
|
): Promise<Object> {
|
||||||
return connection.request({
|
return connection.request({
|
||||||
command: 'account_offers',
|
command: 'account_offers',
|
||||||
account: address,
|
account: address,
|
||||||
marker: marker,
|
marker: marker,
|
||||||
limit: utils.clamp(limit, 10, 400),
|
limit: utils.clamp(limit, 10, 400),
|
||||||
ledger_index: ledgerVersion
|
ledger_index: ledgerVersion
|
||||||
}).then(data => {
|
}).then(data => ({
|
||||||
return {
|
marker: data.marker,
|
||||||
marker: data.marker,
|
results: data.offers.map(_.partial(parseAccountOrder, address))
|
||||||
results: data.offers.map(_.partial(parseAccountOrder, address))
|
}))
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getOrders(address: string, options: OrdersOptions = {}
|
function getOrders(address: string, options: OrdersOptions = {}
|
||||||
): Promise<GetOrders> {
|
): Promise<GetOrders> {
|
||||||
validate.getOrders({address, options});
|
validate.getOrders({address, options})
|
||||||
|
|
||||||
return utils.ensureLedgerVersion.call(this, options).then(_options => {
|
return utils.ensureLedgerVersion.call(this, options).then(_options => {
|
||||||
const getter = _.partial(requestAccountOffers, this.connection, address,
|
const getter = _.partial(requestAccountOffers, this.connection, address,
|
||||||
_options.ledgerVersion);
|
_options.ledgerVersion)
|
||||||
return utils.getRecursive(getter, _options.limit).then(orders =>
|
return utils.getRecursive(getter, _options.limit).then(orders =>
|
||||||
_.sortBy(orders, (order) => order.properties.sequence));
|
_.sortBy(orders, order => order.properties.sequence))
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = getOrders;
|
export default getOrders
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
/* @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');
|
|
||||||
|
|
||||||
// TODO: remove this function once rippled provides quality directly
|
|
||||||
function computeQuality(takerGets, takerPays) {
|
|
||||||
const quotient = new BigNumber(takerPays.value).dividedBy(takerGets.value);
|
|
||||||
return quotient.toDigits(16, BigNumber.ROUND_HALF_UP).toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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 takerGetsAmount = parseAmount(order.taker_gets);
|
|
||||||
const takerPaysAmount = parseAmount(order.taker_pays);
|
|
||||||
const quantity = (direction === 'buy') ? takerPaysAmount : takerGetsAmount;
|
|
||||||
const totalPrice = (direction === 'buy') ? takerGetsAmount : takerPaysAmount;
|
|
||||||
|
|
||||||
// note: immediateOrCancel and fillOrKill orders cannot enter the order book
|
|
||||||
// so we can omit those flags here
|
|
||||||
const specification = utils.removeUndefined({
|
|
||||||
direction: direction,
|
|
||||||
quantity: quantity,
|
|
||||||
totalPrice: totalPrice,
|
|
||||||
passive: ((order.flags & flags.Passive) !== 0) || undefined,
|
|
||||||
// rippled currently does not provide "expiration" in account_offers
|
|
||||||
expirationTime: utils.parseTimestamp(order.expiration)
|
|
||||||
});
|
|
||||||
|
|
||||||
const makerExchangeRate = order.quality ?
|
|
||||||
utils.adjustQualityForXRP(order.quality.toString(),
|
|
||||||
takerGetsAmount.currency, takerPaysAmount.currency) :
|
|
||||||
computeQuality(takerGetsAmount, takerPaysAmount);
|
|
||||||
const properties = {
|
|
||||||
maker: address,
|
|
||||||
sequence: order.seq,
|
|
||||||
makerExchangeRate: makerExchangeRate
|
|
||||||
};
|
|
||||||
|
|
||||||
return {specification, properties};
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = parseAccountOrder;
|
|
||||||
46
src/ledger/parse/account-order.ts
Normal file
46
src/ledger/parse/account-order.ts
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
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) {
|
||||||
|
const quotient = new BigNumber(takerPays.value).dividedBy(takerGets.value)
|
||||||
|
return quotient.toDigits(16, BigNumber.ROUND_HALF_UP).toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
// rippled 'account_offers' returns a different format for orders than 'tx'
|
||||||
|
// the flags are also different
|
||||||
|
function parseAccountOrder(address: string, order: any): Object {
|
||||||
|
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
|
||||||
|
const totalPrice = (direction === 'buy') ? takerGetsAmount : takerPaysAmount
|
||||||
|
|
||||||
|
// note: immediateOrCancel and fillOrKill orders cannot enter the order book
|
||||||
|
// so we can omit those flags here
|
||||||
|
const specification = removeUndefined({
|
||||||
|
direction: direction,
|
||||||
|
quantity: quantity,
|
||||||
|
totalPrice: totalPrice,
|
||||||
|
passive: ((order.flags & orderFlags.Passive) !== 0) || undefined,
|
||||||
|
// rippled currently does not provide "expiration" in account_offers
|
||||||
|
expirationTime: parseTimestamp(order.expiration)
|
||||||
|
})
|
||||||
|
|
||||||
|
const makerExchangeRate = order.quality ?
|
||||||
|
adjustQualityForXRP(order.quality.toString(),
|
||||||
|
takerGetsAmount.currency, takerPaysAmount.currency) :
|
||||||
|
computeQuality(takerGetsAmount, takerPaysAmount)
|
||||||
|
const properties = {
|
||||||
|
maker: address,
|
||||||
|
sequence: order.seq,
|
||||||
|
makerExchangeRate: makerExchangeRate
|
||||||
|
}
|
||||||
|
|
||||||
|
return {specification, properties}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default parseAccountOrder
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
/* @flow */
|
import {parseQuality} from './utils'
|
||||||
'use strict';
|
import {removeUndefined} from '../../common'
|
||||||
const utils = require('./utils');
|
|
||||||
|
|
||||||
type Trustline = {
|
type Trustline = {
|
||||||
account: string, limit: number, currency: string, quality_in: ?number,
|
account: string, limit: number, currency: string, quality_in: number|null,
|
||||||
quality_out: ?number, no_ripple: boolean, freeze: boolean,
|
quality_out: number|null, no_ripple: boolean, freeze: boolean,
|
||||||
authorized: boolean, limit_peer: string, no_ripple_peer: boolean,
|
authorized: boolean, limit_peer: string, no_ripple_peer: boolean,
|
||||||
freeze_peer: boolean, peer_authorized: boolean, balance: any
|
freeze_peer: boolean, peer_authorized: boolean, balance: any
|
||||||
}
|
}
|
||||||
@@ -20,27 +19,27 @@ type AccountTrustline = {
|
|||||||
// rippled 'account_lines' returns a different format for
|
// rippled 'account_lines' returns a different format for
|
||||||
// trustlines than 'tx'
|
// trustlines than 'tx'
|
||||||
function parseAccountTrustline(trustline: Trustline): AccountTrustline {
|
function parseAccountTrustline(trustline: Trustline): AccountTrustline {
|
||||||
const specification = utils.removeUndefined({
|
const specification = removeUndefined({
|
||||||
limit: trustline.limit,
|
limit: trustline.limit,
|
||||||
currency: trustline.currency,
|
currency: trustline.currency,
|
||||||
counterparty: trustline.account,
|
counterparty: trustline.account,
|
||||||
qualityIn: utils.parseQuality(trustline.quality_in) || undefined,
|
qualityIn: parseQuality(trustline.quality_in) || undefined,
|
||||||
qualityOut: utils.parseQuality(trustline.quality_out) || undefined,
|
qualityOut: parseQuality(trustline.quality_out) || undefined,
|
||||||
ripplingDisabled: trustline.no_ripple || undefined,
|
ripplingDisabled: trustline.no_ripple || undefined,
|
||||||
frozen: trustline.freeze || undefined,
|
frozen: trustline.freeze || undefined,
|
||||||
authorized: trustline.authorized || undefined
|
authorized: trustline.authorized || undefined
|
||||||
});
|
})
|
||||||
// rippled doesn't provide the counterparty's qualities
|
// rippled doesn't provide the counterparty's qualities
|
||||||
const counterparty = utils.removeUndefined({
|
const counterparty = removeUndefined({
|
||||||
limit: trustline.limit_peer,
|
limit: trustline.limit_peer,
|
||||||
ripplingDisabled: trustline.no_ripple_peer || undefined,
|
ripplingDisabled: trustline.no_ripple_peer || undefined,
|
||||||
frozen: trustline.freeze_peer || undefined,
|
frozen: trustline.freeze_peer || undefined,
|
||||||
authorized: trustline.peer_authorized || undefined
|
authorized: trustline.peer_authorized || undefined
|
||||||
});
|
})
|
||||||
const state = {
|
const state = {
|
||||||
balance: trustline.balance
|
balance: trustline.balance
|
||||||
};
|
}
|
||||||
return {specification, counterparty, state};
|
return {specification, counterparty, state}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = parseAccountTrustline;
|
export default parseAccountTrustline
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user