mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-05 05:15:48 +00:00
Compare commits
320 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fbe015758c | ||
|
|
7e24a81764 | ||
|
|
9ab77e90fe | ||
|
|
ae3ed699db | ||
|
|
0c22a9753e | ||
|
|
a447f6b723 | ||
|
|
a8ef614b81 | ||
|
|
9025e8bfa8 | ||
|
|
722f4e175d | ||
|
|
1ad6e5a15f | ||
|
|
3554572db7 | ||
|
|
f1abff962f | ||
|
|
f05941fbc4 | ||
|
|
237c46d5a0 | ||
|
|
76cfb69d9f | ||
|
|
7610df0fbb | ||
|
|
8bc935aa62 | ||
|
|
24587fab9c | ||
|
|
0248475473 | ||
|
|
d2fa5c4b12 | ||
|
|
c60c0cb6e0 | ||
|
|
cdf1112666 | ||
|
|
d861bb2e34 | ||
|
|
006849a3d5 | ||
|
|
a3c1d06eba | ||
|
|
4bd1e7a2bc | ||
|
|
68643f3118 | ||
|
|
560dfc8ae6 | ||
|
|
b0459e096b | ||
|
|
2a0dfc4587 | ||
|
|
2dcd5f94fb | ||
|
|
13685d03e1 | ||
|
|
278df9025a | ||
|
|
cb608406f8 | ||
|
|
f4a55d03d3 | ||
|
|
d3b6b8127c | ||
|
|
bc1f9f8a28 | ||
|
|
9a5c9aea75 | ||
|
|
f1004c6db2 | ||
|
|
7708c64576 | ||
|
|
0527b8c981 | ||
|
|
13f89e2fcc | ||
|
|
69a0a473a6 | ||
|
|
4ab82d7e01 | ||
|
|
4be209e286 | ||
|
|
8b10325895 | ||
|
|
70bf600247 | ||
|
|
d42e06d48b | ||
|
|
9c080b6790 | ||
|
|
033257b03b | ||
|
|
39d8bcdfc2 | ||
|
|
2ddcb4e2b7 | ||
|
|
d972718a53 | ||
|
|
6abed8dd53 | ||
|
|
e74e697b45 | ||
|
|
26c59e8565 | ||
|
|
a5e83c4f23 | ||
|
|
900c4bbd2e | ||
|
|
947ec3edc2 | ||
|
|
957f10d9f1 | ||
|
|
89aa54dff8 | ||
|
|
bb76530e4b | ||
|
|
011e2cc1e3 | ||
|
|
4c594f8964 | ||
|
|
1fcfcf2392 | ||
|
|
6311abff81 | ||
|
|
ed2da57475 | ||
|
|
778ccd4805 | ||
|
|
327c35252f | ||
|
|
5e7af2fba4 | ||
|
|
dce15bc579 | ||
|
|
d5e32db954 | ||
|
|
bdfa83592b | ||
|
|
23e473b688 | ||
|
|
0dfd3a0ae0 | ||
|
|
d107092540 | ||
|
|
c2f379d3b3 | ||
|
|
57b70300f5 | ||
|
|
eeba86f9c5 | ||
|
|
e0d68e60ec | ||
|
|
254248486b | ||
|
|
1b57cc6d35 | ||
|
|
77234f256d | ||
|
|
795d31d2db | ||
|
|
f3f10fd9bd | ||
|
|
7100b4be8d | ||
|
|
b1a7200d1b | ||
|
|
5d8bb541c6 | ||
|
|
b51c59b23a | ||
|
|
2cd434e861 | ||
|
|
1599eb9629 | ||
|
|
8ef7481858 | ||
|
|
344d478b3f | ||
|
|
39b7e27aa6 | ||
|
|
b1876b4f77 | ||
|
|
db3b41d1ba | ||
|
|
02b5d14d0f | ||
|
|
0120044c96 | ||
|
|
ad6304e857 | ||
|
|
7cba84b8cf | ||
|
|
5a9a4be163 | ||
|
|
4d1a31d3c9 | ||
|
|
6e3ceec4e5 | ||
|
|
bc7d3c0af8 | ||
|
|
519ddee092 | ||
|
|
3e0fcc5b8b | ||
|
|
b1972985c4 | ||
|
|
51c42e9257 | ||
|
|
86dcbcc671 | ||
|
|
3b7cd9d84f | ||
|
|
1073ec6214 | ||
|
|
14a5e42a63 | ||
|
|
b4564a86b4 | ||
|
|
03386a61e9 | ||
|
|
8bb2623360 | ||
|
|
ab0e4188b3 | ||
|
|
42c853dbf4 | ||
|
|
ce48a1793b | ||
|
|
6177543d98 | ||
|
|
9697bfa817 | ||
|
|
70425ab5c8 | ||
|
|
7cccb451d2 | ||
|
|
a39fb9d551 | ||
|
|
8f7cdc6e4f | ||
|
|
8f7e365b03 | ||
|
|
64735e523f | ||
|
|
f126610219 | ||
|
|
2caef539ce | ||
|
|
468fb87749 | ||
|
|
4f4808ff15 | ||
|
|
e6bbca7df1 | ||
|
|
e7d1095be2 | ||
|
|
a08d5ce6e5 | ||
|
|
fec2f5578d | ||
|
|
4869e30914 | ||
|
|
e1f31765e7 | ||
|
|
a3668defa8 | ||
|
|
765ff9fa32 | ||
|
|
dd04177f83 | ||
|
|
2e2ab6bffc | ||
|
|
934cacfc1b | ||
|
|
9800fd8f11 | ||
|
|
3e84996788 | ||
|
|
5a3f55d774 | ||
|
|
dbddc314a6 | ||
|
|
c98f875811 | ||
|
|
29a1ffb3b8 | ||
|
|
17770ad4c9 | ||
|
|
cc9ed435eb | ||
|
|
27a723b453 | ||
|
|
af6c9b6bd2 | ||
|
|
2d3bbecb05 | ||
|
|
51e4cb15b4 | ||
|
|
5ce91a027c | ||
|
|
3cb337e7ec | ||
|
|
c29f92f05b | ||
|
|
01903cc6d2 | ||
|
|
fff7a6bc9e | ||
|
|
678c67622d | ||
|
|
2a6aec94fb | ||
|
|
bc52f33e9c | ||
|
|
006beeb5f9 | ||
|
|
ff85b3c4c9 | ||
|
|
6c7b2b17dc | ||
|
|
131de6661c | ||
|
|
d416f31801 | ||
|
|
8885a9e3e5 | ||
|
|
27e100f4ee | ||
|
|
40dc49bd63 | ||
|
|
989509dc07 | ||
|
|
9c3f5fbcd2 | ||
|
|
0917f66cb2 | ||
|
|
66c56df7dc | ||
|
|
b5fdfa2604 | ||
|
|
a0d4a3c84d | ||
|
|
d8374b2f49 | ||
|
|
a2a2162f48 | ||
|
|
d845d094db | ||
|
|
81e805fcb9 | ||
|
|
81283eeb84 | ||
|
|
60069d0a28 | ||
|
|
7c0561d17f | ||
|
|
45ac10b215 | ||
|
|
47f5943cf7 | ||
|
|
73d30242c9 | ||
|
|
5a4e33a02d | ||
|
|
edbbbec8f3 | ||
|
|
f8811f27a0 | ||
|
|
ad6138a14e | ||
|
|
e6fec67ce9 | ||
|
|
08a09fab9c | ||
|
|
1bf06bc656 | ||
|
|
cf46808557 | ||
|
|
df5a8656f6 | ||
|
|
b41f00515b | ||
|
|
2b22b49f83 | ||
|
|
4c0eda95c6 | ||
|
|
92e4644d60 | ||
|
|
11b67b15e4 | ||
|
|
565cd59f13 | ||
|
|
f4643c7b52 | ||
|
|
a292c2841c | ||
|
|
edd57a89c1 | ||
|
|
0d3bc96672 | ||
|
|
cc96d21da6 | ||
|
|
ed4e07907f | ||
|
|
da6e4be815 | ||
|
|
391cba18b6 | ||
|
|
49f55cea48 | ||
|
|
fc361841b0 | ||
|
|
5db493df1c | ||
|
|
ca317f01db | ||
|
|
2687830623 | ||
|
|
4d9603ae7b | ||
|
|
61087c9406 | ||
|
|
4d6251be37 | ||
|
|
18b817c284 | ||
|
|
61649b1428 | ||
|
|
c9f82be54c | ||
|
|
416dc44d05 | ||
|
|
97712bfe96 | ||
|
|
f923a62f54 | ||
|
|
a41c5ddc62 | ||
|
|
564f248fe0 | ||
|
|
e712034c0f | ||
|
|
ca88298b76 | ||
|
|
5ac21f993e | ||
|
|
5eb12c9d28 | ||
|
|
e12bea4b27 | ||
|
|
cad9521049 | ||
|
|
0847002c96 | ||
|
|
c3783533e9 | ||
|
|
85a7e935b2 | ||
|
|
43658264a8 | ||
|
|
b00f5c5a1c | ||
|
|
7af758bf88 | ||
|
|
c1a0be2402 | ||
|
|
1d4bcd4e0f | ||
|
|
4450ef822e | ||
|
|
ef74c7ca11 | ||
|
|
27eadc5587 | ||
|
|
0b03de66e7 | ||
|
|
cfcea4affb | ||
|
|
4e13170123 | ||
|
|
fe4cf94b62 | ||
|
|
f4233d7615 | ||
|
|
6e5bebfe81 | ||
|
|
21b0e09837 | ||
|
|
7b243dff03 | ||
|
|
fbe67df069 | ||
|
|
ea82c8cce3 | ||
|
|
e5322fb8e4 | ||
|
|
c5e6c5819b | ||
|
|
c3975dfc68 | ||
|
|
ddf7ca78ee | ||
|
|
71d8b6c9bf | ||
|
|
f11cd65494 | ||
|
|
59f7d49b80 | ||
|
|
447ae3f38f | ||
|
|
b2c4f935e7 | ||
|
|
5a85385db6 | ||
|
|
6dcd9e9014 | ||
|
|
eebfe02163 | ||
|
|
19294f5435 | ||
|
|
ef17cd86a8 | ||
|
|
ac62a336ea | ||
|
|
bdb7454737 | ||
|
|
4e9082f4d9 | ||
|
|
7daa4b4c3b | ||
|
|
7be13bebfc | ||
|
|
aea75f2beb | ||
|
|
cb59f86d4c | ||
|
|
8f340c1cde | ||
|
|
76659b613b | ||
|
|
79c5428da2 | ||
|
|
ca2d137d52 | ||
|
|
9789f76f64 | ||
|
|
df6eee1084 | ||
|
|
09461fb3c8 | ||
|
|
5607f2d379 | ||
|
|
3b7f556887 | ||
|
|
e84633de13 | ||
|
|
2b2267c46e | ||
|
|
37090716d3 | ||
|
|
3535ce1b04 | ||
|
|
dda865b6f2 | ||
|
|
9115a7193d | ||
|
|
6d347bcec0 | ||
|
|
b96d26acc2 | ||
|
|
5dbfe04a9a | ||
|
|
7e11b4e03d | ||
|
|
e2eaf9718c | ||
|
|
2576abe06e | ||
|
|
07a15d7b91 | ||
|
|
c5fdb3e2f6 | ||
|
|
0b068dab6a | ||
|
|
b4497bcb08 | ||
|
|
3baea7752f | ||
|
|
05cce3dbab | ||
|
|
d23dca2ef1 | ||
|
|
bcf93e230e | ||
|
|
4bd39b9bb1 | ||
|
|
8797cdb27e | ||
|
|
ab259fa519 | ||
|
|
585ca4160d | ||
|
|
5fe1ebdd45 | ||
|
|
a0ba289848 | ||
|
|
b6f0aa3914 | ||
|
|
a47eef3283 | ||
|
|
e0bcf19340 | ||
|
|
fa9305626b | ||
|
|
a573465e41 | ||
|
|
9527d6ed22 | ||
|
|
3ef60e0391 | ||
|
|
6028115e52 | ||
|
|
301b34a923 | ||
|
|
01c6417425 | ||
|
|
e4f9be5af8 | ||
|
|
6ebaec31a5 | ||
|
|
250e987fd9 |
10
.gitignore
vendored
10
.gitignore
vendored
@@ -17,7 +17,7 @@
|
||||
|
||||
# Ignore object files.
|
||||
*.o
|
||||
build/ripple*.js
|
||||
build/*.js
|
||||
tags
|
||||
bin/rippled
|
||||
Debug/*.*
|
||||
@@ -45,4 +45,10 @@ test/config.js
|
||||
/coverage
|
||||
|
||||
# Ignore IntelliJ files
|
||||
.idea
|
||||
.idea
|
||||
|
||||
# Ignore npm-debug
|
||||
npm-debug.log
|
||||
|
||||
# Ignore dist folder, build for bower
|
||||
dist/
|
||||
|
||||
@@ -4,3 +4,10 @@ node_js:
|
||||
script: npm test --coverage
|
||||
after_success:
|
||||
- npm run coveralls
|
||||
notifications:
|
||||
webhooks:
|
||||
urls:
|
||||
- https://webhooks.gitter.im/e/d1ec4245f90231619d30
|
||||
on_success: change # options: [always|never|change] default: always
|
||||
on_failure: always # options: [always|never|change] default: always
|
||||
on_start: false # default: false
|
||||
106
Gruntfile.js
106
Gruntfile.js
@@ -1,106 +0,0 @@
|
||||
module.exports = function(grunt) {
|
||||
grunt.loadNpmTasks('grunt-webpack');
|
||||
grunt.loadNpmTasks('grunt-dox');
|
||||
grunt.loadNpmTasks('grunt-contrib-concat');
|
||||
grunt.loadNpmTasks('grunt-contrib-watch');
|
||||
|
||||
grunt.initConfig({
|
||||
pkg: grunt.file.readJSON('package.json'),
|
||||
meta: {
|
||||
banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
|
||||
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
|
||||
'<%= pkg.homepage ? "* " + pkg.homepage + "\n" : "" %>' +
|
||||
'* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
|
||||
' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */'
|
||||
},
|
||||
concat: {
|
||||
sjcl: {
|
||||
src: [
|
||||
"src/js/sjcl/core/sjcl.js",
|
||||
"src/js/sjcl/core/aes.js",
|
||||
"src/js/sjcl/core/bitArray.js",
|
||||
"src/js/sjcl/core/codecString.js",
|
||||
"src/js/sjcl/core/codecHex.js",
|
||||
"src/js/sjcl/core/codecBase64.js",
|
||||
"src/js/sjcl/core/codecBytes.js",
|
||||
"src/js/sjcl/core/sha256.js",
|
||||
"src/js/sjcl/core/sha512.js",
|
||||
"src/js/sjcl/core/sha1.js",
|
||||
"src/js/sjcl/core/ccm.js",
|
||||
// "src/js/sjcl/core/cbc.js",
|
||||
// "src/js/sjcl/core/ocb2.js",
|
||||
"src/js/sjcl/core/hmac.js",
|
||||
"src/js/sjcl/core/pbkdf2.js",
|
||||
"src/js/sjcl/core/random.js",
|
||||
"src/js/sjcl/core/convenience.js",
|
||||
"src/js/sjcl/core/bn.js",
|
||||
"src/js/sjcl/core/ecc.js",
|
||||
"src/js/sjcl/core/srp.js",
|
||||
"src/js/sjcl-custom/sjcl-ecc-pointextras.js",
|
||||
"src/js/sjcl-custom/sjcl-secp256k1.js",
|
||||
"src/js/sjcl-custom/sjcl-ripemd160.js",
|
||||
"src/js/sjcl-custom/sjcl-extramath.js",
|
||||
"src/js/sjcl-custom/sjcl-montgomery.js",
|
||||
"src/js/sjcl-custom/sjcl-validecc.js",
|
||||
"src/js/sjcl-custom/sjcl-ecdsa-canonical.js",
|
||||
"src/js/sjcl-custom/sjcl-ecdsa-der.js",
|
||||
"src/js/sjcl-custom/sjcl-ecdsa-recoverablepublickey.js",
|
||||
"src/js/sjcl-custom/sjcl-jacobi.js"
|
||||
],
|
||||
dest: 'build/sjcl.js'
|
||||
}
|
||||
},
|
||||
webpack: {
|
||||
options: {
|
||||
entry: "./src/js/ripple/index.js",
|
||||
output: {
|
||||
library: "ripple"
|
||||
},
|
||||
cache: true
|
||||
},
|
||||
lib: {
|
||||
output: {
|
||||
filename: "build/ripple-<%= pkg.version %>.js"
|
||||
}
|
||||
},
|
||||
lib_debug: {
|
||||
output: {
|
||||
filename: "build/ripple-<%= pkg.version %>-debug.js"
|
||||
},
|
||||
debug: true,
|
||||
devtool: 'eval'
|
||||
},
|
||||
lib_min: {
|
||||
output: {
|
||||
filename: "build/ripple-<%= pkg.version %>-min.js"
|
||||
},
|
||||
optimize: {
|
||||
minimize: true
|
||||
}
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
sjcl: {
|
||||
files: ['<%= concat.sjcl.src %>'],
|
||||
tasks: 'concat:sjcl'
|
||||
},
|
||||
lib: {
|
||||
files: 'src/js/ripple/*.js',
|
||||
tasks: 'webpack:lib_debug'
|
||||
}
|
||||
},
|
||||
dox: {
|
||||
libdocs: {
|
||||
options: {
|
||||
title: "Test"
|
||||
},
|
||||
src: ['src/js/ripple/'],
|
||||
dest: 'build/docs'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Tasks
|
||||
grunt.registerTask('default', ['concat:sjcl', 'webpack']);
|
||||
|
||||
};
|
||||
43
Gulpfile.js
43
Gulpfile.js
@@ -5,6 +5,8 @@ var rename = require('gulp-rename');
|
||||
var webpack = require('webpack');
|
||||
var jshint = require('gulp-jshint');
|
||||
var map = require('map-stream');
|
||||
var bump = require('gulp-bump');
|
||||
var argv = require('yargs').argv;
|
||||
//var header = require('gulp-header');
|
||||
|
||||
var pkg = require('./package.json');
|
||||
@@ -66,6 +68,45 @@ gulp.task('build', [ 'concat-sjcl' ], function(callback) {
|
||||
}, callback);
|
||||
});
|
||||
|
||||
gulp.task('bower-build', [ 'build' ], function(callback) {
|
||||
return gulp.src([ './build/ripple-', '.js' ].join(pkg.version))
|
||||
.pipe(rename('ripple.js'))
|
||||
.pipe(gulp.dest('./dist/'));
|
||||
});
|
||||
|
||||
gulp.task('bower-build-min', [ 'build-min' ], function(callback) {
|
||||
return gulp.src([ './build/ripple-', '-min.js' ].join(pkg.version))
|
||||
.pipe(rename('ripple-min.js'))
|
||||
.pipe(gulp.dest('./dist/'));
|
||||
});
|
||||
|
||||
gulp.task('bower-build-debug', [ 'build-debug' ], function(callback) {
|
||||
return gulp.src([ './build/ripple-', '-debug.js' ].join(pkg.version))
|
||||
.pipe(rename('ripple-debug.js'))
|
||||
.pipe(gulp.dest('./dist/'));
|
||||
});
|
||||
|
||||
gulp.task('bower-version', function() {
|
||||
gulp.src('./dist/bower.json')
|
||||
.pipe(bump({version: pkg.version}))
|
||||
.pipe(gulp.dest('./dist/'));
|
||||
});
|
||||
|
||||
gulp.task('version-bump', function() {
|
||||
if (!argv.type) {
|
||||
throw new Error("No type found, pass it in using the --type argument");
|
||||
}
|
||||
gulp.src('./package.json')
|
||||
.pipe(bump({type:argv.type}))
|
||||
.pipe(gulp.dest('./'));
|
||||
});
|
||||
|
||||
gulp.task('version-beta', function() {
|
||||
gulp.src('./package.json')
|
||||
.pipe(bump({version: pkg.version+'-beta'}))
|
||||
.pipe(gulp.dest('./'));
|
||||
});
|
||||
|
||||
gulp.task('build-min', [ 'build' ], function(callback) {
|
||||
return gulp.src([ './build/ripple-', '.js' ].join(pkg.version))
|
||||
.pipe(uglify())
|
||||
@@ -118,3 +159,5 @@ gulp.task('watch', function() {
|
||||
});
|
||||
|
||||
gulp.task('default', [ 'concat-sjcl', 'build', 'build-debug', 'build-min' ]);
|
||||
|
||||
gulp.task('bower', ['bower-build', 'bower-build-min', 'bower-build-debug', 'bower-version']);
|
||||
|
||||
110
HISTORY.md
110
HISTORY.md
@@ -1,3 +1,113 @@
|
||||
##0.9.2
|
||||
|
||||
+ [Add paging behavior for requesting account lines and 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)
|
||||
|
||||
+ [Fix: cap IOU Amounts to their max and min value] (https://github.com/ripple/ripple-lib/commit/f05941fbc46fdb7c6fe7ad72927af02d527ffeed)
|
||||
|
||||
##0.9.1
|
||||
|
||||
+ 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))
|
||||
|
||||
+ Change initial account transaction sequence to 1 ([a3c1d06](https://github.com/ripple/ripple-lib/commit/a3c1d06eba883dc84fe2bfe700e4309795c84cac))
|
||||
|
||||
+ 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: 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
|
||||
|
||||
+ 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)
|
||||
|
||||
+ 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))
|
||||
|
||||
+ **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))
|
||||
|
||||
+ 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))
|
||||
|
||||
|
||||
##0.8.2
|
||||
|
||||
+ Currency: Allow mixed letters and numbers in currencies
|
||||
|
||||
+ Deprecate account_tx map/reduce/filterg
|
||||
|
||||
+ Fix: correct requestLedger arguments
|
||||
|
||||
+ Fix: missing subscription on error events for some server methods
|
||||
|
||||
+ Fix: orderbook reset on reconnect
|
||||
|
||||
+ Fix: ripple-lib crashing. Add potential missing error handlers
|
||||
|
||||
|
||||
##0.8.1
|
||||
|
||||
+ Wallet: Add Wallet class that generates wallets
|
||||
|
||||
+ Make npm test runnable in Windows.
|
||||
|
||||
+ Fix several stability issues, see merged PR's for details
|
||||
|
||||
+ Fix bug in Amount.to_human_full()
|
||||
|
||||
+ Fix undefined fee states when connecting to a rippled that is syncing
|
||||
|
||||
|
||||
##0.8.0
|
||||
|
||||
+ Orderbook: Added tracking of offer funds for determining when offers are not funded
|
||||
|
||||
+ Orderbook: Added tests
|
||||
|
||||
+ 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: 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.broadcast()` now returns the number of servers request was sent to
|
||||
|
||||
+ 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: Make Constants static fields on the class, instead of a seperate export
|
||||
|
||||
|
||||
##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 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")`
|
||||
|
||||
+ 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
|
||||
|
||||
+ Add 2-factor authentication support for vault client
|
||||
|
||||
+ Removed vestiges of Grunt, switched to Gulp
|
||||
|
||||
|
||||
##0.7.37
|
||||
|
||||
+ **Deprecations**
|
||||
|
||||
77
README.md
77
README.md
@@ -1,37 +1,36 @@
|
||||
#The Ripple JavaScript Library
|
||||
#ripple-lib
|
||||
|
||||
JavaScript client for [rippled](https://github.com/ripple/rippled)
|
||||
|
||||
[](https://travis-ci.org/ripple/ripple-lib) [](https://coveralls.io/r/ripple/ripple-lib?branch=develop)
|
||||
|
||||
[](https://www.npmjs.org/package/ripple-lib)
|
||||
|
||||
`ripple-lib` connects to the Ripple network via the WebSocket protocol and runs in Node.js as well as in the browser.
|
||||
###Features
|
||||
|
||||
###Use ripple-lib for:
|
||||
+ Connect to a rippled server in JavaScript (Node.js or browser)
|
||||
+ Issue [rippled API](https://ripple.com/wiki/JSON_Messages) requests
|
||||
+ Listen to events on the Ripple network (transaction, ledger, etc.)
|
||||
+ Sign and submit transactions to the Ripple network
|
||||
|
||||
+ Connecting to a local or remote rippled in JavaScript (Node.js or browser)
|
||||
+ Issuing [rippled API](https://ripple.com/wiki/JSON_Messages) requests
|
||||
+ Listening to events on the Ripple network (transaction, ledger, etc.)
|
||||
+ Signing and submitting transactions to the Ripple network
|
||||
###In this file
|
||||
|
||||
###In this file:
|
||||
1. [Installation](README.md#installation)
|
||||
2. [Quickstart](README.md#quickstart)
|
||||
3. [Running tests](https://github.com/ripple/ripple-lib#running-tests)
|
||||
|
||||
1. Overview
|
||||
2. [Getting `ripple-lib`](README.md#getting-ripple-lib)
|
||||
3. [Quickstart](README.md#quickstart)
|
||||
4. [Running tests](https://github.com/ripple/ripple-lib#running-tests)
|
||||
###Additional documentation
|
||||
|
||||
###For additional documentation see:
|
||||
1. [Guides](docs/GUIDES.md)
|
||||
2. [API Reference](docs/REFERENCE.md)
|
||||
3. [Wiki](https://ripple.com/wiki/Ripple_JavaScript_library)
|
||||
|
||||
1. [The `ripple-lib` Guides (docs/GUIDES.md)](docs/GUIDES.md)
|
||||
2. [The `ripple-lib` API Reference (docs/REFERENCE.md)](docs/REFERENCE.md)
|
||||
3. https://ripple.com/wiki/Ripple_JavaScript_library
|
||||
###Also see
|
||||
|
||||
###Also see:
|
||||
+ [The Ripple wiki](https://ripple.com/wiki)
|
||||
+ [ripple.com](https://ripple.com)
|
||||
|
||||
+ https://ripple.com/wiki
|
||||
+ https://ripple.com
|
||||
|
||||
##Getting `ripple-lib`
|
||||
##Installation
|
||||
|
||||
**Via npm for Node.js**
|
||||
|
||||
@@ -39,19 +38,28 @@
|
||||
$ npm install ripple-lib
|
||||
```
|
||||
|
||||
**Build from the source using `grunt`**
|
||||
**Via bower (for browser use)**
|
||||
|
||||
```
|
||||
$ bower install ripple
|
||||
```
|
||||
|
||||
See the [bower-ripple repo](https://github.com/ripple/bower-ripple) for additional bower instructions
|
||||
|
||||
|
||||
**Building ripple-lib from github**
|
||||
|
||||
```
|
||||
$ git clone https://github.com/ripple/ripple-lib
|
||||
$ npm install
|
||||
$ grunt
|
||||
$ npm run build
|
||||
```
|
||||
|
||||
Then use the minified `build/ripple-*-min.js` in your webpage
|
||||
Then use the minified `build/ripple-*-min.js`
|
||||
|
||||
##Quickstart
|
||||
|
||||
`Remote` ([remote.js](https://github.com/ripple/ripple-lib/blob/develop/src/js/ripple/remote.js)) is the module responsible for managing connections to `rippled` servers:
|
||||
`Remote.js` ([remote.js](https://github.com/ripple/ripple-lib/blob/develop/src/js/ripple/remote.js)) is the point of entry for interacting with rippled
|
||||
|
||||
```js
|
||||
/* Loading ripple-lib with Node.js */
|
||||
@@ -62,35 +70,24 @@ var Remote = require('ripple-lib').Remote;
|
||||
|
||||
var remote = new Remote({
|
||||
// see the API Reference for available options
|
||||
trusted: true,
|
||||
local_signing: true,
|
||||
local_fee: true,
|
||||
fee_cushion: 1.5,
|
||||
servers: [
|
||||
{
|
||||
host: 's1.ripple.com'
|
||||
, port: 443
|
||||
, secure: true
|
||||
}
|
||||
]
|
||||
servers: [ 'wss://s1.ripple.com:443' ]
|
||||
});
|
||||
|
||||
remote.connect(function() {
|
||||
/* remote connected */
|
||||
remote.request('server_info', function(err, info) {
|
||||
|
||||
// see the API Reference for available functions
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
See [The `ripple-lib` Guides](docs/GUIDES.md) and [The `ripple-lib` API Reference](docs/REFERENCE.md) for walkthroughs and details about all of the available functions and options.
|
||||
|
||||
##Running tests
|
||||
|
||||
1. Clone the repository
|
||||
|
||||
2. `cd` into the repository and install dependencies with `npm install`
|
||||
|
||||
3. `npm test` or `make test` or `node_modules\.bin\mocha test\*-test.js`
|
||||
3. `npm test` or `node_modules/.bin/mocha test/*-test.js`
|
||||
|
||||
**Generating code coverage**
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ function ready() {
|
||||
function print_usage() {
|
||||
console.log(
|
||||
'Usage: rsign.js <secret> <json>\n\n',
|
||||
'Example: rsign.js ssq55ueDob4yV3kPVnNQLHB6icwpC',
|
||||
'Example: rsign.js ssq55ueDob4yV3kPVnNQLHB6icwpC','\''+
|
||||
JSON.stringify({
|
||||
TransactionType: 'Payment',
|
||||
Account: 'r3P9vH81KBayazSTrQj6S25jW6kDb779Gi',
|
||||
@@ -64,7 +64,7 @@ function print_usage() {
|
||||
Amount: '200000000',
|
||||
Fee: '10',
|
||||
Sequence: 1
|
||||
})
|
||||
})+'\''
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
4550
build/sjcl.js
4550
build/sjcl.js
File diff suppressed because it is too large
Load Diff
163
docs/GUIDES.md
163
docs/GUIDES.md
@@ -1,26 +1,36 @@
|
||||
#`ripple-lib` Guides
|
||||
#Guides
|
||||
|
||||
This file provides step-by-step walkthroughs for some of the most common usages of `ripple-lib`.
|
||||
|
||||
###Guides in this document:
|
||||
###In this document
|
||||
|
||||
1. [Connecting to the Ripple network with `Remote`](GUIDES.md#1-connecting-to-the-ripple-network-with-remote)
|
||||
2. [Using `Remote` functions and `Request` objects](GUIDES.md#2-using-remote-functions-and-request-objects)
|
||||
3. [Submitting a payment to the network](GUIDES.md#3-submitting-a-payment-to-the-network)
|
||||
1. [Connecting to the Ripple network with `Remote`](GUIDES.md#connecting-to-the-ripple-network)
|
||||
2. [Using `Remote` functions and `Request` objects](GUIDES.md#sending-rippled-API-requests)
|
||||
3. [Listening to the network](GUIDES.md#listening-to-the-network)
|
||||
4. [Submitting a payment to the network](GUIDES.md#submitting-a-payment-to-the-network)
|
||||
* [A note on transaction fees](GUIDES.md#a-note-on-transaction-fees)
|
||||
4. [Submitting a trade offer to the network](GUIDES.md#4-submitting-a-trade-offer-to-the-network)
|
||||
5. [Listening to the network](GUIDES.md#5-listening-to-the-network)
|
||||
5. [Submitting a trade offer to the network](GUIDES.md#submitting-a-trade-offer-to-the-network)
|
||||
|
||||
###Also see
|
||||
|
||||
###Also see:
|
||||
1. [The ripple-lib README](../README.md)
|
||||
2. [The ripple-lib API Reference](REFERENCE.md)
|
||||
|
||||
1. [The `ripple-lib` README](../README.md)
|
||||
2. [The `ripple-lib` API Reference](REFERENCE.md)
|
||||
##Generating a new Ripple Wallet
|
||||
|
||||
##1. Connecting to the Ripple network with `Remote`
|
||||
```js
|
||||
var Wallet = require('ripple-lib').Wallet;
|
||||
|
||||
1. [Get `ripple-lib`](README.md#getting-ripple-lib)
|
||||
2. Load the `ripple-lib` module into a Node.js file or webpage:
|
||||
var wallet = Wallet.generate();
|
||||
console.log(wallet);
|
||||
// { address: 'rEf4sbVobiiDGExrNj2PkNHGMA8eS6jWh3',
|
||||
// secret: 'shFh4a38EZpEdZxrLifEnVPAoBRce' }
|
||||
```
|
||||
|
||||
##Connecting to the Ripple network
|
||||
|
||||
1. [Get ripple-lib](README.md#getting-ripple-lib)
|
||||
2. Load the ripple-lib module into a Node.js file or webpage:
|
||||
```js
|
||||
/* Loading ripple-lib with Node.js */
|
||||
var Remote = require('ripple-lib').Remote;
|
||||
@@ -37,32 +47,36 @@ This file provides step-by-step walkthroughs for some of the most common usages
|
||||
});
|
||||
```
|
||||
__NOTE:__ See the API Reference for available [`Remote` options](REFERENCE.md#1-remote-options)
|
||||
|
||||
4. You're connected! Read on to see what to do now.
|
||||
|
||||
|
||||
##2. Using `Remote` functions and `Request` objects
|
||||
##Sending rippled API requests
|
||||
|
||||
All `Remote` functions return a `Request` object.
|
||||
`Remote` contains functions for constructing a `Request` object.
|
||||
|
||||
A `Request` is an `EventEmitter` so you can listen for success or failure events -- or, instead, you can provide a callback to the `Remote` function.
|
||||
A `Request` is an `EventEmitter` so you can listen for success or failure events -- or, instead, you can provide a callback.
|
||||
|
||||
Here is an example, using `request_server_info()`, of how `Remote` functions can be used with event listeners (the first code block) or with a callback (the second block):
|
||||
Here is an example, using [request_server_info](https://ripple.com/wiki/JSON_Messages#server_info).
|
||||
|
||||
+ Using a `Remote` function with `Request` event listeners:
|
||||
+ Constructing a `Request` with event listeners
|
||||
```js
|
||||
var request = remote.request_server_info();
|
||||
request.on('success', function(res) {
|
||||
var request = remote.request('server_info');
|
||||
|
||||
request.on('success', function onSuccess(res) {
|
||||
//handle success
|
||||
});
|
||||
request.on('error', function(err) {
|
||||
|
||||
request.on('error', function onError(err) {
|
||||
//handle error
|
||||
});
|
||||
request.request(); // this triggers the request if it has not already been sent to the server
|
||||
|
||||
request.request();
|
||||
```
|
||||
|
||||
+ Using a `Remote` function with a callback:
|
||||
+ Using a callback:
|
||||
```js
|
||||
remote.request_server_info(function(err, res) {
|
||||
remote.request('server_info', function(err, res) {
|
||||
if (err) {
|
||||
//handle error
|
||||
} else {
|
||||
@@ -74,9 +88,44 @@ remote.request_server_info(function(err, res) {
|
||||
__NOTE:__ See the API Reference for available [`Remote` functions](REFERENCE.md#2-remote-functions)
|
||||
|
||||
|
||||
##Listening to the network
|
||||
|
||||
See the [wiki](https://ripple.com/wiki/JSON_Messages#subscribe) for details on subscription requests.
|
||||
|
||||
##3. Submitting a payment to the network
|
||||
```js
|
||||
/* Loading ripple-lib with Node.js */
|
||||
var Remote = require('ripple-lib').Remote;
|
||||
|
||||
/* Loading ripple-lib in a webpage */
|
||||
// var Remote = ripple.Remote;
|
||||
|
||||
var remote = new Remote({options});
|
||||
|
||||
remote.connect(function() {
|
||||
var request = remote.request('subscribe');
|
||||
|
||||
request.addStream('ledger'); //remote will emit `ledger_closed`
|
||||
request.addStream('transactions'); //remote will emit `transaction`
|
||||
|
||||
request.on('ledger_closed', function onLedgerClosed(ledgerData) {
|
||||
//handle ledger
|
||||
});
|
||||
|
||||
request.on('transaction', function onTransacstion(transaction) {
|
||||
//handle transaction
|
||||
});
|
||||
|
||||
request.request(function(err) {
|
||||
if (err) {
|
||||
} else {
|
||||
}
|
||||
});
|
||||
});
|
||||
```
|
||||
* https://ripple.com/wiki/RPC_API#transactions_stream_messages
|
||||
* https://ripple.com/wiki/RPC_API#ledger_stream_messages
|
||||
|
||||
##Submitting a payment to the network
|
||||
|
||||
Submitting a payment transaction to the Ripple network involves connecting to a `Remote`, creating a transaction, signing it with the user's secret, and submitting it to the `rippled` server. Note that the `Amount` module is used to convert human-readable amounts like '1XRP' or '10.50USD' to the type of Amount object used by the Ripple network.
|
||||
|
||||
@@ -97,13 +146,11 @@ var AMOUNT = Amount.from_human('1XRP');
|
||||
var remote = new Remote({ /* Remote options */ });
|
||||
|
||||
remote.connect(function() {
|
||||
remote.set_secret(MY_ADDRESS, MY_SECRET);
|
||||
remote.setSecret(MY_ADDRESS, MY_SECRET);
|
||||
|
||||
var transaction = remote.transaction();
|
||||
|
||||
transaction.payment({
|
||||
from: MY_ADDRESS,
|
||||
to: RECIPIENT,
|
||||
var transaction = remote.createTransaction('Payment', {
|
||||
account: MY_ADDRESS,
|
||||
destination: RECIPIENT,
|
||||
amount: AMOUNT
|
||||
});
|
||||
|
||||
@@ -139,27 +186,17 @@ var Amount = require('ripple-lib').Amount;
|
||||
|
||||
var MY_ADDRESS = 'rrrMyAddress';
|
||||
var MY_SECRET = 'secret';
|
||||
|
||||
var BUY_AMOUNT = Amount.from_human('100XRP');
|
||||
var SELL_AMOUNT = Amount.from_human('1USD');
|
||||
|
||||
// EXPIRATION must be a Date object, leave undefined to submit offer that won't expire
|
||||
var now = new Date();
|
||||
var tomorrow = new Date(now.getTime() + (24 * 60 * 60 * 1000));
|
||||
var EXPIRATION = tomorrow;
|
||||
var GATEWAY = 'rrrGateWay';
|
||||
|
||||
var remote = new Remote({ /* Remote options */ });
|
||||
|
||||
remote.connect(function() {
|
||||
remote.set_secret(MY_ADDRESS, MY_SECRET);
|
||||
remote.setSecret(MY_ADDRESS, MY_SECRET);
|
||||
|
||||
var transaction = remote.transaction();
|
||||
|
||||
transaction.offer_create({
|
||||
from: MY_ADDRESS,
|
||||
buy: BUY_AMOUNT,
|
||||
sell: SELL_AMOUNT,
|
||||
expiration: EXPIRATION
|
||||
var transaction = remote.createTransaction('OfferCreate', {
|
||||
account: MY_ADDRESS,
|
||||
taker_pays: '1',
|
||||
taker_gets: '1/USD/' + GATEWAY
|
||||
});
|
||||
|
||||
transaction.submit(function(err, res) {
|
||||
@@ -167,35 +204,3 @@ remote.connect(function() {
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
##5. Listening to the network
|
||||
|
||||
In some (relatively rare) cases you may want to subscribe to the network event feed and listen for transactions and the ledger closings. [Ripple.com](http://www.ripple.com) uses this feature of `ripple-lib` to display the live feed on the top of each page and the ledger closing visualization on the [Developers page](http://ripple.com/devs).
|
||||
|
||||
```js
|
||||
/* Loading ripple-lib with Node.js */
|
||||
var Remote = require('ripple-lib').Remote;
|
||||
|
||||
/* Loading ripple-lib in a webpage */
|
||||
// var Remote = ripple.Remote;
|
||||
|
||||
var remote = new Remote({options});
|
||||
|
||||
remote.connect(function() {
|
||||
remote.on('transaction_all', transactionListener);
|
||||
remote.on('ledger_closed', ledgerListener);
|
||||
});
|
||||
|
||||
function transactionListener (transaction_data) {
|
||||
// handle transaction_data
|
||||
// see https://ripple.com/wiki/RPC_API#transactions_stream_messages for the format of transaction_data
|
||||
}
|
||||
|
||||
function ledgerListener (ledger_data) {
|
||||
// handle ledger_data
|
||||
// see https://ripple.com/wiki/RPC_API#ledger_stream_messages for the format of ledger_data
|
||||
}
|
||||
```
|
||||
* https://ripple.com/wiki/RPC_API#transactions_stream_messages
|
||||
* https://ripple.com/wiki/RPC_API#ledger_stream_messages
|
||||
|
||||
|
||||
@@ -1,28 +1,26 @@
|
||||
#`ripple-lib` API Reference
|
||||
#API Reference
|
||||
|
||||
__(More examples coming soon!)__
|
||||
|
||||
###In this document:
|
||||
|
||||
1. [`Remote` options](REFERENCE.md#1-remote-options)
|
||||
2. [`Remote` functions](REFERENCE.md#2-remote-functions)
|
||||
+ [Server info functions](REFERENCE.md#server-info-functions)
|
||||
+ [Ledger query functions](REFERENCE.md#ledger-query-functions)
|
||||
+ [Transaction query functions](REFERENCE.md#transaction-query-functions)
|
||||
+ [Account query functions](REFERENCE.md#account-query-functions)
|
||||
+ [Order book query functions](REFERENCE.md#order-book-query-functions)
|
||||
+ [Transaction submission functions](REFERENCE.md#transaction-submission-functions)
|
||||
3. [`Transaction` events](REFERENCE.md#3-transaction-events)
|
||||
4. [`Amount` objects](REFERENCE.md#4-amount-objects)
|
||||
|
||||
1. [`Remote` options](REFERENCE.md#remote-options)
|
||||
2. [`Request` constructors](REFERENCE.md#request-constructor-functions)
|
||||
+ [Server requests](REFERENCE.md#server-requests)
|
||||
+ [Ledger requests](REFERENCE.md#ledger-requests)
|
||||
+ [Transaction requests](REFERENCE.md#transaction-requests)
|
||||
+ [Account requests](REFERENCE.md#account-requests)
|
||||
+ [Orderbook requests](REFERENCE.md#orderbook-requests)
|
||||
+ [Transaction requests](REFERENCE.md#transaction-requests)
|
||||
3. [`Transaction` constructors](REFERENCE.md#transaction-constructors)
|
||||
+ [Transaction events](REFERENCE.md#transaction-events)
|
||||
|
||||
###Also see:
|
||||
|
||||
1. [The `ripple-lib` README](../README.md)
|
||||
2. [The `ripple-lib` GUIDES](GUIDES.md)
|
||||
1. [The ripple-lib README](../README.md)
|
||||
2. [The ripple-lib GUIDES](GUIDES.md)
|
||||
|
||||
|
||||
#1. `Remote` options
|
||||
#Remote options
|
||||
|
||||
```js
|
||||
/* Loading ripple-lib with Node.js */
|
||||
@@ -31,98 +29,86 @@ var Remote = require('ripple-lib').Remote;
|
||||
/* Loading ripple-lib in a webpage */
|
||||
// var Remote = ripple.Remote;
|
||||
|
||||
var remote = new Remote({options});
|
||||
var options = { };
|
||||
|
||||
var remote = new Remote(options);
|
||||
```
|
||||
|
||||
A new `Remote` can be created with the following options:
|
||||
|
||||
+ `trace` Log all of the events emitted (boolean)
|
||||
+ `max_listeners` Set maxListeners for remote; prevents EventEmitter warnings (number)
|
||||
+ `connection_offset` Connect to remote servers on supplied interval (number in seconds)
|
||||
+ `trusted` truthy, if remote is trusted (boolean)
|
||||
+ `local_fee` Set whether the transaction fee range will be set locally (boolean, default is true, see [A note on transaction fees](GUIDES.md#a-note-on-transaction-fees))
|
||||
+ `fee_cushion` Extra fee multiplier to account for async fee changes (number, e.g. 1.5, see [A note on transaction fees](GUIDES.md#a-note-on-transaction-fees))
|
||||
+ `max_fee` Maximum acceptable transaction fee (number in [XRP drops](https://ripple.com/wiki/Ripple_credits#Notes_on_drops), see [A note on transaction fees](GUIDES.md#a-note-on-transaction-fees))
|
||||
+ `servers` Array of server objects of the following form:
|
||||
+ `trace` *boolean default: false* Log all of the events emitted
|
||||
+ `max_listeners` *number default: 0* Set maxListeners for servers
|
||||
+ `trusted` *boolean default: false*, if remote is trusted (boolean)
|
||||
+ `local_signing` *boolean default: true*
|
||||
+ `local_fee` *boolean default: true* Set whether the transaction fee range will be set locally, see [A note on transaction fees](GUIDES.md#a-note-on-transaction-fees))
|
||||
+ `fee_cushion` *number default: 1.2* Extra fee multiplier to account for async fee changes, see [A note on transaction fees](GUIDES.md#a-note-on-transaction-fees))
|
||||
+ `max_fee` *number default: Infinity* Maximum acceptable transaction fee, see [A note on transaction fees](GUIDES.md#a-note-on-transaction-fees)
|
||||
+ `servers` *array* Array of server objects of the following form:
|
||||
|
||||
```js
|
||||
{
|
||||
host: <string>
|
||||
, port: <number>
|
||||
, secure: <boolean>
|
||||
{
|
||||
host: <string>,
|
||||
port: <number>,
|
||||
secure: <boolean>
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
#2. `Remote` functions
|
||||
|
||||
|
||||
|
||||
##Server info functions
|
||||
|
||||
**[request_server_info([callback])](https://ripple.com/wiki/RPC_API#server_info)**
|
||||
|
||||
Returns information about the state of the server. If you are connected to multiple servers and want to select by a particular host, use `request.set_server`. Example:
|
||||
or
|
||||
|
||||
```js
|
||||
var request = remote.request_server_info();
|
||||
request.set_server('my.hostname');
|
||||
request.callback(function(err, res) {
|
||||
|
||||
});
|
||||
request.request();
|
||||
'wss://host:port'
|
||||
```
|
||||
|
||||
**[request_unl_list([callback])](https://ripple.com/wiki/RPC_API#unl_list)**
|
||||
#Request constructor functions
|
||||
|
||||
**[request_unl_add(addr, comment, [callback])](https://ripple.com/wiki/RPC_API#unl_add)**
|
||||
##Server requests
|
||||
|
||||
**[request_unl_delete(node, [callback])](https://ripple.com/wiki/RPC_API#unl_delete)**
|
||||
**[server_info([callback])](https://ripple.com/wiki/JSON_Messages#server_info)**
|
||||
|
||||
**[request_peers([callback])](https://ripple.com/wiki/RPC_API#peers)**
|
||||
Returns information about the state of the server. If you are connected to multiple servers and want to select by a particular host, use `request.setServer`. Example:
|
||||
|
||||
```js
|
||||
var request = remote.request('server_info');
|
||||
|
||||
request.setServer('wss://s1.ripple.com');
|
||||
|
||||
request.request(function(err, res) {
|
||||
|
||||
});
|
||||
```
|
||||
|
||||
**[unl_list([callback])](https://ripple.com/wiki/JSON_Messages#unl_list)**
|
||||
|
||||
**[unl_add(addr, comment, [callback])](https://ripple.com/wiki/JSON_Messages#unl_add)**
|
||||
|
||||
**[unl_delete(node, [callback])](https://ripple.com/wiki/JSON_Messages#unl_delete)**
|
||||
|
||||
**[requestPeers([callback])](https://ripple.com/wiki/JSON_Messages#peers)**
|
||||
|
||||
|
||||
**[request_connect(ip, port, [callback])](https://ripple.com/wiki/RPC_API#connect)**
|
||||
**[connect(ip, port, [callback])](https://ripple.com/wiki/JSON_Messages#connect)**
|
||||
|
||||
##Ledger requests
|
||||
|
||||
**[ledger(ledger, [opts], [callback])](https://ripple.com/wiki/JSON_Messages#ledger)**
|
||||
|
||||
##Ledger query functions
|
||||
**ledger_header([callback])**
|
||||
|
||||
**[request_ledger(ledger, [opts], [callback])](https://ripple.com/wiki/RPC_API#ledger)**
|
||||
**[ledger_current([callback])](https://ripple.com/wiki/JSON_Messages#ledger_current)**
|
||||
|
||||
**request_ledger_header([callback])**
|
||||
**[ledger_entry(type, [callback])](https://ripple.com/wiki/JSON_Messages#ledger_entry)**
|
||||
|
||||
**[request_ledger_current([callback])](https://ripple.com/wiki/RPC_API#ledger_current)**
|
||||
|
||||
**[request_ledger_entry(type, [callback])](https://ripple.com/wiki/RPC_API#ledger_entry)**
|
||||
|
||||
**[request_subscribe(streams, [callback])](https://ripple.com/wiki/RPC_API#subscribe)**
|
||||
**[subscribe([streams], [callback])](https://ripple.com/wiki/JSON_Messages#subscribe)**
|
||||
|
||||
Start receiving selected streams from the server.
|
||||
|
||||
**[request_unsubscribe(streams, [callback])](https://ripple.com/wiki/RPC_API#unsubscribe)**
|
||||
**[unsubscribe([streams], [callback])](https://ripple.com/wiki/JSON_Messages#unsubscribe)**
|
||||
|
||||
Stop receiving selected streams from the server.
|
||||
|
||||
##Account requests
|
||||
|
||||
|
||||
|
||||
##Transaction query functions
|
||||
|
||||
**[request_transaction_entry(hash, [ledger_hash], [callback])](https://ripple.com/wiki/RPC_API#transaction_entry)**
|
||||
|
||||
Searches a particular ledger for a transaction hash. Default ledger is the open ledger.
|
||||
|
||||
**[request_tx(hash, [callback])](https://ripple.com/wiki/RPC_API#tx)**
|
||||
|
||||
Searches ledger history for validated transaction hashes.
|
||||
|
||||
|
||||
|
||||
|
||||
##Account query functions
|
||||
|
||||
**[request_account_info(account, [callback])](https://ripple.com/wiki/RPC_API#account_info)**
|
||||
**[account_info(account, [callback])](https://ripple.com/wiki/JSON_Messages#account_info)**
|
||||
|
||||
Return information about the specified account.
|
||||
|
||||
@@ -143,21 +129,21 @@ Return information about the specified account.
|
||||
}
|
||||
```
|
||||
|
||||
**[request_account_lines(accountID, account_index, current, [callback])](https://ripple.com/wiki/RPC_API#account_lines)**
|
||||
**[account_lines(accountID, [account_index], [ledger], [callback])](https://ripple.com/wiki/JSON_Messages#account_lines)**
|
||||
|
||||
**[request_account_offers(accountID, account_index, current, [callback])](https://ripple.com/wiki/RPC_API#account_offers)**
|
||||
**[account_offers(accountID, [account_index], [ledger], [callback])](https://ripple.com/wiki/JSON_Messages#account_offers)**
|
||||
|
||||
Return the specified account's outstanding offers.
|
||||
|
||||
**[request_account_tx(opts, [callback])](https://ripple.com/wiki/RPC_API#account_tx)**
|
||||
**[account_tx(options, [callback])](https://ripple.com/wiki/JSON_Messages#account_tx)**
|
||||
|
||||
Fetch a list of transactions that applied to this account.
|
||||
|
||||
Options:
|
||||
|
||||
+ `account`
|
||||
+ `ledger_index_min` *deprecated, -1*
|
||||
+ `ledger_index_max` *deprecated, -1*
|
||||
+ `ledger_index_min`
|
||||
+ `ledger_index_max`
|
||||
+ `binary` *false*
|
||||
+ `count` *false*
|
||||
+ `descending` *false*
|
||||
@@ -167,92 +153,150 @@ Options:
|
||||
+ `fwd_marker`
|
||||
+ `rev_marker`
|
||||
|
||||
**[request_wallet_accounts(seed, [callback])](https://ripple.com/wiki/RPC_API#wallet_accounts)**
|
||||
**[wallet_accounts(seed, [callback])](https://ripple.com/wiki/JSON_Messages#wallet_accounts)**
|
||||
|
||||
Return a list of accounts for a wallet.
|
||||
Return a list of accounts for a wallet. *Requires trusted remote*
|
||||
|
||||
+ requires trusted remote
|
||||
|
||||
**request_account_balance(account, ledger, [callback])**
|
||||
**account_balance(account, [ledger], [callback])**
|
||||
|
||||
Get the balance for an account. Returns an [Amount](https://github.com/ripple/ripple-lib/blob/develop/src/js/ripple/amount.js) object.
|
||||
|
||||
**request_account_flags(account, current, [callback])**
|
||||
**account_flags(account, [ledger], [callback])**
|
||||
|
||||
Return the flags for an account.
|
||||
|
||||
**request_owner_count(account, current, [callback])**
|
||||
**owner_count(account, [ledger], [callback])**
|
||||
|
||||
Return the owner count for an account.
|
||||
|
||||
**request_ripple_balance(account, issuer, currency, current, [callback])**
|
||||
**ripple_balance(account, issuer, currency, [ledger], [callback])**
|
||||
|
||||
Return a request to get a ripple balance
|
||||
|
||||
##Orderbook requests
|
||||
|
||||
**[book_offers(options, [callback])](https://ripple.com/wiki/JSON_Messages#book_offers)**
|
||||
|
||||
|
||||
##Order book query functions
|
||||
|
||||
**[request_book_offers(gets, pays, taker, [callback])](https://ripple.com/wiki/RPC_API#book_offers)**
|
||||
|
||||
Return the offers for an order book as one or more pages.
|
||||
Return the offers for an order book, also called a *snapshot*
|
||||
|
||||
```js
|
||||
var request = remote.request_book_offers({
|
||||
gets: {
|
||||
var request = remote.request('book_offers', {
|
||||
taker_gets: {
|
||||
'currency':'XRP'
|
||||
},
|
||||
pays: {
|
||||
taker_pays: {
|
||||
'currency':'USD',
|
||||
'issuer': 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
|
||||
}
|
||||
});
|
||||
|
||||
request.request();
|
||||
request.request(function(err, offers) {
|
||||
//handle offers
|
||||
});
|
||||
```
|
||||
|
||||
##Transaction requests
|
||||
|
||||
**[transaction_entry(hash, [ledger_hash], [callback])](https://ripple.com/wiki/JSON_Messages#transaction_entry)**
|
||||
|
||||
Searches a particular ledger for a transaction hash. Default ledger is the open ledger.
|
||||
|
||||
##Transaction submission functions
|
||||
**[tx(hash, [callback])](https://ripple.com/wiki/JSON_Messages#tx)**
|
||||
|
||||
**[request_sign(secret, tx_json, [callback])](https://ripple.com/wiki/RPC_API#sign)**
|
||||
Searches ledger history for validated transaction hashes.
|
||||
|
||||
Sign a transaction.
|
||||
**[sign(secret, tx_json, [callback])](https://ripple.com/wiki/JSON_Messages#sign)**
|
||||
|
||||
+ requires trusted remote
|
||||
Sign a transaction. *Requires trusted remote*
|
||||
|
||||
**[request_submit([callback])](https://ripple.com/wiki/RPC_API#submit)**
|
||||
**[submit([callback])](https://ripple.com/wiki/JSON_Messages#submit)**
|
||||
|
||||
Submit a transaction to the network. This command is used internally to submit transactions with a greater degree of reliability. See [Submitting a payment to the network](GUIDES.md#3-submitting-a-payment-to-the-network) for details.
|
||||
|
||||
**[ripple_path_find(src_account, dst_account, dst_amount, src_currencies, [callback])](https://ripple.com/wiki/JSON_Messages#path_find)**
|
||||
|
||||
**[request_ripple_path_find(src_account, dst_account, dst_amount, src_currencies, [callback])](https://ripple.com/wiki/RPC_API#path_find)**
|
||||
#Transaction constructors
|
||||
|
||||
Use `remote.createTransaction('TransactionType', [options])` to construct a transaction. To submit, use `transaction.submit([callback])`.
|
||||
|
||||
**transaction([destination], [source], [amount], [callback])**
|
||||
**Payment**
|
||||
|
||||
Returns a [Transaction](https://github.com/ripple/ripple-lib/blob/develop/src/js/ripple/transaction.js) object
|
||||
```js
|
||||
var transaction = remote.createTransaction('Payment', {
|
||||
account: MY_ADDRESS,
|
||||
destination: DEST_ADDRESS,
|
||||
amount: AMOUNT
|
||||
});
|
||||
```
|
||||
|
||||
**AccountSet**
|
||||
|
||||
#3. Transaction events
|
||||
```js
|
||||
var transaction = remote.createTransaction('AccountSet', {
|
||||
account: MY_ADDRESS,
|
||||
set: 'RequireDest',
|
||||
clear: 'RequireAuth'
|
||||
});
|
||||
```
|
||||
|
||||
**TrustSet**
|
||||
|
||||
```js
|
||||
var transaction = remote.createTransaction('TrustSet', {
|
||||
account: MY_ADDRESS,
|
||||
limit: '1/USD/rrrrrrrrrrrrrrrrrrrrBZbvji'
|
||||
});
|
||||
```
|
||||
|
||||
**OfferCreate**
|
||||
|
||||
```js
|
||||
var transaction = remote.createTransaction('OfferCreate', {
|
||||
account: MY_ADDRESS,
|
||||
taker_pays: '1',
|
||||
taker_gets: '1/USD/rrrrrrrrrrrrrrrrrrrrBZbvji'
|
||||
});
|
||||
```
|
||||
|
||||
##Transaction events
|
||||
|
||||
[Transaction](https://github.com/ripple/ripple-lib/blob/develop/src/js/ripple/transaction.js) objects are EventEmitters. They may emit the following events.
|
||||
|
||||
+ `final` Transaction has erred or succeeded. This event indicates that the transaction has finished processing.
|
||||
+ `error` Transaction has erred. This event is a final state.
|
||||
+ `success` Transaction succeeded. This event is a final state.
|
||||
+ `presubmit` Immediately before transaction is submitted
|
||||
+ `postsubmit` Immediately after transaction is submitted
|
||||
+ `submitted` Transaction has been submitted to the network. The submission may result in a remote error or success.
|
||||
+ `resubmitted` Transaction is beginning resubmission.
|
||||
+ `proposed` Transaction has been submitted *successfully* to the network. The transaction at this point is awaiting validation in a ledger.
|
||||
+ `timeout` Transaction submission timed out. The transaction will be resubmitted.
|
||||
+ `resubmit` Transaction is beginning resubmission.
|
||||
+ `fee_adjusted` Transaction fee has been adjusted during its pending state. The transaction fee will only be adjusted if the remote is configured for local fees, which it is by default.
|
||||
+ `abort` Transaction has been aborted. Transactions are only aborted by manual calls to `#abort`.
|
||||
+ `missing` Four ledgers have closed without detecting validated transaction
|
||||
+ `lost` Eight ledgers have closed without detecting validated transaction. Consider the transaction lost and err/finalize.
|
||||
|
||||
##Complete payment example
|
||||
|
||||
#4. Amount objects
|
||||
```js
|
||||
remote.setSecret(MY_ADDRESS, MY_SECRET);
|
||||
|
||||
var transaction = remote.createTransaction('Payment', {
|
||||
account: MY_ADDRESS,
|
||||
destination: DEST_ADDRESS,
|
||||
amount: AMOUNT
|
||||
});
|
||||
|
||||
transaction.on('resubmitted', function() {
|
||||
// initial submission failed, resubmitting
|
||||
});
|
||||
|
||||
transaction.submit(function(err, res) {
|
||||
// submission has finalized with either an error or success.
|
||||
// the transaction will not be retried after this point
|
||||
});
|
||||
```
|
||||
|
||||
#Amount objects
|
||||
|
||||
Coming Soon
|
||||
|
||||
142
npm-shrinkwrap.json
generated
Normal file
142
npm-shrinkwrap.json
generated
Normal file
@@ -0,0 +1,142 @@
|
||||
{
|
||||
"name": "ripple-lib",
|
||||
"version": "0.9.0-rc5",
|
||||
"dependencies": {
|
||||
"async": {
|
||||
"version": "0.8.0",
|
||||
"from": "async@>=0.8.0 <0.9.0"
|
||||
},
|
||||
"extend": {
|
||||
"version": "1.2.1",
|
||||
"from": "extend@>=1.2.1 <1.3.0"
|
||||
},
|
||||
"lru-cache": {
|
||||
"version": "2.5.0",
|
||||
"from": "lru-cache@>=2.5.0 <2.6.0"
|
||||
},
|
||||
"ripple-wallet-generator": {
|
||||
"version": "1.0.1",
|
||||
"from": "ripple-wallet-generator@1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/ripple-wallet-generator/-/ripple-wallet-generator-1.0.1.tgz"
|
||||
},
|
||||
"superagent": {
|
||||
"version": "0.18.2",
|
||||
"from": "superagent@>=0.18.0 <0.19.0",
|
||||
"dependencies": {
|
||||
"qs": {
|
||||
"version": "0.6.6",
|
||||
"from": "qs@0.6.6",
|
||||
"resolved": "https://registry.npmjs.org/qs/-/qs-0.6.6.tgz"
|
||||
},
|
||||
"formidable": {
|
||||
"version": "1.0.14",
|
||||
"from": "formidable@1.0.14",
|
||||
"resolved": "https://registry.npmjs.org/formidable/-/formidable-1.0.14.tgz"
|
||||
},
|
||||
"mime": {
|
||||
"version": "1.2.11",
|
||||
"from": "mime@1.2.11",
|
||||
"resolved": "https://registry.npmjs.org/mime/-/mime-1.2.11.tgz"
|
||||
},
|
||||
"component-emitter": {
|
||||
"version": "1.1.2",
|
||||
"from": "component-emitter@1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.1.2.tgz"
|
||||
},
|
||||
"methods": {
|
||||
"version": "1.0.1",
|
||||
"from": "methods@1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/methods/-/methods-1.0.1.tgz"
|
||||
},
|
||||
"cookiejar": {
|
||||
"version": "2.0.1",
|
||||
"from": "cookiejar@2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/cookiejar/-/cookiejar-2.0.1.tgz"
|
||||
},
|
||||
"debug": {
|
||||
"version": "1.0.4",
|
||||
"from": "debug@>=1.0.1 <1.1.0",
|
||||
"dependencies": {
|
||||
"ms": {
|
||||
"version": "0.6.2",
|
||||
"from": "ms@0.6.2",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-0.6.2.tgz"
|
||||
}
|
||||
}
|
||||
},
|
||||
"reduce-component": {
|
||||
"version": "1.0.1",
|
||||
"from": "reduce-component@1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/reduce-component/-/reduce-component-1.0.1.tgz"
|
||||
},
|
||||
"form-data": {
|
||||
"version": "0.1.3",
|
||||
"from": "form-data@0.1.3",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-0.1.3.tgz",
|
||||
"dependencies": {
|
||||
"combined-stream": {
|
||||
"version": "0.0.5",
|
||||
"from": "combined-stream@>=0.0.4 <0.1.0",
|
||||
"dependencies": {
|
||||
"delayed-stream": {
|
||||
"version": "0.0.5",
|
||||
"from": "delayed-stream@0.0.5",
|
||||
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-0.0.5.tgz"
|
||||
}
|
||||
}
|
||||
},
|
||||
"async": {
|
||||
"version": "0.9.0",
|
||||
"from": "async@>=0.9.0 <0.10.0"
|
||||
}
|
||||
}
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "1.0.27-1",
|
||||
"from": "readable-stream@1.0.27-1",
|
||||
"dependencies": {
|
||||
"core-util-is": {
|
||||
"version": "1.0.1",
|
||||
"from": "core-util-is@>=1.0.0 <1.1.0"
|
||||
},
|
||||
"isarray": {
|
||||
"version": "0.0.1",
|
||||
"from": "isarray@0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz"
|
||||
},
|
||||
"string_decoder": {
|
||||
"version": "0.10.31",
|
||||
"from": "string_decoder@>=0.10.0 <0.11.0"
|
||||
},
|
||||
"inherits": {
|
||||
"version": "2.0.1",
|
||||
"from": "inherits@>=2.0.1 <2.1.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"ws": {
|
||||
"version": "0.4.32",
|
||||
"from": "ws@>=0.4.31 <0.5.0",
|
||||
"dependencies": {
|
||||
"commander": {
|
||||
"version": "2.1.0",
|
||||
"from": "commander@>=2.1.0 <2.2.0"
|
||||
},
|
||||
"nan": {
|
||||
"version": "1.0.0",
|
||||
"from": "nan@>=1.0.0 <1.1.0"
|
||||
},
|
||||
"tinycolor": {
|
||||
"version": "0.0.1",
|
||||
"from": "tinycolor@>=0.0.0 <1.0.0"
|
||||
},
|
||||
"options": {
|
||||
"version": "0.0.6",
|
||||
"from": "options@>=0.0.5"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
15
package.json
15
package.json
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "ripple-lib",
|
||||
"version": "0.7.37",
|
||||
"description": "Ripple JavaScript client library",
|
||||
"version": "0.9.2-rc3",
|
||||
"description": "A JavaScript API for interacting with Ripple in Node.js and the browser",
|
||||
"files": [
|
||||
"src/js/*",
|
||||
"bin/*",
|
||||
@@ -20,24 +20,27 @@
|
||||
"extend": "~1.2.1",
|
||||
"lru-cache": "~2.5.0",
|
||||
"superagent": "^0.18.0",
|
||||
"gulp-uglify": "~0.3.0",
|
||||
"gulp-rename": "~1.2.0"
|
||||
"ripple-wallet-generator": "1.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "~1.14.0",
|
||||
"gulp": "~3.6.2",
|
||||
"gulp-concat": "~2.2.0",
|
||||
"gulp-jshint": "~1.5.5",
|
||||
"gulp-uglify": "~0.3.0",
|
||||
"gulp-rename": "~1.2.0",
|
||||
"gulp-bump": "~0.1.10",
|
||||
"webpack": "~1.1.11",
|
||||
"map-stream": "~0.1.0",
|
||||
"istanbul": "~0.2.10",
|
||||
"coveralls": "~2.10.0",
|
||||
"nock": "^0.34.1"
|
||||
"nock": "^0.34.1",
|
||||
"yargs": "~1.3.1"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "node_modules/.bin/gulp",
|
||||
"pretest": "node_modules/.bin/gulp concat-sjcl",
|
||||
"test": "./node_modules/.bin/istanbul test -x build/sjcl.js -x src/js/jsbn/* ./node_modules/.bin/_mocha -- --reporter spec test/*-test.js",
|
||||
"test": "./node_modules/.bin/istanbul test -x build/sjcl.js -x src/js/jsbn/* ./node_modules/mocha/bin/_mocha -- --reporter spec test/*-test.js",
|
||||
"coveralls": "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls"
|
||||
},
|
||||
"repository": {
|
||||
|
||||
43
scripts/publish
Normal file
43
scripts/publish
Normal file
@@ -0,0 +1,43 @@
|
||||
echo "PUBLISH"
|
||||
|
||||
function exit_on_error {
|
||||
res=$?
|
||||
[[ ${res:-99} -eq 0 ]] || exit $res
|
||||
}
|
||||
|
||||
rm -rf build
|
||||
|
||||
npm install
|
||||
gulp
|
||||
npm test
|
||||
exit_on_error
|
||||
|
||||
echo ""
|
||||
echo "publish to npm"
|
||||
npm publish
|
||||
exit_on_error
|
||||
|
||||
rm -rf dist
|
||||
echo ""
|
||||
echo "publish to bower"
|
||||
|
||||
git clone git@github.com:ripple/bower-ripple.git dist
|
||||
gulp bower
|
||||
exit_on_error
|
||||
|
||||
cd dist
|
||||
version=$(cat bower.json | grep -Eo '([0-9]\.?)+(-rc[0-9])?')
|
||||
echo "version: $version"
|
||||
git add ripple.js ripple-debug.js ripple-min.js bower.json
|
||||
exit_on_error
|
||||
|
||||
git commit -m "[TASK] add v$version"
|
||||
exit_on_error
|
||||
|
||||
git tag "v$version"
|
||||
exit_on_error
|
||||
|
||||
git push origin master
|
||||
git push --tags origin master
|
||||
|
||||
cd ..
|
||||
43
scripts/publish_rc
Normal file
43
scripts/publish_rc
Normal file
@@ -0,0 +1,43 @@
|
||||
echo "PUBLISH RELEASE CANDIDATE"
|
||||
|
||||
function exit_on_error {
|
||||
res=$?
|
||||
[[ ${res:-99} -eq 0 ]] || exit $res
|
||||
}
|
||||
|
||||
rm -rf build
|
||||
|
||||
npm install
|
||||
gulp
|
||||
npm test
|
||||
exit_on_error
|
||||
|
||||
echo ""
|
||||
echo "publish rc to npm"
|
||||
npm publish --tag beta
|
||||
exit_on_error
|
||||
|
||||
rm -rf dist
|
||||
echo ""
|
||||
echo "publish to bower"
|
||||
|
||||
git clone git@github.com:ripple/bower-ripple.git dist
|
||||
gulp bower
|
||||
exit_on_error
|
||||
|
||||
cd dist
|
||||
version=$(cat bower.json | grep -Eo '([0-9]\.?)+(-rc[0-9])?')
|
||||
echo "version: $version"
|
||||
git add ripple.js ripple-debug.js ripple-min.js bower.json
|
||||
exit_on_error
|
||||
|
||||
git commit -m "[TASK] add v$version"
|
||||
exit_on_error
|
||||
|
||||
git tag "v$version"
|
||||
exit_on_error
|
||||
|
||||
git push origin master
|
||||
git push --tags origin master
|
||||
|
||||
cd ..
|
||||
12
scripts/publish_to_bower
Normal file
12
scripts/publish_to_bower
Normal file
@@ -0,0 +1,12 @@
|
||||
rm -rf dist
|
||||
git clone git@github.com:ripple/bower-ripple.git dist
|
||||
gulp bower
|
||||
cd dist
|
||||
version=$(cat bower.json | grep -Eo '([0-9]\.?)+(-rc[0-9])?')
|
||||
echo "version: $version"
|
||||
git add ripple.js ripple-debug.js ripple-min.js bower.json
|
||||
git commit -m "[TASK] add v$version"
|
||||
git tag "v$version"
|
||||
git push origin master
|
||||
git push --tags origin master
|
||||
cd ..
|
||||
@@ -174,8 +174,8 @@ Account.prototype.getNextSequence = function(callback) {
|
||||
|
||||
function accountInfo(err, info) {
|
||||
if (isNotFound(err)) {
|
||||
// New accounts will start out as sequence zero
|
||||
callback(null, 0);
|
||||
// New accounts will start out as sequence one
|
||||
callback(null, 1);
|
||||
} else if (err) {
|
||||
callback(err);
|
||||
} else {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Represent Ripple amounts and currencies.
|
||||
// - Numbers in hex are big-endian.
|
||||
|
||||
var extend = require('extend');
|
||||
var utils = require('./utils');
|
||||
var sjcl = utils.sjcl;
|
||||
var bn = sjcl.bn;
|
||||
@@ -11,7 +12,25 @@ var UInt160 = require('./uint160').UInt160;
|
||||
var Seed = require('./seed').Seed;
|
||||
var Currency = require('./currency').Currency;
|
||||
|
||||
var consts = exports.consts = {
|
||||
//
|
||||
// Amount class in the style of Java's BigInteger class
|
||||
// http://docs.oracle.com/javase/1.3/docs/api/java/math/BigInteger.html
|
||||
//
|
||||
|
||||
function Amount() {
|
||||
// Json format:
|
||||
// integer : XRP
|
||||
// { 'value' : ..., 'currency' : ..., 'issuer' : ...}
|
||||
|
||||
this._value = new BigInteger(); // NaN for bad value. Always positive.
|
||||
this._offset = 0; // Always 0 for XRP.
|
||||
this._is_native = true; // Default to XRP. Only valid if value is not NaN.
|
||||
this._is_negative = false;
|
||||
this._currency = new Currency();
|
||||
this._issuer = new UInt160();
|
||||
};
|
||||
|
||||
var consts = {
|
||||
currency_xns: 0,
|
||||
currency_one: 1,
|
||||
xns_precision: 6,
|
||||
@@ -32,26 +51,19 @@ var consts = exports.consts = {
|
||||
|
||||
cMinOffset: -96,
|
||||
cMaxOffset: 80,
|
||||
|
||||
// Maximum possible amount for non-XRP currencies using the maximum mantissa
|
||||
// with maximum exponent. Corresponds to hex 0xEC6386F26FC0FFFF.
|
||||
max_value: '9999999999999999e80',
|
||||
// Minimum possible amount for non-XRP currencies.
|
||||
min_value: '-1000000000000000e-96'
|
||||
};
|
||||
|
||||
// Add constants to Amount class
|
||||
extend(Amount, consts);
|
||||
|
||||
//
|
||||
// Amount class in the style of Java's BigInteger class
|
||||
// http://docs.oracle.com/javase/1.3/docs/api/java/math/BigInteger.html
|
||||
//
|
||||
|
||||
function Amount() {
|
||||
// Json format:
|
||||
// integer : XRP
|
||||
// { 'value' : ..., 'currency' : ..., 'issuer' : ...}
|
||||
|
||||
this._value = new BigInteger(); // NaN for bad value. Always positive.
|
||||
this._offset = 0; // Always 0 for XRP.
|
||||
this._is_native = true; // Default to XRP. Only valid if value is not NaN.
|
||||
this._is_negative = false;
|
||||
this._currency = new Currency();
|
||||
this._issuer = new UInt160();
|
||||
};
|
||||
// DEPRECATED: Use Amount instead, e.g. Amount.currency_xns
|
||||
exports.consts = consts;
|
||||
|
||||
// Given '100/USD/mtgox' return the a string with mtgox remapped.
|
||||
Amount.text_full_rewrite = function(j) {
|
||||
@@ -131,12 +143,12 @@ Amount.prototype.add = function(v) {
|
||||
var o2 = v._offset;
|
||||
|
||||
while (o1 < o2) {
|
||||
v1 = v1.divide(consts.bi_10);
|
||||
v1 = v1.divide(Amount.bi_10);
|
||||
o1 += 1;
|
||||
}
|
||||
|
||||
while (o2 < o1) {
|
||||
v2 = v2.divide(consts.bi_10);
|
||||
v2 = v2.divide(Amount.bi_10);
|
||||
o2 += 1;
|
||||
}
|
||||
|
||||
@@ -159,13 +171,245 @@ Amount.prototype.add = function(v) {
|
||||
return result;
|
||||
};
|
||||
|
||||
// Result in terms of this currency and issuer.
|
||||
Amount.prototype.subtract = function(v) {
|
||||
// Correctness over speed, less code has less bugs, reuse add code.
|
||||
return this.add(Amount.from_json(v).negate());
|
||||
};
|
||||
|
||||
// Result in terms of this' currency and issuer.
|
||||
// XXX Diverges from cpp.
|
||||
Amount.prototype.multiply = function(v) {
|
||||
var result;
|
||||
|
||||
v = Amount.from_json(v);
|
||||
|
||||
if (this.is_zero()) {
|
||||
result = this;
|
||||
} else if (v.is_zero()) {
|
||||
result = this.clone();
|
||||
result._value = BigInteger.ZERO;
|
||||
} else {
|
||||
var v1 = this._value;
|
||||
var o1 = this._offset;
|
||||
var v2 = v._value;
|
||||
var o2 = v._offset;
|
||||
|
||||
if (this.is_native()) {
|
||||
while (v1.compareTo(Amount.bi_man_min_value) < 0) {
|
||||
v1 = v1.multiply(Amount.bi_10);
|
||||
o1 -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (v.is_native()) {
|
||||
while (v2.compareTo(Amount.bi_man_min_value) < 0) {
|
||||
v2 = v2.multiply(Amount.bi_10);
|
||||
o2 -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
result = new Amount();
|
||||
result._offset = o1 + o2 + 14;
|
||||
result._value = v1.multiply(v2).divide(Amount.bi_1e14).add(Amount.bi_7);
|
||||
result._is_native = this._is_native;
|
||||
result._is_negative = this._is_negative !== v._is_negative;
|
||||
result._currency = this._currency;
|
||||
result._issuer = this._issuer;
|
||||
|
||||
result.canonicalize();
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
// Result in terms of this' currency and issuer.
|
||||
Amount.prototype.divide = function(d) {
|
||||
var result;
|
||||
|
||||
d = Amount.from_json(d);
|
||||
|
||||
if (d.is_zero()) {
|
||||
throw new Error('divide by zero');
|
||||
}
|
||||
|
||||
if (this.is_zero()) {
|
||||
result = this;
|
||||
} else if (!this.is_valid()) {
|
||||
throw new Error('Invalid dividend');
|
||||
} else if (!d.is_valid()) {
|
||||
throw new Error('Invalid divisor');
|
||||
} else {
|
||||
var _n = this;
|
||||
|
||||
if (_n.is_native()) {
|
||||
_n = _n.clone();
|
||||
|
||||
while (_n._value.compareTo(Amount.bi_man_min_value) < 0) {
|
||||
_n._value = _n._value.multiply(Amount.bi_10);
|
||||
_n._offset -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
var _d = d;
|
||||
|
||||
if (_d.is_native()) {
|
||||
_d = _d.clone();
|
||||
|
||||
while (_d._value.compareTo(Amount.bi_man_min_value) < 0) {
|
||||
_d._value = _d._value.multiply(Amount.bi_10);
|
||||
_d._offset -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
result = new Amount();
|
||||
result._offset = _n._offset - _d._offset - 17;
|
||||
result._value = _n._value.multiply(Amount.bi_1e17).divide(_d._value).add(Amount.bi_5);
|
||||
result._is_native = _n._is_native;
|
||||
result._is_negative = _n._is_negative !== _d._is_negative;
|
||||
result._currency = _n._currency;
|
||||
result._issuer = _n._issuer;
|
||||
|
||||
result.canonicalize();
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* This function calculates a ratio - such as a price - between two Amount
|
||||
* objects.
|
||||
*
|
||||
* The return value will have the same type (currency) as the numerator. This is
|
||||
* a simplification, which should be sane in most cases. For example, a USD/XRP
|
||||
* price would be rendered as USD.
|
||||
*
|
||||
* @example
|
||||
* var price = buy_amount.ratio_human(sell_amount);
|
||||
*
|
||||
* @this {Amount} The numerator (top half) of the fraction.
|
||||
* @param {Amount} denominator The denominator (bottom half) of the fraction.
|
||||
* @param opts Options for the calculation.
|
||||
* @param opts.reference_date {Date|Number} Date based on which demurrage/interest
|
||||
* should be applied. Can be given as JavaScript Date or int for Ripple epoch.
|
||||
* @return {Amount} The resulting ratio. Unit will be the same as numerator.
|
||||
*/
|
||||
|
||||
Amount.prototype.ratio_human = function(denominator, opts) {
|
||||
opts = extend({ }, opts);
|
||||
|
||||
var numerator = this;
|
||||
|
||||
if (typeof denominator === 'number' && parseInt(denominator, 10) === denominator) {
|
||||
// Special handling of integer arguments
|
||||
denominator = Amount.from_json(String(denominator) + '.0');
|
||||
} else {
|
||||
denominator = Amount.from_json(denominator);
|
||||
}
|
||||
|
||||
denominator = Amount.from_json(denominator);
|
||||
|
||||
// If either operand is NaN, the result is NaN.
|
||||
if (!numerator.is_valid() || !denominator.is_valid()) {
|
||||
return Amount.NaN();
|
||||
}
|
||||
|
||||
if (denominator.is_zero()) {
|
||||
return Amount.NaN();
|
||||
}
|
||||
|
||||
// Apply interest/demurrage
|
||||
//
|
||||
// We only need to apply it to the second factor, because the currency unit of
|
||||
// the first factor will carry over into the result.
|
||||
if (opts.reference_date) {
|
||||
denominator = denominator.applyInterest(opts.reference_date);
|
||||
}
|
||||
|
||||
// Special case: The denominator is a native (XRP) amount.
|
||||
//
|
||||
// In that case, it's going to be expressed as base units (1 XRP =
|
||||
// 10^xns_precision base units).
|
||||
//
|
||||
// However, the unit of the denominator is lost, so when the resulting ratio
|
||||
// is printed, the ratio is going to be too small by a factor of
|
||||
// 10^xns_precision.
|
||||
//
|
||||
// To compensate, we multiply the numerator by 10^xns_precision.
|
||||
if (denominator._is_native) {
|
||||
numerator = numerator.clone();
|
||||
numerator._value = numerator._value.multiply(Amount.bi_xns_unit);
|
||||
numerator.canonicalize();
|
||||
}
|
||||
|
||||
return numerator.divide(denominator);
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculate a product of two amounts.
|
||||
*
|
||||
* This function allows you to calculate a product between two amounts which
|
||||
* retains XRPs human/external interpretation (i.e. 1 XRP = 1,000,000 base
|
||||
* units).
|
||||
*
|
||||
* Intended use is to calculate something like: 10 USD * 10 XRP/USD = 100 XRP
|
||||
*
|
||||
* @example
|
||||
* var sell_amount = buy_amount.product_human(price);
|
||||
*
|
||||
* @see Amount#ratio_human
|
||||
*
|
||||
* @this {Amount} The first factor of the product.
|
||||
* @param {Amount} factor The second factor of the product.
|
||||
* @param opts Options for the calculation.
|
||||
* @param opts.reference_date {Date|Number} Date based on which demurrage/interest
|
||||
* should be applied. Can be given as JavaScript Date or int for Ripple epoch.
|
||||
* @return {Amount} The product. Unit will be the same as the first factor.
|
||||
*/
|
||||
Amount.prototype.product_human = function(factor, opts) {
|
||||
opts = opts || {};
|
||||
|
||||
if (typeof factor === 'number' && parseInt(factor, 10) === factor) {
|
||||
// Special handling of integer arguments
|
||||
factor = Amount.from_json(String(factor) + '.0');
|
||||
} else {
|
||||
factor = Amount.from_json(factor);
|
||||
}
|
||||
|
||||
// If either operand is NaN, the result is NaN.
|
||||
if (!this.is_valid() || !factor.is_valid()) {
|
||||
return Amount.NaN();
|
||||
}
|
||||
|
||||
// Apply interest/demurrage
|
||||
//
|
||||
// We only need to apply it to the second factor, because the currency unit of
|
||||
// the first factor will carry over into the result.
|
||||
if (opts.reference_date) {
|
||||
factor = factor.applyInterest(opts.reference_date);
|
||||
}
|
||||
|
||||
var product = this.multiply(factor);
|
||||
|
||||
// Special case: The second factor is a native (XRP) amount expressed as base
|
||||
// units (1 XRP = 10^xns_precision base units).
|
||||
//
|
||||
// See also Amount#ratio_human.
|
||||
if (factor._is_native) {
|
||||
product._value = product._value.divide(Amount.bi_xns_unit);
|
||||
product.canonicalize();
|
||||
}
|
||||
|
||||
return product;
|
||||
};
|
||||
|
||||
/**
|
||||
* Turn this amount into its inverse.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
Amount.prototype._invert = function() {
|
||||
this._value = consts.bi_1e32.divide(this._value);
|
||||
this._value = Amount.bi_1e32.divide(this._value);
|
||||
this._offset = -32 - this._offset;
|
||||
this.canonicalize();
|
||||
|
||||
@@ -182,6 +426,33 @@ Amount.prototype.invert = function() {
|
||||
return this.copy()._invert();
|
||||
};
|
||||
|
||||
/**
|
||||
* Canonicalize amount value
|
||||
*
|
||||
* Mirrors rippled's internal Amount representation
|
||||
* From https://github.com/ripple/rippled/blob/develop/src/ripple/data/protocol/STAmount.h#L31-L40
|
||||
*
|
||||
* Internal form:
|
||||
* 1: If amount is zero, then value is zero and offset is -100
|
||||
* 2: Otherwise:
|
||||
* legal offset range is -96 to +80 inclusive
|
||||
* value range is 10^15 to (10^16 - 1) inclusive
|
||||
* amount = value * [10 ^ offset]
|
||||
*
|
||||
* -------------------
|
||||
*
|
||||
* The amount can be epxresses as A x 10^B
|
||||
* Where:
|
||||
* - A must be an integer between 10^15 and (10^16)-1 inclusive
|
||||
* - B must be between -96 and 80 inclusive
|
||||
*
|
||||
* This results
|
||||
* - minumum: 10^15 x 10^-96 -> 10^-81 -> -1e-81
|
||||
* - maximum: (10^16)-1 x 10^80 -> 9999999999999999e80
|
||||
*
|
||||
* @returns {Amount}
|
||||
* @throws {Error} if offset exceeds legal ranges, meaning the amount value is bigger than supported
|
||||
*/
|
||||
Amount.prototype.canonicalize = function() {
|
||||
if (!(this._value instanceof BigInteger)) {
|
||||
// NaN.
|
||||
@@ -195,34 +466,43 @@ Amount.prototype.canonicalize = function() {
|
||||
// Normalize _offset to 0.
|
||||
|
||||
while (this._offset < 0) {
|
||||
this._value = this._value.divide(consts.bi_10);
|
||||
this._value = this._value.divide(Amount.bi_10);
|
||||
this._offset += 1;
|
||||
}
|
||||
|
||||
while (this._offset > 0) {
|
||||
this._value = this._value.multiply(consts.bi_10);
|
||||
this._value = this._value.multiply(Amount.bi_10);
|
||||
this._offset -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
// XXX Make sure not bigger than supported. Throw if so.
|
||||
} else if (this.is_zero()) {
|
||||
this._offset = -100;
|
||||
this._offset = Amount.cMinOffset;
|
||||
this._is_negative = false;
|
||||
} else {
|
||||
// Normalize mantissa to valid range.
|
||||
|
||||
while (this._value.compareTo(consts.bi_man_min_value) < 0) {
|
||||
this._value = this._value.multiply(consts.bi_10);
|
||||
while (this._value.compareTo(Amount.bi_man_min_value) < 0) {
|
||||
this._value = this._value.multiply(Amount.bi_10);
|
||||
this._offset -= 1;
|
||||
}
|
||||
|
||||
while (this._value.compareTo(consts.bi_man_max_value) > 0) {
|
||||
this._value = this._value.divide(consts.bi_10);
|
||||
while (this._value.compareTo(Amount.bi_man_max_value) > 0) {
|
||||
this._value = this._value.divide(Amount.bi_10);
|
||||
this._offset += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure not bigger than supported. Throw if so.
|
||||
if (this.is_negative() && this._offset < Amount.cMinOffset) {
|
||||
throw new Error('Exceeding min value of ' + Amount.min_value);
|
||||
}
|
||||
|
||||
// Make sure not smaller than supported. Throw if so.
|
||||
if (!this.is_negative() && this._offset > Amount.cMaxOffset) {
|
||||
throw new Error('Exceeding max value of ' + Amount.max_value);
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
@@ -233,6 +513,8 @@ Amount.prototype.clone = function(negate) {
|
||||
Amount.prototype.compareTo = function(v) {
|
||||
var result;
|
||||
|
||||
v = Amount.from_json(v);
|
||||
|
||||
if (!this.is_comparable(v)) {
|
||||
result = Amount.NaN();
|
||||
} else if (this._is_negative !== v._is_negative) {
|
||||
@@ -295,9 +577,7 @@ Amount.prototype.equals = function(d, ignore_issuer) {
|
||||
return this.equals(Amount.from_json(d));
|
||||
}
|
||||
|
||||
var result = true;
|
||||
|
||||
result = !((!this.is_valid() || !d.is_valid())
|
||||
var result = !((!this.is_valid() || !d.is_valid())
|
||||
|| (this._is_native !== d._is_native)
|
||||
|| (!this._value.equals(d._value) || this._offset !== d._offset)
|
||||
|| (this._is_negative !== d._is_negative)
|
||||
@@ -306,180 +586,6 @@ Amount.prototype.equals = function(d, ignore_issuer) {
|
||||
return result;
|
||||
};
|
||||
|
||||
// Result in terms of this' currency and issuer.
|
||||
Amount.prototype.divide = function(d) {
|
||||
var result;
|
||||
|
||||
if (d.is_zero()) {
|
||||
throw new Error('divide by zero');
|
||||
}
|
||||
|
||||
if (this.is_zero()) {
|
||||
result = this;
|
||||
} else if (!this.is_valid()) {
|
||||
throw new Error('Invalid dividend');
|
||||
} else if (!d.is_valid()) {
|
||||
throw new Error('Invalid divisor');
|
||||
} else {
|
||||
var _n = this;
|
||||
|
||||
if (_n.is_native()) {
|
||||
_n = _n.clone();
|
||||
|
||||
while (_n._value.compareTo(consts.bi_man_min_value) < 0) {
|
||||
_n._value = _n._value.multiply(consts.bi_10);
|
||||
_n._offset -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
var _d = d;
|
||||
|
||||
if (_d.is_native()) {
|
||||
_d = _d.clone();
|
||||
|
||||
while (_d._value.compareTo(consts.bi_man_min_value) < 0) {
|
||||
_d._value = _d._value.multiply(consts.bi_10);
|
||||
_d._offset -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
result = new Amount();
|
||||
result._offset = _n._offset - _d._offset - 17;
|
||||
result._value = _n._value.multiply(consts.bi_1e17).divide(_d._value).add(consts.bi_5);
|
||||
result._is_native = _n._is_native;
|
||||
result._is_negative = _n._is_negative !== _d._is_negative;
|
||||
result._currency = _n._currency;
|
||||
result._issuer = _n._issuer;
|
||||
|
||||
result.canonicalize();
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculate a ratio between two amounts.
|
||||
*
|
||||
* This function calculates a ratio - such as a price - between two Amount
|
||||
* objects.
|
||||
*
|
||||
* The return value will have the same type (currency) as the numerator. This is
|
||||
* a simplification, which should be sane in most cases. For example, a USD/XRP
|
||||
* price would be rendered as USD.
|
||||
*
|
||||
* @example
|
||||
* var price = buy_amount.ratio_human(sell_amount);
|
||||
*
|
||||
* @this {Amount} The numerator (top half) of the fraction.
|
||||
* @param {Amount} denominator The denominator (bottom half) of the fraction.
|
||||
* @param opts Options for the calculation.
|
||||
* @param opts.reference_date {Date|Number} Date based on which demurrage/interest
|
||||
* should be applied. Can be given as JavaScript Date or int for Ripple epoch.
|
||||
* @return {Amount} The resulting ratio. Unit will be the same as numerator.
|
||||
*/
|
||||
Amount.prototype.ratio_human = function(denominator, opts) {
|
||||
opts = opts || {};
|
||||
|
||||
if (typeof denominator === 'number' && parseInt(denominator, 10) === denominator) {
|
||||
// Special handling of integer arguments
|
||||
denominator = Amount.from_json('' + denominator + '.0');
|
||||
} else {
|
||||
denominator = Amount.from_json(denominator);
|
||||
}
|
||||
|
||||
var numerator = this;
|
||||
denominator = Amount.from_json(denominator);
|
||||
|
||||
// If either operand is NaN, the result is NaN.
|
||||
if (!numerator.is_valid() || !denominator.is_valid()) {
|
||||
return Amount.NaN();
|
||||
}
|
||||
|
||||
// Apply interest/demurrage
|
||||
//
|
||||
// We only need to apply it to the second factor, because the currency unit of
|
||||
// the first factor will carry over into the result.
|
||||
if (opts.reference_date) {
|
||||
denominator = denominator.applyInterest(opts.reference_date);
|
||||
}
|
||||
|
||||
// Special case: The denominator is a native (XRP) amount.
|
||||
//
|
||||
// In that case, it's going to be expressed as base units (1 XRP =
|
||||
// 10^xns_precision base units).
|
||||
//
|
||||
// However, the unit of the denominator is lost, so when the resulting ratio
|
||||
// is printed, the ratio is going to be too small by a factor of
|
||||
// 10^xns_precision.
|
||||
//
|
||||
// To compensate, we multiply the numerator by 10^xns_precision.
|
||||
if (denominator._is_native) {
|
||||
numerator = numerator.clone();
|
||||
numerator._value = numerator._value.multiply(consts.bi_xns_unit);
|
||||
numerator.canonicalize();
|
||||
}
|
||||
|
||||
return numerator.divide(denominator);
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculate a product of two amounts.
|
||||
*
|
||||
* This function allows you to calculate a product between two amounts which
|
||||
* retains XRPs human/external interpretation (i.e. 1 XRP = 1,000,000 base
|
||||
* units).
|
||||
*
|
||||
* Intended use is to calculate something like: 10 USD * 10 XRP/USD = 100 XRP
|
||||
*
|
||||
* @example
|
||||
* var sell_amount = buy_amount.product_human(price);
|
||||
*
|
||||
* @see Amount#ratio_human
|
||||
*
|
||||
* @this {Amount} The first factor of the product.
|
||||
* @param {Amount} factor The second factor of the product.
|
||||
* @param opts Options for the calculation.
|
||||
* @param opts.reference_date {Date|Number} Date based on which demurrage/interest
|
||||
* should be applied. Can be given as JavaScript Date or int for Ripple epoch.
|
||||
* @return {Amount} The product. Unit will be the same as the first factor.
|
||||
*/
|
||||
Amount.prototype.product_human = function(factor, opts) {
|
||||
opts = opts || {};
|
||||
|
||||
if (typeof factor === 'number' && parseInt(factor, 10) === factor) {
|
||||
// Special handling of integer arguments
|
||||
factor = Amount.from_json(String(factor) + '.0');
|
||||
} else {
|
||||
factor = Amount.from_json(factor);
|
||||
}
|
||||
|
||||
// If either operand is NaN, the result is NaN.
|
||||
if (!this.is_valid() || !factor.is_valid()) {
|
||||
return Amount.NaN();
|
||||
}
|
||||
|
||||
// Apply interest/demurrage
|
||||
//
|
||||
// We only need to apply it to the second factor, because the currency unit of
|
||||
// the first factor will carry over into the result.
|
||||
if (opts.reference_date) {
|
||||
factor = factor.applyInterest(opts.reference_date);
|
||||
}
|
||||
|
||||
var product = this.multiply(factor);
|
||||
|
||||
// Special case: The second factor is a native (XRP) amount expressed as base
|
||||
// units (1 XRP = 10^xns_precision base units).
|
||||
//
|
||||
// See also Amount#ratio_human.
|
||||
if (factor._is_native) {
|
||||
product._value = product._value.divide(consts.bi_xns_unit);
|
||||
product.canonicalize();
|
||||
}
|
||||
|
||||
return product;
|
||||
};
|
||||
|
||||
// True if Amounts are valid and both native or non-native.
|
||||
Amount.prototype.is_comparable = function(v) {
|
||||
return this._value instanceof BigInteger
|
||||
@@ -518,50 +624,6 @@ Amount.prototype.issuer = function() {
|
||||
return this._issuer;
|
||||
};
|
||||
|
||||
// Result in terms of this' currency and issuer.
|
||||
// XXX Diverges from cpp.
|
||||
Amount.prototype.multiply = function(v) {
|
||||
var result;
|
||||
|
||||
if (this.is_zero()) {
|
||||
result = this;
|
||||
} else if (v.is_zero()) {
|
||||
result = this.clone();
|
||||
result._value = BigInteger.ZERO;
|
||||
} else {
|
||||
var v1 = this._value;
|
||||
var o1 = this._offset;
|
||||
var v2 = v._value;
|
||||
var o2 = v._offset;
|
||||
|
||||
if (this.is_native()) {
|
||||
while (v1.compareTo(consts.bi_man_min_value) < 0) {
|
||||
v1 = v1.multiply(consts.bi_10);
|
||||
o1 -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (v.is_native()) {
|
||||
while (v2.compareTo(consts.bi_man_min_value) < 0) {
|
||||
v2 = v2.multiply(consts.bi_10);
|
||||
o2 -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
result = new Amount();
|
||||
result._offset = o1 + o2 + 14;
|
||||
result._value = v1.multiply(v2).divide(consts.bi_1e14).add(consts.bi_7);
|
||||
result._is_native = this._is_native;
|
||||
result._is_negative = this._is_negative !== v._is_negative;
|
||||
result._currency = this._currency;
|
||||
result._issuer = this._issuer;
|
||||
|
||||
result.canonicalize();
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
// Return a new value.
|
||||
Amount.prototype.negate = function() {
|
||||
return this.clone('NEGATE');
|
||||
@@ -598,30 +660,48 @@ Amount.prototype.invert = function() {
|
||||
* The regular expression below matches above cases, broken down for better understanding:
|
||||
*
|
||||
* ^\s* // start with any amount of whitespace
|
||||
* ([a-zA-Z]{3}|[0-9]{3}) // either 3 letter alphabetic currency-code or 3 digit numeric currency-code. See ISO 4217
|
||||
* ([A-z]{3}|[0-9]{3}) // either 3 letter alphabetic currency-code or 3 digit numeric currency-code. See ISO 4217
|
||||
* \s* // any amount of whitespace
|
||||
* (-)? // optional dash
|
||||
* (\d+) // 1 or more digits
|
||||
* (?:\.(\d*))? // optional . character with any amount of digits
|
||||
* \s* // any amount of whitespace
|
||||
* ([a-f0-9]{40}|[a-z0-9]{3})? // optional 40 character hex string OR 3 letters
|
||||
* ([A-z]{3}|[0-9]{3})? // either 3 letter alphabetic currency-code or 3 digit numeric currency-code. See ISO 4217
|
||||
* \s* // any amount of whitespace
|
||||
* $ // end of string
|
||||
*
|
||||
*/
|
||||
Amount.human_RE = /^\s*([a-z]{3}|[0-9]{3})?\s*(-)?(\d+)(?:\.(\d*))?\s*([a-f0-9]{40}|[a-z0-9]{3})?\s*$/i;
|
||||
Amount.human_RE_hex = /^\s*(-)?(\d+)(?:\.(\d*))?\s*([a-fA-F0-9]{40})\s*$/;
|
||||
Amount.human_RE = /^\s*([A-z]{3}|[0-9]{3})?\s*(-)?(\d+)(?:\.(\d*))?\s*([A-z]{3}|[0-9]{3})?\s*$/;
|
||||
|
||||
Amount.prototype.parse_human = function(j, opts) {
|
||||
opts = opts || {};
|
||||
|
||||
var m = String(j).match(Amount.human_RE);
|
||||
var integer;
|
||||
var fraction;
|
||||
var currency;
|
||||
var precision = null;
|
||||
|
||||
if (m) {
|
||||
var currency = m[1] || m[5] || 'XRP';
|
||||
var integer = m[3] || '0';
|
||||
var fraction = m[4] || '';
|
||||
var precision = null;
|
||||
// first check if it's a hex formatted currency
|
||||
var matches = String(j).match(Amount.human_RE_hex);
|
||||
if (matches && matches.length === 5 && matches[4]) {
|
||||
integer = matches[2];
|
||||
fraction = matches[3] || '';
|
||||
currency = matches[4];
|
||||
this._is_negative = Boolean(matches[1]);
|
||||
}
|
||||
|
||||
if (integer === void(0) && currency === void(0)) {
|
||||
var m = String(j).match(Amount.human_RE);
|
||||
if (m) {
|
||||
currency = m[5] || m[1] || 'XRP';
|
||||
integer = m[5] && m[1] ? m[1] + '' + m[3] : (m[3] || '0');
|
||||
fraction = m[4] || '';
|
||||
this._is_negative = Boolean(m[2]);
|
||||
}
|
||||
}
|
||||
|
||||
if (integer) {
|
||||
currency = currency.toUpperCase();
|
||||
|
||||
this._value = new BigInteger(integer);
|
||||
@@ -634,22 +714,20 @@ Amount.prototype.parse_human = function(j, opts) {
|
||||
fraction += '0';
|
||||
}
|
||||
this._is_native = true;
|
||||
this._value = this._value.multiply(consts.bi_xns_unit).add(new BigInteger(fraction));
|
||||
this._value = this._value.multiply(Amount.bi_xns_unit).add(new BigInteger(fraction));
|
||||
} else {
|
||||
// Other currencies have arbitrary precision
|
||||
fraction = fraction.replace(/0+$/, '');
|
||||
precision = fraction.length;
|
||||
|
||||
this._is_native = false;
|
||||
var multiplier = consts.bi_10.clone().pow(precision);
|
||||
var multiplier = Amount.bi_10.clone().pow(precision);
|
||||
this._value = this._value.multiply(multiplier).add(new BigInteger(fraction));
|
||||
this._offset = -precision;
|
||||
|
||||
this.canonicalize();
|
||||
}
|
||||
|
||||
this._is_negative = !!m[2];
|
||||
|
||||
// Apply interest/demurrage
|
||||
if (opts.reference_date && this._currency.has_interest()) {
|
||||
var interest = this._currency.get_interest_at(opts.reference_date);
|
||||
@@ -842,8 +920,8 @@ Amount.prototype.parse_native = function(j) {
|
||||
this._value = new BigInteger(m[2]);
|
||||
} else {
|
||||
// Float notation : values multiplied by 1,000,000.
|
||||
var int_part = (new BigInteger(m[2])).multiply(consts.bi_xns_unit);
|
||||
var fraction_part = (new BigInteger(m[3])).multiply(new BigInteger(String(Math.pow(10, 1+consts.xns_precision-m[3].length))));
|
||||
var int_part = (new BigInteger(m[2])).multiply(Amount.bi_xns_unit);
|
||||
var fraction_part = (new BigInteger(m[3])).multiply(new BigInteger(String(Math.pow(10, 1+Amount.xns_precision-m[3].length))));
|
||||
|
||||
this._value = int_part.add(fraction_part);
|
||||
}
|
||||
@@ -852,7 +930,7 @@ Amount.prototype.parse_native = function(j) {
|
||||
this._offset = 0;
|
||||
this._is_negative = !!m[1] && this._value.compareTo(BigInteger.ZERO) !== 0;
|
||||
|
||||
if (this._value.compareTo(consts.bi_xns_max) > 0) {
|
||||
if (this._value.compareTo(Amount.bi_xns_max) > 0) {
|
||||
this._value = NaN;
|
||||
}
|
||||
} else {
|
||||
@@ -894,7 +972,7 @@ Amount.prototype.parse_value = function(j) {
|
||||
var fraction = new BigInteger(d[3]);
|
||||
var precision = d[3].length;
|
||||
|
||||
this._value = integer.multiply(consts.bi_10.clone().pow(precision)).add(fraction);
|
||||
this._value = integer.multiply(Amount.bi_10.clone().pow(precision)).add(fraction);
|
||||
this._offset = -precision;
|
||||
this._is_negative = !!d[1];
|
||||
|
||||
@@ -935,12 +1013,6 @@ Amount.prototype.set_issuer = function(issuer) {
|
||||
return this;
|
||||
};
|
||||
|
||||
// Result in terms of this' currency and issuer.
|
||||
Amount.prototype.subtract = function(v) {
|
||||
// Correctness over speed, less code has less bugs, reuse add code.
|
||||
return this.add(Amount.from_json(v).negate());
|
||||
};
|
||||
|
||||
Amount.prototype.to_number = function(allow_nan) {
|
||||
var s = this.to_text(allow_nan);
|
||||
return typeof s === 'string' ? Number(s) : s;
|
||||
@@ -951,7 +1023,7 @@ Amount.prototype.to_text = function(allow_nan) {
|
||||
var result = NaN;
|
||||
|
||||
if (this._is_native) {
|
||||
if (this.is_valid() && this._value.compareTo(consts.bi_xns_max) <= 0){
|
||||
if (this.is_valid() && this._value.compareTo(Amount.bi_xns_max) <= 0){
|
||||
result = this._value.toString();
|
||||
}
|
||||
} else if (this.is_zero()) {
|
||||
@@ -1059,8 +1131,8 @@ Amount.prototype.to_human = function(opts) {
|
||||
ref = this.applyInterest(opts.reference_date);
|
||||
}
|
||||
|
||||
var order = ref._is_native ? consts.xns_precision : -ref._offset;
|
||||
var denominator = consts.bi_10.clone().pow(order);
|
||||
var order = ref._is_native ? Amount.xns_precision : -ref._offset;
|
||||
var denominator = Amount.bi_10.clone().pow(order);
|
||||
var int_part = ref._value.divide(denominator).toString();
|
||||
var fraction_part = ref._value.mod(denominator).toString();
|
||||
|
||||
@@ -1073,12 +1145,26 @@ Amount.prototype.to_human = function(opts) {
|
||||
fraction_part = fraction_part.replace(/0*$/, '');
|
||||
|
||||
if (fraction_part.length || !opts.skip_empty_fraction) {
|
||||
|
||||
// Enforce the maximum number of decimal digits (precision)
|
||||
if (typeof opts.precision === 'number') {
|
||||
if (opts.precision === 0 && fraction_part.charCodeAt(0) >= 53) {
|
||||
int_part = (Number(int_part) + 1).toString();
|
||||
if (opts.precision <= 0) {
|
||||
|
||||
// increment the int_part if the first decimal is 5 or higher
|
||||
if (fraction_part.charCodeAt(0) >= 53) {
|
||||
int_part = (Number(int_part) + 1).toString();
|
||||
}
|
||||
fraction_part = '';
|
||||
} else {
|
||||
var precision = Math.min(opts.precision, fraction_part.length);
|
||||
fraction_part = Math.round(fraction_part / Math.pow(10, fraction_part.length - precision)).toString();
|
||||
|
||||
// because the division above will cut off the leading 0's we have to add them back again
|
||||
// XXX look for a more elegant alternative
|
||||
while (fraction_part.length < precision) {
|
||||
fraction_part = '0' + fraction_part;
|
||||
}
|
||||
}
|
||||
fraction_part = fraction_part.slice(0, opts.precision);
|
||||
}
|
||||
|
||||
// Limit the number of significant digits (max_sig_digits)
|
||||
@@ -1143,7 +1229,7 @@ Amount.prototype.to_human_full = function(opts) {
|
||||
var a = this.to_human(opts);
|
||||
var c = this._currency.to_human();
|
||||
var i = this._issuer.to_json(opts);
|
||||
var o = this.is_native ? (o = a + '/' + c) : (o = a + '/' + c + '/' + i);
|
||||
var o = this.is_native() ? (o = a + '/' + c) : (o = a + '/' + c + '/' + i);
|
||||
return o;
|
||||
};
|
||||
|
||||
@@ -1155,7 +1241,7 @@ Amount.prototype.to_json = function() {
|
||||
} else {
|
||||
var amount_json = {
|
||||
value : this.to_text(),
|
||||
currency : this._currency.to_json()
|
||||
currency : this._currency.has_interest() ? this._currency.to_hex() : this._currency.to_json()
|
||||
};
|
||||
if (this._issuer.is_valid()) {
|
||||
amount_json.issuer = this._issuer.to_json();
|
||||
|
||||
@@ -382,23 +382,32 @@ exports.metadata = [
|
||||
];
|
||||
|
||||
exports.ter = {
|
||||
tesSUCCESS: 0,
|
||||
tecCLAIM: 100,
|
||||
tecPATH_PARTIAL: 101,
|
||||
tecUNFUNDED_ADD: 102,
|
||||
tecUNFUNDED_OFFER: 103,
|
||||
tecUNFUNDED_PAYMENT: 104,
|
||||
tecFAILED_PROCESSING: 105,
|
||||
tecDIR_FULL: 121,
|
||||
tecINSUF_RESERVE_LINE: 122,
|
||||
tecINSUF_RESERVE_OFFER: 123,
|
||||
tecNO_DST: 124,
|
||||
tecNO_DST_INSUF_XRP: 125,
|
||||
tecNO_LINE_INSUF_RESERVE: 126,
|
||||
tecNO_LINE_REDUNDANT: 127,
|
||||
tecPATH_DRY: 128,
|
||||
tecUNFUNDED: 129,
|
||||
tecMASTER_DISABLED: 130,
|
||||
tecNO_REGULAR_KEY: 131,
|
||||
tecOWNERS: 132
|
||||
tesSUCCESS : 0,
|
||||
tecCLAIM : 100,
|
||||
tecPATH_PARTIAL : 101,
|
||||
tecUNFUNDED_ADD : 102,
|
||||
tecUNFUNDED_OFFER : 103,
|
||||
tecUNFUNDED_PAYMENT : 104,
|
||||
tecFAILED_PROCESSING : 105,
|
||||
tecDIR_FULL : 121,
|
||||
tecINSUF_RESERVE_LINE : 122,
|
||||
tecINSUF_RESERVE_OFFER : 123,
|
||||
tecNO_DST : 124,
|
||||
tecNO_DST_INSUF_XRP : 125,
|
||||
tecNO_LINE_INSUF_RESERVE : 126,
|
||||
tecNO_LINE_REDUNDANT : 127,
|
||||
tecPATH_DRY : 128,
|
||||
tecUNFUNDED : 129, // Deprecated, old ambiguous unfunded.
|
||||
tecMASTER_DISABLED : 130,
|
||||
tecNO_REGULAR_KEY : 131,
|
||||
tecOWNERS : 132,
|
||||
tecNO_ISSUER : 133,
|
||||
tecNO_AUTH : 134,
|
||||
tecNO_LINE : 135,
|
||||
tecINSUFF_FEE : 136,
|
||||
tecFROZEN : 137,
|
||||
tecNO_TARGET : 138,
|
||||
tecNO_PERMISSION : 139,
|
||||
tecNO_ENTRY : 140,
|
||||
tecINSUFFICIENT_RESERVE : 141
|
||||
};
|
||||
|
||||
@@ -7,12 +7,15 @@ var log = require('./log').sub('blob');
|
||||
var BlobClient = {};
|
||||
|
||||
//Blob object class
|
||||
function BlobObj(url, id, key) {
|
||||
this.url = url;
|
||||
this.id = id;
|
||||
this.key = key;
|
||||
this.identity = new Identity(this);
|
||||
this.data = { };
|
||||
function BlobObj(options) {
|
||||
if (!options) options = { };
|
||||
|
||||
this.device_id = options.device_id;
|
||||
this.url = options.url;
|
||||
this.id = options.blob_id;
|
||||
this.key = options.key;
|
||||
this.identity = new Identity(this);
|
||||
this.data = { };
|
||||
};
|
||||
|
||||
// Blob operations
|
||||
@@ -96,16 +99,29 @@ BlobObj.prototype.init = function(fn) {
|
||||
self.url = 'http://' + url;
|
||||
}
|
||||
|
||||
url = self.url + '/v1/blob/' + self.id;
|
||||
|
||||
url = self.url + '/v1/blob/' + self.id;
|
||||
if (this.device_id) url += '?device_id=' + this.device_id;
|
||||
|
||||
request.get(url, function(err, resp) {
|
||||
if (err || !resp.body || resp.body.result !== 'success') {
|
||||
if (err) {
|
||||
return fn(new Error(err.message || 'Could not retrieve blob'));
|
||||
} else if (!resp.body) {
|
||||
return fn(new Error('Could not retrieve blob'));
|
||||
} else if (resp.body.twofactor) {
|
||||
resp.body.twofactor.blob_id = self.id;
|
||||
resp.body.twofactor.blob_url = self.url;
|
||||
resp.body.twofactor.device_id = self.device_id;
|
||||
resp.body.twofactor.blob_key = self.key
|
||||
return fn(resp.body);
|
||||
} else if (resp.body.result !== 'success') {
|
||||
return fn(new Error('Incorrect username or password'));
|
||||
}
|
||||
|
||||
self.revision = resp.body.revision;
|
||||
self.encrypted_secret = resp.body.encrypted_secret;
|
||||
self.identity_id = resp.body.identity_id;
|
||||
self.missing_fields = resp.body.missing_fields;
|
||||
//self.attestations = resp.body.attestation_summary;
|
||||
|
||||
if (!self.decrypt(resp.body.blob)) {
|
||||
return fn(new Error('Error while decrypting blob'));
|
||||
@@ -497,7 +513,6 @@ BlobObj.prototype.postUpdate = function(op, pointer, params, fn) {
|
||||
|
||||
|
||||
var signedRequest = new SignedRequest(config);
|
||||
|
||||
var signed = signedRequest.signHmac(this.data.auth_secret, this.id);
|
||||
|
||||
request.post(signed.url)
|
||||
@@ -513,6 +528,73 @@ BlobObj.prototype.postUpdate = function(op, pointer, params, fn) {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* get2FA - HMAC signed request
|
||||
*/
|
||||
|
||||
BlobObj.prototype.get2FA = function (fn) {
|
||||
var config = {
|
||||
method : 'GET',
|
||||
url : this.url + '/v1/blob/' + this.id + '/2FA?device_id=' + this.device_id,
|
||||
};
|
||||
|
||||
var signedRequest = new SignedRequest(config);
|
||||
var signed = signedRequest.signHmac(this.data.auth_secret, this.id);
|
||||
|
||||
request.get(signed.url)
|
||||
.end(function(err, resp) {
|
||||
if (err) {
|
||||
fn(err);
|
||||
} else if (resp.body && resp.body.result === 'success') {
|
||||
fn(null, resp.body);
|
||||
} else if (resp.body && resp.body.result === 'error') {
|
||||
fn(new Error(resp.body.message));
|
||||
} else {
|
||||
fn(new Error('Unable to retrieve settings.'));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* set2FA
|
||||
* modify 2 factor auth settings
|
||||
* @params {object} options
|
||||
* @params {string} options.masterkey
|
||||
* @params {boolean} options.enabled
|
||||
* @params {string} options.phone
|
||||
* @params {string} options.country_code
|
||||
*/
|
||||
|
||||
BlobObj.prototype.set2FA = function(options, fn) {
|
||||
|
||||
var config = {
|
||||
method : 'POST',
|
||||
url : this.url + '/v1/blob/' + this.id + '/2FA',
|
||||
data : {
|
||||
enabled : options.enabled,
|
||||
phone : options.phone,
|
||||
country_code : options.country_code
|
||||
}
|
||||
};
|
||||
|
||||
var signedRequest = new SignedRequest(config);
|
||||
var signed = signedRequest.signAsymmetric(options.masterkey, this.data.account_id, this.id);
|
||||
|
||||
request.post(signed.url)
|
||||
.send(signed.data)
|
||||
.end(function(err, resp) {
|
||||
if (err) {
|
||||
fn(err);
|
||||
} else if (resp.body && resp.body.result === 'success') {
|
||||
fn(null, resp.body);
|
||||
} else if (resp.body && resp.body.result === 'error') {
|
||||
fn(resp.body);
|
||||
} else {
|
||||
fn(new Error('Unable to update settings.'));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/***** helper functions *****/
|
||||
|
||||
function normalizeSubcommands(subcommands, compress) {
|
||||
@@ -796,7 +878,7 @@ exports.Blob = BlobObj;
|
||||
* Get ripple name for a given address
|
||||
*/
|
||||
|
||||
exports.getRippleName = function(url, address, fn) {
|
||||
BlobClient.getRippleName = function(url, address, fn) {
|
||||
if (!crypt.isValidAddress(address)) {
|
||||
return fn (new Error('Invalid ripple address'));
|
||||
}
|
||||
@@ -817,13 +899,90 @@ exports.getRippleName = function(url, address, fn) {
|
||||
|
||||
/**
|
||||
* Retrive a blob with url, id and key
|
||||
* @params {object} options
|
||||
* @params {string} options.url
|
||||
* @params {string} options.blob_id
|
||||
* @params {string} options.key
|
||||
* @params {string} options.device_id //optional
|
||||
*/
|
||||
|
||||
BlobClient.get = function (url, id, crypt, fn) {
|
||||
var blob = new BlobObj(url, id, crypt);
|
||||
BlobClient.get = function (options, fn) {
|
||||
var blob = new BlobObj(options);
|
||||
blob.init(fn);
|
||||
};
|
||||
|
||||
/**
|
||||
* requestToken
|
||||
* request new token to be sent for 2FA
|
||||
* @param {string} url
|
||||
* @param {string} id
|
||||
* @param {string} force_sms
|
||||
*/
|
||||
|
||||
BlobClient.requestToken = function (url, id, force_sms, fn) {
|
||||
var config = {
|
||||
method : 'GET',
|
||||
url : url + '/v1/blob/' + id + '/2FA/requestToken'
|
||||
};
|
||||
|
||||
|
||||
if (force_sms && force_sms instanceof Function) {
|
||||
fn = force_sms;
|
||||
} else if (force_sms) {
|
||||
config.url += "?force_sms=true";
|
||||
}
|
||||
|
||||
request.get(config.url)
|
||||
.end(function(err, resp) {
|
||||
if (err) {
|
||||
fn(err);
|
||||
} else if (resp.body && resp.body.result === 'success') {
|
||||
fn(null, resp.body);
|
||||
} else if (resp.body && resp.body.result === 'error') {
|
||||
fn(new Error(resp.body.message));
|
||||
} else {
|
||||
fn(new Error('Unable to request authentication token.'));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* verifyToken
|
||||
* verify a device token for 2FA
|
||||
* @param {object} options
|
||||
* @param {string} options.url
|
||||
* @param {string} options.id
|
||||
* @param {string} options.device_id
|
||||
* @param {string} options.token
|
||||
* @param {boolean} options.remember_me
|
||||
*/
|
||||
|
||||
BlobClient.verifyToken = function (options, fn) {
|
||||
var config = {
|
||||
method : 'POST',
|
||||
url : options.url + '/v1/blob/' + options.id + '/2FA/verifyToken',
|
||||
data : {
|
||||
device_id : options.device_id,
|
||||
token : options.token,
|
||||
remember_me : options.remember_me
|
||||
}
|
||||
};
|
||||
|
||||
request.post(config.url)
|
||||
.send(config.data)
|
||||
.end(function(err, resp) {
|
||||
if (err) {
|
||||
fn(err);
|
||||
} else if (resp.body && resp.body.result === 'success') {
|
||||
fn(null, resp.body);
|
||||
} else if (resp.body && resp.body.result === 'error') {
|
||||
fn(new Error(resp.body.message));
|
||||
} else {
|
||||
fn(new Error('Unable to verify authentication token.'));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Verify email address
|
||||
*/
|
||||
@@ -842,8 +1001,15 @@ BlobClient.verify = function(url, username, token, fn) {
|
||||
};
|
||||
|
||||
/**
|
||||
* ResendEmail
|
||||
* resend verification email
|
||||
* resendEmail
|
||||
* send a new verification email
|
||||
* @param {object} opts
|
||||
* @param {string} opts.id
|
||||
* @param {string} opts.username
|
||||
* @param {string} opts.account_id
|
||||
* @param {string} opts.email
|
||||
* @param {string} opts.activateLink
|
||||
* @param {function} fn - Callback
|
||||
*/
|
||||
|
||||
BlobClient.resendEmail = function (opts, fn) {
|
||||
@@ -916,9 +1082,14 @@ BlobClient.recoverBlob = function (opts, fn) {
|
||||
});
|
||||
|
||||
function handleRecovery (resp) {
|
||||
//decrypt crypt key
|
||||
var crypt = decryptBlobCrypt(opts.masterkey, resp.body.encrypted_blobdecrypt_key);
|
||||
var blob = new BlobObj(opts.url, resp.body.blob_id, crypt);
|
||||
|
||||
var params = {
|
||||
url : opts.url,
|
||||
blob_id : resp.body.blob_id,
|
||||
key : decryptBlobCrypt(opts.masterkey, resp.body.encrypted_blobdecrypt_key)
|
||||
}
|
||||
|
||||
var blob = new BlobObj(params);
|
||||
|
||||
blob.revision = resp.body.revision;
|
||||
blob.encrypted_secret = resp.body.encrypted_secret;
|
||||
@@ -944,38 +1115,6 @@ BlobClient.recoverBlob = function (opts, fn) {
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* updateProfile
|
||||
* update information stored outside the blob
|
||||
*/
|
||||
|
||||
BlobClient.updateProfile = function (opts, fn) {
|
||||
var config = {
|
||||
method: 'POST',
|
||||
url: opts.url + '/v1/user/' + opts.username + '/profile',
|
||||
dataType: 'json',
|
||||
data: opts.profile
|
||||
};
|
||||
|
||||
var signedRequest = new SignedRequest(config);
|
||||
var signed = signedRequest.signHmac(opts.auth_secret, opts.blob_id);
|
||||
|
||||
request.post(signed.url)
|
||||
.send(signed.data)
|
||||
.end(function(err, resp) {
|
||||
if (err) {
|
||||
log.error('updateProfile:', err);
|
||||
fn(new Error('Failed to update profile - XHR error'));
|
||||
} else if (resp.body && resp.body.result === 'success') {
|
||||
fn(null, resp.body);
|
||||
} else if (resp.body) {
|
||||
log.error('updateProfile:', resp.body);
|
||||
} else {
|
||||
fn(new Error('Failed to update profile'));
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* updateKeys
|
||||
@@ -1088,7 +1227,12 @@ BlobClient.rename = function (opts, fn) {
|
||||
*/
|
||||
|
||||
BlobClient.create = function(options, fn) {
|
||||
var blob = new BlobObj(options.url, options.id, options.crypt);
|
||||
var params = {
|
||||
url : options.url,
|
||||
blob_id : options.id,
|
||||
key : options.crypt
|
||||
}
|
||||
var blob = new BlobObj(params);
|
||||
|
||||
blob.revision = 0;
|
||||
|
||||
@@ -1134,6 +1278,7 @@ BlobClient.create = function(options, fn) {
|
||||
if (err) {
|
||||
fn(err);
|
||||
} else if (resp.body && resp.body.result === 'success') {
|
||||
blob.identity_id = resp.body.identity_id;
|
||||
fn(null, blob, resp.body);
|
||||
} else if (resp.body && resp.body.result === 'error') {
|
||||
fn(new Error(resp.body.message));
|
||||
@@ -1144,7 +1289,13 @@ BlobClient.create = function(options, fn) {
|
||||
};
|
||||
|
||||
/**
|
||||
* deleteBlob
|
||||
* deleteBlob
|
||||
* @param {object} options
|
||||
* @param {string} options.url
|
||||
* @param {string} options.username
|
||||
* @param {string} options.blob_id
|
||||
* @param {string} options.account_id
|
||||
* @param {string} options.masterkey
|
||||
*/
|
||||
|
||||
BlobClient.deleteBlob = function(options, fn) {
|
||||
@@ -1171,4 +1322,263 @@ BlobClient.deleteBlob = function(options, fn) {
|
||||
});
|
||||
};
|
||||
|
||||
/*** identity related functions ***/
|
||||
|
||||
/**
|
||||
* updateProfile
|
||||
* update information stored outside the blob - HMAC signed
|
||||
* @param {object}
|
||||
* @param {string} opts.url
|
||||
* @param {string} opts.auth_secret
|
||||
* @param {srring} opts.blob_id
|
||||
* @param {object} opts.profile
|
||||
* @param {array} opts.profile.attributes (optional, array of attribute objects)
|
||||
* @param {array} opts.profile.addresses (optional, array of address objects)
|
||||
*
|
||||
* @param {string} attribute.id ... id of existing attribute
|
||||
* @param {string} attribute.name ... attribute name i.e. ripple_address
|
||||
* @param {string} attribute.type ... optional, sub-type of attribute
|
||||
* @param {string} attribute.value ... value of attribute
|
||||
* @param {string} attribute.domain ... corresponding domain
|
||||
* @param {string} attribute.status ... “current”, “removed”, etc.
|
||||
* @param {string} attribute.visibitlity ... “public”, ”private”
|
||||
*/
|
||||
|
||||
BlobClient.updateProfile = function (opts, fn) {
|
||||
var config = {
|
||||
method: 'POST',
|
||||
url: opts.url + '/v1/profile/',
|
||||
dataType: 'json',
|
||||
data: opts.profile
|
||||
};
|
||||
|
||||
var signedRequest = new SignedRequest(config);
|
||||
var signed = signedRequest.signHmac(opts.auth_secret, opts.blob_id);
|
||||
|
||||
request.post(signed.url)
|
||||
.send(signed.data)
|
||||
.end(function(err, resp) {
|
||||
|
||||
if (err) {
|
||||
log.error('updateProfile:', err);
|
||||
fn(new Error('Failed to update profile - XHR error'));
|
||||
} else if (resp.body && resp.body.result === 'success') {
|
||||
fn(null, resp.body);
|
||||
} else if (resp.body) {
|
||||
log.error('updateProfile:', resp.body);
|
||||
fn(new Error('Failed to update profile'));
|
||||
} else {
|
||||
fn(new Error('Failed to update profile'));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* getProfile
|
||||
* @param {Object} opts
|
||||
* @param {string} opts.url
|
||||
* @param {string} opts.auth_secret
|
||||
* @param {srring} opts.blob_id
|
||||
*/
|
||||
|
||||
BlobClient.getProfile = function (opts, fn) {
|
||||
var config = {
|
||||
method: 'GET',
|
||||
url: opts.url + '/v1/profile/'
|
||||
};
|
||||
|
||||
var signedRequest = new SignedRequest(config);
|
||||
var signed = signedRequest.signHmac(opts.auth_secret, opts.blob_id);
|
||||
|
||||
request.get(signed.url)
|
||||
.send(signed.data)
|
||||
.end(function(err, resp) {
|
||||
|
||||
if (err) {
|
||||
log.error('getProfile:', err);
|
||||
fn(new Error('Failed to get profile - XHR error'));
|
||||
} else if (resp.body && resp.body.result === 'success') {
|
||||
fn(null, resp.body);
|
||||
} else if (resp.body) {
|
||||
log.error('getProfile:', resp.body);
|
||||
fn(new Error('Failed to get profile'));
|
||||
} else {
|
||||
fn(new Error('Failed to get profile'));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* getAttestation
|
||||
* @param {Object} opts
|
||||
* @param {string} opts.url
|
||||
* @param {string} opts.auth_secret
|
||||
* @param {string} opts.blob_id
|
||||
* @param {string} opts.type (email,phone,basic_identity)
|
||||
* @param {object} opts.phone (required for type 'phone')
|
||||
* @param {string} opts.email (required for type 'email')
|
||||
*/
|
||||
|
||||
BlobClient.getAttestation = function (opts, fn) {
|
||||
var params = { };
|
||||
|
||||
if (opts.phone) params.phone = opts.phone;
|
||||
if (opts.email) params.email = opts.email;
|
||||
|
||||
var config = {
|
||||
method: 'POST',
|
||||
url: opts.url + '/v1/attestation/' + opts.type,
|
||||
dataType: 'json',
|
||||
data: params
|
||||
};
|
||||
|
||||
var signedRequest = new SignedRequest(config);
|
||||
var signed = signedRequest.signHmac(opts.auth_secret, opts.blob_id);
|
||||
|
||||
request.post(signed.url)
|
||||
.send(signed.data)
|
||||
.end(function(err, resp) {
|
||||
|
||||
if (err) {
|
||||
log.error('attest:', err);
|
||||
fn(new Error('attestation error - XHR error'));
|
||||
} else if (resp.body && resp.body.result === 'success') {
|
||||
if (resp.body.attestation) {
|
||||
resp.body.decoded = BlobClient.parseAttestation(resp.body.attestation);
|
||||
}
|
||||
|
||||
fn(null, resp.body);
|
||||
} else if (resp.body) {
|
||||
log.error('attestation:', resp.body);
|
||||
fn(new Error('attestation error: ' + resp.body.message || ""));
|
||||
} else {
|
||||
fn(new Error('attestation error'));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* getAttestationSummary
|
||||
* @param {Object} opts
|
||||
* @param {string} opts.url
|
||||
* @param {string} opts.auth_secret
|
||||
* @param {string} opts.blob_id
|
||||
*/
|
||||
|
||||
BlobClient.getAttestationSummary = function (opts, fn) {
|
||||
|
||||
|
||||
var config = {
|
||||
method: 'GET',
|
||||
url: opts.url + '/v1/attestation/summary',
|
||||
dataType: 'json'
|
||||
};
|
||||
|
||||
if (opts.full) config.url += '?full=true';
|
||||
|
||||
var signedRequest = new SignedRequest(config);
|
||||
var signed = signedRequest.signHmac(opts.auth_secret, opts.blob_id);
|
||||
|
||||
request.get(signed.url)
|
||||
.send(signed.data)
|
||||
.end(function(err, resp) {
|
||||
|
||||
if (err) {
|
||||
log.error('attest:', err);
|
||||
fn(new Error('attestation error - XHR error'));
|
||||
} else if (resp.body && resp.body.result === 'success') {
|
||||
if (resp.body.attestation) {
|
||||
resp.body.decoded = BlobClient.parseAttestation(resp.body.attestation);
|
||||
}
|
||||
|
||||
fn(null, resp.body);
|
||||
} else if (resp.body) {
|
||||
log.error('attestation:', resp.body);
|
||||
fn(new Error('attestation error: ' + resp.body.message || ""));
|
||||
} else {
|
||||
fn(new Error('attestation error'));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* updateAttestation
|
||||
* @param {Object} opts
|
||||
* @param {string} opts.url
|
||||
* @param {string} opts.auth_secret
|
||||
* @param {string} opts.blob_id
|
||||
* @param {string} opts.type (email,phone,profile,identity)
|
||||
* @param {object} opts.phone (required for type 'phone')
|
||||
* @param {object} opts.profile (required for type 'profile')
|
||||
* @param {string} opts.email (required for type 'email')
|
||||
* @param {string} opts.answers (required for type 'identity')
|
||||
* @param {string} opts.token (required for completing email or phone attestations)
|
||||
*/
|
||||
|
||||
BlobClient.updateAttestation = function (opts, fn) {
|
||||
|
||||
var params = { };
|
||||
|
||||
if (opts.phone) params.phone = opts.phone;
|
||||
if (opts.profile) params.profile = opts.profile;
|
||||
if (opts.email) params.email = opts.email;
|
||||
if (opts.token) params.token = opts.token;
|
||||
if (opts.answers) params.answers = opts.answers;
|
||||
|
||||
var config = {
|
||||
method: 'POST',
|
||||
url: opts.url + '/v1/attestation/' + opts.type + '/update',
|
||||
dataType: 'json',
|
||||
data: params
|
||||
};
|
||||
|
||||
var signedRequest = new SignedRequest(config);
|
||||
var signed = signedRequest.signHmac(opts.auth_secret, opts.blob_id);
|
||||
|
||||
request.post(signed.url)
|
||||
.send(signed.data)
|
||||
.end(function(err, resp) {
|
||||
|
||||
if (err) {
|
||||
log.error('attest:', err);
|
||||
fn(new Error('attestation error - XHR error'));
|
||||
} else if (resp.body && resp.body.result === 'success') {
|
||||
if (resp.body.attestation) {
|
||||
resp.body.decoded = BlobClient.parseAttestation(resp.body.attestation);
|
||||
}
|
||||
|
||||
fn(null, resp.body);
|
||||
} else if (resp.body) {
|
||||
log.error('attestation:', resp.body);
|
||||
fn(new Error('attestation error: ' + resp.body.message || ""));
|
||||
} else {
|
||||
fn(new Error('attestation error'));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* parseAttestation
|
||||
* @param {Object} attestation
|
||||
*/
|
||||
|
||||
BlobClient.parseAttestation = function (attestation) {
|
||||
var segments = decodeURIComponent(attestation).split('.');
|
||||
var decoded;
|
||||
|
||||
// base64 decode and parse JSON
|
||||
try {
|
||||
decoded = {
|
||||
header : JSON.parse(crypt.decodeBase64(segments[0])),
|
||||
payload : JSON.parse(crypt.decodeBase64(segments[1])),
|
||||
signature : segments[2]
|
||||
};
|
||||
|
||||
} catch (e) {
|
||||
console.log("invalid attestation:", e);
|
||||
}
|
||||
|
||||
return decoded;
|
||||
};
|
||||
|
||||
exports.BlobClient = BlobClient;
|
||||
|
||||
@@ -56,6 +56,18 @@ function keyHash(key, token) {
|
||||
return sjcl.codec.hex.fromBits(sjcl.bitArray.bitSlice(hmac.encrypt(token), 0, 256));
|
||||
};
|
||||
|
||||
/**
|
||||
* add entropy at each call to get random words
|
||||
* @param {number} nWords
|
||||
*/
|
||||
function randomWords (nWords) {
|
||||
for (var i = 0; i < 8; i++) {
|
||||
sjcl.random.addEntropy(Math.random(), 32, "Math.random()");
|
||||
}
|
||||
|
||||
return sjcl.random.randomWords(nWords);
|
||||
}
|
||||
|
||||
/****** exposed functions ******/
|
||||
|
||||
/**
|
||||
@@ -213,7 +225,7 @@ Crypt.isValidAddress = function (address) {
|
||||
*/
|
||||
|
||||
Crypt.createSecret = function (nWords) {
|
||||
return sjcl.codec.hex.fromBits(sjcl.random.randomWords(nWords));
|
||||
return sjcl.codec.hex.fromBits(randomWords(nWords));
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -221,7 +233,7 @@ Crypt.createSecret = function (nWords) {
|
||||
*/
|
||||
|
||||
Crypt.createMaster = function () {
|
||||
return base.encode_check(33, sjcl.codec.bytes.fromBits(sjcl.random.randomWords(4)));
|
||||
return base.encode_check(33, sjcl.codec.bytes.fromBits(randomWords(4)));
|
||||
};
|
||||
|
||||
|
||||
@@ -310,4 +322,12 @@ Crypt.base64UrlToBase64 = function(encodedData) {
|
||||
return encodedData;
|
||||
};
|
||||
|
||||
/**
|
||||
* base64 to UTF8
|
||||
*/
|
||||
|
||||
Crypt.decodeBase64 = function (data) {
|
||||
return sjcl.codec.utf8String.fromBits(sjcl.codec.base64.toBits(data));
|
||||
}
|
||||
|
||||
exports.Crypt = Crypt;
|
||||
|
||||
@@ -50,14 +50,10 @@ Currency.HEX_CURRENCY_BAD = '0000000000000000000000005852500000000000';
|
||||
* \s*$ // end with any amount of whitespace
|
||||
*
|
||||
*/
|
||||
Currency.prototype.human_RE = /^\s*([a-zA-Z]{3}|[0-9]{3})(\s*-\s*[- \w]+)?(\s*\(-?\d+\.?\d*%pa\))?\s*$/;
|
||||
Currency.prototype.human_RE = /^\s*([a-zA-Z0-9]{3})(\s*-\s*[- \w]+)?(\s*\(-?\d+\.?\d*%pa\))?\s*$/;
|
||||
|
||||
Currency.from_json = function(j, shouldInterpretXrpAsIou) {
|
||||
if (j instanceof this) {
|
||||
return j.clone();
|
||||
} else {
|
||||
return (new this()).parse_json(j, shouldInterpretXrpAsIou);
|
||||
}
|
||||
return (new Currency()).parse_json(j, shouldInterpretXrpAsIou);
|
||||
};
|
||||
|
||||
Currency.from_human = function(j, opts) {
|
||||
@@ -66,17 +62,18 @@ Currency.from_human = function(j, opts) {
|
||||
|
||||
// this._value = NaN on error.
|
||||
Currency.prototype.parse_json = function(j, shouldInterpretXrpAsIou) {
|
||||
if (j instanceof Currency) {
|
||||
return j.clone();
|
||||
}
|
||||
|
||||
this._value = NaN;
|
||||
|
||||
switch (typeof j) {
|
||||
case 'string':
|
||||
|
||||
if (!j || /^(0|XRP)$/.test(j)) {
|
||||
if (shouldInterpretXrpAsIou) {
|
||||
this.parse_hex(Currency.HEX_CURRENCY_BAD);
|
||||
} else {
|
||||
this.parse_hex(Currency.HEX_ZERO);
|
||||
}
|
||||
// if an empty string is given, fall back to XRP
|
||||
if (!j) {
|
||||
this.parse_hex(shouldInterpretXrpAsIou ? Currency.HEX_CURRENCY_BAD : Currency.HEX_ZERO);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -86,6 +83,17 @@ Currency.prototype.parse_json = function(j, shouldInterpretXrpAsIou) {
|
||||
if (matches) {
|
||||
|
||||
var currencyCode = matches[1];
|
||||
|
||||
// for the currency 'XRP' case
|
||||
// we drop everything else that could have been provided
|
||||
// e.g. 'XRP - Ripple'
|
||||
if (!currencyCode || /^(0|XRP)$/.test(currencyCode)) {
|
||||
this.parse_hex(shouldInterpretXrpAsIou ? Currency.HEX_CURRENCY_BAD : Currency.HEX_ZERO);
|
||||
|
||||
// early break, we can't have interest on XRP
|
||||
break;
|
||||
}
|
||||
|
||||
// the full currency is matched as it is part of the valid currency format, but not stored
|
||||
// var full_currency = matches[2] || '';
|
||||
var interest = matches[3] || '';
|
||||
@@ -270,7 +278,7 @@ Currency.prototype.has_interest = function() {
|
||||
* @returns {number} - interest for provided interval, can be negative for demurred currencies
|
||||
*/
|
||||
Currency.prototype.get_interest_at = function(referenceDate, decimals) {
|
||||
if (!this.has_interest) {
|
||||
if (!this.has_interest()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -313,18 +321,20 @@ Currency.prototype.to_json = function(opts) {
|
||||
return 'XRP';
|
||||
}
|
||||
|
||||
var opts = opts || {};
|
||||
|
||||
var currency;
|
||||
var fullName = opts && opts.full_name ? " - " + opts.full_name : "";
|
||||
var fullName = opts && opts.full_name ? ' - ' + opts.full_name : '';
|
||||
opts.show_interest = opts.show_interest !== void(0) ? opts.show_interest : this.has_interest();
|
||||
|
||||
// Any currency with standard properties and a valid code can be abbreviated
|
||||
// in the JSON wire format as the three character code.
|
||||
if (/^[A-Z0-9]{3}$/.test(this._iso_code) && !this.has_interest()) {
|
||||
if (!opts.force_hex && /^[A-Z0-9]{3}$/.test(this._iso_code)) {
|
||||
currency = this._iso_code + fullName;
|
||||
if (opts.show_interest) {
|
||||
var decimals = !isNaN(opts.decimals) ? opts.decimals : void(0);
|
||||
var interestPercentage = this.has_interest() ? this.get_interest_percentage_at(this._interest_start + 3600 * 24 * 365, decimals) : 0;
|
||||
currency += ' (' + interestPercentage + '%pa)';
|
||||
}
|
||||
|
||||
// If there is interest, append the annual interest to the full currency name
|
||||
} else if (this.has_interest()) {
|
||||
var decimals = opts ? opts.decimals : undefined;
|
||||
currency = this._iso_code + fullName + " (" + this.get_interest_percentage_at(this._interest_start + 3600 * 24 * 365, decimals) + "%pa)";
|
||||
} else {
|
||||
|
||||
// Fallback to returning the raw currency hex
|
||||
|
||||
@@ -18,6 +18,7 @@ exports.RippleTxt = require('./rippletxt').RippleTxt;
|
||||
exports.binformat = require('./binformat');
|
||||
exports.utils = require('./utils');
|
||||
exports.Server = require('./server').Server;
|
||||
exports.Wallet = require('./wallet');
|
||||
|
||||
// Important: We do not guarantee any specific version of SJCL or for any
|
||||
// specific features to be included. The version and configuration may change at
|
||||
|
||||
@@ -69,6 +69,7 @@ var BasicLogEngine = {
|
||||
});
|
||||
|
||||
args.unshift(msg);
|
||||
args.unshift('[' + new Date().toISOString() + ']');
|
||||
|
||||
console.log.apply(console, args);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ var InteractiveLogEngine = {
|
||||
});
|
||||
|
||||
args.unshift(msg);
|
||||
args.unshift('[' + new Date().toISOString() + ']');
|
||||
|
||||
console.log.apply(console, args);
|
||||
}
|
||||
|
||||
@@ -5,47 +5,51 @@ var Amount = require('./amount').Amount;
|
||||
|
||||
/**
|
||||
* Meta data processing facility
|
||||
*
|
||||
* @constructor
|
||||
* @param {Object} transaction metadata
|
||||
*/
|
||||
|
||||
function Meta(raw_data) {
|
||||
function Meta(data) {
|
||||
var self = this;
|
||||
|
||||
this.nodes = [ ];
|
||||
|
||||
raw_data.AffectedNodes.forEach(function(an) {
|
||||
var result = { };
|
||||
if (typeof data !== 'object') {
|
||||
throw new TypeError('Missing metadata');
|
||||
}
|
||||
|
||||
if ((result.diffType = self.diffType(an))) {
|
||||
an = an[result.diffType];
|
||||
if (!Array.isArray(data.AffectedNodes)) {
|
||||
throw new TypeError('Metadata missing AffectedNodes');
|
||||
}
|
||||
|
||||
result.entryType = an.LedgerEntryType;
|
||||
result.ledgerIndex = an.LedgerIndex;
|
||||
result.fields = extend({}, an.PreviousFields, an.NewFields, an.FinalFields);
|
||||
result.fieldsPrev = an.PreviousFields || {};
|
||||
result.fieldsNew = an.NewFields || {};
|
||||
result.fieldsFinal = an.FinalFields || {};
|
||||
|
||||
// getAffectedBooks will set this
|
||||
// result.bookKey = undefined;
|
||||
|
||||
self.nodes.push(result);
|
||||
}
|
||||
});
|
||||
data.AffectedNodes.forEach(this.addNode, this);
|
||||
};
|
||||
|
||||
Meta.node_types = [
|
||||
Meta.nodeTypes = [
|
||||
'CreatedNode',
|
||||
'ModifiedNode',
|
||||
'DeletedNode'
|
||||
];
|
||||
|
||||
Meta.prototype.diffType = function(an) {
|
||||
var result = false;
|
||||
Meta.amountFieldsAffectingIssuer = [
|
||||
'LowLimit',
|
||||
'HighLimit',
|
||||
'TakerPays',
|
||||
'TakerGets'
|
||||
];
|
||||
|
||||
for (var i=0; i<Meta.node_types.length; i++) {
|
||||
var x = Meta.node_types[i];
|
||||
if (an.hasOwnProperty(x)) {
|
||||
result = x;
|
||||
/**
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Meta.prototype.getNodeType = function(node) {
|
||||
var result = null;
|
||||
|
||||
for (var i=0; i<Meta.nodeTypes.length; i++) {
|
||||
var type = Meta.nodeTypes[i];
|
||||
if (node.hasOwnProperty(type)) {
|
||||
result = type;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -53,6 +57,63 @@ Meta.prototype.diffType = function(an) {
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add node to metadata
|
||||
*
|
||||
* @param {Object} node
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Meta.prototype.addNode = function(node) {
|
||||
this._affectedAccounts = void(0);
|
||||
this._affectedBooks = void(0);
|
||||
|
||||
var result = { };
|
||||
|
||||
if ((result.nodeType = this.getNodeType(node))) {
|
||||
node = node[result.nodeType];
|
||||
|
||||
result.diffType = result.nodeType;
|
||||
result.entryType = node.LedgerEntryType;
|
||||
result.ledgerIndex = node.LedgerIndex;
|
||||
result.fields = extend({ }, node.PreviousFields, node.NewFields, node.FinalFields);
|
||||
result.fieldsPrev = node.PreviousFields || { };
|
||||
result.fieldsNew = node.NewFields || { };
|
||||
result.fieldsFinal = node.FinalFields || { };
|
||||
|
||||
// getAffectedBooks will set this
|
||||
// result.bookKey = undefined;
|
||||
|
||||
this.nodes.push(result);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get affected nodes array
|
||||
*
|
||||
* @param {Object} filter options
|
||||
* @return {Array} nodes
|
||||
*/
|
||||
|
||||
Meta.prototype.getNodes = function(options) {
|
||||
if (typeof options === 'object') {
|
||||
return this.nodes.filter(function(node) {
|
||||
if (options.nodeType && options.nodeType !== node.nodeType) {
|
||||
return false;
|
||||
}
|
||||
if (options.entryType && options.entryType !== node.entryType) {
|
||||
return false;
|
||||
}
|
||||
if (options.bookKey && options.bookKey !== node.bookKey) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
} else {
|
||||
return this.nodes;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Execute a function on each affected node.
|
||||
*
|
||||
@@ -61,7 +122,7 @@ Meta.prototype.diffType = function(an) {
|
||||
*
|
||||
* {
|
||||
* // Type of diff, e.g. CreatedNode, ModifiedNode
|
||||
* diffType: 'CreatedNode'
|
||||
* nodeType: 'CreatedNode'
|
||||
*
|
||||
* // Type of node affected, e.g. RippleState, AccountRoot
|
||||
* entryType: 'RippleState',
|
||||
@@ -72,7 +133,7 @@ Meta.prototype.diffType = function(an) {
|
||||
* // Contains all fields with later versions taking precedence
|
||||
* //
|
||||
* // This is a shorthand for doing things like checking which account
|
||||
* // this affected without having to check the diffType.
|
||||
* // this affected without having to check the nodeType.
|
||||
* fields: {...},
|
||||
*
|
||||
* // Old fields (before the change)
|
||||
@@ -88,43 +149,39 @@ Meta.prototype.diffType = function(an) {
|
||||
* The second parameter to the callback is the index of the node in the metadata
|
||||
* (first entry is index 0).
|
||||
*/
|
||||
Meta.prototype.each = function(fn) {
|
||||
for (var i = 0, l = this.nodes.length; i < l; i++) {
|
||||
fn(this.nodes[i], i);
|
||||
}
|
||||
};
|
||||
|
||||
([
|
||||
[
|
||||
'forEach',
|
||||
'map',
|
||||
'filter',
|
||||
'every',
|
||||
'some',
|
||||
'reduce'
|
||||
]).forEach(function(fn) {
|
||||
].forEach(function(fn) {
|
||||
Meta.prototype[fn] = function() {
|
||||
return Array.prototype[fn].apply(this.nodes, arguments);
|
||||
};
|
||||
});
|
||||
|
||||
var amountFieldsAffectingIssuer = [
|
||||
'LowLimit',
|
||||
'HighLimit',
|
||||
'TakerPays',
|
||||
'TakerGets'
|
||||
];
|
||||
Meta.prototype.each = Meta.prototype.forEach;
|
||||
|
||||
Meta.prototype.getAffectedAccounts = function(from) {
|
||||
if (this._affectedAccounts) {
|
||||
return this._affectedAccounts;
|
||||
}
|
||||
|
||||
Meta.prototype.getAffectedAccounts = function() {
|
||||
var accounts = [ ];
|
||||
|
||||
// This code should match the behavior of the C++ method:
|
||||
// TransactionMetaSet::getAffectedAccounts
|
||||
this.nodes.forEach(function(an) {
|
||||
var fields = (an.diffType === 'CreatedNode') ? an.fieldsNew : an.fieldsFinal;
|
||||
for (var i in fields) {
|
||||
var field = fields[i];
|
||||
for (var i=0; i<this.nodes.length; i++) {
|
||||
var node = this.nodes[i];
|
||||
var fields = (node.nodeType === 'CreatedNode') ? node.fieldsNew : node.fieldsFinal;
|
||||
for (var fieldName in fields) {
|
||||
var field = fields[fieldName];
|
||||
if (typeof field === 'string' && UInt160.is_valid(field)) {
|
||||
accounts.push(field);
|
||||
} else if (amountFieldsAffectingIssuer.indexOf(i) !== -1) {
|
||||
} else if (~Meta.amountFieldsAffectingIssuer.indexOf(fieldName)) {
|
||||
var amount = Amount.from_json(field);
|
||||
var issuer = amount.issuer();
|
||||
if (issuer.is_valid() && !issuer.is_zero()) {
|
||||
@@ -132,43 +189,53 @@ Meta.prototype.getAffectedAccounts = function() {
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return utils.arrayUnique(accounts);
|
||||
this._affectedAccounts = utils.arrayUnique(accounts);
|
||||
|
||||
return this._affectedAccounts;
|
||||
};
|
||||
|
||||
Meta.prototype.getAffectedBooks = function() {
|
||||
if (this._affectedBooks) {
|
||||
return this._affectedBooks;
|
||||
}
|
||||
|
||||
var books = [ ];
|
||||
|
||||
this.nodes.forEach(function(an) {
|
||||
if (an.entryType !== 'Offer') {
|
||||
return;
|
||||
for (var i=0; i<this.nodes.length; i++) {
|
||||
var node = this.nodes[i];
|
||||
|
||||
if (node.entryType !== 'Offer') {
|
||||
continue;
|
||||
}
|
||||
|
||||
var gets = Amount.from_json(an.fields.TakerGets);
|
||||
var pays = Amount.from_json(an.fields.TakerPays);
|
||||
|
||||
var gets = Amount.from_json(node.fields.TakerGets);
|
||||
var pays = Amount.from_json(node.fields.TakerPays);
|
||||
var getsKey = gets.currency().to_json();
|
||||
var paysKey = pays.currency().to_json();
|
||||
|
||||
if (getsKey !== 'XRP') {
|
||||
getsKey += '/' + gets.issuer().to_json();
|
||||
}
|
||||
|
||||
var paysKey = pays.currency().to_json();
|
||||
if (paysKey !== 'XRP') {
|
||||
paysKey += '/' + pays.issuer().to_json();
|
||||
}
|
||||
|
||||
var key = [ getsKey, paysKey ].join(':');
|
||||
var key = getsKey + ':' + paysKey;
|
||||
|
||||
// Hell of a lot of work, so we are going to cache this. We can use this
|
||||
// later to good effect in OrderBook.notify to make sure we only process
|
||||
// pertinent offers.
|
||||
an.bookKey = key;
|
||||
node.bookKey = key;
|
||||
|
||||
books.push(key);
|
||||
});
|
||||
}
|
||||
|
||||
return utils.arrayUnique(books);
|
||||
this._affectedBooks = utils.arrayUnique(books);
|
||||
|
||||
return this._affectedBooks;
|
||||
};
|
||||
|
||||
exports.Meta = Meta;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -11,12 +11,19 @@ var Server = require('./server').Server;
|
||||
// 'remoteError'
|
||||
// 'remoteUnexpected'
|
||||
// 'remoteDisconnected'
|
||||
|
||||
/**
|
||||
* Request
|
||||
*
|
||||
* @param {Remote} remote
|
||||
* @param {String} command
|
||||
*/
|
||||
|
||||
function Request(remote, command) {
|
||||
EventEmitter.call(this);
|
||||
|
||||
this.remote = remote;
|
||||
this.requested = false;
|
||||
|
||||
this.message = {
|
||||
command: command,
|
||||
id: void(0)
|
||||
@@ -26,23 +33,27 @@ function Request(remote, command) {
|
||||
util.inherits(Request, EventEmitter);
|
||||
|
||||
Request.prototype.broadcast = function() {
|
||||
this._broadcast = true;
|
||||
return this.request();
|
||||
var connectedServers = this.remote.getConnectedServers();
|
||||
this.request(connectedServers);
|
||||
return connectedServers.length;
|
||||
};
|
||||
|
||||
// Send the request to a remote.
|
||||
Request.prototype.request = function(remote) {
|
||||
Request.prototype.request = function(servers, callback) {
|
||||
if (this.requested) {
|
||||
return;
|
||||
return this;
|
||||
}
|
||||
|
||||
if (typeof servers === 'function') {
|
||||
callback = servers;
|
||||
}
|
||||
|
||||
this.requested = true;
|
||||
|
||||
this.on('error', function(){});
|
||||
this.emit('request', remote);
|
||||
this.emit('request', this.remote);
|
||||
|
||||
if (this._broadcast) {
|
||||
this.remote._servers.forEach(function(server) {
|
||||
if (Array.isArray(servers)) {
|
||||
servers.forEach(function(server) {
|
||||
this.setServer(server);
|
||||
this.remote.request(this);
|
||||
}, this);
|
||||
@@ -50,13 +61,15 @@ Request.prototype.request = function(remote) {
|
||||
this.remote.request(this);
|
||||
}
|
||||
|
||||
this.callback(callback);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
Request.prototype.callback = function(callback, successEvent, errorEvent) {
|
||||
var self = this;
|
||||
|
||||
if (this.requested || typeof callback !== 'function') {
|
||||
if (typeof callback !== 'function') {
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -195,6 +208,13 @@ Request.prototype.ledgerIndex = function(ledger_index) {
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set either ledger_index or ledger_hash based on heuristic
|
||||
*
|
||||
* @param {Number|String} ledger identifier
|
||||
*/
|
||||
|
||||
Request.prototype.selectLedger =
|
||||
Request.prototype.ledgerSelect = function(ledger) {
|
||||
switch (ledger) {
|
||||
case 'current':
|
||||
@@ -204,10 +224,10 @@ Request.prototype.ledgerSelect = function(ledger) {
|
||||
break;
|
||||
|
||||
default:
|
||||
if (isNaN(ledger)) {
|
||||
this.message.ledger_hash = ledger;
|
||||
} else if ((ledger = Number(ledger))) {
|
||||
this.message.ledger_index = ledger;
|
||||
if (Number(ledger)) {
|
||||
this.message.ledger_index = Number(ledger);
|
||||
} else if (/^[A-F0-9]+$/.test(ledger)) {
|
||||
this.message.ledger_hash = ledger;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -275,6 +295,7 @@ Request.prototype.rippleState = function(account, issuer, currency) {
|
||||
return this;
|
||||
};
|
||||
|
||||
Request.prototype.setAccounts =
|
||||
Request.prototype.accounts = function(accounts, proposed) {
|
||||
if (!Array.isArray(accounts)) {
|
||||
accounts = [ accounts ];
|
||||
@@ -295,9 +316,14 @@ Request.prototype.accounts = function(accounts, proposed) {
|
||||
};
|
||||
|
||||
Request.prototype.addAccount = function(account, proposed) {
|
||||
if (Array.isArray(account)) {
|
||||
account.forEach(this.addAccount, this);
|
||||
return this;
|
||||
}
|
||||
|
||||
var processedAccount = UInt160.json_rewrite(account);
|
||||
|
||||
if (proposed) {
|
||||
if (proposed === true) {
|
||||
this.message.accounts_proposed = (this.message.accounts_proposed || []).concat(processedAccount);
|
||||
} else {
|
||||
this.message.accounts = (this.message.accounts || []).concat(processedAccount);
|
||||
@@ -306,15 +332,22 @@ Request.prototype.addAccount = function(account, proposed) {
|
||||
return this;
|
||||
};
|
||||
|
||||
Request.prototype.setAccountsProposed =
|
||||
Request.prototype.rtAccounts =
|
||||
Request.prototype.accountsProposed = function(accounts) {
|
||||
return this.accounts(accounts, true);
|
||||
};
|
||||
|
||||
Request.prototype.addAccountProposed = function(account) {
|
||||
if (Array.isArray(account)) {
|
||||
account.forEach(this.addAccountProposed, this);
|
||||
return this;
|
||||
}
|
||||
|
||||
return this.addAccount(account, true);
|
||||
};
|
||||
|
||||
Request.prototype.setBooks =
|
||||
Request.prototype.books = function(books, snapshot) {
|
||||
// Reset list of books (this method overwrites the current list)
|
||||
this.message.books = [ ];
|
||||
@@ -328,8 +361,9 @@ Request.prototype.books = function(books, snapshot) {
|
||||
};
|
||||
|
||||
Request.prototype.addBook = function(book, snapshot) {
|
||||
if (!Array.isArray(this.message.books)) {
|
||||
this.message.books = [ ];
|
||||
if (Array.isArray(book)) {
|
||||
book.forEach(this.addBook, this);
|
||||
return this;
|
||||
}
|
||||
|
||||
var json = { };
|
||||
@@ -340,25 +374,64 @@ Request.prototype.addBook = function(book, snapshot) {
|
||||
}
|
||||
|
||||
var obj = json[side] = {
|
||||
currency: Currency.json_rewrite(book[side].currency)
|
||||
currency: Currency.json_rewrite(book[side].currency, { force_hex: true })
|
||||
};
|
||||
|
||||
if (obj.currency !== 'XRP') {
|
||||
if (!Currency.from_json(obj.currency).is_native()) {
|
||||
obj.issuer = UInt160.json_rewrite(book[side].issuer);
|
||||
}
|
||||
}
|
||||
|
||||
[ 'taker_gets', 'taker_pays' ].forEach(processSide);
|
||||
|
||||
if (snapshot) {
|
||||
if (typeof snapshot !== 'boolean') {
|
||||
json.snapshot = true;
|
||||
} else if (snapshot) {
|
||||
json.snapshot = true;
|
||||
} else {
|
||||
delete json.snapshot;
|
||||
}
|
||||
|
||||
if (book.both) {
|
||||
json.both = true;
|
||||
}
|
||||
|
||||
this.message.books.push(json);
|
||||
this.message.books = (this.message.books || []).concat(json);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
Request.prototype.addStream = function(stream, values) {
|
||||
var self = this;
|
||||
|
||||
if (Array.isArray(values)) {
|
||||
switch (stream) {
|
||||
case 'accounts':
|
||||
this.addAccount(values);
|
||||
break;
|
||||
case 'accounts_proposed':
|
||||
this.addAccountProposed(values);
|
||||
break;
|
||||
case 'books':
|
||||
this.addBook(values);
|
||||
break;
|
||||
}
|
||||
} else if (arguments.length > 1) {
|
||||
for (arg in arguments) {
|
||||
this.addStream(arguments[arg]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Array.isArray(this.message.streams)) {
|
||||
this.message.streams = [ ];
|
||||
}
|
||||
|
||||
if (this.message.streams.indexOf(stream) === -1) {
|
||||
this.message.streams.push(stream);
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
exports.Request = Request;
|
||||
|
||||
@@ -33,8 +33,8 @@ Seed.prototype.parse_json = function (j) {
|
||||
// XXX Should actually always try and continue if it failed.
|
||||
} else if (j[0] === 's') {
|
||||
this._value = Base.decode_check(Base.VER_FAMILY_SEED, j);
|
||||
} else if (j.length === 32) {
|
||||
this._value = this.parse_hex(j);
|
||||
} else if (/^[0-9a-fA-f]{32}$/.test(j)) {
|
||||
this.parse_hex(j);
|
||||
// XXX Should also try 1751
|
||||
} else {
|
||||
this.parse_passphrase(j);
|
||||
@@ -93,9 +93,14 @@ function SHA256_RIPEMD160(bits) {
|
||||
*
|
||||
* {Uint160} (from_json able), specifies the address matching the KeyPair
|
||||
* that is desired.
|
||||
*
|
||||
* @param maxLoops (optional)
|
||||
* {Number} specifies the amount of attempts taken to generate
|
||||
* a matching KeyPair
|
||||
*/
|
||||
Seed.prototype.get_key = function (account) {
|
||||
Seed.prototype.get_key = function (account, maxLoops) {
|
||||
var account_number = 0, address;
|
||||
var max_loops = maxLoops || 1;
|
||||
|
||||
if (!this.is_valid()) {
|
||||
throw new Error('Cannot generate keys from invalid seed!');
|
||||
@@ -103,6 +108,7 @@ Seed.prototype.get_key = function (account) {
|
||||
if (account) {
|
||||
if (typeof account === 'number') {
|
||||
account_number = account;
|
||||
max_loops = account_number+1;
|
||||
} else {
|
||||
address = UInt160.from_json(account);
|
||||
}
|
||||
@@ -121,9 +127,9 @@ Seed.prototype.get_key = function (account) {
|
||||
|
||||
var sec;
|
||||
var key_pair;
|
||||
var max_loops = 1000; // TODO
|
||||
|
||||
do {
|
||||
|
||||
i = 0;
|
||||
|
||||
do {
|
||||
@@ -135,15 +141,15 @@ Seed.prototype.get_key = function (account) {
|
||||
sec = sec.add(private_gen).mod(curve.r);
|
||||
key_pair = KeyPair.from_bn_secret(sec);
|
||||
|
||||
if (--max_loops <= 0) {
|
||||
if (max_loops-- <= 0) {
|
||||
// We are almost certainly looking for an account that would take same
|
||||
// value of $too_long {forever, ...}
|
||||
throw new Error('Too many loops looking for KeyPair yielding '+
|
||||
address.to_json() +' from ' + this.to_json());
|
||||
};
|
||||
} while (address && !key_pair.get_address().equals(address));
|
||||
}
|
||||
|
||||
return key_pair;
|
||||
} while (address && !key_pair.get_address().equals(address));
|
||||
return key_pair;
|
||||
};
|
||||
|
||||
exports.Seed = Seed;
|
||||
|
||||
@@ -117,7 +117,7 @@ SerializedType.prototype.parse_varint = function (so) {
|
||||
*/
|
||||
function append_byte_array(so, val, bytes) {
|
||||
if (!isNumber(val)) {
|
||||
throw new Error('Value is not a number');
|
||||
throw new Error('Value is not a number', bytes);
|
||||
}
|
||||
|
||||
if (val < 0 || val >= Math.pow(256, bytes)) {
|
||||
@@ -345,7 +345,7 @@ var STAmount = exports.Amount = new SerializedType({
|
||||
|
||||
// Next eight bits: offset/exponent
|
||||
hi |= ((97 + amount._offset) & 0xff) << 22;
|
||||
// Remaining 52 bits: mantissa
|
||||
// Remaining 54 bits: mantissa
|
||||
hi |= amount._value.shiftRight(32).intValue() & 0x3fffff;
|
||||
lo = amount._value.intValue() & 0xffffffff;
|
||||
}
|
||||
@@ -625,7 +625,13 @@ function serialize(so, field_name, value) {
|
||||
// Get the serializer class (ST...) for a field based on the type bits.
|
||||
var serialized_object_type = exports[binformat.types[type_bits]];
|
||||
//do something with val[keys] and val[keys[i]];
|
||||
serialized_object_type.serialize(so, value);
|
||||
|
||||
try {
|
||||
serialized_object_type.serialize(so, value);
|
||||
} catch (e) {
|
||||
e.message += ' (' + field_name + ')';
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
//Take the serialized object, figure out what type/field it is, and return the parsing of that.
|
||||
|
||||
@@ -51,51 +51,48 @@ function Server(remote, opts) {
|
||||
}
|
||||
|
||||
this._remote = remote;
|
||||
this._opts = opts;
|
||||
this._ws = void(0);
|
||||
this._opts = opts;
|
||||
this._ws = void(0);
|
||||
|
||||
this._connected = false;
|
||||
this._connected = false;
|
||||
this._shouldConnect = false;
|
||||
this._state = 'offline';
|
||||
this._state = 'offline';
|
||||
|
||||
this._id = 0;
|
||||
this._retry = 0;
|
||||
this._id = 0; // request ID
|
||||
this._retry = 0;
|
||||
this._requests = { };
|
||||
|
||||
this._load_base = 256;
|
||||
this._load_base = 256;
|
||||
this._load_factor = 256;
|
||||
|
||||
this._fee = 10;
|
||||
this._fee_ref = 10;
|
||||
this._fee_base = 10;
|
||||
this._fee = 10;
|
||||
this._fee_ref = 10;
|
||||
this._fee_base = 10;
|
||||
this._reserve_base = void(0);
|
||||
this._reserve_inc = void(0);
|
||||
this._fee_cushion = this._remote.fee_cushion;
|
||||
this._reserve_inc = void(0);
|
||||
this._fee_cushion = this._remote.fee_cushion;
|
||||
|
||||
this._lastLedgerIndex = NaN;
|
||||
this._lastLedgerClose = NaN;
|
||||
|
||||
this._score = 0;
|
||||
|
||||
this._scoreWeights = {
|
||||
ledgerclose: 5,
|
||||
response: 1
|
||||
};
|
||||
|
||||
this._pubkey_node = '';
|
||||
|
||||
this._url = this._opts.url = (this._opts.secure ? 'wss://' : 'ws://')
|
||||
+ this._opts.host + ':' + this._opts.port;
|
||||
|
||||
this.on('message', onMessage);
|
||||
|
||||
function onMessage(message) {
|
||||
this.on('message', function onMessage(message) {
|
||||
self._handleMessage(message);
|
||||
};
|
||||
});
|
||||
|
||||
this.on('response_subscribe', onSubscribeResponse);
|
||||
|
||||
function onSubscribeResponse(message) {
|
||||
this.on('response_subscribe', function onSubscribe(message) {
|
||||
self._handleResponseSubscribe(message);
|
||||
};
|
||||
});
|
||||
|
||||
function setActivityInterval() {
|
||||
var interval = self._checkActivity.bind(self);
|
||||
@@ -109,17 +106,38 @@ function Server(remote, opts) {
|
||||
|
||||
this.once('ledger_closed', setActivityInterval);
|
||||
|
||||
this._remote.on('ledger_closed', function(ledger) {
|
||||
this._remote.on('ledger_closed', function onRemoteLedgerClose(ledger) {
|
||||
self._updateScore('ledgerclose', ledger);
|
||||
});
|
||||
|
||||
this.on('response_ping', function(message, request) {
|
||||
this.on('response_ping', function onPingResponse(message, request) {
|
||||
self._updateScore('response', request);
|
||||
});
|
||||
|
||||
this.on('load_changed', function(load) {
|
||||
this.on('load_changed', function onLoadChange(load) {
|
||||
self._updateScore('loadchange', load);
|
||||
});
|
||||
|
||||
// If server is not up-to-date, request server_info
|
||||
// for getting pubkey_node & hostid information.
|
||||
// Otherwise this information is available on the
|
||||
// initial server subscribe response
|
||||
this.on('connect', function requestServerID() {
|
||||
if (self._pubkey_node) {
|
||||
return;
|
||||
}
|
||||
|
||||
self.on('response_server_info', function setServerID(message) {
|
||||
try {
|
||||
self._pubkey_node = message.info.pubkey_node;
|
||||
} catch (e) {
|
||||
}
|
||||
});
|
||||
|
||||
var serverInfoRequest = self._remote.requestServerInfo();
|
||||
serverInfoRequest.on('error', function() { });
|
||||
self._request(serverInfoRequest);
|
||||
});
|
||||
};
|
||||
|
||||
util.inherits(Server, EventEmitter);
|
||||
@@ -168,7 +186,7 @@ Server.websocketConstructor = function() {
|
||||
Server.prototype._setState = function(state) {
|
||||
if (state !== this._state) {
|
||||
if (this._remote.trace) {
|
||||
log.info('set_state:', state);
|
||||
log.info(this.getServerID(), 'set_state:', state);
|
||||
}
|
||||
|
||||
this._state = state;
|
||||
@@ -177,6 +195,7 @@ Server.prototype._setState = function(state) {
|
||||
switch (state) {
|
||||
case 'online':
|
||||
this._connected = true;
|
||||
this._retry = 0;
|
||||
this.emit('connect');
|
||||
break;
|
||||
case 'offline':
|
||||
@@ -199,7 +218,7 @@ Server.prototype._setState = function(state) {
|
||||
*/
|
||||
|
||||
Server.prototype._checkActivity = function() {
|
||||
if (!this._connected) {
|
||||
if (!this.isConnected()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -210,6 +229,9 @@ Server.prototype._checkActivity = function() {
|
||||
var delta = (Date.now() - this._lastLedgerClose);
|
||||
|
||||
if (delta > (1000 * 25)) {
|
||||
if (this._remote.trace) {
|
||||
log.info(this.getServerID(), 'reconnect: activity delta:', delta);
|
||||
}
|
||||
this.reconnect();
|
||||
}
|
||||
};
|
||||
@@ -227,7 +249,7 @@ Server.prototype._checkActivity = function() {
|
||||
*/
|
||||
|
||||
Server.prototype._updateScore = function(type, data) {
|
||||
if (!this._connected) {
|
||||
if (!this.isConnected()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -253,15 +275,20 @@ Server.prototype._updateScore = function(type, data) {
|
||||
}
|
||||
|
||||
if (this._score > 1e3) {
|
||||
if (this._remote.trace) {
|
||||
log.info(this.getServerID(), 'reconnect: score:', this._score);
|
||||
}
|
||||
this.reconnect();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the remote address for a server.
|
||||
* Get the server's remote address
|
||||
*
|
||||
* Incompatible with ripple-lib client build
|
||||
*/
|
||||
|
||||
Server.prototype.getRemoteAddress =
|
||||
Server.prototype._remoteAddress = function() {
|
||||
var address;
|
||||
try {
|
||||
@@ -271,6 +298,15 @@ Server.prototype._remoteAddress = function() {
|
||||
return address;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the server's hostid
|
||||
*/
|
||||
|
||||
Server.prototype.getHostID =
|
||||
Server.prototype.getServerID = function() {
|
||||
return this._url + ' (' + (this._pubkey_node ? this._pubkey_node : '') + ')';
|
||||
};
|
||||
|
||||
/**
|
||||
* Disconnect from rippled WebSocket server
|
||||
*
|
||||
@@ -278,8 +314,23 @@ Server.prototype._remoteAddress = function() {
|
||||
*/
|
||||
|
||||
Server.prototype.disconnect = function() {
|
||||
var self = this;
|
||||
|
||||
if (!this.isConnected()) {
|
||||
this.once('socket_open', function() {
|
||||
self.disconnect();
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
//these need to be reset so that updateScore
|
||||
//and checkActivity do not trigger reconnect
|
||||
this._lastLedgerIndex = NaN;
|
||||
this._lastLedgerClose = NaN;
|
||||
this._score = 0;
|
||||
this._shouldConnect = false;
|
||||
this._setState('offline');
|
||||
|
||||
if (this._ws) {
|
||||
this._ws.close();
|
||||
}
|
||||
@@ -294,13 +345,19 @@ Server.prototype.disconnect = function() {
|
||||
Server.prototype.reconnect = function() {
|
||||
var self = this;
|
||||
|
||||
function disconnected() {
|
||||
function reconnect() {
|
||||
self._shouldConnect = true;
|
||||
self._retry = 0;
|
||||
self.connect();
|
||||
};
|
||||
|
||||
if (this._ws) {
|
||||
this.once('disconnect', disconnected);
|
||||
this.disconnect();
|
||||
if (this._ws && this._shouldConnect) {
|
||||
if (this.isConnected()) {
|
||||
this.once('disconnect', reconnect);
|
||||
this.disconnect();
|
||||
} else {
|
||||
reconnect();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -315,27 +372,27 @@ Server.prototype.reconnect = function() {
|
||||
Server.prototype.connect = function() {
|
||||
var self = this;
|
||||
|
||||
var WebSocket = Server.websocketConstructor();
|
||||
|
||||
if (!WebSocket) {
|
||||
throw new Error('No websocket support detected!');
|
||||
}
|
||||
|
||||
// We don't connect if we believe we're already connected. This means we have
|
||||
// recently received a message from the server and the WebSocket has not
|
||||
// reported any issues either. If we do fail to ping or the connection drops,
|
||||
// we will automatically reconnect.
|
||||
if (this._connected) {
|
||||
if (this.isConnected()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._remote.trace) {
|
||||
log.info('connect:', this._opts.url);
|
||||
}
|
||||
|
||||
// Ensure any existing socket is given the command to close first.
|
||||
if (this._ws) {
|
||||
this._ws.close();
|
||||
}
|
||||
|
||||
var WebSocket = Server.websocketConstructor();
|
||||
|
||||
if (!WebSocket) {
|
||||
throw new Error('No websocket support detected!');
|
||||
if (this._remote.trace) {
|
||||
log.info(this.getServerID(), 'connect');
|
||||
}
|
||||
|
||||
var ws = this._ws = new WebSocket(this._opts.url);
|
||||
@@ -352,7 +409,7 @@ Server.prototype.connect = function() {
|
||||
if (ws === self._ws) {
|
||||
self.emit('socket_open');
|
||||
// Subscribe to events
|
||||
self._request(self._remote._serverPrepareSubscribe());
|
||||
self._request(self._remote._serverPrepareSubscribe(self));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -361,7 +418,7 @@ Server.prototype.connect = function() {
|
||||
self.emit('socket_error');
|
||||
|
||||
if (self._remote.trace) {
|
||||
log.info('onerror:', self._opts.url, e.data || e);
|
||||
log.info(self.getServerID(), 'onerror:', e.data || e);
|
||||
}
|
||||
|
||||
// Most connection errors for WebSockets are conveyed as 'close' events with
|
||||
@@ -385,7 +442,7 @@ Server.prototype.connect = function() {
|
||||
ws.onclose = function onClose() {
|
||||
if (ws === self._ws) {
|
||||
if (self._remote.trace) {
|
||||
log.info('onclose:', self._opts.url, ws.readyState);
|
||||
log.info(self.getServerID(), 'onclose:', ws.readyState);
|
||||
}
|
||||
self._handleClose();
|
||||
}
|
||||
@@ -418,7 +475,7 @@ Server.prototype._retryConnect = function() {
|
||||
function connectionRetry() {
|
||||
if (self._shouldConnect) {
|
||||
if (self._remote.trace) {
|
||||
log.info('retry', self._opts.url);
|
||||
log.info(self.getServerID(), 'retry', self._retry);
|
||||
}
|
||||
self.connect();
|
||||
}
|
||||
@@ -437,15 +494,15 @@ Server.prototype._handleClose = function() {
|
||||
var self = this;
|
||||
var ws = this._ws;
|
||||
|
||||
this.emit('socket_close');
|
||||
this._setState('offline');
|
||||
|
||||
function noOp(){};
|
||||
|
||||
// Prevent additional events from this socket
|
||||
ws.onopen = ws.onerror = ws.onclose = ws.onmessage = noOp;
|
||||
|
||||
if (self._shouldConnect) {
|
||||
this.emit('socket_close');
|
||||
this._setState('offline');
|
||||
|
||||
if (this._shouldConnect) {
|
||||
this._retryConnect();
|
||||
}
|
||||
};
|
||||
@@ -496,6 +553,7 @@ Server.prototype._handleServerStatus = function(message) {
|
||||
// This message is only received when online.
|
||||
// As we are connected, it is the definitive final state.
|
||||
var isOnline = ~Server.onlineStates.indexOf(message.server_status);
|
||||
|
||||
this._setState(isOnline ? 'online' : 'offline');
|
||||
|
||||
if (!Server.isLoadStatus(message)) {
|
||||
@@ -506,7 +564,7 @@ Server.prototype._handleServerStatus = function(message) {
|
||||
this._remote.emit('load', message, this);
|
||||
|
||||
var loadChanged = message.load_base !== this._load_base
|
||||
|| message.load_factor !== this._load_factor
|
||||
|| message.load_factor !== this._load_factor;
|
||||
|
||||
if (loadChanged) {
|
||||
this._load_base = message.load_base;
|
||||
@@ -524,14 +582,14 @@ Server.prototype._handleResponse = function(message) {
|
||||
|
||||
if (!request) {
|
||||
if (this._remote.trace) {
|
||||
log.info('UNEXPECTED:', this._opts.url, message);
|
||||
log.info(this.getServerID(), 'UNEXPECTED:', message);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.status === 'success') {
|
||||
if (this._remote.trace) {
|
||||
log.info('response:', this._opts.url, message);
|
||||
log.info(this.getServerID(), 'response:', message);
|
||||
}
|
||||
|
||||
var command = request.message.command;
|
||||
@@ -545,22 +603,20 @@ Server.prototype._handleResponse = function(message) {
|
||||
});
|
||||
} else if (message.error) {
|
||||
if (this._remote.trace) {
|
||||
log.info('error:', this._opts.url, message);
|
||||
log.info(this.getServerID(), 'error:', message);
|
||||
}
|
||||
|
||||
var error = {
|
||||
request.emit('error', {
|
||||
error: 'remoteError',
|
||||
error_message: 'Remote reported an error.',
|
||||
remote: message
|
||||
};
|
||||
|
||||
request.emit('error', error);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Server.prototype._handlePathFind = function(message) {
|
||||
if (this._remote.trace) {
|
||||
log.info('path_find:', this._opts.url, message);
|
||||
log.info(this.getServerID(), 'path_find:', message);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -568,27 +624,53 @@ Server.prototype._handlePathFind = function(message) {
|
||||
* Handle subscription response messages. Subscription response
|
||||
* messages indicate that a connection to the server is ready
|
||||
*
|
||||
* @param {Object} message
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Server.prototype._handleResponseSubscribe = function(message) {
|
||||
if (~(Server.onlineStates.indexOf(message.server_status))) {
|
||||
this._setState('online');
|
||||
if (!this._remote._allow_partial_history
|
||||
&& !Server.hasFullLedgerHistory(message)) {
|
||||
// Server has partial history and Remote has been configured to disallow
|
||||
// servers with incomplete history
|
||||
return this.reconnect();
|
||||
}
|
||||
if (message.pubkey_node) {
|
||||
// pubkey_node is used to identify the server
|
||||
this._pubkey_node = message.pubkey_node;
|
||||
}
|
||||
if (Server.isLoadStatus(message)) {
|
||||
this._load_base = message.load_base || 256;
|
||||
this._load_factor = message.load_factor || 256;
|
||||
this._fee_ref = message.fee_ref;
|
||||
this._fee_base = message.fee_base;
|
||||
this._load_base = message.load_base || 256;
|
||||
this._load_factor = message.load_factor || 256;
|
||||
this._fee_ref = message.fee_ref || 10;
|
||||
this._fee_base = message.fee_base || 10;
|
||||
this._reserve_base = message.reserve_base;
|
||||
this._reserve_inc = message.reserve_inc;
|
||||
this._reserve_inc = message.reserve_inc;
|
||||
}
|
||||
if (~Server.onlineStates.indexOf(message.server_status)) {
|
||||
this._setState('online');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Check that server message indicates that server has complete ledger history
|
||||
*
|
||||
* @param {Object} message
|
||||
* @return {Boolean}
|
||||
*/
|
||||
|
||||
Server.hasFullLedgerHistory = function(message) {
|
||||
return (typeof message === 'object')
|
||||
&& (message.server_status === 'full')
|
||||
&& (typeof message.validated_ledgers === 'string')
|
||||
&& (message.validated_ledgers.split('-').length === 2);
|
||||
};
|
||||
|
||||
/**
|
||||
* Check that received message from rippled is valid
|
||||
*
|
||||
* @api private
|
||||
* @param {Object} message
|
||||
* @return {Boolean}
|
||||
*/
|
||||
|
||||
Server.isValidMessage = function(message) {
|
||||
@@ -597,14 +679,15 @@ Server.isValidMessage = function(message) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Check that received serverStatus message contains
|
||||
* load status information
|
||||
* Check that received serverStatus message contains load status information
|
||||
*
|
||||
* @api private
|
||||
* @param {Object} message
|
||||
* @return {Boolean}
|
||||
*/
|
||||
|
||||
Server.isLoadStatus = function(message) {
|
||||
return (typeof message.load_base === 'number')
|
||||
return (typeof message === 'object')
|
||||
&& (typeof message.load_base === 'number')
|
||||
&& (typeof message.load_factor === 'number');
|
||||
};
|
||||
|
||||
@@ -618,17 +701,17 @@ Server.isLoadStatus = function(message) {
|
||||
Server.prototype._sendMessage = function(message) {
|
||||
if (this._ws) {
|
||||
if (this._remote.trace) {
|
||||
log.info('request:', this._opts.url, message);
|
||||
log.info(this.getServerID(), 'request:', message);
|
||||
}
|
||||
this._ws.send(JSON.stringify(message));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Submit a Request object.
|
||||
* Submit a Request object
|
||||
*
|
||||
* Requests are indexed by message ID, which is repeated
|
||||
* in the response from rippled WebSocket server
|
||||
* Requests are indexed by message ID, which is repeated in the response from
|
||||
* rippled WebSocket server
|
||||
*
|
||||
* @param {Request} request
|
||||
* @api private
|
||||
@@ -640,7 +723,7 @@ Server.prototype._request = function(request) {
|
||||
// Only bother if we are still connected.
|
||||
if (!this._ws) {
|
||||
if (this._remote.trace) {
|
||||
log.info('request: DROPPING:', self._opts.url, request.message);
|
||||
log.info(this.getServerID(), 'request: DROPPING:', request.message);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -658,20 +741,19 @@ Server.prototype._request = function(request) {
|
||||
self._sendMessage(request.message);
|
||||
};
|
||||
|
||||
if (this._isConnected(request)) {
|
||||
var isOpen = this._ws.readyState === 1;
|
||||
var isSubscribeRequest = request && request.message.command === 'subscribe';
|
||||
|
||||
if (this.isConnected() || (isOpen && isSubscribeRequest)) {
|
||||
sendRequest();
|
||||
} else {
|
||||
// XXX There are many ways to make this smarter.
|
||||
this.once('connect', sendRequest);
|
||||
}
|
||||
};
|
||||
|
||||
Server.prototype._isConnected = function(request) {
|
||||
var isSubscribeRequest = request
|
||||
&& request.message.command === 'subscribe'
|
||||
&& this._ws.readyState === 1;
|
||||
|
||||
return this._connected || (this._ws && isSubscribeRequest);
|
||||
Server.prototype.isConnected =
|
||||
Server.prototype._isConnected = function() {
|
||||
return this._connected;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -60,7 +60,7 @@ function Transaction(remote) {
|
||||
|
||||
var self = this;
|
||||
|
||||
var remote = remote || { };
|
||||
var remote = remote || void(0);
|
||||
|
||||
this.remote = remote;
|
||||
|
||||
@@ -69,7 +69,7 @@ function Transaction(remote) {
|
||||
|
||||
this._secret = void(0);
|
||||
this._build_path = false;
|
||||
this._maxFee = this.remote.max_fee;
|
||||
this._maxFee = (typeof remote === 'object') ? this.remote.max_fee : void(0);
|
||||
|
||||
this.state = 'unsubmitted';
|
||||
this.finalized = false;
|
||||
@@ -79,7 +79,7 @@ function Transaction(remote) {
|
||||
this.submitIndex = void(0);
|
||||
|
||||
// Canonical signing setting defaults to the Remote's configuration
|
||||
this.canonical = (typeof remote === 'object') ? !!remote.canonical_signing : true;
|
||||
this.canonical = (typeof remote === 'object') ? Boolean(remote.canonical_signing) : true;
|
||||
|
||||
// We aren't clever enough to eschew preventative measures so we keep an array
|
||||
// of all submitted transactionIDs (which can change due to load_factor
|
||||
@@ -133,7 +133,10 @@ Transaction.flags = {
|
||||
TrustSet: {
|
||||
SetAuth: 0x00010000,
|
||||
NoRipple: 0x00020000,
|
||||
ClearNoRipple: 0x00040000
|
||||
SetNoRipple: 0x00020000,
|
||||
ClearNoRipple: 0x00040000,
|
||||
SetFreeze: 0x00100000,
|
||||
ClearFreeze: 0x00200000
|
||||
},
|
||||
|
||||
OfferCreate: {
|
||||
@@ -158,10 +161,15 @@ Transaction.set_clear_flags = {
|
||||
asfRequireDest: 1,
|
||||
asfRequireAuth: 2,
|
||||
asfDisallowXRP: 3,
|
||||
asfDisableMaster: 4
|
||||
asfDisableMaster: 4,
|
||||
asfNoFreeze: 6,
|
||||
asfGlobalFreeze: 7
|
||||
}
|
||||
};
|
||||
|
||||
Transaction.MEMO_TYPES = {
|
||||
};
|
||||
|
||||
Transaction.formats = require('./binformat').tx;
|
||||
|
||||
Transaction.prototype.consts = {
|
||||
@@ -233,7 +241,7 @@ Transaction.prototype.finalize = function(message) {
|
||||
};
|
||||
|
||||
Transaction.prototype._accountSecret = function(account) {
|
||||
return this.remote.secrets[account];
|
||||
return this.remote ? this.remote.secrets[account] : void(0);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -258,6 +266,10 @@ Transaction.prototype.feeUnits = function() {
|
||||
*/
|
||||
|
||||
Transaction.prototype._computeFee = function() {
|
||||
if (!this.remote) {
|
||||
return void(0);
|
||||
}
|
||||
|
||||
var servers = this.remote._servers;
|
||||
var fees = [ ];
|
||||
|
||||
@@ -472,13 +484,30 @@ Transaction.prototype.clientID = function(id) {
|
||||
};
|
||||
|
||||
Transaction.prototype.lastLedger = function(sequence) {
|
||||
if (typeof sequence === 'number') {
|
||||
if (typeof sequence === 'number' && isFinite(sequence)) {
|
||||
this._setLastLedger = true;
|
||||
this.tx_json.LastLedgerSequence = sequence;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
/*
|
||||
* Set the transaction's proposed fee. No op when fee parameter
|
||||
* is not 0 or a positive number
|
||||
*
|
||||
* @param {Number} fee The proposed fee
|
||||
*
|
||||
* @returns {Transaction} calling instance for chaining
|
||||
*/
|
||||
Transaction.prototype.maxFee = function(fee) {
|
||||
if (typeof fee === 'number' && fee >= 0) {
|
||||
this._setMaxFee = true;
|
||||
this._maxFee = fee;
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
Transaction._pathRewrite = function(path) {
|
||||
if (!Array.isArray(path)) {
|
||||
return;
|
||||
@@ -590,6 +619,48 @@ Transaction.prototype.setFlags = function(flags) {
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add a Memo to transaction. Memos can be used as key-value,
|
||||
* using the MemoType as a key
|
||||
*
|
||||
* @param {String} type
|
||||
* @param {String} data
|
||||
*/
|
||||
|
||||
Transaction.prototype.addMemo = function(type, data) {
|
||||
if (!/(undefined|string)/.test(typeof type)) {
|
||||
throw new Error('MemoType must be a string');
|
||||
}
|
||||
|
||||
if (!/(undefined|string)/.test(typeof data)) {
|
||||
throw new Error('MemoData must be a string');
|
||||
}
|
||||
|
||||
function toHex(str) {
|
||||
return sjcl.codec.hex.fromBits(sjcl.codec.utf8String.toBits(str));
|
||||
};
|
||||
|
||||
var memo = { };
|
||||
|
||||
if (type) {
|
||||
if (Transaction.MEMO_TYPES[type]) {
|
||||
//XXX Maybe in the future we want a schema validator for
|
||||
//memo types
|
||||
memo.MemoType = Transaction.MEMO_TYPES[type];
|
||||
} else {
|
||||
memo.MemoType = toHex(type);
|
||||
}
|
||||
}
|
||||
|
||||
if (data) {
|
||||
memo.MemoData = toHex(data);
|
||||
}
|
||||
|
||||
this.tx_json.Memos = (this.tx_json.Memos || []).concat({ Memo: memo });
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
// Options:
|
||||
// .domain() NYI
|
||||
// .flags()
|
||||
@@ -848,6 +919,10 @@ Transaction.prototype.submit = function(callback) {
|
||||
|
||||
var account = this.tx_json.Account;
|
||||
|
||||
if (!this.remote) {
|
||||
return this.emit('error', new Error('No remote found'));
|
||||
}
|
||||
|
||||
if (!UInt160.is_valid(account)) {
|
||||
return this.emit('error', new RippleError('tejInvalidAccount', 'Account is missing or invalid'));
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ function TransactionManager(account) {
|
||||
this._remote = account._remote;
|
||||
this._nextSequence = void(0);
|
||||
this._maxFee = this._remote.max_fee;
|
||||
this._maxAttempts = this._remote.max_attempts;
|
||||
this._submissionTimeout = this._remote._submission_timeout;
|
||||
this._pending = new PendingQueue();
|
||||
|
||||
@@ -344,7 +345,7 @@ TransactionManager.prototype._request = function(tx) {
|
||||
var self = this;
|
||||
var remote = this._remote;
|
||||
|
||||
if (tx.attempts > 10) {
|
||||
if (tx.attempts > this._maxAttempts) {
|
||||
return tx.emit('error', new RippleError('tejAttemptsExceeded'));
|
||||
}
|
||||
|
||||
@@ -386,6 +387,13 @@ TransactionManager.prototype._request = function(tx) {
|
||||
case 'tefPAST_SEQ':
|
||||
self._resubmit(1, tx);
|
||||
break;
|
||||
case 'tefALREADY':
|
||||
if (tx.responses === tx.submissions) {
|
||||
tx.emit('error', message);
|
||||
} else {
|
||||
submitRequest.once('success', submitted);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
tx.emit('error', message);
|
||||
}
|
||||
@@ -450,6 +458,7 @@ TransactionManager.prototype._request = function(tx) {
|
||||
message.result = message.engine_result || '';
|
||||
|
||||
tx.result = message;
|
||||
tx.responses += 1;
|
||||
|
||||
if (remote.trace) {
|
||||
log.info('submit response:', message);
|
||||
@@ -543,7 +552,7 @@ TransactionManager.prototype._request = function(tx) {
|
||||
}
|
||||
|
||||
submitRequest.timeout(self._submissionTimeout, requestTimeout);
|
||||
submitRequest.broadcast();
|
||||
tx.submissions = submitRequest.broadcast();
|
||||
|
||||
tx.attempts++;
|
||||
tx.emit('postsubmit');
|
||||
@@ -656,6 +665,8 @@ TransactionManager.prototype.submit = function(tx) {
|
||||
}
|
||||
|
||||
tx.attempts = 0;
|
||||
tx.submissions = 0;
|
||||
tx.responses = 0;
|
||||
|
||||
// ND: this is the ONLY place we put the tx into the queue. The
|
||||
// TransactionQueue queue is merely a list, so any mutations to tx._hash
|
||||
|
||||
@@ -55,9 +55,10 @@ VaultClient.prototype.getAuthInfo = function (username, callback) {
|
||||
*/
|
||||
|
||||
VaultClient.prototype._deriveLoginKeys = function (authInfo, password, callback) {
|
||||
|
||||
var normalizedUsername = authInfo.username.toLowerCase().replace(/-/g, '');
|
||||
|
||||
//derive login keys
|
||||
crypt.derive(authInfo.pakdf, 'login', authInfo.username.toLowerCase(), password, function(err, keys) {
|
||||
crypt.derive(authInfo.pakdf, 'login', normalizedUsername, password, function(err, keys) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
} else {
|
||||
@@ -74,8 +75,10 @@ VaultClient.prototype._deriveLoginKeys = function (authInfo, password, callback)
|
||||
*/
|
||||
|
||||
VaultClient.prototype._deriveUnlockKey = function (authInfo, password, keys, callback) {
|
||||
var normalizedUsername = authInfo.username.toLowerCase().replace(/-/g, '');
|
||||
|
||||
//derive unlock key
|
||||
crypt.derive(authInfo.pakdf, 'unlock', authInfo.username.toLowerCase(), password, function(err, unlock) {
|
||||
crypt.derive(authInfo.pakdf, 'unlock', normalizedUsername, password, function(err, unlock) {
|
||||
if (err) {
|
||||
log.error('derive:', err);
|
||||
return callback(err);
|
||||
@@ -130,7 +133,7 @@ VaultClient.prototype.exists = function(username, callback) {
|
||||
* @param {function} fn - Callback function
|
||||
*/
|
||||
|
||||
VaultClient.prototype.login = function(username, password, callback) {
|
||||
VaultClient.prototype.login = function(username, password, device_id, callback) {
|
||||
var self = this;
|
||||
|
||||
var steps = [
|
||||
@@ -153,7 +156,14 @@ VaultClient.prototype.login = function(username, password, callback) {
|
||||
}
|
||||
|
||||
function getBlob(authInfo, password, keys, callback) {
|
||||
blobClient.get(authInfo.blobvault, keys.id, keys.crypt, function(err, blob) {
|
||||
var options = {
|
||||
url : authInfo.blobvault,
|
||||
blob_id : keys.id,
|
||||
key : keys.crypt,
|
||||
device_id : device_id
|
||||
};
|
||||
|
||||
blobClient.get(options, function(err, blob) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -215,7 +225,7 @@ VaultClient.prototype.login = function(username, password, callback) {
|
||||
* @param {function} fn - Callback function
|
||||
*/
|
||||
|
||||
VaultClient.prototype.relogin = function(url, id, key, callback) {
|
||||
VaultClient.prototype.relogin = function(url, id, key, device_id, callback) {
|
||||
//use the url from previously retrieved authInfo, if necessary
|
||||
if (!url && this.infos[id]) {
|
||||
url = this.infos[id].blobvault;
|
||||
@@ -225,7 +235,14 @@ VaultClient.prototype.relogin = function(url, id, key, callback) {
|
||||
return callback(new Error('Blob vault URL is required'));
|
||||
}
|
||||
|
||||
blobClient.get(url, id, key, function(err, blob) {
|
||||
var options = {
|
||||
url : url,
|
||||
blob_id : id,
|
||||
key : key,
|
||||
device_id : device_id
|
||||
};
|
||||
|
||||
blobClient.get(options, function(err, blob) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
} else {
|
||||
@@ -290,7 +307,7 @@ VaultClient.prototype.unlock = function(username, password, encryptSecret, fn) {
|
||||
* @param {function} fn - Callback function
|
||||
*/
|
||||
|
||||
VaultClient.prototype.loginAndUnlock = function(username, password, fn) {
|
||||
VaultClient.prototype.loginAndUnlock = function(username, password, device_id, fn) {
|
||||
var self = this;
|
||||
|
||||
var steps = [
|
||||
@@ -302,7 +319,7 @@ VaultClient.prototype.loginAndUnlock = function(username, password, fn) {
|
||||
async.waterfall(steps, fn);
|
||||
|
||||
function login (callback) {
|
||||
self.login(username, password, function(err, resp) {
|
||||
self.login(username, password, device_id, function(err, resp) {
|
||||
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -371,69 +388,6 @@ VaultClient.prototype.verify = function(username, token, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* resendEmail
|
||||
* send a new verification email
|
||||
* @param {object} options
|
||||
* @param {string} options.id
|
||||
* @param {string} options.username
|
||||
* @param {string} options.account_id
|
||||
* @param {string} options.email
|
||||
* @param {string} options.activateLink
|
||||
* @param {function} fn - Callback
|
||||
*/
|
||||
|
||||
VaultClient.prototype.resendEmail = function (options, fn) {
|
||||
blobClient.resendEmail(options, fn);
|
||||
};
|
||||
|
||||
/**
|
||||
* deleteBlob
|
||||
* @param {object} options
|
||||
* @param {string} options.url
|
||||
* @param {string} options.username
|
||||
* @param {string} options.blob_id
|
||||
* @param {string} options.account_id
|
||||
* @param {string} options.masterkey
|
||||
*/
|
||||
|
||||
VaultClient.prototype.deleteBlob = function (options, fn) {
|
||||
blobClient.deleteBlob(options, fn);
|
||||
};
|
||||
|
||||
/**
|
||||
* updateProfile
|
||||
* update information stored outside the blob
|
||||
* @param {object}
|
||||
* @param {string} options.url
|
||||
* @param {string} options.username
|
||||
* @param {string} options.auth_secret
|
||||
* @param {srring} options.blob_id
|
||||
* @param {object} options.profile
|
||||
* @param {string} options.profile.phone - optional
|
||||
* @param {string} options.profile.country - optional
|
||||
* @param {string} options.profile.region - optional
|
||||
* @param {string} options.profile.city - optional
|
||||
*/
|
||||
|
||||
VaultClient.prototype.updateProfile = function (options, fn) {
|
||||
blobClient.updateProfile(options, fn);
|
||||
};
|
||||
|
||||
/**
|
||||
* recoverBlob
|
||||
* recover blob with account secret
|
||||
* @param {object} options
|
||||
* @param {string} options.url
|
||||
* @param {string} options.username
|
||||
* @param {string} options.masterkey
|
||||
* @param {function}
|
||||
*/
|
||||
|
||||
VaultClient.prototype.recoverBlob = function (options, fn) {
|
||||
blobClient.recoverBlob(options, fn);
|
||||
};
|
||||
|
||||
/*
|
||||
* changePassword
|
||||
* @param {object} options
|
||||
@@ -578,6 +532,11 @@ VaultClient.prototype.register = function(options, fn) {
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* validateUsername
|
||||
* check username for validity
|
||||
*/
|
||||
|
||||
VaultClient.prototype.validateUsername = function (username) {
|
||||
username = String(username).trim();
|
||||
var result = {
|
||||
@@ -604,4 +563,31 @@ VaultClient.prototype.validateUsername = function (username) {
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* generateDeviceID
|
||||
* create a new random device ID for 2FA
|
||||
*/
|
||||
VaultClient.prototype.generateDeviceID = function () {
|
||||
return crypt.createSecret(4);
|
||||
};
|
||||
|
||||
/*** pass thru some blob client function ***/
|
||||
|
||||
VaultClient.prototype.resendEmail = blobClient.resendEmail;
|
||||
|
||||
VaultClient.prototype.recoverBlob = blobClient.recoverBlob;
|
||||
|
||||
VaultClient.prototype.deleteBlob = blobClient.deleteBlob;
|
||||
|
||||
VaultClient.prototype.requestToken = blobClient.requestToken;
|
||||
|
||||
VaultClient.prototype.verifyToken = blobClient.verifyToken;
|
||||
|
||||
VaultClient.prototype.getAttestation = blobClient.getAttestation;
|
||||
|
||||
VaultClient.prototype.updateAttestation = blobClient.updateAttestation;
|
||||
|
||||
VaultClient.prototype.getAttestationSummary = blobClient.getAttestationSummary;
|
||||
|
||||
//export by name
|
||||
exports.VaultClient = VaultClient;
|
||||
|
||||
8
src/js/ripple/wallet.js
Normal file
8
src/js/ripple/wallet.js
Normal file
@@ -0,0 +1,8 @@
|
||||
var sjcl = require('./utils').sjcl;
|
||||
|
||||
var WalletGenerator = require('ripple-wallet-generator')({
|
||||
sjcl: sjcl
|
||||
});
|
||||
|
||||
module.exports = WalletGenerator;
|
||||
|
||||
@@ -3,7 +3,7 @@ var Account = require('../src/js/ripple/account').Account;
|
||||
|
||||
describe('Account', function(){
|
||||
|
||||
describe('._publicKeyToAddress()', function(){
|
||||
describe('#_publicKeyToAddress()', function(){
|
||||
|
||||
it('should throw an error if the key is invalid', function(){
|
||||
try {
|
||||
@@ -29,7 +29,7 @@ describe('Account', function(){
|
||||
|
||||
});
|
||||
|
||||
describe('.publicKeyIsActive()', function(){
|
||||
describe('#publicKeyIsActive()', function(){
|
||||
|
||||
it('should respond true if the public key corresponds to the account address and the master key IS NOT disabled', function(){
|
||||
|
||||
@@ -178,4 +178,4 @@ describe('Account', function(){
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@@ -16,41 +16,241 @@ describe('Amount', function() {
|
||||
assert(Amount.from_json('1').is_positive());
|
||||
});
|
||||
});
|
||||
describe('Positives', function() {
|
||||
it('Number 1', function() {
|
||||
assert(Amount.from_json('1').is_positive());
|
||||
});
|
||||
});
|
||||
// also tested extensively in other cases
|
||||
describe('to_human', function() {
|
||||
it('12345.6789 XAU', function() {
|
||||
assert.strictEqual(Amount.from_human("12345.6789 XAU").to_human(), '12,345.6789');
|
||||
});
|
||||
it('12345.678901234 XAU', function() {
|
||||
assert.strictEqual(Amount.from_human("12345.678901234 XAU").to_human(), '12,345.678901234');
|
||||
});
|
||||
it('to human, precision -1, should be ignored, precision needs to be >= 0', function() {
|
||||
assert.strictEqual(Amount.from_human("12345.678901234 XAU").to_human({precision:-1}), '12,346');
|
||||
});
|
||||
it('to human, precision 0', function() {
|
||||
assert.strictEqual(Amount.from_human("12345.678901234 XAU").to_human({precision:0}), '12,346');
|
||||
});
|
||||
it('to human, precision 1', function() {
|
||||
assert.strictEqual(Amount.from_human("12345.678901234 XAU").to_human({precision:1}), '12,345.7');
|
||||
});
|
||||
it('to human, precision 2', function() {
|
||||
assert.strictEqual(Amount.from_human("12345.678901234 XAU").to_human({precision:2}), '12,345.68');
|
||||
});
|
||||
it('to human, precision 3', function() {
|
||||
assert.strictEqual(Amount.from_human("12345.678901234 XAU").to_human({precision:3}), '12,345.679');
|
||||
});
|
||||
it('to human, precision 4', function() {
|
||||
assert.strictEqual(Amount.from_human("12345.678901234 XAU").to_human({precision:4}), '12,345.6789');
|
||||
});
|
||||
it('to human, precision 5', function() {
|
||||
assert.strictEqual(Amount.from_human("12345.678901234 XAU").to_human({precision:5}), '12,345.67890');
|
||||
});
|
||||
it('to human, precision -1, should be ignored, precision needs to be >= 0', function() {
|
||||
assert.strictEqual(Amount.from_human("0.00012345 XAU").to_human({precision:-1}), '0');
|
||||
});
|
||||
it('to human, precision 0', function() {
|
||||
assert.strictEqual(Amount.from_human("0.00012345 XAU").to_human({precision:0}), '0');
|
||||
});
|
||||
it('to human, precision 1', function() {
|
||||
assert.strictEqual(Amount.from_human("0.00012345 XAU").to_human({precision:1}), '0.0');
|
||||
});
|
||||
it('to human, precision 2', function() {
|
||||
assert.strictEqual(Amount.from_human("0.00012345 XAU").to_human({precision:2}), '0.00');
|
||||
});
|
||||
it('to human, precision 5', function() {
|
||||
assert.strictEqual(Amount.from_human("0.00012345 XAU").to_human({precision:5}), '0.00012');
|
||||
});
|
||||
it('to human, precision 6', function() {
|
||||
assert.strictEqual(Amount.from_human("0.00012345 XAU").to_human({precision:6}), '0.000123');
|
||||
});
|
||||
it('to human, precision 16', function() {
|
||||
assert.strictEqual(Amount.from_human("0.00012345 XAU").to_human({precision:16}), '0.00012345');
|
||||
});
|
||||
it('to human, precision 16, min_precision 16', function() {
|
||||
assert.strictEqual(Amount.from_human("0.00012345 XAU").to_human({precision:16, min_precision:16}), '0.0001234500000000');
|
||||
});
|
||||
it('to human, precision 16, min_precision 12', function() {
|
||||
assert.strictEqual(Amount.from_human("0.00012345 XAU").to_human({precision:16, min_precision:12}), '0.000123450000');
|
||||
});
|
||||
it('to human, precision 0, first decimal 4', function() {
|
||||
assert.strictEqual(Amount.from_human("0.4 XAU").to_human({precision:0}), '0');
|
||||
});
|
||||
it('to human, precision 0, first decimal 5', function() {
|
||||
assert.strictEqual(Amount.from_human("0.5 XAU").to_human({precision:0}), '1');
|
||||
});
|
||||
it('to human, precision 0, first decimal 8', function() {
|
||||
assert.strictEqual(Amount.from_human("0.8 XAU").to_human({precision:0}), '1');
|
||||
});
|
||||
it('to human, precision 0, precision 16', function() {
|
||||
assert.strictEqual(Amount.from_human("0.0 XAU").to_human({precision:16}), '0.0');
|
||||
});
|
||||
it('to human, precision 0, precision 8, min_precision 16', function() {
|
||||
assert.strictEqual(Amount.from_human("0.0 XAU").to_human({precision:8, min_precision:16}), '0.0000000000000000');
|
||||
});
|
||||
it('to human, precision 0, first decimal 8', function() {
|
||||
assert.strictEqual(Amount.from_human("0.8 XAU").to_human({precision:0}), '1');
|
||||
});
|
||||
it('to human, precision 6, min_precision 6, max_sig_digits 20', function() {
|
||||
assert.strictEqual(Amount.from_human("0.0 XAU").to_human({precision: 6, min_precision: 6, max_sig_digits: 20}), '0.000000');
|
||||
});
|
||||
it('to human, precision 16, min_precision 6, max_sig_digits 20', function() {
|
||||
assert.strictEqual(Amount.from_human("0.0 XAU").to_human({precision: 16, min_precision: 6, max_sig_digits: 20}), '0.000000');
|
||||
});
|
||||
});
|
||||
describe('from_human', function() {
|
||||
it('1 XRP', function() {
|
||||
assert.strictEqual(Amount.from_human("1 XRP").to_text_full(), '1/XRP');
|
||||
});
|
||||
it('1 XRP human', function() {
|
||||
assert.strictEqual(Amount.from_human("1 XRP").to_human_full(), '1/XRP');
|
||||
});
|
||||
it('0.1 XRP', function() {
|
||||
assert.strictEqual(Amount.from_human("0.1 XRP").to_text_full(), '0.1/XRP');
|
||||
});
|
||||
it('0.1 XRP human', function() {
|
||||
assert.strictEqual(Amount.from_human("0.1 XRP").to_human_full(), '0.1/XRP');
|
||||
});
|
||||
it('0.1 USD', function() {
|
||||
assert.strictEqual(Amount.from_human("0.1 USD").to_text_full(), '0.1/USD/NaN');
|
||||
});
|
||||
it('0.1 USD human', function() {
|
||||
assert.strictEqual(Amount.from_human("0.1 USD").to_human_full(), '0.1/USD/NaN');
|
||||
});
|
||||
it('10000 USD', function() {
|
||||
assert.strictEqual(Amount.from_human("10000 USD").to_text_full(), '10000/USD/NaN');
|
||||
});
|
||||
it('10000 USD human', function() {
|
||||
assert.strictEqual(Amount.from_human("10000 USD").to_human_full(), '10,000/USD/NaN');
|
||||
});
|
||||
it('USD 10000', function() {
|
||||
assert.strictEqual(Amount.from_human("USD 10000").to_text_full(), '10000/USD/NaN');
|
||||
});
|
||||
it('USD 10000 human', function() {
|
||||
assert.strictEqual(Amount.from_human("USD 10000").to_human_full(), '10,000/USD/NaN');
|
||||
});
|
||||
it('12345.6789 XAU', function() {
|
||||
assert.strictEqual(Amount.from_human("12345.6789 XAU").to_text_full(), '12345.6789/XAU/NaN');
|
||||
});
|
||||
it('12345.6789 XAU human', function() {
|
||||
assert.strictEqual(Amount.from_human("12345.6789 XAU").to_human_full(), '12,345.6789/XAU/NaN');
|
||||
});
|
||||
it('12345.6789 015841551A748AD2C1F76FF6ECB0CCCD00000000', function() {
|
||||
assert.strictEqual(Amount.from_human("12345.6789 015841551A748AD2C1F76FF6ECB0CCCD00000000").to_text_full(), '12345.6789/XAU (-0.5%pa)/NaN');
|
||||
});
|
||||
it('12345.6789 015841551A748AD2C1F76FF6ECB0CCCD00000000 human', function() {
|
||||
assert.strictEqual(Amount.from_human("12345.6789 015841551A748AD2C1F76FF6ECB0CCCD00000000").to_human_full(), '12,345.6789/XAU (-0.5%pa)/NaN');
|
||||
});
|
||||
it('12345.6789 0000000000000000000000005553440000000000', function() {
|
||||
assert.strictEqual(Amount.from_human("12345.6789 0000000000000000000000005553440000000000").to_text_full(), '12345.6789/USD/NaN');
|
||||
});
|
||||
it('12345.6789 0000000000000000000000005553440000000000 human', function() {
|
||||
assert.strictEqual(Amount.from_human("12345.6789 0000000000000000000000005553440000000000").to_human_full(), '12,345.6789/USD/NaN');
|
||||
});
|
||||
it('10 0000000000000000000000005553440000000000', function() {
|
||||
assert.strictEqual(Amount.from_human("10 0000000000000000000000005553440000000000").to_text_full(), '10/USD/NaN');
|
||||
});
|
||||
it('10 0000000000000000000000005553440000000000 human', function() {
|
||||
assert.strictEqual(Amount.from_human("10 0000000000000000000000005553440000000000").to_human_full(), '10/USD/NaN');
|
||||
});
|
||||
it('100 0000000000000000000000005553440000000000', function() {
|
||||
assert.strictEqual(Amount.from_human("100 0000000000000000000000005553440000000000").to_text_full(), '100/USD/NaN');
|
||||
});
|
||||
it('100 0000000000000000000000005553440000000000 human', function() {
|
||||
assert.strictEqual(Amount.from_human("100 0000000000000000000000005553440000000000").to_human_full(), '100/USD/NaN');
|
||||
});
|
||||
it('1000 0000000000000000000000005553440000000000', function() {
|
||||
assert.strictEqual(Amount.from_human("1000 0000000000000000000000005553440000000000").to_text_full(), '1000/USD/NaN');
|
||||
});
|
||||
it('1000 0000000000000000000000005553440000000000 human', function() {
|
||||
assert.strictEqual(Amount.from_human("1000 0000000000000000000000005553440000000000").to_human_full(), '1,000/USD/NaN');
|
||||
});
|
||||
it('-100 0000000000000000000000005553440000000000', function() {
|
||||
assert.strictEqual(Amount.from_human("-100 0000000000000000000000005553440000000000").to_text_full(), '-100/USD/NaN');
|
||||
});
|
||||
it('-100 0000000000000000000000005553440000000000 human', function() {
|
||||
assert.strictEqual(Amount.from_human("-100 0000000000000000000000005553440000000000").to_human_full(), '-100/USD/NaN');
|
||||
});
|
||||
it('-1000 0000000000000000000000005553440000000000', function() {
|
||||
assert.strictEqual(Amount.from_human("-1000 0000000000000000000000005553440000000000").to_text_full(), '-1000/USD/NaN');
|
||||
});
|
||||
it('-1000 0000000000000000000000005553440000000000 human', function() {
|
||||
assert.strictEqual(Amount.from_human("-1000 0000000000000000000000005553440000000000").to_human_full(), '-1,000/USD/NaN');
|
||||
});
|
||||
it('-1000.001 0000000000000000000000005553440000000000', function() {
|
||||
assert.strictEqual(Amount.from_human("-1000.001 0000000000000000000000005553440000000000").to_text_full(), '-1000.001/USD/NaN');
|
||||
});
|
||||
it('-1000.001 0000000000000000000000005553440000000000 human', function() {
|
||||
assert.strictEqual(Amount.from_human("-1000.001 0000000000000000000000005553440000000000").to_human_full(), '-1,000.001/USD/NaN');
|
||||
});
|
||||
it('XAU 12345.6789', function() {
|
||||
assert.strictEqual(Amount.from_human("XAU 12345.6789").to_text_full(), '12345.6789/XAU/NaN');
|
||||
});
|
||||
it('XAU 12345.6789 human', function() {
|
||||
assert.strictEqual(Amount.from_human("XAU 12345.6789").to_human_full(), '12,345.6789/XAU/NaN');
|
||||
});
|
||||
it('101 12345.6789', function() {
|
||||
assert.strictEqual(Amount.from_human("101 12345.6789").to_text_full(), '12345.6789/101/NaN');
|
||||
});
|
||||
it('101 12345.6789 human', function() {
|
||||
assert.strictEqual(Amount.from_human("101 12345.6789").to_human_full(), '12,345.6789/101/NaN');
|
||||
});
|
||||
it('12345.6789 101', function() {
|
||||
assert.strictEqual(Amount.from_human("12345.6789 101").to_text_full(), '12345.6789/101/NaN');
|
||||
});
|
||||
it('12345.6789 101 human', function() {
|
||||
assert.strictEqual(Amount.from_human("12345.6789 101").to_human_full(), '12,345.6789/101/NaN');
|
||||
});
|
||||
});
|
||||
describe('from_json', function() {
|
||||
it('1 XRP', function() {
|
||||
assert.strictEqual(Amount.from_json("1/XRP").to_text_full(), "1/XRP/NaN");
|
||||
});
|
||||
it('1 XRP human', function() {
|
||||
assert.strictEqual(Amount.from_json("1/XRP").to_human_full(), "1/XRP/NaN");
|
||||
});
|
||||
});
|
||||
describe('from_number', function() {
|
||||
it('Number 1', function() {
|
||||
assert.strictEqual(Amount.from_number(1).to_text_full(), '1/1/rrrrrrrrrrrrrrrrrrrrBZbvji');
|
||||
});
|
||||
it('Number 1 human', function() {
|
||||
assert.strictEqual(Amount.from_number(1).to_human_full(), '1/1/rrrrrrrrrrrrrrrrrrrrBZbvji');
|
||||
});
|
||||
it('Number 2', function() {
|
||||
assert.strictEqual(Amount.from_number(2).to_text_full(), '2/1/rrrrrrrrrrrrrrrrrrrrBZbvji');
|
||||
});
|
||||
it('Number 2 human', function() {
|
||||
assert.strictEqual(Amount.from_number(2).to_human_full(), '2/1/rrrrrrrrrrrrrrrrrrrrBZbvji');
|
||||
});
|
||||
it('Multiply 2 "1" with 3 "1", by product_human', function () {
|
||||
assert.strictEqual(Amount.from_number(2).product_human(Amount.from_number(3)).to_text_full(), '6/1/rrrrrrrrrrrrrrrrrrrrBZbvji');
|
||||
});
|
||||
it('Multiply 2 "1" with 3 "1", by product_human human', function () {
|
||||
assert.strictEqual(Amount.from_number(2).product_human(Amount.from_number(3)).to_human_full(), '6/1/rrrrrrrrrrrrrrrrrrrrBZbvji');
|
||||
});
|
||||
it('Multiply 3 USD with 3 "1"', function () {
|
||||
assert.strictEqual(Amount.from_json('3/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_number(3)).to_text_full(), '9/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
});
|
||||
it('Multiply 3 USD with 3 "1" human', function () {
|
||||
assert.strictEqual(Amount.from_json('3/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_number(3)).to_human_full(), '9/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
});
|
||||
it('Multiply -1 "1" with 3 USD', function () {
|
||||
assert.strictEqual(Amount.from_number(-1).multiply(Amount.from_json('3/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_text_full(), '-3/1/rrrrrrrrrrrrrrrrrrrrBZbvji');
|
||||
});
|
||||
it('Multiply -1 "1" with 3 USD human', function () {
|
||||
assert.strictEqual(Amount.from_number(-1).multiply(Amount.from_json('3/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full(), '-3/1/rrrrrrrrrrrrrrrrrrrrBZbvji');
|
||||
});
|
||||
it('Multiply -1 "1" with 3 USD, by product_human', function () {
|
||||
assert.strictEqual(Amount.from_number(-1).product_human(Amount.from_json('3/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_text_full(), '-3/1/rrrrrrrrrrrrrrrrrrrrBZbvji');
|
||||
});
|
||||
it('Multiply -1 "1" with 3 USD, by product_human human', function () {
|
||||
assert.strictEqual(Amount.from_number(-1).product_human(Amount.from_json('3/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full(), '-3/1/rrrrrrrrrrrrrrrrrrrrBZbvji');
|
||||
});
|
||||
});
|
||||
describe('text_full_rewrite', function() {
|
||||
it('Number 1', function() {
|
||||
@@ -117,9 +317,24 @@ describe('Amount', function() {
|
||||
assert.strictEqual(typeof Amount.from_json('x').to_text(true), 'number');
|
||||
assert(isNaN(Amount.from_json('x').to_text(true)));
|
||||
});
|
||||
it('parse dem', function() {
|
||||
assert.strictEqual(Amount.from_json('10/015841551A748AD2C1F76FF6ECB0CCCD00000000/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_text_full(), '10/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
});
|
||||
it('parse dem human', function() {
|
||||
assert.strictEqual(Amount.from_json('10/015841551A748AD2C1F76FF6ECB0CCCD00000000/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_human_full(), '10/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
});
|
||||
it('parse dem', function() {
|
||||
assert.strictEqual(Amount.from_json('10/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_text_full(), '10/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
});
|
||||
it('parse dem human', function() {
|
||||
assert.strictEqual(Amount.from_json('10/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_human_full(), '10/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
});
|
||||
it('Parse 800/USD/mtgox', function () {
|
||||
assert.strictEqual('800/USD/'+config.accounts['mtgox'].account, Amount.from_json('800/USD/mtgox').to_text_full());
|
||||
});
|
||||
it('Parse 800/USD/mtgox human', function () {
|
||||
assert.strictEqual('800/USD/'+config.accounts['mtgox'].account, Amount.from_json('800/USD/mtgox').to_human_full());
|
||||
});
|
||||
it('Parse native 0', function () {
|
||||
assert.strictEqual('0/XRP', Amount.from_json('0').to_text_full());
|
||||
});
|
||||
@@ -163,7 +378,69 @@ describe('Amount', function() {
|
||||
assert.strictEqual('0/111/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('0/111/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_text_full());
|
||||
});
|
||||
it('Parse 0.0/12D/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', function () {
|
||||
assert.strictEqual('0/XRP/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('0/12D/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_text_full());
|
||||
assert.strictEqual('0/12D/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('0/12D/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_text_full());
|
||||
});
|
||||
it('Parse native 0 human', function () {
|
||||
assert.strictEqual('0/XRP', Amount.from_json('0').to_human_full());
|
||||
});
|
||||
it('Parse native 0.0 human', function () {
|
||||
assert.strictEqual('0/XRP', Amount.from_json('0.0').to_human_full());
|
||||
});
|
||||
it('Parse native -0 human', function () {
|
||||
assert.strictEqual('0/XRP', Amount.from_json('-0').to_human_full());
|
||||
});
|
||||
it('Parse native -0.0 human', function () {
|
||||
assert.strictEqual('0/XRP', Amount.from_json('-0.0').to_human_full());
|
||||
});
|
||||
it('Parse native 1000 human', function () {
|
||||
assert.strictEqual('0.001/XRP', Amount.from_json('1000').to_human_full());
|
||||
});
|
||||
it('Parse native 12.3 human', function () {
|
||||
assert.strictEqual('12.3/XRP', Amount.from_json('12.3').to_human_full());
|
||||
});
|
||||
it('Parse native -12.3 human', function () {
|
||||
assert.strictEqual('-12.3/XRP', Amount.from_json('-12.3').to_human_full());
|
||||
});
|
||||
it('Parse 123./USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh human', function () {
|
||||
assert.strictEqual('123/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('123./USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_human_full());
|
||||
});
|
||||
it('Parse 12300/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh human', function () {
|
||||
assert.strictEqual('12,300/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('12300/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_human_full());
|
||||
});
|
||||
it('Parse 12.3/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh human', function () {
|
||||
assert.strictEqual('12.3/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('12.3/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_human_full());
|
||||
});
|
||||
it('Parse 1.2300/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh human', function () {
|
||||
assert.strictEqual('1.23/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('1.2300/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_human_full());
|
||||
});
|
||||
it('Parse -0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh human', function () {
|
||||
assert.strictEqual('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('-0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_human_full());
|
||||
});
|
||||
it('Parse -0.0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh human', function () {
|
||||
assert.strictEqual('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('-0.0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_human_full());
|
||||
});
|
||||
it('Parse 0.0/111/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh human', function () {
|
||||
assert.strictEqual('0/111/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('0/111/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_human_full());
|
||||
});
|
||||
it('Parse 0.0/12D/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh human', function () {
|
||||
assert.strictEqual('0/12D/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('0/12D/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_human_full());
|
||||
});
|
||||
});
|
||||
describe('Amount to_json', function() {
|
||||
it('10 USD', function() {
|
||||
var amount = Amount.from_human("10 USD").to_json();
|
||||
assert.strictEqual("10", amount.value);
|
||||
assert.strictEqual("USD", amount.currency);
|
||||
});
|
||||
it('10 0000000000000000000000005553440000000000', function() {
|
||||
var amount = Amount.from_human("10 0000000000000000000000005553440000000000").to_json();
|
||||
assert.strictEqual("10", amount.value);
|
||||
assert.strictEqual("USD", amount.currency);
|
||||
});
|
||||
it('10 015841551A748AD2C1F76FF6ECB0CCCD00000000', function() {
|
||||
var amount = Amount.from_human("10 015841551A748AD2C1F76FF6ECB0CCCD00000000").to_json();
|
||||
assert.strictEqual("10", amount.value);
|
||||
assert.strictEqual("015841551A748AD2C1F76FF6ECB0CCCD00000000", amount.currency);
|
||||
});
|
||||
});
|
||||
describe('Amount operations', function() {
|
||||
@@ -305,6 +582,144 @@ describe('Amount', function() {
|
||||
it('Divide EUR by XRP, neg, <1', function () {
|
||||
assert.strictEqual('-0.05/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('-100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').divide(Amount.from_json('2000')).to_text_full());
|
||||
});
|
||||
it('Negate native 123 human', function () {
|
||||
assert.strictEqual('-0.000123/XRP', Amount.from_json('123').negate().to_human_full());
|
||||
});
|
||||
it('Negate native -123 human', function () {
|
||||
assert.strictEqual('0.000123/XRP', Amount.from_json('-123').negate().to_human_full());
|
||||
});
|
||||
it('Negate non-native 123 human', function () {
|
||||
assert.strictEqual('-123/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('123/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').negate().to_human_full());
|
||||
});
|
||||
it('Negate non-native -123 human', function () {
|
||||
assert.strictEqual('123/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('-123/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').negate().to_human_full());
|
||||
});
|
||||
it('Clone non-native -123 human', function () {
|
||||
assert.strictEqual('-123/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('-123/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').clone().to_human_full());
|
||||
});
|
||||
it('Add XRP to XRP human', function () {
|
||||
assert.strictEqual('0.0002/XRP', Amount.from_json('150').add(Amount.from_json('50')).to_human_full());
|
||||
});
|
||||
it('Add USD to USD human', function () {
|
||||
assert.strictEqual('200.52/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('150.02/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').add(Amount.from_json('50.5/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Add 0 USD to 1 USD human', function() {
|
||||
assert.strictEqual('1' , Amount.from_json('1/USD').add('0/USD').to_human());
|
||||
});
|
||||
it('Subtract USD from USD human', function() {
|
||||
assert.strictEqual('99.52/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('150.02/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').subtract(Amount.from_json('50.5/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Multiply 0 XRP with 0 XRP human', function () {
|
||||
assert.strictEqual('0/XRP', Amount.from_json('0').multiply(Amount.from_json('0')).to_human_full());
|
||||
});
|
||||
it('Multiply 0 USD with 0 XRP human', function () {
|
||||
assert.strictEqual('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_json('0')).to_human_full());
|
||||
});
|
||||
it('Multiply 0 XRP with 0 USD human', function () {
|
||||
assert.strictEqual('0/XRP', Amount.from_json('0').multiply(Amount.from_json('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Multiply 1 XRP with 0 XRP human', function () {
|
||||
assert.strictEqual('0/XRP', Amount.from_json('1').multiply(Amount.from_json('0')).to_human_full());
|
||||
});
|
||||
it('Multiply 1 USD with 0 XRP human', function () {
|
||||
assert.strictEqual('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_json('0')).to_human_full());
|
||||
});
|
||||
it('Multiply 1 XRP with 0 USD human', function () {
|
||||
assert.strictEqual('0/XRP', Amount.from_json('1').multiply(Amount.from_json('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Multiply 0 XRP with 1 XRP human', function () {
|
||||
assert.strictEqual('0/XRP', Amount.from_json('0').multiply(Amount.from_json('1')).to_human_full());
|
||||
});
|
||||
it('Multiply 0 USD with 1 XRP human', function () {
|
||||
assert.strictEqual('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_json('1')).to_human_full());
|
||||
});
|
||||
it('Multiply 0 XRP with 1 USD human', function () {
|
||||
assert.strictEqual('0/XRP', Amount.from_json('0').multiply(Amount.from_json('1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Multiply XRP with USD human', function () {
|
||||
assert.equal('0.002/XRP', Amount.from_json('200').multiply(Amount.from_json('10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Multiply XRP with USD human', function () {
|
||||
assert.strictEqual('0.2/XRP', Amount.from_json('20000').multiply(Amount.from_json('10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Multiply XRP with USD human', function () {
|
||||
assert.strictEqual('20/XRP', Amount.from_json('2000000').multiply(Amount.from_json('10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Multiply XRP with USD, neg human', function () {
|
||||
assert.strictEqual('-0.002/XRP', Amount.from_json('200').multiply(Amount.from_json('-10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Multiply XRP with USD, neg, frac human', function () {
|
||||
assert.strictEqual('-0.222/XRP', Amount.from_json('-6000').multiply(Amount.from_json('37/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Multiply USD with USD human', function () {
|
||||
assert.strictEqual('20,000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('2000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_json('10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Multiply USD with USD human', function () {
|
||||
assert.strictEqual('200,000,000,000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('2000000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_json('100000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Multiply EUR with USD, result < 1 human', function () {
|
||||
assert.strictEqual('100,000/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_json('1000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Multiply EUR with USD, neg human', function () {
|
||||
assert.strictEqual('-48,000,000/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('-24000/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_json('2000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Multiply EUR with USD, neg, <1 human', function () {
|
||||
assert.strictEqual('-100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('0.1/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_json('-1000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Multiply EUR with XRP, factor < 1 human', function () {
|
||||
assert.strictEqual('100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('0.05/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_json('2000')).to_human_full());
|
||||
});
|
||||
it('Multiply EUR with XRP, neg human', function () {
|
||||
assert.strictEqual('-500/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('-100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_json('5')).to_human_full());
|
||||
});
|
||||
it('Multiply EUR with XRP, neg, <1 human', function () {
|
||||
assert.strictEqual('-100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('-0.05/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_json('2000')).to_human_full());
|
||||
});
|
||||
it('Multiply XRP with XRP human', function () {
|
||||
assert.strictEqual('0.0001/XRP', Amount.from_json('10').multiply(Amount.from_json('10')).to_human_full());
|
||||
});
|
||||
it('Divide XRP by USD human', function () {
|
||||
assert.strictEqual('0.00002/XRP', Amount.from_json('200').divide(Amount.from_json('10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Divide XRP by USD human', function () {
|
||||
assert.strictEqual('0.002/XRP', Amount.from_json('20000').divide(Amount.from_json('10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Divide XRP by USD human', function () {
|
||||
assert.strictEqual('0.2/XRP', Amount.from_json('2000000').divide(Amount.from_json('10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Divide XRP by USD, neg human', function () {
|
||||
assert.strictEqual('-0.00002/XRP', Amount.from_json('200').divide(Amount.from_json('-10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Divide XRP by USD, neg, frac human', function () {
|
||||
assert.strictEqual('-0.000162/XRP', Amount.from_json('-6000').divide(Amount.from_json('37/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Divide USD by USD human', function () {
|
||||
assert.strictEqual('200/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('2000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').divide(Amount.from_json('10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Divide USD by USD, fractional human', function () {
|
||||
assert.strictEqual('57,142.85714285714/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('2000000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').divide(Amount.from_json('35/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Divide USD by USD human', function () {
|
||||
assert.strictEqual('20/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('2000000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').divide(Amount.from_json('100000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Divide EUR by USD, factor < 1 human', function () {
|
||||
assert.strictEqual('0.1/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').divide(Amount.from_json('1000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Divide EUR by USD, neg human', function () {
|
||||
assert.strictEqual('-12/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('-24000/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').divide(Amount.from_json('2000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Divide EUR by USD, neg, <1 human', function () {
|
||||
assert.strictEqual('-0.1/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').divide(Amount.from_json('-1000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Divide EUR by XRP, result < 1 human', function () {
|
||||
assert.strictEqual('0.05/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').divide(Amount.from_json('2000')).to_human_full());
|
||||
});
|
||||
it('Divide EUR by XRP, neg human', function () {
|
||||
assert.strictEqual('-20/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('-100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').divide(Amount.from_json('5')).to_human_full());
|
||||
});
|
||||
it('Divide EUR by XRP, neg, <1 human', function () {
|
||||
assert.strictEqual('-0.05/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('-100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').divide(Amount.from_json('2000')).to_human_full());
|
||||
});
|
||||
it('Divide by zero should throw', function() {
|
||||
assert.throws(function() {
|
||||
Amount.from_json(1).divide(Amount.from_json(0));
|
||||
@@ -542,12 +957,87 @@ describe('Amount', function() {
|
||||
it('Multiply USD with XAU (dem)', function () {
|
||||
assert.strictEqual(Amount.from_json('2000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').product_human(Amount.from_json('10/015841551A748AD2C1F76FF6ECB0CCCD00000000/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'), {reference_date: 443845330 + 31535000}).to_text_full(), '19900.00316303882/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
});
|
||||
it('Multiply 0 XRP with 0 XRP human', function () {
|
||||
assert.strictEqual('0/XRP', Amount.from_json('0').product_human(Amount.from_json('0')).to_human_full());
|
||||
});
|
||||
it('Multiply 0 USD with 0 XRP human', function () {
|
||||
assert.strictEqual('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').product_human(Amount.from_json('0')).to_human_full());
|
||||
});
|
||||
it('Multiply 0 XRP with 0 USD human', function () {
|
||||
assert.strictEqual('0/XRP', Amount.from_json('0').product_human(Amount.from_json('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Multiply 1 XRP with 0 XRP human', function () {
|
||||
assert.strictEqual('0/XRP', Amount.from_json('1').product_human(Amount.from_json('0')).to_human_full());
|
||||
});
|
||||
it('Multiply 1 USD with 0 XRP human', function () {
|
||||
assert.strictEqual('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').product_human(Amount.from_json('0')).to_human_full());
|
||||
});
|
||||
it('Multiply 1 XRP with 0 USD human', function () {
|
||||
assert.strictEqual('0/XRP', Amount.from_json('1').product_human(Amount.from_json('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Multiply 0 XRP with 1 XRP human', function () {
|
||||
assert.strictEqual('0/XRP', Amount.from_json('0').product_human(Amount.from_json('1')).to_human_full());
|
||||
});
|
||||
it('Multiply 0 USD with 1 XRP human', function () {
|
||||
assert.strictEqual('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').product_human(Amount.from_json('1')).to_human_full());
|
||||
});
|
||||
it('Multiply 0 XRP with 1 USD human', function () {
|
||||
assert.strictEqual('0/XRP', Amount.from_json('0').product_human(Amount.from_json('1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Multiply XRP with USD human', function () {
|
||||
assert.equal('0.002/XRP', Amount.from_json('200').product_human(Amount.from_json('10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Multiply XRP with USD human', function () {
|
||||
assert.strictEqual('0.2/XRP', Amount.from_json('20000').product_human(Amount.from_json('10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Multiply XRP with USD human', function () {
|
||||
assert.strictEqual('20/XRP', Amount.from_json('2000000').product_human(Amount.from_json('10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Multiply XRP with USD, neg human', function () {
|
||||
assert.strictEqual('-0.002/XRP', Amount.from_json('200').product_human(Amount.from_json('-10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Multiply XRP with USD, neg, frac human', function () {
|
||||
assert.strictEqual('-0.222/XRP', Amount.from_json('-6000').product_human(Amount.from_json('37/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Multiply USD with USD human', function () {
|
||||
assert.strictEqual('20,000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('2000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').product_human(Amount.from_json('10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Multiply USD with USD human', function () {
|
||||
assert.strictEqual('200,000,000,000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('2000000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').product_human(Amount.from_json('100000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Multiply EUR with USD, result < 1 human', function () {
|
||||
assert.strictEqual('100,000/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').product_human(Amount.from_json('1000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
|
||||
});
|
||||
it('Multiply EUR with USD, neg human', function () {
|
||||
assert.strictEqual(Amount.from_json('-24000/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').product_human(Amount.from_json('2000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full(), '-48,000,000/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
});
|
||||
it('Multiply EUR with USD, neg, <1 human', function () {
|
||||
assert.strictEqual(Amount.from_json('0.1/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').product_human(Amount.from_json('-1000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full(), '-100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
});
|
||||
it('Multiply EUR with XRP, factor < 1 human', function () {
|
||||
assert.strictEqual(Amount.from_json('0.05/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').product_human(Amount.from_json('2000')).to_human_full(), '0.0001/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
});
|
||||
it('Multiply EUR with XRP, neg human', function () {
|
||||
assert.strictEqual(Amount.from_json('-100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').product_human(Amount.from_json('5')).to_human_full(), '-0.0005/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
});
|
||||
it('Multiply EUR with XRP, neg, <1 human', function () {
|
||||
assert.strictEqual(Amount.from_json('-0.05/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').product_human(Amount.from_json('2000')).to_human_full(), '-0.0001/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
});
|
||||
it('Multiply XRP with XRP human', function () {
|
||||
assert.strictEqual(Amount.from_json('10000000').product_human(Amount.from_json('10')).to_human_full(), '0.0001/XRP');
|
||||
});
|
||||
it('Multiply USD with XAU (dem) human', function () {
|
||||
assert.strictEqual(Amount.from_json('2000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').product_human(Amount.from_json('10/015841551A748AD2C1F76FF6ECB0CCCD00000000/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'), {reference_date: 443845330 + 31535000}).to_human_full(), '19,900.00316303882/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
});
|
||||
});
|
||||
|
||||
describe('ratio_human', function() {
|
||||
it('Divide USD by XAU (dem)', function () {
|
||||
assert.strictEqual(Amount.from_json('2000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').ratio_human(Amount.from_json('10/015841551A748AD2C1F76FF6ECB0CCCD00000000/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'), {reference_date: 443845330 + 31535000}).to_text_full(), '201.0049931765529/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
});
|
||||
it('Divide USD by XAU (dem) human', function () {
|
||||
assert.strictEqual(Amount.from_json('2000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').ratio_human(Amount.from_json('10/015841551A748AD2C1F76FF6ECB0CCCD00000000/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'), {reference_date: 443845330 + 31535000}).to_human_full(), '201.0049931765529/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
});
|
||||
});
|
||||
|
||||
describe('_invert', function() {
|
||||
@@ -560,6 +1050,15 @@ describe('Amount', function() {
|
||||
it('Invert 0.02', function () {
|
||||
assert.strictEqual(Amount.from_json('0.02/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').invert().to_text_full(), '50/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
});
|
||||
it('Invert 1 human', function () {
|
||||
assert.strictEqual(Amount.from_json('1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').invert().to_human_full(), '1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
});
|
||||
it('Invert 20 human', function () {
|
||||
assert.strictEqual(Amount.from_json('20/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').invert().to_human_full(), '0.05/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
});
|
||||
it('Invert 0.02 human', function () {
|
||||
assert.strictEqual(Amount.from_json('0.02/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').invert().to_human_full(), '50/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
});
|
||||
});
|
||||
|
||||
describe('from_quality', function() {
|
||||
@@ -593,5 +1092,150 @@ describe('Amount', function() {
|
||||
it('USD/XAU(dem) inverse', function () {
|
||||
assert.strictEqual(Amount.from_quality('CDFD3AFB2F8C5DBEF75B081F7C957FF5509563266F28F36C5704A0FB0BAD8800', '015841551A748AD2C1F76FF6ECB0CCCD00000000', 'rUyPiNcSFFj6uMR2gEaD8jUerQ59G1qvwN', {inverse: true, base_currency: 'USD', reference_date: 443845330 + 31535000}).to_text_full(), '0.007675186123263489/XAU (-0.5%pa)/rUyPiNcSFFj6uMR2gEaD8jUerQ59G1qvwN');
|
||||
});
|
||||
it('BTC/XRP human', function () {
|
||||
assert.strictEqual(Amount.from_quality('7B73A610A009249B0CC0D4311E8BA7927B5A34D86634581C5F0FF9FF678E1000', 'XRP', NaN, {base_currency: 'BTC'}).to_human_full(), '44,970/XRP');
|
||||
});
|
||||
it('BTC/XRP inverse human', function () {
|
||||
assert.strictEqual(Amount.from_quality('37AAC93D336021AE94310D0430FFA090F7137C97D473488C4A0918D0DEF8624E', 'XRP', NaN, {inverse: true, base_currency: 'BTC'}).to_human_full(), '39,053.954453/XRP');
|
||||
});
|
||||
it('XRP/USD human', function () {
|
||||
assert.strictEqual(Amount.from_quality('DFA3B6DDAB58C7E8E5D944E736DA4B7046C30E4F460FD9DE4D05DCAA8FE12000', 'USD', 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', {base_currency: 'XRP'}).to_human_full(), '0.0165/USD/rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B');
|
||||
});
|
||||
it('XRP/USD inverse human', function () {
|
||||
assert.strictEqual(Amount.from_quality('4627DFFCFF8B5A265EDBD8AE8C14A52325DBFEDAF4F5C32E5C22A840E27DCA9B', 'USD', 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', {inverse: true, base_currency: 'XRP'}).to_human_full(), '0.010251/USD/rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B');
|
||||
});
|
||||
it('BTC/USD human', function () {
|
||||
assert.strictEqual(Amount.from_quality('6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC9858038D7EA4C68000', 'USD', 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', {base_currency: 'BTC'}).to_human_full(), '1,000/USD/rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B');
|
||||
});
|
||||
it('BTC/USD inverse human', function () {
|
||||
assert.strictEqual(Amount.from_quality('20294C923E80A51B487EB9547B3835FD483748B170D2D0A455071AFD498D0000', 'USD', 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', {inverse: true, base_currency: 'BTC'}).to_human_full(), '0.5/USD/rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B');
|
||||
});
|
||||
it('XAU(dem)/XRP human', function () {
|
||||
assert.strictEqual(Amount.from_quality('587322CCBDE0ABD01704769A73A077C32FB39057D813D4165F1FF973CAF997EF', 'XRP', NaN, {base_currency: '015841551A748AD2C1F76FF6ECB0CCCD00000000', reference_date: 443845330 + 31535000}).to_human_full(), '90,452.246928/XRP');
|
||||
});
|
||||
it('XAU(dem)/XRP inverse human', function () {
|
||||
assert.strictEqual(Amount.from_quality('F72C7A9EAE4A45ED1FB547AD037D07B9B965C6E662BEBAFA4A03F2A976804235', 'XRP', NaN, {inverse: true, base_currency: '015841551A748AD2C1F76FF6ECB0CCCD00000000', reference_date: 443845330 + 31535000}).to_human_full(), '90,442.196677/XRP');
|
||||
});
|
||||
it('USD/XAU(dem) human', function () {
|
||||
assert.strictEqual(Amount.from_quality('4743E58E44974B325D42FD2BB683A6E36950F350EE46DD3A521B644B99782F5F', '015841551A748AD2C1F76FF6ECB0CCCD00000000', 'rUyPiNcSFFj6uMR2gEaD8jUerQ59G1qvwN', {base_currency: 'USD', reference_date: 443845330 + 31535000}).to_human_full(), '0.007710100231303007/XAU (-0.5%pa)/rUyPiNcSFFj6uMR2gEaD8jUerQ59G1qvwN');
|
||||
});
|
||||
it('USD/XAU(dem) inverse human', function () {
|
||||
assert.strictEqual(Amount.from_quality('CDFD3AFB2F8C5DBEF75B081F7C957FF5509563266F28F36C5704A0FB0BAD8800', '015841551A748AD2C1F76FF6ECB0CCCD00000000', 'rUyPiNcSFFj6uMR2gEaD8jUerQ59G1qvwN', {inverse: true, base_currency: 'USD', reference_date: 443845330 + 31535000}).to_human_full(), '0.007675186123263489/XAU (-0.5%pa)/rUyPiNcSFFj6uMR2gEaD8jUerQ59G1qvwN');
|
||||
});
|
||||
});
|
||||
|
||||
describe('apply interest', function() {
|
||||
it ('from_json apply interest 10 XAU', function() {
|
||||
var demAmount = Amount.from_json('10/0158415500000000C1F76FF6ECB0BAC600000000/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
assert.strictEqual(demAmount.to_text_full(), '10/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
demAmount = demAmount.applyInterest(459990264);
|
||||
assert.strictEqual(demAmount.to_text_full(), '9.294949401870435/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
|
||||
});
|
||||
it ('from_json apply interest XAU', function() {
|
||||
var demAmount = Amount.from_json('1235.5/0158415500000000C1F76FF6ECB0BAC600000000/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
assert.strictEqual(demAmount.to_text_full(), '1235.5/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
demAmount = demAmount.applyInterest(459990264);
|
||||
assert.strictEqual(demAmount.to_text_full(), '1148.390998601092/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
});
|
||||
it ('from_human with reference date', function() {
|
||||
var demAmount = Amount.from_human('10 0158415500000000C1F76FF6ECB0BAC600000000', {reference_date:459990264});
|
||||
demAmount.set_issuer("rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh");
|
||||
assert.strictEqual(demAmount.to_text_full(), '10.75853086191915/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
});
|
||||
it ('from_json apply interest 10 XAU human', function() {
|
||||
var demAmount = Amount.from_json('10/0158415500000000C1F76FF6ECB0BAC600000000/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
assert.strictEqual(demAmount.to_human_full(), '10/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
demAmount = demAmount.applyInterest(459990264);
|
||||
assert.strictEqual(demAmount.to_human_full(), '9.294949401870435/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
|
||||
});
|
||||
it ('from_json apply interest XAU human', function() {
|
||||
var demAmount = Amount.from_json('1235.5/0158415500000000C1F76FF6ECB0BAC600000000/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
assert.strictEqual(demAmount.to_human_full(), '1,235.5/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
demAmount = demAmount.applyInterest(459990264);
|
||||
assert.strictEqual(demAmount.to_human_full(), '1,148.390998601092/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
});
|
||||
it ('from_human with reference date human', function() {
|
||||
var demAmount = Amount.from_human('10 0158415500000000C1F76FF6ECB0BAC600000000', {reference_date:459990264});
|
||||
demAmount.set_issuer("rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh");
|
||||
assert.strictEqual(demAmount.to_human_full(), '10.75853086191915/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
});
|
||||
});
|
||||
|
||||
describe('amount limits', function() {
|
||||
it ('max JSON wire limite', function() {
|
||||
assert.strictEqual(Amount.bi_xns_max.toString(), '9000000000000000000');
|
||||
});
|
||||
|
||||
it ('max JSON wire limite', function() {
|
||||
assert.strictEqual(Amount.bi_xns_min.toString(), '-9000000000000000000');
|
||||
});
|
||||
|
||||
it('max mantissa value', function() {
|
||||
assert.strictEqual(Amount.bi_man_max_value.toString(), '9999999999999999');
|
||||
});
|
||||
|
||||
it('min mantissa value', function() {
|
||||
assert.strictEqual(Amount.bi_man_min_value.toString(), '1000000000000000');
|
||||
});
|
||||
|
||||
it ('from_json minimum XRP', function() {
|
||||
console.log('max', Amount.bi_xns_max.toString());
|
||||
var amt = Amount.from_json('-9000000000000000000');
|
||||
assert.strictEqual(amt.to_json(), '-9000000000000000000');
|
||||
});
|
||||
|
||||
it ('from_json maximum XRP', function() {
|
||||
var amt = Amount.from_json('-9000000000000000000');
|
||||
assert.strictEqual(amt.to_json(), '-9000000000000000000');
|
||||
});
|
||||
|
||||
it ('from_json less than minimum XRP', function() {
|
||||
var amt = Amount.from_json('-9000000000000000001');
|
||||
assert.strictEqual(amt.to_json(), '0');
|
||||
});
|
||||
|
||||
it ('from_json more than maximum XRP', function() {
|
||||
var amt = Amount.from_json('9000000000000000001');
|
||||
assert.strictEqual(amt.to_json(), '0');
|
||||
});
|
||||
|
||||
it ('from_json minimum IOU', function() {
|
||||
var amt = Amount.from_json('-1e-81/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
assert.strictEqual(amt._value.toString(), Amount.bi_man_min_value.toString());
|
||||
assert.strictEqual(amt.to_text(), '-1000000000000000e-96');
|
||||
assert.strictEqual(amt.to_text(), Amount.min_value);
|
||||
});
|
||||
|
||||
it('from_json exceed minimum IOU', function() {
|
||||
assert.throws(function() {
|
||||
Amount.from_json('-1e-82/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')
|
||||
}, 'Exceeding min value of ' + Amount.min_value);
|
||||
});
|
||||
|
||||
it ('from_json maximum IOU', function() {
|
||||
var amt = Amount.from_json('9999999999999999e80/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
assert.strictEqual(amt._value.toString(), Amount.bi_man_max_value.toString());
|
||||
assert.strictEqual(amt.to_text(), '9999999999999999e80');
|
||||
});
|
||||
|
||||
it ('from_json exceed maximum IOU', function() {
|
||||
assert.throws(function() {
|
||||
Amount.from_json('9999999999999999e81/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')
|
||||
}, 'Exceeding max value of ' + Amount.max_value);
|
||||
});
|
||||
|
||||
it ('from_json normalize mantissa to valid max range, lost significant digits', function() {
|
||||
var amt = Amount.from_json('99999999999999999999999999999999/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
assert.strictEqual(amt._value.toString(), Amount.bi_man_max_value.toString());
|
||||
assert.strictEqual(amt.to_text(), '9999999999999999e16');
|
||||
});
|
||||
|
||||
it ('from_json normalize mantissa to min valid range, lost significant digits', function() {
|
||||
var amt = Amount.from_json('-0.0000000000000000000000001/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
assert.strictEqual(amt._value.toString(), Amount.bi_man_min_value.toString());
|
||||
assert.strictEqual(amt.to_text(), '-1000000000000000e-40');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
var assert = require('assert');
|
||||
var utils = require('./testutils');
|
||||
var currency = utils.load_module('currency').Currency;
|
||||
var timeUtil = utils.load_module('utils').time;
|
||||
|
||||
describe('Currency', function() {
|
||||
describe('json_rewrite', function() {
|
||||
@@ -16,17 +17,34 @@ describe('Currency', function() {
|
||||
});
|
||||
});
|
||||
describe('from_json', function() {
|
||||
it('from_json().to_json() == "XRP"', function() {
|
||||
var r = currency.from_json();
|
||||
assert(!r.is_valid());
|
||||
assert.strictEqual('XRP', r.to_json());
|
||||
});
|
||||
it('from_json(NaN).to_json() == "XRP"', function() {
|
||||
var r = currency.from_json(NaN);
|
||||
assert(!r.is_valid());
|
||||
assert.strictEqual('XRP', r.to_json());
|
||||
});
|
||||
it('from_json().to_json("") == "XRP"', function() {
|
||||
var r = currency.from_json('');
|
||||
assert(r.is_valid());
|
||||
assert(r.is_native());
|
||||
assert.strictEqual('XRP', r.to_json());
|
||||
});
|
||||
it('from_json("XRP").to_json() == "XRP"', function() {
|
||||
var r = currency.from_json('XRP');
|
||||
assert(r.is_valid());
|
||||
assert(r.is_native());
|
||||
assert.strictEqual('XRP', r.to_json());
|
||||
});
|
||||
it('from_json("0000000000000000000000000000000000000000").to_json() == "XRP"', function() {
|
||||
var r = currency.from_json('0000000000000000000000000000000000000000');
|
||||
assert(r.is_valid());
|
||||
assert(r.is_native());
|
||||
assert.strictEqual('XRP', r.to_json());
|
||||
});
|
||||
it('from_json("111").to_human()', function() {
|
||||
var r = currency.from_json("111");
|
||||
assert(r.is_valid());
|
||||
@@ -34,8 +52,24 @@ describe('Currency', function() {
|
||||
});
|
||||
it('from_json("1D2").to_human()', function() {
|
||||
var r = currency.from_json("1D2");
|
||||
assert(!r.is_valid());
|
||||
assert.strictEqual('XRP', r.to_json());
|
||||
assert(r.is_valid());
|
||||
assert.strictEqual('1D2', r.to_json());
|
||||
});
|
||||
it('from_json("XAU").to_json() hex', function() {
|
||||
var r = currency.from_json("XAU");
|
||||
assert.strictEqual('0000000000000000000000005841550000000000', r.to_json({force_hex: true}));
|
||||
});
|
||||
it('from_json("XAU (0.5%pa").to_json() hex', function() {
|
||||
var r = currency.from_json("XAU (0.5%pa)");
|
||||
assert.strictEqual('015841550000000041F78E0A28CBF19200000000', r.to_json({force_hex: true}));
|
||||
});
|
||||
it('json_rewrite("015841550000000041F78E0A28CBF19200000000").to_json() hex', function() {
|
||||
var r = currency.json_rewrite('015841550000000041F78E0A28CBF19200000000');
|
||||
assert.strictEqual('XAU (0.5%pa)', r);
|
||||
});
|
||||
it('json_rewrite("015841550000000041F78E0A28CBF19200000000") hex', function() {
|
||||
var r = currency.json_rewrite('015841550000000041F78E0A28CBF19200000000', {force_hex: true});
|
||||
assert.strictEqual('015841550000000041F78E0A28CBF19200000000', r);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -60,6 +94,9 @@ describe('Currency', function() {
|
||||
var cur = currency.from_human('EUR (0.5361%pa)');
|
||||
assert.strictEqual(cur.to_json(), 'EUR (0.54%pa)');
|
||||
assert.strictEqual(cur.to_json({decimals:4, full_name:'Euro'}), 'EUR - Euro (0.5361%pa)');
|
||||
assert.strictEqual(cur.to_json({decimals:void(0), full_name:'Euro'}), 'EUR - Euro (0.54%pa)');
|
||||
assert.strictEqual(cur.to_json({decimals:undefined, full_name:'Euro'}), 'EUR - Euro (0.54%pa)');
|
||||
assert.strictEqual(cur.to_json({decimals:'henk', full_name:'Euro'}), 'EUR - Euro (0.54%pa)');
|
||||
assert.strictEqual(cur.get_interest_percentage_at(undefined, 4), 0.5361);
|
||||
});
|
||||
it('From human "TYX - 30-Year Treasuries (1.5%pa)"', function() {
|
||||
@@ -78,6 +115,16 @@ describe('Currency', function() {
|
||||
var cur = currency.from_human('INR - 30 Indian Rupees');
|
||||
assert.strictEqual(cur.to_json(), 'INR');
|
||||
});
|
||||
it('From human "XRP"', function() {
|
||||
var cur = currency.from_human('XRP');
|
||||
assert.strictEqual(cur.to_json(), 'XRP');
|
||||
assert(cur.is_native(), true);
|
||||
});
|
||||
it('From human "XRP - Ripples"', function() {
|
||||
var cur = currency.from_human('XRP - Ripples');
|
||||
assert.strictEqual(cur.to_json(), 'XRP');
|
||||
assert(cur.is_native(), true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -89,8 +136,28 @@ describe('Currency', function() {
|
||||
assert.strictEqual('XRP', currency.from_json(NaN).to_human());
|
||||
});
|
||||
it('"015841551A748AD2C1F76FF6ECB0CCCD00000000") == "015841551A748AD2C1F76FF6ECB0CCCD00000000"', function() {
|
||||
assert.strictEqual(currency.from_json("015841551A748AD2C1F76FF6ECB0CCCD00000000").to_human(),
|
||||
'XAU (-0.5%pa)');
|
||||
assert.strictEqual(currency.from_json("015841551A748AD2C1F76FF6ECB0CCCD00000000").to_human(), 'XAU (-0.5%pa)');
|
||||
});
|
||||
it('"015841551A748AD2C1F76FF6ECB0CCCD00000000") == "015841551A748AD2C1F76FF6ECB0CCCD00000000"', function() {
|
||||
assert.strictEqual(currency.from_json("015841551A748AD2C1F76FF6ECB0CCCD00000000").to_human({full_name:'Gold'}), 'XAU - Gold (-0.5%pa)');
|
||||
});
|
||||
it('to_human interest XAU with full name, do not show interest', function() {
|
||||
assert.strictEqual(currency.from_json("015841551A748AD2C1F76FF6ECB0CCCD00000000").to_human({full_name:'Gold', show_interest:false}), 'XAU - Gold');
|
||||
});
|
||||
it('to_human interest XAU with full name, show interest', function() {
|
||||
assert.strictEqual(currency.from_json("015841551A748AD2C1F76FF6ECB0CCCD00000000").to_human({full_name:'Gold', show_interest:true}), 'XAU - Gold (-0.5%pa)');
|
||||
});
|
||||
it('to_human interest XAU, do show interest', function() {
|
||||
assert.strictEqual(currency.from_json("015841551A748AD2C1F76FF6ECB0CCCD00000000").to_human({show_interest:true}), 'XAU (-0.5%pa)');
|
||||
});
|
||||
it('to_human interest XAU, do not show interest', function() {
|
||||
assert.strictEqual(currency.from_json("015841551A748AD2C1F76FF6ECB0CCCD00000000").to_human({show_interest:false}), 'XAU');
|
||||
});
|
||||
it('to_human with full_name "USD - US Dollar show interest"', function() {
|
||||
assert.strictEqual(currency.from_json('USD').to_human({full_name:'US Dollar', show_interest:true}), 'USD - US Dollar (0%pa)');
|
||||
});
|
||||
it('to_human with full_name "USD - US Dollar do not show interest"', function() {
|
||||
assert.strictEqual(currency.from_json('USD').to_human({full_name:'US Dollar', show_interest:false}), 'USD - US Dollar');
|
||||
});
|
||||
it('to_human with full_name "USD - US Dollar"', function() {
|
||||
assert.strictEqual('USD - US Dollar', currency.from_json('USD').to_human({full_name:'US Dollar'}));
|
||||
@@ -98,6 +165,15 @@ describe('Currency', function() {
|
||||
it('to_human with full_name "XRP - Ripples"', function() {
|
||||
assert.strictEqual('XRP - Ripples', currency.from_json('XRP').to_human({full_name:'Ripples'}));
|
||||
});
|
||||
it('to_human human "TIM" without full_name', function() {
|
||||
var cur = currency.from_json("TIM");
|
||||
assert.strictEqual(cur.to_human(), "TIM");
|
||||
});
|
||||
it('to_human "TIM" with null full_name', function() {
|
||||
var cur = currency.from_json("TIM");
|
||||
assert.strictEqual(cur.to_human({full_name: null}), "TIM");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('from_hex', function() {
|
||||
@@ -108,10 +184,20 @@ describe('Currency', function() {
|
||||
assert.strictEqual(cur.to_json(), cur.to_human());
|
||||
});
|
||||
});
|
||||
describe('parse_json(currency obj)', function() {
|
||||
assert.strictEqual('USD', new currency().parse_json(currency.from_json('USD')).to_json());
|
||||
describe('parse_json', function() {
|
||||
it('should parse a currency object', function() {
|
||||
assert.strictEqual('USD', new currency().parse_json(currency.from_json('USD')).to_json());
|
||||
assert.strictEqual('USD (0.5%pa)', new currency().parse_json(currency.from_json('USD (0.5%pa)')).to_json());
|
||||
});
|
||||
it('should clone for parse_json on itself', function() {
|
||||
var cur = currency.from_json('USD');
|
||||
var cur2 = currency.from_json(cur);
|
||||
assert.strictEqual(cur.to_json(), cur2.to_json());
|
||||
|
||||
assert.strictEqual('USD (0.5%pa)', new currency().parse_json(currency.from_json('USD (0.5%pa)')).to_json());
|
||||
cur = currency.from_hex('015841551A748AD2C1F76FF6ECB0CCCD00000000');
|
||||
cur2 = currency.from_json(cur);
|
||||
assert.strictEqual(cur.to_json(), cur2.to_json());
|
||||
});
|
||||
});
|
||||
|
||||
describe('is_valid', function() {
|
||||
@@ -153,14 +239,16 @@ describe('Currency', function() {
|
||||
return +(Math.round(num + "e+"+precision) + "e-"+precision);
|
||||
}
|
||||
describe('get_interest_at', function() {
|
||||
it('returns demurred value for demurrage currency', function() {
|
||||
it('should return demurred value for demurrage currency', function() {
|
||||
var cur = currency.from_json('015841551A748AD2C1F76FF6ECB0CCCD00000000');
|
||||
|
||||
// At start, no demurrage should occur
|
||||
assert.equal(1, cur.get_interest_at(443845330));
|
||||
assert.equal(1, precision(cur.get_interest_at(new Date(timeUtil.fromRipple(443845330))), 14));
|
||||
|
||||
// After one year, 0.5% should have occurred
|
||||
assert.equal(0.995, precision(cur.get_interest_at(443845330 + 31536000), 14));
|
||||
assert.equal(0.995, precision(cur.get_interest_at(new Date(timeUtil.fromRipple(443845330 + 31536000))), 14));
|
||||
|
||||
// After one demurrage period, 1/e should have occurred
|
||||
assert.equal(1/Math.E, cur.get_interest_at(443845330 + 6291418827.05));
|
||||
@@ -171,6 +259,11 @@ describe('Currency', function() {
|
||||
// One demurrage period before start, rate should be e
|
||||
assert.equal(Math.E, cur.get_interest_at(443845330 - 6291418827.05));
|
||||
});
|
||||
it('should return 0 for currency without interest', function() {
|
||||
var cur = currency.from_json('USD - US Dollar');
|
||||
assert.equal(0, cur.get_interest_at(443845330));
|
||||
assert.equal(0, cur.get_interest_at(443845330 + 31536000));
|
||||
});
|
||||
});
|
||||
describe('get_iso', function() {
|
||||
it('should get "XRP" iso_code', function() {
|
||||
|
||||
@@ -82,8 +82,17 @@ describe('Message', function(){
|
||||
});
|
||||
|
||||
it('should throw an error if given an invalid secret key', function(){
|
||||
// Annoyingly non hex can be fed to the BigInteger(s, 16) constructor and
|
||||
// it will parse as a number. Before the commit of this comment, this test
|
||||
// involved a fixture of 32 chars, which was assumed to be hex. The test
|
||||
// passed, but for the wrong wreasons. There was a bug in Seed.parse_json.
|
||||
|
||||
var secret_string = 'badsafRpB5euNL52PZPTSqrE9gvuFwTC';
|
||||
// Seed.from_json only creates invalid seeds from empty strings or invalid
|
||||
// base58 starting with an s, which it tries to base 58 decode/check sum.
|
||||
// The rest will be assumed to be a passphrase.
|
||||
|
||||
// This is a bad b58 seed
|
||||
var secret_string = 'sbadsafRpB5euNL52PZPTSqrE9gvuFwTC';
|
||||
var hash = 'e865bcc63a86ef21585ac8340a7cc8590ed85175a2a718c6fb2bfb2715d13778';
|
||||
|
||||
assert.throws(function(){
|
||||
|
||||
1553
test/orderbook-test.js
Normal file
1553
test/orderbook-test.js
Normal file
File diff suppressed because it is too large
Load Diff
@@ -28,156 +28,120 @@ describe('Remote', function () {
|
||||
// 'bitcoin': 'localhost:3000'
|
||||
// 'bitcoin': 'https://www.bitstamp.net/ripple/bridge/out/bitcoin/'
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
};
|
||||
});
|
||||
|
||||
it('remote server initialization - url object', function() {
|
||||
var remote = new Remote({
|
||||
servers: [ { host: 's-west.ripple.com', port: 443, secure: true } ],
|
||||
});
|
||||
assert(Array.isArray(remote._servers));
|
||||
assert(remote._servers[0] instanceof Server);
|
||||
assert.strictEqual(remote._servers[0]._url, 'wss://s-west.ripple.com:443');
|
||||
})
|
||||
|
||||
describe('remote server initialization - url object', function() {
|
||||
it('should construct url', function (done) {
|
||||
it('remote server initialization - url object - no secure property', function() {
|
||||
var remote = new Remote({
|
||||
servers: [ { host: 's-west.ripple.com', port: 443 } ]
|
||||
});
|
||||
assert(Array.isArray(remote._servers));
|
||||
assert(remote._servers[0] instanceof Server);
|
||||
assert.strictEqual(remote._servers[0]._url, 'wss://s-west.ripple.com:443');
|
||||
})
|
||||
|
||||
it('remote server initialization - url object - secure: false', function() {
|
||||
var remote = new Remote({
|
||||
servers: [ { host: 's-west.ripple.com', port: 443, secure: false } ]
|
||||
});
|
||||
assert(Array.isArray(remote._servers));
|
||||
assert(remote._servers[0] instanceof Server);
|
||||
assert.strictEqual(remote._servers[0]._url, 'ws://s-west.ripple.com:443');
|
||||
});
|
||||
|
||||
it('remote server initialization - url object - string port', function() {
|
||||
var remote = new Remote({
|
||||
servers: [ { host: 's-west.ripple.com', port: '443', secure: true } ]
|
||||
});
|
||||
assert(Array.isArray(remote._servers));
|
||||
assert(remote._servers[0] instanceof Server);
|
||||
assert.strictEqual(remote._servers[0]._url, 'wss://s-west.ripple.com:443');
|
||||
})
|
||||
|
||||
it('remote server initialization - url object - invalid host', function() {
|
||||
assert.throws(
|
||||
function() {
|
||||
var remote = new Remote({
|
||||
servers: [ { host: 's-west.ripple.com', port: 443, secure: true } ],
|
||||
servers: [ { host: '+', port: 443, secure: true } ]
|
||||
});
|
||||
assert(Array.isArray(remote._servers));
|
||||
assert(remote._servers[0] instanceof Server);
|
||||
assert.strictEqual(remote._servers[0]._url, 'wss://s-west.ripple.com:443');
|
||||
done();
|
||||
})
|
||||
});
|
||||
}, Error);
|
||||
})
|
||||
|
||||
describe('remote server initialization - url object - no secure property', function() {
|
||||
it('should construct url', function (done) {
|
||||
it('remote server initialization - url object - invalid port', function() {
|
||||
assert.throws(
|
||||
function() {
|
||||
var remote = new Remote({
|
||||
servers: [ { host: 's-west.ripple.com', port: 443 } ]
|
||||
servers: [ { host: 's-west.ripple.com', port: null, secure: true } ]
|
||||
});
|
||||
assert(Array.isArray(remote._servers));
|
||||
assert(remote._servers[0] instanceof Server);
|
||||
assert.strictEqual(remote._servers[0]._url, 'wss://s-west.ripple.com:443');
|
||||
done();
|
||||
})
|
||||
}, TypeError);
|
||||
});
|
||||
|
||||
describe('remote server initialization - url object - secure: false', function() {
|
||||
it('should construct url', function (done) {
|
||||
it('remote server initialization - url object - port out of range', function() {
|
||||
assert.throws(
|
||||
function() {
|
||||
var remote = new Remote({
|
||||
servers: [ { host: 's-west.ripple.com', port: 443, secure: false } ]
|
||||
servers: [ { host: 's-west.ripple.com', port: 65537, secure: true } ]
|
||||
});
|
||||
assert(Array.isArray(remote._servers));
|
||||
assert(remote._servers[0] instanceof Server);
|
||||
assert.strictEqual(remote._servers[0]._url, 'ws://s-west.ripple.com:443');
|
||||
done();
|
||||
})
|
||||
}, Error);
|
||||
});
|
||||
|
||||
describe('remote server initialization - url object - string port', function() {
|
||||
it('should construct url', function (done) {
|
||||
it('remote server initialization - url string', function() {
|
||||
var remote = new Remote({
|
||||
servers: [ 'wss://s-west.ripple.com:443' ]
|
||||
});
|
||||
assert(Array.isArray(remote._servers));
|
||||
assert(remote._servers[0] instanceof Server);
|
||||
assert.strictEqual(remote._servers[0]._url, 'wss://s-west.ripple.com:443');
|
||||
});
|
||||
|
||||
it('remote server initialization - url string - ws://', function() {
|
||||
var remote = new Remote({
|
||||
servers: [ 'ws://s-west.ripple.com:443' ]
|
||||
});
|
||||
assert(Array.isArray(remote._servers));
|
||||
assert(remote._servers[0] instanceof Server);
|
||||
assert.strictEqual(remote._servers[0]._url, 'ws://s-west.ripple.com:443');
|
||||
});
|
||||
|
||||
it('remote server initialization - url string - invalid host', function() {
|
||||
assert.throws(
|
||||
function() {
|
||||
var remote = new Remote({
|
||||
servers: [ { host: 's-west.ripple.com', port: '443', secure: true } ]
|
||||
servers: [ 'ws://+:443' ]
|
||||
});
|
||||
assert(Array.isArray(remote._servers));
|
||||
assert(remote._servers[0] instanceof Server);
|
||||
assert.strictEqual(remote._servers[0]._url, 'wss://s-west.ripple.com:443');
|
||||
done();
|
||||
})
|
||||
}, Error
|
||||
);
|
||||
});
|
||||
|
||||
describe('remote server initialization - url object - invalid host', function() {
|
||||
it('should construct url', function (done) {
|
||||
assert.throws(
|
||||
function() {
|
||||
var remote = new Remote({
|
||||
servers: [ { host: '+', port: 443, secure: true } ]
|
||||
});
|
||||
}, Error);
|
||||
done();
|
||||
})
|
||||
});
|
||||
|
||||
describe('remote server initialization - url object - invalid port', function() {
|
||||
it('should construct url', function (done) {
|
||||
assert.throws(
|
||||
function() {
|
||||
var remote = new Remote({
|
||||
servers: [ { host: 's-west.ripple.com', port: null, secure: true } ]
|
||||
});
|
||||
}, TypeError);
|
||||
done();
|
||||
})
|
||||
});
|
||||
|
||||
describe('remote server initialization - url object - port out of range', function() {
|
||||
it('should construct url', function (done) {
|
||||
assert.throws(
|
||||
function() {
|
||||
var remote = new Remote({
|
||||
servers: [ { host: 's-west.ripple.com', port: 65537, secure: true } ]
|
||||
});
|
||||
}, Error);
|
||||
done();
|
||||
})
|
||||
});
|
||||
|
||||
describe('remote server initialization - url string', function() {
|
||||
it('should construct url', function (done) {
|
||||
it('remote server initialization - url string - invalid port', function() {
|
||||
assert.throws(
|
||||
function() {
|
||||
var remote = new Remote({
|
||||
servers: [ 'wss://s-west.ripple.com:443' ]
|
||||
servers: [ 'ws://s-west.ripple.com:null' ]
|
||||
});
|
||||
assert(Array.isArray(remote._servers));
|
||||
assert(remote._servers[0] instanceof Server);
|
||||
assert.strictEqual(remote._servers[0]._url, 'wss://s-west.ripple.com:443');
|
||||
done();
|
||||
})
|
||||
}, Error
|
||||
);
|
||||
});
|
||||
|
||||
describe('remote server initialization - url string - ws://', function() {
|
||||
it('should construct url', function (done) {
|
||||
it('remote server initialization - url string - port out of range', function() {
|
||||
assert.throws(
|
||||
function() {
|
||||
var remote = new Remote({
|
||||
servers: [ 'ws://s-west.ripple.com:443' ]
|
||||
servers: [ 'ws://s-west.ripple.com:65537:' ]
|
||||
});
|
||||
assert(Array.isArray(remote._servers));
|
||||
assert(remote._servers[0] instanceof Server);
|
||||
assert.strictEqual(remote._servers[0]._url, 'ws://s-west.ripple.com:443');
|
||||
done();
|
||||
})
|
||||
});
|
||||
|
||||
describe('remote server initialization - url string - invalid host', function() {
|
||||
it('should construct url', function (done) {
|
||||
assert.throws(
|
||||
function() {
|
||||
var remote = new Remote({
|
||||
servers: [ 'ws://+:443' ]
|
||||
});
|
||||
}, Error
|
||||
);
|
||||
done();
|
||||
})
|
||||
});
|
||||
|
||||
describe('remote server initialization - url string - invalid port', function() {
|
||||
it('should construct url', function (done) {
|
||||
assert.throws(
|
||||
function() {
|
||||
var remote = new Remote({
|
||||
servers: [ 'ws://s-west.ripple.com:null' ]
|
||||
});
|
||||
}, Error
|
||||
);
|
||||
done();
|
||||
})
|
||||
});
|
||||
|
||||
describe('remote server initialization - url string - port out of range', function() {
|
||||
it('should construct url', function (done) {
|
||||
assert.throws(
|
||||
function() {
|
||||
var remote = new Remote({
|
||||
servers: [ 'ws://s-west.ripple.com:65537:' ]
|
||||
});
|
||||
}, Error
|
||||
);
|
||||
done();
|
||||
})
|
||||
}, Error
|
||||
);
|
||||
});
|
||||
|
||||
describe('request constructors', function () {
|
||||
@@ -186,64 +150,229 @@ describe('Remote', function () {
|
||||
remote = new Remote(options);
|
||||
});
|
||||
|
||||
describe('requesting a ledger', function () {
|
||||
it('should return a request', function (done) {
|
||||
var request = remote.request_ledger(null, {}, callback);
|
||||
assert(request instanceof Request);
|
||||
done();
|
||||
})
|
||||
it('requesting a ledger', function () {
|
||||
var request = remote.request_ledger(null, {}, callback);
|
||||
assert(request instanceof Request);
|
||||
});
|
||||
|
||||
describe('requesting server info', function () {
|
||||
it('should return a request object', function (done) {
|
||||
var request = remote.request_server_info(null, {}, callback);
|
||||
assert(request instanceof Request);
|
||||
done();
|
||||
})
|
||||
it('requesting server info', function () {
|
||||
var request = remote.request_server_info(null, {}, callback);
|
||||
assert(request instanceof Request);
|
||||
})
|
||||
|
||||
describe('requesting peers', function () {
|
||||
it('should return a request object', function (done) {
|
||||
var request = remote.request_peers(null, {}, callback);
|
||||
assert(request instanceof Request);
|
||||
done();
|
||||
});
|
||||
it('requesting peers', function () {
|
||||
var request = remote.request_peers(null, {}, callback);
|
||||
assert(request instanceof Request);
|
||||
});
|
||||
|
||||
describe('requesting a connection', function () {
|
||||
it('should return a request object', function (done) {
|
||||
var request = remote.request_connect(null, {}, callback);
|
||||
assert(request instanceof Request);
|
||||
done();
|
||||
});
|
||||
it('requesting a connection', function () {
|
||||
var request = remote.request_connect(null, {}, callback);
|
||||
assert(request instanceof Request);
|
||||
});
|
||||
|
||||
describe('making a unique node list add request', function () {
|
||||
it('should return a request object', function (done) {
|
||||
var request = remote.request_unl_add(null, {}, callback);
|
||||
assert(request instanceof Request);
|
||||
done();
|
||||
});
|
||||
it('making a unique node list add request', function () {
|
||||
var request = remote.request_unl_add(null, {}, callback);
|
||||
assert(request instanceof Request);
|
||||
});
|
||||
|
||||
describe('making a unique node list request', function () {
|
||||
it('should return a request object', function (done) {
|
||||
var request = remote.request_unl_list(null, {}, callback);
|
||||
assert(request instanceof Request);
|
||||
done();
|
||||
});
|
||||
it('making a unique node list request', function () {
|
||||
var request = remote.request_unl_list(null, {}, callback);
|
||||
assert(request instanceof Request);
|
||||
});
|
||||
|
||||
describe('making a unique node list delete request', function () {
|
||||
it('should return a request object', function (done) {
|
||||
var request = remote.request_unl_delete(null, {}, callback);
|
||||
assert(request instanceof Request);
|
||||
done();
|
||||
});
|
||||
it('making a unique node list delete request', function () {
|
||||
var request = remote.request_unl_delete(null, {}, callback);
|
||||
assert(request instanceof Request);
|
||||
});
|
||||
})
|
||||
|
||||
describe('create remote and get pending transactions', function() {
|
||||
it('request account info with ledger index', function() {
|
||||
var request = remote.requestAccountInfo('r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', 9592219);
|
||||
assert.strictEqual(request.message.command, 'account_info');
|
||||
assert.strictEqual(request.message.account, 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS');
|
||||
assert.strictEqual(request.message.ledger_index, 9592219);
|
||||
});
|
||||
it('request account info with ledger hash', function() {
|
||||
var request = remote.requestAccountInfo('r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', 'B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE');
|
||||
assert.strictEqual(request.message.command, 'account_info');
|
||||
assert.strictEqual(request.message.account, 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS');
|
||||
assert.strictEqual(request.message.ledger_hash, 'B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE');
|
||||
});
|
||||
it('request account info with ledger identifier', function() {
|
||||
var request = remote.requestAccountInfo('r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', 'validated');
|
||||
assert.strictEqual(request.message.command, 'account_info');
|
||||
assert.strictEqual(request.message.account, 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS');
|
||||
assert.strictEqual(request.message.ledger_index, 'validated');
|
||||
});
|
||||
|
||||
it('request account balance with ledger index', function() {
|
||||
var request = remote.requestAccountBalance('r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', 9592219);
|
||||
assert.strictEqual(request.message.command, 'ledger_entry');
|
||||
assert.strictEqual(request.message.account_root, 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS');
|
||||
assert.strictEqual(request.message.ledger_index, 9592219);
|
||||
});
|
||||
it('request account balance with ledger hash', function() {
|
||||
var request = remote.requestAccountBalance('r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', 'B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE');
|
||||
assert.strictEqual(request.message.command, 'ledger_entry');
|
||||
assert.strictEqual(request.message.account_root, 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS');
|
||||
assert.strictEqual(request.message.ledger_hash, 'B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE');
|
||||
});
|
||||
it('request account balance with ledger identifier', function() {
|
||||
var request = remote.requestAccountBalance('r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', 'validated');
|
||||
assert.strictEqual(request.message.command, 'ledger_entry');
|
||||
assert.strictEqual(request.message.account_root, 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS');
|
||||
assert.strictEqual(request.message.ledger_index, 'validated');
|
||||
});
|
||||
});
|
||||
|
||||
it('pagingAccountRequest', function() {
|
||||
var request = Remote.pagingAccountRequest('account_lines', 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS');
|
||||
assert.deepEqual(request.message, {
|
||||
command: 'account_lines',
|
||||
id: undefined,
|
||||
account: 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS'
|
||||
});
|
||||
});
|
||||
|
||||
it('pagingAccountRequest - limit', function() {
|
||||
var request = Remote.pagingAccountRequest('account_lines', 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', {limit: 100});
|
||||
assert.deepEqual(request.message, {
|
||||
command: 'account_lines',
|
||||
id: undefined,
|
||||
account: 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS',
|
||||
limit: 100
|
||||
});
|
||||
});
|
||||
|
||||
it('pagingAccountRequest - limit, marker', function() {
|
||||
var request = Remote.pagingAccountRequest('account_lines', 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', {limit: 100, marker: '29F992CC252056BF690107D1E8F2D9FBAFF29FF107B62B1D1F4E4E11ADF2CC73'});
|
||||
assert.deepEqual(request.message, {
|
||||
command: 'account_lines',
|
||||
id: undefined,
|
||||
account: 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS',
|
||||
limit: 100,
|
||||
marker: '29F992CC252056BF690107D1E8F2D9FBAFF29FF107B62B1D1F4E4E11ADF2CC73'
|
||||
});
|
||||
|
||||
assert(!request.requested);
|
||||
});
|
||||
|
||||
it('pagingAccountRequest - limit min', function() {
|
||||
assert.strictEqual(Remote.pagingAccountRequest('account_lines', 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', {limit: 0}).message.limit, 0);
|
||||
assert.strictEqual(Remote.pagingAccountRequest('account_lines', 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', {limit: -1}).message.limit, 0);
|
||||
assert.strictEqual(Remote.pagingAccountRequest('account_lines', 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', {limit: -1e9}).message.limit, 0);
|
||||
assert.strictEqual(Remote.pagingAccountRequest('account_lines', 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', {limit: -1e24}).message.limit, 0);
|
||||
});
|
||||
|
||||
it('pagingAccountRequest - limit max', function() {
|
||||
assert.strictEqual(Remote.pagingAccountRequest('account_lines', 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', {limit: 1e9}).message.limit, 1e9);
|
||||
assert.strictEqual(Remote.pagingAccountRequest('account_lines', 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', {limit: 1e9+1}).message.limit, 1e9);
|
||||
assert.strictEqual(Remote.pagingAccountRequest('account_lines', 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', {limit: 1e10}).message.limit, 1e9);
|
||||
assert.strictEqual(Remote.pagingAccountRequest('account_lines', 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', {limit: 1e24}).message.limit, 1e9);
|
||||
});
|
||||
|
||||
it('requestAccountLines, account and callback', function() {
|
||||
var callback = function() {};
|
||||
var remote = new Remote({
|
||||
servers: [ { host: 's-west.ripple.com', port: 443, secure: true } ]
|
||||
});
|
||||
var request = remote.requestAccountLines(
|
||||
'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS',
|
||||
callback
|
||||
);
|
||||
|
||||
assert.deepEqual(request.message, {
|
||||
command: 'account_lines',
|
||||
id: undefined,
|
||||
account: 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS'
|
||||
});
|
||||
|
||||
assert(request.requested);
|
||||
});
|
||||
|
||||
it('requestAccountLines, ledger, peer', function() {
|
||||
var callback = function() {};
|
||||
var remote = new Remote({
|
||||
servers: [ { host: 's-west.ripple.com', port: 443, secure: true } ]
|
||||
});
|
||||
var request = remote.requestAccountLines(
|
||||
'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS',
|
||||
{
|
||||
ledger: 'validated',
|
||||
peer: 'rfYv1TXnwgDDK4WQNbFALykYuEBnrR4pDX'
|
||||
},
|
||||
callback
|
||||
);
|
||||
|
||||
assert.deepEqual(request.message, {
|
||||
command: 'account_lines',
|
||||
id: undefined,
|
||||
account: 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS',
|
||||
ledger_index: 'validated',
|
||||
peer: 'rfYv1TXnwgDDK4WQNbFALykYuEBnrR4pDX'
|
||||
});
|
||||
|
||||
assert(request.requested);
|
||||
});
|
||||
|
||||
it('requestAccountLines, ledger, peer, limit and marker', function() {
|
||||
var callback = function() {};
|
||||
var remote = new Remote({
|
||||
servers: [ { host: 's-west.ripple.com', port: 443, secure: true } ]
|
||||
});
|
||||
var request = remote.requestAccountLines(
|
||||
'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS',
|
||||
{
|
||||
ledger: 'validated',
|
||||
peer: 'rfYv1TXnwgDDK4WQNbFALykYuEBnrR4pDX',
|
||||
limit: 200,
|
||||
marker: '29F992CC252056BF690107D1E8F2D9FBAFF29FF107B62B1D1F4E4E11ADF2CC73'
|
||||
},
|
||||
callback
|
||||
);
|
||||
|
||||
assert.deepEqual(request.message, {
|
||||
command: 'account_lines',
|
||||
id: undefined,
|
||||
account: 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS',
|
||||
ledger_index: 'validated',
|
||||
peer: 'rfYv1TXnwgDDK4WQNbFALykYuEBnrR4pDX',
|
||||
limit: 200,
|
||||
marker: '29F992CC252056BF690107D1E8F2D9FBAFF29FF107B62B1D1F4E4E11ADF2CC73'
|
||||
});
|
||||
|
||||
assert(request.requested);
|
||||
});
|
||||
|
||||
it('requestAccountOffers, ledger, peer, limit and marker', function() {
|
||||
var callback = function() {};
|
||||
var remote = new Remote({
|
||||
servers: [ { host: 's-west.ripple.com', port: 443, secure: true } ]
|
||||
});
|
||||
var request = remote.requestAccountOffers(
|
||||
'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS',
|
||||
{
|
||||
ledger: 'validated',
|
||||
peer: 'rfYv1TXnwgDDK4WQNbFALykYuEBnrR4pDX',
|
||||
limit: 32,
|
||||
marker: '29F992CC252056BF690107D1E8F2D9FBAFF29FF107B62B1D1F4E4E11ADF2CC73'
|
||||
},
|
||||
callback
|
||||
);
|
||||
|
||||
assert.deepEqual(request.message, {
|
||||
command: 'account_offers',
|
||||
id: undefined,
|
||||
account: 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS',
|
||||
ledger_index: 'validated',
|
||||
peer: 'rfYv1TXnwgDDK4WQNbFALykYuEBnrR4pDX',
|
||||
limit: 32,
|
||||
marker: '29F992CC252056BF690107D1E8F2D9FBAFF29FF107B62B1D1F4E4E11ADF2CC73'
|
||||
});
|
||||
|
||||
assert(request.requested);
|
||||
});
|
||||
|
||||
it('create remote and get pending transactions', function() {
|
||||
before(function() {
|
||||
tx = [{
|
||||
tx_json: {
|
||||
@@ -301,7 +430,7 @@ describe('Remote', function () {
|
||||
callback(null, tx);
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
it('should set transaction members correct ', function(done) {
|
||||
remote = new Remote(options);
|
||||
|
||||
@@ -3,6 +3,7 @@ var utils = require('./testutils');
|
||||
var Request = utils.load_module('request').Request;
|
||||
var Remote = utils.load_module('remote').Remote;
|
||||
var Server = utils.load_module('server').Server;
|
||||
var Currency = utils.load_module('currency').Currency;
|
||||
|
||||
function makeServer(url) {
|
||||
var server = new Server(new process.EventEmitter(), url);
|
||||
@@ -325,6 +326,7 @@ describe('Request', function() {
|
||||
var request = new Request(remote, 'server_info');
|
||||
request.ledgerChoose();
|
||||
assert.strictEqual(request.message.ledger_hash, 'B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE');
|
||||
assert.strictEqual(request.message.ledger_index, void(0));
|
||||
});
|
||||
|
||||
it('Select ledger - identifier', function() {
|
||||
@@ -334,6 +336,7 @@ describe('Request', function() {
|
||||
var request = new Request(remote, 'server_info');
|
||||
request.ledgerSelect('validated');
|
||||
assert.strictEqual(request.message.ledger_index, 'validated');
|
||||
assert.strictEqual(request.message.ledger_hash, void(0));
|
||||
});
|
||||
|
||||
it('Select ledger - index', function() {
|
||||
@@ -343,6 +346,7 @@ describe('Request', function() {
|
||||
var request = new Request(remote, 'server_info');
|
||||
request.ledgerSelect(7016915);
|
||||
assert.strictEqual(request.message.ledger_index, 7016915);
|
||||
assert.strictEqual(request.message.ledger_hash, void(0));
|
||||
});
|
||||
|
||||
it('Select ledger - hash', function() {
|
||||
@@ -352,15 +356,23 @@ describe('Request', function() {
|
||||
var request = new Request(remote, 'server_info');
|
||||
request.ledgerSelect('B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE');
|
||||
assert.strictEqual(request.message.ledger_hash, 'B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE');
|
||||
assert.strictEqual(request.message.ledger_index, void(0));
|
||||
});
|
||||
|
||||
it('Select ledger - hash', function() {
|
||||
it('Select ledger - undefined', function() {
|
||||
var remote = new Remote();
|
||||
remote._connected = true;
|
||||
|
||||
var request = new Request(remote, 'server_info');
|
||||
request.ledgerSelect('B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE');
|
||||
assert.strictEqual(request.message.ledger_hash, 'B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE');
|
||||
request.ledgerSelect();
|
||||
assert.strictEqual(request.message.ledger_hash, void(0));
|
||||
assert.strictEqual(request.message.ledger_index, void(0));
|
||||
request.ledgerSelect(null);
|
||||
assert.strictEqual(request.message.ledger_hash, void(0));
|
||||
assert.strictEqual(request.message.ledger_index, void(0));
|
||||
request.ledgerSelect(NaN);
|
||||
assert.strictEqual(request.message.ledger_hash, void(0));
|
||||
assert.strictEqual(request.message.ledger_index, void(0));
|
||||
});
|
||||
|
||||
it('Set account_root', function() {
|
||||
@@ -554,7 +566,19 @@ describe('Request', function() {
|
||||
|
||||
request.books(books);
|
||||
|
||||
assert.deepEqual(request.message.books, books);
|
||||
assert.deepEqual(request.message.books, [
|
||||
{
|
||||
'taker_gets': {
|
||||
'currency': Currency.from_json('EUR').to_hex(),
|
||||
'issuer': 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
|
||||
},
|
||||
'taker_pays': {
|
||||
'currency': Currency.from_json('USD').to_hex(),
|
||||
'issuer': 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
|
||||
},
|
||||
'snapshot': true
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
it('Add book', function() {
|
||||
@@ -577,13 +601,14 @@ describe('Request', function() {
|
||||
assert.deepEqual(request.message.books, [
|
||||
{
|
||||
'taker_gets': {
|
||||
'currency': 'CNY',
|
||||
'currency': Currency.from_json('CNY').to_hex(),
|
||||
'issuer': 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
|
||||
},
|
||||
'taker_pays': {
|
||||
'currency': 'USD',
|
||||
'currency': Currency.from_json('USD').to_hex(),
|
||||
'issuer': 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
|
||||
}
|
||||
},
|
||||
'snapshot': true
|
||||
}
|
||||
]);
|
||||
|
||||
@@ -605,13 +630,14 @@ describe('Request', function() {
|
||||
assert.deepEqual(request.message.books, [
|
||||
{
|
||||
'taker_gets': {
|
||||
'currency': 'EUR',
|
||||
'currency': '0000000000000000000000004555520000000000', // EUR hex
|
||||
'issuer': 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
|
||||
},
|
||||
'taker_pays': {
|
||||
'currency': 'USD',
|
||||
'currency': '0000000000000000000000005553440000000000', // USD hex
|
||||
'issuer': 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
|
||||
}
|
||||
},
|
||||
'snapshot': true
|
||||
},
|
||||
]);
|
||||
});
|
||||
@@ -638,7 +664,7 @@ describe('Request', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Add book - with snapshot', function() {
|
||||
it('Add book - without snapshot', function() {
|
||||
var remote = new Remote();
|
||||
remote._connected = true;
|
||||
|
||||
@@ -661,6 +687,28 @@ describe('Request', function() {
|
||||
request.addBook(book, true);
|
||||
|
||||
assert.deepEqual(request.message.books, [{
|
||||
'taker_gets': {
|
||||
'currency': Currency.from_json('EUR').to_hex(),
|
||||
'issuer': 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
|
||||
},
|
||||
'taker_pays': {
|
||||
'currency': Currency.from_json('USD').to_hex(),
|
||||
'issuer': 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
|
||||
},
|
||||
'both': true,
|
||||
'snapshot': true
|
||||
}]);
|
||||
});
|
||||
|
||||
it('Add book - no snapshot', function() {
|
||||
var remote = new Remote();
|
||||
remote._connected = true;
|
||||
|
||||
var request = new Request(remote, 'server_info');
|
||||
|
||||
request.message.books = void(0);
|
||||
|
||||
var book = {
|
||||
'taker_gets': {
|
||||
'currency': 'EUR',
|
||||
'issuer': 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
|
||||
@@ -669,8 +717,76 @@ describe('Request', function() {
|
||||
'currency': 'USD',
|
||||
'issuer': 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
|
||||
},
|
||||
'snapshot': true,
|
||||
'both': true
|
||||
};
|
||||
|
||||
request.addBook(book, false);
|
||||
|
||||
assert.deepEqual(request.message.books, [{
|
||||
'taker_gets': {
|
||||
'currency': Currency.from_json('EUR').to_hex(),
|
||||
'issuer': 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
|
||||
},
|
||||
'taker_pays': {
|
||||
'currency': Currency.from_json('USD').to_hex(),
|
||||
'issuer': 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
|
||||
},
|
||||
'both': true
|
||||
}]);
|
||||
});
|
||||
|
||||
it('Add stream', function() {
|
||||
var remote = new Remote();
|
||||
remote._connected = true;
|
||||
|
||||
var request = new Request(remote, 'subscribe');
|
||||
|
||||
request.addStream('server', 'ledger');
|
||||
request.addStream('transactions', 'transactions_proposed');
|
||||
request.addStream('accounts', [ 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B' ]);
|
||||
request.addStream('accounts_proposed', [ 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59' ]);
|
||||
request.addStream('books', [{
|
||||
'taker_gets': {
|
||||
'currency': 'EUR',
|
||||
'issuer': 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
|
||||
},
|
||||
'taker_pays': {
|
||||
'currency': 'USD',
|
||||
'issuer': 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
|
||||
}
|
||||
}]);
|
||||
|
||||
assert.deepEqual(request.message, {
|
||||
'command': 'subscribe',
|
||||
'id': void(0),
|
||||
'streams': [
|
||||
'server',
|
||||
'ledger',
|
||||
'transactions',
|
||||
'transactions_proposed',
|
||||
'accounts',
|
||||
'accounts_proposed',
|
||||
'books'
|
||||
],
|
||||
'accounts': [
|
||||
'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
|
||||
],
|
||||
'accounts_proposed': [
|
||||
'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59'
|
||||
],
|
||||
'books': [
|
||||
{
|
||||
'taker_gets': {
|
||||
'currency': '0000000000000000000000004555520000000000',
|
||||
'issuer': 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
|
||||
},
|
||||
'taker_pays': {
|
||||
'currency': '0000000000000000000000005553440000000000',
|
||||
'issuer': 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
|
||||
},
|
||||
'snapshot': true
|
||||
}
|
||||
]
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,59 +5,71 @@ var config = require('./testutils').get_config();
|
||||
|
||||
describe('Seed', function() {
|
||||
it('can generate many addresses', function () {
|
||||
var seed = Seed.from_json("masterpassphrase");
|
||||
|
||||
// Note: Created with jRippleAPI code
|
||||
// Link: https://github.com/pmarches/jRippleAPI/blob/master/src/jrippleapi/keys/RippleDeterministicKeyGenerator.java
|
||||
var test_data = [
|
||||
// Format:
|
||||
// [passphrase, address, nth-for-seed, expected-public-key]
|
||||
["masterpassphrase", "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", 0,
|
||||
"0330E7FC9D56BB25D6893BA3F317AE5BCF33B3291BD63DB32654A313222F7FD020"],
|
||||
["masterpassphrase", "r4bYF7SLUMD7QgSLLpgJx38WJSY12ViRjP", 1,
|
||||
"02CD8C4CE87F86AAD1D9D18B03DE28E6E756F040BD72A9C127862833EB90D60BAD"],
|
||||
["masterpassphrase", "rLpAd4peHUMBPbVJASMYK5GTBUSwXRD9nx", 2,
|
||||
"0259A57642A6F4AEFC9B8062AF453FDEEEAC5572BA602BB1DBD5EF011394C6F9FC"],
|
||||
["otherpassphrase", "rpe3YWSVwGU2PmUzebAPg2deBXHtmba7hJ", 0,
|
||||
"022235A3DB2CAE57C60B7831929611D58867F86D28C0AD3C82473CC4A84990D01B"],
|
||||
["otherpassphrase", "raAPC2gALSmsTkXR4wUwQcPgX66kJuLv2S", 5,
|
||||
"03F0619AFABE08D22D98C8721895FE3673B6174168949976F2573CE1138C124994"],
|
||||
["yetanotherpassphrase", "rKnM44fS48qrGiDxB5fB5u64vHVJwjDPUo", 0,
|
||||
"0385AD049327EF7E5EC429350A15CEB23955037DE99660F6E70C11C5ABF4407036"],
|
||||
["yetanotherpassphrase", "rMvkT1RHPfsZwTFbKDKBEisa5U4d2a9V8n", 1,
|
||||
"023A2876EA130CBE7BBA0573C2DB4C4CEB9A7547666915BD40366CDC6150CF54DC"]
|
||||
];
|
||||
|
||||
// To reviewer/merger: Even generating keypairs for thi this small amount of
|
||||
// addresses makes the test suite run SO SLOW. Consider cutting at the tail.
|
||||
var first_nth_addresses = [
|
||||
// 0th implied
|
||||
"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh",
|
||||
// 1th implied
|
||||
"r4bYF7SLUMD7QgSLLpgJx38WJSY12ViRjP",
|
||||
// 2th implied
|
||||
"rLpAd4peHUMBPbVJASMYK5GTBUSwXRD9nx",
|
||||
// ...
|
||||
"rN9HWHPAftXC6xNxJRqgVr1HexpUi6FBUa",
|
||||
"rhwPfeEkeQh2vqoKGPBpPyS9nKmKZdpypu",
|
||||
"rKdNfPfrzfisDCPCqK67YhDLezuVKGKXNm",
|
||||
"rsn4NeGzMRvMn5ABQxmt9VNEkSknVneBK4",
|
||||
"rUSJGFH1kQnaKpoAhkArfyw6HZVe8GT5w3",
|
||||
"r3EYp6isx2Row5pu19C4Ujvp68oEEabhuA",
|
||||
"rGiYpnAn9DTXiM78CCJcYAuL6QHEDdazHA",
|
||||
"rVrRVeqqEJHAove5B9TqBAHEXBTzMi5eu",
|
||||
"rJbarThDXYXxtCgDxRoTCDf2NoYdgSjuVk",
|
||||
"rfuWNJ1TkQzoZZcc4K8wmtsUiGwURFbed1",
|
||||
"rpuTqebfbZZdKEUV3bjecoViNL4W4gepWZ",
|
||||
"r42ywHUco4C2AjgaSmYM7uX13Kbz6GdDKp",
|
||||
"rnWb45MLd5hQiB6Arr94DdY2z95quL7XNf",
|
||||
"rMukaQ87bfAeddcT16RtgS3RbFmaQWrSGu",
|
||||
"rN6dMHU51K9y8eVMhjQMsQVp5gPwt3eYYx",
|
||||
"rfRFyeJDNqpfZVFmjNj9tNzFVsCNAWKtNc",
|
||||
"rMoGSX48KrT31HKx9KfMSnYhjvRw3YYzQW",
|
||||
"rfTiEfbeVsYU7QEe1Zfogiz7h43x6ChKGC"
|
||||
]
|
||||
|
||||
function assert_helper(account_id, expected) {
|
||||
var keypair = seed.get_key(account_id);
|
||||
assert.strictEqual(keypair.get_address().to_json(),
|
||||
expected);
|
||||
function assert_helper(seed_json, address_or_nth, expected) {
|
||||
var seed = Seed.from_json(seed_json);
|
||||
var keypair = seed.get_key(address_or_nth, 500);
|
||||
assert.strictEqual(keypair.to_hex_pub(), expected);
|
||||
}
|
||||
for (var nth = 0; nth < first_nth_addresses.length; nth++) {
|
||||
var expected = first_nth_addresses[nth], looking_for;
|
||||
|
||||
for (var nth = 0; nth < test_data.length; nth++) {
|
||||
var seed_json = test_data[nth][0];
|
||||
var address = test_data[nth][1];
|
||||
var nth_for_seed = test_data[nth][2];
|
||||
var expected = test_data[nth][3];
|
||||
|
||||
//`seed.get_key($ripple_address)` is arguably an ill concieved feature
|
||||
// as it needs to generate `nth` many keypairs and generate hashed public
|
||||
// keys (addresses) for equality tests ??
|
||||
// Would need remote.set_secret(address, private_key_not_seed) ??
|
||||
assert_helper((looking_for = expected), expected)
|
||||
assert_helper(seed_json, address, expected);
|
||||
|
||||
// This isn't too bad as it only needs to generate one keypair `seq`
|
||||
assert_helper((looking_for = nth), expected)
|
||||
assert_helper(seed_json, nth_for_seed, expected);
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
it('should return the key_pair for a valid account and secret pair', function() {
|
||||
var address = 'r3GgMwvgvP8h4yVWvjH1dPZNvC37TjzBBE';
|
||||
var seed = Seed.from_json('shsWGZcmZz6YsWWmcnpfr6fLTdtFV');
|
||||
var keyPair = seed.get_key(address);
|
||||
assert.strictEqual(keyPair.get_address().to_json(), address);
|
||||
assert.strictEqual(keyPair.to_hex_pub(), '02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8');
|
||||
});
|
||||
|
||||
it('should not find a KeyPair for a secret that does not belong to the given account', function() {
|
||||
var address = 'r3GgMwvgvP8h4yVWvjH1dPZNvC37TjzBBE';
|
||||
var secret = 'snoPBrXtMeMyMHUVTgbuqAfg1SUTb';
|
||||
var seed = Seed.from_json('snoPBrXtMeMyMHUVTgbuqAfg1SUTb');
|
||||
try {
|
||||
seed.get_key(address);
|
||||
assert(false, 'should throw an error');
|
||||
} catch(e) {
|
||||
assert.strictEqual(e.message, 'Too many loops looking for KeyPair yielding '+address+' from '+secret);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
// vim:sw=2:sts=2:ts=8:et
|
||||
|
||||
@@ -2,6 +2,7 @@ var utils = require('./testutils');
|
||||
var assert = require('assert');
|
||||
var SerializedObject = utils.load_module('serializedobject').SerializedObject;
|
||||
var types = utils.load_module('serializedtypes');
|
||||
var amountConstants = require('../src/js/ripple/amount').consts;
|
||||
var BigInteger = require('../src/js/jsbn/jsbn').BigInteger;
|
||||
|
||||
var config = require('./testutils').get_config();
|
||||
@@ -550,6 +551,11 @@ describe('Serialized types', function() {
|
||||
});
|
||||
assert.strictEqual(so.to_hex(), 'D5438D7EA4C68000015841551A748AD23FEFFFFFFFEA028000000000E4FE687C90257D3D2D694C8531CDEECBE84F3367');
|
||||
});
|
||||
it('Serialize max_value/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Amount.serialize(so, amountConstants.max_value+'/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
assert.strictEqual(so.to_hex(), 'EC6386F26FC0FFFF0000000000000000000000005553440000000000B5F762798A53D543A014CAF8B297CFF8F2F937E8');
|
||||
});
|
||||
it('Parse 1 XRP', function () {
|
||||
var so = new SerializedObject('4000000000000001');
|
||||
assert.strictEqual(types.Amount.parse(so).to_json(), '1');
|
||||
@@ -582,6 +588,10 @@ describe('Serialized types', function() {
|
||||
var so = new SerializedObject('94838D7EA4C680000000000000000000000000005553440000000000B5F762798A53D543A014CAF8B297CFF8F2F937E8');
|
||||
assert.strictEqual(types.Amount.parse(so).to_text_full(), '-1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
});
|
||||
it('Parse max_value/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', function () {
|
||||
var so = new SerializedObject('EC6386F26FC0FFFF0000000000000000000000005553440000000000B5F762798A53D543A014CAF8B297CFF8F2F937E8');
|
||||
assert.strictEqual(types.Amount.parse(so).to_text_full(), amountConstants.max_value+'/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Account', function() {
|
||||
|
||||
@@ -84,16 +84,16 @@ describe('Server', function() {
|
||||
var server = new Server(new Remote(), 'wss://localhost:5006');
|
||||
|
||||
var ledger = {
|
||||
'type': 'ledgerClosed',
|
||||
'fee_base': 10,
|
||||
'fee_ref': 10,
|
||||
'ledger_hash': 'D29E1F2A2617A88E9DAA14F468B169E6875092ECA0B3B1FA2BE1BC5524DE7CB2',
|
||||
'ledger_index': 7035609,
|
||||
'ledger_time': 455327690,
|
||||
'reserve_base': 20000000,
|
||||
'reserve_inc': 5000000,
|
||||
'txn_count': 1,
|
||||
'validated_ledgers': '32570-7035609'
|
||||
type: 'ledgerClosed',
|
||||
fee_base: 10,
|
||||
fee_ref: 10,
|
||||
ledger_hash: 'D29E1F2A2617A88E9DAA14F468B169E6875092ECA0B3B1FA2BE1BC5524DE7CB2',
|
||||
ledger_index: 7035609,
|
||||
ledger_time: 455327690,
|
||||
reserve_base: 20000000,
|
||||
reserve_inc: 5000000,
|
||||
txn_count: 1,
|
||||
validated_ledgers: '32570-7035609'
|
||||
};
|
||||
|
||||
server._updateScore = function(type, data) {
|
||||
@@ -125,8 +125,8 @@ describe('Server', function() {
|
||||
var server = new Server(new Remote(), 'wss://localhost:5006');
|
||||
|
||||
var load = {
|
||||
'fee_base': 10,
|
||||
'fee_ref': 10
|
||||
fee_base: 10,
|
||||
fee_ref: 10
|
||||
};
|
||||
|
||||
server._updateScore = function(type, data) {
|
||||
@@ -361,22 +361,22 @@ describe('Server', function() {
|
||||
});
|
||||
|
||||
ws.send(JSON.stringify({
|
||||
'id': 0,
|
||||
'status': 'success',
|
||||
'type': 'response',
|
||||
'result': {
|
||||
'fee_base': 10,
|
||||
'fee_ref': 10,
|
||||
'ledger_hash': '1838539EE12463C36F2C53B079D807C697E3D93A1936B717E565A4A912E11776',
|
||||
'ledger_index': 7053695,
|
||||
'ledger_time': 455414390,
|
||||
'load_base': 256,
|
||||
'load_factor': 256,
|
||||
'random': 'E56C9154D9BE94D49C581179356C2E084E16D18D74E8B09093F2D61207625E6A',
|
||||
'reserve_base': 20000000,
|
||||
'reserve_inc': 5000000,
|
||||
'server_status': 'full',
|
||||
'validated_ledgers': '32570-7053695'
|
||||
id: 0,
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
result: {
|
||||
fee_base: 10,
|
||||
fee_ref: 10,
|
||||
ledger_hash: '1838539EE12463C36F2C53B079D807C697E3D93A1936B717E565A4A912E11776',
|
||||
ledger_index: 7053695,
|
||||
ledger_time: 455414390,
|
||||
load_base: 256,
|
||||
load_factor: 256,
|
||||
random: 'E56C9154D9BE94D49C581179356C2E084E16D18D74E8B09093F2D61207625E6A',
|
||||
reserve_base: 20000000,
|
||||
reserve_inc: 5000000,
|
||||
server_status: 'full',
|
||||
validated_ledgers: '32570-7053695'
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -411,17 +411,54 @@ describe('Server', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Connect - prior WebSocket connection exists', function(done) {
|
||||
it.skip('Connect - prior WebSocket connection exists', function(done) {
|
||||
var wss = new ws.Server({ port: 5748 });
|
||||
|
||||
wss.once('connection', function(ws) {
|
||||
ws.once('message', function(message) {
|
||||
var m = JSON.parse(message);
|
||||
|
||||
assert.deepEqual(m, {
|
||||
command: 'subscribe',
|
||||
id: 0,
|
||||
streams: [ 'ledger', 'server' ]
|
||||
});
|
||||
|
||||
ws.send(JSON.stringify({
|
||||
id: 0,
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
result: {
|
||||
fee_base: 10,
|
||||
fee_ref: 10,
|
||||
ledger_hash: '1838539EE12463C36F2C53B079D807C697E3D93A1936B717E565A4A912E11776',
|
||||
ledger_index: 7053695,
|
||||
ledger_time: 455414390,
|
||||
load_base: 256,
|
||||
load_factor: 256,
|
||||
random: 'E56C9154D9BE94D49C581179356C2E084E16D18D74E8B09093F2D61207625E6A',
|
||||
reserve_base: 20000000,
|
||||
reserve_inc: 5000000,
|
||||
server_status: 'full',
|
||||
validated_ledgers: '32570-7053695'
|
||||
}
|
||||
}));
|
||||
|
||||
wss.close();
|
||||
});
|
||||
});
|
||||
|
||||
var server = new Server(new Remote(), 'ws://localhost:5748');
|
||||
server._connected = false;
|
||||
|
||||
server._ws = {
|
||||
close: function() {
|
||||
server.once('connect', function() {
|
||||
server.once('disconnect', function() {
|
||||
done();
|
||||
}
|
||||
};
|
||||
});
|
||||
server.disconnect();
|
||||
});
|
||||
|
||||
server.connect();
|
||||
server.connect();
|
||||
});
|
||||
|
||||
it('Connect - no WebSocket constructor', function() {
|
||||
@@ -441,10 +478,107 @@ describe('Server', function() {
|
||||
Server.websocketConstructor = websocketConstructor;
|
||||
});
|
||||
|
||||
it('Connect - partial history disabled', function(done) {
|
||||
var wss = new ws.Server({ port: 5748 });
|
||||
|
||||
wss.once('connection', function(ws) {
|
||||
ws.once('message', function(message) {
|
||||
var m = JSON.parse(message);
|
||||
|
||||
assert.deepEqual(m, {
|
||||
command: 'subscribe',
|
||||
id: 0,
|
||||
streams: [ 'ledger', 'server' ]
|
||||
});
|
||||
|
||||
ws.send(JSON.stringify({
|
||||
id: 0,
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
result: {
|
||||
fee_base: 10,
|
||||
fee_ref: 10,
|
||||
ledger_hash: '1838539EE12463C36F2C53B079D807C697E3D93A1936B717E565A4A912E11776',
|
||||
ledger_index: 7053695,
|
||||
ledger_time: 455414390,
|
||||
load_base: 256,
|
||||
load_factor: 256,
|
||||
random: 'E56C9154D9BE94D49C581179356C2E084E16D18D74E8B09093F2D61207625E6A',
|
||||
reserve_base: 20000000,
|
||||
reserve_inc: 5000000,
|
||||
server_status: 'syncing',
|
||||
validated_ledgers: '3175520-3176615'
|
||||
}
|
||||
}));
|
||||
|
||||
wss.close();
|
||||
});
|
||||
});
|
||||
|
||||
var server = new Server(new Remote({ allow_partial_history: false }), 'ws://localhost:5748');
|
||||
|
||||
server.reconnect = function() {
|
||||
setImmediate(function() {
|
||||
done();
|
||||
});
|
||||
};
|
||||
|
||||
server.once('connect', function() {
|
||||
assert(false, 'Should not connect');
|
||||
});
|
||||
|
||||
server.connect();
|
||||
});
|
||||
|
||||
it('Connect - syncing state', function(done) {
|
||||
// Test that fee and load defaults are not overwritten by
|
||||
// undefined properties on server subscribe response
|
||||
var wss = new ws.Server({ port: 5748 });
|
||||
|
||||
wss.once('connection', function(ws) {
|
||||
ws.once('message', function(message) {
|
||||
var m = JSON.parse(message);
|
||||
|
||||
assert.deepEqual(m, {
|
||||
command: 'subscribe',
|
||||
id: 0,
|
||||
streams: [ 'ledger', 'server' ]
|
||||
});
|
||||
|
||||
ws.send(JSON.stringify({
|
||||
id: 0,
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
result: {
|
||||
load_base: 256,
|
||||
load_factor: 256,
|
||||
server_status: 'syncing'
|
||||
}
|
||||
}));
|
||||
|
||||
wss.close();
|
||||
});
|
||||
});
|
||||
|
||||
var server = new Server(new Remote(), 'ws://localhost:5748');
|
||||
|
||||
server.once('connect', function() {
|
||||
assert(server.isConnected());
|
||||
assert.strictEqual(server._load_base, 256);
|
||||
assert.strictEqual(server._load_factor, 256);
|
||||
assert.strictEqual(server._fee_base, 10);
|
||||
assert.strictEqual(server._fee_ref, 10);
|
||||
done();
|
||||
});
|
||||
|
||||
server.connect();
|
||||
});
|
||||
|
||||
|
||||
it('Reconnect', function(done) {
|
||||
var server = new Server(new Remote(), 'ws://localhost:5748');
|
||||
server._connected = true;
|
||||
|
||||
server._shouldConnect = true;
|
||||
server._ws = { };
|
||||
|
||||
var disconnected = false;
|
||||
@@ -512,22 +646,22 @@ describe('Server', function() {
|
||||
});
|
||||
|
||||
ws.send(JSON.stringify({
|
||||
'id': 0,
|
||||
'status': 'success',
|
||||
'type': 'response',
|
||||
'result': {
|
||||
'fee_base': 10,
|
||||
'fee_ref': 10,
|
||||
'ledger_hash': '1838539EE12463C36F2C53B079D807C697E3D93A1936B717E565A4A912E11776',
|
||||
'ledger_index': 7053695,
|
||||
'ledger_time': 455414390,
|
||||
'load_base': 256,
|
||||
'load_factor': 256,
|
||||
'random': 'E56C9154D9BE94D49C581179356C2E084E16D18D74E8B09093F2D61207625E6A',
|
||||
'reserve_base': 20000000,
|
||||
'reserve_inc': 5000000,
|
||||
'server_status': 'full',
|
||||
'validated_ledgers': '32570-7053695'
|
||||
id: 0,
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
result: {
|
||||
fee_base: 10,
|
||||
fee_ref: 10,
|
||||
ledger_hash: '1838539EE12463C36F2C53B079D807C697E3D93A1936B717E565A4A912E11776',
|
||||
ledger_index: 7053695,
|
||||
ledger_time: 455414390,
|
||||
load_base: 256,
|
||||
load_factor: 256,
|
||||
random: 'E56C9154D9BE94D49C581179356C2E084E16D18D74E8B09093F2D61207625E6A',
|
||||
reserve_base: 20000000,
|
||||
reserve_inc: 5000000,
|
||||
server_status: 'full',
|
||||
validated_ledgers: '32570-7053695'
|
||||
}
|
||||
}));
|
||||
});
|
||||
@@ -535,10 +669,13 @@ describe('Server', function() {
|
||||
|
||||
var server = new Server(new Remote(), 'ws://localhost:5748');
|
||||
|
||||
server.once('disconnect', function() {
|
||||
done();
|
||||
});
|
||||
|
||||
server.once('connect', function() {
|
||||
server._retryConnect = function(){
|
||||
wss.close();
|
||||
done();
|
||||
};
|
||||
server._ws.emit('error', new Error());
|
||||
});
|
||||
@@ -642,7 +779,29 @@ describe('Server', function() {
|
||||
type: 'response',
|
||||
status: 'success',
|
||||
result: {
|
||||
test: 'property'
|
||||
info: {
|
||||
build_version: "0.25.2-rc1",
|
||||
complete_ledgers: "32570-7623483",
|
||||
hostid: "MAC",
|
||||
io_latency_ms: 1,
|
||||
last_close: {
|
||||
converge_time_s: 2.052,
|
||||
proposers: 5
|
||||
},
|
||||
load_factor: 1,
|
||||
peers: 50,
|
||||
pubkey_node: "n94pSqypSfddzAVj9qoezHyUoetsrMnwgNuBqRJ3WHvM8aMMf7rW",
|
||||
server_state: "full",
|
||||
validated_ledger: {
|
||||
age: 5,
|
||||
base_fee_xrp: 0.00001,
|
||||
hash: "AB575193C623179078BE7CC42965FD4262EE8611D1CE7F839CEEBFFEF4B653B6",
|
||||
reserve_base_xrp: 20,
|
||||
reserve_inc_xrp: 5,
|
||||
seq: 7623483
|
||||
},
|
||||
validation_quorum: 3
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -841,8 +1000,6 @@ describe('Server', function() {
|
||||
server._ws = { readyState: 1 };
|
||||
|
||||
assert(!server._isConnected());
|
||||
assert(!server._isConnected({ message: { command: 'ping' } }));
|
||||
assert(server._isConnected({ message: { command: 'subscribe' } }));
|
||||
|
||||
server._connected = true;
|
||||
|
||||
@@ -885,4 +1042,100 @@ describe('Server', function() {
|
||||
server._reserve_inc = 5000000;
|
||||
assert.strictEqual(server._reserve().to_json(), '20000000');
|
||||
});
|
||||
|
||||
it('Cache hostid', function(done) {
|
||||
var wss = new ws.Server({ port: 5748 });
|
||||
|
||||
wss.once('connection', function(ws) {
|
||||
function sendServerInfo(message) {
|
||||
ws.send(JSON.stringify({
|
||||
id: message.id,
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
result: {
|
||||
info: {
|
||||
build_version: "0.25.2-rc1",
|
||||
complete_ledgers: "32570-7623483",
|
||||
hostid: "MAC",
|
||||
io_latency_ms: 1,
|
||||
last_close: {
|
||||
converge_time_s: 2.052,
|
||||
proposers: 5
|
||||
},
|
||||
load_factor: 1,
|
||||
peers: 50,
|
||||
pubkey_node: "n94pSqypSfddzAVj9qoezHyUoetsrMnwgNuBqRJ3WHvM8aMMf7rW",
|
||||
server_state: "full",
|
||||
validated_ledger: {
|
||||
age: 5,
|
||||
base_fee_xrp: 0.00001,
|
||||
hash: "AB575193C623179078BE7CC42965FD4262EE8611D1CE7F839CEEBFFEF4B653B6",
|
||||
reserve_base_xrp: 20,
|
||||
reserve_inc_xrp: 5,
|
||||
seq: 7623483
|
||||
},
|
||||
validation_quorum: 3
|
||||
}
|
||||
}
|
||||
}));
|
||||
};
|
||||
|
||||
function sendSubscribe(message) {
|
||||
ws.send(JSON.stringify({
|
||||
id: message.id,
|
||||
status: 'success',
|
||||
type: 'response',
|
||||
result: {
|
||||
fee_base: 10,
|
||||
fee_ref: 10,
|
||||
ledger_hash: '1838539EE12463C36F2C53B079D807C697E3D93A1936B717E565A4A912E11776',
|
||||
ledger_index: 7053695,
|
||||
ledger_time: 455414390,
|
||||
load_base: 256,
|
||||
load_factor: 256,
|
||||
random: 'E56C9154D9BE94D49C581179356C2E084E16D18D74E8B09093F2D61207625E6A',
|
||||
reserve_base: 20000000,
|
||||
reserve_inc: 5000000,
|
||||
server_status: 'full',
|
||||
validated_ledgers: '32570-7053695'
|
||||
}
|
||||
}));
|
||||
};
|
||||
|
||||
ws.on('message', function(message) {
|
||||
var m = JSON.parse(message);
|
||||
|
||||
switch (m.command) {
|
||||
case 'subscribe':
|
||||
assert.strictEqual(m.command, 'subscribe');
|
||||
assert.deepEqual(m.streams, [ 'ledger', 'server' ]);
|
||||
sendSubscribe(m);
|
||||
break;
|
||||
case 'server_info':
|
||||
assert.strictEqual(m.command, 'server_info');
|
||||
sendServerInfo(m);
|
||||
wss.close();
|
||||
break;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var server = new Server(new Remote(), 'ws://localhost:5748');
|
||||
|
||||
server.once('connect', function() {
|
||||
var receivedSubscribe = false;
|
||||
|
||||
server.once('response_server_info', function() {
|
||||
receivedSubscribe = true;
|
||||
});
|
||||
|
||||
server.once('disconnect', function() {
|
||||
assert(receivedSubscribe);
|
||||
assert.strictEqual(server.getServerID(), 'ws://localhost:5748 (n94pSqypSfddzAVj9qoezHyUoetsrMnwgNuBqRJ3WHvM8aMMf7rW)');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
server.connect();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -26,8 +26,9 @@ describe('Signing', function() {
|
||||
assert(_isNaN(new Seed().parse_json('').to_json()));
|
||||
});
|
||||
it('hex string', function() {
|
||||
// 32 0s is a valid hex repr of seed bytes
|
||||
var str = new Array(33).join('0');
|
||||
assert(_isNaN(new Seed().parse_json(str).to_json()));
|
||||
assert.strictEqual((new Seed().parse_json(str).to_json()), 'sp6JS7f14BuwFY8Mw6bTtLKWauoUs');
|
||||
});
|
||||
it('passphrase', function() {
|
||||
var str = new Array(60).join('0');
|
||||
|
||||
@@ -229,6 +229,11 @@ describe('Transaction', function() {
|
||||
assert.strictEqual(transaction._computeFee(), '72');
|
||||
});
|
||||
|
||||
it('Compute fee, no remote', function() {
|
||||
var transaction = new Transaction();
|
||||
assert.strictEqual(transaction._computeFee(10), void(0));
|
||||
});
|
||||
|
||||
it('Compute fee - no connected server', function() {
|
||||
var remote = new Remote();
|
||||
|
||||
@@ -292,9 +297,7 @@ describe('Transaction', function() {
|
||||
var s3 = new Server(remote, 'wss://s-west.ripple.com:443');
|
||||
s3._connected = true;
|
||||
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
s3._load_factor = (256 * 7) + 1;
|
||||
// Is this ever possible? <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
var s4 = new Server(remote, 'wss://s-west.ripple.com:443');
|
||||
s4._connected = true;
|
||||
@@ -373,6 +376,16 @@ describe('Transaction', function() {
|
||||
done();
|
||||
});
|
||||
|
||||
it('Complete transaction, local signing, no remote', function(done) {
|
||||
var transaction = new Transaction();
|
||||
transaction._secret = 'sh2pTicynUEG46jjR4EoexHcQEoij';
|
||||
transaction.tx_json.Account = 'rMWwx3Ma16HnqSd4H6saPisihX9aKpXxHJ';
|
||||
|
||||
assert(transaction.complete());
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it('Complete transaction - untrusted', function(done) {
|
||||
var remote = new Remote();
|
||||
var transaction = new Transaction(remote);
|
||||
@@ -813,11 +826,29 @@ describe('Transaction', function() {
|
||||
assert.strictEqual(transaction.tx_json.LastLedgerSequence, void(0));
|
||||
assert(!transaction._setLastLedger);
|
||||
|
||||
transaction.lastLedger(NaN);
|
||||
assert.strictEqual(transaction.tx_json.LastLedgerSequence, void(0));
|
||||
assert(!transaction._setLastLedger);
|
||||
|
||||
transaction.lastLedger(12);
|
||||
assert.strictEqual(transaction.tx_json.LastLedgerSequence, 12);
|
||||
assert(transaction._setLastLedger);
|
||||
});
|
||||
|
||||
it('Set Max Fee', function() {
|
||||
var transaction = new Transaction();
|
||||
|
||||
transaction.maxFee('a');
|
||||
assert(!transaction._setMaxFee);
|
||||
|
||||
transaction.maxFee(NaN);
|
||||
assert(!transaction._setMaxFee);
|
||||
|
||||
transaction.maxFee(1000);
|
||||
assert.strictEqual(transaction._maxFee, 1000);
|
||||
assert.strictEqual(transaction._setMaxFee, true);
|
||||
});
|
||||
|
||||
it('Rewrite transaction path', function() {
|
||||
var transaction = new Transaction();
|
||||
|
||||
@@ -1017,6 +1048,53 @@ describe('Transaction', function() {
|
||||
transaction.setFlags('test');
|
||||
});
|
||||
|
||||
it('Add Memo', function() {
|
||||
var transaction = new Transaction();
|
||||
transaction.tx_json.TransactionType = 'Payment';
|
||||
|
||||
transaction.addMemo('testkey', 'testvalue');
|
||||
transaction.addMemo('testkey2', 'testvalue2');
|
||||
transaction.addMemo('testkey3');
|
||||
transaction.addMemo(void(0), 'testvalue4');
|
||||
|
||||
var expected = [
|
||||
{ Memo: {
|
||||
MemoType: new Buffer('testkey').toString('hex'),
|
||||
MemoData: new Buffer('testvalue').toString('hex')
|
||||
}},
|
||||
{ Memo: {
|
||||
MemoType: new Buffer('testkey2').toString('hex'),
|
||||
MemoData: new Buffer('testvalue2').toString('hex')
|
||||
}},
|
||||
{ Memo: {
|
||||
MemoType: new Buffer('testkey3').toString('hex')
|
||||
}},
|
||||
{ Memo: {
|
||||
MemoData: new Buffer('testvalue4').toString('hex')
|
||||
} }
|
||||
];
|
||||
|
||||
assert.deepEqual(transaction.tx_json.Memos, expected);
|
||||
});
|
||||
|
||||
it('Add Memo - invalid MemoType', function() {
|
||||
var transaction = new Transaction();
|
||||
transaction.tx_json.TransactionType = 'Payment';
|
||||
|
||||
assert.throws(function() {
|
||||
transaction.addMemo(1);
|
||||
}, /^Error: MemoType must be a string$/);
|
||||
});
|
||||
|
||||
it('Add Memo - invalid MemoData', function() {
|
||||
var transaction = new Transaction();
|
||||
transaction.tx_json.TransactionType = 'Payment';
|
||||
|
||||
assert.throws(function() {
|
||||
transaction.addMemo('key', 1);
|
||||
}, /^Error: MemoData must be a string$/);
|
||||
});
|
||||
|
||||
it('Construct AccountSet transaction', function() {
|
||||
var transaction = new Transaction().accountSet('rsLEU1TPdCJPPysqhWYw9jD97xtG5WqSJm');
|
||||
|
||||
@@ -1456,6 +1534,18 @@ describe('Transaction', function() {
|
||||
transaction.submit(submitCallback);
|
||||
});
|
||||
|
||||
it('Submit transaction - submission error, no remote', function(done) {
|
||||
var transaction = new Transaction();
|
||||
|
||||
transaction.once('error', function(error) {
|
||||
assert(error);
|
||||
assert.strictEqual(error.message, 'No remote found');
|
||||
done();
|
||||
});
|
||||
|
||||
transaction.submit();
|
||||
});
|
||||
|
||||
it('Submit transaction - invalid account', function(done) {
|
||||
var remote = new Remote();
|
||||
var transaction = new Transaction(remote).accountSet('r36xtKNKR43SeXnGn7kN4r4JdQzcrkqpWe');
|
||||
|
||||
@@ -19,6 +19,8 @@ var exampleData = {
|
||||
masterkey : 'ssize4HrSYZShMWBtK6BhALGEk8VH',
|
||||
email_token : '77825040-9096-4695-9cbc-76720f6a8649',
|
||||
activateLink : 'https://staging.ripple.com/client/#/register/activate/',
|
||||
device_id : "ac1b6f6dbca98190eb9687ba06f0e066",
|
||||
identity_id : "17fddb71-a5c2-44ce-8b50-4b381339d4f2",
|
||||
blob: {
|
||||
url: 'https://id.staging.ripple.com',
|
||||
id: 'ef203d3e76552c0592384f909e6f61f1d1f02f61f07643ce015d8b0c9710dd2f',
|
||||
@@ -102,13 +104,31 @@ var recoverRes = {
|
||||
result: 'success'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var getProfileRes = {
|
||||
"result":"success",
|
||||
"addresses":[],
|
||||
"attributes":[{
|
||||
"attribute_id":"4034e477-ffc9-48c4-bcbc-058293f081d8",
|
||||
"identity_id":"17fddb71-a5c2-44ce-8b50-4b381339d4f2",
|
||||
"name":"email",
|
||||
"type":"default",
|
||||
"domain":null,
|
||||
"value":"example@example.com",
|
||||
"visibility":"public",
|
||||
"updated":null
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
var blob = new Blob();
|
||||
blob.url = exampleData.blob.url;
|
||||
blob.id = exampleData.blob.id;
|
||||
blob.key = exampleData.blob.key;
|
||||
blob.data = exampleData.blob.data;
|
||||
blob.revision = exampleData.blob.data.revision;
|
||||
blob.url = exampleData.blob.url;
|
||||
blob.id = exampleData.blob.id;
|
||||
blob.device_id = exampleData.device_id;
|
||||
blob.key = exampleData.blob.key;
|
||||
blob.identity_id = exampleData.blob.identity_id;
|
||||
blob.data = exampleData.blob.data;
|
||||
blob.revision = exampleData.blob.data.revision;
|
||||
|
||||
//must be set for self signed certs
|
||||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
||||
@@ -131,14 +151,12 @@ var mockDelete;
|
||||
|
||||
if (!online) {
|
||||
mockRippleTxt = nock('https://ripple.com')
|
||||
.persist()
|
||||
.get('/ripple.txt')
|
||||
.reply(200, rippleTxtRes, {
|
||||
'Content-Type': 'text/plain'
|
||||
});
|
||||
|
||||
mockRippleTxt2 = nock('https://' + exampleData.domain)
|
||||
.persist()
|
||||
.get('/ripple.txt')
|
||||
.reply(200, rippleTxtRes, {
|
||||
'Content-Type': 'text/plain'
|
||||
@@ -151,21 +169,21 @@ if (!online) {
|
||||
'Content-Type': 'text/plain'
|
||||
});
|
||||
|
||||
mockRegister = nock('https://id.staging.ripple.com').persist();
|
||||
mockRegister = nock('https://id.staging.ripple.com');
|
||||
mockRegister.filteringPath(/(v1\/user\?signature(.+))/g, 'register/')
|
||||
.post('/register/')
|
||||
.reply(200, { result: 'error', message: 'User already exists' }, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
mockDelete = nock('https://id.staging.ripple.com').persist();
|
||||
mockDelete = nock('https://id.staging.ripple.com');
|
||||
mockDelete.filteringPath(/(v1\/user\/(.+))/g, 'delete/')
|
||||
.delete('/delete/')
|
||||
.reply(200, { result: 'success' }, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
mockBlob = nock('https://id.staging.ripple.com').persist();
|
||||
mockBlob = nock('https://id.staging.ripple.com');
|
||||
mockBlob.get('/v1/authinfo?domain=' + exampleData.domain + '&username=' + exampleData.username.toLowerCase())
|
||||
.reply(200, JSON.stringify(authInfoRes.body), {
|
||||
'Content-Type': 'application/json'
|
||||
@@ -177,52 +195,46 @@ if (!online) {
|
||||
});
|
||||
|
||||
mockBlob.filteringPath(/(blob\/.+)/g, 'blob/')
|
||||
.persist()
|
||||
.get('/v1/blob/')
|
||||
.reply(200, JSON.stringify(blobRes.body), {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
mockRename = nock('https://id.staging.ripple.com/v1/user/').persist();
|
||||
mockRename = nock('https://id.staging.ripple.com/v1/user/');
|
||||
mockRename.filteringPath(/((.+)\/rename(.+))/g, 'rename/')
|
||||
.post('rename/')
|
||||
.reply(200, {result:'success',message:'rename'}, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
mockUpdate = nock('https://id.staging.ripple.com/v1/user/').persist();
|
||||
mockUpdate.filteringPath(/((.+)\/update(.+))/g, 'update/')
|
||||
mockUpdate = nock('https://id.staging.ripple.com/v1/user/');
|
||||
mockUpdate.filteringPath(/((.+)\/updatekeys(.+))/g, 'update/')
|
||||
.post('update/')
|
||||
.reply(200, {result:'success',message:'updateKeys'}, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
mockRecover = nock('https://id.staging.ripple.com/').persist();
|
||||
mockRecover = nock('https://id.staging.ripple.com/')
|
||||
mockRecover.filteringPath(/((.+)user\/recov\/(.+))/g, 'recov/')
|
||||
.get('recov/')
|
||||
.reply(200, recoverRes.body, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
mockVerify = nock('https://id.staging.ripple.com/v1/user/').persist();
|
||||
|
||||
mockVerify = nock('https://id.staging.ripple.com/v1/user/');
|
||||
mockVerify.filteringPath(/((.+)\/verify(.+))/g, 'verify/')
|
||||
.get('verify/')
|
||||
.reply(200, {result:'error', message:'invalid token'}, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
mockEmail = nock('https://id.staging.ripple.com/v1/user').persist();
|
||||
mockEmail = nock('https://id.staging.ripple.com/v1/user');
|
||||
mockEmail.filteringPath(/((.+)\/email(.+))/g, 'email/')
|
||||
.post('email/')
|
||||
.reply(200, {result:'success'}, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
mockProfile = nock('https://id.staging.ripple.com/v1/user').persist();
|
||||
mockProfile.filteringPath(/((.+)\/profile(.+))/g, 'profile/')
|
||||
.post('profile/')
|
||||
.reply(200, {result:'success'}, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
}
|
||||
|
||||
describe('Ripple Txt', function () {
|
||||
@@ -289,7 +301,7 @@ describe('VaultClient', function () {
|
||||
describe('#login', function() {
|
||||
it('with username and password should retrive the blob, crypt key, and id', function(done) {
|
||||
this.timeout(10000);
|
||||
client.login(exampleData.username, exampleData.password, function(err, resp) {
|
||||
client.login(exampleData.username, exampleData.password, exampleData.device_id, function(err, resp) {
|
||||
if (online) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(typeof resp, 'object');
|
||||
@@ -313,7 +325,7 @@ describe('VaultClient', function () {
|
||||
describe('#relogin', function() {
|
||||
it('should retrieve the decrypted blob with blob vault url, id, and crypt key', function(done) {
|
||||
this.timeout(10000);
|
||||
client.relogin(exampleData.blob.url, exampleData.id, exampleData.crypt, function(err, resp) {
|
||||
client.relogin(exampleData.blob.url, exampleData.id, exampleData.crypt, exampleData.device_id, function(err, resp) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(typeof resp, 'object');
|
||||
assert(resp.blob instanceof Blob);
|
||||
@@ -345,7 +357,7 @@ describe('VaultClient', function () {
|
||||
describe('#loginAndUnlock', function () {
|
||||
it('should get the decrypted blob and decrypted secret given name and password', function (done) {
|
||||
this.timeout(10000);
|
||||
client.loginAndUnlock(exampleData.username, exampleData.password, function(err, resp) {
|
||||
client.loginAndUnlock(exampleData.username, exampleData.password, exampleData.device_id, function(err, resp) {
|
||||
if (online) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(typeof resp, 'object');
|
||||
@@ -416,6 +428,7 @@ describe('VaultClient', function () {
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
describe('#updateProfile', function () {
|
||||
it('should update profile parameters associated with a blob', function (done) {
|
||||
this.timeout(10000);
|
||||
@@ -439,7 +452,7 @@ describe('VaultClient', function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
*/
|
||||
|
||||
});
|
||||
|
||||
@@ -454,7 +467,7 @@ describe('Blob', function () {
|
||||
if (online) {
|
||||
this.timeout(10000);
|
||||
|
||||
client.login(exampleData.username, exampleData.password, function(err, res) {
|
||||
client.login(exampleData.username, exampleData.password, exampleData.device_id, function(err, res) {
|
||||
resp = res;
|
||||
blob = res.blob;
|
||||
done();
|
||||
@@ -462,6 +475,7 @@ describe('Blob', function () {
|
||||
} else {
|
||||
|
||||
mockBlob.filteringPath(/(blob\/.+)/g, 'blob/')
|
||||
.persist()
|
||||
.post('/v1/blob/')
|
||||
.reply(200, {result:'success'}, {
|
||||
'Content-Type': 'application/json'
|
||||
@@ -689,6 +703,145 @@ describe('Blob', function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('identityVault', function() {
|
||||
it('#identity - Get Attestation', function (done) {
|
||||
var options = {
|
||||
url : blob.url,
|
||||
auth_secret : blob.data.auth_secret,
|
||||
blob_id : blob.id,
|
||||
};
|
||||
|
||||
options.type = 'identity';
|
||||
|
||||
nock('https://id.staging.ripple.com')
|
||||
.filteringPath(/(v1\/attestation\/identity(.+))/g, '')
|
||||
.post('/')
|
||||
.reply(200, {
|
||||
result: 'success',
|
||||
status: 'verified',
|
||||
attestation: 'eyJ6IjoieiJ9.eyJ6IjoieiJ9.sig',
|
||||
blinded:'eyJ6IjoieiJ9.eyJ6IjoieiJ9.sig'
|
||||
}, {'Content-Type': 'application/json'});
|
||||
|
||||
client.getAttestation(options, function(err, resp) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(resp.result, 'success');
|
||||
assert.strictEqual(typeof resp.attestation, 'string');
|
||||
assert.strictEqual(typeof resp.blinded, 'string');
|
||||
assert.deepEqual(resp.decoded, {"header":{"z":"z"},"payload":{"z":"z"},"signature":"sig"})
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('#identity - Update Attestation', function (done) {
|
||||
|
||||
var options = {
|
||||
url : blob.url,
|
||||
auth_secret : blob.data.auth_secret,
|
||||
blob_id : blob.id,
|
||||
};
|
||||
|
||||
options.type = 'identity';
|
||||
|
||||
nock('https://id.staging.ripple.com')
|
||||
.filteringPath(/(v1\/attestation\/identity\/update(.+))/g, '')
|
||||
.post('/')
|
||||
.reply(200, {
|
||||
result: 'success',
|
||||
status: 'verified',
|
||||
attestation: 'eyJ6IjoieiJ9.eyJ6IjoieiJ9.sig',
|
||||
blinded:'eyJ6IjoieiJ9.eyJ6IjoieiJ9.sig'
|
||||
}, {'Content-Type': 'application/json'});
|
||||
|
||||
client.updateAttestation(options, function(err, resp) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(resp.result, 'success');
|
||||
assert.strictEqual(typeof resp.attestation, 'string');
|
||||
assert.strictEqual(typeof resp.blinded, 'string');
|
||||
assert.deepEqual(resp.decoded, {"header":{"z":"z"},"payload":{"z":"z"},"signature":"sig"})
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('#identity - Get Attestation Summary', function (done) {
|
||||
|
||||
var options = {
|
||||
url : blob.url,
|
||||
auth_secret : blob.data.auth_secret,
|
||||
blob_id : blob.id,
|
||||
};
|
||||
|
||||
nock('https://id.staging.ripple.com')
|
||||
.filteringPath(/(v1\/attestation\/summary(.+))/g, '')
|
||||
.get('/')
|
||||
.reply(200, {
|
||||
result: 'success',
|
||||
attestation: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IjY2ZGI3MzgxIn0%3D.eyJwcm9maWxlX3ZlcmlmaWVkIjpmYWxzZSwiaWRlbnRpdHlfdmVyaWZpZWQiOmZhbHNlLCJpc3MiOiJodHRwczovL2lkLnJpcHBsZS5jb20iLCJzdWIiOiIwNDMzNTA0ZS0yYTRmLTQ1NjktODQwMi1lYWI2YTU0YTgzYjUiLCJleHAiOjE0MTI4MTc2NjksImlhdCI6MTQxMjgxNTgwOX0%3D.Jt14Y2TsM7fKqGWn0j16cPldlYqRr7%2F2dptBsdZuZhRGRTREO4TSpZZhBaU95WL3M9eXIfaoSs8f2pTOa%2BBGAYHZSZK4%2FLqeWdDH8zz8Bx9YFqGije1KmHQR%2FeoWSp1GTEfcq5Oho4nSHozHhGNN8IrDkl8woMvWb%2FE1938Y5Zl2vyv7wjlNUF4ND33XWzJkvQjzIK15uYfaB%2FUIsNW32udfHAdkigesdMDNm%2BRGBqHMDZeAMdVxzrDzE3m8oWKDMJXbcaLmk75COfJrLWYiZCHd7VcReyPEZegwEucetZJ9uDnoBcvw0%2B6hIRmjTN6Gy1eeBoJaiDYsWuOwInbIlw%3D%3D',
|
||||
}, {'Content-Type': 'application/json'});
|
||||
|
||||
client.getAttestationSummary(options, function(err, resp) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(resp.result, 'success');
|
||||
assert.strictEqual(typeof resp.attestation, 'string');
|
||||
assert.strictEqual(typeof resp.decoded.header, 'object');
|
||||
assert.strictEqual(typeof resp.decoded.payload, 'object');
|
||||
assert.strictEqual(typeof resp.decoded.signature, 'string');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
//only do these offline
|
||||
if (!online) {
|
||||
|
||||
describe('2FA', function() {
|
||||
|
||||
it('#2FA_set2FA', function (done) {
|
||||
blob.set2FA({masterkey:exampleData.masterkey}, function(err, resp){
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(typeof resp, 'object');
|
||||
assert.strictEqual(typeof resp.result, 'string');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('#2FA_get2FA', function (done) {
|
||||
blob.get2FA(function(err, resp) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(typeof resp, 'object');
|
||||
assert.strictEqual(typeof resp.result, 'string');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('#2FA_requestToken', function (done) {
|
||||
client.requestToken(exampleData.blob.url, exampleData.blob.id, function(err, resp){
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(typeof resp, 'object');
|
||||
assert.strictEqual(typeof resp.result, 'string');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('#2FA_verifyToken', function (done) {
|
||||
var options = {
|
||||
url : exampleData.blob.url,
|
||||
id : exampleData.blob.id,
|
||||
device_id : client.generateDeviceID(),
|
||||
token : "5555",
|
||||
remember_me : true
|
||||
}
|
||||
|
||||
client.verifyToken(options, function(err, resp){
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(typeof resp, 'object');
|
||||
assert.strictEqual(typeof resp.result, 'string');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (!online) {
|
||||
after(function () {
|
||||
|
||||
Reference in New Issue
Block a user