mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-15 01:55:48 +00:00
Compare commits
36 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 | ||
|
|
3ee7998261 | ||
|
|
6fb9ed8312 | ||
|
|
89f79c35f5 | ||
|
|
6bdd4b2670 | ||
|
|
acd79d19e2 | ||
|
|
674d4a957d | ||
|
|
bdbf264771 | ||
|
|
8f17873da2 | ||
|
|
b0cac776ee | ||
|
|
625dba4d85 | ||
|
|
261b72d0fc | ||
|
|
b5b167ef6d |
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' ]);
|
||||
|
||||
14
HISTORY.md
14
HISTORY.md
@@ -1,3 +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)
|
||||
|
||||
26
README.md
26
README.md
@@ -1,6 +1,6 @@
|
||||
#ripple-lib
|
||||
|
||||
JavaScript client for [rippled](https://github.com/ripple/rippled)
|
||||
A JavaScript API for interacting with Ripple in Node.js and the browser
|
||||
|
||||
[](https://travis-ci.org/ripple/ripple-lib) [](https://coveralls.io/r/ripple/ripple-lib?branch=develop)
|
||||
|
||||
@@ -15,9 +15,9 @@ JavaScript client for [rippled](https://github.com/ripple/rippled)
|
||||
|
||||
###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 @@ JavaScript client for [rippled](https://github.com/ripple/rippled)
|
||||
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
|
||||
|
||||
@@ -75,8 +81,8 @@ var remote = new Remote({
|
||||
|
||||
remote.connect(function() {
|
||||
/* remote connected */
|
||||
remote.request('server_info', function(err, info) {
|
||||
|
||||
remote.requestServerInfo(function(err, info) {
|
||||
// process err and info
|
||||
});
|
||||
});
|
||||
```
|
||||
@@ -87,7 +93,7 @@ remote.connect(function() {
|
||||
|
||||
2. `cd` into the repository and install dependencies with `npm install`
|
||||
|
||||
3. `npm test` or `node_modules/.bin/mocha test/*-test.js`
|
||||
3. `npm test`
|
||||
|
||||
**Generating code coverage**
|
||||
|
||||
|
||||
@@ -40,9 +40,19 @@ This file provides step-by-step walkthroughs for some of the most common usages
|
||||
```
|
||||
3. Create a new `Remote` and connect to the network:
|
||||
```js
|
||||
|
||||
var options = {
|
||||
trace : false,
|
||||
trusted: true,
|
||||
local_signing: true,
|
||||
servers: [
|
||||
{ host: 's-west.ripple.com', port: 443, secure: true }
|
||||
]
|
||||
}
|
||||
|
||||
var remote = new Remote({options});
|
||||
|
||||
remote.connect(function() {
|
||||
remote.connect(function(err, res) {
|
||||
/* remote connected, use some remote functions here */
|
||||
});
|
||||
```
|
||||
@@ -57,11 +67,11 @@ This file provides step-by-step walkthroughs for some of the most common usages
|
||||
|
||||
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](https://ripple.com/wiki/JSON_Messages#server_info).
|
||||
Here is an example, using [requestServerInfo](https://ripple.com/wiki/JSON_Messages#server_info).
|
||||
|
||||
+ Constructing a `Request` with event listeners
|
||||
```js
|
||||
var request = remote.request('server_info');
|
||||
var request = remote.requestServerInfo();
|
||||
|
||||
request.on('success', function onSuccess(res) {
|
||||
//handle success
|
||||
@@ -102,23 +112,43 @@ See the [wiki](https://ripple.com/wiki/JSON_Messages#subscribe) for details on s
|
||||
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
|
||||
var remote = new Remote({
|
||||
// see the API Reference for available options
|
||||
servers: [ 'wss://s1.ripple.com:443' ]
|
||||
});
|
||||
|
||||
request.on('transaction', function onTransacstion(transaction) {
|
||||
//handle transaction
|
||||
});
|
||||
remote.connect(function() {
|
||||
console.log('Remote connected');
|
||||
|
||||
request.request(function(err) {
|
||||
if (err) {
|
||||
} else {
|
||||
}
|
||||
var streams = [
|
||||
'ledger',
|
||||
'transactions'
|
||||
];
|
||||
|
||||
var request = remote.requestSubscribe(streams);
|
||||
|
||||
request.on('error', function(error) {
|
||||
console.log('request error: ', error);
|
||||
});
|
||||
|
||||
|
||||
// the `ledger_closed` and `transaction` will come in on the remote
|
||||
// since the request for subscribe is finalized after the success return
|
||||
// the streaming events will still come in, but not on the initial request
|
||||
remote.on('ledger_closed', function(ledger) {
|
||||
console.log('ledger_closed: ', JSON.stringify(ledger, null, 2));
|
||||
});
|
||||
|
||||
remote.on('transaction', function(transaction) {
|
||||
console.log('transaction: ', JSON.stringify(transaction, null, 2));
|
||||
});
|
||||
|
||||
remote.on('error', function(error) {
|
||||
console.log('remote error: ', error);
|
||||
});
|
||||
|
||||
// fire the request
|
||||
request.request();
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
@@ -18,7 +18,7 @@ __(More examples coming soon!)__
|
||||
###Also see:
|
||||
|
||||
1. [The ripple-lib README](../README.md)
|
||||
2. [The ripple-lib GUIDES](GUIDES.md)
|
||||
2. [The ripple-lib GUIDES](GUIDES.md)a
|
||||
|
||||
#Remote options
|
||||
|
||||
@@ -61,14 +61,34 @@ or
|
||||
|
||||
#Request constructor functions
|
||||
|
||||
Some requests have helper methods to construct the requests object and set properties on the message object. These will often be the more used requests and the helper methods is the preferred way of constructing these requests.
|
||||
Other request can still be made, but the type will have to be passed in directly to request constructor. See examples below.
|
||||
|
||||
If the method is camelCased and starts with `request`, it's a helper method that wraps the request constructor.
|
||||
|
||||
##Server requests
|
||||
|
||||
**[server_info([callback])](https://ripple.com/wiki/JSON_Messages#server_info)**
|
||||
**[requestServerInfo([callback])](https://ripple.com/wiki/JSON_Messages#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.setServer`. Example:
|
||||
|
||||
```js
|
||||
var request = remote.request('server_info');
|
||||
var request = remote.requestServerInfo();
|
||||
|
||||
request.setServer('wss://s1.ripple.com');
|
||||
|
||||
request.request(function(err, res) {
|
||||
|
||||
});
|
||||
```
|
||||
**[requestPeers([callback])](https://ripple.com/wiki/JSON_Messages#peers)**
|
||||
|
||||
**[requestConnect(ip, port, [callback])](https://ripple.com/wiki/JSON_Messages#connect)**
|
||||
|
||||
**[unl_list([callback])](https://ripple.com/wiki/JSON_Messages#unl_list)**
|
||||
|
||||
```js
|
||||
var request = remote.request('un_list');
|
||||
|
||||
request.setServer('wss://s1.ripple.com');
|
||||
|
||||
@@ -77,42 +97,48 @@ 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)**
|
||||
|
||||
|
||||
**[connect(ip, port, [callback])](https://ripple.com/wiki/JSON_Messages#connect)**
|
||||
|
||||
##Ledger requests
|
||||
|
||||
**[ledger(ledger, [opts], [callback])](https://ripple.com/wiki/JSON_Messages#ledger)**
|
||||
**[requestLedger([opts], [callback])](https://ripple.com/wiki/JSON_Messages#ledger)**
|
||||
|
||||
**ledger_header([callback])**
|
||||
**[requestLedgerHeader([callback])](https://wiki.ripple.com/JSON_Messages#ledger_data)**
|
||||
|
||||
**[ledger_current([callback])](https://ripple.com/wiki/JSON_Messages#ledger_current)**
|
||||
**[requestLedgerCurrent([callback])](https://ripple.com/wiki/JSON_Messages#ledger_current)**
|
||||
|
||||
**[ledger_entry(type, [callback])](https://ripple.com/wiki/JSON_Messages#ledger_entry)**
|
||||
**[requestLedgerEntry(type, [callback])](https://ripple.com/wiki/JSON_Messages#ledger_entry)**
|
||||
|
||||
**[subscribe([streams], [callback])](https://ripple.com/wiki/JSON_Messages#subscribe)**
|
||||
**[requestSubscribe([streams], [callback])](https://ripple.com/wiki/JSON_Messages#subscribe)**
|
||||
|
||||
Start receiving selected streams from the server.
|
||||
|
||||
**[unsubscribe([streams], [callback])](https://ripple.com/wiki/JSON_Messages#unsubscribe)**
|
||||
**[requestUnsubscribe([streams], [callback])](https://ripple.com/wiki/JSON_Messages#unsubscribe)**
|
||||
|
||||
Stop receiving selected streams from the server.
|
||||
|
||||
##Account requests
|
||||
|
||||
**[account_info(account, [callback])](https://ripple.com/wiki/JSON_Messages#account_info)**
|
||||
**[requestAccountInfo(options, [callback])](https://ripple.com/wiki/JSON_Messages#account_info)**
|
||||
|
||||
Return information about the specified account.
|
||||
|
||||
```
|
||||
var options = {
|
||||
account: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B',
|
||||
ledger: 'validated'
|
||||
};
|
||||
|
||||
var request = remote.requestAccountInfo(options, function(err, info) {
|
||||
/* process info */
|
||||
});
|
||||
|
||||
|
||||
// response
|
||||
{
|
||||
ledger_current_index: <number>,
|
||||
account_data: {
|
||||
@@ -129,13 +155,35 @@ Return information about the specified account.
|
||||
}
|
||||
```
|
||||
|
||||
**[account_lines(accountID, [account_index], [ledger], [callback])](https://ripple.com/wiki/JSON_Messages#account_lines)**
|
||||
**[requestAccountLines(options, [callback])](https://ripple.com/wiki/JSON_Messages#account_lines)**
|
||||
|
||||
**[account_offers(accountID, [account_index], [ledger], [callback])](https://ripple.com/wiki/JSON_Messages#account_offers)**
|
||||
**[requestAccountOffers(options, [callback])](https://ripple.com/wiki/JSON_Messages#account_offers)**
|
||||
|
||||
Return the specified account's outstanding offers.
|
||||
|
||||
**[account_tx(options, [callback])](https://ripple.com/wiki/JSON_Messages#account_tx)**
|
||||
Requests for both `account_lines` and `account_offers` support paging. The amount of results per response can be configured with the `limit`.
|
||||
The responses can be paged through by using the `marker`.
|
||||
|
||||
```
|
||||
// A valid `ledger_index` or `ledger_hash` is required to provide a reliable result.
|
||||
// Results can change between ledger closes, so the provided ledger will be used as base.
|
||||
var options = {
|
||||
account: < rippleAccount >,
|
||||
limit: < Number between 10 and 400 >,
|
||||
ledger: < valid ledger_index or ledger_hash >
|
||||
}
|
||||
|
||||
// The `marker` comes back in an account request if there are more results than are returned
|
||||
// in the current response. The amount of results per response are determined by the `limit`.
|
||||
if (marker) {
|
||||
options.marker = < marker >;
|
||||
}
|
||||
|
||||
var request = remote.requestAccountOffers(options);
|
||||
```
|
||||
|
||||
|
||||
**[requestAccountTransactions(options, [callback])](https://ripple.com/wiki/JSON_Messages#account_tx)**
|
||||
|
||||
Fetch a list of transactions that applied to this account.
|
||||
|
||||
@@ -153,42 +201,46 @@ Options:
|
||||
+ `fwd_marker`
|
||||
+ `rev_marker`
|
||||
|
||||
**[wallet_accounts(seed, [callback])](https://ripple.com/wiki/JSON_Messages#wallet_accounts)**
|
||||
**[requestWalletAccounts(seed, [callback])](https://ripple.com/wiki/JSON_Messages#wallet_accounts)**
|
||||
|
||||
Return a list of accounts for a wallet. *Requires trusted remote*
|
||||
|
||||
**account_balance(account, [ledger], [callback])**
|
||||
**requestAccountBalance(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.
|
||||
|
||||
**account_flags(account, [ledger], [callback])**
|
||||
**requestAccountFlags(account, [ledger], [callback])**
|
||||
|
||||
Return the flags for an account.
|
||||
|
||||
**owner_count(account, [ledger], [callback])**
|
||||
**requestOwnerCount(account, [ledger], [callback])**
|
||||
|
||||
Return the owner count for an account.
|
||||
|
||||
**ripple_balance(account, issuer, currency, [ledger], [callback])**
|
||||
**requestRippleBalance(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)**
|
||||
**[requestBookOffers(options, [callback])](https://ripple.com/wiki/JSON_Messages#book_offers)**
|
||||
|
||||
Return the offers for an order book, also called a *snapshot*
|
||||
|
||||
```js
|
||||
var request = remote.request('book_offers', {
|
||||
taker_gets: {
|
||||
'currency':'XRP'
|
||||
var options = {
|
||||
gets: {
|
||||
issuer: < issuer >,
|
||||
currency: < currency >
|
||||
},
|
||||
taker_pays: {
|
||||
'currency':'USD',
|
||||
'issuer': 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
|
||||
}
|
||||
});
|
||||
pays: {
|
||||
issuer: < issuer >,
|
||||
currency: < currency >
|
||||
},
|
||||
limit: < limit >
|
||||
};
|
||||
|
||||
var request = remote.requestBookOffers(options);
|
||||
|
||||
request.request(function(err, offers) {
|
||||
//handle offers
|
||||
@@ -197,23 +249,23 @@ request.request(function(err, offers) {
|
||||
|
||||
##Transaction requests
|
||||
|
||||
**[transaction_entry(hash, [ledger_hash], [callback])](https://ripple.com/wiki/JSON_Messages#transaction_entry)**
|
||||
**[requestTransactionEntry(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.
|
||||
|
||||
**[tx(hash, [callback])](https://ripple.com/wiki/JSON_Messages#tx)**
|
||||
**[requestTransaction(hash, [callback])](https://ripple.com/wiki/JSON_Messages#tx)**
|
||||
|
||||
Searches ledger history for validated transaction hashes.
|
||||
|
||||
**[sign(secret, tx_json, [callback])](https://ripple.com/wiki/JSON_Messages#sign)**
|
||||
**[requestSign(secret, tx_json, [callback])](https://ripple.com/wiki/JSON_Messages#sign)**
|
||||
|
||||
Sign a transaction. *Requires trusted remote*
|
||||
|
||||
**[submit([callback])](https://ripple.com/wiki/JSON_Messages#submit)**
|
||||
**[requestSubmit([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)**
|
||||
**[pathFind(src_account, dst_account, dst_amount, src_currencies)](https://ripple.com/wiki/JSON_Messages#path_find)**
|
||||
|
||||
#Transaction constructors
|
||||
|
||||
|
||||
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.2-rc5",
|
||||
"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'
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ Currency.prototype.parse_json = function(j, shouldInterpretXrpAsIou) {
|
||||
case 'string':
|
||||
|
||||
// if an empty string is given, fall back to XRP
|
||||
if (!j) {
|
||||
if (!j || j === '0') {
|
||||
this.parse_hex(shouldInterpretXrpAsIou ? Currency.HEX_CURRENCY_BAD : Currency.HEX_ZERO);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -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())));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,8 +46,16 @@ function TransactionManager(account) {
|
||||
}
|
||||
|
||||
if (submission instanceof Transaction) {
|
||||
|
||||
// ND: A `success` handler will `finalize` this later
|
||||
submission.emit('success', transaction);
|
||||
switch (transaction.engine_result) {
|
||||
case 'tesSUCCESS':
|
||||
submission.emit('success', transaction);
|
||||
break;
|
||||
default:
|
||||
submission.emit('error', transaction);
|
||||
}
|
||||
|
||||
} else {
|
||||
self._pending.addReceivedId(hash, transaction);
|
||||
}
|
||||
@@ -357,8 +365,6 @@ TransactionManager.prototype._request = function(tx) {
|
||||
return tx.emit('error', new RippleError('tejLocalSigningRequired', message));
|
||||
}
|
||||
|
||||
tx.emit('presubmit');
|
||||
|
||||
if (tx.finalized) {
|
||||
return;
|
||||
}
|
||||
@@ -413,8 +419,6 @@ TransactionManager.prototype._request = function(tx) {
|
||||
if (tx.finalized) {
|
||||
return;
|
||||
}
|
||||
|
||||
tx.emit('error', message);
|
||||
};
|
||||
|
||||
function transactionFailedLocal(message) {
|
||||
@@ -551,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');
|
||||
};
|
||||
|
||||
@@ -198,6 +198,16 @@ describe('Currency', function() {
|
||||
cur2 = currency.from_json(cur);
|
||||
assert.strictEqual(cur.to_json(), cur2.to_json());
|
||||
});
|
||||
it('should parse json 0', function() {
|
||||
var cur = currency.from_json(0);
|
||||
assert.strictEqual(cur.to_json(), 'XRP');
|
||||
assert.strictEqual(cur.get_iso(), 'XRP');
|
||||
});
|
||||
it('should parse json 0', function() {
|
||||
var cur = currency.from_json('0');
|
||||
assert.strictEqual(cur.to_json(), 'XRP');
|
||||
assert.strictEqual(cur.get_iso(), 'XRP');
|
||||
});
|
||||
});
|
||||
|
||||
describe('is_valid', function() {
|
||||
|
||||
@@ -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