mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-14 17:45:48 +00:00
Compare commits
27 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bb79cf2a87 | ||
|
|
28451df1a8 | ||
|
|
38e288f62a | ||
|
|
905f908450 | ||
|
|
672171fd0c | ||
|
|
520660ecbc | ||
|
|
06acb5faf2 | ||
|
|
d43fa03f05 | ||
|
|
baed1aaf92 | ||
|
|
cc229e803c | ||
|
|
d6b1728c23 | ||
|
|
bc5dcc359c | ||
|
|
ced07e1d6b | ||
|
|
cffffd9591 | ||
|
|
b8766e263f | ||
|
|
fc426d5764 | ||
|
|
056d2381cd | ||
|
|
2932a0ec5f | ||
|
|
d3d85a3fcf | ||
|
|
7a1feaa897 | ||
|
|
5f3cf72cc6 | ||
|
|
cae980788e | ||
|
|
df763b8765 | ||
|
|
365085809e | ||
|
|
8f17873da2 | ||
|
|
b0cac776ee | ||
|
|
625dba4d85 |
117
Gulpfile.js
117
Gulpfile.js
@@ -68,45 +68,6 @@ 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())
|
||||
@@ -128,6 +89,66 @@ gulp.task('build-debug', [ 'concat-sjcl' ], function(callback) {
|
||||
}, callback);
|
||||
});
|
||||
|
||||
/**
|
||||
* Generate a WebPack external for a given unavailable module which replaces
|
||||
* that module's constructor with an error-thrower
|
||||
*/
|
||||
|
||||
function buildUseError(cons) {
|
||||
return 'var {<CONS>:function(){throw new Error("Class is unavailable in this build: <CONS>")}}'
|
||||
.replace(new RegExp('<CONS>', 'g'), cons);
|
||||
};
|
||||
|
||||
gulp.task('build-core', [ 'concat-sjcl' ], function(callback) {
|
||||
webpack({
|
||||
entry: [
|
||||
'./src/js/ripple/remote.js'
|
||||
],
|
||||
externals: [
|
||||
{
|
||||
'./transaction': buildUseError('Transaction'),
|
||||
'./orderbook': buildUseError('OrderBook'),
|
||||
'./account': buildUseError('Account'),
|
||||
'./serializedobject': buildUseError('SerializedObject')
|
||||
}
|
||||
],
|
||||
output: {
|
||||
library: 'ripple',
|
||||
path: './build/',
|
||||
filename: [ 'ripple-', '-core.js' ].join(pkg.version)
|
||||
},
|
||||
plugins: [
|
||||
new webpack.optimize.UglifyJsPlugin()
|
||||
]
|
||||
}, 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('bower', ['bower-build', 'bower-build-min', 'bower-build-debug', 'bower-version']);
|
||||
|
||||
gulp.task('lint', function() {
|
||||
gulp.src('src/js/ripple/*.js')
|
||||
.pipe(jshint())
|
||||
@@ -158,6 +179,20 @@ gulp.task('watch', function() {
|
||||
gulp.watch('src/js/ripple/*', [ 'build-debug' ]);
|
||||
});
|
||||
|
||||
gulp.task('default', [ 'concat-sjcl', 'build', 'build-debug', 'build-min' ]);
|
||||
gulp.task('version-bump', function() {
|
||||
if (!argv.type) {
|
||||
throw new Error("No type found, pass it in using the --type argument");
|
||||
}
|
||||
|
||||
gulp.task('bower', ['bower-build', 'bower-build-min', 'bower-build-debug', 'bower-version']);
|
||||
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('default', [ 'concat-sjcl', 'build', 'build-debug', 'build-min' ]);
|
||||
|
||||
10
HISTORY.md
10
HISTORY.md
@@ -1,7 +1,17 @@
|
||||
##0.9.3
|
||||
|
||||
+ [Change `presubmit` to emit immediately before transaction submit](https://github.com/ripple/ripple-lib/commit/7a1feaa89701bf861ab31ebd8ffdc8d8d1474e29)
|
||||
|
||||
+ [Add a "core" browser build of ripple-lib which has a subset of features and smaller file size](https://github.com/ripple/ripple-lib/pull/205)
|
||||
|
||||
+ [Update binformat with missing fields from rippled](https://github.com/ripple/ripple-lib/commit/cae980788efb00191bfd0988ed836d60cdf7a9a2)
|
||||
|
||||
+ [Wait for transaction validation before returning `tec` error](https://github.com/ripple/ripple-lib/commit/6bdd4b2670906588852fc4dda457607b4aac08e4)
|
||||
|
||||
+ [Change default `max_fee` on `Remote` to `1 XRP`](https://github.com/ripple/ripple-lib/commit/d6b1728c23ff85c3cc791bed6982a750641fd95f)
|
||||
|
||||
+ [Fix: Request ledger_accept should return the Remote](https://github.com/ripple/ripple-lib/pull/209)
|
||||
|
||||
##0.9.2
|
||||
|
||||
+ [**Breaking change**: Change accountRequest method signature](https://github.com/ripple/ripple-lib/commit/6f5d1104aa3eb440c518ec4f39e264fdce15fa15)
|
||||
|
||||
18
README.md
18
README.md
@@ -15,9 +15,9 @@ A JavaScript API for interacting with Ripple in Node.js and the browser
|
||||
|
||||
###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. [Installation](#installation)
|
||||
2. [Quick start](#quick-start)
|
||||
3. [Running tests](#running-tests)
|
||||
|
||||
###Additional documentation
|
||||
|
||||
@@ -47,7 +47,9 @@ A JavaScript API for interacting with Ripple in Node.js and the browser
|
||||
See the [bower-ripple repo](https://github.com/ripple/bower-ripple) for additional bower instructions
|
||||
|
||||
|
||||
**Building ripple-lib from github**
|
||||
**Building ripple-lib for browser environments**
|
||||
|
||||
ripple-lib uses Gulp to generate browser builds. These steps will generate minified and non-minified builds of ripple-lib in the `build/` directory.
|
||||
|
||||
```
|
||||
$ git clone https://github.com/ripple/ripple-lib
|
||||
@@ -55,9 +57,13 @@ See the [bower-ripple repo](https://github.com/ripple/bower-ripple) for addition
|
||||
$ npm run build
|
||||
```
|
||||
|
||||
Then use the minified `build/ripple-*-min.js`
|
||||
**Restricted browser builds**
|
||||
|
||||
##Quickstart
|
||||
You may generate browser builds that contain a subset of features. To do this, run `./node_modules/.bin/gulp build-<name>`
|
||||
|
||||
+ `build-core` Contains the functionality to make requests and listen for events such as `ledgerClose`. Only `ripple.Remote` is currently exposed. Advanced features like transaction submission and orderbook tracking are excluded from this build.
|
||||
|
||||
##Quick start
|
||||
|
||||
`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
|
||||
|
||||
|
||||
2
npm-shrinkwrap.json
generated
2
npm-shrinkwrap.json
generated
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ripple-lib",
|
||||
"version": "0.9.0-rc5",
|
||||
"version": "0.9.3",
|
||||
"dependencies": {
|
||||
"async": {
|
||||
"version": "0.8.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ripple-lib",
|
||||
"version": "0.9.3-rc1",
|
||||
"version": "0.9.3",
|
||||
"description": "A JavaScript API for interacting with Ripple in Node.js and the browser",
|
||||
"files": [
|
||||
"src/js/*",
|
||||
|
||||
@@ -106,7 +106,8 @@ var FIELDS_MAP = exports.fields = {
|
||||
16: 'BookDirectory',
|
||||
17: 'InvoiceID',
|
||||
18: 'Nickname',
|
||||
19: 'Feature'
|
||||
19: 'Amendment',
|
||||
20: 'TicketID'
|
||||
},
|
||||
6: { // Amount
|
||||
1: 'Amount',
|
||||
@@ -135,7 +136,8 @@ var FIELDS_MAP = exports.fields = {
|
||||
10: 'ExpireCode',
|
||||
11: 'CreateCode',
|
||||
12: 'MemoType',
|
||||
13: 'MemoData'
|
||||
13: 'MemoData',
|
||||
14: 'MemoFormat'
|
||||
},
|
||||
8: { // Account
|
||||
1: 'Account',
|
||||
@@ -187,7 +189,7 @@ var FIELDS_MAP = exports.fields = {
|
||||
19: { // Vector256
|
||||
1: 'Indexes',
|
||||
2: 'Hashes',
|
||||
3: 'Features'
|
||||
3: 'Amendments'
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ function Remote(opts, trace) {
|
||||
this.canonical_signing = (typeof opts.canonical_signing === 'boolean') ? opts.canonical_signing : true;
|
||||
|
||||
this.fee_cushion = (typeof opts.fee_cushion === 'number') ? opts.fee_cushion : 1.2;
|
||||
this.max_fee = (typeof opts.max_fee === 'number') ? opts.max_fee : Infinity;
|
||||
this.max_fee = (typeof opts.max_fee === 'number') ? opts.max_fee : 1000000; // default max fee is 1 XRP, 10^6 drops
|
||||
|
||||
this.max_attempts = (typeof opts.max_attempts === 'number') ? opts.max_attempts : 10;
|
||||
|
||||
@@ -1217,6 +1217,7 @@ Remote.prototype.requestTx = function(hash, callback) {
|
||||
* @param {String} marker - start position in response paging
|
||||
* @param [Function] callback
|
||||
* @return {Request}
|
||||
* @throws {Error} if a marker is provided, but no ledger_index or ledger_hash
|
||||
*/
|
||||
Remote.accountRequest = function(type, options, callback) {
|
||||
var account, ledger, peer, limit, marker;
|
||||
@@ -1658,7 +1659,7 @@ Remote.prototype.requestLedgerAccept = function(callback) {
|
||||
request.callback(callback, 'ledger_closed');
|
||||
request.request();
|
||||
|
||||
return this;
|
||||
return request;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,7 +2,6 @@ var util = require('util');
|
||||
var url = require('url');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var Amount = require('./amount').Amount;
|
||||
var Transaction = require('./transaction').Transaction;
|
||||
var log = require('./log').internal.sub('server');
|
||||
|
||||
/**
|
||||
@@ -760,22 +759,16 @@ Server.prototype._isConnected = function() {
|
||||
* Calculate transaction fee
|
||||
*
|
||||
* @param {Transaction|Number} Fee units for a provided transaction
|
||||
* @return {Number} Final fee in XRP for specified number of fee units
|
||||
* @return {String} Final fee in XRP for specified number of fee units
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Server.prototype._computeFee = function(transaction) {
|
||||
var units;
|
||||
|
||||
if (transaction instanceof Transaction) {
|
||||
units = transaction._getFeeUnits();
|
||||
} else if (typeof transaction === 'number') {
|
||||
units = transaction;
|
||||
} else {
|
||||
Server.prototype._computeFee = function(feeUnits) {
|
||||
if (isNaN(feeUnits)) {
|
||||
throw new Error('Invalid argument');
|
||||
}
|
||||
|
||||
return this._feeTx(units).to_json();
|
||||
return this._feeTx(Number(feeUnits)).to_json();
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -276,7 +276,7 @@ Transaction.prototype._computeFee = function() {
|
||||
for (var i=0; i<servers.length; i++) {
|
||||
var server = servers[i];
|
||||
if (server._connected) {
|
||||
fees.push(Number(server._computeFee(this)));
|
||||
fees.push(Number(server._computeFee(this._getFeeUnits())));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -365,8 +365,6 @@ TransactionManager.prototype._request = function(tx) {
|
||||
return tx.emit('error', new RippleError('tejLocalSigningRequired', message));
|
||||
}
|
||||
|
||||
tx.emit('presubmit');
|
||||
|
||||
if (tx.finalized) {
|
||||
return;
|
||||
}
|
||||
@@ -557,9 +555,11 @@ TransactionManager.prototype._request = function(tx) {
|
||||
return;
|
||||
}
|
||||
|
||||
submitRequest.timeout(self._submissionTimeout, requestTimeout);
|
||||
tx.submissions = submitRequest.broadcast();
|
||||
tx.emit('presubmit');
|
||||
|
||||
submitRequest.timeout(self._submissionTimeout, requestTimeout);
|
||||
|
||||
tx.submissions = submitRequest.broadcast();
|
||||
tx.attempts++;
|
||||
tx.emit('postsubmit');
|
||||
};
|
||||
|
||||
@@ -42,12 +42,12 @@ describe('Remote', function () {
|
||||
|
||||
it('remote server initialization - url object', function() {
|
||||
var remote = new Remote({
|
||||
servers: [ { host: 's-west.ripple.com', port: 443, secure: true } ],
|
||||
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 - no secure property', function() {
|
||||
var remote = new Remote({
|
||||
@@ -56,7 +56,7 @@ describe('Remote', function () {
|
||||
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({
|
||||
@@ -74,7 +74,7 @@ describe('Remote', function () {
|
||||
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(
|
||||
@@ -83,7 +83,7 @@ describe('Remote', function () {
|
||||
servers: [ { host: '+', port: 443, secure: true } ]
|
||||
});
|
||||
}, Error);
|
||||
})
|
||||
});
|
||||
|
||||
it('remote server initialization - url object - invalid port', function() {
|
||||
assert.throws(
|
||||
@@ -151,6 +151,34 @@ describe('Remote', function () {
|
||||
);
|
||||
});
|
||||
|
||||
it('remote server initialization - set max_fee - number', function() {
|
||||
var remote = new Remote({
|
||||
max_fee: 10
|
||||
});
|
||||
assert.strictEqual(remote.max_fee, 10);
|
||||
|
||||
remote = new Remote({
|
||||
max_fee: 1234567890
|
||||
});
|
||||
assert.strictEqual(remote.max_fee, 1234567890);
|
||||
});
|
||||
|
||||
it('remote server initialization - set max_fee - string fails, should be number', function() {
|
||||
var remote = new Remote({
|
||||
max_fee: '1234567890'
|
||||
});
|
||||
assert.strictEqual(remote.max_fee, 1e6);
|
||||
});
|
||||
|
||||
it('remote server initialization - max_fee - default', function() {
|
||||
var remote = new Remote({
|
||||
max_fee: void(0)
|
||||
});
|
||||
assert.strictEqual(remote.max_fee, 1e6);
|
||||
assert.strictEqual(remote.max_fee, 1000000);
|
||||
assert.strictEqual((new Remote()).max_fee, 1e6);
|
||||
});
|
||||
|
||||
describe('request constructors', function () {
|
||||
beforeEach(function () {
|
||||
callback = function () {}
|
||||
@@ -489,9 +517,9 @@ describe('Remote', function () {
|
||||
},
|
||||
parseJson: function(json) {}
|
||||
}
|
||||
}
|
||||
};
|
||||
remote.getPendingTransactions();
|
||||
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
@@ -1006,12 +1006,6 @@ describe('Server', function() {
|
||||
assert(server._isConnected());
|
||||
});
|
||||
|
||||
it('Compute fee - transaction', function() {
|
||||
var server = new Server(new Remote(), 'ws://localhost:5748');
|
||||
var transaction = new Transaction();
|
||||
assert.strictEqual(server._computeFee(transaction), '12');
|
||||
});
|
||||
|
||||
it('Compute fee - fee units', function() {
|
||||
var server = new Server(new Remote(), 'ws://localhost:5748');
|
||||
var transaction = new Transaction();
|
||||
@@ -1033,7 +1027,7 @@ describe('Server', function() {
|
||||
server._load_factor = 256 * 4;
|
||||
|
||||
var transaction = new Transaction();
|
||||
assert.strictEqual(server._computeFee(transaction), '48');
|
||||
assert.strictEqual(server._computeFee(10), '48');
|
||||
});
|
||||
|
||||
it('Compute reserve', function() {
|
||||
|
||||
@@ -1560,33 +1560,34 @@ describe('Transaction', function() {
|
||||
transaction.submit();
|
||||
});
|
||||
|
||||
it.skip('Abort submission', function(done) {
|
||||
it('Abort submission on presubmit', function(done) {
|
||||
var remote = new Remote();
|
||||
var transaction = new Transaction(remote).accountSet('r36xtKNKR43SeXnGn7kN4r4JdQzcrkqpWe');
|
||||
var account = remote.addAccount('r36xtKNKR43SeXnGn7kN4r4JdQzcrkqpWe');
|
||||
remote.setSecret('rJaT8TafQfYJqDm8aC5n3Yx5yWEL2Ery79', 'snPwFATthTkKnGjEW73q3TL4yci1Q');
|
||||
|
||||
var server = new Server(remote, 'wss://s1.ripple.com:443');
|
||||
server._computeFee = function() { return '12'; };
|
||||
server._connected = true;
|
||||
|
||||
remote._servers.push(server);
|
||||
remote._connected = true;
|
||||
remote._ledger_current_index = 1;
|
||||
|
||||
var transaction = new Transaction(remote).accountSet('rJaT8TafQfYJqDm8aC5n3Yx5yWEL2Ery79');
|
||||
var account = remote.account('rJaT8TafQfYJqDm8aC5n3Yx5yWEL2Ery79');
|
||||
|
||||
account._transactionManager._nextSequence = 1;
|
||||
|
||||
account._transactionManager._request = function(tx) {
|
||||
setTimeout(function() {
|
||||
tx.emit('success', { });
|
||||
}, 20);
|
||||
};
|
||||
transaction.once('presubmit', function() {
|
||||
transaction.abort();
|
||||
});
|
||||
|
||||
transaction.complete = function() {
|
||||
return this;
|
||||
};
|
||||
|
||||
function submitCallback(err, res) {
|
||||
transaction.submit(function(err, res) {
|
||||
setImmediate(function() {
|
||||
assert(err);
|
||||
assert.strictEqual(err.result, 'tejAbort');
|
||||
done();
|
||||
});
|
||||
};
|
||||
|
||||
transaction.submit(submitCallback);
|
||||
transaction.abort();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user