Compare commits

...

94 Commits
1.5.0 ... 1.6.2

Author SHA1 Message Date
Elliot Lee
208f5f6c5c Release 1.6.2 2020-01-17 15:30:21 -08:00
Elliot Lee
de3e2a9867 Docs: Fix whitespace
Do not use newline-trimming ending tag

Fix #1175 (bug introduced in #1153)
2020-01-17 15:24:23 -08:00
dependabot-preview[bot]
40eea3c659 Bump typescript from 3.7.4 to 3.7.5 (#1181)
Bumps [typescript](https://github.com/Microsoft/TypeScript) from 3.7.4 to 3.7.5.
- [Release notes](https://github.com/Microsoft/TypeScript/releases)
- [Commits](https://github.com/Microsoft/TypeScript/compare/v3.7.4...v3.7.5)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-17 14:45:33 -05:00
FKSRipple
4a848ec527 Merge pull request #1179 from nickewansmith/fix-unhandled-rejection-warning-on-heartbeat
Catch possible error in reconnect() on _heartbeat(), emit reconnect error
2020-01-16 08:32:37 -08:00
FKSRipple
10414e169c Merge pull request #1171 from ripple/dependabot/npm_and_yarn/typescript-eslint/eslint-plugin-2.16.0
Bump @typescript-eslint/eslint-plugin from 2.13.0 to 2.16.0
2020-01-16 08:22:42 -08:00
FKSRipple
1a6c68d028 Merge pull request #1173 from ripple/FKSRipple-patch-1-1
Add Update note to HISTORY.md
2020-01-16 08:22:21 -08:00
FKSRipple
9156734ced Update HISTORY.md 2020-01-16 08:22:00 -08:00
FKSRipple
0dfe3ff4ac Merge pull request #1177 from ripple/dependabot/npm_and_yarn/types/ws-7.2.0
Bump @types/ws from 6.0.4 to 7.2.0
2020-01-16 08:21:12 -08:00
FKSRipple
3a8c7f02cc Merge pull request #1176 from ripple/dependabot/npm_and_yarn/types/node-13.1.7
Bump @types/node from 13.1.6 to 13.1.7
2020-01-16 08:20:53 -08:00
Nicholas Smith
e03b192fcc Catch possible error in reconnect() on _heartbeat(), emit reconnect error 2020-01-15 12:36:39 -05:00
dependabot-preview[bot]
cf40bd2c30 Bump @types/ws from 6.0.4 to 7.2.0
Bumps [@types/ws](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/ws) from 6.0.4 to 7.2.0.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/ws)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-15 13:40:35 +00:00
dependabot-preview[bot]
4082e88416 Bump @types/node from 13.1.6 to 13.1.7
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 13.1.6 to 13.1.7.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-15 13:40:09 +00:00
FKSRipple
27abc10d93 Merge pull request #1172 from ripple/dependabot/npm_and_yarn/ts-node-8.6.2
Bump ts-node from 8.5.4 to 8.6.2
2020-01-14 11:27:39 -08:00
FKSRipple
d6474d71f2 Update HISTORY.md 2020-01-14 11:26:35 -08:00
dependabot-preview[bot]
d57603e854 Bump ts-node from 8.5.4 to 8.6.2
Bumps [ts-node](https://github.com/TypeStrong/ts-node) from 8.5.4 to 8.6.2.
- [Release notes](https://github.com/TypeStrong/ts-node/releases)
- [Commits](https://github.com/TypeStrong/ts-node/compare/v8.5.4...v8.6.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-14 13:41:19 +00:00
dependabot-preview[bot]
ac92584678 Bump @typescript-eslint/eslint-plugin from 2.13.0 to 2.16.0
Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 2.13.0 to 2.16.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v2.16.0/packages/eslint-plugin)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-14 13:40:55 +00:00
Elliot Lee
c234be0a8c Release 1.6.1 (#1170)
Update HISTORY and version number
2020-01-13 23:48:59 -08:00
Hans Bergren
7c6b8398cf Improve documentation for generateXAddress() (#1169)
It takes an optional property for including the classic address in the
return payload

Co-authored-by: Elliot Lee
2020-01-13 23:39:02 -08:00
Elliot Lee
7de677c953 Create SECURITY.md (#1164) 2020-01-13 23:27:05 -08:00
FKSRipple
aa23f44555 Merge pull request #1168 from ripple/dependabot/npm_and_yarn/mocha-junit-reporter-1.23.2
Bump mocha-junit-reporter from 1.23.1 to 1.23.2
2020-01-13 22:17:47 -08:00
dependabot-preview[bot]
901d75a1eb Bump mocha-junit-reporter from 1.23.1 to 1.23.2
Bumps [mocha-junit-reporter](https://github.com/michaelleeallen/mocha-junit-reporter) from 1.23.1 to 1.23.2.
- [Release notes](https://github.com/michaelleeallen/mocha-junit-reporter/releases)
- [Commits](https://github.com/michaelleeallen/mocha-junit-reporter/compare/v1.23.1...v1.23.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-13 13:27:35 +00:00
FKSRipple
aa95286810 Merge pull request #1140 from ripple/connection-cleanup-tests
Refactor tests to support the new connection logic
2020-01-10 17:24:52 -08:00
FKSRipple
f6b3f661d6 Merge branch 'develop' into connection-cleanup-tests 2020-01-10 16:15:16 -08:00
FKSRipple
0850d85791 Merge pull request #1141 from ripple/connection-cleanup-logic
Refactor the Connection class
2020-01-10 16:10:27 -08:00
FKSRipple
c564400ac4 Merge pull request #1119 from ripple/connection-cleanup-ledger
Add LedgerHistory to Connection
2020-01-10 16:07:08 -08:00
dependabot-preview[bot]
94ab545ffe Bump @types/node from 13.1.4 to 13.1.6 (#1163)
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 13.1.4 to 13.1.6.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-10 11:57:41 -08:00
Hans Bergren
e10df203b7 Update documentation for functions that can be called offline (#1159)
You can also generate an X-Address without a connection to the ledger.
2020-01-09 10:33:12 -05:00
Hans Bergren
eea20a6eab Improve documentation for address generation (#1158)
The documentation previously just stated that any array of integers
was acceptable for providing as entropy, but it must be an array of
length 16 where the values are from 0-255 (uint8) to ensure we have
16 bytes of entropy.
2020-01-08 18:30:08 -05:00
Fred K. Schott
5f208801ee move backoff into codebase 2020-01-08 14:50:17 -08:00
Fred K. Schott
0a22697e5d Refactor the Connection 2020-01-08 12:21:37 -08:00
Fred K. Schott
30cf4f0b00 cleanup event listeners 2020-01-08 12:20:58 -08:00
Fred K. Schott
e4bb88a725 clarify comment 2020-01-08 12:20:58 -08:00
Fred K. Schott
e3822e6bc3 refactor tests for the new connection logic 2020-01-08 12:20:58 -08:00
Fred K. Schott
20d3be0d1d nevermind, regression wasn't actually a regression 2020-01-08 12:20:40 -08:00
Fred K. Schott
1785863686 update docs, fix a regression 2020-01-08 11:53:33 -08:00
FKSRipple
ea4ced3cc1 Merge pull request #1154 from ripple/dependabot/npm_and_yarn/types/node-13.1.4
Bump @types/node from 13.1.2 to 13.1.4
2020-01-08 11:35:01 -08:00
FKSRipple
149008d18b Merge pull request #1156 from ripple/dependabot/npm_and_yarn/ripple-binary-codec-0.2.6
Bump ripple-binary-codec from 0.2.5 to 0.2.6
2020-01-08 11:34:15 -08:00
FKSRipple
55a21d2eec Merge pull request #1157 from ripple/dependabot/npm_and_yarn/mocha-7.0.0
Bump mocha from 6.2.2 to 7.0.0
2020-01-08 11:32:45 -08:00
dependabot-preview[bot]
c7491e631a Bump mocha from 6.2.2 to 7.0.0
Bumps [mocha](https://github.com/mochajs/mocha) from 6.2.2 to 7.0.0.
- [Release notes](https://github.com/mochajs/mocha/releases)
- [Changelog](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mochajs/mocha/compare/v6.2.2...v7.0.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-08 13:40:56 +00:00
dependabot-preview[bot]
468a205e36 Bump ripple-binary-codec from 0.2.5 to 0.2.6
Bumps [ripple-binary-codec](https://github.com/ripple/ripple-binary-codec) from 0.2.5 to 0.2.6.
- [Release notes](https://github.com/ripple/ripple-binary-codec/releases)
- [Changelog](https://github.com/ripple/ripple-binary-codec/blob/master/HISTORY.md)
- [Commits](https://github.com/ripple/ripple-binary-codec/compare/0.2.5...0.2.6)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-08 13:40:27 +00:00
dependabot-preview[bot]
bebe951a57 Bump @types/node from 13.1.2 to 13.1.4
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 13.1.2 to 13.1.4.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-08 13:39:39 +00:00
FKSRipple
85a8ab32ef update docs dependencies (#1153) 2020-01-07 15:30:29 -08:00
FKSRipple
34ddbe170c Merge pull request #1127 from you21979/fix-account-object
fix AccountObjectsResponse structure
2020-01-07 11:52:01 -08:00
FKSRipple
e9846eb249 Merge pull request #1145 from ripple/dependabot/npm_and_yarn/nyc-15.0.0
Bump nyc from 14.1.1 to 15.0.0
2020-01-07 11:51:39 -08:00
FKSRipple
7cc418ac93 Merge pull request #1131 from ripple/dependabot/npm_and_yarn/ws-7.2.1
Bump ws from 7.2.0 to 7.2.1
2020-01-07 11:50:43 -08:00
FKSRipple
69532a4f23 Merge pull request #1128 from ripple/dependabot/npm_and_yarn/typescript-3.7.4
Bump typescript from 3.6.4 to 3.7.4
2020-01-07 11:49:21 -08:00
FKSRipple
f59419d96f Update ledger_entries.ts 2020-01-07 11:44:14 -08:00
FKSRipple
7f288d0555 Update signers.ts 2020-01-07 11:43:37 -08:00
FKSRipple
53afa8c276 Merge pull request #1121 from r0bertz/develop
Document message type 'path_find' that connection can listen on
2020-01-07 11:34:57 -08:00
dependabot-preview[bot]
22f4dd2f75 Bump ws from 7.2.0 to 7.2.1
Bumps [ws](https://github.com/websockets/ws) from 7.2.0 to 7.2.1.
- [Release notes](https://github.com/websockets/ws/releases)
- [Commits](https://github.com/websockets/ws/compare/7.2.0...7.2.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-07 19:29:37 +00:00
FKSRipple
0989152024 Merge pull request #1150 from ripple/dependabot/npm_and_yarn/ripple-lib-transactionparser-0.8.2
Bump ripple-lib-transactionparser from 0.8.1 to 0.8.2
2020-01-07 11:28:03 -08:00
dependabot-preview[bot]
f74809d361 Bump nyc from 14.1.1 to 15.0.0
Bumps [nyc](https://github.com/istanbuljs/nyc) from 14.1.1 to 15.0.0.
- [Release notes](https://github.com/istanbuljs/nyc/releases)
- [Changelog](https://github.com/istanbuljs/nyc/blob/master/CHANGELOG.md)
- [Commits](https://github.com/istanbuljs/nyc/compare/v14.1.1...v15.0.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-07 19:27:39 +00:00
FKSRipple
9724cf7776 Merge pull request #1144 from ripple/dependabot/npm_and_yarn/eslint-6.8.0
Bump eslint from 6.5.1 to 6.8.0
2020-01-07 11:26:01 -08:00
dependabot-preview[bot]
909e5438a8 Bump typescript from 3.6.4 to 3.7.4
Bumps [typescript](https://github.com/Microsoft/TypeScript) from 3.6.4 to 3.7.4.
- [Release notes](https://github.com/Microsoft/TypeScript/releases)
- [Commits](https://github.com/Microsoft/TypeScript/commits)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-06 21:49:27 +00:00
Hans Bergren
3c534d87c0 Release 1.6.0 2020-01-06 16:47:44 -05:00
dependabot-preview[bot]
4022a59705 Bump ripple-lib-transactionparser from 0.8.1 to 0.8.2
Bumps [ripple-lib-transactionparser](https://github.com/ripple/ripple-lib-extensions) from 0.8.1 to 0.8.2.
- [Release notes](https://github.com/ripple/ripple-lib-extensions/releases)
- [Commits](https://github.com/ripple/ripple-lib-extensions/compare/0.8.1...0.8.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-06 13:26:07 +00:00
Elliot Lee
138e7942da Add support for AccountDelete (#1120)
https://xrpl.org/accountdelete.html
2020-01-06 04:01:10 -08:00
dependabot-preview[bot]
d7d26a3ae1 Bump eslint from 6.5.1 to 6.8.0
Bumps [eslint](https://github.com/eslint/eslint) from 6.5.1 to 6.8.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/master/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v6.5.1...v6.8.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-06 03:56:35 +00:00
dependabot-preview[bot]
23504821cf Bump @typescript-eslint/parser from 2.13.0 to 2.14.0 (#1147)
Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 2.13.0 to 2.14.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/parser/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v2.14.0/packages/parser)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-05 19:54:52 -08:00
dependabot-preview[bot]
b09da3e8f1 Bump @types/node from 13.1.1 to 13.1.2 (#1148)
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 13.1.1 to 13.1.2.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-05 19:54:37 -08:00
Elliot Lee
f3dd2fec99 Merge pull request #1098 from nickewansmith/fix-possible-unhandled-throw-on-send
Adds unit test for ripple#1092, fixes unhandled throw on upgraded ws send
2020-01-05 19:51:58 -08:00
Elliot Lee
462e375800 Add ripple-latest.js to npm 2019-12-28 11:51:00 -08:00
Elliot Lee
ca8c881375 Release 1.5.1 2019-12-28 11:47:57 -08:00
Elliot Lee
96605a57d4 Fix CDNs (#1142)
* Rename browser build output file to ripple-latest-min.js (the name prior to #1061)
* Add unpkg and jsdelivr
2019-12-28 11:46:52 -08:00
FKSRipple
491ce40081 Merge pull request #1136 from ripple/dependabot/npm_and_yarn/typescript-eslint/eslint-plugin-2.13.0
Bump @typescript-eslint/eslint-plugin from 2.5.0 to 2.13.0
2019-12-27 12:46:00 -08:00
FKSRipple
f33eb07bdd Merge pull request #1135 from ripple/dependabot/npm_and_yarn/https-proxy-agent-4.0.0
Bump https-proxy-agent from 3.0.1 to 4.0.0
2019-12-27 10:16:58 -08:00
dependabot-preview[bot]
8bb1dc9b47 Bump @typescript-eslint/eslint-plugin from 2.5.0 to 2.13.0
Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 2.5.0 to 2.13.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v2.13.0/packages/eslint-plugin)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-12-27 18:03:54 +00:00
FKSRipple
78b50472da Merge pull request #1137 from ripple/dependabot/npm_and_yarn/types/node-13.1.1
Bump @types/node from 12.12.5 to 13.1.1
2019-12-27 10:02:11 -08:00
FKSRipple
e0259b37ed Merge pull request #1138 from ripple/dependabot/npm_and_yarn/eventemitter2-6.0.0
Bump eventemitter2 from 5.0.1 to 6.0.0
2019-12-27 10:01:27 -08:00
FKSRipple
bf863a2594 Merge pull request #1139 from ripple/dependabot/npm_and_yarn/typescript-eslint/parser-2.13.0
Bump @typescript-eslint/parser from 2.5.0 to 2.13.0
2019-12-27 10:01:10 -08:00
FKSRipple
edd174881e Merge pull request #1134 from ripple/dependabot/npm_and_yarn/types/lodash-4.14.149
Bump @types/lodash from 4.14.144 to 4.14.149
2019-12-27 09:57:50 -08:00
dependabot-preview[bot]
0bf747f6fc Bump @typescript-eslint/parser from 2.5.0 to 2.13.0
Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 2.5.0 to 2.13.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/parser/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v2.13.0/packages/parser)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-12-27 13:40:22 +00:00
dependabot-preview[bot]
ab4d2b5d58 Bump eventemitter2 from 5.0.1 to 6.0.0
Bumps [eventemitter2](https://github.com/hij1nx/EventEmitter2) from 5.0.1 to 6.0.0.
- [Release notes](https://github.com/hij1nx/EventEmitter2/releases)
- [Changelog](https://github.com/EventEmitter2/EventEmitter2/blob/master/CHANGELOG.md)
- [Commits](https://github.com/hij1nx/EventEmitter2/commits/v6.0.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-12-27 13:39:54 +00:00
dependabot-preview[bot]
1b81280358 Bump mocha from 6.2.0 to 6.2.2 (#1126)
Bumps [mocha](https://github.com/mochajs/mocha) from 6.2.0 to 6.2.2.
- [Release notes](https://github.com/mochajs/mocha/releases)
- [Changelog](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mochajs/mocha/compare/v6.2.0...v6.2.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-12-26 12:49:31 -08:00
dependabot-preview[bot]
32f4eea3b8 Bump @types/node from 12.12.5 to 13.1.1
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 12.12.5 to 13.1.1.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-12-26 20:21:14 +00:00
dependabot-preview[bot]
1a3a49decb Bump @types/ws from 6.0.3 to 6.0.4 (#1125)
Bumps [@types/ws](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/ws) from 6.0.3 to 6.0.4.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/ws)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-12-26 12:19:32 -08:00
dependabot-preview[bot]
416717aff6 Bump https-proxy-agent from 3.0.1 to 4.0.0
Bumps [https-proxy-agent](https://github.com/TooTallNate/node-https-proxy-agent) from 3.0.1 to 4.0.0.
- [Release notes](https://github.com/TooTallNate/node-https-proxy-agent/releases)
- [Commits](https://github.com/TooTallNate/node-https-proxy-agent/compare/3.0.1...4.0.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-12-24 13:53:06 +00:00
dependabot-preview[bot]
769d955a40 Bump @types/lodash from 4.14.144 to 4.14.149
Bumps [@types/lodash](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/lodash) from 4.14.144 to 4.14.149.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/lodash)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-12-24 13:52:42 +00:00
dependabot-preview[bot]
6de85b841d Bump ts-node from 8.4.1 to 8.5.4 (#1124)
Bumps [ts-node](https://github.com/TypeStrong/ts-node) from 8.4.1 to 8.5.4.
- [Release notes](https://github.com/TypeStrong/ts-node/releases)
- [Commits](https://github.com/TypeStrong/ts-node/compare/v8.4.1...v8.5.4)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-12-23 11:40:59 -08:00
yuki akiyama
66db127245 fix AccountObjectsResponse: Does not match the structure returned by the API. 2019-12-23 13:21:26 +09:00
dependabot-preview[bot]
b4c6af29e4 Bump webpack from 4.41.2 to 4.41.4 (#1123)
Bumps [webpack](https://github.com/webpack/webpack) from 4.41.2 to 4.41.4.
- [Release notes](https://github.com/webpack/webpack/releases)
- [Commits](https://github.com/webpack/webpack/compare/v4.41.2...v4.41.4)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-12-22 15:53:29 -08:00
dependabot-preview[bot]
7192606e21 Bump webpack-cli from 3.3.9 to 3.3.10 (#1122)
Bumps [webpack-cli](https://github.com/webpack/webpack-cli) from 3.3.9 to 3.3.10.
- [Release notes](https://github.com/webpack/webpack-cli/releases)
- [Changelog](https://github.com/webpack/webpack-cli/blob/v3.3.10/CHANGELOG.md)
- [Commits](https://github.com/webpack/webpack-cli/compare/v3.3.9...v3.3.10)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-12-22 15:52:01 -08:00
Robert Zhang
932be02e9e Document message type 'path_find' that connection can listen on 2019-12-21 20:01:00 -08:00
Fred K. Schott
fc524894c6 add ledger to connection 2019-12-18 11:35:47 -08:00
FKSRipple
f5196389e8 Merge pull request #1116 from ripple/prettier-format
run prettier format
2019-12-18 11:25:14 -08:00
FKSRipple
27be06c5c9 Merge pull request #1118 from ripple/eslint-fix
Fix incorrect eslint matching glob
2019-12-18 11:24:52 -08:00
Fred K. Schott
1d3ddb5e85 update eslint command 2019-12-17 10:36:32 -08:00
Fred K. Schott
2145c104fd run prettier format 2019-12-17 10:35:59 -08:00
FKSRipple
64e0d098e7 Merge pull request #1115 from ripple/connection-cleanup-config
Cleanup the connection config state
2019-12-17 10:31:04 -08:00
FKSRipple
50d8cbb0ee Merge pull request #1114 from ripple/connection-cleanup-trace
Cleanup the connection trace logic
2019-12-17 08:58:44 -08:00
Fred K. Schott
9580397558 cleanup the connection config 2019-12-16 17:26:00 -08:00
Fred K. Schott
cf544b74f5 fix msg abbreviation 2019-12-16 17:25:21 -08:00
Fred K. Schott
312f831efb cleanup the connection trace logic 2019-12-16 11:57:51 -08:00
Nicholas Smith
fa6a2c5bbb Adds unit test for ripple#1092, fixes unhandled throw when not connected on send due to upgraded ws module 2019-11-17 01:28:19 -05:00
196 changed files with 6354 additions and 4500 deletions

View File

@@ -20,6 +20,7 @@
"no-useless-constructor": 0,
"no-unused-vars": 0,
"no-prototype-builtins": 0,
"require-atomic-updates": 0
"require-atomic-updates": 0,
"no-dupe-class-members": 0
}
}

View File

@@ -5,5 +5,6 @@
"semi": false,
"singleQuote": true,
"trailingComma": "none",
"quoteProps": "consistent"
"quoteProps": "consistent",
"bracketSpacing": false
}

View File

@@ -1,5 +1,49 @@
# ripple-lib Release History
## 1.6.2 (2020-01-17)
* Bug fix: Catch possible error in reconnect() on _heartbeat(), emit reconnect error (#1179)
* Docs: Fix whitespace
* Dependencies
* Update @typescript-eslint/eslint-plugin, ts-node, @types/node, @types/ws, typescript
## 1.6.1 (2020-01-14)
> **Update Note:** In this release we refactored the internal connection logic of ripple-lib to improve resiliency across dropped messages and reconnects. The external interface remains the same, with zero changes to public methods/properties. However, If you experience any problems around connections, requests, and request retries, please [file an issue]( https://github.com/ripple/ripple-lib/issues/new) with the repo (and be sure to test against v1.6.0 to confirm that the problem was introduced in this version).
* Documentation
* Document message type 'path_find' (#1121) (thanks @r0bertz)
* Improve documentation for address generation; functions that can be called offline; generateXAddress() (#1158, #1159, #1169) (thanks @hbergren)
* Add [Security Policy](https://github.com/ripple/ripple-lib/blob/develop/SECURITY.md)
* Bug fixes
* Types: Fix AccountObjectsResponse structure (#1127) (thanks @you21979)
* In some cases, ripple-lib would fail to wait for the connection to be ready (#1119)
* Dependencies
* Update docs dependencies, ejs and doctoc (#1153)
* Update eslint, ripple-lib-transactionparser, typescript, nyc, ws, @types/node, ripple-binary-codec, mocha, mocha-junit-reporter
* Internal
* Add LedgerHistory to Connection (#1119): Moved ledger logic into its own Ledger class
## 1.6.0 (2020-01-06)
* Add support for AccountDelete (#1120)
* Improve error type given on rejected message _send to be DisconnectedError (#1098)
* Internal
* Add unit test for unhandled promise rejection warning on message _send (#1098)
* Dependencies
* Update @types/node, @typescript-eslint/parser
## 1.5.1 (2019-12-28)
* Fix support for CDNs (#1142)
* Internal
* Clean up connection trace logic (#1114)
* Clean up the connection config (#1115)
* Run prettier format (#1116)
* Update eslint command (#1118)
* Dependencies
* Update webpack-cli, webpack, ts-node, @types/lodash, @types/ws, @types/node, @typescript-eslint/parser, @typescript-eslint/eslint-plugin, https-proxy-agent, mocha, eventemitter2
## 1.5.0 (2019-12-14)
* Add support for `WalletLocator` (#1083)
@@ -427,7 +471,7 @@ f28921f57a133678dcb3cb54c497626bd76b1f953d22d61f3ddca31c8947d552 ripple-1.1.0-m
The SHA-256 checksums for the browser version of this release can be found
below.
```
% shasum -a 256 *
% shasum -a 256 *
2556fe17296e127ed44e7066e90a6175e2b164f00ca3c1aa7b1c554f31c688dd ripple-1.0.2-debug.js
e0342ea21eac32a1024c62034fba09c6f26dd3e7371b23ea1e153e03135cd590 ripple-1.0.2-min.js
c7286c517497d018d02d09257e81172b61d36c8b9885a077af68e8133c3b3b9b ripple-1.0.2.js

29
SECURITY.md Normal file
View File

@@ -0,0 +1,29 @@
# Security Policy
## Supported Versions
This table shows which versions of ripple-lib are currently supported with security updates:
| Version | Supported |
| ------- | ---------------------- |
| 1.x | :white_check_mark: Yes |
| 0.x | :x: No |
## Responsible disclosure security policy
The responsible disclosure of vulnerabilities helps to protect users of the project. Vulnerabilities are first triaged in a private manner, and only publicly disclosed after a reasonable time period that allows patching the vulnerability and provides an upgrade path for users.
When contacting us directly via email, we will do our best to respond in a reasonable time to resolve the issue. Do not disclose the vulnerability until it has been patched and users have been given time to upgrade.
We kindly ask you to refrain from malicious acts that put our users, the project, or any of the projects team members at risk.
## Reporting a security issue
Security is a top priority. But no matter how much effort we put into security, there can still be vulnerabilities present.
If you discover a security vulnerability, please use the following means of communications to report it to us:
- Report the security issue to bugs@ripple.com
- [Ripple Bug Bounty](https://ripple.com/bug-bounty/)
Your efforts to responsibly disclose your findings are sincerely appreciated and will be taken into account to acknowledge your contributions.

View File

@@ -221,6 +221,7 @@ Methods that depend on the state of the XRP Ledger are unavailable in offline mo
* [prepareEscrowExecution](#prepareescrowexecution)
* [sign](#sign)
* [generateAddress](#generateaddress)
* [generateXAddress](#generatexaddress)
* [computeLedgerHash](#computeledgerhash)
# Basic Types
@@ -834,6 +835,7 @@ Type | Description
`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.
`path_find` | Asynchronous follow-up response to the currently open path\_find request. See [rippled path\_find method](https://xrpl.org/path_find.html) for details.
To register your listener function, use `connection.on(type, handler)`.
@@ -4511,7 +4513,7 @@ Prepare a transaction. The prepared transaction must subsequently be [signed](#s
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).
Notably, this is the preferred method for preparing `DepositPreauth` or `AccountDelete` transactions.
### Parameters
@@ -5662,7 +5664,8 @@ Name | Type | Description
---- | ---- | -----------
options | object | *Optional* Options to control how the address and secret are generated.
*options.* algorithm | string | *Optional* The digital signature algorithm to generate an address for. Can be `ecdsa-secp256k1` (default) or `ed25519`.
*options.* entropy | array\<integer\> | *Optional* The entropy to use to generate the seed.
*options.* entropy | array\<integer\> | *Optional* The entropy to use to generate the seed. Must be an array of length 16 with values from 0-255 (16 bytes of entropy)
*options.* includeClassicAddress | boolean | *Optional* Specifies whether the classic address should also be included in the returned payload.
*options.* test | boolean | *Optional* Specifies whether the address is intended for use on a test network such as Testnet or Devnet. If `true`, the address should only be used for testing, and will start with `T`. If `false`, the address should only be used on mainnet, and will start with `X`.
### Return Value
@@ -5703,7 +5706,7 @@ Name | Type | Description
---- | ---- | -----------
options | object | *Optional* Options to control how the address and secret are generated.
*options.* algorithm | string | *Optional* The digital signature algorithm to generate an address for. Can be `ecdsa-secp256k1` (default) or `ed25519`.
*options.* entropy | array\<integer\> | *Optional* The entropy to use to generate the seed.
*options.* entropy | array\<integer\> | *Optional* The entropy to use to generate the seed. Must be an array of length 16 with values from 0-255 (16 bytes of entropy)
*options.* includeClassicAddress | boolean | *Optional* If `true`, return the classic address, in addition to the X-address.
*options.* test | boolean | *Optional* Specifies whether the address is intended for use on a test network such as Testnet or Devnet. If `true`, the address should only be used for testing, and will start with `T`. If `false`, the address should only be used on mainnet, and will start with `X`.

View File

@@ -1,69 +1,69 @@
<% include introduction.md.ejs %>
<% include boilerplate.md.ejs %>
<% include offline.md.ejs %>
<% 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('introduction.md.ejs') %>
<%- include('boilerplate.md.ejs') %>
<%- include('offline.md.ejs') %>
<%- 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 staticMethods.md.ejs %>
<% include renameCounterpartyToIssuer.md.ejs %>
<% include formatBidsAndAsks.md.ejs %>
<%- include('staticMethods.md.ejs') %>
<%- include('renameCounterpartyToIssuer.md.ejs') %>
<%- include('formatBidsAndAsks.md.ejs') %>
<% include methods.md.ejs %>
<% include connect.md.ejs %>
<% include disconnect.md.ejs %>
<% include isConnected.md.ejs %>
<% include getServerInfo.md.ejs %>
<% include getFee.md.ejs %>
<% include getLedgerVersion.md.ejs %>
<% include getTransaction.md.ejs %>
<% include getTransactions.md.ejs %>
<% include getTrustlines.md.ejs %>
<% include getBalances.md.ejs %>
<% include getBalanceSheet.md.ejs %>
<% include getPaths.md.ejs %>
<% include getOrders.md.ejs %>
<% include getOrderbook.md.ejs %>
<% include getSettings.md.ejs %>
<% include getAccountInfo.md.ejs %>
<% 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 %>
<% include prepareOrderCancellation.md.ejs %>
<% include prepareSettings.md.ejs %>
<% include prepareEscrowCreation.md.ejs %>
<% include prepareEscrowCancellation.md.ejs %>
<% include prepareEscrowExecution.md.ejs %>
<% include preparePaymentChannelCreate.md.ejs %>
<% include preparePaymentChannelClaim.md.ejs %>
<% include preparePaymentChannelFund.md.ejs %>
<% include prepareCheckCreate.md.ejs %>
<% include prepareCheckCancel.md.ejs %>
<% include prepareCheckCash.md.ejs %>
<% include sign.md.ejs %>
<% include combine.md.ejs %>
<% include submit.md.ejs %>
<% include generateXAddress.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 rippleTimeToISO8601.md.ejs %>
<% include txFlags.md.ejs %>
<% include schemaValidator.md.ejs %>
<% include events.md.ejs %>
<%- include('methods.md.ejs') %>
<%- include('connect.md.ejs') %>
<%- include('disconnect.md.ejs') %>
<%- include('isConnected.md.ejs') %>
<%- include('getServerInfo.md.ejs') %>
<%- include('getFee.md.ejs') %>
<%- include('getLedgerVersion.md.ejs') %>
<%- include('getTransaction.md.ejs') %>
<%- include('getTransactions.md.ejs') %>
<%- include('getTrustlines.md.ejs') %>
<%- include('getBalances.md.ejs') %>
<%- include('getBalanceSheet.md.ejs') %>
<%- include('getPaths.md.ejs') %>
<%- include('getOrders.md.ejs') %>
<%- include('getOrderbook.md.ejs') %>
<%- include('getSettings.md.ejs') %>
<%- include('getAccountInfo.md.ejs') %>
<%- 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') %>
<%- include('prepareOrderCancellation.md.ejs') %>
<%- include('prepareSettings.md.ejs') %>
<%- include('prepareEscrowCreation.md.ejs') %>
<%- include('prepareEscrowCancellation.md.ejs') %>
<%- include('prepareEscrowExecution.md.ejs') %>
<%- include('preparePaymentChannelCreate.md.ejs') %>
<%- include('preparePaymentChannelClaim.md.ejs') %>
<%- include('preparePaymentChannelFund.md.ejs') %>
<%- include('prepareCheckCreate.md.ejs') %>
<%- include('prepareCheckCancel.md.ejs') %>
<%- include('prepareCheckCash.md.ejs') %>
<%- include('sign.md.ejs') %>
<%- include('combine.md.ejs') %>
<%- include('submit.md.ejs') %>
<%- include('generateXAddress.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('rippleTimeToISO8601.md.ejs') %>
<%- include('txFlags.md.ejs') %>
<%- include('schemaValidator.md.ejs') %>
<%- include('events.md.ejs') %>

View File

@@ -23,4 +23,5 @@ Methods that depend on the state of the XRP Ledger are unavailable in offline mo
* [prepareEscrowExecution](#prepareescrowexecution)
* [sign](#sign)
* [generateAddress](#generateaddress)
* [generateXAddress](#generatexaddress)
* [computeLedgerHash](#computeledgerhash)

View File

@@ -6,7 +6,7 @@ Prepare a transaction. The prepared transaction must subsequently be [signed](#s
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).
Notably, this is the preferred method for preparing `DepositPreauth` or `AccountDelete` transactions.
### Parameters

View File

@@ -39,6 +39,7 @@ Type | Description
`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.
`path_find` | Asynchronous follow-up response to the currently open path\_find request. See [rippled path\_find method](https://xrpl.org/path_find.html) for details.
To register your listener function, use `connection.on(type, handler)`.

View File

@@ -1,13 +1,16 @@
{
"name": "ripple-lib",
"version": "1.5.0",
"version": "1.6.2",
"license": "ISC",
"description": "A TypeScript/JavaScript API for interacting with the XRP Ledger in Node.js and the browser",
"files": [
"dist/npm/*",
"build/ripple-latest-min.js"
"build/ripple-latest-min.js",
"build/ripple-latest.js"
],
"main": "dist/npm/",
"unpkg": "build/ripple-latest-min.js",
"jsdelivr": "build/ripple-latest-min.js",
"types": "dist/npm/index.d.ts",
"browser": {
"ws": "./dist/npm/common/wswrapper.js",
@@ -18,32 +21,33 @@
},
"dependencies": {
"@types/lodash": "^4.14.136",
"@types/ws": "^6.0.3",
"@types/ws": "^7.2.0",
"bignumber.js": "^9.0.0",
"https-proxy-agent": "^3.0.0",
"https-proxy-agent": "^4.0.0",
"jsonschema": "1.2.2",
"lodash": "^4.17.4",
"lodash.isequal": "^4.5.0",
"ripple-address-codec": "^4.0.0",
"ripple-binary-codec": "^0.2.5",
"ripple-keypairs": "^0.11.0",
"ripple-lib-transactionparser": "0.8.1",
"ripple-lib-transactionparser": "0.8.2",
"ws": "^7.2.0"
},
"devDependencies": {
"@types/mocha": "^5.2.7",
"@types/node": "^12.12.5",
"@types/node": "^13.1.1",
"@typescript-eslint/eslint-plugin": "^2.3.3",
"@typescript-eslint/parser": "^2.3.3",
"assert-diff": "^2.0.3",
"doctoc": "^0.15.0",
"ejs": "^2.3.4",
"doctoc": "^1.4.0",
"ejs": "^3.0.1",
"eslint": "^6.5.1",
"eventemitter2": "^5.0.1",
"eventemitter2": "^6.0.0",
"json-schema-to-markdown-table": "^0.4.0",
"mocha": "6.2.0",
"mocha": "7.0.0",
"mocha-junit-reporter": "^1.9.1",
"nyc": "^14.1.1",
"nyc": "^15.0.0",
"prettier": "^1.19.1",
"ts-node": "^8.4.1",
"typescript": "^3.6.4",
"webpack": "^4.41.2",
@@ -63,7 +67,8 @@
"prepublish": "yarn clean && yarn build",
"test": "TS_NODE_PROJECT=src/tsconfig.json nyc mocha --exit",
"test:watch": "TS_NODE_PROJECT=src/tsconfig.json mocha --watch --reporter dot",
"lint": "eslint src/**/*.ts 'test/*-test.{ts,js}'",
"format": "prettier --write '{src,test}/**/*.ts'",
"lint": "eslint 'src/**/*.ts' 'test/*-test.{ts,js}'",
"perf": "./scripts/perf_test.sh",
"start": "node scripts/http.js"
},

View File

@@ -24,8 +24,7 @@ import getBalances from './ledger/balances'
import getBalanceSheet from './ledger/balance-sheet'
import getPaths from './ledger/pathfind'
import getOrders from './ledger/orders'
import {getOrderbook,
formatBidsAndAsks} from './ledger/orderbook'
import {getOrderbook, formatBidsAndAsks} from './ledger/orderbook'
import {getSettings, parseAccountFlags} from './ledger/settings'
import getAccountInfo from './ledger/accountinfo'
import getAccountObjects from './ledger/accountobjects'
@@ -47,7 +46,11 @@ import prepareSettings from './transaction/settings'
import sign from './transaction/sign'
import combine from './transaction/combine'
import submit from './transaction/submit'
import {generateAddressAPI, GenerateAddressOptions, GeneratedAddress} from './offline/generate-address'
import {
generateAddressAPI,
GenerateAddressOptions,
GeneratedAddress
} from './offline/generate-address'
import {deriveKeypair, deriveAddress, deriveXAddress} from './offline/derive'
import computeLedgerHash from './offline/ledgerhash'
import signPaymentChannelClaim from './offline/sign-payment-channel-claim'
@@ -55,19 +58,28 @@ import verifyPaymentChannelClaim from './offline/verify-payment-channel-claim'
import getLedger from './ledger/ledger'
import {
AccountObjectsRequest, AccountObjectsResponse,
AccountOffersRequest, AccountOffersResponse,
AccountInfoRequest, AccountInfoResponse,
AccountLinesRequest, AccountLinesResponse,
BookOffersRequest, BookOffersResponse,
GatewayBalancesRequest, GatewayBalancesResponse,
LedgerRequest, LedgerResponse,
LedgerDataRequest, LedgerDataResponse,
LedgerEntryRequest, LedgerEntryResponse,
ServerInfoRequest, ServerInfoResponse,
AccountObjectsRequest,
AccountObjectsResponse,
AccountOffersRequest,
AccountOffersResponse,
AccountInfoRequest,
AccountInfoResponse,
AccountLinesRequest,
AccountLinesResponse,
BookOffersRequest,
BookOffersResponse,
GatewayBalancesRequest,
GatewayBalancesResponse,
LedgerRequest,
LedgerResponse,
LedgerDataRequest,
LedgerDataResponse,
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'
@@ -75,15 +87,14 @@ import * as schemaValidator from './common/schema-validator'
import {getServerInfo, getFee} from './common/serverinfo'
import {clamp, renameCounterpartyToIssuer} from './ledger/utils'
import {TransactionJSON, Instructions, Prepare} from './transaction/types'
import {ConnectionOptions} from './common/connection'
import {ConnectionUserOptions} from './common/connection'
import {isValidXAddress, isValidClassicAddress} from 'ripple-address-codec'
export interface APIOptions extends ConnectionOptions {
server?: string,
feeCushion?: number,
maxFeeXRP?: string,
trace?: boolean,
proxy?: string,
export interface APIOptions extends ConnectionUserOptions {
server?: string
feeCushion?: number
maxFeeXRP?: string
proxy?: string
timeout?: number
}
@@ -92,7 +103,7 @@ export interface APIOptions extends ConnectionOptions {
* command. This varies from command to command, but we need to know it to
* properly count across many requests.
*/
function getCollectKeyFromCommand(command: string): string|undefined {
function getCollectKeyFromCommand(command: string): string | undefined {
switch (command) {
case 'account_offers':
case 'book_offers':
@@ -141,12 +152,12 @@ class RippleAPI extends EventEmitter {
this.emit('connected')
})
this.connection.on('disconnected', code => {
let finalCode = code;
// This is a backwards-compatible fix for this change in the ws library:
// https://github.com/websockets/ws/issues/1257
let finalCode = code
// 1005: This is a backwards-compatible fix for this change in the ws library: https://github.com/websockets/ws/issues/1257
// 4000: Connection uses a 4000 code internally to indicate a manual disconnect/close
// TODO: Remove in next major, breaking version
if (finalCode === 1005) {
finalCode = 1000;
if (finalCode === 1005 || finalCode === 4000) {
finalCode = 1000
}
this.emit('disconnected', finalCode)
})
@@ -157,33 +168,51 @@ class RippleAPI extends EventEmitter {
}
}
/**
* Makes a request to the API with the given command and
* additional request body parameters.
*/
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_data', params?: LedgerDataRequest):
Promise<LedgerDataResponse>
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: '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_data',
params?: LedgerDataRequest
): Promise<LedgerDataResponse>
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,
@@ -225,8 +254,10 @@ class RippleAPI extends EventEmitter {
*
* You can later submit the transaction with `submit()`.
*/
async prepareTransaction(txJSON: TransactionJSON, instructions: Instructions = {}):
Promise<Prepare> {
async prepareTransaction(
txJSON: TransactionJSON,
instructions: Instructions = {}
): Promise<Prepare> {
return transactionUtils.prepareTransaction(txJSON, this, instructions)
}
@@ -254,16 +285,23 @@ class RippleAPI extends EventEmitter {
* general use. Instead, use rippled's built-in pagination and make multiple
* requests as needed.
*/
async _requestAll(command: 'account_offers', params: AccountOffersRequest):
Promise<AccountOffersResponse[]>
async _requestAll(command: 'book_offers', params: BookOffersRequest):
Promise<BookOffersResponse[]>
async _requestAll(command: 'account_lines', params: AccountLinesRequest):
Promise<AccountLinesResponse[]>
async _requestAll(
command: 'account_offers',
params: AccountOffersRequest
): Promise<AccountOffersResponse[]>
async _requestAll(
command: 'book_offers',
params: BookOffersRequest
): Promise<BookOffersResponse[]>
async _requestAll(
command: 'account_lines',
params: AccountLinesRequest
): Promise<AccountLinesResponse[]>
async _requestAll(
command: string,
params: any = {},
options: {collect?: string} = {}): Promise<any[]> {
options: {collect?: string} = {}
): Promise<any[]> {
// The data under collection is keyed based on the command. Fail if command
// not recognized and collection key not provided.
const collectKey = options.collect || getCollectKeyFromCommand(command)
@@ -272,8 +310,7 @@ class RippleAPI extends EventEmitter {
}
// If limit is not provided, fetches all data over multiple requests.
// NOTE: This may return much more than needed. Set limit when possible.
const countTo: number =
(params.limit !== undefined) ? params.limit : Infinity
const countTo: number = params.limit !== undefined ? params.limit : Infinity
let count: number = 0
let marker: string = params.marker
let lastBatchLength: number
@@ -297,7 +334,7 @@ class RippleAPI extends EventEmitter {
} else {
lastBatchLength = 0
}
} while(!!marker && count < countTo && lastBatchLength !== 0)
} while (!!marker && count < countTo && lastBatchLength !== 0)
return results
}
@@ -375,6 +412,4 @@ class RippleAPI extends EventEmitter {
isValidSecret = schemaValidator.isValidSecret
}
export {
RippleAPI
}
export {RippleAPI}

View File

@@ -1,24 +1,23 @@
import * as _ from 'lodash'
import {RippleAPI, APIOptions} from './api'
class RippleAPIBroadcast extends RippleAPI {
ledgerVersion: number | undefined = undefined
private _apis: RippleAPI[]
constructor(servers, options: APIOptions = {}) {
super(options)
const apis: RippleAPI[] = servers.map(server => new RippleAPI(
_.assign({}, options, {server})
))
const apis: RippleAPI[] = servers.map(
server => new RippleAPI(_.assign({}, options, {server}))
)
// exposed for testing
this._apis = apis
this.getMethodNames().forEach(name => {
this[name] = function() { // eslint-disable-line no-loop-func
this[name] = function() {
// eslint-disable-line no-loop-func
return Promise.race(apis.map(api => api[name](...arguments)))
}
})
@@ -44,13 +43,16 @@ class RippleAPIBroadcast extends RippleAPI {
apis.forEach(api => {
api.on('ledger', this.onLedgerEvent.bind(this))
api.on('error', (errorCode, errorMessage, data) =>
this.emit('error', errorCode, errorMessage, data))
this.emit('error', errorCode, errorMessage, data)
)
})
}
onLedgerEvent(ledger) {
if (ledger.ledgerVersion > this.ledgerVersion ||
this.ledgerVersion === undefined) {
if (
ledger.ledgerVersion > this.ledgerVersion ||
this.ledgerVersion === undefined
) {
this.ledgerVersion = ledger.ledgerVersion
this.emit('ledger', ledger)
}
@@ -68,6 +70,4 @@ class RippleAPIBroadcast extends RippleAPI {
}
}
export {
RippleAPIBroadcast
}
export {RippleAPIBroadcast}

44
src/common/backoff.ts Normal file
View File

@@ -0,0 +1,44 @@
/*
* Original code based on "backo" - https://github.com/segmentio/backo
* MIT License - Copyright 2014 Segment.io
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* A Back off strategy that increases exponentionally. Useful with repeated
* setTimeout calls over a network (where the destination may be down).
*/
export class ExponentialBackoff {
private readonly ms: number
private readonly max: number
private readonly factor: number = 2
private readonly jitter: number = 0
attempts: number = 0
constructor(opts: {min?: number; max?: number} = {}) {
this.ms = opts.min || 100
this.max = opts.max || 10000
}
/**
* Return the backoff duration.
*/
duration() {
var ms = this.ms * Math.pow(this.factor, this.attempts++)
if (this.jitter) {
var rand = Math.random()
var deviation = Math.floor(rand * this.jitter * ms)
ms = (Math.floor(rand * 10) & 1) == 0 ? ms - deviation : ms + deviation
}
return Math.min(ms, this.max) | 0
}
/**
* Reset the number of attempts.
*/
reset() {
this.attempts = 0
}
}

View File

@@ -1,9 +1,9 @@
function setPrototypeOf(object, prototype) {
// Object.setPrototypeOf not supported on Internet Explorer 9
Object.setPrototypeOf ? Object.setPrototypeOf(object, prototype) :
// @ts-ignore: Specifically a fallback for IE9
object.__proto__ = prototype
Object.setPrototypeOf
? Object.setPrototypeOf(object, prototype)
: // @ts-ignore: Specifically a fallback for IE9
(object.__proto__ = prototype)
}
function getConstructorName(object: object): string {
@@ -17,7 +17,4 @@ function getConstructorName(object: object): string {
return functionConstructor ? functionConstructor[1] : classConstructor[1]
}
export {
getConstructorName,
setPrototypeOf
}
export {getConstructorName, setPrototypeOf}

File diff suppressed because it is too large Load Diff

View File

@@ -1,9 +1,7 @@
import {txFlagIndices} from './txflags'
// Ordering from https://developers.ripple.com/accountroot.html
const accountRootFlags = {
// lsfDefaultRipple:
// Enable rippling on trust lines by default.
// Required for issuing addresses; discouraged for others.
@@ -73,8 +71,12 @@ const AccountFlagIndices = {
}
const AccountFields = {
EmailHash: {name: 'emailHash', encoding: 'hex',
length: 32, defaults: '00000000000000000000000000000000'},
EmailHash: {
name: 'emailHash',
encoding: 'hex',
length: 32,
defaults: '00000000000000000000000000000000'
},
WalletLocator: {name: 'walletLocator'},
MessageKey: {name: 'messageKey'},
Domain: {name: 'domain', encoding: 'hex'},
@@ -82,8 +84,4 @@ const AccountFields = {
TickSize: {name: 'tickSize', defaults: 0}
}
export {
AccountFields,
AccountFlagIndices,
AccountFlags
}
export {AccountFields, AccountFlagIndices, AccountFlags}

View File

@@ -1,9 +1,7 @@
import {inspect} from 'util'
import * as browserHacks from './browser-hacks'
class RippleError extends Error {
name: string
message: string
data?: any
@@ -70,8 +68,11 @@ class MissingLedgerHistoryError extends RippleError {
class PendingLedgerVersionError extends RippleError {
constructor(message?: string) {
super(message || 'maxLedgerVersion is greater than server\'s most recent' +
' validated ledger')
super(
message ||
"maxLedgerVersion is greater than server's most recent" +
' validated ledger'
)
}
}

View File

@@ -11,18 +11,18 @@
* some arbitrary string. For example "TXN".
*/
enum HashPrefix {
enum HashPrefix {
// transaction plus signature to give transaction ID
TRANSACTION_ID = 0x54584E00, // 'TXN'
TRANSACTION_ID = 0x54584e00, // 'TXN'
// transaction plus metadata
TRANSACTION_NODE = 0x534E4400, // 'TND'
TRANSACTION_NODE = 0x534e4400, // 'TND'
// inner node in tree
INNER_NODE = 0x4D494E00, // 'MIN'
INNER_NODE = 0x4d494e00, // 'MIN'
// leaf node in tree
LEAF_NODE = 0x4D4C4E00, // 'MLN'
LEAF_NODE = 0x4d4c4e00, // 'MLN'
// inner transaction to sign
TRANSACTION_SIGN = 0x53545800, // 'STX'
@@ -31,10 +31,10 @@
TRANSACTION_SIGN_TESTNET = 0x73747800, // 'stx'
// inner transaction to multisign
TRANSACTION_MULTISIGN = 0x534D5400, // 'SMT'
TRANSACTION_MULTISIGN = 0x534d5400, // 'SMT'
// ledger
LEDGER = 0x4C575200 // 'LWR'
LEDGER = 0x4c575200 // 'LWR'
}
export default HashPrefix

View File

@@ -18,8 +18,11 @@ const bytesToHex = (bytes: number[]): string => {
return Buffer.from(bytes).toString('hex')
}
const bigintToHex = (integerString: string | number | BigNumber, byteLength: number): string => {
const hex = (new BigNumber(integerString)).toString(16)
const bigintToHex = (
integerString: string | number | BigNumber,
byteLength: number
): string => {
const hex = new BigNumber(integerString).toString(16)
return padLeftZero(hex, byteLength * 2)
}
@@ -28,12 +31,15 @@ const ledgerSpaceHex = (name: string): string => {
}
const addressToHex = (address: string): string => {
return (Buffer.from(decodeAccountID(address))).toString('hex')
return Buffer.from(decodeAccountID(address)).toString('hex')
}
const currencyToHex = (currency: string): string => {
if (currency.length === 3) {
const bytes = new Array(20 + 1).join('0').split('').map(parseFloat)
const bytes = new Array(20 + 1)
.join('0')
.split('')
.map(parseFloat)
bytes[12] = currency.charCodeAt(0) & 0xff
bytes[13] = currency.charCodeAt(1) & 0xff
bytes[14] = currency.charCodeAt(2) & 0xff
@@ -51,7 +57,7 @@ const addLengthPrefix = (hex: string): string => {
return bytesToHex([193 + (x >>> 8), x & 0xff]) + hex
} else if (length <= 918744) {
const x = length - 12481
return bytesToHex([241 + (x >>> 16), x >>> 8 & 0xff, x & 0xff]) + hex
return bytesToHex([241 + (x >>> 16), (x >>> 8) & 0xff, x & 0xff]) + hex
}
throw new Error('Variable integer overflow.')
}
@@ -65,7 +71,9 @@ export const computeTransactionHash = (txJSON: any): string => {
return computeBinaryTransactionHash(encode(txJSON))
}
export const computeBinaryTransactionSigningHash = (txBlobHex: string): string => {
export const computeBinaryTransactionSigningHash = (
txBlobHex: string
): string => {
const prefix = HashPrefix.TRANSACTION_SIGN.toString(16).toUpperCase()
return sha512Half(prefix + txBlobHex)
}
@@ -79,9 +87,9 @@ export const computeAccountHash = (address: string): string => {
}
export const computeSignerListHash = (address: string): string => {
return sha512Half(ledgerSpaceHex('signerList') +
addressToHex(address) +
'00000000') // uint32(0) signer list index
return sha512Half(
ledgerSpaceHex('signerList') + addressToHex(address) + '00000000'
) // uint32(0) signer list index
}
export const computeOrderHash = (address: string, sequence: number): string => {
@@ -89,18 +97,24 @@ export const computeOrderHash = (address: string, sequence: number): string => {
return sha512Half(prefix + addressToHex(address) + intToHex(sequence, 4))
}
export const computeTrustlineHash = (address1: string, address2: string, currency: string): string => {
export const computeTrustlineHash = (
address1: string,
address2: string,
currency: string
): string => {
const address1Hex = addressToHex(address1)
const address2Hex = addressToHex(address2)
const swap = (new BigNumber(address1Hex, 16)).isGreaterThan(
new BigNumber(address2Hex, 16))
const swap = new BigNumber(address1Hex, 16).isGreaterThan(
new BigNumber(address2Hex, 16)
)
const lowAddressHex = swap ? address2Hex : address1Hex
const highAddressHex = swap ? address1Hex : address2Hex
const prefix = ledgerSpaceHex('rippleState')
return sha512Half(prefix + lowAddressHex + highAddressHex +
currencyToHex(currency))
return sha512Half(
prefix + lowAddressHex + highAddressHex + currencyToHex(currency)
)
}
export const computeTransactionTreeHash = (transactions: any[]): string => {
@@ -131,25 +145,35 @@ export const computeStateTreeHash = (entries: any[]): string => {
// see rippled Ledger::updateHash()
export const computeLedgerHash = (ledgerHeader): string => {
const prefix = HashPrefix.LEDGER.toString(16).toUpperCase()
return sha512Half(prefix +
intToHex(ledgerHeader.ledger_index, 4) +
bigintToHex(ledgerHeader.total_coins, 8) +
ledgerHeader.parent_hash +
ledgerHeader.transaction_hash +
ledgerHeader.account_hash +
intToHex(ledgerHeader.parent_close_time, 4) +
intToHex(ledgerHeader.close_time, 4) +
intToHex(ledgerHeader.close_time_resolution, 1) +
intToHex(ledgerHeader.close_flags, 1)
return sha512Half(
prefix +
intToHex(ledgerHeader.ledger_index, 4) +
bigintToHex(ledgerHeader.total_coins, 8) +
ledgerHeader.parent_hash +
ledgerHeader.transaction_hash +
ledgerHeader.account_hash +
intToHex(ledgerHeader.parent_close_time, 4) +
intToHex(ledgerHeader.close_time, 4) +
intToHex(ledgerHeader.close_time_resolution, 1) +
intToHex(ledgerHeader.close_flags, 1)
)
}
export const computeEscrowHash = (address, sequence): string => {
return sha512Half(ledgerSpaceHex('escrow') + addressToHex(address) +
intToHex(sequence, 4))
return sha512Half(
ledgerSpaceHex('escrow') + addressToHex(address) + intToHex(sequence, 4)
)
}
export const computePaymentChannelHash = (address, dstAddress, sequence): string => {
return sha512Half(ledgerSpaceHex('paychan') + addressToHex(address) +
addressToHex(dstAddress) + intToHex(sequence, 4))
export const computePaymentChannelHash = (
address,
dstAddress,
sequence
): string => {
return sha512Half(
ledgerSpaceHex('paychan') +
addressToHex(address) +
addressToHex(dstAddress) +
intToHex(sequence, 4)
)
}

View File

@@ -1,4 +1,3 @@
/**
* Ripple ledger namespace prefixes.
*
@@ -8,18 +7,18 @@
* Each namespace is just a single character prefix.
*/
export default {
account : 'a',
dirNode : 'd',
generatorMap : 'g',
rippleState : 'r',
offer : 'o', // Entry for an offer.
ownerDir : 'O', // Directory of things owned by an account.
bookDir : 'B', // Directory of order books.
contract : 'c',
skipList : 's',
amendment : 'f',
feeSettings : 'e',
signerList : 'S',
escrow : 'u',
paychan : 'x'
account: 'a',
dirNode: 'd',
generatorMap: 'g',
rippleState: 'r',
offer: 'o', // Entry for an offer.
ownerDir: 'O', // Directory of things owned by an account.
bookDir: 'B', // Directory of order books.
contract: 'c',
skipList: 's',
amendment: 'f',
feeSettings: 'e',
signerList: 'S',
escrow: 'u',
paychan: 'x'
}

View File

@@ -1,7 +1,11 @@
import {createHash} from 'crypto'
const sha512Half = (hex: string): string => {
return createHash('sha512').update(Buffer.from(hex, 'hex')).digest('hex').toUpperCase().slice(0, 64)
return createHash('sha512')
.update(Buffer.from(hex, 'hex'))
.digest('hex')
.toUpperCase()
.slice(0, 64)
}
export default sha512Half

View File

@@ -1,6 +1,7 @@
import hashPrefix from './hash-prefix'
import sha512Half from './sha512Half'
const HEX_ZERO = '0000000000000000000000000000000000000000000000000000000000000000'
const HEX_ZERO =
'0000000000000000000000000000000000000000000000000000000000000000'
export enum NodeType {
INNER = 1,
@@ -18,15 +19,17 @@ export abstract class Node {
public constructor() {}
public addItem(_tag: string, _node: Node): void {
throw new Error('Called unimplemented virtual method SHAMapTreeNode#addItem.')
throw new Error(
'Called unimplemented virtual method SHAMapTreeNode#addItem.'
)
}
public get hash(): string|void {
throw new Error('Called unimplemented virtual method SHAMapTreeNode#hash.');
public get hash(): string | void {
throw new Error('Called unimplemented virtual method SHAMapTreeNode#hash.')
}
}
export class InnerNode extends Node {
public leaves: { [slot: number]: Node }
public leaves: {[slot: number]: Node}
public type: NodeType
public depth: number
public empty: boolean
@@ -48,9 +51,10 @@ export class InnerNode extends Node {
* @param {string} tag equates to a ledger entry `index`
* @param {Node} node to add
* @return {void}
*/
*/
public addItem(tag: string, node: Node): void {
const existingNode = this.getNode(parseInt(tag[this.depth],16))
const existingNode = this.getNode(parseInt(tag[this.depth], 16))
if (existingNode) {
// A node already exists in this slot
if (existingNode instanceof InnerNode) {
@@ -60,15 +64,16 @@ export class InnerNode extends Node {
if (existingNode.tag === tag) {
// Collision
throw new Error(
'Tried to add a node to a SHAMap that was already in there.')
'Tried to add a node to a SHAMap that was already in there.'
)
} else {
// Turn it into an inner node
const newInnerNode = new InnerNode(this.depth + 1)
// Parent new and existing node
newInnerNode.addItem(existingNode.tag, existingNode)
newInnerNode.addItem(tag, node)
// And place the newly created inner node in the slot
this.setNode(parseInt(tag[this.depth], 16), newInnerNode)
}
@@ -87,7 +92,7 @@ export class InnerNode extends Node {
*/
public setNode(slot: number, node: Node): void {
if (slot < 0 || slot > 15) {
throw new Error ('Invalid slot: slot must be between 0-15.')
throw new Error('Invalid slot: slot must be between 0-15.')
}
this.leaves[slot] = node
this.empty = false
@@ -100,8 +105,8 @@ export class InnerNode extends Node {
*/
public getNode(slot: number): Node {
if (slot < 0 || slot > 15) {
throw new Error ('Invalid slot: slot must be between 0-15.')
}
throw new Error('Invalid slot: slot must be between 0-15.')
}
return this.leaves[slot]
}
@@ -113,7 +118,7 @@ export class InnerNode extends Node {
}
const prefix = hashPrefix.INNER_NODE.toString(16)
return sha512Half(prefix + hex)
}
}
}
export class Leaf extends Node {
@@ -135,21 +140,24 @@ export class Leaf extends Node {
this.data = data
}
public get hash(): string|void {
public get hash(): string | void {
switch (this.type) {
case NodeType.ACCOUNT_STATE:
case NodeType.ACCOUNT_STATE: {
const leafPrefix = hashPrefix.LEAF_NODE.toString(16)
return sha512Half(leafPrefix + this.data + this.tag)
case NodeType.TRANSACTION_NO_METADATA:
}
case NodeType.TRANSACTION_NO_METADATA: {
const txIDPrefix = hashPrefix.TRANSACTION_ID.toString(16)
return sha512Half(txIDPrefix + this.data)
case NodeType.TRANSACTION_METADATA:
}
case NodeType.TRANSACTION_METADATA: {
const txNodePrefix = hashPrefix.TRANSACTION_NODE.toString(16)
return sha512Half(txNodePrefix + this.data + this.tag)
}
default:
throw new Error('Tried to hash a SHAMap node of unknown type.')
}
}
}
}
export class SHAMap {

View File

@@ -6,16 +6,15 @@ import {xAddressToClassicAddress, isValidXAddress} from 'ripple-address-codec'
export function ensureClassicAddress(account: string): string {
if (isValidXAddress(account)) {
const {
classicAddress,
tag
} = xAddressToClassicAddress(account)
const {classicAddress, tag} = xAddressToClassicAddress(account)
// Except for special cases, X-addresses used for requests
// must not have an embedded tag. In other words,
// `tag` should be `false`.
if (tag !== false) {
throw new Error('This command does not support the use of a tag. Use an address without a tag.')
throw new Error(
'This command does not support the use of a tag. Use an address without a tag.'
)
}
// For rippled requests that use an account, always use a classic address.
@@ -25,12 +24,7 @@ export function ensureClassicAddress(account: string): string {
}
}
export {
constants,
errors,
validate,
serverInfo
}
export {constants, errors, validate, serverInfo}
export {
dropsToXrp,
xrpToDrops,
@@ -40,5 +34,5 @@ export {
iso8601ToRippleTime,
rippleTimeToISO8601
} from './utils'
export {default as Connection} from './connection'
export {Connection} from './connection'
export {txFlags} from './txflags'

View File

@@ -18,7 +18,6 @@ function mergeIntervals(intervals: Interval[]): Interval[] {
}
class RangeSet {
ranges: Array<[number, number]>
constructor() {
@@ -30,8 +29,9 @@ class RangeSet {
}
serialize() {
return this.ranges.map(range =>
range[0].toString() + '-' + range[1].toString()).join(',')
return this.ranges
.map(range => range[0].toString() + '-' + range[1].toString())
.join(',')
}
addRange(start: number, end: number) {

View File

@@ -62,6 +62,8 @@ function loadSchemas() {
require('./schemas/specifications/check-cash.json'),
require('./schemas/specifications/check-cancel.json'),
require('./schemas/specifications/trustline.json'),
require('./schemas/specifications/deposit-preauth.json'),
require('./schemas/specifications/account-delete.json'),
require('./schemas/output/sign.json'),
require('./schemas/output/submit.json'),
require('./schemas/output/get-account-info.json'),
@@ -175,8 +177,4 @@ function isValidAddress(address: string): boolean {
return isValidXAddress(address) || isValidClassicAddress(address)
}
export {
schemaValidate,
isValidSecret,
isValidAddress
}
export {schemaValidate, isValidSecret, isValidAddress}

View File

@@ -14,7 +14,7 @@
"minimum": 0,
"maximum": 255
},
"description": "The entropy to use to generate the seed."
"description": "The entropy to use to generate the seed. Must be an array of length 16 with values from 0-255 (16 bytes of entropy)"
},
"algorithm": {
"type": "string",

View File

@@ -14,7 +14,7 @@
"minimum": 0,
"maximum": 255
},
"description": "The entropy to use to generate the seed."
"description": "The entropy to use to generate the seed. Must be an array of length 16 with values from 0-255 (16 bytes of entropy)"
},
"algorithm": {
"type": "string",
@@ -24,6 +24,10 @@
"test": {
"type": "boolean",
"description": "Specifies whether the address is intended for use on a test network such as Testnet or Devnet. If `true`, the address should only be used for testing, and will start with `T`. If `false`, the address should only be used on mainnet, and will start with `X`."
},
"includeClassicAddress": {
"type": "boolean",
"description": "Specifies whether the classic address should also be included in the returned payload."
}
},
"additionalProperties": false

View File

@@ -18,6 +18,8 @@
"paymentChannelClaim",
"checkCreate",
"checkCancel",
"checkCash"
"checkCash",
"depositPreauth",
"accountDelete"
]
}

View File

@@ -208,6 +208,30 @@
"$ref": "paymentChannelClaim"
}
}
},
{
"properties": {
"type": {
"enum": [
"depositPreauth"
]
},
"specification": {
"$ref": "depositPreauth"
}
}
},
{
"properties": {
"type": {
"enum": [
"accountDelete"
]
},
"specification": {
"$ref": "accountDelete"
}
}
}
]
}

View File

@@ -0,0 +1,29 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "accountDelete",
"link": "account-delete",
"type": "object",
"properties": {
"destination": {
"$ref": "address",
"description": "Address of an account to receive any leftover XRP after deleting the sending account. Must be a funded account in the ledger, and must not be the sending account."
},
"destinationTag": {
"$ref": "tag",
"description": "(Optional) Arbitrary destination tag that identifies a hosted recipient or other information for the recipient of the deleted account's leftover XRP."
},
"destinationXAddress": {
"$ref": "address",
"description": "X-address of an account to receive any leftover XRP after deleting the sending account. Must be a funded account in the ledger, and must not be the sending account."
}
},
"anyOf": [
{
"required": ["destination"]
},
{
"required": ["destinationXAddress"]
}
],
"additionalProperties": false
}

View File

@@ -0,0 +1,21 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "depositPreauth",
"link": "deposit-preauth",
"type": "object",
"properties": {
"authorize": {
"$ref": "address",
"description": "Address of the account that can cash the check."
},
"unauthorize": {
"$ref": "address",
"description": "Address of the account that can cash the check."
}
},
"oneOf": [
{"required": ["authorize"]},
{"required": ["unauthorize"]}
],
"additionalProperties": false
}

View File

@@ -4,32 +4,32 @@ import BigNumber from 'bignumber.js'
import {RippleAPI} from '..'
export type GetServerInfoResponse = {
buildVersion: string,
completeLedgers: string,
hostID: string,
ioLatencyMs: number,
buildVersion: string
completeLedgers: string
hostID: string
ioLatencyMs: number
load?: {
jobTypes: Array<object>,
jobTypes: Array<object>
threads: number
},
}
lastClose: {
convergeTimeS: number,
convergeTimeS: number
proposers: number
},
loadFactor: number,
peers: number,
pubkeyNode: string,
pubkeyValidator?: string,
serverState: string,
}
loadFactor: number
peers: number
pubkeyNode: string
pubkeyValidator?: string
serverState: string
validatedLedger: {
age: number,
baseFeeXRP: string,
hash: string,
reserveBaseXRP: string,
reserveIncrementXRP: string,
age: number
baseFeeXRP: string
hash: string
reserveBaseXRP: string
reserveIncrementXRP: string
ledgerVersion: number
},
validationQuorum: number,
}
validationQuorum: number
networkLedger?: string
}
@@ -51,12 +51,9 @@ function getServerInfo(this: RippleAPI): Promise<GetServerInfoResponse> {
reserveIncXrp: 'reserveIncrementXRP',
seq: 'ledgerVersion'
})
info.validatedLedger.baseFeeXRP =
info.validatedLedger.baseFeeXRP.toString()
info.validatedLedger.reserveBaseXRP =
info.validatedLedger.reserveBaseXRP.toString()
info.validatedLedger.reserveIncrementXRP =
info.validatedLedger.reserveIncrementXRP.toString()
info.validatedLedger.baseFeeXRP = info.validatedLedger.baseFeeXRP.toString()
info.validatedLedger.reserveBaseXRP = info.validatedLedger.reserveBaseXRP.toString()
info.validatedLedger.reserveIncrementXRP = info.validatedLedger.reserveIncrementXRP.toString()
}
return info
})
@@ -64,10 +61,7 @@ function getServerInfo(this: RippleAPI): Promise<GetServerInfoResponse> {
// 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> {
async function getFee(this: RippleAPI, cushion?: number): Promise<string> {
if (cushion === undefined) {
cushion = this._feeCushion
}
@@ -82,10 +76,7 @@ async function getFee(
// 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)
return new BigNumber(fee.toFixed(6)).toString(10)
}
export {
getServerInfo,
getFee
}
export {getServerInfo, getFee}

View File

@@ -58,7 +58,4 @@ const txFlagIndices = {
}
}
export {
txFlags,
txFlagIndices
}
export {txFlags, txFlagIndices}

View File

@@ -5,19 +5,19 @@ import {
} from '../objects'
export interface AccountInfoRequest {
account: string,
strict?: boolean,
queue?: boolean,
ledger_hash?: string,
ledger_index?: number | ('validated' | 'closed' | 'current'),
account: string
strict?: boolean
queue?: boolean
ledger_hash?: string
ledger_index?: number | ('validated' | 'closed' | 'current')
signer_lists?: boolean
}
export interface AccountInfoResponse {
account_data: AccountRootLedgerEntry,
signer_lists?: SignerListLedgerEntry[],
ledger_current_index?: number,
ledger_index?: number,
queue_data?: QueueData,
account_data: AccountRootLedgerEntry
signer_lists?: SignerListLedgerEntry[]
ledger_current_index?: number
ledger_index?: number
queue_data?: QueueData
validated?: boolean
}

View File

@@ -1,19 +1,19 @@
import {Trustline} from '../objects'
export interface AccountLinesRequest {
account: string,
ledger_hash?: string,
ledger_index?: number | ('validated' | 'closed' | 'current'),
peer?: string,
limit?: number,
marker?: any,
account: string
ledger_hash?: string
ledger_index?: number | ('validated' | 'closed' | 'current')
peer?: string
limit?: number
marker?: any
}
export interface AccountLinesResponse {
account: string,
lines: Trustline[],
ledger_current_index?: number,
ledger_index?: number,
ledger_hash?: string,
marker?: any,
account: string
lines: Trustline[]
ledger_current_index?: number
ledger_index?: number
ledger_hash?: string
marker?: any
}

View File

@@ -1,84 +1,91 @@
import {
CheckLedgerEntry, RippleStateLedgerEntry,
OfferLedgerEntry, SignerListLedgerEntry,
EscrowLedgerEntry, PayChannelLedgerEntry,
CheckLedgerEntry,
RippleStateLedgerEntry,
OfferLedgerEntry,
SignerListLedgerEntry,
EscrowLedgerEntry,
PayChannelLedgerEntry,
DepositPreauthLedgerEntry
} from '../objects'
export interface GetAccountObjectsOptions {
type?: string | (
'check' |
'escrow' |
'offer' |
'payment_channel' |
'signer_list' |
'state'
),
ledgerHash?: string,
ledgerIndex?: number | ('validated' | 'closed' | 'current'),
limit?: number,
type?:
| string
| (
| 'check'
| 'escrow'
| 'offer'
| 'payment_channel'
| 'signer_list'
| 'state'
)
ledgerHash?: string
ledgerIndex?: number | ('validated' | 'closed' | 'current')
limit?: number
marker?: string
}
export interface AccountObjectsRequest {
account: string,
account: string
// (Optional) Filter results to include only this type of ledger object.
type?: string | (
'check' |
'escrow' |
'offer' |
'payment_channel' |
'signer_list' |
'state'
),
type?:
| string
| (
| 'check'
| 'escrow'
| 'offer'
| 'payment_channel'
| 'signer_list'
| 'state'
)
// (Optional) A 20-byte hex string for the ledger version to use.
ledger_hash?: string,
ledger_hash?: string
// (Optional) The sequence number of the ledger to use,
// or a shortcut string to choose a ledger automatically.
ledger_index?: number | ('validated' | 'closed' | 'current'),
ledger_index?: number | ('validated' | 'closed' | 'current')
limit?: number,
limit?: number
marker?: string
}
export interface AccountObjectsResponse {
account: string,
account: string
// Array of objects owned by this account.
// from the getAccountObjects section of the dev center
account_objects: Array<
CheckLedgerEntry |
RippleStateLedgerEntry |
OfferLedgerEntry |
SignerListLedgerEntry |
EscrowLedgerEntry |
PayChannelLedgerEntry |
DepositPreauthLedgerEntry
>,
| CheckLedgerEntry
| RippleStateLedgerEntry
| OfferLedgerEntry
| SignerListLedgerEntry
| EscrowLedgerEntry
| PayChannelLedgerEntry
| DepositPreauthLedgerEntry
>
// (May be omitted) The identifying hash of the ledger
// that was used to generate this response.
ledger_hash?: string,
ledger_hash?: string
// (May be omitted) The sequence number of the ledger version
// that was used to generate this response.
ledger_index?: number,
ledger_index?: number
// (May be omitted) The sequence number of the current in-progress ledger
// version that was used to generate this response.
ledger_current_index?: number,
ledger_current_index?: number
// The limit that was used in this request, if any.
limit?: number,
limit?: number
// Server-defined value indicating the response is paginated. Pass this
// to the next call to resume where this call left off. Omitted when there
// are no additional pages after this one.
marker?: string,
marker?: string
// If true, this information comes from a ledger version
// that has been validated by consensus.

View File

@@ -1,27 +1,27 @@
import {RippledAmount} from '../objects'
export interface AccountOffersRequest {
account: string,
ledger_hash?: string,
ledger_index?: number | ('validated' | 'closed' | 'current'),
limit?: number,
marker?: any,
account: string
ledger_hash?: string
ledger_index?: number | ('validated' | 'closed' | 'current')
limit?: number
marker?: any
}
export interface AccountOffersResponse {
account: string,
ledger_hash?: string,
ledger_current_index?: number,
ledger_index?: number,
marker?: any,
offers?: AccountOffer[],
account: string
ledger_hash?: string
ledger_current_index?: number
ledger_index?: number
marker?: any
offers?: AccountOffer[]
}
export interface AccountOffer {
seq: number,
flags: number,
taker_gets: RippledAmount,
taker_pays: RippledAmount,
quality: string,
seq: number
flags: number
taker_gets: RippledAmount
taker_pays: RippledAmount
quality: string
expiration?: number
}

View File

@@ -1,30 +1,26 @@
import {
TakerRequestAmount,
RippledAmount,
OfferLedgerEntry
} from '../objects'
import {TakerRequestAmount, RippledAmount, OfferLedgerEntry} from '../objects'
export interface BookOffersRequest {
taker?: string,
taker_gets: TakerRequestAmount,
taker_pays: TakerRequestAmount,
ledger_hash?: string,
ledger_index?: number | ('validated' | 'closed' | 'current'),
limit?: number,
taker?: string
taker_gets: TakerRequestAmount
taker_pays: TakerRequestAmount
ledger_hash?: string
ledger_index?: number | ('validated' | 'closed' | 'current')
limit?: number
marker?: any
}
export interface BookOffersResponse {
offers: BookOffer[],
ledger_hash?: string,
ledger_current_index?: number,
ledger_index?: number,
offers: BookOffer[]
ledger_hash?: string
ledger_current_index?: number
ledger_index?: number
marker?: any
}
export interface BookOffer extends OfferLedgerEntry {
quality?: string
owner_funds?: string,
taker_gets_funded?: RippledAmount,
owner_funds?: string
taker_gets_funded?: RippledAmount
taker_pays_funded?: RippledAmount
}

View File

@@ -1,19 +1,19 @@
import {Amount} from '../objects'
export interface GatewayBalancesRequest {
account: string,
strict?: boolean,
hotwallet: string|Array<string>,
ledger_hash?: string,
account: string
strict?: boolean
hotwallet: string | Array<string>
ledger_hash?: string
ledger_index?: number | ('validated' | 'closed' | 'current')
}
export interface GatewayBalancesResponse {
account: string,
obligations?: {[currency: string]: string},
balances?: {[address: string]: Amount[]},
assets?: {[address: string]: Amount[]},
ledger_hash?: string,
ledger_current_index?: number,
account: string
obligations?: {[currency: string]: string}
balances?: {[address: string]: Amount[]}
assets?: {[address: string]: Amount[]}
ledger_hash?: string
ledger_current_index?: number
ledger_index?: number
}

View File

@@ -1,4 +1,4 @@
import { LedgerData } from '../objects'
import {LedgerData} from '../objects'
export interface LedgerDataRequest {
id?: any
@@ -9,4 +9,4 @@ export interface LedgerDataRequest {
marker?: string
}
export type LedgerDataResponse = LedgerData;
export type LedgerDataResponse = LedgerData

View File

@@ -3,29 +3,34 @@ import {LedgerEntry} from '../objects'
export interface LedgerEntryRequest {
ledger_hash?: string
ledger_index?: number | ('validated' | 'closed' | 'current')
index?: string,
account_root?: string,
directory?: string | {
sub_index?: number,
dir_root: string
} | {
sub_index?: number,
owner: string
},
offer?: string | {
account: string,
seq: number
},
index?: string
account_root?: string
directory?:
| string
| {
sub_index?: number
dir_root: string
}
| {
sub_index?: number
owner: string
}
offer?:
| string
| {
account: string
seq: number
}
ripple_state?: {
accounts: [string, string],
accounts: [string, string]
currency: string
},
}
binary?: boolean
}
export interface LedgerEntryResponse {
index: string,
ledger_index: number,
node_binary?: string,
node?: LedgerEntry,
index: string
ledger_index: number
node_binary?: string
node?: LedgerEntry
}

View File

@@ -4,48 +4,48 @@ export interface ServerInfoRequest {
export interface ServerInfoResponse {
info: {
amendment_blocked?: boolean,
build_version: string,
closed_ledger?: LedgerInfo,
complete_ledgers: string,
hostid: string,
io_latency_ms: number,
amendment_blocked?: boolean
build_version: string
closed_ledger?: LedgerInfo
complete_ledgers: string
hostid: string
io_latency_ms: number
last_close: {
converge_time_s: number,
converge_time_s: number
proposers: number
},
}
load?: {
job_types: {
job_type: string,
per_second: number,
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,
}
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,
age: number
base_fee_xrp: number
hash: string
reserve_base_xrp: number
reserve_inc_xrp: number
seq: number
}

View File

@@ -1,19 +1,19 @@
import {Amount} from './amounts'
export type Adjustment = {
address: string,
amount: Amount,
address: string
amount: Amount
tag?: number
}
export type MaxAdjustment = {
address: string,
maxAmount: Amount,
address: string
maxAmount: Amount
tag?: number
}
export type MinAdjustment = {
address: string,
minAmount: Amount,
address: string
minAmount: Amount
tag?: number
}

View File

@@ -2,7 +2,6 @@ export interface Amount extends Issue {
value: string
}
export type RippledAmount = string | Amount
/**

View File

@@ -1,23 +1,23 @@
export interface Ledger {
account_hash: string,
close_time: number,
close_time_human: string,
close_time_resolution: number,
closed: boolean,
ledger_hash: string,
ledger_index: string,
parent_hash: string,
total_coins: string,
transaction_hash: string,
transactions: string[] | object[],
account_hash: string
close_time: number
close_time_human: string
close_time_resolution: number
closed: boolean
ledger_hash: string
ledger_index: string
parent_hash: string
total_coins: string
transaction_hash: string
transactions: string[] | object[]
// @deprecated
seqNum?: string,
seqNum?: string
// @deprecated
totalCoins?: string,
totalCoins?: string
// @deprecated
hash?: string,
close_flags?: number,
parent_close_time?: number,
accountState?: any[],
hash?: string
close_flags?: number
parent_close_time?: number
accountState?: any[]
validated?: boolean
}

View File

@@ -2,5 +2,5 @@ export interface LedgerData {
ledger_index: string
ledger_hash: string
marker: string
state: ({ data?: string; LedgerEntryType?: string; index: string } & any)[]
}
state: ({data?: string; LedgerEntryType?: string; index: string} & any)[]
}

View File

@@ -2,188 +2,189 @@ import {SignerEntry} from './index'
import {Amount, RippledAmount} from './amounts'
export interface AccountRootLedgerEntry {
LedgerEntryType: 'AccountRoot',
Account: string,
Balance: string,
Flags: number,
OwnerCount: number,
PreviousTxnID: string,
PreviousTxnLgrSeq: number,
Sequence: number,
AccountTxnID?: string,
Domain?: string,
EmailHash?: string,
LedgerEntryType: 'AccountRoot'
Account: string
Balance: string
Flags: number
OwnerCount: number
PreviousTxnID: string
PreviousTxnLgrSeq: number
Sequence: number
AccountTxnID?: string
Domain?: string
EmailHash?: string
MessageKey?: string
RegularKey?: string,
TickSize?: number,
TransferRate?: number,
WalletLocator?: string,
RegularKey?: string
TickSize?: number
TransferRate?: number
WalletLocator?: string
WalletSize?: number // DEPRECATED
}
export interface AmendmentsLedgerEntry {
LedgerEntryType: 'Amendments',
Amendments?: string[],
Majorities?: any[],
LedgerEntryType: 'Amendments'
Amendments?: string[]
Majorities?: any[]
Flags: 0
}
export interface CheckLedgerEntry {
LedgerEntryType: 'Check',
Account: string,
Destination, string,
Flags: 0,
OwnerNode: string,
PreviousTxnID: string,
PreviousTxnLgrSeq: number,
SendMax: string | object,
Sequence: number,
DestinationNode: string,
DestinationTag: number,
Expiration: number,
InvoiceID: string,
LedgerEntryType: 'Check'
Account: string
Destination
string
Flags: 0
OwnerNode: string
PreviousTxnID: string
PreviousTxnLgrSeq: number
SendMax: string | object
Sequence: number
DestinationNode: string
DestinationTag: number
Expiration: number
InvoiceID: string
SourceTag: number
}
export interface DepositPreauthLedgerEntry {
LedgerEntryType: 'DepositPreauth',
Account: string,
Authorize: string,
OwnerNode: string,
PreviousTxnID: string,
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,
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,
extends DirectoryNodeLedgerEntry {
TakerPaysCurrency: string
TakerPaysIssuer: string
TakerGetsCurrency: string
TakerGetsIssuer: string
ExchangeRate?: number // DEPRECATED
}
export interface OwnerDirectoryNodeLedgerEntry
extends DirectoryNodeLedgerEntry {
Owner: string,
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,
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,
LedgerEntryType: 'FeeSettings'
BaseFee: string
ReferenceFeeUnits: number
ReserveBase: number
ReserveIncrement: number
Flags: number
}
export interface LedgerHashesLedgerEntry {
LedgerEntryType: 'LedgerHashes',
Hashes: string[],
Flags: number,
FirstLedgerSequence?: number, // DEPRECATED
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,
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,
Account: string,
Amount: string,
Balance: string,
PublicKey: string,
Destination: string,
SettleDelay: number,
Expiration?: number,
CancelAfter?: number,
SourceTag?: number,
DestinationTag?: number,
OwnerNode: string,
PreviousTxnID: string,
PreviousTxnLgrSeq: number,
LedgerEntryType: 'PayChannel'
Sequence: number
Account: string
Amount: string
Balance: string
PublicKey: string
Destination: string
SettleDelay: number
Expiration?: number
CancelAfter?: number
SourceTag?: number
DestinationTag?: number
OwnerNode: string
PreviousTxnID: string
PreviousTxnLgrSeq: number
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,
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,
SignerQuorum: number,
SignerEntries: SignerEntry[],
SignerListID: number,
PreviousTxnID: string,
LedgerEntryType: 'SignerList'
OwnerNode: string
SignerQuorum: number
SignerEntries: SignerEntry[]
SignerListID: number
PreviousTxnID: string
PreviousTxnLgrSeq: number
}
// 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 |
RippleStateLedgerEntry |
SignerListLedgerEntry
| AccountRootLedgerEntry
| AmendmentsLedgerEntry
| CheckLedgerEntry
| DepositPreauthLedgerEntry
| DirectoryNodeLedgerEntry
| OfferDirectoryNodeLedgerEntry
| OwnerDirectoryNodeLedgerEntry
| EscrowLedgerEntry
| FeeSettingsLedgerEntry
| LedgerHashesLedgerEntry
| OfferLedgerEntry
| PayChannelLedgerEntry
| RippleStateLedgerEntry
| SignerListLedgerEntry

View File

@@ -1,6 +1,5 @@
export type Memo = {
type?: string,
format?: string,
type?: string
format?: string
data?: string
}

View File

@@ -2,14 +2,14 @@ import {Amount} from './amounts'
import {Memo} from './memos'
export type FormattedOrderSpecification = {
direction: string,
quantity: Amount,
totalPrice: Amount,
immediateOrCancel?: boolean,
fillOrKill?: boolean,
expirationTime?: string,
orderToReplace?: number,
memos?: Memo[],
direction: string
quantity: Amount
totalPrice: Amount
immediateOrCancel?: boolean
fillOrKill?: boolean
expirationTime?: string
orderToReplace?: number
memos?: Memo[]
// 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.

View File

@@ -1,16 +1,16 @@
export interface QueueTransaction {
auth_change: boolean,
fee: string,
fee_level: string,
max_spend_drops: string,
auth_change: boolean
fee: string
fee_level: string
max_spend_drops: string
seq: number
}
export interface QueueData {
txn_count: number,
auth_change_queued?: boolean,
lowest_sequence?: number,
highest_sequence?: number,
max_spend_drops_total?: string,
txn_count: number
auth_change_queued?: boolean
lowest_sequence?: number
highest_sequence?: number
max_spend_drops_total?: string
transactions?: QueueTransaction[]
}

View File

@@ -1,33 +1,33 @@
import {Memo} from './memos'
export type WeightedSigner = {
address: string,
address: string
weight: number
}
export type Signers = {
threshold?: number,
threshold?: number
weights: WeightedSigner[]
}
export type FormattedSettings = {
defaultRipple?: boolean,
depositAuth?: boolean,
disableMasterKey?: boolean,
disallowIncomingXRP?: boolean,
domain?: string,
emailHash?: string|null,
walletLocator?: string|null,
enableTransactionIDTracking?: boolean,
globalFreeze?: boolean,
memos?: Memo[],
messageKey?: string,
noFreeze?: boolean,
passwordSpent?: boolean,
regularKey?: string,
requireAuthorization?: boolean,
requireDestinationTag?: boolean,
signers?: Signers,
transferRate?: number|null,
defaultRipple?: boolean
depositAuth?: boolean
disableMasterKey?: boolean
disallowIncomingXRP?: boolean
domain?: string
emailHash?: string | null
walletLocator?: string | null
enableTransactionIDTracking?: boolean
globalFreeze?: boolean
memos?: Memo[]
messageKey?: string
noFreeze?: boolean
passwordSpent?: boolean
regularKey?: string
requireAuthorization?: boolean
requireDestinationTag?: boolean
signers?: Signers
transferRate?: number | null
tickSize?: number
}

View File

@@ -1,4 +1,6 @@
export interface SignerEntry {
Account: string,
SignerWeight: number
SignerEntry: {
Account: string
SignerWeight: number
}
}

View File

@@ -2,21 +2,21 @@ import {RippledAmount} from './amounts'
import {Memo} from './memos'
export interface OfferCreateTransaction {
TransactionType: 'OfferCreate',
Account: string,
AccountTxnID?: string,
Fee: string,
Field: any,
Flags: number,
LastLedgerSequence?: number,
Sequence: number,
Signers: any[],
SigningPubKey: string,
SourceTag?: number,
TakerGets: RippledAmount,
TakerPays: RippledAmount,
TxnSignature: string,
Expiration?: number,
Memos?: Memo[],
OfferSequence?: number,
TransactionType: 'OfferCreate'
Account: string
AccountTxnID?: string
Fee: string
Field: any
Flags: number
LastLedgerSequence?: number
Sequence: number
Signers: any[]
SigningPubKey: string
SourceTag?: number
TakerGets: RippledAmount
TakerPays: RippledAmount
TxnSignature: string
Expiration?: number
Memos?: Memo[]
OfferSequence?: number
}

View File

@@ -1,41 +1,41 @@
import {Memo} from './memos'
export interface Trustline {
account: string,
balance: string,
currency: string,
limit: string,
limit_peer: string,
quality_in: number,
quality_out: number,
no_ripple?: boolean,
no_ripple_peer?: boolean,
freeze?: boolean,
freeze_peer?: boolean,
authorized?: boolean,
peer_authorized?: boolean,
account: string
balance: string
currency: string
limit: string
limit_peer: string
quality_in: number
quality_out: number
no_ripple?: boolean
no_ripple_peer?: boolean
freeze?: boolean
freeze_peer?: boolean
authorized?: boolean
peer_authorized?: boolean
}
export type FormattedTrustlineSpecification = {
currency: string,
counterparty: string,
limit: string,
qualityIn?: number,
qualityOut?: number,
ripplingDisabled?: boolean,
authorized?: boolean,
frozen?: boolean,
currency: string
counterparty: string
limit: string
qualityIn?: number
qualityOut?: number
ripplingDisabled?: boolean
authorized?: boolean
frozen?: boolean
memos?: Memo[]
}
export type FormattedTrustline = {
specification: FormattedTrustlineSpecification,
specification: FormattedTrustlineSpecification
counterparty: {
limit: string,
ripplingDisabled?: boolean,
frozen?: boolean,
limit: string
ripplingDisabled?: boolean
frozen?: boolean
authorized?: boolean
},
}
state: {
balance: string
}

View File

@@ -16,74 +16,93 @@ function isValidSecret(secret: string): boolean {
function dropsToXrp(drops: BigNumber.Value): 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]*$).`)
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.`)
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 = new BigNumber(drops).toString(10)
// drops are only whole units
if (drops.includes('.')) {
throw new ValidationError(`dropsToXrp: value '${drops}' has` +
` too many decimal places.`)
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]+$).`)
throw new ValidationError(
`dropsToXrp: failed sanity check -` +
` value '${drops}',` +
` does not match (^-?[0-9]+$).`
)
}
return (new BigNumber(drops)).dividedBy(1000000.0).toString(10)
return new BigNumber(drops).dividedBy(1000000.0).toString(10)
}
function xrpToDrops(xrp: BigNumber.Value): 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]*$).`)
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.`)
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)
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.]+$).`)
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.`)
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.`)
throw new ValidationError(
`xrpToDrops: value '${xrp}' has` + ` too many decimal places.`
)
}
return (new BigNumber(xrp)).times(1000000.0).integerValue(BigNumber.ROUND_FLOOR).toString(10)
return new BigNumber(xrp)
.times(1000000.0)
.integerValue(BigNumber.ROUND_FLOOR)
.toString(10)
}
function toRippledAmount(amount: Amount): RippledAmount {
@@ -95,8 +114,11 @@ function toRippledAmount(amount: Amount): RippledAmount {
}
return {
currency: amount.currency,
issuer: amount.counterparty ? amount.counterparty :
(amount.issuer ? amount.issuer : undefined),
issuer: amount.counterparty
? amount.counterparty
: amount.issuer
? amount.issuer
: undefined,
value: amount.value
}
}
@@ -105,16 +127,20 @@ function convertKeysFromSnakeCaseToCamelCase(obj: any): any {
if (typeof obj === 'object') {
const accumulator = Array.isArray(obj) ? [] : {}
let newKey
return _.reduce(obj, (result, value, key) => {
newKey = key
// taking this out of function leads to error in PhantomJS
const FINDSNAKE = /([a-zA-Z]_[a-zA-Z])/g
if (FINDSNAKE.test(key)) {
newKey = key.replace(FINDSNAKE, r => r[0] + r[2].toUpperCase())
}
result[newKey] = convertKeysFromSnakeCaseToCamelCase(value)
return result
}, accumulator)
return _.reduce(
obj,
(result, value, key) => {
newKey = key
// taking this out of function leads to error in PhantomJS
const FINDSNAKE = /([a-zA-Z]_[a-zA-Z])/g
if (FINDSNAKE.test(key)) {
newKey = key.replace(FINDSNAKE, r => r[0] + r[2].toUpperCase())
}
result[newKey] = convertKeysFromSnakeCaseToCamelCase(value)
return result
},
accumulator
)
}
return obj
}
@@ -128,7 +154,7 @@ function removeUndefined<T extends object>(obj: T): T {
* @return {Number} ms since unix epoch
*/
function rippleToUnixTimestamp(rpepoch: number): number {
return (rpepoch + 0x386D4380) * 1000
return (rpepoch + 0x386d4380) * 1000
}
/**
@@ -136,7 +162,7 @@ function rippleToUnixTimestamp(rpepoch: number): number {
* @return {Number} seconds since ripple epoch (1/1/2000 GMT)
*/
function unixToRippleTimestamp(timestamp: number): number {
return Math.round(timestamp / 1000) - 0x386D4380
return Math.round(timestamp / 1000) - 0x386d4380
}
function rippleTimeToISO8601(rippleTime: number): string {
@@ -161,4 +187,3 @@ export {
iso8601ToRippleTime,
isValidSecret
}

View File

@@ -7,8 +7,11 @@ function error(text) {
}
function validateLedgerRange(options) {
if (!_.isUndefined(options) && !_.isUndefined(options.minLedgerVersion)
&& !_.isUndefined(options.maxLedgerVersion)) {
if (
!_.isUndefined(options) &&
!_.isUndefined(options.minLedgerVersion) &&
!_.isUndefined(options.maxLedgerVersion)
) {
if (Number(options.minLedgerVersion) > Number(options.maxLedgerVersion)) {
throw error('minLedgerVersion must not be greater than maxLedgerVersion')
}
@@ -20,110 +23,143 @@ function validateOptions(schema, instance) {
validateLedgerRange(instance.options)
}
export const getPaths =
_.partial(schemaValidate, 'getPathsParameters')
export const getPaths = _.partial(schemaValidate, 'getPathsParameters')
export const getTransactions =
_.partial(validateOptions, 'getTransactionsParameters')
export const getTransactions = _.partial(
validateOptions,
'getTransactionsParameters'
)
export const getSettings =
_.partial(validateOptions, 'getSettingsParameters')
export const getSettings = _.partial(validateOptions, 'getSettingsParameters')
export const getAccountInfo =
_.partial(validateOptions, 'getAccountInfoParameters')
export const getAccountInfo = _.partial(
validateOptions,
'getAccountInfoParameters'
)
export const getTrustlines =
_.partial(validateOptions, 'getTrustlinesParameters')
export const getTrustlines = _.partial(
validateOptions,
'getTrustlinesParameters'
)
export const getBalances =
_.partial(validateOptions, 'getBalancesParameters')
export const getBalances = _.partial(validateOptions, 'getBalancesParameters')
export const getBalanceSheet =
_.partial(validateOptions, 'getBalanceSheetParameters')
export const getBalanceSheet = _.partial(
validateOptions,
'getBalanceSheetParameters'
)
export const getOrders =
_.partial(validateOptions, 'getOrdersParameters')
export const getOrders = _.partial(validateOptions, 'getOrdersParameters')
export const getOrderbook =
_.partial(validateOptions, 'getOrderbookParameters')
export const getOrderbook = _.partial(validateOptions, 'getOrderbookParameters')
export const getTransaction =
_.partial(validateOptions, 'getTransactionParameters')
export const getTransaction = _.partial(
validateOptions,
'getTransactionParameters'
)
export const getPaymentChannel =
_.partial(validateOptions, 'getPaymentChannelParameters')
export const getPaymentChannel = _.partial(
validateOptions,
'getPaymentChannelParameters'
)
export const getLedger =
_.partial(validateOptions, 'getLedgerParameters')
export const getLedger = _.partial(validateOptions, 'getLedgerParameters')
export const preparePayment =
_.partial(schemaValidate, 'preparePaymentParameters')
export const preparePayment = _.partial(
schemaValidate,
'preparePaymentParameters'
)
export const prepareOrder =
_.partial(schemaValidate, 'prepareOrderParameters')
export const prepareOrder = _.partial(schemaValidate, 'prepareOrderParameters')
export const prepareOrderCancellation =
_.partial(schemaValidate, 'prepareOrderCancellationParameters')
export const prepareOrderCancellation = _.partial(
schemaValidate,
'prepareOrderCancellationParameters'
)
export const prepareTrustline =
_.partial(schemaValidate, 'prepareTrustlineParameters')
export const prepareTrustline = _.partial(
schemaValidate,
'prepareTrustlineParameters'
)
export const prepareSettings =
_.partial(schemaValidate, 'prepareSettingsParameters')
export const prepareSettings = _.partial(
schemaValidate,
'prepareSettingsParameters'
)
export const prepareEscrowCreation =
_.partial(schemaValidate, 'prepareEscrowCreationParameters')
export const prepareEscrowCreation = _.partial(
schemaValidate,
'prepareEscrowCreationParameters'
)
export const prepareEscrowCancellation =
_.partial(schemaValidate, 'prepareEscrowCancellationParameters')
export const prepareEscrowCancellation = _.partial(
schemaValidate,
'prepareEscrowCancellationParameters'
)
export const prepareEscrowExecution =
_.partial(schemaValidate, 'prepareEscrowExecutionParameters')
export const prepareEscrowExecution = _.partial(
schemaValidate,
'prepareEscrowExecutionParameters'
)
export const preparePaymentChannelCreate =
_.partial(schemaValidate, 'preparePaymentChannelCreateParameters')
export const preparePaymentChannelCreate = _.partial(
schemaValidate,
'preparePaymentChannelCreateParameters'
)
export const preparePaymentChannelFund =
_.partial(schemaValidate, 'preparePaymentChannelFundParameters')
export const preparePaymentChannelFund = _.partial(
schemaValidate,
'preparePaymentChannelFundParameters'
)
export const preparePaymentChannelClaim =
_.partial(schemaValidate, 'preparePaymentChannelClaimParameters')
export const preparePaymentChannelClaim = _.partial(
schemaValidate,
'preparePaymentChannelClaimParameters'
)
export const prepareCheckCreate =
_.partial(schemaValidate, 'prepareCheckCreateParameters')
export const prepareCheckCreate = _.partial(
schemaValidate,
'prepareCheckCreateParameters'
)
export const prepareCheckCash =
_.partial(schemaValidate, 'prepareCheckCashParameters')
export const prepareCheckCash = _.partial(
schemaValidate,
'prepareCheckCashParameters'
)
export const prepareCheckCancel =
_.partial(schemaValidate, 'prepareCheckCancelParameters')
export const prepareCheckCancel = _.partial(
schemaValidate,
'prepareCheckCancelParameters'
)
export const sign =
_.partial(schemaValidate, 'signParameters')
export const sign = _.partial(schemaValidate, 'signParameters')
export const combine =
_.partial(schemaValidate, 'combineParameters')
export const combine = _.partial(schemaValidate, 'combineParameters')
export const submit =
_.partial(schemaValidate, 'submitParameters')
export const submit = _.partial(schemaValidate, 'submitParameters')
export const computeLedgerHash =
_.partial(schemaValidate, 'computeLedgerHashParameters')
export const computeLedgerHash = _.partial(
schemaValidate,
'computeLedgerHashParameters'
)
export const generateAddress =
_.partial(schemaValidate, 'generateAddressParameters')
export const generateAddress = _.partial(
schemaValidate,
'generateAddressParameters'
)
export const signPaymentChannelClaim =
_.partial(schemaValidate, 'signPaymentChannelClaimParameters')
export const signPaymentChannelClaim = _.partial(
schemaValidate,
'signPaymentChannelClaimParameters'
)
export const verifyPaymentChannelClaim =
_.partial(schemaValidate, 'verifyPaymentChannelClaimParameters')
export const verifyPaymentChannelClaim = _.partial(
schemaValidate,
'verifyPaymentChannelClaimParameters'
)
export const apiOptions =
_.partial(schemaValidate, 'api-options')
export const apiOptions = _.partial(schemaValidate, 'api-options')
export const instructions =
_.partial(schemaValidate, 'instructions')
export const instructions = _.partial(schemaValidate, 'instructions')
export const tx_json =
_.partial(schemaValidate, 'tx-json')
export const tx_json = _.partial(schemaValidate, 'tx-json')

View File

@@ -17,7 +17,6 @@ declare class WebSocket {
* same, as `ws` package provides.
*/
class WSWrapper extends EventEmitter {
private _ws: WebSocket
static CONNECTING = 0
static OPEN = 1
@@ -60,8 +59,6 @@ class WSWrapper extends EventEmitter {
get readyState() {
return this._ws.readyState
}
}
export = WSWrapper

View File

@@ -1,8 +1,6 @@
export {RippleAPI} from './api'
export {
FormattedTransactionType
} from './transaction/types'
export {FormattedTransactionType} from './transaction/types'
// Broadcast api is experimental
export {RippleAPIBroadcast} from './broadcast'

View File

@@ -1,4 +1,9 @@
import {validate, removeUndefined, dropsToXrp, ensureClassicAddress} from '../common'
import {
validate,
removeUndefined,
dropsToXrp,
ensureClassicAddress
} from '../common'
import {RippleAPI} from '..'
import {AccountInfoResponse} from '../common/types/commands/account_info'
@@ -7,11 +12,11 @@ export type GetAccountInfoOptions = {
}
export type FormattedGetAccountInfoResponse = {
sequence: number,
xrpBalance: string,
ownerCount: number,
previousInitiatedTransactionID: string,
previousAffectingTransactionID: string,
sequence: number
xrpBalance: string
ownerCount: number
previousInitiatedTransactionID: string
previousAffectingTransactionID: string
previousAffectingTransactionLedgerVersion: number
}
@@ -30,7 +35,9 @@ function formatAccountInfo(
}
export default async function getAccountInfo(
this: RippleAPI, address: string, options: GetAccountInfoOptions = {}
this: RippleAPI,
address: string,
options: GetAccountInfoOptions = {}
): Promise<FormattedGetAccountInfoResponse> {
// 1. Validate
validate.getAccountInfo({address, options})

View File

@@ -14,14 +14,17 @@ export default async function getAccountObjects(
// through to rippled. rippled validates requests.
// Make Request
const response = await this.request('account_objects', removeUndefined({
account: address,
type: options.type,
ledger_hash: options.ledgerHash,
ledger_index: options.ledgerIndex,
limit: options.limit,
marker: options.marker
}))
const response = await this.request(
'account_objects',
removeUndefined({
account: address,
type: options.type,
ledger_hash: options.ledgerHash,
ledger_index: options.ledgerIndex,
limit: options.limit,
marker: options.marker
})
)
// Return Response
return response
}

View File

@@ -5,17 +5,17 @@ import {ensureLedgerVersion} from './utils'
import {RippleAPI} from '..'
export type BalanceSheetOptions = {
excludeAddresses?: Array<string>,
excludeAddresses?: Array<string>
ledgerVersion?: number
}
export type GetBalanceSheet = {
balances?: Array<Amount>,
assets?: Array<Amount>,
balances?: Array<Amount>
assets?: Array<Amount>
obligations?: Array<{
currency: string,
value: string
}>
currency: string
value: string
}>
}
function formatBalanceSheet(balanceSheet): GetBalanceSheet {
@@ -48,7 +48,9 @@ function formatBalanceSheet(balanceSheet): GetBalanceSheet {
}
async function getBalanceSheet(
this: RippleAPI, address: string, options: BalanceSheetOptions = {}
this: RippleAPI,
address: string,
options: BalanceSheetOptions = {}
): Promise<GetBalanceSheet> {
// 1. Validate
validate.getBalanceSheet({address, options})

View File

@@ -6,8 +6,8 @@ import {FormattedTrustline} from '../common/types/objects/trustlines'
import {RippleAPI} from '..'
export type Balance = {
value: string,
currency: string,
value: string
currency: string
counterparty?: string
}
@@ -23,9 +23,9 @@ function getTrustlineBalanceAmount(trustline: FormattedTrustline) {
function formatBalances(options, balances) {
const result = balances.trustlines.map(getTrustlineBalanceAmount)
if (!(options.counterparty ||
(options.currency && options.currency !== 'XRP')
)) {
if (
!(options.counterparty || (options.currency && options.currency !== 'XRP'))
) {
const xrpBalance = {
currency: 'XRP',
value: balances.xrp
@@ -39,7 +39,9 @@ function formatBalances(options, balances) {
return result
}
function getLedgerVersionHelper(connection: Connection, optionValue?: number
function getLedgerVersionHelper(
connection: Connection,
optionValue?: number
): Promise<number> {
if (optionValue !== undefined && optionValue !== null) {
return Promise.resolve(optionValue)
@@ -47,7 +49,10 @@ function getLedgerVersionHelper(connection: Connection, optionValue?: number
return connection.getLedgerVersion()
}
function getBalances(this: RippleAPI, address: string, options: GetTrustlinesOptions = {}
function getBalances(
this: RippleAPI,
address: string,
options: GetTrustlinesOptions = {}
): Promise<GetBalances> {
validate.getTrustlines({address, options})
@@ -59,12 +64,16 @@ function getBalances(this: RippleAPI, address: string, options: GetTrustlinesOpt
address = ensureClassicAddress(address)
return Promise.all([
getLedgerVersionHelper(this.connection, options.ledgerVersion).then(
ledgerVersion =>
utils.getXRPBalance(this.connection, address, ledgerVersion)),
getLedgerVersionHelper(
this.connection,
options.ledgerVersion
).then(ledgerVersion =>
utils.getXRPBalance(this.connection, address, ledgerVersion)
),
this.getTrustlines(address, options)
]).then(results =>
formatBalances(options, {xrp: results[0], trustlines: results[1]}))
formatBalances(options, {xrp: results[0], trustlines: results[1]})
)
}
export default getBalances

View File

@@ -3,15 +3,16 @@ import {FormattedLedger, parseLedger} from './parse/ledger'
import {RippleAPI} from '..'
export type GetLedgerOptions = {
ledgerHash?: string,
ledgerVersion?: number,
includeAllData?: boolean,
includeTransactions?: boolean,
ledgerHash?: string
ledgerVersion?: number
includeAllData?: boolean
includeTransactions?: boolean
includeState?: boolean
}
async function getLedger(
this: RippleAPI, options: GetLedgerOptions = {}
this: RippleAPI,
options: GetLedgerOptions = {}
): Promise<FormattedLedger> {
// 1. Validate
validate.getLedger({options})

View File

@@ -11,7 +11,7 @@ import {RippleAPI} from '..'
import BigNumber from 'bignumber.js'
export type FormattedOrderbook = {
bids: FormattedOrderbookOrder[],
bids: FormattedOrderbookOrder[]
asks: FormattedOrderbookOrder[]
}
@@ -34,13 +34,18 @@ function flipOrder(order: FormattedOrderbookOrder) {
return _.merge({}, order, {specification: newSpecification})
}
function alignOrder(base: Issue, order: FormattedOrderbookOrder): FormattedOrderbookOrder {
function alignOrder(
base: Issue,
order: FormattedOrderbookOrder
): FormattedOrderbookOrder {
const quantity = order.specification.quantity
return isSameIssue(quantity, base) ? order : flipOrder(order)
}
export function formatBidsAndAsks(
orderbook: OrderbookInfo, offers: BookOffer[]) {
orderbook: OrderbookInfo,
offers: BookOffer[]
) {
// the "base" currency is the currency that you are buying or selling
// the "counter" is the currency that the "base" is priced in
// a "bid"/"ask" is an order to buy/sell the base, respectively
@@ -51,9 +56,11 @@ export function formatBidsAndAsks(
// for asks: lowest quality => lowest totalPrice/quantity => lowest price
// for both bids and asks, lowest quality is closest to mid-market
// we sort the orders so that earlier orders are closer to mid-market
const orders = offers.sort((a, b) => {
return (new BigNumber(a.quality)).comparedTo(b.quality)
}).map(parseOrderbookOrder)
const orders = offers
.sort((a, b) => {
return new BigNumber(a.quality).comparedTo(b.quality)
})
.map(parseOrderbookOrder)
const alignedOrders = orders.map(_.partial(alignOrder, orderbook.base))
const bids = alignedOrders.filter(_.partial(directionFilter, 'buy'))
@@ -64,8 +71,11 @@ export function formatBidsAndAsks(
// account is to specify a "perspective", which affects which unfunded offers
// are returned
async function makeRequest(
api: RippleAPI, taker: string, options: GetOrderbookOptions,
takerGets: Issue, takerPays: Issue
api: RippleAPI,
taker: string,
options: GetOrderbookOptions,
takerGets: Issue,
takerPays: Issue
) {
const orderData = utils.renameCounterpartyToIssuerInOrder({
taker_gets: takerGets,
@@ -80,14 +90,13 @@ async function makeRequest(
})
}
export type GetOrderbookOptions = {
limit?: number,
limit?: number
ledgerVersion?: number
}
export type OrderbookInfo = {
base: Issue,
base: Issue
counter: Issue
}
@@ -105,10 +114,13 @@ export async function getOrderbook(
makeRequest(this, address, options, orderbook.counter, orderbook.base)
])
// 3. Return Formatted Response
const directOffers = _.flatMap(directOfferResults,
directOfferResult => directOfferResult.offers)
const reverseOffers = _.flatMap(reverseOfferResults,
reverseOfferResult => reverseOfferResult.offers)
return formatBidsAndAsks(orderbook,
[...directOffers, ...reverseOffers])
const directOffers = _.flatMap(
directOfferResults,
directOfferResult => directOfferResult.offers
)
const reverseOffers = _.flatMap(
reverseOfferResults,
reverseOfferResult => reverseOfferResult.offers
)
return formatBidsAndAsks(orderbook, [...directOffers, ...reverseOffers])
}

View File

@@ -5,12 +5,13 @@ import {RippleAPI} from '..'
import {AccountOffersResponse} from '../common/types/commands'
export type GetOrdersOptions = {
limit?: number,
limit?: number
ledgerVersion?: number
}
function formatResponse(
address: string, responses: AccountOffersResponse[]
address: string,
responses: AccountOffersResponse[]
): FormattedAccountOrder[] {
let orders: FormattedAccountOrder[] = []
for (const response of responses) {
@@ -23,14 +24,16 @@ function formatResponse(
}
export default async function getOrders(
this: RippleAPI, address: string, options: GetOrdersOptions = {}
this: RippleAPI,
address: string,
options: GetOrdersOptions = {}
): Promise<FormattedAccountOrder[]> {
// 1. Validate
validate.getOrders({address, options})
// 2. Make Request
const responses = await this._requestAll('account_offers', {
account: address,
ledger_index: options.ledgerVersion || await this.getLedgerVersion(),
ledger_index: options.ledgerVersion || (await this.getLedgerVersion()),
limit: options.limit
})
// 3. Return Formatted Response, from the perspective of `address`

View File

@@ -0,0 +1,34 @@
import * as assert from 'assert'
import {removeUndefined} from '../../common'
import {classicAddressToXAddress} from 'ripple-address-codec'
export type FormattedAccountDelete = {
// account (address) of an account to receive any leftover XRP after deleting the sending account.
// Must be a funded account in the ledger, and must not be the sending account.
destination: string
// (Optional) Arbitrary destination tag that identifies a hosted recipient or other information
// for the recipient of the deleted account's leftover XRP. NB: Ensure that the hosted recipient is
// able to account for AccountDelete transactions; if not, your balance may not be properly credited.
destinationTag?: number
// X-address of an account to receive any leftover XRP after deleting the sending account.
// Must be a funded account in the ledger, and must not be the sending account.
destinationXAddress: string
}
function parseAccountDelete(tx: any): FormattedAccountDelete {
assert.ok(tx.TransactionType === 'AccountDelete')
return removeUndefined({
destination: tx.Destination,
destinationTag: tx.DestinationTag,
destinationXAddress: classicAddressToXAddress(
tx.Destination,
tx.DestinationTag === undefined ? false : tx.DestinationTag,
false
)
})
}
export default parseAccountDelete

View File

@@ -6,10 +6,10 @@ import {orderFlags} from './flags'
import {FormattedOrderSpecification} from '../../common/types/objects'
export type FormattedAccountOrder = {
specification: FormattedOrderSpecification,
properties: {
maker: string,
sequence: number,
specification: FormattedOrderSpecification
properties: {
maker: string
sequence: number
makerExchangeRate: string
}
}
@@ -23,13 +23,14 @@ function computeQuality(takerGets, takerPays) {
// rippled 'account_offers' returns a different format for orders than 'tx'
// the flags are also different
export function parseAccountOrder(
address: string, order: any
address: string,
order: any
): FormattedAccountOrder {
const direction = (order.flags & orderFlags.Sell) === 0 ? 'buy' : 'sell'
const takerGetsAmount = parseAmount(order.taker_gets)
const takerPaysAmount = parseAmount(order.taker_pays)
const quantity = (direction === 'buy') ? takerPaysAmount : takerGetsAmount
const totalPrice = (direction === 'buy') ? takerGetsAmount : takerPaysAmount
const quantity = direction === 'buy' ? takerPaysAmount : takerGetsAmount
const totalPrice = direction === 'buy' ? takerGetsAmount : takerPaysAmount
// note: immediateOrCancel and fillOrKill orders cannot enter the order book
// so we can omit those flags here
@@ -37,15 +38,18 @@ export function parseAccountOrder(
direction: direction,
quantity: quantity,
totalPrice: totalPrice,
passive: ((order.flags & orderFlags.Passive) !== 0) || undefined,
passive: (order.flags & orderFlags.Passive) !== 0 || undefined,
// rippled currently does not provide "expiration" in account_offers
expirationTime: parseTimestamp(order.expiration)
})
const makerExchangeRate = order.quality ?
adjustQualityForXRP(order.quality.toString(),
takerGetsAmount.currency, takerPaysAmount.currency) :
computeQuality(takerGetsAmount, takerPaysAmount)
const makerExchangeRate = order.quality
? adjustQualityForXRP(
order.quality.toString(),
takerGetsAmount.currency,
takerPaysAmount.currency
)
: computeQuality(takerGetsAmount, takerPaysAmount)
const properties = {
maker: address,
sequence: order.seq,

View File

@@ -1,5 +1,3 @@
function parseAmendment(tx: any) {
return {
amendment: tx.Amendment

View File

@@ -1,7 +1,6 @@
import * as common from '../../common'
import {Amount, RippledAmount} from '../../common/types/objects'
function parseAmount(amount: RippledAmount): Amount {
if (typeof amount === 'string') {
return {

View File

@@ -2,7 +2,6 @@ import * as assert from 'assert'
import {removeUndefined} from '../../common'
export type FormattedCheckCancel = {
// ID of the Check ledger object to cancel.
checkID: string
}

View File

@@ -4,14 +4,13 @@ import parseAmount from './amount'
import {Amount} from '../../common/types/objects'
export type FormattedCheckCash = {
// ID of the Check ledger object to cash.
checkID: string,
checkID: string
// (Optional) redeem the Check for exactly this amount, if possible.
// The currency must match that of the `SendMax` of the corresponding
// `CheckCreate` transaction.
amount: Amount,
amount: Amount
// (Optional) redeem the Check for at least this amount and
// for as much as possible.

View File

@@ -5,19 +5,18 @@ import parseAmount from './amount'
import {Amount} from '../../common/types/objects'
export type FormattedCheckCreate = {
// account that can cash the check.
destination: string,
destination: string
// amount the check is allowed to debit the sender,
// including transfer fees on non-XRP currencies.
sendMax: Amount,
sendMax: Amount
// (Optional) identifies the reason for the check, or a hosted recipient.
destinationTag?: string,
destinationTag?: string
// (Optional) time in seconds since the Ripple Epoch.
expiration?: string,
expiration?: string
// (Optional) 256-bit hash representing a specific reason or identifier.
invoiceID?: string

View File

@@ -3,7 +3,7 @@ import {removeUndefined} from '../../common'
export type FormattedDepositPreauth = {
// account (address) of the sender to preauthorize
authorize: string,
authorize: string
// account (address) of the sender whose preauthorization should be revoked
unauthorize: string

View File

@@ -1,9 +1,8 @@
import BigNumber from 'bignumber.js'
import {dropsToXrp} from '../../common'
function parseFeeUpdate(tx: any) {
const baseFeeDrops = (new BigNumber(tx.BaseFee, 16)).toString()
const baseFeeDrops = new BigNumber(tx.BaseFee, 16).toString()
return {
baseFeeXRP: dropsToXrp(baseFeeDrops),
referenceFeeUnits: tx.ReferenceFeeUnits,

View File

@@ -4,11 +4,12 @@ import {constants} from '../../common'
const AccountFields = constants.AccountFields
function parseField(info, value) {
if (info.encoding === 'hex' && !info.length) { // e.g. "domain"
if (info.encoding === 'hex' && !info.length) {
// e.g. "domain"
return Buffer.from(value, 'hex').toString('ascii')
}
if (info.shift) {
return (new BigNumber(value)).shiftedBy(-info.shift).toNumber()
return new BigNumber(value).shiftedBy(-info.shift).toNumber()
}
return value
}
@@ -42,7 +43,8 @@ function parseFields(data: any): object {
address: entry.SignerEntry.Account,
weight: entry.SignerEntry.SignerWeight
}
})
}
)
}
}
return settings

View File

@@ -1,5 +1,3 @@
const orderFlags = {
Passive: 0x00010000,
Sell: 0x00020000 // offer was placed as a sell
@@ -16,7 +14,4 @@ const trustlineFlags = {
HighFreeze: 0x00800000
}
export {
orderFlags,
trustlineFlags
}
export {orderFlags, trustlineFlags}

View File

@@ -7,19 +7,19 @@ export type FormattedLedger = {
// TODO: properties in type don't match response object. Fix!
// accepted: boolean,
// closed: boolean,
stateHash: string,
closeTime: string,
closeTimeResolution: number,
closeFlags: number,
ledgerHash: string,
ledgerVersion: number,
parentLedgerHash: string,
parentCloseTime: string,
totalDrops: string,
transactionHash: string,
transactions?: Array<object>,
transactionHashes?: Array<string>,
rawState?: string,
stateHash: string
closeTime: string
closeTimeResolution: number
closeFlags: number
ledgerHash: string
ledgerVersion: number
parentLedgerHash: string
parentCloseTime: string
totalDrops: string
transactionHash: string
transactions?: Array<object>
transactionHashes?: Array<string>
rawState?: string
stateHashes?: Array<string>
}
@@ -44,8 +44,10 @@ function parseTransactions(transactions, ledgerVersion) {
return {transactionHashes: transactions}
}
return {
transactions: _.map(transactions,
_.partial(parseTransactionWrapper, ledgerVersion))
transactions: _.map(
transactions,
_.partial(parseTransactionWrapper, ledgerVersion)
)
}
}
@@ -66,20 +68,22 @@ function parseState(state) {
*/
export function parseLedger(ledger: Ledger): FormattedLedger {
const ledgerVersion = parseInt(ledger.ledger_index || ledger.seqNum, 10)
return removeUndefined(Object.assign(
{
stateHash: ledger.account_hash,
closeTime: rippleTimeToISO8601(ledger.close_time),
closeTimeResolution: ledger.close_time_resolution,
closeFlags: ledger.close_flags,
ledgerHash: ledger.hash || ledger.ledger_hash,
ledgerVersion: ledgerVersion,
parentLedgerHash: ledger.parent_hash,
parentCloseTime: rippleTimeToISO8601(ledger.parent_close_time),
totalDrops: ledger.total_coins || ledger.totalCoins,
transactionHash: ledger.transaction_hash
},
parseTransactions(ledger.transactions, ledgerVersion),
parseState(ledger.accountState)
))
return removeUndefined(
Object.assign(
{
stateHash: ledger.account_hash,
closeTime: rippleTimeToISO8601(ledger.close_time),
closeTimeResolution: ledger.close_time_resolution,
closeFlags: ledger.close_flags,
ledgerHash: ledger.hash || ledger.ledger_hash,
ledgerVersion: ledgerVersion,
parentLedgerHash: ledger.parent_hash,
parentCloseTime: rippleTimeToISO8601(ledger.parent_close_time),
totalDrops: ledger.total_coins || ledger.totalCoins,
transactionHash: ledger.transaction_hash
},
parseTransactions(ledger.transactions, ledgerVersion),
parseState(ledger.accountState)
)
)
}

View File

@@ -15,17 +15,16 @@ function parseOrder(tx: OfferCreateTransaction): FormattedOrderSpecification {
const direction = (tx.Flags & flags.Sell) === 0 ? 'buy' : 'sell'
const takerGetsAmount = parseAmount(tx.TakerGets)
const takerPaysAmount = parseAmount(tx.TakerPays)
const quantity = (direction === 'buy') ? takerPaysAmount : takerGetsAmount
const totalPrice = (direction === 'buy') ? takerGetsAmount : takerPaysAmount
const quantity = direction === 'buy' ? takerPaysAmount : takerGetsAmount
const totalPrice = direction === 'buy' ? takerGetsAmount : takerPaysAmount
return removeUndefined({
direction: direction,
quantity: quantity,
totalPrice: totalPrice,
passive: ((tx.Flags & flags.Passive) !== 0) || undefined,
immediateOrCancel: ((tx.Flags & flags.ImmediateOrCancel) !== 0)
|| undefined,
fillOrKill: ((tx.Flags & flags.FillOrKill) !== 0) || undefined,
passive: (tx.Flags & flags.Passive) !== 0 || undefined,
immediateOrCancel: (tx.Flags & flags.ImmediateOrCancel) !== 0 || undefined,
fillOrKill: (tx.Flags & flags.FillOrKill) !== 0 || undefined,
expirationTime: parseTimestamp(tx.Expiration)
})
}

View File

@@ -8,27 +8,25 @@ import {BookOffer} from '../../common/types/commands'
import {Amount, FormattedOrderSpecification} from '../../common/types/objects'
export type FormattedOrderbookOrder = {
specification: FormattedOrderSpecification,
specification: FormattedOrderSpecification
properties: {
maker: string,
sequence: number,
maker: string
sequence: number
makerExchangeRate: string
},
}
state?: {
fundedAmount: Amount,
fundedAmount: Amount
priceOfFundedAmount: Amount
},
}
data: BookOffer
}
export function parseOrderbookOrder(
data: BookOffer
): FormattedOrderbookOrder {
export function parseOrderbookOrder(data: BookOffer): FormattedOrderbookOrder {
const direction = (data.Flags & orderFlags.Sell) === 0 ? 'buy' : 'sell'
const takerGetsAmount = parseAmount(data.TakerGets)
const takerPaysAmount = parseAmount(data.TakerPays)
const quantity = (direction === 'buy') ? takerPaysAmount : takerGetsAmount
const totalPrice = (direction === 'buy') ? takerGetsAmount : takerPaysAmount
const quantity = direction === 'buy' ? takerPaysAmount : takerGetsAmount
const totalPrice = direction === 'buy' ? takerGetsAmount : takerPaysAmount
// note: immediateOrCancel and fillOrKill orders cannot enter the order book
// so we can omit those flags here
@@ -36,21 +34,26 @@ export function parseOrderbookOrder(
direction: direction,
quantity: quantity,
totalPrice: totalPrice,
passive: ((data.Flags & orderFlags.Passive) !== 0) || undefined,
passive: (data.Flags & orderFlags.Passive) !== 0 || undefined,
expirationTime: parseTimestamp(data.Expiration)
})
const properties = {
maker: data.Account,
sequence: data.Sequence,
makerExchangeRate: adjustQualityForXRP(data.quality,
takerGetsAmount.currency, takerPaysAmount.currency)
makerExchangeRate: adjustQualityForXRP(
data.quality,
takerGetsAmount.currency,
takerPaysAmount.currency
)
}
const takerGetsFunded = data.taker_gets_funded ?
parseAmount(data.taker_gets_funded) : undefined
const takerPaysFunded = data.taker_pays_funded ?
parseAmount(data.taker_pays_funded) : undefined
const takerGetsFunded = data.taker_gets_funded
? parseAmount(data.taker_gets_funded)
: undefined
const takerPaysFunded = data.taker_pays_funded
? parseAmount(data.taker_pays_funded)
: undefined
const available = removeUndefined({
fundedAmount: takerGetsFunded,
priceOfFundedAmount: takerPaysFunded

View File

@@ -4,33 +4,48 @@ import {Amount, RippledAmount} from '../../common/types/objects'
import {Path, GetPaths, RippledPathsResponse} from '../pathfind-types'
function parsePaths(paths) {
return paths.map(steps => steps.map(step =>
_.omit(step, ['type', 'type_hex'])))
return paths.map(steps =>
steps.map(step => _.omit(step, ['type', 'type_hex']))
)
}
function removeAnyCounterpartyEncoding(address: string, amount: Amount) {
return amount.counterparty === address ?
_.omit(amount, 'counterparty') : amount
return amount.counterparty === address
? _.omit(amount, 'counterparty')
: amount
}
function createAdjustment(
address: string, adjustmentWithoutAddress: object): any {
address: string,
adjustmentWithoutAddress: object
): any {
const amountKey = _.keys(adjustmentWithoutAddress)[0]
const amount = adjustmentWithoutAddress[amountKey]
return _.set({address: address}, amountKey,
removeAnyCounterpartyEncoding(address, amount))
return _.set(
{address: address},
amountKey,
removeAnyCounterpartyEncoding(address, amount)
)
}
function parseAlternative(sourceAddress: string, destinationAddress: string,
destinationAmount: RippledAmount, alternative: any
function parseAlternative(
sourceAddress: string,
destinationAddress: string,
destinationAmount: RippledAmount,
alternative: any
): Path {
// we use "maxAmount"/"minAmount" here so that the result can be passed
// directly to preparePayment
const amounts = (alternative.destination_amount !== undefined) ?
{source: {amount: parseAmount(alternative.source_amount)},
destination: {minAmount: parseAmount(alternative.destination_amount)}} :
{source: {maxAmount: parseAmount(alternative.source_amount)},
destination: {amount: parseAmount(destinationAmount)}}
const amounts =
alternative.destination_amount !== undefined
? {
source: {amount: parseAmount(alternative.source_amount)},
destination: {minAmount: parseAmount(alternative.destination_amount)}
}
: {
source: {maxAmount: parseAmount(alternative.source_amount)},
destination: {amount: parseAmount(destinationAmount)}
}
return {
source: createAdjustment(sourceAddress, amounts.source),
@@ -44,7 +59,8 @@ function parsePathfind(pathfindResult: RippledPathsResponse): GetPaths {
const destinationAddress = pathfindResult.destination_account
const destinationAmount = pathfindResult.destination_amount
return pathfindResult.alternatives.map(alt =>
parseAlternative(sourceAddress, destinationAddress, destinationAmount, alt))
parseAlternative(sourceAddress, destinationAddress, destinationAmount, alt)
)
}
export default parsePathfind

View File

@@ -3,17 +3,17 @@ import {removeUndefined, dropsToXrp} from '../../common'
import {PayChannelLedgerEntry} from '../../common/types/objects'
export type FormattedPaymentChannel = {
account: string,
amount: string,
balance: string,
publicKey: string,
destination: string,
settleDelay: number,
expiration?: string,
cancelAfter?: string,
sourceTag?: number,
destinationTag?: number,
previousAffectingTransactionID: string,
account: string
amount: string
balance: string
publicKey: string
destination: string
settleDelay: number
expiration?: string
cancelAfter?: string
sourceTag?: number
destinationTag?: number
previousAffectingTransactionID: string
previousAffectingTransactionLedgerVersion: number
}

View File

@@ -13,8 +13,9 @@ function isQualityLimited(tx) {
}
function removeGenericCounterparty(amount, address) {
return amount.counterparty === address ?
_.omit(amount, 'counterparty') : amount
return amount.counterparty === address
? _.omit(amount, 'counterparty')
: amount
}
// Payment specification
@@ -24,12 +25,14 @@ function parsePayment(tx: any): object {
const source = {
address: tx.Account,
maxAmount: removeGenericCounterparty(
parseAmount(tx.SendMax || tx.Amount), tx.Account),
parseAmount(tx.SendMax || tx.Amount),
tx.Account
),
tag: tx.SourceTag
}
const destination: {
address: string,
address: string
tag: number | undefined
} = {
address: tx.Destination,

View File

@@ -5,8 +5,9 @@ const AccountFlags = constants.AccountFlags
import parseFields from './fields'
function getAccountRootModifiedNode(tx: any) {
const modifiedNodes = tx.meta.AffectedNodes.filter(node =>
node.ModifiedNode.LedgerEntryType === 'AccountRoot')
const modifiedNodes = tx.meta.AffectedNodes.filter(
node => node.ModifiedNode.LedgerEntryType === 'AccountRoot'
)
assert.ok(modifiedNodes.length === 1)
return modifiedNodes[0].ModifiedNode
}
@@ -51,8 +52,11 @@ function parseFlags(tx: any): any {
function parseSettings(tx: any) {
const txType = tx.TransactionType
assert.ok(txType === 'AccountSet' || txType === 'SetRegularKey' ||
txType === 'SignerListSet')
assert.ok(
txType === 'AccountSet' ||
txType === 'SetRegularKey' ||
txType === 'SignerListSet'
)
return _.assign({}, parseFlags(tx), parseFields(tx))
}

View File

@@ -1,27 +1,31 @@
import {parseOutcome} from './utils'
import {removeUndefined} from '../../common'
import parsePayment from './payment'
import parseTrustline from './trustline'
import parseOrder from './order'
import parseOrderCancellation from './cancellation'
import parseSettings from './settings'
import parseAccountDelete from './account-delete'
import parseCheckCancel from './check-cancel'
import parseCheckCash from './check-cash'
import parseCheckCreate from './check-create'
import parseDepositPreauth from './deposit-preauth'
import parseEscrowCancellation from './escrow-cancellation'
import parseEscrowCreation from './escrow-creation'
import parseEscrowExecution from './escrow-execution'
import parseEscrowCancellation from './escrow-cancellation'
import parseCheckCreate from './check-create'
import parseCheckCash from './check-cash'
import parseCheckCancel from './check-cancel'
import parseDepositPreauth from './deposit-preauth'
import parseOrderCancellation from './cancellation'
import parseOrder from './order'
import parsePayment from './payment'
import parsePaymentChannelClaim from './payment-channel-claim'
import parsePaymentChannelCreate from './payment-channel-create'
import parsePaymentChannelFund from './payment-channel-fund'
import parsePaymentChannelClaim from './payment-channel-claim'
import parseFeeUpdate from './fee-update'
import parseAmendment from './amendment'
import parseTrustline from './trustline'
import parseAmendment from './amendment' // pseudo-transaction
import parseFeeUpdate from './fee-update' // pseudo-transaction
function parseTransactionType(type) {
// Ordering matches https://developers.ripple.com/transaction-types.html
const mapping = {
AccountSet: 'settings',
AccountDelete: 'accountDelete',
CheckCancel: 'checkCancel',
CheckCash: 'checkCash',
CheckCreate: 'checkCreate',
@@ -49,30 +53,35 @@ function parseTransactionType(type) {
function parseTransaction(tx: any, includeRawTransaction: boolean): any {
const type = parseTransactionType(tx.TransactionType)
const mapping = {
'payment': parsePayment,
'trustline': parseTrustline,
'order': parseOrder,
'orderCancellation': parseOrderCancellation,
'settings': parseSettings,
'escrowCreation': parseEscrowCreation,
'escrowExecution': parseEscrowExecution,
'escrowCancellation': parseEscrowCancellation,
'checkCreate': parseCheckCreate,
'checkCash': parseCheckCash,
'checkCancel': parseCheckCancel,
'depositPreauth': parseDepositPreauth,
'paymentChannelCreate': parsePaymentChannelCreate,
'paymentChannelFund': parsePaymentChannelFund,
'paymentChannelClaim': parsePaymentChannelClaim,
'feeUpdate': parseFeeUpdate,
'amendment': parseAmendment
settings: parseSettings,
accountDelete: parseAccountDelete,
checkCancel: parseCheckCancel,
checkCash: parseCheckCash,
checkCreate: parseCheckCreate,
depositPreauth: parseDepositPreauth,
escrowCancellation: parseEscrowCancellation,
escrowCreation: parseEscrowCreation,
escrowExecution: parseEscrowExecution,
orderCancellation: parseOrderCancellation,
order: parseOrder,
payment: parsePayment,
paymentChannelClaim: parsePaymentChannelClaim,
paymentChannelCreate: parsePaymentChannelCreate,
paymentChannelFund: parsePaymentChannelFund,
trustline: parseTrustline,
amendment: parseAmendment, // pseudo-transaction
feeUpdate: parseFeeUpdate // pseudo-transaction
}
const parser: Function = mapping[type]
const specification = parser ? parser(tx) : {
UNAVAILABLE: 'Unrecognized transaction type.',
SEE_RAW_TRANSACTION: 'Since this type is unrecognized, `rawTransaction` is included in this response.'
}
const specification = parser
? parser(tx)
: {
UNAVAILABLE: 'Unrecognized transaction type.',
SEE_RAW_TRANSACTION:
'Since this type is unrecognized, `rawTransaction` is included in this response.'
}
if (!parser) {
includeRawTransaction = true
}

View File

@@ -24,7 +24,10 @@ function parseTrustline(tx: any): object {
qualityIn: parseQuality(tx.QualityIn),
qualityOut: parseQuality(tx.QualityOut),
ripplingDisabled: parseFlag(
tx.Flags, flags.SetNoRipple, flags.ClearNoRipple),
tx.Flags,
flags.SetNoRipple,
flags.ClearNoRipple
),
frozen: parseFlag(tx.Flags, flags.SetFreeze, flags.ClearFreeze),
authorized: parseFlag(tx.Flags, flags.SetAuth, 0)
})

View File

@@ -7,25 +7,28 @@ import parseAmount from './amount'
import {Amount, Memo} from '../../common/types/objects'
function adjustQualityForXRP(
quality: string, takerGetsCurrency: string, takerPaysCurrency: string
quality: string,
takerGetsCurrency: string,
takerPaysCurrency: string
) {
// quality = takerPays.value/takerGets.value
// using drops (1e-6 XRP) for XRP values
const numeratorShift = (takerPaysCurrency === 'XRP' ? -6 : 0)
const denominatorShift = (takerGetsCurrency === 'XRP' ? -6 : 0)
const numeratorShift = takerPaysCurrency === 'XRP' ? -6 : 0
const denominatorShift = takerGetsCurrency === 'XRP' ? -6 : 0
const shift = numeratorShift - denominatorShift
return shift === 0 ? quality :
(new BigNumber(quality)).shiftedBy(shift).toString()
return shift === 0
? quality
: new BigNumber(quality).shiftedBy(shift).toString()
}
function parseQuality(quality?: number|null): number|undefined {
function parseQuality(quality?: number | null): number | undefined {
if (typeof quality !== 'number') {
return undefined
}
return (new BigNumber(quality)).shiftedBy(-9).toNumber()
return new BigNumber(quality).shiftedBy(-9).toNumber()
}
function parseTimestamp(rippleTime?: number|null): string|undefined {
function parseTimestamp(rippleTime?: number | null): string | undefined {
if (typeof rippleTime !== 'number') {
return undefined
}
@@ -57,14 +60,14 @@ function isPartialPayment(tx: any) {
}
function parseDeliveredAmount(tx: any): Amount | void {
if (tx.TransactionType !== 'Payment' ||
tx.meta.TransactionResult !== 'tesSUCCESS') {
if (
tx.TransactionType !== 'Payment' ||
tx.meta.TransactionResult !== 'tesSUCCESS'
) {
return undefined
}
if (tx.meta.delivered_amount &&
tx.meta.delivered_amount === 'unavailable') {
if (tx.meta.delivered_amount && tx.meta.delivered_amount === 'unavailable') {
return undefined
}
@@ -96,7 +99,7 @@ function parseDeliveredAmount(tx: any): Amount | void {
return undefined
}
function parseOutcome(tx: any): any|undefined {
function parseOutcome(tx: any): any | undefined {
const metadata = tx.meta || tx.metaData
if (!metadata) {
return undefined
@@ -121,11 +124,11 @@ function parseOutcome(tx: any): any|undefined {
})
}
function hexToString(hex: string): string|undefined {
function hexToString(hex: string): string | undefined {
return hex ? Buffer.from(hex, 'hex').toString('utf-8') : undefined
}
function parseMemos(tx: any): Array<Memo>|undefined {
function parseMemos(tx: any): Array<Memo> | undefined {
if (!Array.isArray(tx.Memos) || tx.Memos.length === 0) {
return undefined
}

View File

@@ -1,18 +1,22 @@
import {Amount, RippledAmount, Adjustment, MaxAdjustment,
MinAdjustment} from '../common/types/objects'
import {
Amount,
RippledAmount,
Adjustment,
MaxAdjustment,
MinAdjustment
} from '../common/types/objects'
// Amount where counterparty and value are optional
export type LaxLaxAmount = {
currency: string,
value?: string,
issuer?: string,
currency: string
value?: string
issuer?: string
counterparty?: string
}
export type Path = {
source: Adjustment | MaxAdjustment,
destination: Adjustment | MinAdjustment,
source: Adjustment | MaxAdjustment
destination: Adjustment | MinAdjustment
paths: string
}
@@ -20,41 +24,43 @@ export type GetPaths = Array<Path>
export type PathFind = {
source: {
address: string,
amount?: Amount,
currencies?: Array<{currency: string, counterparty?:string}>
},
address: string
amount?: Amount
currencies?: Array<{currency: string; counterparty?: string}>
}
destination: {
address: string,
address: string
amount: LaxLaxAmount
}
}
export type PathFindRequest = {
command: string,
source_account: string,
destination_amount: RippledAmount,
destination_account: string,
source_currencies?: {currency: string, issuer?: string}[],
command: string
source_account: string
destination_amount: RippledAmount
destination_account: string
source_currencies?: {currency: string; issuer?: string}[]
send_max?: RippledAmount
}
export type RippledPathsResponse = {
alternatives: Array<{
paths_computed: Array<Array<{
type: number,
type_hex: string,
account?: string,
issuer?: string,
currency?: string
}>>,
paths_computed: Array<
Array<{
type: number
type_hex: string
account?: string
issuer?: string
currency?: string
}>
>
source_amount: RippledAmount
}>,
type: string,
destination_account: string,
destination_amount: RippledAmount,
destination_currencies?: Array<string>,
source_account: string,
source_currencies?: Array<{currency: string}>,
}>
type: string
destination_account: string
destination_amount: RippledAmount
destination_currencies?: Array<string>
source_account: string
source_currencies?: Array<{currency: string}>
full_reply?: boolean
}

View File

@@ -12,28 +12,37 @@ import {Connection} from '../common'
import parsePathfind from './parse/pathfind'
import {RippledAmount, Amount} from '../common/types/objects'
import {
GetPaths, PathFind, RippledPathsResponse, PathFindRequest
GetPaths,
PathFind,
RippledPathsResponse,
PathFindRequest
} from './pathfind-types'
import {RippleAPI} from '..'
const NotFoundError = errors.NotFoundError
const ValidationError = errors.ValidationError
function addParams(request: PathFindRequest, result: RippledPathsResponse
function addParams(
request: PathFindRequest,
result: RippledPathsResponse
): RippledPathsResponse {
return _.defaults(_.assign({}, result, {
source_account: request.source_account,
source_currencies: request.source_currencies
}), {destination_amount: request.destination_amount})
return _.defaults(
_.assign({}, result, {
source_account: request.source_account,
source_currencies: request.source_currencies
}),
{destination_amount: request.destination_amount}
)
}
function requestPathFind(connection: Connection, pathfind: PathFind
function requestPathFind(
connection: Connection,
pathfind: PathFind
): Promise<RippledPathsResponse> {
const destinationAmount: Amount = _.assign(
{
// This is converted back to drops by toRippledAmount()
value: pathfind.destination.amount.currency === 'XRP' ?
dropsToXrp('-1') : '-1'
value:
pathfind.destination.amount.currency === 'XRP' ? dropsToXrp('-1') : '-1'
},
pathfind.destination.amount
)
@@ -43,21 +52,26 @@ function requestPathFind(connection: Connection, pathfind: PathFind
destination_account: pathfind.destination.address,
destination_amount: toRippledAmount(destinationAmount)
}
if (typeof request.destination_amount === 'object'
&& !request.destination_amount.issuer) {
if (
typeof request.destination_amount === 'object' &&
!request.destination_amount.issuer
) {
// Convert blank issuer to sender's address
// (Ripple convention for 'any issuer')
// https://developers.ripple.com/payment.html#special-issuer-values-for-sendmax-and-amount
request.destination_amount.issuer = request.destination_account
}
if (pathfind.source.currencies && pathfind.source.currencies.length > 0) {
request.source_currencies = pathfind.source.currencies.map(
amount => renameCounterpartyToIssuer(amount))
request.source_currencies = pathfind.source.currencies.map(amount =>
renameCounterpartyToIssuer(amount)
)
}
if (pathfind.source.amount) {
if (pathfind.destination.amount.value !== undefined) {
throw new ValidationError('Cannot specify both source.amount'
+ ' and destination.amount.value in getPaths')
throw new ValidationError(
'Cannot specify both source.amount' +
' and destination.amount.value in getPaths'
)
}
request.send_max = toRippledAmount(pathfind.source.amount)
if (typeof request.send_max !== 'string' && !request.send_max.issuer) {
@@ -68,12 +82,14 @@ function requestPathFind(connection: Connection, pathfind: PathFind
return connection.request(request).then(paths => addParams(request, paths))
}
function addDirectXrpPath(paths: RippledPathsResponse, xrpBalance: string
function addDirectXrpPath(
paths: RippledPathsResponse,
xrpBalance: string
): RippledPathsResponse {
// Add XRP "path" only if the source acct has enough XRP to make the payment
const destinationAmount = paths.destination_amount
// @ts-ignore: destinationAmount can be a currency amount object! Fix!
if ((new BigNumber(xrpBalance)).isGreaterThanOrEqualTo(destinationAmount)) {
if (new BigNumber(xrpBalance).isGreaterThanOrEqualTo(destinationAmount)) {
paths.alternatives.unshift({
paths_computed: [],
source_amount: paths.destination_amount
@@ -84,38 +100,49 @@ function addDirectXrpPath(paths: RippledPathsResponse, xrpBalance: string
function isRippledIOUAmount(amount: RippledAmount) {
// rippled XRP amounts are specified as decimal strings
return (typeof amount === 'object') &&
amount.currency && (amount.currency !== 'XRP')
return (
typeof amount === 'object' && amount.currency && amount.currency !== 'XRP'
)
}
function conditionallyAddDirectXRPPath(connection: Connection, address: string,
function conditionallyAddDirectXRPPath(
connection: Connection,
address: string,
paths: RippledPathsResponse
): Promise<RippledPathsResponse> {
if (isRippledIOUAmount(paths.destination_amount)
|| !_.includes(paths.destination_currencies, 'XRP')) {
if (
isRippledIOUAmount(paths.destination_amount) ||
!_.includes(paths.destination_currencies, 'XRP')
) {
return Promise.resolve(paths)
}
return getXRPBalance(connection, address, undefined).then(
xrpBalance => addDirectXrpPath(paths, xrpBalance))
return getXRPBalance(connection, address, undefined).then(xrpBalance =>
addDirectXrpPath(paths, xrpBalance)
)
}
function filterSourceFundsLowPaths(pathfind: PathFind,
function filterSourceFundsLowPaths(
pathfind: PathFind,
paths: RippledPathsResponse
): RippledPathsResponse {
if (pathfind.source.amount &&
pathfind.destination.amount.value === undefined && paths.alternatives) {
if (
pathfind.source.amount &&
pathfind.destination.amount.value === undefined &&
paths.alternatives
) {
paths.alternatives = _.filter(paths.alternatives, alt => {
if (!alt.source_amount) {
return false
}
const pathfindSourceAmountValue = new BigNumber(
pathfind.source.amount.currency === 'XRP' ?
xrpToDrops(pathfind.source.amount.value) :
pathfind.source.amount.value)
pathfind.source.amount.currency === 'XRP'
? xrpToDrops(pathfind.source.amount.value)
: pathfind.source.amount.value
)
const altSourceAmountValue = new BigNumber(
typeof alt.source_amount === 'string' ?
alt.source_amount :
alt.source_amount.value
typeof alt.source_amount === 'string'
? alt.source_amount
: alt.source_amount.value
)
return altSourceAmountValue.eq(pathfindSourceAmountValue)
})
@@ -127,24 +154,35 @@ function formatResponse(pathfind: PathFind, paths: RippledPathsResponse) {
if (paths.alternatives && paths.alternatives.length > 0) {
return parsePathfind(paths)
}
if (paths.destination_currencies !== undefined &&
!_.includes(paths.destination_currencies,
pathfind.destination.amount.currency)) {
throw new NotFoundError('No paths found. ' +
'The destination_account does not accept ' +
pathfind.destination.amount.currency + ', they only accept: ' +
paths.destination_currencies.join(', '))
if (
paths.destination_currencies !== undefined &&
!_.includes(
paths.destination_currencies,
pathfind.destination.amount.currency
)
) {
throw new NotFoundError(
'No paths found. ' +
'The destination_account does not accept ' +
pathfind.destination.amount.currency +
', they only accept: ' +
paths.destination_currencies.join(', ')
)
} else if (paths.source_currencies && paths.source_currencies.length > 0) {
throw new NotFoundError('No paths found. Please ensure' +
' that the source_account has sufficient funds to execute' +
' the payment in one of the specified source_currencies. If it does' +
' there may be insufficient liquidity in the network to execute' +
' this payment right now')
throw new NotFoundError(
'No paths found. Please ensure' +
' that the source_account has sufficient funds to execute' +
' the payment in one of the specified source_currencies. If it does' +
' there may be insufficient liquidity in the network to execute' +
' this payment right now'
)
} else {
throw new NotFoundError('No paths found.' +
' Please ensure that the source_account has sufficient funds to' +
' execute the payment. If it does there may be insufficient liquidity' +
' in the network to execute this payment right now')
throw new NotFoundError(
'No paths found.' +
' Please ensure that the source_account has sufficient funds to' +
' execute the payment. If it does there may be insufficient liquidity' +
' in the network to execute this payment right now'
)
}
}
@@ -152,9 +190,10 @@ function getPaths(this: RippleAPI, pathfind: PathFind): Promise<GetPaths> {
validate.getPaths({pathfind})
const address = pathfind.source.address
return requestPathFind(this.connection, pathfind).then(paths =>
conditionallyAddDirectXRPPath(this.connection, address, paths)
)
return requestPathFind(this.connection, pathfind)
.then(paths =>
conditionallyAddDirectXRPPath(this.connection, address, paths)
)
.then(paths => filterSourceFundsLowPaths(pathfind, paths))
.then(paths => formatResponse(pathfind, paths))
}

View File

@@ -10,15 +10,18 @@ const NotFoundError = errors.NotFoundError
function formatResponse(
response: LedgerEntryResponse
): FormattedPaymentChannel {
if (response.node === undefined ||
response.node.LedgerEntryType !== 'PayChannel') {
if (
response.node === undefined ||
response.node.LedgerEntryType !== 'PayChannel'
) {
throw new NotFoundError('Payment channel ledger entry not found')
}
return parsePaymentChannel(response.node)
}
async function getPaymentChannel(
this: RippleAPI, id: string
this: RippleAPI,
id: string
): Promise<FormattedPaymentChannel> {
// 1. Validate
validate.getPaymentChannel({id})

View File

@@ -12,8 +12,9 @@ export type SettingsOptions = {
}
export function parseAccountFlags(
value: number,
options: {excludeFalse?: boolean} = {}) {
value: number,
options: {excludeFalse?: boolean} = {}
) {
const settings = {}
for (const flagName in AccountFlags) {
if (value & AccountFlags[flagName]) {
@@ -35,7 +36,9 @@ function formatSettings(response: AccountInfoResponse) {
}
export async function getSettings(
this: RippleAPI, address: string, options: SettingsOptions = {}
this: RippleAPI,
address: string,
options: SettingsOptions = {}
): Promise<FormattedSettings> {
// 1. Validate
validate.getSettings({address, options})

View File

@@ -8,19 +8,20 @@ import {RippledError} from '../common/errors'
import {RippleAPI} from '..'
export type TransactionOptions = {
minLedgerVersion?: number,
maxLedgerVersion?: number,
minLedgerVersion?: number
maxLedgerVersion?: number
includeRawTransaction?: boolean
}
type TransactionResponse = FormattedTransactionType & {
hash: string,
ledger_index: number,
meta: any,
validated?: boolean
hash: string
ledger_index: number
meta: any
validated?: boolean
}
function attachTransactionDate(connection: Connection, tx: any
function attachTransactionDate(
connection: Connection,
tx: any
): Promise<TransactionResponse> {
if (tx.date) {
return Promise.resolve(tx)
@@ -31,7 +32,8 @@ function attachTransactionDate(connection: Connection, tx: any
if (!ledgerVersion) {
return new Promise(() => {
const error = new errors.NotFoundError(
'Transaction has not been validated yet; try again later')
'Transaction has not been validated yet; try again later'
)
error.data = {
details: '(ledger_index and LedgerSequence not found in tx)'
}
@@ -44,56 +46,74 @@ function attachTransactionDate(connection: Connection, tx: any
ledger_index: ledgerVersion
}
return connection.request(request).then(data => {
if (typeof data.ledger.close_time === 'number') {
return _.assign({date: data.ledger.close_time}, tx)
}
throw new errors.UnexpectedError('Ledger missing close_time')
}).catch(error => {
if (error instanceof errors.UnexpectedError) {
throw error
}
throw new errors.NotFoundError('Transaction ledger not found')
})
return connection
.request(request)
.then(data => {
if (typeof data.ledger.close_time === 'number') {
return _.assign({date: data.ledger.close_time}, tx)
}
throw new errors.UnexpectedError('Ledger missing close_time')
})
.catch(error => {
if (error instanceof errors.UnexpectedError) {
throw error
}
throw new errors.NotFoundError('Transaction ledger not found')
})
}
function isTransactionInRange(tx: any, options: TransactionOptions) {
return (!options.minLedgerVersion
|| tx.ledger_index >= options.minLedgerVersion)
&& (!options.maxLedgerVersion
|| tx.ledger_index <= options.maxLedgerVersion)
return (
(!options.minLedgerVersion ||
tx.ledger_index >= options.minLedgerVersion) &&
(!options.maxLedgerVersion || tx.ledger_index <= options.maxLedgerVersion)
)
}
function convertError(connection: Connection, options: TransactionOptions,
function convertError(
connection: Connection,
options: TransactionOptions,
error: RippledError
): Promise<Error> {
let shouldUseNotFoundError = false
if ((error.data && error.data.error === 'txnNotFound') || error.message === 'txnNotFound') {
if (
(error.data && error.data.error === 'txnNotFound') ||
error.message === 'txnNotFound'
) {
shouldUseNotFoundError = true
}
// In the future, we should deprecate this error, instead passing through the one from rippled.
const _error = shouldUseNotFoundError ? new errors.NotFoundError('Transaction not found') : error
const _error = shouldUseNotFoundError
? new errors.NotFoundError('Transaction not found')
: error
if (_error instanceof errors.NotFoundError) {
return utils.hasCompleteLedgerRange(connection, options.minLedgerVersion,
options.maxLedgerVersion).then(hasCompleteLedgerRange => {
if (!hasCompleteLedgerRange) {
return utils.isPendingLedgerVersion(
connection, options.maxLedgerVersion)
.then(isPendingLedgerVersion => {
return isPendingLedgerVersion ?
new errors.PendingLedgerVersionError() :
new errors.MissingLedgerHistoryError()
})
}
return _error
})
return utils
.hasCompleteLedgerRange(
connection,
options.minLedgerVersion,
options.maxLedgerVersion
)
.then(hasCompleteLedgerRange => {
if (!hasCompleteLedgerRange) {
return utils
.isPendingLedgerVersion(connection, options.maxLedgerVersion)
.then(isPendingLedgerVersion => {
return isPendingLedgerVersion
? new errors.PendingLedgerVersionError()
: new errors.MissingLedgerHistoryError()
})
}
return _error
})
}
return Promise.resolve(_error)
}
function formatResponse(options: TransactionOptions, tx: TransactionResponse
function formatResponse(
options: TransactionOptions,
tx: TransactionResponse
): FormattedTransactionType {
if (tx.validated !== true || !isTransactionInRange(tx, options)) {
throw new errors.NotFoundError('Transaction not found')
@@ -101,7 +121,10 @@ function formatResponse(options: TransactionOptions, tx: TransactionResponse
return parseTransaction(tx, options.includeRawTransaction)
}
async function getTransaction(this: RippleAPI, id: string, options: TransactionOptions = {}
async function getTransaction(
this: RippleAPI,
id: string,
options: TransactionOptions = {}
): Promise<FormattedTransactionType> {
validate.getTransaction({id, options})
const _options = await utils.ensureLedgerVersion.call(this, options)
@@ -113,7 +136,7 @@ async function getTransaction(this: RippleAPI, id: string, options: TransactionO
const txWithDate = await attachTransactionDate(this.connection, tx)
return formatResponse(_options, txWithDate)
} catch (error) {
throw (await convertError(this.connection, _options, error))
throw await convertError(this.connection, _options, error)
}
}

View File

@@ -1,5 +1,5 @@
import * as _ from 'lodash'
import binary from 'ripple-binary-codec';
import binary from 'ripple-binary-codec'
import {computeTransactionHash} from '../common/hashes'
import * as utils from './utils'
import parseTransaction from './parse/transaction'
@@ -9,17 +9,17 @@ import {FormattedTransactionType} from '../transaction/types'
import {RippleAPI} from '..'
export type TransactionsOptions = {
start?: string,
limit?: number,
minLedgerVersion?: number,
maxLedgerVersion?: number,
earliestFirst?: boolean,
excludeFailures?: boolean,
initiated?: boolean,
counterparty?: string,
types?: Array<string>,
includeRawTransactions?: boolean,
binary?: boolean,
start?: string
limit?: number
minLedgerVersion?: number
maxLedgerVersion?: number
earliestFirst?: boolean
excludeFailures?: boolean
initiated?: boolean
counterparty?: string
types?: Array<string>
includeRawTransactions?: boolean
binary?: boolean
startTx?: FormattedTransactionType
}
@@ -39,8 +39,10 @@ function parseBinaryTransaction(transaction) {
function parseAccountTxTransaction(tx, includeRawTransaction: boolean) {
const _tx = tx.tx_blob ? parseBinaryTransaction(tx) : tx
// rippled uses a different response format for 'account_tx' than 'tx'
return parseTransaction(_.assign({}, _tx.tx,
{meta: _tx.meta, validated: _tx.validated}), includeRawTransaction)
return parseTransaction(
_.assign({}, _tx.tx, {meta: _tx.meta, validated: _tx.validated}),
includeRawTransaction
)
}
function counterpartyFilter(filters, tx: FormattedTransactionType) {
@@ -48,15 +50,20 @@ function counterpartyFilter(filters, tx: FormattedTransactionType) {
return true
}
const specification: any = tx.specification
if (specification && ((specification.destination &&
specification.destination.address === filters.counterparty) ||
(specification.counterparty === filters.counterparty))) {
return true
if (
specification &&
((specification.destination &&
specification.destination.address === filters.counterparty) ||
specification.counterparty === filters.counterparty)
) {
return true
}
return false
}
function transactionFilter(address: string, filters: TransactionsOptions,
function transactionFilter(
address: string,
filters: TransactionsOptions,
tx: FormattedTransactionType
) {
if (filters.excludeFailures && tx.outcome.result !== 'tesSUCCESS') {
@@ -78,15 +85,21 @@ function transactionFilter(address: string, filters: TransactionsOptions,
}
function orderFilter(
options: TransactionsOptions, tx: FormattedTransactionType
options: TransactionsOptions,
tx: FormattedTransactionType
) {
return !options.startTx || (options.earliestFirst ?
utils.compareTransactions(tx, options.startTx) > 0 :
utils.compareTransactions(tx, options.startTx) < 0)
return (
!options.startTx ||
(options.earliestFirst
? utils.compareTransactions(tx, options.startTx) > 0
: utils.compareTransactions(tx, options.startTx) < 0)
)
}
function formatPartialResponse(address: string,
options: TransactionsOptions, data
function formatPartialResponse(
address: string,
options: TransactionsOptions,
data
) {
const parse = tx =>
parseAccountTxTransaction(tx, options.includeRawTransactions)
@@ -100,8 +113,12 @@ function formatPartialResponse(address: string,
}
}
function getAccountTx(connection: Connection, address: string,
options: TransactionsOptions, marker: string, limit: number
function getAccountTx(
connection: Connection,
address: string,
options: TransactionsOptions,
marker: string,
limit: number
) {
const request = {
command: 'account_tx',
@@ -116,12 +133,15 @@ function getAccountTx(connection: Connection, address: string,
marker: marker
}
return connection.request(request).then(response =>
formatPartialResponse(address, options, response))
return connection
.request(request)
.then(response => formatPartialResponse(address, options, response))
}
function checkForLedgerGaps(connection: Connection,
options: TransactionsOptions, transactions: GetTransactionsResponse
function checkForLedgerGaps(
connection: Connection,
options: TransactionsOptions,
transactions: GetTransactionsResponse
) {
let {minLedgerVersion, maxLedgerVersion} = options
@@ -136,25 +156,32 @@ function checkForLedgerGaps(connection: Connection,
}
}
return utils.hasCompleteLedgerRange(connection, minLedgerVersion,
maxLedgerVersion).then(hasCompleteLedgerRange => {
if (!hasCompleteLedgerRange) {
throw new errors.MissingLedgerHistoryError()
}
})
return utils
.hasCompleteLedgerRange(connection, minLedgerVersion, maxLedgerVersion)
.then(hasCompleteLedgerRange => {
if (!hasCompleteLedgerRange) {
throw new errors.MissingLedgerHistoryError()
}
})
}
function formatResponse(connection: Connection, options: TransactionsOptions,
function formatResponse(
connection: Connection,
options: TransactionsOptions,
transactions: GetTransactionsResponse
) {
const compare = options.earliestFirst ? utils.compareTransactions :
_.rearg(utils.compareTransactions, 1, 0)
const compare = options.earliestFirst
? utils.compareTransactions
: _.rearg(utils.compareTransactions, 1, 0)
const sortedTransactions = transactions.sort(compare)
return checkForLedgerGaps(connection, options, sortedTransactions).then(
() => sortedTransactions)
() => sortedTransactions
)
}
function getTransactionsInternal(connection: Connection, address: string,
function getTransactionsInternal(
connection: Connection,
address: string,
options: TransactionsOptions
): Promise<GetTransactionsResponse> {
const getter = _.partial(getAccountTx, connection, address, options)
@@ -162,7 +189,10 @@ function getTransactionsInternal(connection: Connection, address: string,
return utils.getRecursive(getter, options.limit).then(format)
}
function getTransactions(this: RippleAPI, address: string, options: TransactionsOptions = {}
function getTransactions(
this: RippleAPI,
address: string,
options: TransactionsOptions = {}
): Promise<GetTransactionsResponse> {
validate.getTransactions({address, options})
@@ -176,8 +206,9 @@ function getTransactions(this: RippleAPI, address: string, options: Transactions
if (options.start) {
return getTransaction.call(this, options.start).then(tx => {
const ledgerVersion = tx.outcome.ledgerVersion
const bound = options.earliestFirst ?
{minLedgerVersion: ledgerVersion} : {maxLedgerVersion: ledgerVersion}
const bound = options.earliestFirst
? {minLedgerVersion: ledgerVersion}
: {maxLedgerVersion: ledgerVersion}
const startOptions = _.assign({}, defaults, options, {startTx: tx}, bound)
return getTransactionsInternal(this.connection, address, startOptions)
})

View File

@@ -5,9 +5,9 @@ import {RippleAPI} from '..'
import {FormattedTrustline} from '../common/types/objects/trustlines'
export type GetTrustlinesOptions = {
counterparty?: string,
currency?: string,
limit?: number,
counterparty?: string
currency?: string
limit?: number
ledgerVersion?: number
}
@@ -16,7 +16,9 @@ function currencyFilter(currency: string, trustline: FormattedTrustline) {
}
async function getTrustlines(
this: RippleAPI, address: string, options: GetTrustlinesOptions = {}
this: RippleAPI,
address: string,
options: GetTrustlinesOptions = {}
): Promise<FormattedTrustline[]> {
// 1. Validate
validate.getTrustlines({address, options})

View File

@@ -4,10 +4,10 @@ import * as common from '../common'
import {Connection} from '../common'
import {FormattedTransactionType} from '../transaction/types'
import {Issue} from '../common/types/objects'
import {RippleAPI} from '..'
import {RippleAPI} from '..'
export type RecursiveData = {
marker: string,
marker: string
results: Array<any>
}
@@ -18,7 +18,9 @@ function clamp(value: number, min: number, max: number): number {
return Math.min(Math.max(value, min), max)
}
function getXRPBalance(connection: Connection, address: string,
function getXRPBalance(
connection: Connection,
address: string,
ledgerVersion?: number
): Promise<string> {
const request = {
@@ -26,13 +28,16 @@ function getXRPBalance(connection: Connection, address: string,
account: address,
ledger_index: ledgerVersion
}
return connection.request(request).then(data =>
common.dropsToXrp(data.account_data.Balance))
return connection
.request(request)
.then(data => common.dropsToXrp(data.account_data.Balance))
}
// If the marker is omitted from a response, you have reached the end
function getRecursiveRecur(
getter: Getter, marker: string | undefined, limit: number
getter: Getter,
marker: string | undefined,
limit: number
): Promise<Array<any>> {
return getter(marker, limit).then(data => {
const remaining = limit - data.results.length
@@ -50,17 +55,20 @@ function getRecursive(getter: Getter, limit?: number): Promise<Array<any>> {
}
function renameCounterpartyToIssuer<T>(
obj: T & {counterparty?: string, issuer?: string}
): (T & {issuer?: string}) {
const issuer = (obj.counterparty !== undefined) ?
obj.counterparty :
((obj.issuer !== undefined) ? obj.issuer : undefined)
obj: T & {counterparty?: string; issuer?: string}
): T & {issuer?: string} {
const issuer =
obj.counterparty !== undefined
? obj.counterparty
: obj.issuer !== undefined
? obj.issuer
: undefined
const withIssuer = Object.assign({}, obj, {issuer})
delete withIssuer.counterparty
return withIssuer
}
export type RequestBookOffersArgs = {taker_gets: Issue, taker_pays: Issue}
export type RequestBookOffersArgs = {taker_gets: Issue; taker_pays: Issue}
function renameCounterpartyToIssuerInOrder(order: RequestBookOffersArgs) {
const taker_gets = renameCounterpartyToIssuer(order.taker_gets)
@@ -70,7 +78,7 @@ function renameCounterpartyToIssuerInOrder(order: RequestBookOffersArgs) {
}
function signum(num) {
return (num === 0) ? 0 : (num > 0 ? 1 : -1)
return num === 0 ? 0 : num > 0 ? 1 : -1
}
/**
@@ -80,7 +88,8 @@ function signum(num) {
* See: https://developers.ripple.com/transaction-metadata.html
*/
function compareTransactions(
first: FormattedTransactionType, second: FormattedTransactionType
first: FormattedTransactionType,
second: FormattedTransactionType
): number {
if (!first.outcome || !second.outcome) {
return 0
@@ -91,30 +100,38 @@ function compareTransactions(
return first.outcome.ledgerVersion < second.outcome.ledgerVersion ? -1 : 1
}
function hasCompleteLedgerRange(connection: Connection,
minLedgerVersion?: number, maxLedgerVersion?: number
function hasCompleteLedgerRange(
connection: Connection,
minLedgerVersion?: number,
maxLedgerVersion?: number
): Promise<boolean> {
const firstLedgerVersion = 32570 // earlier versions have been lost
return connection.hasLedgerVersions(
minLedgerVersion || firstLedgerVersion, maxLedgerVersion)
minLedgerVersion || firstLedgerVersion,
maxLedgerVersion
)
}
function isPendingLedgerVersion(connection: Connection,
function isPendingLedgerVersion(
connection: Connection,
maxLedgerVersion?: number
): Promise<boolean> {
return connection.getLedgerVersion().then(ledgerVersion =>
ledgerVersion < (maxLedgerVersion || 0))
return connection
.getLedgerVersion()
.then(ledgerVersion => ledgerVersion < (maxLedgerVersion || 0))
}
function ensureLedgerVersion(this: RippleAPI, options: any
): Promise<object> {
if (Boolean(options) && options.ledgerVersion !== undefined &&
function ensureLedgerVersion(this: RippleAPI, options: any): Promise<object> {
if (
Boolean(options) &&
options.ledgerVersion !== undefined &&
options.ledgerVersion !== null
) {
return Promise.resolve(options)
}
return this.getLedgerVersion().then(ledgerVersion =>
_.assign({}, options, {ledgerVersion}))
_.assign({}, options, {ledgerVersion})
)
}
export {

View File

@@ -1,13 +1,13 @@
import {deriveKeypair, deriveAddress} from 'ripple-keypairs'
import {classicAddressToXAddress} from 'ripple-address-codec'
function deriveXAddress(options: {publicKey: string, tag: number | false, test: boolean}): string {
function deriveXAddress(options: {
publicKey: string
tag: number | false
test: boolean
}): string {
const classicAddress = deriveAddress(options.publicKey)
return classicAddressToXAddress(classicAddress, options.tag, options.test)
}
export {
deriveKeypair,
deriveAddress,
deriveXAddress
}
export {deriveKeypair, deriveAddress, deriveXAddress}

View File

@@ -3,23 +3,23 @@ import keypairs from 'ripple-keypairs'
import {errors, validate} from '../common'
export type GeneratedAddress = {
xAddress: string,
classicAddress?: string,
address?: string, // @deprecated Use `classicAddress` instead.
xAddress: string
classicAddress?: string
address?: string // @deprecated Use `classicAddress` instead.
secret: string
}
export interface GenerateAddressOptions {
// The entropy to use to generate the seed.
entropy?: Uint8Array | number[],
entropy?: Uint8Array | number[]
// The digital signature algorithm to generate an address for. Can be `ecdsa-secp256k1` (default) or `ed25519`.
algorithm?: 'ecdsa-secp256k1' | 'ed25519',
algorithm?: 'ecdsa-secp256k1' | 'ed25519'
// Specifies whether the address is intended for use on a test network such as Testnet or Devnet.
// If `true`, the address should only be used for testing, and will start with `T`.
// If `false` (default), the address should only be used on mainnet, and will start with `X`.
test?: boolean,
test?: boolean
// If `true`, return the classic address, in addition to the X-address.
includeClassicAddress?: boolean
@@ -32,7 +32,11 @@ function generateAddressAPI(options: GenerateAddressOptions): GeneratedAddress {
const keypair = keypairs.deriveKeypair(secret)
const classicAddress = keypairs.deriveAddress(keypair.publicKey)
const returnValue: any = {
xAddress: classicAddressToXAddress(classicAddress, false, options && options.test),
xAddress: classicAddressToXAddress(
classicAddress,
false,
options && options.test
),
secret
}
if (options.includeClassicAddress) {
@@ -45,6 +49,4 @@ function generateAddressAPI(options: GenerateAddressOptions): GeneratedAddress {
}
}
export {
generateAddressAPI
}
export {generateAddressAPI}

View File

@@ -1,5 +1,9 @@
import * as _ from 'lodash'
import {computeLedgerHash, computeTransactionTreeHash, computeStateTreeHash} from '../common/hashes'
import {
computeLedgerHash,
computeTransactionTreeHash,
computeStateTreeHash
} from '../common/hashes'
import * as common from '../common'
function convertLedgerHeader(header): any {
@@ -25,63 +29,79 @@ function hashLedgerHeader(ledgerHeader) {
return computeLedgerHash(header)
}
function computeTransactionHash(ledger,
options: ComputeLedgerHeaderHashOptions) {
function computeTransactionHash(
ledger,
options: ComputeLedgerHeaderHashOptions
) {
let transactions: any[]
if (ledger.rawTransactions) {
transactions = JSON.parse(ledger.rawTransactions)
} else if (ledger.transactions) {
try {
transactions = ledger.transactions.map(tx =>
JSON.parse(tx.rawTransaction))
JSON.parse(tx.rawTransaction)
)
} catch (e) {
if (e.toString() === 'SyntaxError: Unexpected' +
' token u in JSON at position 0') {
if (
e.toString() ===
'SyntaxError: Unexpected' + ' token u in JSON at position 0'
) {
// one or more of the `tx.rawTransaction`s is undefined
throw new common.errors.ValidationError('ledger'
+ ' is missing raw transactions')
throw new common.errors.ValidationError(
'ledger' + ' is missing raw transactions'
)
}
}
} else {
if (options.computeTreeHashes) {
throw new common.errors.ValidationError('transactions'
+ ' property is missing from the ledger')
throw new common.errors.ValidationError(
'transactions' + ' property is missing from the ledger'
)
}
return ledger.transactionHash
}
const txs = _.map(transactions, tx => {
const mergeTx = _.assign({}, _.omit(tx, 'tx'), tx.tx || {})
// rename `meta` back to `metaData`
const renameMeta = _.assign({}, _.omit(mergeTx, 'meta'),
tx.meta ? {metaData: tx.meta} : {})
const renameMeta = _.assign(
{},
_.omit(mergeTx, 'meta'),
tx.meta ? {metaData: tx.meta} : {}
)
return renameMeta
})
const transactionHash = computeTransactionTreeHash(txs)
if (ledger.transactionHash !== undefined
&& ledger.transactionHash !== transactionHash) {
throw new common.errors.ValidationError('transactionHash in header'
+ ' does not match computed hash of transactions', {
if (
ledger.transactionHash !== undefined &&
ledger.transactionHash !== transactionHash
) {
throw new common.errors.ValidationError(
'transactionHash in header' +
' does not match computed hash of transactions',
{
transactionHashInHeader: ledger.transactionHash,
computedHashOfTransactions: transactionHash
})
}
)
}
return transactionHash
}
function computeStateHash(ledger,
options: ComputeLedgerHeaderHashOptions) {
function computeStateHash(ledger, options: ComputeLedgerHeaderHashOptions) {
if (ledger.rawState === undefined) {
if (options.computeTreeHashes) {
throw new common.errors.ValidationError('rawState'
+ ' property is missing from the ledger')
throw new common.errors.ValidationError(
'rawState' + ' property is missing from the ledger'
)
}
return ledger.stateHash
}
const state = JSON.parse(ledger.rawState)
const stateHash = computeStateTreeHash(state)
if (ledger.stateHash !== undefined && ledger.stateHash !== stateHash) {
throw new common.errors.ValidationError('stateHash in header'
+ ' does not match computed hash of state')
throw new common.errors.ValidationError(
'stateHash in header' + ' does not match computed hash of state'
)
}
return stateHash
}
@@ -90,8 +110,10 @@ export type ComputeLedgerHeaderHashOptions = {
computeTreeHashes?: boolean
}
function computeLedgerHeaderHash(ledger: any,
options: ComputeLedgerHeaderHashOptions = {}): string {
function computeLedgerHeaderHash(
ledger: any,
options: ComputeLedgerHeaderHashOptions = {}
): string {
const subhashes = {
transactionHash: computeTransactionHash(ledger, options),
stateHash: computeStateHash(ledger, options)

View File

@@ -3,7 +3,9 @@ import keypairs from 'ripple-keypairs'
import binary from 'ripple-binary-codec'
const {validate, xrpToDrops} = common
function signPaymentChannelClaim(channel: string, amount: string,
function signPaymentChannelClaim(
channel: string,
amount: string,
privateKey: string
): string {
validate.signPaymentChannelClaim({channel, amount, privateKey})

View File

@@ -2,8 +2,11 @@ import keypairs from 'ripple-keypairs'
import binary from 'ripple-binary-codec'
import {validate, xrpToDrops} from '../common'
function verifyPaymentChannelClaim(channel: string, amount: string,
signature: string, publicKey: string
function verifyPaymentChannelClaim(
channel: string,
amount: string,
signature: string,
publicKey: string
): string {
validate.verifyPaymentChannelClaim({channel, amount, signature, publicKey})

View File

@@ -9,12 +9,14 @@ function getLedgerVersion(this: RippleAPI): Promise<number> {
return this.connection.getLedgerVersion()
}
function connect(this: RippleAPI): Promise<void> {
async function connect(this: RippleAPI): Promise<void> {
return this.connection.connect()
}
function disconnect(this: RippleAPI): Promise<void> {
return this.connection.disconnect()
async function disconnect(this: RippleAPI): Promise<void> {
// backwards compatibility: connection.disconnect() can return a number, but
// this method returns nothing. SO we await but don't return any result.
await this.connection.disconnect()
}
function formatLedgerClose(ledgerClose: any): object {
@@ -30,10 +32,4 @@ function formatLedgerClose(ledgerClose: any): object {
}
}
export {
connect,
disconnect,
isConnected,
getLedgerVersion,
formatLedgerClose
}
export {connect, disconnect, isConnected, getLedgerVersion, formatLedgerClose}

Some files were not shown because too many files have changed in this diff Show More