mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-06 05:45:48 +00:00
Compare commits
72 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50a7320886 | ||
|
|
418987476e | ||
|
|
89e4ff328c | ||
|
|
04bf49cb43 | ||
|
|
1c017df2a3 | ||
|
|
5fed1f08e4 | ||
|
|
82c349c8c4 | ||
|
|
0f7af6a4e9 | ||
|
|
8db1791ed2 | ||
|
|
a29ec1b8c7 | ||
|
|
232a760a58 | ||
|
|
f4ad04d334 | ||
|
|
8dfec20871 | ||
|
|
64745017e9 | ||
|
|
37edede728 | ||
|
|
f785605db8 | ||
|
|
01ad30ab07 | ||
|
|
e08d507462 | ||
|
|
4c23bd5ad3 | ||
|
|
b15abd5376 | ||
|
|
79971f906b | ||
|
|
9eec98778f | ||
|
|
dcd0e14142 | ||
|
|
cfcbc9aab7 | ||
|
|
a80de5658a | ||
|
|
34215eb309 | ||
|
|
9458005d7f | ||
|
|
5f36df0172 | ||
|
|
3ff4929a49 | ||
|
|
4bea69d647 | ||
|
|
09541dae86 | ||
|
|
bcbcc53c87 | ||
|
|
76f120bec9 | ||
|
|
f8bf28876d | ||
|
|
b03795df09 | ||
|
|
dbe20d6574 | ||
|
|
0550fab73e | ||
|
|
3f2d9d198e | ||
|
|
b9c953fce6 | ||
|
|
181cfd69de | ||
|
|
569766b8f8 | ||
|
|
53a232ebdc | ||
|
|
4c9a2ff538 | ||
|
|
dc623cd049 | ||
|
|
7cd517268b | ||
|
|
2438295e70 | ||
|
|
f5e1a4a588 | ||
|
|
9e9a0a7d9b | ||
|
|
1c68283d1e | ||
|
|
28796d37cb | ||
|
|
067bc48d4e | ||
|
|
b94698df0b | ||
|
|
4f40b5cb6d | ||
|
|
14704eee6b | ||
|
|
860f6a6cd8 | ||
|
|
7a928804ec | ||
|
|
14444bea3f | ||
|
|
47a139fdff | ||
|
|
4e30b9b2fa | ||
|
|
2112d4c0b3 | ||
|
|
1d1132b7fa | ||
|
|
e07fa11923 | ||
|
|
7c92adbf45 | ||
|
|
d55aa2339f | ||
|
|
95e39153da | ||
|
|
65d8260908 | ||
|
|
1aa9feda71 | ||
|
|
2e5b435b11 | ||
|
|
54f12862dc | ||
|
|
226ef862ae | ||
|
|
4a0d675726 | ||
|
|
b2b6715ac0 |
@@ -3,6 +3,7 @@ node_js:
|
||||
- 6
|
||||
- 8
|
||||
- 9
|
||||
- 10
|
||||
script:
|
||||
- yarn compile
|
||||
- yarn test
|
||||
|
||||
232
HISTORY.md
232
HISTORY.md
@@ -1,5 +1,234 @@
|
||||
# ripple-lib Release History
|
||||
|
||||
## 1.1.0 (2018-10-31)
|
||||
|
||||
+ Add support for Node.js v10 LTS (#964)
|
||||
+ Add [DepositPreauth](https://developers.ripple.com/depositauth.html) ([#958](https://github.com/ripple/ripple-lib/pull/958))
|
||||
+ In `FormattedTransactionType`, the `Outcome`'s `balanceChanges` property had
|
||||
the wrong type. This is now fixed (#955)
|
||||
+ Add/fix docs for: xrpToDrops, dropsToXrp, iso8601ToRippleTime, schemaValidator, isValidAddress, isValidSecret, deriveKeypair, deriveAddress
|
||||
|
||||
The SHA-256 checksums for the browser version of this release can be found
|
||||
below.
|
||||
```
|
||||
% shasum -a 256 *
|
||||
e1d742092b3c0fcee97a875e18db4baeab3bbc82f08b96e883ee188c5f0cfb37 ripple-1.1.0-debug.js
|
||||
f28921f57a133678dcb3cb54c497626bd76b1f953d22d61f3ddca31c8947d552 ripple-1.1.0-min.js
|
||||
3696871a80c1102635699994adcaf00cdfdfcff5014fc2eba3d8f8d8437c8f91 ripple-1.1.0.js
|
||||
```
|
||||
|
||||
## 1.0.2 (2018-10-16)
|
||||
|
||||
+ Fix #954: Exclude SendMax from all XRP to XRP payments (thanks @jefftrudeau)
|
||||
+ TypeScript
|
||||
+ book_offers returns offers type OfferLedgerEntry (#951)
|
||||
+ Use `object` (#936)
|
||||
|
||||
The SHA-256 checksums for the browser version of this release can be found
|
||||
below.
|
||||
```
|
||||
% shasum -a 256 *
|
||||
2556fe17296e127ed44e7066e90a6175e2b164f00ca3c1aa7b1c554f31c688dd ripple-1.0.2-debug.js
|
||||
e0342ea21eac32a1024c62034fba09c6f26dd3e7371b23ea1e153e03135cd590 ripple-1.0.2-min.js
|
||||
c7286c517497d018d02d09257e81172b61d36c8b9885a077af68e8133c3b3b9b ripple-1.0.2.js
|
||||
```
|
||||
|
||||
## 1.0.1 (2018-09-27)
|
||||
|
||||
+ Add address/secret/key validation and derivation methods ([#932](https://github.com/ripple/ripple-lib/pull/932))
|
||||
+ `isValidAddress(address: string) : boolean`: Checks if the specified string contains a valid address.
|
||||
+ `isValidSecret(secret: string): boolean`: Checks if the specified string contains a valid secret.
|
||||
+ `deriveKeypair(seed: string): {privateKey: string, publicKey: string}`: Derive a public and private key from a seed.
|
||||
+ `deriveAddress(publicKey: string): string`: Derive an XRP Ledger address from a public key.
|
||||
+ To derive an address from a secret:
|
||||
1. Derive the public key from the secret.
|
||||
2. Derive the address from the public key.
|
||||
+ Example: `const address = api.deriveAddress(api.deriveKeypair(secret).publicKey)`
|
||||
+ Update server regex to accommodate UDS (#944)
|
||||
+ Include memos when parsing trustlines (#949)
|
||||
+ Add remaining LedgerEntry types (#943)
|
||||
|
||||
The SHA-256 checksums for the browser version of this release can be found
|
||||
below.
|
||||
```
|
||||
% shasum -a 256 *
|
||||
9b6408641ce83659afcd5765c256c35829a4fcb4c3244dc9ca6bf27c871a45c4 ripple-1.0.1-debug.js
|
||||
7ab2b69fe59c2d4a74638116e2ba3b387155eb2d23e48a01bbf7beb72911f898 ripple-1.0.1-min.js
|
||||
8bb4dcad9ce25a27003b1d73d71ddf41b8a5af02ece4ebbfeaff4aeb91f3b8c4 ripple-1.0.1.js
|
||||
```
|
||||
|
||||
## 1.0.0 (2018-08-30)
|
||||
|
||||
We are pleased to announce the release of `ripple-lib` version 1.0.0.
|
||||
|
||||
This version features a range of changes and improvements that make the library
|
||||
more capable and flexible. It includes new methods for accessing rippled APIs,
|
||||
including subscriptions.
|
||||
|
||||
When using this version with `rippled` for online functionality, we recommend
|
||||
using `rippled` version 1.0.1 or later.
|
||||
|
||||
Here is a summary of the changes since `ripple-lib` version 0.22.0, which was
|
||||
the last non-beta version.
|
||||
|
||||
### New Features
|
||||
|
||||
+ [Add `request()`, `hasNextPage()`, and `requestNextPage()` for accessing `rippled`
|
||||
APIs](https://github.com/ripple/ripple-lib/blob/09541dae86bc859bf5928ac65b2645dfaaf7f8b1/docs/index.md#rippled-apis).
|
||||
+ Add `prepareTransaction()` for preparing raw `txJSON`.
|
||||
+ XRP amounts can be specified in drops. Also, `xrpToDrops()` and `dropsToXrp()`
|
||||
are available to make conversions.
|
||||
+ `getTransaction` responses can include a new `channelChanges` property that
|
||||
describes the details of a payment channel.
|
||||
|
||||
### Data Validation and Errors
|
||||
|
||||
+ [Amounts in drops and XRP are checked for
|
||||
validity](https://github.com/ripple/ripple-lib/blob/develop/HISTORY.md#100-beta1-2018-05-24).
|
||||
+ [A maximum fee is now
|
||||
imposed](https://github.com/ripple/ripple-lib/blob/develop/HISTORY.md#100-beta2-2018-06-08). Exceeding it causes a `ValidationError` to be
|
||||
thrown.
|
||||
+ Errors are improved and more data validation was added.
|
||||
+ Bug fix: `getPaths` now filters paths correctly and works correctly when the
|
||||
destination currency is XRP.
|
||||
|
||||
### Breaking Changes
|
||||
|
||||
The following changes were introduced in 1.0.0.
|
||||
|
||||
+ `getTransaction()` and `getTransactions()`
|
||||
+ The `specification.destination.amount` field has been removed from the parsed transaction response.
|
||||
+ To determine the amount that a transaction delivered, use `outcome.deliveredAmount`.
|
||||
+ If you require the provisional requested `Amount` from the original transaction:
|
||||
+ Use `getTransaction`'s `includeRawTransaction` option, or
|
||||
+ Use `getTransactions`'s `includeRawTransactions` option, or
|
||||
+ Use the rippled APIs directly with `request`. For example, call the API methods `tx`, `account_tx`, etc.
|
||||
+ `getLedger()` response object
|
||||
+ The `rawTransactions` field has been removed (for consistency with `getTransaction()` and `getTransactions()`).
|
||||
+ Instead, within each `transaction`, use the new `rawTransaction` JSON string.
|
||||
+ The `metaData` field has been renamed to `meta` for consistency with rippled's `tx` method.
|
||||
+ `ledger_index` has been added to each raw transaction.
|
||||
|
||||
The SHA-256 checksums for the browser version of this release can be found
|
||||
below.
|
||||
```
|
||||
% shasum -a 256 *
|
||||
06e5efcb6846ad45dedfd85cfa2ef4bdeb608b15ccbfb60b872c995d97342426 ripple-1.0.0-debug.js
|
||||
cdb26b928a89ce228c727d1ff966df266eb46b2f76bd94f81cbeb0a9d75febf0 ripple-1.0.0-min.js
|
||||
f74ee804e8a945a994e4e3901a0a3eb52292fbdcbff61ed30cefb8ffbcba50c3 ripple-1.0.0.js
|
||||
```
|
||||
|
||||
## 1.0.0-beta.5 (2018-08-11)
|
||||
|
||||
+ [Fix a TypeScript error by importing the `Prepare` type](https://github.com/ripple/ripple-lib/commit/7cd517268bda5fe74b91dad02fedf8b51b7eae9b)
|
||||
|
||||
## 1.0.0-beta.4 (2018-08-10)
|
||||
|
||||
+ [Add `prepareTransaction()`](https://github.com/ripple/ripple-lib/pull/898)
|
||||
+ Internal improvements and cleanup
|
||||
|
||||
## 1.0.0-beta.3 (2018-07-17)
|
||||
|
||||
+ For payment channel transactions, `getTransaction` includes a new
|
||||
`channelChanges` property that describes the details of the payment channel.
|
||||
(#920)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
+ A bug caused calculated fees to use too many decimal places. This was fixed by
|
||||
rounding fees to 6 decimal places. (#912)
|
||||
+ When using the Settings transaction to set up a multi-signing list, the
|
||||
threshold and weights fields are required. (#909)
|
||||
+ Docs: Fix the MIMETYPE in examples with memos. (#914)
|
||||
|
||||
The SHA-256 checksums for the browser version of this release can be found
|
||||
below.
|
||||
```
|
||||
% shasum -a 256 *
|
||||
460dbb521e24c44cb53dabc1a74feeca33d031b44d889dd5b51103ca92d51de6 ripple-1.0.0-beta.3-debug.js
|
||||
cccfd24973c6b7990d9e933a589175dae26249825737fff4f2f73d8558a3f186 ripple-1.0.0-beta.3-min.js
|
||||
0dc456a58fb078347d9920310621595905085595d73c2b8fe96bea73bcf35450 ripple-1.0.0-beta.3.js
|
||||
```
|
||||
|
||||
## 1.0.0-beta.2 (2018-06-08)
|
||||
|
||||
### Breaking Changes
|
||||
|
||||
+ During transaction preparation, there is now a maximum fee. Also, when a transaction is signed, its fee is checked and an error is thrown if the fee exceeds the maximum. The default `maxFeeXRP` is `'2'` (2 XRP). Override this value in the RippleAPI constructor.
|
||||
+ Attempting to prepare a transaction with an exact `fee` higher than `maxFeeXRP` causes a `ValidationError` to be thrown.
|
||||
+ Attempting to sign a transaction with a fee higher than `maxFeeXRP` causes a `ValidationError` to be thrown.
|
||||
+ The value returned by `getFee()` is capped at `maxFeeXRP`.
|
||||
|
||||
### Other Changes
|
||||
|
||||
+ In Transaction Instructions, the `maxFee` parameter is deprecated. Use the `maxFeeXRP` parameter in the RippleAPI constructor.
|
||||
|
||||
#### Overview of new fee limit
|
||||
|
||||
Most users of ripple-lib do not need to make any code changes to accommodate the new soft limit on fees. The limit is designed to protect against the most severe cases where an unintentionally high fee may be used.
|
||||
|
||||
+ When having ripple-lib provide the fee with a `prepare*` method, a maximum fee of `maxFeeXRP` (default 2 XRP) applies. You can prepare more economical transactions by setting a lower `maxFeeXRP`, or support high-priority transactions by setting a higher `maxFeeXRP` in the RippleAPI constructor.
|
||||
+ When using `sign` with a Fee higher than `maxFeeXRP`, a `ValidationError` is thrown.
|
||||
|
||||
If you have any questions or concerns, please open an issue on GitHub.
|
||||
|
||||
The SHA-256 checksums for the browser version of this release can be found
|
||||
below.
|
||||
```
|
||||
% shasum -a 256 *
|
||||
ef348a2805098e61395b689b410cbf4bfd35e4d72e38c89f4ab74ec5e19793f5 ripple-1.0.0-beta.2-debug.js
|
||||
ea33fd53df8c7176d5fbf52dae0b64aade7180860f26449062cdbefaf8bd4d9b ripple-1.0.0-beta.2-min.js
|
||||
fe5cc6e97c9b8a1470dacb34f16a64255cd639a25381abe9db1ba79e102456f2 ripple-1.0.0-beta.2.js
|
||||
```
|
||||
|
||||
## 1.0.0-beta.1 (2018-05-24)
|
||||
|
||||
### Breaking Changes
|
||||
|
||||
+ Amounts in drops and XRP are checked for validity. Some
|
||||
methods may now throw a `BigNumber Error` or `ValidationError` if the amount
|
||||
is invalid. This may include methods that previously did not throw.
|
||||
+ Note that 1 drop is equivalent to 0.000001 XRP and 1 XRP is equivalent to 1,000,000 drops.
|
||||
+ Using drops is recommended. All rippled APIs require XRP amounts to be
|
||||
expressed in drops.
|
||||
|
||||
### Other Changes
|
||||
|
||||
+ Allow specifying amounts in drops for consistency with the `rippled`
|
||||
APIs.
|
||||
+ Export `xrpToDrops()` and `dropsToXrp()` functions.
|
||||
+ Potentially breaking change: Improve errors. For example, `RippledError` now includes the full response from
|
||||
the `rippled` server ([#687](https://github.com/ripple/ripple-lib/issues/687)). `NotConnectedError`
|
||||
may be thrown with a different message than before.
|
||||
|
||||
The SHA-256 checksums for the browser version of this release can be found
|
||||
below.
|
||||
```
|
||||
% shasum -a 256 *
|
||||
a80ebb39e186640246306eadb2879147458c8271fd3c6cb32e6ef78d0b4b01a5 ripple-1.0.0-beta.1-debug.js
|
||||
81bcc4b5fd6fd52220ed151242eaddd63eb29c4078845edc68f65b769557d126 ripple-1.0.0-beta.1-min.js
|
||||
738b4d65b58cf4e3542fa396f8d319a24cd7d0b7aff5ff629a900e244f735ff4 ripple-1.0.0-beta.1.js
|
||||
```
|
||||
|
||||
## 1.0.0-beta.0 (2018-05-10)
|
||||
|
||||
+ [Add `request`, `hasNextPage`, and
|
||||
`requestNextPage`](https://github.com/ripple/ripple-lib/pull/887).
|
||||
+ This provides support for all rippled APIs, including subscriptions.
|
||||
|
||||
When using rippled APIs, you must:
|
||||
+ For all XRP amounts, use drops (1 drop = 0.000001 XRP).
|
||||
+ Instead of `counterparty`, use `issuer`.
|
||||
|
||||
The SHA-256 checksums for the browser version of this release can be found
|
||||
below.
|
||||
```
|
||||
% shasum -a 256 *
|
||||
ab2094979a3d6b320c7bc22bc5946c50fa5e29af0976d352e7689b0a4d840c55 ripple-1.0.0-beta.0-debug.js
|
||||
0e7f7d740606c2866ebf63776b13b41a555848e1a1419e2c8058d2e6c562d7fd ripple-1.0.0-beta.0-min.js
|
||||
bd05e8806832ca4192aea7ba2d0362baa9f44605f8e8e6676acd25eb0b94b778 ripple-1.0.0-beta.0.js
|
||||
```
|
||||
|
||||
## 0.22.0 (2018-05-10)
|
||||
|
||||
+ [`getOrderbook` - return raw order data](https://github.com/ripple/ripple-lib/pull/886). The full `BookOffer` data is now provided under `data`.
|
||||
@@ -61,6 +290,9 @@ below.
|
||||
## 0.19.0 (2018-03-02)
|
||||
|
||||
+ [Add support for Checks](https://github.com/ripple/ripple-lib/pull/853)
|
||||
+ **CheckCreate** adds a check entry to the ledger. The check is a promise from the source of the check that the destination of the check may cash the check and receive up to the SendMax specified on the check. The check may have an (optional) expiration, after which the check may no longer be cashed.
|
||||
+ **CheckCancel** removes the check from the ledger without transferring funds. Either the check's source or destination can cancel the check at any time. After a check has expired, any account can cancel the check.
|
||||
+ **CheckCash** is a request by the destination of the check to transfer a requested amount of funds, up to the check's SendMax, from the source to the destination. The destination may receive less than the SendMax due to transfer fees.
|
||||
+ [Add support for the Deposit Authorization account root flag](https://github.com/ripple/ripple-lib/pull/852)
|
||||
+ [Generate .ts.d TypeScript declaration files](https://github.com/ripple/ripple-lib/pull/851)
|
||||
+ [Improve documentation of getTransactions params](https://github.com/ripple/ripple-lib/pull/856)
|
||||
|
||||
46
README.md
46
README.md
@@ -2,8 +2,6 @@
|
||||
|
||||
A JavaScript API for interacting with the XRP Ledger
|
||||
|
||||
[](https://circleci.com/gh/ripple/ripple-lib/tree/develop) [](https://coveralls.io/r/ripple/ripple-lib?branch=develop)
|
||||
|
||||
[](https://www.npmjs.org/package/ripple-lib)
|
||||
|
||||
### Features
|
||||
@@ -12,27 +10,59 @@ A JavaScript API for interacting with the XRP Ledger
|
||||
+ Issue [rippled API](https://ripple.com/build/rippled-apis/) requests
|
||||
+ Listen to events on the XRP Ledger (transaction, ledger, etc.)
|
||||
+ Sign and submit transactions to the XRP Ledger
|
||||
+ Type definitions for TypeScript
|
||||
|
||||
## Getting Started
|
||||
|
||||
See also: [RippleAPI Beginners Guide](https://ripple.com/build/rippleapi-beginners-guide/)
|
||||
|
||||
You can use `npm`, but we recommend using `yarn` for the added assurance provided by `yarn.lock`.
|
||||
### Requirements
|
||||
|
||||
+ [Yarn Installation Instructions](https://yarnpkg.com/en/docs/install)
|
||||
+ **[Node v10](https://nodejs.org/)** is recommended. Other versions may work but are not frequently tested.
|
||||
+ **[Yarn](https://yarnpkg.com/)** is recommended. `npm` may work but we use `yarn.lock`.
|
||||
|
||||
Install `ripple-lib`:
|
||||
### Install
|
||||
|
||||
In an existing project (with `package.json`), install `ripple-lib`:
|
||||
```
|
||||
$ yarn add ripple-lib
|
||||
```
|
||||
|
||||
Then see the [documentation](https://github.com/ripple/ripple-lib/blob/develop/docs/index.md) and [code samples](https://github.com/ripple/ripple-lib/tree/develop/docs/samples)
|
||||
Then see the [documentation](https://github.com/ripple/ripple-lib/blob/develop/docs/index.md) and [code samples](https://github.com/ripple/ripple-lib/tree/develop/docs/samples).
|
||||
|
||||
## Running tests
|
||||
### Mailing Lists
|
||||
|
||||
We have a low-traffic mailing list for announcements of new ripple-lib releases. (About 1 email per week)
|
||||
|
||||
+ [Subscribe to ripple-lib-announce](https://groups.google.com/forum/#!forum/ripple-lib-announce)
|
||||
|
||||
If you're using the XRP Ledger in production, you should run a [rippled server](https://github.com/ripple/rippled) and subscribe to the ripple-server mailing list as well.
|
||||
|
||||
+ [Subscribe to ripple-server](https://groups.google.com/forum/#!forum/ripple-server)
|
||||
|
||||
## Development
|
||||
|
||||
To build the library for Node.js:
|
||||
```
|
||||
$ yarn compile
|
||||
```
|
||||
|
||||
The TypeScript compiler will [output](./tsconfig.json#L7) the resulting JS files in `./dist/npm/`.
|
||||
|
||||
To build the library for the browser:
|
||||
```
|
||||
$ yarn build
|
||||
```
|
||||
|
||||
Gulp will [output](./Gulpfile.js) the resulting JS files in `./build/`.
|
||||
|
||||
For more details, see the `scripts` in `package.json`.
|
||||
|
||||
## Running Tests
|
||||
|
||||
1. Clone the repository
|
||||
2. `cd` into the repository and install dependencies with `yarn install`
|
||||
3. `yarn test` or `yarn test --coverage` (`istanbul` will create coverage reports in `coverage/lcov-report/`)
|
||||
3. `yarn test`
|
||||
|
||||
## Generating Documentation
|
||||
|
||||
|
||||
790
docs/index.md
790
docs/index.md
File diff suppressed because it is too large
Load Diff
@@ -19,14 +19,13 @@ Currencies are represented as either 3-character currency codes or 40-character
|
||||
## Value
|
||||
A *value* is a quantity of a currency represented as a decimal string. Be careful: JavaScript's native number format does not have sufficient precision to represent all values. XRP has different precision from other currencies.
|
||||
|
||||
**XRP** has 6 significant digits past the decimal point. In other words, XRP cannot be divided into positive values smaller than `0.000001` (1e-6). XRP has a maximum value of `100000000000` (1e11).
|
||||
**XRP** has 6 significant digits past the decimal point. In other words, XRP cannot be divided into positive values smaller than `0.000001` (1e-6). This smallest unit is called a "drop". XRP has a maximum value of `100000000000` (1e11). Some RippleAPI methods accept XRP in order to maintain compatibility with older versions of the API. For consistency with the `rippled` APIs, we recommend formally specifying XRP values in *drops* in all API requests, and converting them to XRP for display. This is similar to Bitcoin's *satoshis* and Ethereum's *wei*. 1 XRP = 1,000,000 drops.
|
||||
|
||||
**Non-XRP values** have 16 decimal digits of precision, with a maximum value of `9999999999999999e80`. The smallest positive non-XRP value is `1e-81`.
|
||||
|
||||
|
||||
## Amount
|
||||
|
||||
Example amount:
|
||||
Example 100.00 USD amount:
|
||||
|
||||
```json
|
||||
{
|
||||
@@ -36,15 +35,16 @@ Example amount:
|
||||
}
|
||||
```
|
||||
|
||||
Example XRP amount:
|
||||
Example 3.0 XRP amount, in drops:
|
||||
```json
|
||||
{
|
||||
"currency": "XRP",
|
||||
"value": "2000"
|
||||
"currency": "drops",
|
||||
"value": "3000000"
|
||||
}
|
||||
```
|
||||
(Requires `ripple-lib` version 1.0.0 or higher.)
|
||||
|
||||
An *amount* is data structure representing a currency, a quantity of that currency, and the counterparty on the trustline that holds the value. For XRP, there is no counterparty.
|
||||
An *amount* is an object specifying a currency, a quantity of that currency, and the counterparty (issuer) on the trustline that holds the value. For XRP, there is no counterparty.
|
||||
|
||||
A *lax amount* allows the counterparty to be omitted for all currencies. If the counterparty is not specified in an amount within a transaction specification, then any counterparty may be used for that amount.
|
||||
|
||||
@@ -52,4 +52,4 @@ A *lax lax amount* allows either or both the counterparty and value to be omitte
|
||||
|
||||
A *balance* is an amount than can have a negative value.
|
||||
|
||||
<%- renderSchema('objects/amount-base.json') %>
|
||||
<%- renderSchema('objects/amountbase.json') %>
|
||||
|
||||
@@ -55,7 +55,7 @@ If you omit the `server` parameter, RippleAPI operates [offline](#offline-functi
|
||||
|
||||
1. Install [Node.js](https://nodejs.org) and [Yarn](https://yarnpkg.com/en/docs/install). Most Linux distros have a package for Node.js; check that it's the version you want.
|
||||
2. Use yarn to install RippleAPI:
|
||||
`yarn install ripple-lib`
|
||||
`yarn add ripple-lib`
|
||||
|
||||
After you have installed ripple-lib, you can create scripts using the [boilerplate](#boilerplate) and run them using the Node.js executable, typically named `node`:
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## computeLedgerHash
|
||||
|
||||
`computeLedgerHash(ledger: Object): string`
|
||||
`computeLedgerHash(ledger: object): string`
|
||||
|
||||
Compute the hash of a ledger.
|
||||
|
||||
|
||||
19
docs/src/deriveAddress.md.ejs
Normal file
19
docs/src/deriveAddress.md.ejs
Normal file
@@ -0,0 +1,19 @@
|
||||
## deriveAddress
|
||||
|
||||
`deriveAddress(publicKey: string): string`
|
||||
|
||||
Derive an XRP Ledger address from a public key.
|
||||
|
||||
### Parameters
|
||||
|
||||
This method takes one parameter, the public key from which to derive the address.
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns a string corresponding to the address derived from the public key.
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
var address = api.deriveAddress(public_key);
|
||||
```
|
||||
21
docs/src/deriveKeypair.md.ejs
Normal file
21
docs/src/deriveKeypair.md.ejs
Normal file
@@ -0,0 +1,21 @@
|
||||
## deriveKeypair
|
||||
|
||||
`deriveKeypair(seed: string): {privateKey: string, publicKey: string}`
|
||||
|
||||
Derive a public and private key from a seed.
|
||||
|
||||
### Parameters
|
||||
|
||||
This method takes one parameter, the seed from which to derive the public and private key.
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns an object containing the public and private components of the keypair corresponding to the seed.
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
var keypair = api.deriveKeypair(seed)
|
||||
var public_key = keypair.publicKey;
|
||||
var private_key = keypair.privateKey;
|
||||
```
|
||||
@@ -1,6 +1,6 @@
|
||||
## getAccountInfo
|
||||
|
||||
`getAccountInfo(address: string, options: Object): Promise<Object>`
|
||||
`getAccountInfo(address: string, options: object): Promise<object>`
|
||||
|
||||
Returns information for the specified account. Note: For account data that is modifiable by the user, see [getSettings](#getsettings).
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## getBalanceSheet
|
||||
|
||||
`getBalanceSheet(address: string, options: Object): Promise<Object>`
|
||||
`getBalanceSheet(address: string, options: object): Promise<object>`
|
||||
|
||||
Returns aggregate balances by currency plus a breakdown of assets and obligations for a specified account.
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## getBalances
|
||||
|
||||
`getBalances(address: string, options: Object): Promise<Array<Object>>`
|
||||
`getBalances(address: string, options: object): Promise<Array<object>>`
|
||||
|
||||
Returns balances for a specified account.
|
||||
|
||||
|
||||
@@ -4,13 +4,15 @@
|
||||
|
||||
Returns the estimated transaction fee for the rippled server the RippleAPI instance is connected to.
|
||||
|
||||
This will use the [feeCushion parameter](#parameters) provided to the RippleAPI constructor, or the default value of `1.2`.
|
||||
|
||||
### Parameters
|
||||
|
||||
This method has no parameters.
|
||||
<%- renderSchema('input/get-fee.json') %>
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns a promise that resolves with a string encoded floating point value representing the estimated fee to submit a transaction, expressed in XRP.
|
||||
This method returns a promise that resolves with a string-encoded floating point value representing the estimated fee to submit a transaction, expressed in XRP.
|
||||
|
||||
### Example
|
||||
|
||||
@@ -19,5 +21,5 @@ return api.getFee().then(fee => {/* ... */});
|
||||
```
|
||||
|
||||
```json
|
||||
"0.012"
|
||||
"0.000012"
|
||||
```
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## getLedger
|
||||
|
||||
`getLedger(options: Object): Promise<Object>`
|
||||
`getLedger(options: object): Promise<object>`
|
||||
|
||||
Returns header information for the specified ledger (or the most recent validated ledger if no ledger is specified). Optionally, all the transactions that were validated in the ledger or the account state information can be returned with the ledger header.
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## getOrderbook
|
||||
|
||||
`getOrderbook(address: string, orderbook: Object, options: Object): Promise<Object>`
|
||||
`getOrderbook(address: string, orderbook: object, options: object): Promise<object>`
|
||||
|
||||
Returns open orders for the specified account. Open orders are orders that have not yet been fully executed and are still in the order book.
|
||||
|
||||
@@ -14,9 +14,9 @@ This method returns a promise that resolves with an object with the following st
|
||||
|
||||
<%- renderSchema('output/get-orderbook.json') %>
|
||||
|
||||
### New in ripple-lib 0.22.0 and higher
|
||||
### Raw order data
|
||||
|
||||
The response includes a `data` property containing the raw order data. This may include `owner_funds`, `Flags`, and other fields.
|
||||
(Requires ripple-lib 0.22.0 or higher.) The response includes a `data` property containing the raw order data. This may include `owner_funds`, `Flags`, and other fields.
|
||||
|
||||
For details, see the rippled method [book_offers](https://ripple.com/build/rippled-apis/#book-offers).
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## getOrders
|
||||
|
||||
`getOrders(address: string, options: Object): Promise<Array<Object>>`
|
||||
`getOrders(address: string, options: object): Promise<Array<object>>`
|
||||
|
||||
Returns open orders for the specified account. Open orders are orders that have not yet been fully executed and are still in the order book.
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## getPaths
|
||||
|
||||
`getPaths(pathfind: Object): Promise<Array<Object>>`
|
||||
`getPaths(pathfind: object): Promise<Array<object>>`
|
||||
|
||||
Finds paths to send a payment. Paths are options for how to route a payment.
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## getPaymentChannel
|
||||
|
||||
`getPaymentChannel(id: string): Promise<Object>`
|
||||
`getPaymentChannel(id: string): Promise<object>`
|
||||
|
||||
Returns specified payment channel.
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## getSettings
|
||||
|
||||
`getSettings(address: string, options: Object): Promise<Object>`
|
||||
`getSettings(address: string, options: object): Promise<object>`
|
||||
|
||||
Returns settings for the specified account. Note: For account data that is not modifiable by the user, see [getAccountInfo](#getaccountinfo).
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## getTransaction
|
||||
|
||||
`getTransaction(id: string, options: Object): Promise<Object>`
|
||||
`getTransaction(id: string, options: object): Promise<object>`
|
||||
|
||||
Retrieves a transaction by its [Transaction ID](#transaction-id).
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## getTransactions
|
||||
|
||||
`getTransactions(address: string, options: Object): Promise<Array<Object>>`
|
||||
`getTransactions(address: string, options: object): Promise<Array<object>>`
|
||||
|
||||
Retrieves historical transactions of an account.
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## getTrustlines
|
||||
|
||||
`getTrustlines(address: string, options: Object): Promise<Array<Object>>`
|
||||
`getTrustlines(address: string, options: object): Promise<Array<object>>`
|
||||
|
||||
Returns trustlines for a specified account.
|
||||
|
||||
|
||||
27
docs/src/hasNextPage.md.ejs
Normal file
27
docs/src/hasNextPage.md.ejs
Normal file
@@ -0,0 +1,27 @@
|
||||
## hasNextPage
|
||||
|
||||
`hasNextPage(currentResponse): boolean`
|
||||
|
||||
Returns `true` when there are more pages available.
|
||||
|
||||
When there are more results than contained in the response, the response includes a `marker` field. You can use this convenience method, or check for `marker` yourself.
|
||||
|
||||
See [Markers and Pagination](https://ripple.com/build/rippled-apis/#markers-and-pagination).
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns `true` if `currentResponse` includes a `marker`.
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
return api.request('ledger_data', {
|
||||
ledger_index: 'validated'
|
||||
}).then(response => {
|
||||
/* Do something useful with response */
|
||||
|
||||
if (api.hasNextPage(response)) {
|
||||
/* There are more pages available */
|
||||
}
|
||||
}).catch(console.error);
|
||||
```
|
||||
@@ -4,6 +4,10 @@
|
||||
<% include basictypes.md.ejs %>
|
||||
<% include transactions.md.ejs %>
|
||||
<% include specifications.md.ejs %>
|
||||
<% include rippledAPIs.md.ejs %>
|
||||
<% include request.md.ejs %>
|
||||
<% include hasNextPage.md.ejs %>
|
||||
<% include requestNextPage.md.ejs %>
|
||||
<% include methods.md.ejs %>
|
||||
<% include connect.md.ejs %>
|
||||
<% include disconnect.md.ejs %>
|
||||
@@ -24,6 +28,8 @@
|
||||
<% include getAccountObjects.md.ejs %>
|
||||
<% include getPaymentChannel.md.ejs %>
|
||||
<% include getLedger.md.ejs %>
|
||||
<% include parseAccountFlags.md.ejs %>
|
||||
<% include prepareTransaction.md.ejs %>
|
||||
<% include preparePayment.md.ejs %>
|
||||
<% include prepareTrustline.md.ejs %>
|
||||
<% include prepareOrder.md.ejs %>
|
||||
@@ -42,7 +48,15 @@
|
||||
<% include combine.md.ejs %>
|
||||
<% include submit.md.ejs %>
|
||||
<% include generateAddress.md.ejs %>
|
||||
<% include isValidAddress.md.ejs %>
|
||||
<% include isValidSecret.md.ejs %>
|
||||
<% include deriveKeypair.md.ejs %>
|
||||
<% include deriveAddress.md.ejs %>
|
||||
<% include signPaymentChannelClaim.md.ejs %>
|
||||
<% include verifyPaymentChannelClaim.md.ejs %>
|
||||
<% include computeLedgerHash.md.ejs %>
|
||||
<% include xrpToDropsAndDropsToXrp.md.ejs %>
|
||||
<% include iso8601ToRippleTime.md.ejs %>
|
||||
<% include txFlags.md.ejs %>
|
||||
<% include schemaValidator.md.ejs %>
|
||||
<% include events.md.ejs %>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Introduction
|
||||
|
||||
RippleAPI is the official client library to the XRP Ledger. Currently, RippleAPI is only available in JavaScript.
|
||||
RippleAPI (ripple-lib) is the official client library to the XRP Ledger. Currently, RippleAPI is only available in JavaScript.
|
||||
Using RippleAPI, you can:
|
||||
|
||||
* [Query transactions from the XRP Ledger history](#gettransaction)
|
||||
@@ -8,5 +8,3 @@ Using RippleAPI, you can:
|
||||
* [Submit](#submit) transactions to the XRP Ledger, including [Payments](#payment), [Orders](#order), [Settings changes](#settings), and [other types](#transaction-types)
|
||||
* [Generate a new XRP Ledger Address](#generateaddress)
|
||||
* ... and [much more](#api-methods).
|
||||
|
||||
RippleAPI only provides access to *validated*, *immutable* transaction data.
|
||||
|
||||
19
docs/src/isValidAddress.md.ejs
Normal file
19
docs/src/isValidAddress.md.ejs
Normal file
@@ -0,0 +1,19 @@
|
||||
## isValidAddress
|
||||
|
||||
`isValidAddress(address: string): boolean`
|
||||
|
||||
Checks if the specified string contains a valid address.
|
||||
|
||||
### Parameters
|
||||
|
||||
This method takes one parameter, the address to validate.
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns `true` if the address is valid and `false` if it is not.
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
return api.isValidAddress("address")
|
||||
```
|
||||
19
docs/src/isValidSecret.md.ejs
Normal file
19
docs/src/isValidSecret.md.ejs
Normal file
@@ -0,0 +1,19 @@
|
||||
## isValidSecret
|
||||
|
||||
`isValidSecret(secret: string): boolean`
|
||||
|
||||
Checks if the specified string contains a valid secret.
|
||||
|
||||
### Parameters
|
||||
|
||||
This method takes one parameter, the secret which to validate.
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns `true` if the secret is valid and `false` if it is not.
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
return api.isValidSecret("secret")
|
||||
```
|
||||
27
docs/src/iso8601ToRippleTime.md.ejs
Normal file
27
docs/src/iso8601ToRippleTime.md.ejs
Normal file
@@ -0,0 +1,27 @@
|
||||
## iso8601ToRippleTime
|
||||
|
||||
`iso8601ToRippleTime(iso8601: string): number`
|
||||
|
||||
This method parses a string representation of a date, and returns the number of seconds since the "Ripple Epoch" of January 1, 2000 (00:00 UTC).
|
||||
|
||||
The Ripple Epoch is 946684800 seconds after the Unix Epoch.
|
||||
|
||||
This method is useful for creating timestamps to use with the rippled APIs. The rippled APIs represent time as an unsigned integer of the number of seconds since the Ripple Epoch.
|
||||
|
||||
### Parameters
|
||||
|
||||
`iso8601`: A string representing a date and time. This string is parsed using JavaScript's `Date.parse()` method.
|
||||
|
||||
### Return Value
|
||||
|
||||
The number of seconds since the Ripple Epoch.
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
api.iso8601ToRippleTime('2017-02-17T15:04:57Z');
|
||||
```
|
||||
|
||||
```json
|
||||
540659097
|
||||
```
|
||||
35
docs/src/parseAccountFlags.md.ejs
Normal file
35
docs/src/parseAccountFlags.md.ejs
Normal file
@@ -0,0 +1,35 @@
|
||||
## parseAccountFlags
|
||||
|
||||
`parseAccountFlags(Flags: number): object`
|
||||
|
||||
Parse an `AccountRoot` object's [`Flags`](https://developers.ripple.com/accountroot.html#accountroot-flags).
|
||||
|
||||
### Parameters
|
||||
|
||||
This method takes one parameter, the AccountRoot `Flags` number to parse. Note that flags have different mappings on other types of objects or in transactions such as AccountSet.
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns an object with containing a key for each AccountRoot flag known to this version of RippleAPI. Each flag has a boolean value of `true` or `false`.
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
const account_info = await api.request('account_info', {account: 'rKsdkGhyZH6b2Zzd5hNnEqSv2wpznn4n6N'})
|
||||
const flags = api.parseAccountFlags(account_info.account_data.Flags)
|
||||
console.log(JSON.stringify(flags, null, 2))
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"passwordSpent": false,
|
||||
"requireDestinationTag": false,
|
||||
"requireAuthorization": false,
|
||||
"depositAuth": true,
|
||||
"disallowIncomingXRP": false,
|
||||
"disableMasterKey": false,
|
||||
"noFreeze": false,
|
||||
"globalFreeze": false,
|
||||
"defaultRipple": false
|
||||
}
|
||||
```
|
||||
@@ -1,6 +1,6 @@
|
||||
## prepareCheckCancel
|
||||
|
||||
`prepareCheckCancel(address: string, checkCancel: Object, instructions: Object): Promise<Object>`
|
||||
`prepareCheckCancel(address: string, checkCancel: object, instructions: object): Promise<object>`
|
||||
|
||||
Prepare a Check cancellation transaction. This cancels an unredeemed Check, removing it from the ledger without sending any money. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit).
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## prepareCheckCash
|
||||
|
||||
`prepareCheckCash(address: string, checkCash: Object, instructions: Object): Promise<Object>`
|
||||
`prepareCheckCash(address: string, checkCash: object, instructions: object): Promise<object>`
|
||||
|
||||
Prepare a Check cashing transaction. This redeems a Check to receive up to the amount authorized by the corresponding CheckCreate transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit).
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## prepareCheckCreate
|
||||
|
||||
`prepareCheckCreate(address: string, checkCreate: Object, instructions: Object): Promise<Object>`
|
||||
`prepareCheckCreate(address: string, checkCreate: object, instructions: object): Promise<object>`
|
||||
|
||||
Prepare a Check creation transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit).
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## prepareEscrowCancellation
|
||||
|
||||
`prepareEscrowCancellation(address: string, escrowCancellation: Object, instructions: Object): Promise<Object>`
|
||||
`prepareEscrowCancellation(address: string, escrowCancellation: object, instructions: object): Promise<object>`
|
||||
|
||||
Prepare an escrow cancellation transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit).
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## prepareEscrowCreation
|
||||
|
||||
`prepareEscrowCreation(address: string, escrowCreation: Object, instructions: Object): Promise<Object>`
|
||||
`prepareEscrowCreation(address: string, escrowCreation: object, instructions: object): Promise<object>`
|
||||
|
||||
Prepare an escrow creation transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit).
|
||||
|
||||
@@ -8,6 +8,12 @@ Prepare an escrow creation transaction. The prepared transaction must subsequent
|
||||
|
||||
<%- renderSchema('input/prepare-escrow-creation.json') %>
|
||||
|
||||
This is a convenience method for generating the EscrowCreate JSON used by rippled, so the same restrictions apply.
|
||||
|
||||
Field mapping: `allowCancelAfter` is equivalent to rippled's `CancelAfter`; `allowExecuteAfter` is equivalent to `FinishAfter`. At the `allowCancelAfter` time, the escrow is considered expired. This means that the funds can only be returned to the sender. At the `allowExecuteAfter` time, the escrow is permitted to be released to the recipient (if the `condition` is fulfilled).
|
||||
|
||||
Note that `allowCancelAfter` must be chronologically later than `allowExecuteAfter`.
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns a promise that resolves with an object with the following structure:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## prepareEscrowExecution
|
||||
|
||||
`prepareEscrowExecution(address: string, escrowExecution: Object, instructions: Object): Promise<Object>`
|
||||
`prepareEscrowExecution(address: string, escrowExecution: object, instructions: object): Promise<object>`
|
||||
|
||||
Prepare an escrow execution transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit).
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## prepareOrder
|
||||
|
||||
`prepareOrder(address: string, order: Object, instructions: Object): Promise<Object>`
|
||||
`prepareOrder(address: string, order: object, instructions: object): Promise<object>`
|
||||
|
||||
Prepare an order transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit).
|
||||
|
||||
@@ -22,6 +22,8 @@ All "prepare*" methods have the same return type.
|
||||
|
||||
```javascript
|
||||
const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59';
|
||||
|
||||
// Buy 10.10 USD (of the specified issuer) for 2.0 XRP (2000000 drops), fill or kill.
|
||||
const order = <%- importFile('test/fixtures/requests/prepare-order.json') %>;
|
||||
return api.prepareOrder(address, order)
|
||||
.then(prepared => {/* ... */});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## prepareOrderCancellation
|
||||
|
||||
`prepareOrderCancellation(address: string, orderCancellation: Object, instructions: Object): Promise<Object>`
|
||||
`prepareOrderCancellation(address: string, orderCancellation: object, instructions: object): Promise<object>`
|
||||
|
||||
Prepare an order cancellation transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit).
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## preparePayment
|
||||
|
||||
`preparePayment(address: string, payment: Object, instructions: Object): Promise<Object>`
|
||||
`preparePayment(address: string, payment: object, instructions: object): Promise<object>`
|
||||
|
||||
Prepare a payment transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit).
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## preparePaymentChannelClaim
|
||||
|
||||
`preparePaymentChannelClaim(address: string, paymentChannelClaim: Object, instructions: Object): Promise<Object>`
|
||||
`preparePaymentChannelClaim(address: string, paymentChannelClaim: object, instructions: object): Promise<object>`
|
||||
|
||||
Prepare a payment channel claim transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit).
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## preparePaymentChannelCreate
|
||||
|
||||
`preparePaymentChannelCreate(address: string, paymentChannelCreate: Object, instructions: Object): Promise<Object>`
|
||||
`preparePaymentChannelCreate(address: string, paymentChannelCreate: object, instructions: object): Promise<object>`
|
||||
|
||||
Prepare a payment channel creation transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit).
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## preparePaymentChannelFund
|
||||
|
||||
`preparePaymentChannelFund(address: string, paymentChannelFund: Object, instructions: Object): Promise<Object>`
|
||||
`preparePaymentChannelFund(address: string, paymentChannelFund: object, instructions: object): Promise<object>`
|
||||
|
||||
Prepare a payment channel fund transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit).
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## prepareSettings
|
||||
|
||||
`prepareSettings(address: string, settings: Object, instructions: Object): Promise<Object>`
|
||||
`prepareSettings(address: string, settings: object, instructions: object): Promise<object>`
|
||||
|
||||
Prepare a settings transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit).
|
||||
|
||||
|
||||
50
docs/src/prepareTransaction.md.ejs
Normal file
50
docs/src/prepareTransaction.md.ejs
Normal file
@@ -0,0 +1,50 @@
|
||||
## prepareTransaction
|
||||
|
||||
`prepareTransaction(address: string, transaction: object, instructions: object): Promise<object>`
|
||||
|
||||
Prepare a transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit).
|
||||
|
||||
This method works with any of [the transaction types supported by rippled](https://developers.ripple.com/transaction-types.html).
|
||||
|
||||
Notably, this is the preferred method for preparing a `DepositPreauth` transaction (added in rippled 1.1.0).
|
||||
|
||||
### Parameters
|
||||
|
||||
Name | Type | Description
|
||||
---- | ---- | -----------
|
||||
transaction | [transaction](https://developers.ripple.com/transaction-formats.html) | The specification (JSON) of the transaction to prepare. Set `Account` to the address of the account that is creating the transaction. You may omit auto-fillable fields like `Fee`, `Flags`, and `Sequence` to have them set automatically.
|
||||
instructions | [instructions](#transaction-instructions) | *Optional* Instructions for executing the transaction.
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns a promise that resolves with an object with the following structure:
|
||||
|
||||
<aside class="notice">
|
||||
All "prepare*" methods have the same return type.
|
||||
</aside>
|
||||
|
||||
<%- renderSchema("output/prepare.json") %>
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
async function preparedPreauth() {
|
||||
const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59';
|
||||
return api.prepareTransaction({
|
||||
TransactionType: 'DepositPreauth',
|
||||
Account: address,
|
||||
Authorize: 'rMyVso4p83khNyHdV1m1PggV9QNadCj8wM'
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
```javascript
|
||||
{
|
||||
txJSON: '{"TransactionType":"DepositPreauth","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Authorize":"rMyVso4p83khNyHdV1m1PggV9QNadCj8wM","Flags":2147483648,"LastLedgerSequence":13561714,"Fee":"12","Sequence":1}',
|
||||
instructions: {
|
||||
fee: '0.000012',
|
||||
sequence: 1,
|
||||
maxLedgerVersion: 13561714
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -1,6 +1,6 @@
|
||||
## prepareTrustline
|
||||
|
||||
`prepareTrustline(address: string, trustline: Object, instructions: Object): Promise<Object>`
|
||||
`prepareTrustline(address: string, trustline: object, instructions: object): Promise<object>`
|
||||
|
||||
Prepare a trustline transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit).
|
||||
|
||||
|
||||
27
docs/src/request.md.ejs
Normal file
27
docs/src/request.md.ejs
Normal file
@@ -0,0 +1,27 @@
|
||||
## request
|
||||
|
||||
`request(command: string, options: object): Promise<object>`
|
||||
|
||||
Returns the response from invoking the specified command, with the specified options, on the connected rippled server.
|
||||
|
||||
Refer to [rippled APIs](https://ripple.com/build/rippled-apis/) for commands and options. All XRP amounts must be specified in drops. One drop is equal to 0.000001 XRP. See [Specifying Currency Amounts](https://ripple.com/build/rippled-apis/#specifying-currency-amounts).
|
||||
|
||||
Most commands return data for the `current` (in-progress, open) ledger by default. Do not rely on this. Always specify a ledger version in your request. In the example below, the 'validated' ledger is requested, which is the most recent ledger that has been validated by the whole network. See [Specifying Ledgers](https://ripple.com/build/rippled-apis/#specifying-ledgers).
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns a promise that resolves with the response from rippled.
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
// Replace 'ledger' with your desired rippled command
|
||||
return api.request('ledger', {
|
||||
ledger_index: 'validated'
|
||||
}).then(response => {
|
||||
/* Do something useful with response */
|
||||
console.log(JSON.stringify(response, null, 2))
|
||||
}).catch(console.error);
|
||||
```
|
||||
|
||||
<%- renderFixture('responses/ledger.json') %>
|
||||
29
docs/src/requestNextPage.md.ejs
Normal file
29
docs/src/requestNextPage.md.ejs
Normal file
@@ -0,0 +1,29 @@
|
||||
## requestNextPage
|
||||
|
||||
`requestNextPage(command: string, params: object = {}, currentResponse: object): Promise<object>`
|
||||
|
||||
Requests the next page of data.
|
||||
|
||||
You can use this convenience method, or include `currentResponse.marker` in `params` yourself, when using `request`.
|
||||
|
||||
See [Markers and Pagination](https://ripple.com/build/rippled-apis/#markers-and-pagination).
|
||||
|
||||
### Return Value
|
||||
|
||||
This method returns a promise that resolves with the next page of data from rippled.
|
||||
|
||||
If the response does not have a next page, the promise will reject with `new errors.NotFoundError('response does not have a next page')`.
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
const command = 'ledger_data'
|
||||
const params = {
|
||||
ledger_index: 'validated'
|
||||
}
|
||||
return api.request(command, params).then(response => {
|
||||
return api.requestNextPage(command, params, response)
|
||||
}).then(response_page_2 => {
|
||||
/* Do something useful with second page of response */
|
||||
}).catch(console.error);
|
||||
```
|
||||
69
docs/src/rippledAPIs.md.ejs
Normal file
69
docs/src/rippledAPIs.md.ejs
Normal file
@@ -0,0 +1,69 @@
|
||||
# rippled APIs
|
||||
|
||||
ripple-lib relies on [rippled APIs](https://ripple.com/build/rippled-apis/) for all online functionality. With ripple-lib version 1.0.0 and higher, you can easily access rippled APIs through ripple-lib. Use the `request()`, `hasNextPage()`, and `requestNextPage()` methods:
|
||||
* Use `request()` to issue any `rippled` command, including `account_currencies`, `subscribe`, and `unsubscribe`. [Full list of API Methods](https://ripple.com/build/rippled-apis/#api-methods).
|
||||
* Use `hasNextPage()` to determine whether a response has more pages. This is true when the response includes a [`marker` field](https://ripple.com/build/rippled-apis/#markers-and-pagination).
|
||||
* Use `requestNextPage()` to request the next page of data.
|
||||
|
||||
When using rippled APIs:
|
||||
* [Specify XRP amounts in drops](https://developers.ripple.com/basic-data-types.html#specifying-currency-amounts).
|
||||
* [Specify timestamps as the number of seconds since the "Ripple Epoch"](https://developers.ripple.com/basic-data-types.html#specifying-time).
|
||||
* Instead of `counterparty`, use `issuer`.
|
||||
|
||||
## Listening to streams
|
||||
|
||||
The `rippled` server can push updates to your client when various events happen. Refer to [Subscriptions in the `rippled` API docs](https://developers.ripple.com/subscription-methods.html) for details.
|
||||
|
||||
Note that the `streams` parameter for generic streams takes an array. For example, to subscribe to the `validations` stream, use `{ streams: [ 'validations' ] }`.
|
||||
|
||||
The string names of some generic streams to subscribe to are in the table below. (Refer to `rippled` for an up-to-date list of streams.)
|
||||
|
||||
Type | Description
|
||||
---- | -----------
|
||||
`server` | Sends a message whenever the status of the `rippled` server (for example, network connectivity) changes.
|
||||
`ledger` | Sends a message whenever the consensus process declares a new validated ledger.
|
||||
`transactions` | Sends a message whenever a transaction is included in a closed ledger.
|
||||
`transactions_proposed` | Sends a message whenever a transaction is included in a closed ledger, as well as some transactions that have not yet been included in a validated ledger and may never be. Not all proposed transactions appear before validation. Even some transactions that don't succeed are included in validated ledgers because they take the anti-spam transaction fee.
|
||||
`validations` | Sends a message whenever the server receives a validation message, also called a validation vote, regardless of whether the server trusts the validator.
|
||||
`manifests` | Sends a message whenever the server receives a manifest.
|
||||
`peer_status` | (Admin-only) Information about connected peer `rippled` servers, especially with regards to the consensus process.
|
||||
|
||||
When you subscribe to a stream, you must also listen to the relevant message type(s). Some of the available message types are in the table below. (Refer to `rippled` for an up-to-date list of message types.)
|
||||
|
||||
Type | Description
|
||||
---- | -----------
|
||||
`ledgerClosed` | Sent by the `ledger` stream when the consensus process declares a new fully validated ledger. The message identifies the ledger and provides some information about its contents.
|
||||
`validationReceived` | Sent by the `validations` stream when the server receives a validation message, also called a validation vote, regardless of whether the server trusts the validator.
|
||||
`manifestReceived` | Sent by the `manifests` stream when the server receives a manifest.
|
||||
`transaction` | Sent by many subscriptions including `transactions`, `transactions_proposed`, `accounts`, `accounts_proposed`, and `book` (Order Book). See [Transaction Streams](https://ripple.com/build/rippled-apis/#transaction-streams) for details.
|
||||
`peerStatusChange` | (Admin-only) Reports a large amount of information on the activities of other `rippled` servers to which the server is connected.
|
||||
|
||||
To register your listener function, use `connection.on(type, handler)`.
|
||||
|
||||
Here is an example of listening for transactions on given account(s):
|
||||
```
|
||||
const account = 'rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn' // Replace with the account you want notifications for
|
||||
api.connect().then(() => { // Omit this if you are already connected
|
||||
|
||||
// 'transaction' can be replaced with the relevant `type` from the table above
|
||||
api.connection.on('transaction', (event) => {
|
||||
|
||||
// Do something useful with `event`
|
||||
console.log(JSON.stringify(event, null, 2))
|
||||
})
|
||||
|
||||
api.request('subscribe', {
|
||||
accounts: [ account ]
|
||||
}).then(response => {
|
||||
if (response.status === 'success') {
|
||||
console.log('Successfully subscribed')
|
||||
}
|
||||
}).catch(error => {
|
||||
// Handle `error`
|
||||
})
|
||||
})
|
||||
```
|
||||
|
||||
The subscription ends when you unsubscribe or the WebSocket connection is closed.
|
||||
|
||||
For full details, see [rippled Subscriptions](https://ripple.com/build/rippled-apis/#subscriptions).
|
||||
35
docs/src/schemaValidator.md.ejs
Normal file
35
docs/src/schemaValidator.md.ejs
Normal file
@@ -0,0 +1,35 @@
|
||||
## schemaValidator
|
||||
|
||||
Unlike the rest of the ripple-lib API, schemaValidator is a static object on RippleAPI. It provides utility methods that do not use a server.
|
||||
|
||||
## schemaValidate
|
||||
|
||||
`RippleAPI.schemaValidator.schemaValidate(schemaName: string, object: any): void`
|
||||
|
||||
This method checks an object for conformance to a specified schema. It does not return anything, but will throw a `ValidationError` if the object does not conform to the schema.
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
RippleAPI.schemaValidator.schemaValidate('sign', {
|
||||
signedTransaction: '12000322800000002400000017201B0086955368400000000000000C732102F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D874473045022100BDE09A1F6670403F341C21A77CF35BA47E45CDE974096E1AA5FC39811D8269E702203D60291B9A27F1DCABA9CF5DED307B4F23223E0B6F156991DB601DFB9C41CE1C770A726970706C652E636F6D81145E7B112523F68D2F5E879DB4EAC51C6698A69304',
|
||||
id: '02ACE87F1996E3A23690A5BB7F1774BF71CCBA68F79805831B42ABAD5913D6F4'
|
||||
})
|
||||
```
|
||||
|
||||
```json
|
||||
undefined
|
||||
```
|
||||
|
||||
If the object is valid (conforms to the schema), nothing is returned. Otherwise, `schemaValidate` throws an error:
|
||||
|
||||
```javascript
|
||||
RippleAPI.schemaValidator.schemaValidate('sign', {
|
||||
signedTransaction: '12000322800000002400000017201B0086955368400000000000000C732102F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D874473045022100BDE09A1F6670403F341C21A77CF35BA47E45CDE974096E1AA5FC39811D8269E702203D60291B9A27F1DCABA9CF5DED307B4F23223E0B6F156991DB601DFB9C41CE1C770A726970706C652E636F6D81145E7B112523F68D2F5E879DB4EAC51C6698A69304',
|
||||
id: '123'
|
||||
})
|
||||
```
|
||||
|
||||
```
|
||||
[ValidationError(instance.id does not match pattern "^[A-F0-9]{64}$")]
|
||||
```
|
||||
@@ -1,12 +1,16 @@
|
||||
## sign
|
||||
|
||||
```
|
||||
sign(txJSON: string, secret: string, options: Object): {signedTransaction: string, id: string}
|
||||
sign(txJSON: string, keypair: Object, options: Object): {signedTransaction: string, id: string}
|
||||
sign(txJSON: string, secret: string, options: object): {signedTransaction: string, id: string}
|
||||
sign(txJSON: string, keypair: object, options: object): {signedTransaction: string, id: string}
|
||||
```
|
||||
|
||||
Sign a prepared transaction. The signed transaction must subsequently be [submitted](#submit).
|
||||
|
||||
This method can sign any of [the transaction types supported by ripple-binary-codec](https://github.com/ripple/ripple-binary-codec/blob/cfcde79c19c359e9a0466d7bc3dc9a3aef47bb99/src/enums/definitions.json#L1637). When a new transaction type is added to the XRP Ledger, it will be unrecognized until `ripple-binary-codec` is updated. If you try to sign an unrecognized transaction type, this method throws an error similar to the following:
|
||||
|
||||
`Error: [TRANSACTION_TYPE] is not a valid name or ordinal for TransactionType`
|
||||
|
||||
### Parameters
|
||||
|
||||
<%- renderSchema("input/sign.json") %>
|
||||
|
||||
@@ -28,6 +28,8 @@ See [Transaction Types](#transaction-types) for a description.
|
||||
|
||||
<%- renderSchema('specifications/order.json') %>
|
||||
|
||||
The following invalid flag combination causes a `ValidationError`: `immediateOrCancel` and `fillOrKill`. These fields are mutually exclusive, and cannot both be set at the same time.
|
||||
|
||||
### Example
|
||||
|
||||
<%- renderFixture('requests/prepare-order.json') %>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## submit
|
||||
|
||||
`submit(signedTransaction: string): Promise<Object>`
|
||||
`submit(signedTransaction: string): Promise<object>`
|
||||
|
||||
Submits a signed transaction. The transaction is not guaranteed to succeed; it must be verified with [getTransaction](#gettransaction).
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ Transaction instructions indicate how to execute a transaction, complementary wi
|
||||
|
||||
<%- renderSchema("objects/instructions.json") %>
|
||||
|
||||
We recommended that you specify a `maxLedgerVersion` so that you can quickly determine that a failed transaction will never succeeed in the future. It is impossible for a transaction to succeed after the XRP Ledger's consensus-validated ledger version exceeds the transaction's `maxLedgerVersion`. If you omit `maxLedgerVersion`, the "prepare*" method automatically supplies a `maxLedgerVersion` equal to the current ledger plus 3, which it includes in the return value from the "prepare*" method.
|
||||
We recommend that you specify a `maxLedgerVersion` so that you can quickly determine that a failed transaction will never succeeed in the future. It is impossible for a transaction to succeed after the XRP Ledger's consensus-validated ledger version exceeds the transaction's `maxLedgerVersion`. If you omit `maxLedgerVersion`, the "prepare\*" method automatically supplies a `maxLedgerVersion` equal to the current ledger plus 3, which it includes in the return value from the "prepare\*" method.
|
||||
|
||||
## Transaction ID
|
||||
|
||||
|
||||
81
docs/src/txFlags.md.ejs
Normal file
81
docs/src/txFlags.md.ejs
Normal file
@@ -0,0 +1,81 @@
|
||||
## txFlags
|
||||
|
||||
`txFlags.TRANSACTION_TYPE.FLAG`
|
||||
|
||||
This object provides constants for use when creating or interpreting transaction flags. Most transactions have a set of bit-flags that represent various options that affect how a transaction should behave. These options are represented as binary values that can be combined with bitwise-or operations to encode multiple flags at once.
|
||||
|
||||
Most flags only have meaning for a specific transaction type. The same bitwise value may be reused for flags on different transaction types, so it is important to pay attention to the transaction type when setting and reading flags.
|
||||
|
||||
Bits that are not defined as flags MUST be 0.
|
||||
|
||||
### Global Flag
|
||||
|
||||
Applies globally to all transactions.
|
||||
|
||||
`txFlags.Universal.FullyCanonicalSig`: Require a fully-canonical signature. When preparing transactions, ripple-lib enables this flag for you.
|
||||
|
||||
### Payment Flags
|
||||
|
||||
`txFlags.Payment.NoRippleDirect`: Do not use the default path; only use specified paths. This is intended to force the transaction to take arbitrage opportunities. Most clients do not need this.
|
||||
|
||||
`txFlags.Payment.PartialPayment`: If the specified destination amount cannot be sent without spending more than the source maxAmount, reduce the received amount instead of failing outright. See [Partial Payments](https://developers.ripple.com/partial-payments.html) for more details.
|
||||
|
||||
`txFlags.Payment.LimitQuality`: Only take paths where all the conversions have an input:output ratio that is equal or better than the ratio of `destination.amount`:`source.maxAmount`. See [Limit Quality](https://developers.ripple.com/payment.html#limit-quality) for details.
|
||||
|
||||
### OfferCreate Flags
|
||||
|
||||
`txFlags.OfferCreate.Passive`: If enabled, the offer does not consume offers that exactly match it, and instead becomes an Offer object in the ledger. It still consumes offers that cross it.
|
||||
|
||||
`txFlags.OfferCreate.ImmediateOrCancel`: Treat the offer as an Immediate or Cancel order. If enabled, the offer never becomes a ledger object: it only tries to match existing offers in the ledger.
|
||||
|
||||
`txFlags.OfferCreate.FillOrKill`: Treat the offer as a Fill or Kill order.
|
||||
|
||||
`txFlags.OfferCreate.Sell`: Treat the offer as a Sell order. With `order.direction = 'sell'`, exchange the entire `order.quantity`, even if it means obtaining more than the `order.totalPrice` amount in exchange. If using `prepareOrder`, ripple-lib sets this flag for you.
|
||||
|
||||
### TrustSet Flags
|
||||
|
||||
`txFlags.TrustSet.SetAuth`: Authorize the other party to hold issuances from this account. (No effect unless using the AccountSet.RequireAuth flag.) Cannot be unset.
|
||||
|
||||
`txFlags.TrustSet.NoRipple`: Obsolete.
|
||||
|
||||
`txFlags.TrustSet.SetNoRipple`: Blocks [rippling](https://developers.ripple.com/rippling.html) between two trustlines of the same currency, if this flag is set on both.
|
||||
|
||||
`txFlags.TrustSet.ClearNoRipple`: Clears the No-[Rippling](https://developers.ripple.com/rippling.html) flag.
|
||||
|
||||
`txFlags.TrustSet.SetFreeze`: Freeze the trustline. A non-XRP currency can be frozen by the exchange or gateway that issued it. XRP cannot be frozen.
|
||||
|
||||
`txFlags.TrustSet.ClearFreeze`: Unfreeze the trustline.
|
||||
|
||||
### AccountSet Flags
|
||||
|
||||
You can use the `prepareSettings` method to change your account flags. This method uses AccountSet flags internally.
|
||||
|
||||
In the rippled API, Account Flags can be enabled and disabled with the SetFlag and ClearFlag parameters. See [AccountSet Flags](https://developers.ripple.com/accountset.html#accountset-flags).
|
||||
|
||||
The AccountSet transaction type has some transaction flags, but their use is discouraged.
|
||||
|
||||
* `txFlags.AccountSet.RequireDestTag`
|
||||
* `txFlags.AccountSet.OptionalDestTag`
|
||||
* `txFlags.AccountSet.RequireAuth`
|
||||
* `txFlags.AccountSet.OptionalAuth`
|
||||
* `txFlags.AccountSet.DisallowXRP`
|
||||
* `txFlags.AccountSet.AllowXRP`
|
||||
|
||||
### PaymentChannelClaim Flags
|
||||
|
||||
`txFlags.PaymentChannelClaim.Renew`: Clear the channel's Expiration time. (Expiration is different from the channel's immutable CancelAfter time.) Only the source address of the payment channel can use this flag.
|
||||
|
||||
`txFlags.PaymentChannelClaim.Close`: Request to close the channel. Only the channel source and destination addresses can use this flag. This flag closes the channel immediately if it has no more XRP allocated to it after processing the current claim, or if the destination address uses it. If the source address uses this flag when the channel still holds XRP, this schedules the channel to close after SettleDelay seconds have passed. (Specifically, this sets the Expiration of the channel to the close time of the previous ledger plus the channel's SettleDelay time, unless the channel already has an earlier Expiration time.) If the destination address uses this flag when the channel still holds XRP, any XRP that remains after processing the claim is returned to the source address.
|
||||
|
||||
### Other Transaction Types
|
||||
|
||||
The remaining transaction types do not have any flags at this time.
|
||||
|
||||
* OfferCancel
|
||||
* SetRegularKey
|
||||
* SignerListSet
|
||||
* EscrowCreate
|
||||
* EscrowFinish
|
||||
* EscrowCancel
|
||||
* PaymentChannelCreate
|
||||
* PaymentChannelFund
|
||||
47
docs/src/xrpToDropsAndDropsToXrp.md.ejs
Normal file
47
docs/src/xrpToDropsAndDropsToXrp.md.ejs
Normal file
@@ -0,0 +1,47 @@
|
||||
## xrpToDrops
|
||||
|
||||
`xrpToDrops(xrp: string | BigNumber): string`
|
||||
|
||||
Converts an XRP amount to drops. 1 XRP = 1,000,000 drops, so 1 drop = 0.000001 XRP. This method is useful when converting amounts for use with the rippled API, which requires XRP amounts to be specified in drops.
|
||||
|
||||
### Parameters
|
||||
|
||||
`xrp`: A string or BigNumber representing an amount of XRP. If `xrp` is a string, it may start with `-`, must contain at least one number, and may contain up to one `.`. This method throws a `ValidationError` for invalid input.
|
||||
|
||||
### Return Value
|
||||
|
||||
A string representing an equivalent amount of drops.
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
return api.xrpToDrops('1');
|
||||
```
|
||||
|
||||
```json
|
||||
'1000000'
|
||||
```
|
||||
|
||||
## dropsToXrp
|
||||
|
||||
`dropsToXrp(drops: string | BigNumber): string`
|
||||
|
||||
Converts an amount of drops to XRP. 1 drop = 0.000001 XRP, so 1 XRP = 1,000,000 drops. This method is useful when converting amounts from the rippled API, which describes XRP amounts in drops.
|
||||
|
||||
### Parameters
|
||||
|
||||
`drops`: A string or BigNumber representing an amount of drops. If `drops` is a string, it may start with `-` and must contain at least one number. This method throws a `ValidationError` for invalid input.
|
||||
|
||||
### Return Value
|
||||
|
||||
A string representing an equivalent amount of XRP.
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
return api.dropsToXrp('1');
|
||||
```
|
||||
|
||||
```json
|
||||
'0.000001'
|
||||
```
|
||||
10
package.json
10
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ripple-lib",
|
||||
"version": "0.22.0",
|
||||
"version": "1.1.0",
|
||||
"license": "ISC",
|
||||
"description": "A JavaScript API for interacting with Ripple in Node.js and the browser",
|
||||
"files": [
|
||||
@@ -23,10 +23,10 @@
|
||||
"jsonschema": "1.2.2",
|
||||
"lodash": "^4.17.4",
|
||||
"ripple-address-codec": "^2.0.1",
|
||||
"ripple-binary-codec": "^0.1.13",
|
||||
"ripple-binary-codec": "0.2.0",
|
||||
"ripple-hashes": "^0.3.1",
|
||||
"ripple-keypairs": "^0.10.1",
|
||||
"ripple-lib-transactionparser": "^0.6.2",
|
||||
"ripple-lib-transactionparser": "0.7.1",
|
||||
"ws": "^3.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -53,9 +53,9 @@
|
||||
"ts-node": "^3.3.0",
|
||||
"tslint": "^5.8.0",
|
||||
"tslint-eslint-rules": "^4.1.1",
|
||||
"typescript": "^2.6.1",
|
||||
"typescript": "2.9.2",
|
||||
"uglifyjs-webpack-plugin": "^1.1.4",
|
||||
"webpack": "^3.10.0",
|
||||
"webpack": "3.12.0",
|
||||
"yargs": "^8.0.2"
|
||||
},
|
||||
"scripts": {
|
||||
|
||||
11
snippets/parseAccountFlags.js
Normal file
11
snippets/parseAccountFlags.js
Normal file
@@ -0,0 +1,11 @@
|
||||
const RippleAPI = require('../dist/npm').RippleAPI
|
||||
const api = new RippleAPI({server: 'wss://s.altnet.rippletest.net:51233'})
|
||||
|
||||
parseAccountFlags()
|
||||
|
||||
async function parseAccountFlags() {
|
||||
await api.connect()
|
||||
const account_info = await api.request('account_info', {account: 'rKsdkGhyZH6b2Zzd5hNnEqSv2wpznn4n6N'})
|
||||
const flags = api.parseAccountFlags(account_info.account_data.Flags)
|
||||
console.log(JSON.stringify(flags, null, 2))
|
||||
}
|
||||
172
src/api.ts
172
src/api.ts
@@ -1,12 +1,17 @@
|
||||
import * as _ from 'lodash'
|
||||
import {EventEmitter} from 'events'
|
||||
import {Connection, errors, validate} from './common'
|
||||
import {
|
||||
Connection,
|
||||
errors,
|
||||
validate,
|
||||
xrpToDrops,
|
||||
dropsToXrp,
|
||||
iso8601ToRippleTime,
|
||||
txFlags
|
||||
} from './common'
|
||||
import {
|
||||
connect,
|
||||
disconnect,
|
||||
isConnected,
|
||||
getServerInfo,
|
||||
getFee,
|
||||
getLedgerVersion,
|
||||
formatLedgerClose
|
||||
} from './server/server'
|
||||
@@ -18,7 +23,7 @@ import getBalanceSheet from './ledger/balance-sheet'
|
||||
import getPaths from './ledger/pathfind'
|
||||
import getOrders from './ledger/orders'
|
||||
import getOrderbook from './ledger/orderbook'
|
||||
import getSettings from './ledger/settings'
|
||||
import {getSettings, parseAccountFlags} from './ledger/settings'
|
||||
import getAccountInfo from './ledger/accountinfo'
|
||||
import getAccountObjects from './ledger/accountobjects'
|
||||
import getPaymentChannel from './ledger/payment-channel'
|
||||
@@ -40,6 +45,7 @@ import sign from './transaction/sign'
|
||||
import combine from './transaction/combine'
|
||||
import submit from './transaction/submit'
|
||||
import {generateAddressAPI} from './offline/generate-address'
|
||||
import {deriveKeypair, deriveAddress} from './offline/derive'
|
||||
import computeLedgerHash from './offline/ledgerhash'
|
||||
import signPaymentChannelClaim from './offline/sign-payment-channel-claim'
|
||||
import verifyPaymentChannelClaim from './offline/verify-payment-channel-claim'
|
||||
@@ -53,18 +59,23 @@ import {
|
||||
BookOffersRequest, BookOffersResponse,
|
||||
GatewayBalancesRequest, GatewayBalancesResponse,
|
||||
LedgerRequest, LedgerResponse,
|
||||
LedgerEntryRequest, LedgerEntryResponse
|
||||
LedgerEntryRequest, LedgerEntryResponse,
|
||||
ServerInfoRequest, ServerInfoResponse
|
||||
} from './common/types/commands'
|
||||
|
||||
|
||||
import RangeSet from './common/rangeset'
|
||||
import * as ledgerUtils from './ledger/utils'
|
||||
import * as transactionUtils from './transaction/utils'
|
||||
import * as schemaValidator from './common/schema-validator'
|
||||
import {getServerInfo, getFee} from './common/serverinfo'
|
||||
import {clamp} from './ledger/utils'
|
||||
import {Instructions, Prepare} from './transaction/types'
|
||||
|
||||
export type APIOptions = {
|
||||
server?: string,
|
||||
feeCushion?: number,
|
||||
maxFeeXRP?: string,
|
||||
trace?: boolean,
|
||||
proxy?: string,
|
||||
timeout?: number
|
||||
@@ -87,29 +98,17 @@ function getCollectKeyFromCommand(command: string): string|undefined {
|
||||
}
|
||||
}
|
||||
|
||||
// prevent access to non-validated ledger versions
|
||||
export class RestrictedConnection extends Connection {
|
||||
request(request: any, timeout?: number) {
|
||||
const ledger_index = request.ledger_index
|
||||
if (ledger_index !== undefined && ledger_index !== 'validated') {
|
||||
if (!_.isNumber(ledger_index) || ledger_index > this._ledgerVersion) {
|
||||
return Promise.reject(new errors.LedgerVersionError(
|
||||
`ledgerVersion ${ledger_index} is greater than server\'s ` +
|
||||
`most recent validated ledger: ${this._ledgerVersion}`))
|
||||
}
|
||||
}
|
||||
return super.request(request, timeout)
|
||||
}
|
||||
}
|
||||
|
||||
class RippleAPI extends EventEmitter {
|
||||
|
||||
_feeCushion: number
|
||||
connection: RestrictedConnection
|
||||
_maxFeeXRP: string
|
||||
|
||||
// New in > 0.21.0
|
||||
// non-validated ledger versions are allowed, and passed to rippled as-is.
|
||||
connection: Connection
|
||||
|
||||
// these are exposed only for use by unit tests; they are not part of the API.
|
||||
static _PRIVATE = {
|
||||
validate: validate,
|
||||
validate,
|
||||
RangeSet,
|
||||
ledgerUtils,
|
||||
schemaValidator
|
||||
@@ -119,9 +118,10 @@ class RippleAPI extends EventEmitter {
|
||||
super()
|
||||
validate.apiOptions(options)
|
||||
this._feeCushion = options.feeCushion || 1.2
|
||||
this._maxFeeXRP = options.maxFeeXRP || '2'
|
||||
const serverURL = options.server
|
||||
if (serverURL !== undefined) {
|
||||
this.connection = new RestrictedConnection(serverURL, options)
|
||||
this.connection = new Connection(serverURL, options)
|
||||
this.connection.on('ledgerClosed', message => {
|
||||
this.emit('ledger', formatLedgerClose(message))
|
||||
})
|
||||
@@ -137,48 +137,91 @@ class RippleAPI extends EventEmitter {
|
||||
} else {
|
||||
// use null object pattern to provide better error message if user
|
||||
// tries to call a method that requires a connection
|
||||
this.connection = new RestrictedConnection(null, options)
|
||||
this.connection = new Connection(null, options)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async _request(command: 'account_info', params: AccountInfoRequest):
|
||||
Promise<AccountInfoResponse>
|
||||
async _request(command: 'account_lines', params: AccountLinesRequest):
|
||||
Promise<AccountLinesResponse>
|
||||
|
||||
/**
|
||||
* Returns objects owned by an account.
|
||||
* For an account's trust lines and balances,
|
||||
* see `getTrustlines` and `getBalances`.
|
||||
*/
|
||||
async _request(command: 'account_objects', params: AccountObjectsRequest):
|
||||
Promise<AccountObjectsResponse>
|
||||
|
||||
async _request(command: 'account_offers', params: AccountOffersRequest):
|
||||
Promise<AccountOffersResponse>
|
||||
async _request(command: 'book_offers', params: BookOffersRequest):
|
||||
Promise<BookOffersResponse>
|
||||
async _request(command: 'gateway_balances', params: GatewayBalancesRequest):
|
||||
Promise<GatewayBalancesResponse>
|
||||
async _request(command: 'ledger', params: LedgerRequest):
|
||||
Promise<LedgerResponse>
|
||||
async _request(command: 'ledger_entry', params: LedgerEntryRequest):
|
||||
Promise<LedgerEntryResponse>
|
||||
|
||||
/**
|
||||
* Makes a request to the API with the given command and
|
||||
* additional request body parameters.
|
||||
*
|
||||
* NOTE: This command is under development.
|
||||
*/
|
||||
async _request(command: string, params: object = {}) {
|
||||
async request(command: 'account_info', params: AccountInfoRequest):
|
||||
Promise<AccountInfoResponse>
|
||||
async request(command: 'account_lines', params: AccountLinesRequest):
|
||||
Promise<AccountLinesResponse>
|
||||
async request(command: 'account_objects', params: AccountObjectsRequest):
|
||||
Promise<AccountObjectsResponse>
|
||||
async request(command: 'account_offers', params: AccountOffersRequest):
|
||||
Promise<AccountOffersResponse>
|
||||
async request(command: 'book_offers', params: BookOffersRequest):
|
||||
Promise<BookOffersResponse>
|
||||
async request(command: 'gateway_balances', params: GatewayBalancesRequest):
|
||||
Promise<GatewayBalancesResponse>
|
||||
async request(command: 'ledger', params: LedgerRequest):
|
||||
Promise<LedgerResponse>
|
||||
async request(command: 'ledger_entry', params: LedgerEntryRequest):
|
||||
Promise<LedgerEntryResponse>
|
||||
async request(command: 'server_info', params?: ServerInfoRequest):
|
||||
Promise<ServerInfoResponse>
|
||||
async request(command: string, params: any):
|
||||
Promise<any>
|
||||
async request(command: string, params: any = {}): Promise<any> {
|
||||
return this.connection.request({
|
||||
...params,
|
||||
command
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if there are more pages of data.
|
||||
*
|
||||
* When there are more results than contained in the response, the response
|
||||
* includes a `marker` field.
|
||||
*
|
||||
* See https://ripple.com/build/rippled-apis/#markers-and-pagination
|
||||
*/
|
||||
hasNextPage<T extends {marker?: string}>(currentResponse: T): boolean {
|
||||
return !!currentResponse.marker
|
||||
}
|
||||
|
||||
async requestNextPage<T extends {marker?: string}>(
|
||||
command: string,
|
||||
params: object = {},
|
||||
currentResponse: T
|
||||
): Promise<object> {
|
||||
if (!currentResponse.marker) {
|
||||
return Promise.reject(
|
||||
new errors.NotFoundError('response does not have a next page')
|
||||
)
|
||||
}
|
||||
const nextPageParams = Object.assign({}, params, {
|
||||
marker: currentResponse.marker
|
||||
})
|
||||
return this.request(command, nextPageParams)
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare a transaction.
|
||||
*
|
||||
* You can later submit the transaction with `submit()`.
|
||||
*/
|
||||
async prepareTransaction(txJSON: object, instructions: Instructions = {}):
|
||||
Promise<Prepare> {
|
||||
return transactionUtils.prepareTransaction(txJSON, this, instructions)
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a string to hex.
|
||||
*
|
||||
* This can be used to generate `MemoData`, `MemoType`, and `MemoFormat`.
|
||||
*
|
||||
* @param string string to convert to hex
|
||||
*/
|
||||
convertStringToHex(string: string): string {
|
||||
return transactionUtils.convertStringToHex(string)
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes multiple paged requests to the API to return a given number of
|
||||
* resources. _requestAll() will make multiple requests until the `limit`
|
||||
@@ -188,8 +231,9 @@ class RippleAPI extends EventEmitter {
|
||||
* If the command is unknown, an additional `collect` property is required to
|
||||
* know which response key contains the array of resources.
|
||||
*
|
||||
* NOTE: This command is under development and should not yet be relied
|
||||
* on by external consumers.
|
||||
* NOTE: This command is used by existing methods and is not recommended for
|
||||
* general use. Instead, use rippled's built-in pagination and make multiple
|
||||
* requests as needed.
|
||||
*/
|
||||
async _requestAll(command: 'account_offers', params: AccountOffersRequest):
|
||||
Promise<AccountOffersResponse[]>
|
||||
@@ -222,12 +266,9 @@ class RippleAPI extends EventEmitter {
|
||||
limit: countRemaining,
|
||||
marker
|
||||
}
|
||||
// NOTE: We have to generalize the `this._request()` function signature
|
||||
// here until we add support for unknown commands (since command is some
|
||||
// unknown string).
|
||||
const singleResult = await (<Function>this._request)(command, repeatProps)
|
||||
const singleResult = await this.request(command, repeatProps)
|
||||
const collectedData = singleResult[collectKey]
|
||||
marker = singleResult.marker
|
||||
marker = singleResult['marker']
|
||||
results.push(singleResult)
|
||||
// Make sure we handle when no data (not even an empty array) is returned.
|
||||
const isExpectedFormat = Array.isArray(collectedData)
|
||||
@@ -261,6 +302,7 @@ class RippleAPI extends EventEmitter {
|
||||
getAccountObjects = getAccountObjects
|
||||
getPaymentChannel = getPaymentChannel
|
||||
getLedger = getLedger
|
||||
parseAccountFlags = parseAccountFlags
|
||||
|
||||
preparePayment = preparePayment
|
||||
prepareTrustline = prepareTrustline
|
||||
@@ -281,10 +323,20 @@ class RippleAPI extends EventEmitter {
|
||||
submit = submit
|
||||
|
||||
generateAddress = generateAddressAPI
|
||||
deriveKeypair = deriveKeypair
|
||||
deriveAddress = deriveAddress
|
||||
computeLedgerHash = computeLedgerHash
|
||||
signPaymentChannelClaim = signPaymentChannelClaim
|
||||
verifyPaymentChannelClaim = verifyPaymentChannelClaim
|
||||
errors = errors
|
||||
|
||||
xrpToDrops = xrpToDrops
|
||||
dropsToXrp = dropsToXrp
|
||||
iso8601ToRippleTime = iso8601ToRippleTime
|
||||
txFlags = txFlags
|
||||
|
||||
isValidAddress = schemaValidator.isValidAddress
|
||||
isValidSecret = schemaValidator.isValidSecret
|
||||
}
|
||||
|
||||
export {
|
||||
|
||||
@@ -6,7 +6,7 @@ function setPrototypeOf(object, prototype) {
|
||||
object.__proto__ = prototype
|
||||
}
|
||||
|
||||
function getConstructorName(object: Object): string {
|
||||
function getConstructorName(object: object): string {
|
||||
// hack for internet explorer
|
||||
if (!object.constructor.name) {
|
||||
return object.constructor.toString().match(/^function\s+([^(]*)/)![1]
|
||||
|
||||
@@ -7,12 +7,6 @@ import {RippledError, DisconnectedError, NotConnectedError,
|
||||
TimeoutError, ResponseFormatError, ConnectionError,
|
||||
RippledNotInitializedError} from './errors'
|
||||
|
||||
function isStreamMessageType(type) {
|
||||
return type === 'ledgerClosed' ||
|
||||
type === 'transaction' ||
|
||||
type === 'path_find'
|
||||
}
|
||||
|
||||
export interface ConnectionOptions {
|
||||
trace?: boolean,
|
||||
proxy?: string
|
||||
@@ -90,19 +84,20 @@ class Connection extends EventEmitter {
|
||||
const data = JSON.parse(message)
|
||||
if (data.type === 'response') {
|
||||
if (!(Number.isInteger(data.id) && data.id >= 0)) {
|
||||
throw new ResponseFormatError('valid id not found in response')
|
||||
throw new ResponseFormatError('valid id not found in response', data)
|
||||
}
|
||||
return [data.id.toString(), data]
|
||||
} else if (isStreamMessageType(data.type)) {
|
||||
if (data.type === 'ledgerClosed') {
|
||||
this._updateLedgerVersions(data)
|
||||
this._updateFees(data)
|
||||
}
|
||||
return [data.type, data]
|
||||
} else if (data.type === undefined && data.error) {
|
||||
return ['error', data.error, data.error_message, data] // e.g. slowDown
|
||||
}
|
||||
throw new ResponseFormatError('unrecognized message type: ' + data.type)
|
||||
|
||||
// Possible `data.type` values include 'ledgerClosed',
|
||||
// 'transaction', 'path_find', and many others.
|
||||
if (data.type === 'ledgerClosed') {
|
||||
this._updateLedgerVersions(data)
|
||||
this._updateFees(data)
|
||||
}
|
||||
return [data.type, data]
|
||||
}
|
||||
|
||||
_onMessage(message) {
|
||||
@@ -246,7 +241,7 @@ class Connection extends EventEmitter {
|
||||
_onOpenError(reject, error) {
|
||||
this._onOpenErrorBound = null
|
||||
this._unbindOnUnxpectedClose()
|
||||
reject(new NotConnectedError(error && error.message))
|
||||
reject(new NotConnectedError(error.message, error))
|
||||
}
|
||||
|
||||
_createWebSocket(): WebSocket {
|
||||
@@ -404,7 +399,7 @@ class Connection extends EventEmitter {
|
||||
return new Promise((resolve, reject) => {
|
||||
this._ws.send(message, undefined, error => {
|
||||
if (error) {
|
||||
reject(new DisconnectedError(error.message))
|
||||
reject(new DisconnectedError(error.message, error))
|
||||
} else {
|
||||
resolve()
|
||||
}
|
||||
@@ -427,7 +422,7 @@ class Connection extends EventEmitter {
|
||||
function onDisconnect() {
|
||||
clearTimeout(timer)
|
||||
self.removeAllListeners(eventName)
|
||||
reject(new DisconnectedError())
|
||||
reject(new DisconnectedError('websocket was closed'))
|
||||
}
|
||||
|
||||
function cleanup() {
|
||||
@@ -450,12 +445,12 @@ class Connection extends EventEmitter {
|
||||
|
||||
this.once(eventName, response => {
|
||||
if (response.status === 'error') {
|
||||
_reject(new RippledError(response.error))
|
||||
_reject(new RippledError(response.error, response))
|
||||
} else if (response.status === 'success') {
|
||||
_resolve(response.result)
|
||||
} else {
|
||||
_reject(new ResponseFormatError(
|
||||
'unrecognized status: ' + response.status))
|
||||
'unrecognized status: ' + response.status, response))
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ class MissingLedgerHistoryError extends RippleError {
|
||||
|
||||
class PendingLedgerVersionError extends RippleError {
|
||||
constructor(message?: string) {
|
||||
super(message || 'maxLedgerVersion is greater than server\'s most recent ' +
|
||||
super(message || 'maxLedgerVersion is greater than server\'s most recent' +
|
||||
' validated ledger')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,13 +9,13 @@ function loadSchemas() {
|
||||
// listed explicitly for webpack (instead of scanning schemas directory)
|
||||
const schemas = [
|
||||
require('./schemas/objects/tx-json.json'),
|
||||
require('./schemas/objects/tx-type.json'),
|
||||
require('./schemas/objects/transaction-type.json'),
|
||||
require('./schemas/objects/hash128.json'),
|
||||
require('./schemas/objects/hash256.json'),
|
||||
require('./schemas/objects/sequence.json'),
|
||||
require('./schemas/objects/signature.json'),
|
||||
require('./schemas/objects/issue.json'),
|
||||
require('./schemas/objects/ledgerversion.json'),
|
||||
require('./schemas/objects/ledger-version.json'),
|
||||
require('./schemas/objects/max-adjustment.json'),
|
||||
require('./schemas/objects/memo.json'),
|
||||
require('./schemas/objects/memos.json'),
|
||||
@@ -31,21 +31,23 @@ function loadSchemas() {
|
||||
require('./schemas/objects/min-adjustment.json'),
|
||||
require('./schemas/objects/source-exact-adjustment.json'),
|
||||
require('./schemas/objects/destination-exact-adjustment.json'),
|
||||
require('./schemas/objects/tx-hash.json'),
|
||||
require('./schemas/objects/destination-address-tag.json'),
|
||||
require('./schemas/objects/transaction-hash.json'),
|
||||
require('./schemas/objects/address.json'),
|
||||
require('./schemas/objects/adjustment.json'),
|
||||
require('./schemas/objects/quality.json'),
|
||||
require('./schemas/objects/amount.json'),
|
||||
require('./schemas/objects/amount-base.json'),
|
||||
require('./schemas/objects/amountbase.json'),
|
||||
require('./schemas/objects/balance.json'),
|
||||
require('./schemas/objects/blob.json'),
|
||||
require('./schemas/objects/currency.json'),
|
||||
require('./schemas/objects/signed-value.json'),
|
||||
require('./schemas/objects/orderbook.json'),
|
||||
require('./schemas/objects/instructions.json'),
|
||||
require('./schemas/objects/settings.json'),
|
||||
require('./schemas/objects/settings-plus-memos.json'),
|
||||
require('./schemas/specifications/settings.json'),
|
||||
require('./schemas/specifications/payment.json'),
|
||||
require('./schemas/specifications/get-payment.json'),
|
||||
require('./schemas/specifications/escrow-cancellation.json'),
|
||||
require('./schemas/specifications/order-cancellation.json'),
|
||||
require('./schemas/specifications/order.json'),
|
||||
@@ -158,5 +160,6 @@ function schemaValidate(schemaName: string, object: any): void {
|
||||
|
||||
export {
|
||||
schemaValidate,
|
||||
isValidSecret
|
||||
isValidSecret,
|
||||
isValidAddress
|
||||
}
|
||||
|
||||
@@ -12,11 +12,15 @@
|
||||
"minimum": 1,
|
||||
"description": "Factor to multiply estimated fee by to provide a cushion in case the required fee rises during submission of a transaction. Defaults to `1.2`."
|
||||
},
|
||||
"maxFeeXRP": {
|
||||
"type": "string",
|
||||
"description": "Maximum fee to use with transactions, in XRP. Must be a string-encoded number. Defaults to `'2'`."
|
||||
},
|
||||
"server": {
|
||||
"type": "string",
|
||||
"description": "URI for rippled websocket port to connect to. Must start with `wss://` or `ws://`.",
|
||||
"description": "URI for rippled websocket port to connect to. Must start with `wss://`, `ws://`, `wss+unix://`, or `ws+unix://`.",
|
||||
"format": "uri",
|
||||
"pattern": "^wss?://"
|
||||
"pattern": "^(wss?|wss?\\+unix)://"
|
||||
},
|
||||
"proxy": {
|
||||
"format": "uri",
|
||||
|
||||
13
src/common/schemas/input/get-fee.json
Normal file
13
src/common/schemas/input/get-fee.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "getFeeParameters",
|
||||
"description": "Parameters for getFee",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"cushion": {
|
||||
"type": "number",
|
||||
"description": "The fee is the product of the base fee, the `load_factor`, and this cushion. Default is provided by the `RippleAPI` constructor's `feeCushion`."
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
@@ -4,9 +4,9 @@
|
||||
"description": "Parameters for getTransaction",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {"$ref": "id"},
|
||||
"id": {"$ref": "transactionHash"},
|
||||
"options": {
|
||||
"description": "Options to limit the ledger versions to search.",
|
||||
"description": "Options to limit the ledger versions to search and/or to include raw transaction data.",
|
||||
"properties": {
|
||||
"minLedgerVersion": {
|
||||
"$ref": "ledgerVersion",
|
||||
@@ -15,6 +15,9 @@
|
||||
"maxLedgerVersion": {
|
||||
"$ref": "ledgerVersion",
|
||||
"description": "The highest ledger version to search"
|
||||
},
|
||||
"includeRawTransaction": {
|
||||
"description": "Include raw transaction data. For advanced users; exercise caution when interpreting this data. "
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
|
||||
@@ -49,6 +49,9 @@
|
||||
"items": {"$ref": "transactionType"},
|
||||
"description": "Only return transactions of the specified [Transaction Types](#transaction-types)."
|
||||
},
|
||||
"includeRawTransactions": {
|
||||
"description": "Include raw transaction data. For advanced users; exercise caution when interpreting this data. "
|
||||
},
|
||||
"binary": {
|
||||
"type": "boolean",
|
||||
"description": "If true, the transactions will be sent from the server in a condensed binary format rather than JSON."
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "amount",
|
||||
"link": "amount",
|
||||
"description": "An Amount on the Ripple Protocol",
|
||||
"description": "An Amount on the XRP Ledger",
|
||||
"allOf": [
|
||||
{"$ref": "amountbase"},
|
||||
{"required": ["value"]}
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
"$ref": "value"
|
||||
},
|
||||
"currency": {
|
||||
"description": "The three-character code or hexadecimal string used to denote currencies",
|
||||
"description": "The three-character code or hexadecimal string used to denote currencies, or \"drops\" for the smallest unit of XRP.",
|
||||
"$ref": "currency"
|
||||
},
|
||||
"counterparty": {
|
||||
"description": "The Ripple address of the account that owes or is owed the funds (omitted if `currency` is \"XRP\")",
|
||||
"description": "The Ripple address of the account that owes or is owed the funds (omitted if `currency` is \"XRP\" or \"drops\")",
|
||||
"$ref": "address"
|
||||
}
|
||||
},
|
||||
@@ -24,7 +24,7 @@
|
||||
"properties": {
|
||||
"currency": {
|
||||
"not": {
|
||||
"enum": ["XRP"]
|
||||
"enum": ["XRP", "drops"]
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -33,7 +33,7 @@
|
||||
{
|
||||
"properties": {
|
||||
"currency": {
|
||||
"enum": ["XRP"]
|
||||
"enum": ["XRP", "drops"]
|
||||
}
|
||||
},
|
||||
"not": {
|
||||
@@ -4,5 +4,5 @@
|
||||
"description": "The three-character code or hexadecimal string used to denote currencies",
|
||||
"type": "string",
|
||||
"link": "currency",
|
||||
"pattern": "^([a-zA-Z0-9<>(){}[\\]|?!@#$%^&*]{3}|[A-F0-9]{40})$"
|
||||
"pattern": "^([a-zA-Z0-9<>(){}[\\]|?!@#$%^&*]{3}|[A-F0-9]{40}|drops)$"
|
||||
}
|
||||
|
||||
15
src/common/schemas/objects/destination-address-tag.json
Normal file
15
src/common/schemas/objects/destination-address-tag.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "destinationAddressTag",
|
||||
"description": "A destination address and optional tag, with no amount included. When parsing an incoming transaction, the original specification's amount is hidden to prevent misinterpretation. For the amount that the transaction delivered, see `outcome.deliveredAmount`.",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"address": {
|
||||
"$ref": "address",
|
||||
"description": "The address to receive at."
|
||||
},
|
||||
"tag": {"$ref": "tag"}
|
||||
},
|
||||
"required": ["address"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
@@ -9,7 +9,7 @@
|
||||
},
|
||||
"amount": {
|
||||
"$ref": "laxAmount",
|
||||
"description": "An exact amount to deliver to the recipient. If the counterparty is not specified, amounts with any counterparty may be used. (This field is exclusive with destination.minAmount)."
|
||||
"description": "An exact amount to deliver to the recipient. If the counterparty is not specified, amounts with any counterparty may be used. (This field cannot be used with `destination.minAmount`.)"
|
||||
},
|
||||
"tag": {"$ref": "tag"}
|
||||
},
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
"$ref": "value"
|
||||
},
|
||||
"maxFee": {
|
||||
"description": "The maximum fee to pay for the transaction. See [Transaction Fees](#transaction-fees) for more information.",
|
||||
"description": "Deprecated: Use `maxFeeXRP` in the RippleAPI constructor instead. The maximum fee to pay for this transaction. If this exceeds `maxFeeXRP`, `maxFeeXRP` will be used instead. See [Transaction Fees](#transaction-fees) for more information.",
|
||||
"$ref": "value"
|
||||
},
|
||||
"maxLedgerVersion": {
|
||||
|
||||
@@ -93,7 +93,9 @@
|
||||
"minItems": 1,
|
||||
"maxItems": 8
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["threshold", "weights"],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"transferRate": {
|
||||
"description": " The fee to charge when users transfer this account’s issuances, as the decimal amount that must be sent to deliver 1 unit. Has precision up to 9 digits beyond the decimal point. Use `null` to set no fee.",
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "id",
|
||||
"title": "transactionHash",
|
||||
"link": "transaction-id",
|
||||
"description": "A hash of a transaction used to identify the transaction, represented in hexadecimal.",
|
||||
"type": "string",
|
||||
@@ -55,15 +55,11 @@
|
||||
"description": "A transaction in the same format as the return value of [getTransaction](#gettransaction)."
|
||||
}
|
||||
},
|
||||
"rawTransactions": {
|
||||
"type": "string",
|
||||
"description": "A JSON string containing rippled format transaction JSON for all transactions that were validated in this ledger."
|
||||
},
|
||||
"transactionHashes": {
|
||||
"description": "An array of hashes of all transactions that were validated in this ledger.",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "id"
|
||||
"$ref": "transactionHash"
|
||||
}
|
||||
},
|
||||
"rawState": {
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "getTransaction",
|
||||
"description": "getTransaction response",
|
||||
"link": "gettransaction",
|
||||
"properties": {
|
||||
"type": {
|
||||
"$ref": "transactionType"
|
||||
},
|
||||
"specification": {
|
||||
"description": "A specification that would produce the same outcome as this transaction. The structure of the specification depends on the value of the `type` field (see [Transaction Types](#transaction-types) for details). *Note:* This is **not** necessarily the same as the original specification."
|
||||
"description": "A specification that would produce the same outcome as this transaction. *Exception:* For payment transactions, this omits the `destination.amount` field, to prevent misunderstanding. The structure of the specification depends on the value of the `type` field (see [Transaction Types](#transaction-types) for details). *Note:* This is **not** necessarily the same as the original specification."
|
||||
},
|
||||
"outcome": {
|
||||
"$ref": "outcome",
|
||||
"description": "The outcome of the transaction (what effects it had)."
|
||||
},
|
||||
"id": {
|
||||
"$ref": "id",
|
||||
"$ref": "transactionHash",
|
||||
"description": "A hash of the transaction that can be used to identify it."
|
||||
},
|
||||
"address": {
|
||||
@@ -24,6 +25,10 @@
|
||||
"sequence": {
|
||||
"$ref": "sequence",
|
||||
"description": "The account sequence number of the transaction for the account that initiated it."
|
||||
},
|
||||
"rawTransaction": {
|
||||
"description": "The raw transaction data as a JSON string. For advanced users only; exercise caution when interpreting this data.",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -44,7 +49,7 @@
|
||||
]
|
||||
},
|
||||
"specification": {
|
||||
"$ref": "payment"
|
||||
"$ref": "getPayment"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "array",
|
||||
"description": "Key is the ripple address; value is an array of signed amounts representing changes of balances for that address.",
|
||||
"description": "Key is the XRP Ledger address; value is an array of signed amounts representing changes of balances for that address.",
|
||||
"items": {"$ref": "balance"}
|
||||
}
|
||||
},
|
||||
@@ -33,10 +33,14 @@
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "array",
|
||||
"description": "Key is the maker's ripple address; value is an array of changes",
|
||||
"description": "Key is the maker's XRP Ledger address; value is an array of changes",
|
||||
"items": {"$ref": "orderChange"}
|
||||
}
|
||||
},
|
||||
"channelChanges": {
|
||||
"type": "object",
|
||||
"description": "Properties reflecting the details of the payment channel."
|
||||
},
|
||||
"ledgerVersion": {
|
||||
"$ref": "ledgerVersion",
|
||||
"description": "The ledger version that the transaction was validated in."
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
"description": "The signed transaction represented as an uppercase hexadecimal string."
|
||||
},
|
||||
"id": {
|
||||
"$ref": "id",
|
||||
"$ref": "transactionHash",
|
||||
"description": "The [Transaction ID](#transaction-id) of the signed transaction."
|
||||
}
|
||||
},
|
||||
|
||||
39
src/common/schemas/specifications/get-payment.json
Normal file
39
src/common/schemas/specifications/get-payment.json
Normal file
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "getPayment",
|
||||
"description": "A specification of a payment in a response for getTransaction or getTransactions.",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"source": {
|
||||
"$ref": "sourceAdjustment",
|
||||
"description": "The source of the funds to be sent."
|
||||
},
|
||||
"destination": {
|
||||
"$ref": "destinationAddressTag",
|
||||
"description": "The destination of the funds to be sent. Since this is a payment response, the amount is not shown here. For the amount that the transaction delivered, see `outcome.deliveredAmount`."
|
||||
},
|
||||
"paths": {
|
||||
"type": "string",
|
||||
"description": "The paths of trustlines and orders to use in executing the payment."
|
||||
},
|
||||
"memos": {"$ref": "memos"},
|
||||
"invoiceID": {
|
||||
"description": "A 256-bit hash that can be used to identify a particular payment.",
|
||||
"$ref": "hash256"
|
||||
},
|
||||
"allowPartialPayment": {
|
||||
"description": "If true, this payment should proceed even if the whole amount cannot be delivered due to a lack of liquidity or a lack of funds in the source account.",
|
||||
"type": "boolean"
|
||||
},
|
||||
"noDirectRipple": {
|
||||
"description": "If true and paths are specified, the sender would like the XRP Ledger to disregard any direct paths from the source account to the destination account. This may be used to take advantage of an arbitrage opportunity or by gateways wishing to issue balances from a hot wallet to a user who has mistakenly set a trustline directly to the hot wallet.",
|
||||
"type": "boolean"
|
||||
},
|
||||
"limitQuality": {
|
||||
"description": "Only take paths where all the conversions have an input:output ratio that is equal or better than the ratio of destination.amount:source.maxAmount.",
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": ["source", "destination"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
@@ -19,11 +19,11 @@
|
||||
},
|
||||
"immediateOrCancel": {
|
||||
"type": "boolean",
|
||||
"description": "Treat the offer as an [Immediate or Cancel order](http://en.wikipedia.org/wiki/Immediate_or_cancel). If enabled, the offer will never become a ledger node: it only attempts to match existing offers in the ledger."
|
||||
"description": "Treat the offer as an [Immediate or Cancel order](http://en.wikipedia.org/wiki/Immediate_or_cancel). If enabled, the offer will never become a ledger node: it only attempts to match existing offers in the ledger. This cannot be used with `fillOrKill`."
|
||||
},
|
||||
"fillOrKill": {
|
||||
"type": "boolean",
|
||||
"description": "Treat the offer as a [Fill or Kill order](http://en.wikipedia.org/wiki/Fill_or_kill). Only attempt to match existing offers in the ledger, and only do so if the entire quantity can be exchanged."
|
||||
"description": "Treat the offer as a [Fill or Kill order](http://en.wikipedia.org/wiki/Fill_or_kill). Only attempt to match existing offers in the ledger, and only do so if the entire quantity can be exchanged. This cannot be used with `immediateOrCancel`."
|
||||
},
|
||||
"passive": {
|
||||
"description": "If enabled, the offer will not consume offers that exactly match it, and instead becomes an Offer node in the ledger. It will still consume offers that cross it.",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as _ from 'lodash'
|
||||
import {convertKeysFromSnakeCaseToCamelCase} from './utils'
|
||||
import Connection from './connection'
|
||||
import BigNumber from 'bignumber.js'
|
||||
import {RippleAPI} from '../index'
|
||||
|
||||
export type GetServerInfoResponse = {
|
||||
buildVersion: string,
|
||||
@@ -9,7 +9,7 @@ export type GetServerInfoResponse = {
|
||||
hostID: string,
|
||||
ioLatencyMs: number,
|
||||
load?: {
|
||||
jobTypes: Array<Object>,
|
||||
jobTypes: Array<object>,
|
||||
threads: number
|
||||
},
|
||||
lastClose: {
|
||||
@@ -39,8 +39,8 @@ function renameKeys(object, mapping) {
|
||||
})
|
||||
}
|
||||
|
||||
function getServerInfo(connection: Connection): Promise<GetServerInfoResponse> {
|
||||
return connection.request({command: 'server_info'}).then(response => {
|
||||
function getServerInfo(this: RippleAPI): Promise<GetServerInfoResponse> {
|
||||
return this.request('server_info').then(response => {
|
||||
const info = convertKeysFromSnakeCaseToCamelCase(response.info)
|
||||
renameKeys(info, {hostid: 'hostID'})
|
||||
if (info.validatedLedger) {
|
||||
@@ -61,18 +61,27 @@ function getServerInfo(connection: Connection): Promise<GetServerInfoResponse> {
|
||||
})
|
||||
}
|
||||
|
||||
function computeFeeFromServerInfo(cushion: number,
|
||||
serverInfo: GetServerInfoResponse
|
||||
): string {
|
||||
return (new BigNumber(serverInfo.validatedLedger.baseFeeXRP)).
|
||||
times(serverInfo.loadFactor).
|
||||
times(cushion).toString()
|
||||
}
|
||||
// This is a public API that can be called directly.
|
||||
// This is not used by the `prepare*` methods. See `src/transaction/utils.ts`
|
||||
async function getFee(
|
||||
this: RippleAPI,
|
||||
cushion?: number
|
||||
): Promise<string> {
|
||||
if (cushion === undefined) {
|
||||
cushion = this._feeCushion
|
||||
}
|
||||
if (cushion === undefined) {
|
||||
cushion = 1.2
|
||||
}
|
||||
|
||||
function getFee(connection: Connection, cushion: number): Promise<string> {
|
||||
return getServerInfo(connection).then(serverInfo => {
|
||||
return computeFeeFromServerInfo(cushion, serverInfo)
|
||||
})
|
||||
const serverInfo = (await this.request('server_info')).info
|
||||
const baseFeeXrp = new BigNumber(serverInfo.validated_ledger.base_fee_xrp)
|
||||
let fee = baseFeeXrp.times(serverInfo.load_factor).times(cushion)
|
||||
|
||||
// Cap fee to `this._maxFeeXRP`
|
||||
fee = BigNumber.min(fee, this._maxFeeXRP)
|
||||
// Round fee to 6 decimal places
|
||||
return (new BigNumber(fee.toFixed(6))).toString(10)
|
||||
}
|
||||
|
||||
export {
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
const txFlags = {
|
||||
// Universal flags can apply to any transaction type
|
||||
Universal: {
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import {CheckLedgerEntry} from '../objects'
|
||||
import {
|
||||
CheckLedgerEntry, RippleStateLedgerEntry,
|
||||
OfferLedgerEntry, SignerListLedgerEntry,
|
||||
EscrowLedgerEntry, PayChannelLedgerEntry,
|
||||
DepositPreauthLedgerEntry
|
||||
} from '../objects'
|
||||
|
||||
export interface GetAccountObjectsOptions {
|
||||
type?: string | (
|
||||
@@ -44,7 +49,16 @@ export interface AccountObjectsResponse {
|
||||
account: string,
|
||||
|
||||
// Array of objects owned by this account.
|
||||
account_objects: CheckLedgerEntry | object,
|
||||
// from the getAccountObjects section of the dev center
|
||||
account_objects: Array<
|
||||
CheckLedgerEntry |
|
||||
RippleStateLedgerEntry |
|
||||
OfferLedgerEntry |
|
||||
SignerListLedgerEntry |
|
||||
EscrowLedgerEntry |
|
||||
PayChannelLedgerEntry |
|
||||
DepositPreauthLedgerEntry
|
||||
>,
|
||||
|
||||
// (May be omitted) The identifying hash of the ledger
|
||||
// that was used to generate this response.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {
|
||||
TakerRequestAmount,
|
||||
RippledAmount,
|
||||
OfferCreateTransaction
|
||||
OfferLedgerEntry
|
||||
} from '../objects'
|
||||
|
||||
export interface BookOffersRequest {
|
||||
@@ -22,7 +22,7 @@ export interface BookOffersResponse {
|
||||
marker?: any
|
||||
}
|
||||
|
||||
export interface BookOffer extends OfferCreateTransaction {
|
||||
export interface BookOffer extends OfferLedgerEntry {
|
||||
quality?: string
|
||||
owner_funds?: string,
|
||||
taker_gets_funded?: RippledAmount,
|
||||
|
||||
@@ -6,3 +6,4 @@ export * from './book_offers'
|
||||
export * from './gateway_balances'
|
||||
export * from './ledger'
|
||||
export * from './ledger_entry'
|
||||
export * from './server_info'
|
||||
|
||||
51
src/common/types/commands/server_info.ts
Normal file
51
src/common/types/commands/server_info.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
export interface ServerInfoRequest {
|
||||
id?: number
|
||||
}
|
||||
|
||||
export interface ServerInfoResponse {
|
||||
info: {
|
||||
amendment_blocked?: boolean,
|
||||
build_version: string,
|
||||
closed_ledger?: LedgerInfo,
|
||||
complete_ledgers: string,
|
||||
hostid: string,
|
||||
io_latency_ms: number,
|
||||
last_close: {
|
||||
converge_time_s: number,
|
||||
proposers: number
|
||||
},
|
||||
load?: {
|
||||
job_types: {
|
||||
job_type: string,
|
||||
per_second: number,
|
||||
in_progress: number
|
||||
}[],
|
||||
threads: number
|
||||
},
|
||||
load_factor: number,
|
||||
load_factor_local?: number,
|
||||
load_factor_net?: number,
|
||||
load_factor_cluster?: number,
|
||||
load_factor_fee_escalation?: number,
|
||||
load_factor_fee_queue?: number,
|
||||
load_factor_server?: number,
|
||||
peers: number,
|
||||
pubkey_node: string,
|
||||
pubkey_validator: string,
|
||||
server_state: string,
|
||||
state_accounting: any,
|
||||
uptime: number,
|
||||
validated_ledger?: LedgerInfo,
|
||||
validation_quorum: number,
|
||||
validator_list_expires: string
|
||||
},
|
||||
}
|
||||
|
||||
export interface LedgerInfo {
|
||||
age: number,
|
||||
base_fee_xrp: number,
|
||||
hash: string,
|
||||
reserve_base_xrp: number,
|
||||
reserve_inc_xrp: number,
|
||||
seq: number,
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import {SignerEntry} from './index'
|
||||
import {Amount, RippledAmount} from './amounts'
|
||||
|
||||
export interface AccountRootLedgerEntry {
|
||||
LedgerEntryType: 'AccountRoot',
|
||||
@@ -44,6 +45,87 @@ export interface CheckLedgerEntry {
|
||||
SourceTag: number
|
||||
}
|
||||
|
||||
export interface DepositPreauthLedgerEntry {
|
||||
LedgerEntryType: 'DepositPreauth',
|
||||
Account: string,
|
||||
Authorize: string,
|
||||
OwnerNode: string,
|
||||
PreviousTxnID: string,
|
||||
PreviousTxnLgrSeq: number
|
||||
}
|
||||
|
||||
export interface DirectoryNodeLedgerEntry {
|
||||
LedgerEntryType: 'DirectoryNode',
|
||||
Flags: number,
|
||||
RootIndex: string,
|
||||
Indexes: string[],
|
||||
IndexNext?: number,
|
||||
IndexPrevious?: number
|
||||
}
|
||||
|
||||
export interface OfferDirectoryNodeLedgerEntry
|
||||
extends DirectoryNodeLedgerEntry {
|
||||
TakerPaysCurrency: string,
|
||||
TakerPaysIssuer: string,
|
||||
TakerGetsCurrency: string,
|
||||
TakerGetsIssuer: string,
|
||||
ExchangeRate?: number // DEPRECATED
|
||||
}
|
||||
|
||||
export interface OwnerDirectoryNodeLedgerEntry
|
||||
extends DirectoryNodeLedgerEntry {
|
||||
Owner: string,
|
||||
}
|
||||
|
||||
export interface EscrowLedgerEntry {
|
||||
LedgerEntryType: 'Escrow',
|
||||
Account: string,
|
||||
Destination: string,
|
||||
Amount: string,
|
||||
Condition?: string,
|
||||
CancelAfter?: number,
|
||||
FinishAfter?: number,
|
||||
Flags: number,
|
||||
SourceTag?: number,
|
||||
DestinationTag?: number,
|
||||
OwnerNode: string,
|
||||
DestinationNode?: string,
|
||||
PreviousTxnID: string,
|
||||
PreviousTxnLgrSeq: number
|
||||
}
|
||||
|
||||
export interface FeeSettingsLedgerEntry {
|
||||
LedgerEntryType: 'FeeSettings',
|
||||
BaseFee: string,
|
||||
ReferenceFeeUnits: number,
|
||||
ReserveBase: number,
|
||||
ReserveIncrement: number,
|
||||
Flags: number
|
||||
}
|
||||
|
||||
export interface LedgerHashesLedgerEntry {
|
||||
LedgerEntryType: 'LedgerHashes',
|
||||
Hashes: string[],
|
||||
Flags: number,
|
||||
FirstLedgerSequence?: number, // DEPRECATED
|
||||
LastLedgerSequence?: number
|
||||
}
|
||||
|
||||
export interface OfferLedgerEntry {
|
||||
LedgerEntryType: 'Offer',
|
||||
Flags: number,
|
||||
Account: string,
|
||||
Sequence: number,
|
||||
TakerPays: RippledAmount,
|
||||
TakerGets: RippledAmount,
|
||||
BookDirectory: string,
|
||||
BookNode: string,
|
||||
OwnerNode: string,
|
||||
PreviousTxnID: string,
|
||||
PreviousTxnLgrSeq: number,
|
||||
Expiration?: number
|
||||
}
|
||||
|
||||
export interface PayChannelLedgerEntry {
|
||||
LedgerEntryType: 'PayChannel',
|
||||
Sequence: number,
|
||||
@@ -63,6 +145,22 @@ export interface PayChannelLedgerEntry {
|
||||
index: string
|
||||
}
|
||||
|
||||
export interface RippleStateLedgerEntry {
|
||||
LedgerEntryType: 'RippleState',
|
||||
Flags: number,
|
||||
Balance: Amount,
|
||||
LowLimit: Amount,
|
||||
HighLimit: Amount,
|
||||
PreviousTxnID: string,
|
||||
PreviousTxnLgrSeq: number,
|
||||
LowNode?: string,
|
||||
HighNode?: string,
|
||||
LowQualityIn?: number,
|
||||
LowQualityOut?: number,
|
||||
HighQualityIn?: number,
|
||||
HighQualityOut?: number
|
||||
}
|
||||
|
||||
export interface SignerListLedgerEntry {
|
||||
LedgerEntryType: 'SignerList',
|
||||
OwnerNode: string,
|
||||
@@ -73,11 +171,19 @@ export interface SignerListLedgerEntry {
|
||||
PreviousTxnLgrSeq: number
|
||||
}
|
||||
|
||||
// TODO: Add the other ledger entry types, then remove the `any` fallback
|
||||
// see https://ripple.com/build/ledger-format/#ledger-object-types
|
||||
export type LedgerEntry =
|
||||
AccountRootLedgerEntry |
|
||||
AmendmentsLedgerEntry |
|
||||
CheckLedgerEntry |
|
||||
DepositPreauthLedgerEntry |
|
||||
DirectoryNodeLedgerEntry |
|
||||
OfferDirectoryNodeLedgerEntry |
|
||||
OwnerDirectoryNodeLedgerEntry |
|
||||
EscrowLedgerEntry |
|
||||
FeeSettingsLedgerEntry |
|
||||
LedgerHashesLedgerEntry |
|
||||
OfferLedgerEntry |
|
||||
PayChannelLedgerEntry |
|
||||
SignerListLedgerEntry |
|
||||
any
|
||||
RippleStateLedgerEntry |
|
||||
SignerListLedgerEntry
|
||||
|
||||
@@ -11,20 +11,21 @@ export type Signers = {
|
||||
}
|
||||
|
||||
export type FormattedSettings = {
|
||||
passwordSpent?: boolean,
|
||||
requireDestinationTag?: boolean,
|
||||
requireAuthorization?: boolean,
|
||||
disallowIncomingXRP?: boolean,
|
||||
disableMasterKey?: boolean,
|
||||
enableTransactionIDTracking?: boolean,
|
||||
noFreeze?: boolean,
|
||||
globalFreeze?: boolean,
|
||||
defaultRipple?: boolean,
|
||||
emailHash?: string|null,
|
||||
messageKey?: string,
|
||||
depositAuth?: boolean,
|
||||
disableMasterKey?: boolean,
|
||||
disallowIncomingXRP?: boolean,
|
||||
domain?: string,
|
||||
transferRate?: number|null,
|
||||
emailHash?: string|null,
|
||||
enableTransactionIDTracking?: boolean,
|
||||
globalFreeze?: boolean,
|
||||
memos?: Memo[],
|
||||
messageKey?: string,
|
||||
noFreeze?: boolean,
|
||||
passwordSpent?: boolean,
|
||||
regularKey?: string,
|
||||
requireAuthorization?: boolean,
|
||||
requireDestinationTag?: boolean,
|
||||
signers?: Signers,
|
||||
memos?: Memo[]
|
||||
transferRate?: number|null
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import * as _ from 'lodash'
|
||||
import BigNumber from 'bignumber.js'
|
||||
const {deriveKeypair} = require('ripple-keypairs')
|
||||
|
||||
import {deriveKeypair} from 'ripple-keypairs'
|
||||
import {Amount, RippledAmount} from './types/objects'
|
||||
import {ValidationError} from './errors'
|
||||
|
||||
function isValidSecret(secret: string): boolean {
|
||||
try {
|
||||
@@ -13,18 +13,86 @@ function isValidSecret(secret: string): boolean {
|
||||
}
|
||||
}
|
||||
|
||||
function dropsToXrp(drops: string): string {
|
||||
return (new BigNumber(drops)).dividedBy(1000000.0).toString()
|
||||
function dropsToXrp(drops: string | BigNumber): string {
|
||||
if (typeof drops === 'string') {
|
||||
if (!drops.match(/^-?[0-9]*\.?[0-9]*$/)) {
|
||||
throw new ValidationError(`dropsToXrp: invalid value '${drops}',` +
|
||||
` should be a number matching (^-?[0-9]*\.?[0-9]*$).`)
|
||||
} else if (drops === '.') {
|
||||
throw new ValidationError(`dropsToXrp: invalid value '${drops}',` +
|
||||
` should be a BigNumber or string-encoded number.`)
|
||||
}
|
||||
}
|
||||
|
||||
// Converting to BigNumber and then back to string should remove any
|
||||
// decimal point followed by zeros, e.g. '1.00'.
|
||||
// Important: specify base 10 to avoid exponential notation, e.g. '1e-7'.
|
||||
drops = (new BigNumber(drops)).toString(10)
|
||||
|
||||
// drops are only whole units
|
||||
if (drops.includes('.')) {
|
||||
throw new ValidationError(`dropsToXrp: value '${drops}' has` +
|
||||
` too many decimal places.`)
|
||||
}
|
||||
|
||||
// This should never happen; the value has already been
|
||||
// validated above. This just ensures BigNumber did not do
|
||||
// something unexpected.
|
||||
if (!drops.match(/^-?[0-9]+$/)) {
|
||||
throw new ValidationError(`dropsToXrp: failed sanity check -` +
|
||||
` value '${drops}',` +
|
||||
` does not match (^-?[0-9]+$).`)
|
||||
}
|
||||
|
||||
return (new BigNumber(drops)).dividedBy(1000000.0).toString(10)
|
||||
}
|
||||
|
||||
function xrpToDrops(xrp: string): string {
|
||||
return (new BigNumber(xrp)).times(1000000.0).floor().toString()
|
||||
function xrpToDrops(xrp: string | BigNumber): string {
|
||||
if (typeof xrp === 'string') {
|
||||
if (!xrp.match(/^-?[0-9]*\.?[0-9]*$/)) {
|
||||
throw new ValidationError(`xrpToDrops: invalid value '${xrp}',` +
|
||||
` should be a number matching (^-?[0-9]*\.?[0-9]*$).`)
|
||||
} else if (xrp === '.') {
|
||||
throw new ValidationError(`xrpToDrops: invalid value '${xrp}',` +
|
||||
` should be a BigNumber or string-encoded number.`)
|
||||
}
|
||||
}
|
||||
|
||||
// Important: specify base 10 to avoid exponential notation, e.g. '1e-7'.
|
||||
xrp = (new BigNumber(xrp)).toString(10)
|
||||
|
||||
// This should never happen; the value has already been
|
||||
// validated above. This just ensures BigNumber did not do
|
||||
// something unexpected.
|
||||
if (!xrp.match(/^-?[0-9.]+$/)) {
|
||||
throw new ValidationError(`xrpToDrops: failed sanity check -` +
|
||||
` value '${xrp}',` +
|
||||
` does not match (^-?[0-9.]+$).`)
|
||||
}
|
||||
|
||||
const components = xrp.split('.')
|
||||
if (components.length > 2) {
|
||||
throw new ValidationError(`xrpToDrops: failed sanity check -` +
|
||||
` value '${xrp}' has` +
|
||||
` too many decimal points.`)
|
||||
}
|
||||
|
||||
const fraction = components[1] || '0'
|
||||
if (fraction.length > 6) {
|
||||
throw new ValidationError(`xrpToDrops: value '${xrp}' has` +
|
||||
` too many decimal places.`)
|
||||
}
|
||||
|
||||
return (new BigNumber(xrp)).times(1000000.0).floor().toString(10)
|
||||
}
|
||||
|
||||
function toRippledAmount(amount: Amount): RippledAmount {
|
||||
if (amount.currency === 'XRP') {
|
||||
return xrpToDrops(amount.value)
|
||||
}
|
||||
if (amount.currency === 'drops') {
|
||||
return amount.value
|
||||
}
|
||||
return {
|
||||
currency: amount.currency,
|
||||
issuer: amount.counterparty ? amount.counterparty :
|
||||
@@ -65,7 +133,7 @@ function rippleToUnixTimestamp(rpepoch: number): number {
|
||||
|
||||
/**
|
||||
* @param {Number|Date} timestamp (ms since unix epoch)
|
||||
* @return {Number} seconds since ripple epoch ( 1/1/2000 GMT)
|
||||
* @return {Number} seconds since ripple epoch (1/1/2000 GMT)
|
||||
*/
|
||||
function unixToRippleTimestamp(timestamp: number): number {
|
||||
return Math.round(timestamp / 1000) - 0x386D4380
|
||||
@@ -75,6 +143,10 @@ function rippleTimeToISO8601(rippleTime: number): string {
|
||||
return new Date(rippleToUnixTimestamp(rippleTime)).toISOString()
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} iso8601 international standard date format
|
||||
* @return {number} seconds since ripple epoch (1/1/2000 GMT)
|
||||
*/
|
||||
function iso8601ToRippleTime(iso8601: string): number {
|
||||
return unixToRippleTimestamp(Date.parse(iso8601))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
|
||||
|
||||
export {RippleAPI} from './api'
|
||||
|
||||
export {
|
||||
FormattedTransactionType
|
||||
} from './transaction/types'
|
||||
|
||||
// Broadcast api is experimental
|
||||
export {RippleAPIBroadcast} from './broadcast'
|
||||
|
||||
@@ -35,7 +35,7 @@ export default async function getAccountInfo(
|
||||
// 1. Validate
|
||||
validate.getAccountInfo({address, options})
|
||||
// 2. Make Request
|
||||
const response = await this._request('account_info', {
|
||||
const response = await this.request('account_info', {
|
||||
account: address,
|
||||
ledger_index: options.ledgerVersion || 'validated'
|
||||
})
|
||||
|
||||
@@ -14,7 +14,7 @@ export default async function getAccountObjects(
|
||||
// through to rippled. rippled validates requests.
|
||||
|
||||
// Make Request
|
||||
const response = await this._request('account_objects', removeUndefined({
|
||||
const response = await this.request('account_objects', removeUndefined({
|
||||
account: address,
|
||||
type: options.type,
|
||||
ledger_hash: options.ledgerHash,
|
||||
|
||||
@@ -54,7 +54,7 @@ async function getBalanceSheet(
|
||||
validate.getBalanceSheet({address, options})
|
||||
options = await ensureLedgerVersion.call(this, options)
|
||||
// 2. Make Request
|
||||
const response = await this._request('gateway_balances', {
|
||||
const response = await this.request('gateway_balances', {
|
||||
account: address,
|
||||
strict: true,
|
||||
hotwallet: options.excludeAddresses,
|
||||
|
||||
@@ -15,7 +15,7 @@ async function getLedger(
|
||||
// 1. Validate
|
||||
validate.getLedger({options})
|
||||
// 2. Make Request
|
||||
const response = await this._request('ledger', {
|
||||
const response = await this.request('ledger', {
|
||||
ledger_index: options.ledgerVersion || 'validated',
|
||||
expand: options.includeAllData,
|
||||
transactions: options.includeTransactions,
|
||||
@@ -25,5 +25,4 @@ async function getLedger(
|
||||
return parseLedger(response.ledger)
|
||||
}
|
||||
|
||||
|
||||
export default getLedger
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as assert from 'assert'
|
||||
|
||||
function parseOrderCancellation(tx: any): Object {
|
||||
function parseOrderCancellation(tx: any): object {
|
||||
assert(tx.TransactionType === 'OfferCancel')
|
||||
return {
|
||||
orderSequence: tx.OfferSequence
|
||||
|
||||
21
src/ledger/parse/deposit-preauth.ts
Normal file
21
src/ledger/parse/deposit-preauth.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import * as assert from 'assert'
|
||||
import {removeUndefined} from '../../common'
|
||||
|
||||
export type FormattedDepositPreauth = {
|
||||
// account (address) of the sender to preauthorize
|
||||
authorize: string,
|
||||
|
||||
// account (address) of the sender whose preauthorization should be revoked
|
||||
unauthorize: string
|
||||
}
|
||||
|
||||
function parseDepositPreauth(tx: any): FormattedDepositPreauth {
|
||||
assert(tx.TransactionType === 'DepositPreauth')
|
||||
|
||||
return removeUndefined({
|
||||
authorize: tx.Authorize,
|
||||
unauthorize: tx.Unauthorize
|
||||
})
|
||||
}
|
||||
|
||||
export default parseDepositPreauth
|
||||
@@ -2,7 +2,7 @@ import * as assert from 'assert'
|
||||
import {parseMemos} from './utils'
|
||||
import {removeUndefined} from '../../common'
|
||||
|
||||
function parseEscrowCancellation(tx: any): Object {
|
||||
function parseEscrowCancellation(tx: any): object {
|
||||
assert(tx.TransactionType === 'EscrowCancel')
|
||||
|
||||
return removeUndefined({
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user