Compare commits

...

187 Commits

Author SHA1 Message Date
Geert Weening
12e428733a [TASK] bump version to 0.9.4 2014-12-05 15:48:24 -08:00
Geert Weening
9cc6ad09a9 [DOC] update release notes 2014-12-05 15:47:46 -08:00
Geert Weening
84abb5962e [TASK] bump ripple-lib to 0.9.4-rc2 2014-12-04 12:56:17 -08:00
Geert Weening
4bba55d2dc Revert "[FEATURE] improve memo support"
This reverts commit 89adcf4f4e.
2014-12-04 12:54:48 -08:00
Geert Weening
b4cabad44e [TASK] bump version to 0.9.4-rc1 2014-12-04 11:03:01 -08:00
Geert Weening
28cc0f9e3b [DOC] update release notes 2014-12-04 11:02:20 -08:00
wltsmrz
95a2cc18fe Merge pull request #213 from geertweening/feature/memo_format_type
[FEATURE] improve memo support
2014-12-02 00:00:10 -08:00
Geert Weening
8e315a9859 [DOC] update generate wallet example
to take advantage of randomness collected from a rippled
2014-12-01 17:54:34 -08:00
Geert Weening
89adcf4f4e [FEATURE] improve memo support
- add MemoFormat property for memo
- MemoFormat and MemoType must be valid ASCII
- Memo content is converted on the serialization level
- add parsed_* version of Memo content if the parser understand the format
- support `text` and `json` MemoFormat
2014-12-01 09:48:56 -08:00
Geert Weening
3a6c5e41c9 Merge pull request #217 from ripple/orderbook-cleanup
Cleanup, normalize offers from book_offers and transaction stream
2014-11-30 14:14:01 -08:00
wltsmrz
86ed24b94c Cleanup, normalize offers from book_offers and transaction stream 2014-11-29 15:24:15 -08:00
wltsmrz
c792c471c3 Merge pull request #215 from ripple/fix-precision-rounding
Fix to_human precision rounding
2014-11-26 18:31:29 -08:00
wltsmrz
e371cc2c3c Fix to_human precision rounding 2014-11-26 11:32:15 -08:00
Geert Weening
ccf218c8f0 Merge pull request #214 from ripple/fix-fractional-drops
Fix fractional drops in funded taker_pays setter
2014-11-26 09:16:55 -08:00
wltsmrz
0d7fc0a573 Fix fractional drops in funded taker_pays setter 2014-11-25 21:10:57 -08:00
Geert Weening
74cacd5209 [DOC] update offer example 2014-11-19 18:04:45 -08:00
Geert Weening
bb79cf2a87 [TASK] bump version to 0.9.3 2014-11-19 12:09:18 -08:00
Geert Weening
28451df1a8 Merge branch 'develop' into release 2014-11-19 11:32:19 -08:00
Geert Weening
38e288f62a [TASK] bump version to 0.9.2-rc3 2014-11-19 11:31:19 -08:00
Geert Weening
905f908450 [DOC] update release notes 2014-11-19 11:31:19 -08:00
wltsmrz
672171fd0c Merge pull request #211 from jks-liu/fix-link
Fix link in README
2014-11-19 05:24:58 -08:00
Jks Liu
520660ecbc Fix link in README 2014-11-19 16:42:25 +08:00
Geert Weening
06acb5faf2 [TASK] bump version to 0.9.2-rc3 2014-11-18 11:58:41 -08:00
Geert Weening
d43fa03f05 [DOC] update release notes 2014-11-18 11:57:49 -08:00
Geert Weening
baed1aaf92 Merge branch 'release' into develop 2014-11-18 11:54:17 -08:00
wltsmrz
cc229e803c Merge pull request #210 from geertweening/fix/max_fee
[TASK] change default `max_fee` for Remote to 1 XRP
2014-11-18 11:48:37 -08:00
Geert Weening
d6b1728c23 [TASK] change default max_fee for Remote to 1 XRP 2014-11-18 10:47:28 -08:00
wltsmrz
bc5dcc359c Merge pull request #209 from ximinez/ledger_accept
Request ledger_accept returns the Request, not Remote
2014-11-17 12:08:38 -08:00
Edward Hennis
ced07e1d6b Request ledger_accept returns the Request, not Remote 2014-11-17 15:02:45 -05:00
Geert Weening
cffffd9591 [TASK] bump version to 0.9.3-rc2 2014-11-14 10:24:44 -08:00
Geert Weening
b8766e263f [DOC] update release notes 2014-11-14 10:24:00 -08:00
Geert Weening
fc426d5764 Merge branch 'release' into develop 2014-11-14 10:16:34 -08:00
Geert Weening
056d2381cd Merge pull request #208 from ripple/relocate-presubmit
Relocate presubmit emission to immediately before transaction submit
2014-11-14 10:14:02 -08:00
Geert Weening
2932a0ec5f [DOC] add doc that accountRequest throws
if a marker is provided, but no ledger_index or ledger_hash
2014-11-14 10:11:26 -08:00
Geert Weening
d3d85a3fcf [DOC] add doc that accountRequest throws
if a marker is provided, but no ledger_index or ledger_hash
2014-11-14 10:11:13 -08:00
wltsmrz
7a1feaa897 Relocate presubmit emission to immediately before transaction submit 2014-11-13 21:44:20 -08:00
Geert Weening
5f3cf72cc6 Merge pull request #207 from shekenahglory/develop
[TASK] binformat: update fields to match rippled
2014-11-13 14:13:52 -08:00
Matthew Fettig
cae980788e binformat: update fields to match rippled 2014-11-13 11:14:46 -08:00
Geert Weening
df763b8765 Merge pull request #205 from ripple/core-build
Add core build
2014-11-12 10:51:45 -08:00
wltsmrz
365085809e Add note on restricted browser builds 2014-11-12 03:04:51 -08:00
Geert Weening
3ee7998261 [TASK] bump version to 0.9.3-rc1 2014-11-11 17:52:30 -08:00
Geert Weening
6fb9ed8312 [DOC] update release notes 2014-11-11 17:52:13 -08:00
Geert Weening
89f79c35f5 Merge pull request #206 from geertweening/fix/tec_wait_for_validated
[TASK] wait for validation before returning tec error
2014-11-11 17:49:38 -08:00
Geert Weening
6bdd4b2670 [TASK] wait for validation before returning tec error 2014-11-11 16:54:25 -08:00
Geert Weening
acd79d19e2 [TASK] bump version to 0.9.2 2014-11-11 12:14:04 -08:00
Geert Weening
674d4a957d [TASK] bump version to 0.9.2-rc6 2014-11-11 11:51:54 -08:00
Geert Weening
bdbf264771 [FIX] support string '0' being interpreted as XRP 2014-11-11 11:51:12 -08:00
wltsmrz
8f17873da2 Remove server._computeFee(Transaction), require fee units argument 2014-11-11 06:24:34 -08:00
wltsmrz
b0cac776ee Throw an error when trying to use unavailable class in WebPack build 2014-11-11 06:23:37 -08:00
wltsmrz
625dba4d85 Add build-core gulp task 2014-11-11 05:30:50 -08:00
Geert Weening
261b72d0fc [DOC] update API reference 2014-11-10 14:32:35 -08:00
Geert Weening
b5b167ef6d [DOC] update README and GUIDES
to match current API's
2014-11-10 10:14:11 -08:00
Geert Weening
66d21b24cd [TASK] bump ripple-lib to 0.9.2-rc5 2014-11-07 18:22:23 -08:00
Geert Weening
5a084ea3cc [TEST] fix broken tests
as a result of updating account_info request in account.js
2014-11-07 18:22:05 -08:00
Geert Weening
486944fa4c [FIX] request account info in account.js 2014-11-07 18:04:04 -08:00
Geert Weening
b63a76d298 [TASK] bump version to 0.9.2-rc4 2014-11-07 17:45:17 -08:00
Geert Weening
31045039c0 [DOC] update release notes 2014-11-07 17:44:30 -08:00
Geert Weening
6f5d1104aa [TASK] change accountRequest method signature
`(type, options, callback)` where the last argument will be considered for callback if it's a function
2014-11-07 17:08:01 -08:00
Geert Weening
3c9660203b Merge pull request #203 from geertweening/feature/marker_valid_ledger
[FEATURE] check for valid ledger when using marker
2014-11-07 12:57:57 -08:00
Geert Weening
29e1423f84 [FEATURE] check for valid ledger when using marker
when using a marker on an account request, a valid ledger_index or ledger_hash is required, otherwise the results can't be guaranteed to be reliable

consolidated test values for addresses, indexes and hashes
2014-11-07 11:18:24 -08:00
Geert Weening
e42e67e259 [TASK] consolidate accountRequest and pagingAccountRequest
update `requestAccountCurrencies` and  `requestAccountInfo`
2014-11-07 09:52:17 -08:00
Geert Weening
ed018282c4 [TASK] remove clone in favor of copy and update
see 'object' case in `parse_json`
2014-11-06 22:58:04 -08:00
Geert Weening
fbe015758c [TASK] bump version to 0.9.2-rc3 2014-11-06 21:48:01 -08:00
Geert Weening
7e24a81764 [DOC] update release notes 2014-11-06 21:47:44 -08:00
Geert Weening
9ab77e90fe Merge pull request #202 from geertweening/feature/paging_account_request
[FEATURE] add paging account request
2014-11-06 21:41:44 -08:00
Geert Weening
ae3ed699db Merge pull request #201 from geertweening/fix/from_human_full_name_native
[FIX] from_human 'XRP' with full name
2014-11-06 21:41:30 -08:00
Geert Weening
0c22a9753e Merge pull request #199 from geertweening/fix/amount_cap
[FIX] cap IOU Amounts to their max and min value
2014-11-06 21:41:08 -08:00
Geert Weening
a447f6b723 [TEST] add missing testcases for interest bearing currencies
- `get_interest_at` by providing a Date object
- `get_interest_at` for a Currency without interest
2014-11-06 21:38:00 -08:00
Geert Weening
a8ef614b81 [FIX] Currency constructor with Currency object
clone the given Currency instance in `parse_json`
2014-11-06 21:36:57 -08:00
Geert Weening
9025e8bfa8 [FIX] get interest for currency without interest
- `get_interest_at` for a currency without interest would not hit the intended check since the function was used as variable instead of calling the method
2014-11-06 21:35:41 -08:00
Geert Weening
722f4e175d [FEATURE] add paging account request
some requests return results that can be paged through, e.g. `account_lines`
use `limit` and `marker` options to specify results per response and position

change `requestAccountLines` and `requestAccountOffers` to use the `pagingAccountRequest`
2014-11-06 18:40:45 -08:00
Geert Weening
1ad6e5a15f [FIX] from_human 'XRP' with full name
from_human 'XRP - Ripples' should result in native XRP
2014-11-05 16:54:45 -08:00
Geert Weening
3554572db7 [TASK] bump version to 0.9.2-rc2 2014-11-05 16:32:37 -08:00
Geert Weening
f1abff962f Merge pull request #200 from boxbag/fix-max-fee
[FIX] fix test and do not set tx_json.Fee in maxFee method
2014-11-05 16:07:01 -08:00
Geert Weening
f05941fbc4 [FIX] cap IOU Amounts to their max and min value
respect rippled's limits
2014-11-05 16:04:02 -08:00
Bo Chen
237c46d5a0 [FIX] fix test and do not set tx_json.Fee in maxFee method 2014-11-05 15:59:57 -08:00
Geert Weening
76cfb69d9f [TASK] bump version to 0.9.2-rc1 2014-11-05 14:38:47 -08:00
Geert Weening
7610df0fbb [DOC] update release notes 2014-11-05 14:38:35 -08:00
Geert Weening
8bc935aa62 Merge pull request #198 from boxbag/transaction-max-fee
[FEATURE] set max fee the submitter of a transaction is willing to pay
2014-11-05 09:27:26 -08:00
Bo Chen
24587fab9c [FEATURE] set max fee the submitter of a transaction is willing to pay 2014-11-04 14:13:42 -08:00
Geert Weening
0248475473 [DOC] update description in package.json 2014-10-31 18:52:09 -07:00
Geert Weening
d2fa5c4b12 [TASK] bump version to 0.9.1 2014-10-30 10:01:16 -07:00
Geert Weening
c60c0cb6e0 [TASK] bump version to 0.9.1-rc3 2014-10-28 17:35:29 -07:00
Geert Weening
cdf1112666 [FIX] ledgerSelect setting both ledger_index and ledger_hash 2014-10-28 17:33:55 -07:00
Geert Weening
d861bb2e34 [TASK] bump version to 0.9.1-rc2 2014-10-27 17:32:37 -07:00
Geert Weening
006849a3d5 [DOC] update release notes 2014-10-27 17:32:18 -07:00
wltsmrz
a3c1d06eba Change initial account transaction sequence to 1 2014-10-27 17:29:51 -07:00
Geert Weening
4bd1e7a2bc [TASK] bump version to 0.9.1-rc1 2014-10-27 16:40:46 -07:00
Geert Weening
68643f3118 [DOC] update release notes 2014-10-27 16:37:14 -07:00
Geert Weening
560dfc8ae6 Merge branch 'release' into develop 2014-10-27 16:27:52 -07:00
Geert Weening
b0459e096b [TASK] bump version to 0.9.0 2014-10-27 16:25:34 -07:00
Geert Weening
2a0dfc4587 [DOC] update release notes 2014-10-27 16:25:09 -07:00
Geert Weening
2dcd5f94fb [TASK] shrinkwrap packages for dependency locking 2014-10-27 16:24:18 -07:00
Geert Weening
13685d03e1 Merge pull request #195 from ripple/use-ledgerselect
Switch account requests to use ledgerSelect rather than ledgerChoose
2014-10-27 16:07:40 -07:00
wltsmrz
278df9025a Switch account requests to use ledgerSelect rather than ledgerChoose 2014-10-27 15:35:07 -07:00
Geert Weening
cb608406f8 Merge pull request #191 from geertweening/fix/undefined_remote
[FIX] transaction without explicit remote
2014-10-27 12:09:59 -07:00
Geert Weening
f4a55d03d3 Merge pull request #192 from geertweening/fix/amount_precision
[FIX] confusion between precision and min_precision
2014-10-26 19:21:09 -04:00
Geert Weening
d3b6b8127c [FIX] transaction without explicit remote
remote was instantiated as an object and checks through the class for `this.remote` would pass and cause 
unintended behavior

e.g. `.complete()` would view an undefined remote as untrusted and not allow local signing
e.g. calling `_computeFee()` with an undefined remote would crash ripple-lib
2014-10-26 19:09:04 -04:00
wltsmrz
bc1f9f8a28 Fix account root request ledger argument #121 2014-10-26 15:39:17 -07:00
wltsmrz
9a5c9aea75 Merge pull request #193 from professorhantzen/patch-1
[FIX] correct usage example with surrounding apostrophes
2014-10-24 18:12:32 -07:00
professorhantzen
f1004c6db2 Correct usage example with surrounding apostrophes 2014-10-25 13:14:07 +13:00
Geert Weening
7708c64576 [FIX] confusion between precision and min_precision
`precision` expresses precision within the provided value and won't expand it if the max expression of the value is smaller
`min_precision` will expand the value if the max expression of the value is smaller
2014-10-23 17:59:53 -07:00
Geert Weening
0527b8c981 [TASK] move gulp-bump to devDependencies 2014-10-22 12:07:36 -07:00
Geert Weening
13f89e2fcc [TASK] bump version to 0.9.0-rc5 2014-10-21 15:05:02 -07:00
Geert Weening
69a0a473a6 [DOC] update release notes 2014-10-21 15:04:52 -07:00
Geert Weening
4ab82d7e01 Merge pull request #188 from geertweening/fix/amount_precision
[FIX] amount precision bugs
2014-10-21 15:01:50 -07:00
Geert Weening
4be209e286 [FIX] amount precision bugs
- leading 0's for fraction part disappearing
- first decimal lower than 5 wouldn't result in dropping the decimal
2014-10-21 13:22:42 -07:00
Geert Weening
8b10325895 [TASK] bump version to 0.9.0-rc4 2014-10-16 14:11:36 -07:00
Geert Weening
70bf600247 [DOC] update release notes 2014-10-16 14:11:14 -07:00
Geert Weening
d42e06d48b [FIX] fraction_part is a string 2014-10-16 14:05:26 -07:00
wltsmrz
9c080b6790 Merge pull request #187 from ripple/amount_precision
[FIX] Amount.to_human() precision slicing instead of rounding
2014-10-16 14:00:29 -07:00
Geert Weening
033257b03b [FIX] Amount.to_human() precision slicing instead of rounding 2014-10-16 13:54:42 -07:00
Geert Weening
39d8bcdfc2 [TASK] bump version to 0.9.0-rc3 2014-10-15 11:32:16 -07:00
Geert Weening
2ddcb4e2b7 [DOC] update release notes 2014-10-15 11:31:52 -07:00
Geert Weening
d972718a53 Merge pull request #185 from shekenahglory/fix/serialize
[FIX] binformat: added missing TransactionResult options
2014-10-14 11:37:35 -07:00
Matthew Fettig
6abed8dd53 [FIX] binformat: added missing TransactionResult options 2014-10-14 11:32:33 -07:00
Geert Weening
e74e697b45 [TASK] bump version to 0.9.0-rc2 2014-10-09 14:46:12 -07:00
Geert Weening
26c59e8565 [DOC] update release notes 2014-10-09 14:45:44 -07:00
Geert Weening
a5e83c4f23 [FIX] run test by _mocha to capture coverage 2014-10-09 14:35:14 -07:00
wltsmrz
900c4bbd2e Merge pull request #184 from geertweening/show_interest_flag
[FEATURE] add flag to show or hide interest in to_human/to_json
2014-10-09 14:31:43 -07:00
Geert Weening
947ec3edc2 [FEATURE] add flag to show or hide interest in to_human/to_json
The show_interest flag will default to true for interest bearing currencies and false for currencies without interest
2014-10-09 14:31:02 -07:00
Geert Weening
957f10d9f1 [TASK] bump version to 0.9.0-rc1 2014-10-09 09:40:31 -07:00
Geert Weening
89aa54dff8 [DOC] update release notes 2014-10-09 09:39:15 -07:00
Geert Weening
bb76530e4b Merge pull request #179 from geertweening/develop
[FEATURE] make maxLoops in seed.get_key() optional
2014-10-09 09:32:17 -07:00
wltsmrz
011e2cc1e3 Merge pull request #182 from shekenahglory/fix/attestation
[FIX] vault client: URI decode attestation token
2014-10-08 18:41:38 -07:00
Matthew Fettig
4c594f8964 [FIX] vault client: URI decode attestation token 2014-10-08 18:17:30 -07:00
Geert Weening
1fcfcf2392 [TASK] bump version to 0.8.3-rc1 2014-10-06 18:23:59 -07:00
Geert Weening
6311abff81 [DOC] update release notes 2014-10-06 18:23:05 -07:00
Geert Weening
ed2da57475 Merge pull request #181 from shekenahglory/feature/identity
Feature/identity
2014-10-06 18:15:38 -07:00
Matthew Fettig
778ccd4805 [TASK] vault client: tests for attestation routes and full summary 2014-10-06 18:03:52 -07:00
Matthew Fettig
327c35252f [FEATURE] vault client: update attestation and attestation summary 2014-10-03 17:17:09 -07:00
Matthew Fettig
5e7af2fba4 [TASK] switch to new attestation endpoint 2014-10-03 17:17:09 -07:00
Matthew Fettig
dce15bc579 [TASK] vault client: add parameters to attest 2014-10-03 17:17:08 -07:00
Matthew Fettig
d5e32db954 [CHORE] vault client: add type to attest parameters 2014-10-03 17:17:08 -07:00
Matthew Fettig
bdfa83592b [FEATURE] identity functions 2014-10-03 17:17:08 -07:00
Geert Weening
23e473b688 [FEATURE] make maxLoops in seed.get_key optional
default to 1 or the index of the requested account +1
2014-10-02 17:26:01 -07:00
wltsmrz
0dfd3a0ae0 Merge pull request #178 from ripplerm/develop
configurable maxAttempts
2014-10-01 02:07:04 -07:00
ripplerm
d107092540 configurable maxAttempts 2014-10-01 14:43:44 +08:00
wltsmrz
c2f379d3b3 Merge pull request #176 from shekenahglory/develop
[FIX] change handling of requestLedger options
2014-09-28 00:34:30 -07:00
Matthew Fettig
57b70300f5 [FIX] change handling of requestLedger options
ledger_index and ledger_hash were being set to true
instead of the specified value, and according to API
docs 'closed','validated', and 'current' can be
supplied to the ledger_index field to get the most
recent of the specified type
2014-09-26 21:41:22 -07:00
Geert Weening
eeba86f9c5 [TASK] bump version to 0.8.2 2014-09-25 10:05:57 -07:00
Geert Weening
e0d68e60ec Merge pull request #172 from booxood/modify-docs-guides-md
Update docs/GUIDES.md
2014-09-24 23:44:08 -07:00
Liucw
254248486b Update docs/GUIDES.md 2014-09-25 14:34:29 +08:00
Geert Weening
1b57cc6d35 [TASK] bump verison to 0.8.2-rc2 2014-09-22 23:59:12 -07:00
Geert Weening
77234f256d [DOC] update release notes 2014-09-22 23:58:49 -07:00
Geert Weening
795d31d2db Merge branch 'release' into develop 2014-09-22 23:50:45 -07:00
wltsmrz
f3f10fd9bd Fix requestLedger arguments 2014-09-18 02:03:29 -07:00
wltsmrz
7100b4be8d Emit server with subscription events 2014-09-18 01:41:23 -07:00
wltsmrz
b1a7200d1b Deprecate account_tx map/reduce/filter 2014-09-18 01:28:43 -07:00
Geert Weening
5d8bb541c6 [TASK] bump version to 0.8.2-rc1 2014-09-17 15:02:44 -07:00
Geert Weening
b51c59b23a [TASK] update release notes 2014-09-17 15:02:21 -07:00
wltsmrz
2cd434e861 Fix orderbook reset on reconnect 2014-09-17 13:42:24 -07:00
wltsmrz
1599eb9629 Add potential missing error handlers 2014-09-17 13:40:49 -07:00
wltsmrz
8ef7481858 Allow mixed letters and numbers in currencies 2014-09-17 13:39:49 -07:00
Geert Weening
344d478b3f [TASK] bump version to 0.8.1 2014-09-15 16:52:23 -07:00
Geert Weening
39b7e27aa6 [TASK] bump version to 0.8.1-rc3 2014-09-12 14:26:25 -07:00
Geert Weening
b1876b4f77 [DOC] update release notes 2014-09-12 14:26:02 -07:00
wltsmrz
db3b41d1ba Merge pull request #167 from ximinez/ripd-549
[BUG] Fix Amount.to_human_full()
2014-09-12 12:16:03 -07:00
Edward Hennis
02b5d14d0f [BUG] Fix Amount.to_human_full()
* Amount.is_native is a function, but was referenced as a bool.
* Duplicate to_text_full tests to test to_human_full.
2014-09-12 10:52:46 -04:00
wltsmrz
0120044c96 Fix undefined fee states when connecting to a rippled that is syncing 2014-09-11 23:44:21 -07:00
wltsmrz
ad6304e857 Merge pull request #166 from geertweening/develop
[DOC] update README install instructions
2014-09-10 18:54:45 -07:00
Geert Weening
7cba84b8cf [DOC] update README install instructions 2014-09-10 18:51:59 -07:00
Geert Weening
5a9a4be163 [TASK] bump version to 0.8.1-rc2 2014-09-10 17:54:11 -07:00
Geert Weening
4d1a31d3c9 Revert "[FOLD] Add postinstall step to build the sjcl.js"
This reverts commit 42c853dbf4.
2014-09-10 17:53:29 -07:00
Geert Weening
6e3ceec4e5 [TASK] update publish scripts 2014-09-10 17:33:52 -07:00
Geert Weening
bc7d3c0af8 [TASK] add release candidate publish script 2014-09-10 17:32:03 -07:00
Geert Weening
519ddee092 [TASK] bump version to 0.8.1-rc1 2014-09-10 17:28:34 -07:00
Geert Weening
3e0fcc5b8b [DOC] update release notes 2014-09-10 17:28:00 -07:00
wltsmrz
b1972985c4 Merge pull request #164 from geertweening/develop
[FIX] return null for _getServer if there's no connected server
2014-09-08 12:04:22 -07:00
Geert Weening
51c42e9257 [FIX] return null for _getServer if there's no connected server 2014-09-08 11:54:48 -07:00
Geert Weening
86dcbcc671 [TASK] add exit_on_error calls to publish script 2014-09-08 11:54:47 -07:00
wltsmrz
3b7cd9d84f Merge pull request #163 from stevenzeiler/wallet
[TASK] Update package.json for ripple-wallet-generator patch.
2014-09-06 02:18:08 -07:00
Steven Zeiler
1073ec6214 [TASK] Update package.json for ripple-wallet-generator patch.
Removed node_modules from git repo of ripple-wallet-generator
2014-09-05 21:19:09 -07:00
wltsmrz
14a5e42a63 Merge pull request #162 from sublimator/develop
Fix #160, Seed.parse_json of hex
2014-09-05 20:56:53 -07:00
Nicholas Dudfield
b4564a86b4 Fix #160, Seed.parse_json of hex 2014-09-06 10:45:26 +07:00
wltsmrz
03386a61e9 Merge pull request #161 from stevenzeiler/wallet
[FEATURE] Add Wallet class that generates wallets.
2014-09-05 18:22:55 -07:00
Steven Zeiler
8bb2623360 [FEATURE] Add Wallet class that generates wallets.
[DOC] Comment out logged wallet.

[FIX] Use var instead of const.
2014-09-05 18:20:46 -07:00
wltsmrz
ab0e4188b3 Merge pull request #159 from ximinez/ripd-549
Clean up
2014-09-05 13:03:48 -07:00
Edward Hennis
42c853dbf4 [FOLD] Add postinstall step to build the sjcl.js 2014-09-05 14:50:29 -04:00
Geert Weening
ce48a1793b Merge branch 'release' into develop 2014-09-05 10:24:05 -07:00
Geert Weening
6177543d98 [TASK] add publish script 2014-09-05 10:23:59 -07:00
Geert Weening
9697bfa817 [TASK] add publish to bower script 2014-09-05 10:23:59 -07:00
wltsmrz
7cccb451d2 Show field name in serialization failure 2014-09-04 20:13:04 -07:00
wltsmrz
a39fb9d551 Minor cleanup 2014-09-04 19:53:16 -07:00
wltsmrz
8f7cdc6e4f Prevent setting LastLedgerSequence of NaN. Fixes a potential ambiguous serialization error 2014-09-04 19:50:56 -07:00
wltsmrz
8f7e365b03 Wait until remote is connected before emitting ledger_closed events 2014-09-04 18:51:00 -07:00
Edward Hennis
64735e523f Clean up
* Make npm test runnable in Windows.
* Fix paths in README.md
* Ignore all build output files
2014-09-04 20:05:04 -04:00
41 changed files with 2854 additions and 5435 deletions

4
.gitignore vendored
View File

@@ -17,7 +17,7 @@
# Ignore object files.
*.o
build/ripple*.js
build/*.js
tags
bin/rippled
Debug/*.*
@@ -51,4 +51,4 @@ test/config.js
npm-debug.log
# Ignore dist folder, build for bower
dist/
dist/

View File

@@ -68,45 +68,6 @@ gulp.task('build', [ 'concat-sjcl' ], function(callback) {
}, callback);
});
gulp.task('bower-build', [ 'build' ], function(callback) {
return gulp.src([ './build/ripple-', '.js' ].join(pkg.version))
.pipe(rename('ripple.js'))
.pipe(gulp.dest('./dist/'));
});
gulp.task('bower-build-min', [ 'build-min' ], function(callback) {
return gulp.src([ './build/ripple-', '-min.js' ].join(pkg.version))
.pipe(rename('ripple-min.js'))
.pipe(gulp.dest('./dist/'));
});
gulp.task('bower-build-debug', [ 'build-debug' ], function(callback) {
return gulp.src([ './build/ripple-', '-debug.js' ].join(pkg.version))
.pipe(rename('ripple-debug.js'))
.pipe(gulp.dest('./dist/'));
});
gulp.task('bower-version', function() {
gulp.src('./dist/bower.json')
.pipe(bump({version: pkg.version}))
.pipe(gulp.dest('./dist/'));
});
gulp.task('version-bump', function() {
if (!argv.type) {
throw new Error("No type found, pass it in using the --type argument");
}
gulp.src('./package.json')
.pipe(bump({type:argv.type}))
.pipe(gulp.dest('./'));
});
gulp.task('version-beta', function() {
gulp.src('./package.json')
.pipe(bump({version: pkg.version+'-beta'}))
.pipe(gulp.dest('./'));
});
gulp.task('build-min', [ 'build' ], function(callback) {
return gulp.src([ './build/ripple-', '.js' ].join(pkg.version))
.pipe(uglify())
@@ -128,6 +89,66 @@ gulp.task('build-debug', [ 'concat-sjcl' ], function(callback) {
}, callback);
});
/**
* Generate a WebPack external for a given unavailable module which replaces
* that module's constructor with an error-thrower
*/
function buildUseError(cons) {
return 'var {<CONS>:function(){throw new Error("Class is unavailable in this build: <CONS>")}}'
.replace(new RegExp('<CONS>', 'g'), cons);
};
gulp.task('build-core', [ 'concat-sjcl' ], function(callback) {
webpack({
entry: [
'./src/js/ripple/remote.js'
],
externals: [
{
'./transaction': buildUseError('Transaction'),
'./orderbook': buildUseError('OrderBook'),
'./account': buildUseError('Account'),
'./serializedobject': buildUseError('SerializedObject')
}
],
output: {
library: 'ripple',
path: './build/',
filename: [ 'ripple-', '-core.js' ].join(pkg.version)
},
plugins: [
new webpack.optimize.UglifyJsPlugin()
]
}, callback);
});
gulp.task('bower-build', [ 'build' ], function(callback) {
return gulp.src([ './build/ripple-', '.js' ].join(pkg.version))
.pipe(rename('ripple.js'))
.pipe(gulp.dest('./dist/'));
});
gulp.task('bower-build-min', [ 'build-min' ], function(callback) {
return gulp.src([ './build/ripple-', '-min.js' ].join(pkg.version))
.pipe(rename('ripple-min.js'))
.pipe(gulp.dest('./dist/'));
});
gulp.task('bower-build-debug', [ 'build-debug' ], function(callback) {
return gulp.src([ './build/ripple-', '-debug.js' ].join(pkg.version))
.pipe(rename('ripple-debug.js'))
.pipe(gulp.dest('./dist/'));
});
gulp.task('bower-version', function() {
gulp.src('./dist/bower.json')
.pipe(bump({ version: pkg.version }))
.pipe(gulp.dest('./dist/'));
});
gulp.task('bower', ['bower-build', 'bower-build-min', 'bower-build-debug', 'bower-version']);
gulp.task('lint', function() {
gulp.src('src/js/ripple/*.js')
.pipe(jshint())
@@ -158,6 +179,20 @@ gulp.task('watch', function() {
gulp.watch('src/js/ripple/*', [ 'build-debug' ]);
});
gulp.task('default', [ 'concat-sjcl', 'build', 'build-debug', 'build-min' ]);
gulp.task('version-bump', function() {
if (!argv.type) {
throw new Error("No type found, pass it in using the --type argument");
}
gulp.task('bower', ['bower-build', 'bower-build-min', 'bower-build-debug', 'bower-version']);
gulp.src('./package.json')
.pipe(bump({ type: argv.type }))
.pipe(gulp.dest('./'));
});
gulp.task('version-beta', function() {
gulp.src('./package.json')
.pipe(bump({ version: pkg.version + '-beta' }))
.pipe(gulp.dest('./'));
});
gulp.task('default', [ 'concat-sjcl', 'build', 'build-debug', 'build-min' ]);

View File

@@ -1,3 +1,119 @@
##0.9.4
+ [Normalize offers from book_offers and transaction stream](https://github.com/ripple/ripple-lib/commit/86ed24b94cf7c8929c87db3a63e9bbea7f767e9c)
+ [Fix: Amount.to_human() precision rounding](https://github.com/ripple/ripple-lib/commit/e371cc2c3ceccb3c1cfdf18b98d80093147dd8b2)
+ [Fix: fractional drops in funded taker_pays setter](https://github.com/ripple/ripple-lib/commit/0d7fc0a573a144caac15dd13798b23eeb1f95fb4)
##0.9.3
+ [Change `presubmit` to emit immediately before transaction submit](https://github.com/ripple/ripple-lib/commit/7a1feaa89701bf861ab31ebd8ffdc8d8d1474e29)
+ [Add a "core" browser build of ripple-lib which has a subset of features and smaller file size](https://github.com/ripple/ripple-lib/pull/205)
+ [Update binformat with missing fields from rippled](https://github.com/ripple/ripple-lib/commit/cae980788efb00191bfd0988ed836d60cdf7a9a2)
+ [Wait for transaction validation before returning `tec` error](https://github.com/ripple/ripple-lib/commit/6bdd4b2670906588852fc4dda457607b4aac08e4)
+ [Change default `max_fee` on `Remote` to `1 XRP`](https://github.com/ripple/ripple-lib/commit/d6b1728c23ff85c3cc791bed6982a750641fd95f)
+ [Fix: Request ledger_accept should return the Remote](https://github.com/ripple/ripple-lib/pull/209)
##0.9.2
+ [**Breaking change**: Change accountRequest method signature](https://github.com/ripple/ripple-lib/commit/6f5d1104aa3eb440c518ec4f39e264fdce15fa15)
+ [Add paging behavior for account requests, `account_lines` and `account_offers`](https://github.com/ripple/ripple-lib/commit/722f4e175dbbf378e51b49142d0285f87acb22d7)
+ [Add max_fee setter to transactions to set max fee the submitter is willing to pay] (https://github.com/ripple/ripple-lib/commit/24587fab9c8ad3840d7aa345a7037b48839e09d7)
+ [Fix: cap IOU Amounts to their max and min value] (https://github.com/ripple/ripple-lib/commit/f05941fbc46fdb7c6fe7ad72927af02d527ffeed)
Example on how to use paging with `account_offers`:
```
// A valid `ledger_index` or `ledger_hash` is required to provide a reliable result.
// Results can change between ledger closes, so the provided ledger will be used as base.
var options = {
account: < rippleAccount >,
limit: < Number between 10 and 400 >,
ledger: < valid ledger_index or ledger_hash >
}
// The `marker` comes back in an account request if there are more results than are returned
// in the current response. The amount of results per response are determined by the `limit`.
if (marker) {
options.marker = < marker >;
}
var request = remote.requestAccountOffers(options);
```
[Full working example](https://github.com/geertweening/ripple-lib-scripts/blob/master/account_offers_paging.js)
##0.9.1
+ Switch account requests to use ledgerSelect rather than ledgerChoose ([278df90](https://github.com/ripple/ripple-lib/commit/278df9025a20228de22379a53c76ca12d40fa591))
+ **Deprecated** setting `ident` and `account_index` on account requests ([278df90](https://github.com/ripple/ripple-lib/commit/278df9025a20228de22379a53c76ca12d40fa591))
+ Change initial account transaction sequence to 1 ([a3c1d06](https://github.com/ripple/ripple-lib/commit/a3c1d06eba883dc84fe2bfe700e4309795c84cac))
+ Fix: instance transaction withoute remote ([d3b6b81](https://github.com/ripple/ripple-lib/commit/d3b6b8127c7b01e416b400c25abf1719bdd008ca))
+ Fix: account root request ledger argument ([bc1f9f8](https://github.com/ripple/ripple-lib/commit/bc1f9f8a286b187d36ebaf552694e31e73742293))
+ Fix: rsign.js local signing and example ([d3b6b81](https://github.com/ripple/ripple-lib/commit/d3b6b8127c7b01e416b400c25abf1719bdd008ca) and [f1004c6](https://github.com/ripple/ripple-lib/commit/f1004c6db2a0ce59bbabbb8f2b355a9fd9995fd8))
##0.9.0
+ Add routes to the vault client for KYC attestations ([ed2da574](https://github.com/ripple/ripple-lib/commit/ed2da57475acf5e9d2cf3373858f4274832bd83f))
+ Currency: add `show_interest` flag to show or hide interest in `Currency.to_human()` and `Currency.to_json()` [Example use in tests](https://github.com/ripple/ripple-lib/blob/947ec3edc2e7c8f1ef097e496bf552c74366e749/test/currency-test.js#L123)
+ Configurable maxAttempts for transaction submission ([d107092](https://github.com/ripple/ripple-lib/commit/d10709254061e9e4416d2cb78b5cac1ec0d7ffa5))
+ Binformat: added missing TransactionResult options ([6abed8d](https://github.com/ripple/ripple-lib/commit/6abed8dd5311765b2eb70505dadbdf5121439ca8))
+ **Breaking change:** make maxLoops in seed.get_key optional. [Example use in tests](https://github.com/ripple/ripple-lib/blob/23e473b6886c457781949c825b3ff48b3984e51f/test/seed-test.js) ([23e473b](https://github.com/ripple/ripple-lib/commit/23e473b6886c457781949c825b3ff48b3984e51f))
+ Shrinkwrap packages for dependency locking ([2dcd5f9](2dcd5f94fbc71200eb08a5044c76ef94f7971913))
+ Fix: Amount.to_human() precision bugs ([4be209e](https://github.com/ripple/ripple-lib/commit/4be209e286b5b209bec7bcd1212098985e15ff2f) and [7708c64](https://github.com/ripple/ripple-lib/commit/7708c64576e70ce3ac190442daceb30e4446aab7))
+ Fix: change handling of requestLedger options ([57b7030](https://github.com/ripple/ripple-lib/commit/57b70300f5f0c7534ede118ddbb5d8762668a4f8))
##0.8.2
+ Currency: Allow mixed letters and numbers in currencies
+ Deprecate account_tx map/reduce/filterg
+ Fix: correct requestLedger arguments
+ Fix: missing subscription on error events for some server methods
+ Fix: orderbook reset on reconnect
+ Fix: ripple-lib crashing. Add potential missing error handlers
##0.8.1
+ Wallet: Add Wallet class that generates wallets
+ Make npm test runnable in Windows.
+ Fix several stability issues, see merged PR's for details
+ Fix bug in Amount.to_human_full()
+ Fix undefined fee states when connecting to a rippled that is syncing
##0.8.0
+ Orderbook: Added tracking of offer funds for determining when offers are not funded

View File

@@ -1,6 +1,6 @@
#ripple-lib
JavaScript client for [rippled](https://github.com/ripple/rippled)
A JavaScript API for interacting with Ripple in Node.js and the browser
[![Build Status](https://travis-ci.org/ripple/ripple-lib.svg?branch=develop)](https://travis-ci.org/ripple/ripple-lib) [![Coverage Status](https://coveralls.io/repos/ripple/ripple-lib/badge.png?branch=develop)](https://coveralls.io/r/ripple/ripple-lib?branch=develop)
@@ -15,9 +15,9 @@ JavaScript client for [rippled](https://github.com/ripple/rippled)
###In this file
1. [Installation](README.md#installation)
2. [Quickstart](README.md#quickstart)
3. [Running tests](https://github.com/ripple/ripple-lib#running-tests)
1. [Installation](#installation)
2. [Quick start](#quick-start)
3. [Running tests](#running-tests)
###Additional documentation
@@ -38,7 +38,18 @@ JavaScript client for [rippled](https://github.com/ripple/rippled)
$ npm install ripple-lib
```
**Building ripple-lib for browser use**
**Via bower (for browser use)**
```
$ bower install ripple
```
See the [bower-ripple repo](https://github.com/ripple/bower-ripple) for additional bower instructions
**Building ripple-lib for browser environments**
ripple-lib uses Gulp to generate browser builds. These steps will generate minified and non-minified builds of ripple-lib in the `build/` directory.
```
$ git clone https://github.com/ripple/ripple-lib
@@ -46,9 +57,13 @@ JavaScript client for [rippled](https://github.com/ripple/rippled)
$ npm run build
```
Then use the minified `build/ripple-*-min.js` in your webpage
**Restricted browser builds**
##Quickstart
You may generate browser builds that contain a subset of features. To do this, run `./node_modules/.bin/gulp build-<name>`
+ `build-core` Contains the functionality to make requests and listen for events such as `ledgerClose`. Only `ripple.Remote` is currently exposed. Advanced features like transaction submission and orderbook tracking are excluded from this build.
##Quick start
`Remote.js` ([remote.js](https://github.com/ripple/ripple-lib/blob/develop/src/js/ripple/remote.js)) is the point of entry for interacting with rippled
@@ -66,8 +81,8 @@ var remote = new Remote({
remote.connect(function() {
/* remote connected */
remote.request('server_info', function(err, info) {
remote.requestServerInfo(function(err, info) {
// process err and info
});
});
```
@@ -78,7 +93,7 @@ remote.connect(function() {
2. `cd` into the repository and install dependencies with `npm install`
3. `npm test` or `node_modules\.bin\mocha test\*-test.js`
3. `npm test`
**Generating code coverage**

View File

@@ -56,7 +56,7 @@ function ready() {
function print_usage() {
console.log(
'Usage: rsign.js <secret> <json>\n\n',
'Example: rsign.js ssq55ueDob4yV3kPVnNQLHB6icwpC',
'Example: rsign.js ssq55ueDob4yV3kPVnNQLHB6icwpC','\''+
JSON.stringify({
TransactionType: 'Payment',
Account: 'r3P9vH81KBayazSTrQj6S25jW6kDb779Gi',
@@ -64,7 +64,7 @@ function print_usage() {
Amount: '200000000',
Fee: '10',
Sequence: 1
})
})+'\''
);
};

File diff suppressed because it is too large Load Diff

View File

@@ -29,9 +29,19 @@ This file provides step-by-step walkthroughs for some of the most common usages
```
3. Create a new `Remote` and connect to the network:
```js
var options = {
trace : false,
trusted: true,
local_signing: true,
servers: [
{ host: 's-west.ripple.com', port: 443, secure: true }
]
}
var remote = new Remote({options});
remote.connect(function() {
remote.connect(function(err, res) {
/* remote connected, use some remote functions here */
});
```
@@ -39,18 +49,45 @@ This file provides step-by-step walkthroughs for some of the most common usages
4. You're connected! Read on to see what to do now.
##Generating a new Ripple Wallet
```js
var ripple = require('ripple-lib');
// subscribing to a server allows for more entropy
var remote = new ripple.Remote({
servers: [
{ host: 's1.ripple.com', port: 443, secure: true }
]
});
remote.connect(function(err, res) {
/* remote connected */
});
// Wait for randomness to have been added.
// The entropy of the random generator is increased
// by random data received from a rippled
remote.once('random', function(err, info) {
var wallet = ripple.Wallet.generate();
console.log(wallet);
// { address: 'rEf4sbVobiiDGExrNj2PkNHGMA8eS6jWh3',
// secret: 'shFh4a38EZpEdZxrLifEnVPAoBRce' }
});
```
##Sending rippled API requests
`Remote` contains functions for constructing a `Request` object.
`Remote` contains functions for constructing a `Request` object.
A `Request` is an `EventEmitter` so you can listen for success or failure events -- or, instead, you can provide a callback.
Here is an example, using [request_server_info](https://ripple.com/wiki/JSON_Messages#server_info).
Here is an example, using [requestServerInfo](https://ripple.com/wiki/JSON_Messages#server_info).
+ Constructing a `Request` with event listeners
```js
var request = remote.request('server_info');
var request = remote.requestServerInfo();
request.on('success', function onSuccess(res) {
//handle success
@@ -91,23 +128,43 @@ See the [wiki](https://ripple.com/wiki/JSON_Messages#subscribe) for details on s
var remote = new Remote({options});
remote.connect(function() {
var request = remote.request('subscribe');
request.addStream('ledger'); //remote will emit `ledger_closed`
request.addStream('transactions'); //remote will emit `transaction`
request.on('ledger_closed', function onLedgerClosed(ledgerData) {
//handle ledger
var remote = new Remote({
// see the API Reference for available options
servers: [ 'wss://s1.ripple.com:443' ]
});
remote.on('transaction', function onTransacstion(transaction) {
//handle transaction
});
remote.connect(function() {
console.log('Remote connected');
remote.request(function(err) {
if (err) {
} else {
}
var streams = [
'ledger',
'transactions'
];
var request = remote.requestSubscribe(streams);
request.on('error', function(error) {
console.log('request error: ', error);
});
// the `ledger_closed` and `transaction` will come in on the remote
// since the request for subscribe is finalized after the success return
// the streaming events will still come in, but not on the initial request
remote.on('ledger_closed', function(ledger) {
console.log('ledger_closed: ', JSON.stringify(ledger, null, 2));
});
remote.on('transaction', function(transaction) {
console.log('transaction: ', JSON.stringify(transaction, null, 2));
});
remote.on('error', function(error) {
console.log('remote error: ', error);
});
// fire the request
request.request();
});
});
```
@@ -119,7 +176,7 @@ See the [wiki](https://ripple.com/wiki/JSON_Messages#subscribe) for details on s
Submitting a payment transaction to the Ripple network involves connecting to a `Remote`, creating a transaction, signing it with the user's secret, and submitting it to the `rippled` server. Note that the `Amount` module is used to convert human-readable amounts like '1XRP' or '10.50USD' to the type of Amount object used by the Ripple network.
```js
/* Loading ripple-lib Remote and Amount modules in Node.js */
/* Loading ripple-lib Remote and Amount modules in Node.js */
var Remote = require('ripple-lib').Remote;
var Amount = require('ripple-lib').Amount;
@@ -138,8 +195,8 @@ remote.connect(function() {
remote.setSecret(MY_ADDRESS, MY_SECRET);
var transaction = remote.createTransaction('Payment', {
account: MY_ADDRESS,
destination: RECIPIENT,
account: MY_ADDRESS,
destination: RECIPIENT,
amount: AMOUNT
});
@@ -160,12 +217,12 @@ Since the fee required for a transaction may change between the time when the or
The [`max_fee`](REFERENCE.md#1-remote-options) option can be used to avoid submitting a transaction to a server that is charging unreasonably high fees.
##4. Submitting a trade offer to the network
##Submitting a trade offer to the network
Submitting a trade offer to the network is similar to submitting a payment transaction. Here is an example for a trade that expires in 24 hours where you are offering to sell 1 USD in exchange for 100 XRP:
Submitting a trade offer to the network is similar to submitting a payment transaction. Here is an example offering to sell 1 USD in exchange for 100 XRP:
```js
/* Loading ripple-lib Remote and Amount modules in Node.js */
/* Loading ripple-lib Remote and Amount modules in Node.js */
var Remote = require('ripple-lib').Remote;
var Amount = require('ripple-lib').Amount;
@@ -175,14 +232,7 @@ var Amount = require('ripple-lib').Amount;
var MY_ADDRESS = 'rrrMyAddress';
var MY_SECRET = 'secret';
var BUY_AMOUNT = Amount.from_human('100XRP');
var SELL_AMOUNT = Amount.from_human('1USD');
// EXPIRATION must be a Date object, leave undefined to submit offer that won't expire
var now = new Date();
var tomorrow = new Date(now.getTime() + (24 * 60 * 60 * 1000));
var EXPIRATION = tomorrow;
var GATEWAY = 'rrrGateWay';
var remote = new Remote({ /* Remote options */ });
@@ -190,10 +240,9 @@ remote.connect(function() {
remote.setSecret(MY_ADDRESS, MY_SECRET);
var transaction = remote.createTransaction('OfferCreate', {
account: MY_ADDRESS,
buy: BUY_AMOUNT,
sell: SELL_AMOUNT,
expiration: EXPIRATION
account: MY_ADDRESS,
taker_pays: '100',
taker_gets: '1/USD/' + GATEWAY
});
transaction.submit(function(err, res) {

View File

@@ -18,7 +18,7 @@ __(More examples coming soon!)__
###Also see:
1. [The ripple-lib README](../README.md)
2. [The ripple-lib GUIDES](GUIDES.md)
2. [The ripple-lib GUIDES](GUIDES.md)a
#Remote options
@@ -61,14 +61,34 @@ or
#Request constructor functions
Some requests have helper methods to construct the requests object and set properties on the message object. These will often be the more used requests and the helper methods is the preferred way of constructing these requests.
Other request can still be made, but the type will have to be passed in directly to request constructor. See examples below.
If the method is camelCased and starts with `request`, it's a helper method that wraps the request constructor.
##Server requests
**[server_info([callback])](https://ripple.com/wiki/JSON_Messages#server_info)**
**[requestServerInfo([callback])](https://ripple.com/wiki/JSON_Messages#server_info)**
Returns information about the state of the server. If you are connected to multiple servers and want to select by a particular host, use `request.setServer`. Example:
```js
var request = remote.request('server_info');
var request = remote.requestServerInfo();
request.setServer('wss://s1.ripple.com');
request.request(function(err, res) {
});
```
**[requestPeers([callback])](https://ripple.com/wiki/JSON_Messages#peers)**
**[requestConnect(ip, port, [callback])](https://ripple.com/wiki/JSON_Messages#connect)**
**[unl_list([callback])](https://ripple.com/wiki/JSON_Messages#unl_list)**
```js
var request = remote.request('un_list');
request.setServer('wss://s1.ripple.com');
@@ -77,42 +97,48 @@ request.request(function(err, res) {
});
```
**[unl_list([callback])](https://ripple.com/wiki/JSON_Messages#unl_list)**
**[unl_add(addr, comment, [callback])](https://ripple.com/wiki/JSON_Messages#unl_add)**
**[unl_delete(node, [callback])](https://ripple.com/wiki/JSON_Messages#unl_delete)**
**[requestPeers([callback])](https://ripple.com/wiki/JSON_Messages#peers)**
**[connect(ip, port, [callback])](https://ripple.com/wiki/JSON_Messages#connect)**
##Ledger requests
**[ledger(ledger, [opts], [callback])](https://ripple.com/wiki/JSON_Messages#ledger)**
**[requestLedger([opts], [callback])](https://ripple.com/wiki/JSON_Messages#ledger)**
**ledger_header([callback])**
**[requestLedgerHeader([callback])](https://wiki.ripple.com/JSON_Messages#ledger_data)**
**[ledger_current([callback])](https://ripple.com/wiki/JSON_Messages#ledger_current)**
**[requestLedgerCurrent([callback])](https://ripple.com/wiki/JSON_Messages#ledger_current)**
**[ledger_entry(type, [callback])](https://ripple.com/wiki/JSON_Messages#ledger_entry)**
**[requestLedgerEntry(type, [callback])](https://ripple.com/wiki/JSON_Messages#ledger_entry)**
**[subscribe([streams], [callback])](https://ripple.com/wiki/JSON_Messages#subscribe)**
**[requestSubscribe([streams], [callback])](https://ripple.com/wiki/JSON_Messages#subscribe)**
Start receiving selected streams from the server.
**[unsubscribe([streams], [callback])](https://ripple.com/wiki/JSON_Messages#unsubscribe)**
**[requestUnsubscribe([streams], [callback])](https://ripple.com/wiki/JSON_Messages#unsubscribe)**
Stop receiving selected streams from the server.
##Account requests
**[account_info(account, [callback])](https://ripple.com/wiki/JSON_Messages#account_info)**
**[requestAccountInfo(options, [callback])](https://ripple.com/wiki/JSON_Messages#account_info)**
Return information about the specified account.
```
var options = {
account: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B',
ledger: 'validated'
};
var request = remote.requestAccountInfo(options, function(err, info) {
/* process info */
});
// response
{
ledger_current_index: <number>,
account_data: {
@@ -129,13 +155,35 @@ Return information about the specified account.
}
```
**[account_lines(accountID, [account_index], [ledger], [callback])](https://ripple.com/wiki/JSON_Messages#account_lines)**
**[requestAccountLines(options, [callback])](https://ripple.com/wiki/JSON_Messages#account_lines)**
**[account_offers(accountID, [account_index], [ledger], [callback])](https://ripple.com/wiki/JSON_Messages#account_offers)**
**[requestAccountOffers(options, [callback])](https://ripple.com/wiki/JSON_Messages#account_offers)**
Return the specified account's outstanding offers.
**[account_tx(options, [callback])](https://ripple.com/wiki/JSON_Messages#account_tx)**
Requests for both `account_lines` and `account_offers` support paging. The amount of results per response can be configured with the `limit`.
The responses can be paged through by using the `marker`.
```
// A valid `ledger_index` or `ledger_hash` is required to provide a reliable result.
// Results can change between ledger closes, so the provided ledger will be used as base.
var options = {
account: < rippleAccount >,
limit: < Number between 10 and 400 >,
ledger: < valid ledger_index or ledger_hash >
}
// The `marker` comes back in an account request if there are more results than are returned
// in the current response. The amount of results per response are determined by the `limit`.
if (marker) {
options.marker = < marker >;
}
var request = remote.requestAccountOffers(options);
```
**[requestAccountTransactions(options, [callback])](https://ripple.com/wiki/JSON_Messages#account_tx)**
Fetch a list of transactions that applied to this account.
@@ -153,42 +201,46 @@ Options:
+ `fwd_marker`
+ `rev_marker`
**[wallet_accounts(seed, [callback])](https://ripple.com/wiki/JSON_Messages#wallet_accounts)**
**[requestWalletAccounts(seed, [callback])](https://ripple.com/wiki/JSON_Messages#wallet_accounts)**
Return a list of accounts for a wallet. *Requires trusted remote*
**account_balance(account, [ledger], [callback])**
**requestAccountBalance(account, [ledger], [callback])**
Get the balance for an account. Returns an [Amount](https://github.com/ripple/ripple-lib/blob/develop/src/js/ripple/amount.js) object.
**account_flags(account, [ledger], [callback])**
**requestAccountFlags(account, [ledger], [callback])**
Return the flags for an account.
**owner_count(account, [ledger], [callback])**
**requestOwnerCount(account, [ledger], [callback])**
Return the owner count for an account.
**ripple_balance(account, issuer, currency, [ledger], [callback])**
**requestRippleBalance(account, issuer, currency, [ledger], [callback])**
Return a request to get a ripple balance
##Orderbook requests
**[book_offers(options, [callback])](https://ripple.com/wiki/JSON_Messages#book_offers)**
**[requestBookOffers(options, [callback])](https://ripple.com/wiki/JSON_Messages#book_offers)**
Return the offers for an order book, also called a *snapshot*
```js
var request = remote.request('book_offers', {
taker_gets: {
'currency':'XRP'
var options = {
gets: {
issuer: < issuer >,
currency: < currency >
},
taker_pays: {
'currency':'USD',
'issuer': 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
}
});
pays: {
issuer: < issuer >,
currency: < currency >
},
limit: < limit >
};
var request = remote.requestBookOffers(options);
request.request(function(err, offers) {
//handle offers
@@ -197,23 +249,23 @@ request.request(function(err, offers) {
##Transaction requests
**[transaction_entry(hash, [ledger_hash], [callback])](https://ripple.com/wiki/JSON_Messages#transaction_entry)**
**[requestTransactionEntry(hash, [ledger_hash], [callback])](https://ripple.com/wiki/JSON_Messages#transaction_entry)**
Searches a particular ledger for a transaction hash. Default ledger is the open ledger.
**[tx(hash, [callback])](https://ripple.com/wiki/JSON_Messages#tx)**
**[requestTransaction(hash, [callback])](https://ripple.com/wiki/JSON_Messages#tx)**
Searches ledger history for validated transaction hashes.
**[sign(secret, tx_json, [callback])](https://ripple.com/wiki/JSON_Messages#sign)**
**[requestSign(secret, tx_json, [callback])](https://ripple.com/wiki/JSON_Messages#sign)**
Sign a transaction. *Requires trusted remote*
**[submit([callback])](https://ripple.com/wiki/JSON_Messages#submit)**
**[requestSubmit([callback])](https://ripple.com/wiki/JSON_Messages#submit)**
Submit a transaction to the network. This command is used internally to submit transactions with a greater degree of reliability. See [Submitting a payment to the network](GUIDES.md#3-submitting-a-payment-to-the-network) for details.
**[ripple_path_find(src_account, dst_account, dst_amount, src_currencies, [callback])](https://ripple.com/wiki/JSON_Messages#path_find)**
**[pathFind(src_account, dst_account, dst_amount, src_currencies)](https://ripple.com/wiki/JSON_Messages#path_find)**
#Transaction constructors

142
npm-shrinkwrap.json generated Normal file
View File

@@ -0,0 +1,142 @@
{
"name": "ripple-lib",
"version": "0.9.4",
"dependencies": {
"async": {
"version": "0.8.0",
"from": "async@>=0.8.0 <0.9.0"
},
"extend": {
"version": "1.2.1",
"from": "extend@>=1.2.1 <1.3.0"
},
"lru-cache": {
"version": "2.5.0",
"from": "lru-cache@>=2.5.0 <2.6.0"
},
"ripple-wallet-generator": {
"version": "1.0.1",
"from": "ripple-wallet-generator@1.0.1",
"resolved": "https://registry.npmjs.org/ripple-wallet-generator/-/ripple-wallet-generator-1.0.1.tgz"
},
"superagent": {
"version": "0.18.2",
"from": "superagent@>=0.18.0 <0.19.0",
"dependencies": {
"qs": {
"version": "0.6.6",
"from": "qs@0.6.6",
"resolved": "https://registry.npmjs.org/qs/-/qs-0.6.6.tgz"
},
"formidable": {
"version": "1.0.14",
"from": "formidable@1.0.14",
"resolved": "https://registry.npmjs.org/formidable/-/formidable-1.0.14.tgz"
},
"mime": {
"version": "1.2.11",
"from": "mime@1.2.11",
"resolved": "https://registry.npmjs.org/mime/-/mime-1.2.11.tgz"
},
"component-emitter": {
"version": "1.1.2",
"from": "component-emitter@1.1.2",
"resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.1.2.tgz"
},
"methods": {
"version": "1.0.1",
"from": "methods@1.0.1",
"resolved": "https://registry.npmjs.org/methods/-/methods-1.0.1.tgz"
},
"cookiejar": {
"version": "2.0.1",
"from": "cookiejar@2.0.1",
"resolved": "https://registry.npmjs.org/cookiejar/-/cookiejar-2.0.1.tgz"
},
"debug": {
"version": "1.0.4",
"from": "debug@>=1.0.1 <1.1.0",
"dependencies": {
"ms": {
"version": "0.6.2",
"from": "ms@0.6.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-0.6.2.tgz"
}
}
},
"reduce-component": {
"version": "1.0.1",
"from": "reduce-component@1.0.1",
"resolved": "https://registry.npmjs.org/reduce-component/-/reduce-component-1.0.1.tgz"
},
"form-data": {
"version": "0.1.3",
"from": "form-data@0.1.3",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-0.1.3.tgz",
"dependencies": {
"combined-stream": {
"version": "0.0.5",
"from": "combined-stream@>=0.0.4 <0.1.0",
"dependencies": {
"delayed-stream": {
"version": "0.0.5",
"from": "delayed-stream@0.0.5",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-0.0.5.tgz"
}
}
},
"async": {
"version": "0.9.0",
"from": "async@>=0.9.0 <0.10.0"
}
}
},
"readable-stream": {
"version": "1.0.27-1",
"from": "readable-stream@1.0.27-1",
"dependencies": {
"core-util-is": {
"version": "1.0.1",
"from": "core-util-is@>=1.0.0 <1.1.0"
},
"isarray": {
"version": "0.0.1",
"from": "isarray@0.0.1",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz"
},
"string_decoder": {
"version": "0.10.31",
"from": "string_decoder@>=0.10.0 <0.11.0"
},
"inherits": {
"version": "2.0.1",
"from": "inherits@>=2.0.1 <2.1.0"
}
}
}
}
},
"ws": {
"version": "0.4.32",
"from": "ws@>=0.4.31 <0.5.0",
"dependencies": {
"commander": {
"version": "2.1.0",
"from": "commander@>=2.1.0 <2.2.0"
},
"nan": {
"version": "1.0.0",
"from": "nan@>=1.0.0 <1.1.0"
},
"tinycolor": {
"version": "0.0.1",
"from": "tinycolor@>=0.0.0 <1.0.0"
},
"options": {
"version": "0.0.6",
"from": "options@>=0.0.5"
}
}
}
}
}

View File

@@ -1,7 +1,7 @@
{
"name": "ripple-lib",
"version": "0.8.0",
"description": "Ripple JavaScript client library",
"version": "0.9.4",
"description": "A JavaScript API for interacting with Ripple in Node.js and the browser",
"files": [
"src/js/*",
"bin/*",
@@ -20,7 +20,7 @@
"extend": "~1.2.1",
"lru-cache": "~2.5.0",
"superagent": "^0.18.0",
"gulp-bump": "~0.1.10"
"ripple-wallet-generator": "1.0.1"
},
"devDependencies": {
"mocha": "~1.14.0",
@@ -29,6 +29,7 @@
"gulp-jshint": "~1.5.5",
"gulp-uglify": "~0.3.0",
"gulp-rename": "~1.2.0",
"gulp-bump": "~0.1.10",
"webpack": "~1.1.11",
"map-stream": "~0.1.0",
"istanbul": "~0.2.10",
@@ -39,7 +40,7 @@
"scripts": {
"build": "node_modules/.bin/gulp",
"pretest": "node_modules/.bin/gulp concat-sjcl",
"test": "./node_modules/.bin/istanbul test -x build/sjcl.js -x src/js/jsbn/* ./node_modules/.bin/_mocha -- --reporter spec test/*-test.js",
"test": "./node_modules/.bin/istanbul test -x build/sjcl.js -x src/js/jsbn/* ./node_modules/mocha/bin/_mocha -- --reporter spec test/*-test.js",
"coveralls": "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls"
},
"repository": {

43
scripts/publish Normal file
View File

@@ -0,0 +1,43 @@
echo "PUBLISH"
function exit_on_error {
res=$?
[[ ${res:-99} -eq 0 ]] || exit $res
}
rm -rf build
npm install
gulp
npm test
exit_on_error
echo ""
echo "publish to npm"
npm publish
exit_on_error
rm -rf dist
echo ""
echo "publish to bower"
git clone git@github.com:ripple/bower-ripple.git dist
gulp bower
exit_on_error
cd dist
version=$(cat bower.json | grep -Eo '([0-9]\.?)+(-rc[0-9])?')
echo "version: $version"
git add ripple.js ripple-debug.js ripple-min.js bower.json
exit_on_error
git commit -m "[TASK] add v$version"
exit_on_error
git tag "v$version"
exit_on_error
git push origin master
git push --tags origin master
cd ..

43
scripts/publish_rc Normal file
View File

@@ -0,0 +1,43 @@
echo "PUBLISH RELEASE CANDIDATE"
function exit_on_error {
res=$?
[[ ${res:-99} -eq 0 ]] || exit $res
}
rm -rf build
npm install
gulp
npm test
exit_on_error
echo ""
echo "publish rc to npm"
npm publish --tag beta
exit_on_error
rm -rf dist
echo ""
echo "publish to bower"
git clone git@github.com:ripple/bower-ripple.git dist
gulp bower
exit_on_error
cd dist
version=$(cat bower.json | grep -Eo '([0-9]\.?)+(-rc[0-9])?')
echo "version: $version"
git add ripple.js ripple-debug.js ripple-min.js bower.json
exit_on_error
git commit -m "[TASK] add v$version"
exit_on_error
git tag "v$version"
exit_on_error
git push origin master
git push --tags origin master
cd ..

View File

@@ -132,7 +132,7 @@ Account.prototype.isValid = function() {
*/
Account.prototype.getInfo = function(callback) {
return this._remote.request_account_info(this._account_id, callback);
return this._remote.requestAccountInfo({account: this._account_id}, callback);
};
/**
@@ -174,8 +174,8 @@ Account.prototype.getNextSequence = function(callback) {
function accountInfo(err, info) {
if (isNotFound(err)) {
// New accounts will start out as sequence zero
callback(null, 0);
// New accounts will start out as sequence one
callback(null, 1);
} else if (err) {
callback(err);
} else {
@@ -211,7 +211,7 @@ Account.prototype.lines = function(callback) {
}
}
this._remote.requestAccountLines(this._account_id, accountLines);
this._remote.requestAccountLines({account: this._account_id}, accountLines);
return this;
};

View File

@@ -54,7 +54,9 @@ var consts = {
// Maximum possible amount for non-XRP currencies using the maximum mantissa
// with maximum exponent. Corresponds to hex 0xEC6386F26FC0FFFF.
max_value: '9999999999999999e80'
max_value: '9999999999999999e80',
// Minimum possible amount for non-XRP currencies.
min_value: '-1000000000000000e-96'
};
// Add constants to Amount class
@@ -424,6 +426,33 @@ Amount.prototype.invert = function() {
return this.copy()._invert();
};
/**
* Canonicalize amount value
*
* Mirrors rippled's internal Amount representation
* From https://github.com/ripple/rippled/blob/develop/src/ripple/data/protocol/STAmount.h#L31-L40
*
* Internal form:
* 1: If amount is zero, then value is zero and offset is -100
* 2: Otherwise:
* legal offset range is -96 to +80 inclusive
* value range is 10^15 to (10^16 - 1) inclusive
* amount = value * [10 ^ offset]
*
* -------------------
*
* The amount can be epxresses as A x 10^B
* Where:
* - A must be an integer between 10^15 and (10^16)-1 inclusive
* - B must be between -96 and 80 inclusive
*
* This results
* - minumum: 10^15 x 10^-96 -> 10^-81 -> -1e-81
* - maximum: (10^16)-1 x 10^80 -> 9999999999999999e80
*
* @returns {Amount}
* @throws {Error} if offset exceeds legal ranges, meaning the amount value is bigger than supported
*/
Amount.prototype.canonicalize = function() {
if (!(this._value instanceof BigInteger)) {
// NaN.
@@ -447,9 +476,8 @@ Amount.prototype.canonicalize = function() {
}
}
// XXX Make sure not bigger than supported. Throw if so.
} else if (this.is_zero()) {
this._offset = -100;
this._offset = Amount.cMinOffset;
this._is_negative = false;
} else {
// Normalize mantissa to valid range.
@@ -465,6 +493,16 @@ Amount.prototype.canonicalize = function() {
}
}
// Make sure not bigger than supported. Throw if so.
if (this.is_negative() && this._offset < Amount.cMinOffset) {
throw new Error('Exceeding min value of ' + Amount.min_value);
}
// Make sure not smaller than supported. Throw if so.
if (!this.is_negative() && this._offset > Amount.cMaxOffset) {
throw new Error('Exceeding max value of ' + Amount.max_value);
}
return this;
};
@@ -539,9 +577,7 @@ Amount.prototype.equals = function(d, ignore_issuer) {
return this.equals(Amount.from_json(d));
}
var result = true;
result = !((!this.is_valid() || !d.is_valid())
var result = !((!this.is_valid() || !d.is_valid())
|| (this._is_native !== d._is_native)
|| (!this._value.equals(d._value) || this._offset !== d._offset)
|| (this._is_negative !== d._is_negative)
@@ -1111,17 +1147,27 @@ Amount.prototype.to_human = function(opts) {
if (fraction_part.length || !opts.skip_empty_fraction) {
// Enforce the maximum number of decimal digits (precision)
if (typeof opts.precision === 'number') {
if (opts.precision === 0 && fraction_part.charCodeAt(0) >= 53) {
var precision = Math.max(0, opts.precision);
precision = Math.min(precision, fraction_part.length);
var rounded = Number('0.' + fraction_part).toFixed(precision);
if (rounded < 1) {
fraction_part = rounded.substring(2);
} else {
int_part = (Number(int_part) + 1).toString();
fraction_part = '';
}
while (fraction_part.length < precision) {
fraction_part = '0' + fraction_part;
}
fraction_part = fraction_part.slice(0, opts.precision);
}
// Limit the number of significant digits (max_sig_digits)
if (typeof opts.max_sig_digits === 'number') {
// First, we count the significant digits we have.
// A zero in the integer part does not count.
var int_is_zero = +int_part === 0;
var int_is_zero = Number(int_part) === 0;
var digits = int_is_zero ? 0 : int_part.length;
// Don't count leading zeros in the fractional part if the integer part is
@@ -1147,6 +1193,7 @@ Amount.prototype.to_human = function(opts) {
// Enforce the minimum number of decimal digits (min_precision)
if (typeof opts.min_precision === 'number') {
opts.min_precision = Math.max(0, opts.min_precision);
while (fraction_part.length < opts.min_precision) {
fraction_part += '0';
}
@@ -1179,7 +1226,7 @@ Amount.prototype.to_human_full = function(opts) {
var a = this.to_human(opts);
var c = this._currency.to_human();
var i = this._issuer.to_json(opts);
var o = this.is_native ? (o = a + '/' + c) : (o = a + '/' + c + '/' + i);
var o = this.is_native() ? (o = a + '/' + c) : (o = a + '/' + c + '/' + i);
return o;
};

View File

@@ -106,7 +106,8 @@ var FIELDS_MAP = exports.fields = {
16: 'BookDirectory',
17: 'InvoiceID',
18: 'Nickname',
19: 'Feature'
19: 'Amendment',
20: 'TicketID'
},
6: { // Amount
1: 'Amount',
@@ -135,7 +136,8 @@ var FIELDS_MAP = exports.fields = {
10: 'ExpireCode',
11: 'CreateCode',
12: 'MemoType',
13: 'MemoData'
13: 'MemoData',
14: 'MemoFormat'
},
8: { // Account
1: 'Account',
@@ -187,7 +189,7 @@ var FIELDS_MAP = exports.fields = {
19: { // Vector256
1: 'Indexes',
2: 'Hashes',
3: 'Features'
3: 'Amendments'
}
};
@@ -382,23 +384,32 @@ exports.metadata = [
];
exports.ter = {
tesSUCCESS: 0,
tecCLAIM: 100,
tecPATH_PARTIAL: 101,
tecUNFUNDED_ADD: 102,
tecUNFUNDED_OFFER: 103,
tecUNFUNDED_PAYMENT: 104,
tecFAILED_PROCESSING: 105,
tecDIR_FULL: 121,
tecINSUF_RESERVE_LINE: 122,
tecINSUF_RESERVE_OFFER: 123,
tecNO_DST: 124,
tecNO_DST_INSUF_XRP: 125,
tecNO_LINE_INSUF_RESERVE: 126,
tecNO_LINE_REDUNDANT: 127,
tecPATH_DRY: 128,
tecUNFUNDED: 129,
tecMASTER_DISABLED: 130,
tecNO_REGULAR_KEY: 131,
tecOWNERS: 132
tesSUCCESS : 0,
tecCLAIM : 100,
tecPATH_PARTIAL : 101,
tecUNFUNDED_ADD : 102,
tecUNFUNDED_OFFER : 103,
tecUNFUNDED_PAYMENT : 104,
tecFAILED_PROCESSING : 105,
tecDIR_FULL : 121,
tecINSUF_RESERVE_LINE : 122,
tecINSUF_RESERVE_OFFER : 123,
tecNO_DST : 124,
tecNO_DST_INSUF_XRP : 125,
tecNO_LINE_INSUF_RESERVE : 126,
tecNO_LINE_REDUNDANT : 127,
tecPATH_DRY : 128,
tecUNFUNDED : 129, // Deprecated, old ambiguous unfunded.
tecMASTER_DISABLED : 130,
tecNO_REGULAR_KEY : 131,
tecOWNERS : 132,
tecNO_ISSUER : 133,
tecNO_AUTH : 134,
tecNO_LINE : 135,
tecINSUFF_FEE : 136,
tecFROZEN : 137,
tecNO_TARGET : 138,
tecNO_PERMISSION : 139,
tecNO_ENTRY : 140,
tecINSUFFICIENT_RESERVE : 141
};

View File

@@ -119,7 +119,9 @@ BlobObj.prototype.init = function(fn) {
self.revision = resp.body.revision;
self.encrypted_secret = resp.body.encrypted_secret;
self.identity_id = resp.body.identity_id;
self.missing_fields = resp.body.missing_fields;
//self.attestations = resp.body.attestation_summary;
if (!self.decrypt(resp.body.blob)) {
return fn(new Error('Error while decrypting blob'));
@@ -561,7 +563,6 @@ BlobObj.prototype.get2FA = function (fn) {
* @params {boolean} options.enabled
* @params {string} options.phone
* @params {string} options.country_code
* @params {string} options.via //sms, etc
*/
BlobObj.prototype.set2FA = function(options, fn) {
@@ -572,8 +573,7 @@ BlobObj.prototype.set2FA = function(options, fn) {
data : {
enabled : options.enabled,
phone : options.phone,
country_code : options.country_code,
via : options.via
country_code : options.country_code
}
};
@@ -1115,48 +1115,6 @@ BlobClient.recoverBlob = function (opts, fn) {
};
};
/**
* updateProfile
* update information stored outside the blob - HMAC signed
* @param {object}
* @param {string} opts.url
* @param {string} opts.username
* @param {string} opts.auth_secret
* @param {srring} opts.blob_id
* @param {object} opts.profile
* @param {string} opts.profile.phone - optional
* @param {string} opts.profile.country - optional
* @param {string} opts.profile.region - optional
* @param {string} opts.profile.city - optional
*/
BlobClient.updateProfile = function (opts, fn) {
var config = {
method: 'POST',
url: opts.url + '/v1/user/' + opts.username + '/profile',
dataType: 'json',
data: opts.profile
};
var signedRequest = new SignedRequest(config);
var signed = signedRequest.signHmac(opts.auth_secret, opts.blob_id);
request.post(signed.url)
.send(signed.data)
.end(function(err, resp) {
if (err) {
log.error('updateProfile:', err);
fn(new Error('Failed to update profile - XHR error'));
} else if (resp.body && resp.body.result === 'success') {
fn(null, resp.body);
} else if (resp.body) {
log.error('updateProfile:', resp.body);
} else {
fn(new Error('Failed to update profile'));
}
});
};
/**
* updateKeys
@@ -1320,6 +1278,7 @@ BlobClient.create = function(options, fn) {
if (err) {
fn(err);
} else if (resp.body && resp.body.result === 'success') {
blob.identity_id = resp.body.identity_id;
fn(null, blob, resp.body);
} else if (resp.body && resp.body.result === 'error') {
fn(new Error(resp.body.message));
@@ -1363,4 +1322,263 @@ BlobClient.deleteBlob = function(options, fn) {
});
};
/*** identity related functions ***/
/**
* updateProfile
* update information stored outside the blob - HMAC signed
* @param {object}
* @param {string} opts.url
* @param {string} opts.auth_secret
* @param {srring} opts.blob_id
* @param {object} opts.profile
* @param {array} opts.profile.attributes (optional, array of attribute objects)
* @param {array} opts.profile.addresses (optional, array of address objects)
*
* @param {string} attribute.id ... id of existing attribute
* @param {string} attribute.name ... attribute name i.e. ripple_address
* @param {string} attribute.type ... optional, sub-type of attribute
* @param {string} attribute.value ... value of attribute
* @param {string} attribute.domain ... corresponding domain
* @param {string} attribute.status ... “current”, “removed”, etc.
* @param {string} attribute.visibitlity ... “public”, ”private”
*/
BlobClient.updateProfile = function (opts, fn) {
var config = {
method: 'POST',
url: opts.url + '/v1/profile/',
dataType: 'json',
data: opts.profile
};
var signedRequest = new SignedRequest(config);
var signed = signedRequest.signHmac(opts.auth_secret, opts.blob_id);
request.post(signed.url)
.send(signed.data)
.end(function(err, resp) {
if (err) {
log.error('updateProfile:', err);
fn(new Error('Failed to update profile - XHR error'));
} else if (resp.body && resp.body.result === 'success') {
fn(null, resp.body);
} else if (resp.body) {
log.error('updateProfile:', resp.body);
fn(new Error('Failed to update profile'));
} else {
fn(new Error('Failed to update profile'));
}
});
};
/**
* getProfile
* @param {Object} opts
* @param {string} opts.url
* @param {string} opts.auth_secret
* @param {srring} opts.blob_id
*/
BlobClient.getProfile = function (opts, fn) {
var config = {
method: 'GET',
url: opts.url + '/v1/profile/'
};
var signedRequest = new SignedRequest(config);
var signed = signedRequest.signHmac(opts.auth_secret, opts.blob_id);
request.get(signed.url)
.send(signed.data)
.end(function(err, resp) {
if (err) {
log.error('getProfile:', err);
fn(new Error('Failed to get profile - XHR error'));
} else if (resp.body && resp.body.result === 'success') {
fn(null, resp.body);
} else if (resp.body) {
log.error('getProfile:', resp.body);
fn(new Error('Failed to get profile'));
} else {
fn(new Error('Failed to get profile'));
}
});
};
/**
* getAttestation
* @param {Object} opts
* @param {string} opts.url
* @param {string} opts.auth_secret
* @param {string} opts.blob_id
* @param {string} opts.type (email,phone,basic_identity)
* @param {object} opts.phone (required for type 'phone')
* @param {string} opts.email (required for type 'email')
*/
BlobClient.getAttestation = function (opts, fn) {
var params = { };
if (opts.phone) params.phone = opts.phone;
if (opts.email) params.email = opts.email;
var config = {
method: 'POST',
url: opts.url + '/v1/attestation/' + opts.type,
dataType: 'json',
data: params
};
var signedRequest = new SignedRequest(config);
var signed = signedRequest.signHmac(opts.auth_secret, opts.blob_id);
request.post(signed.url)
.send(signed.data)
.end(function(err, resp) {
if (err) {
log.error('attest:', err);
fn(new Error('attestation error - XHR error'));
} else if (resp.body && resp.body.result === 'success') {
if (resp.body.attestation) {
resp.body.decoded = BlobClient.parseAttestation(resp.body.attestation);
}
fn(null, resp.body);
} else if (resp.body) {
log.error('attestation:', resp.body);
fn(new Error('attestation error: ' + resp.body.message || ""));
} else {
fn(new Error('attestation error'));
}
});
};
/**
* getAttestationSummary
* @param {Object} opts
* @param {string} opts.url
* @param {string} opts.auth_secret
* @param {string} opts.blob_id
*/
BlobClient.getAttestationSummary = function (opts, fn) {
var config = {
method: 'GET',
url: opts.url + '/v1/attestation/summary',
dataType: 'json'
};
if (opts.full) config.url += '?full=true';
var signedRequest = new SignedRequest(config);
var signed = signedRequest.signHmac(opts.auth_secret, opts.blob_id);
request.get(signed.url)
.send(signed.data)
.end(function(err, resp) {
if (err) {
log.error('attest:', err);
fn(new Error('attestation error - XHR error'));
} else if (resp.body && resp.body.result === 'success') {
if (resp.body.attestation) {
resp.body.decoded = BlobClient.parseAttestation(resp.body.attestation);
}
fn(null, resp.body);
} else if (resp.body) {
log.error('attestation:', resp.body);
fn(new Error('attestation error: ' + resp.body.message || ""));
} else {
fn(new Error('attestation error'));
}
});
};
/**
* updateAttestation
* @param {Object} opts
* @param {string} opts.url
* @param {string} opts.auth_secret
* @param {string} opts.blob_id
* @param {string} opts.type (email,phone,profile,identity)
* @param {object} opts.phone (required for type 'phone')
* @param {object} opts.profile (required for type 'profile')
* @param {string} opts.email (required for type 'email')
* @param {string} opts.answers (required for type 'identity')
* @param {string} opts.token (required for completing email or phone attestations)
*/
BlobClient.updateAttestation = function (opts, fn) {
var params = { };
if (opts.phone) params.phone = opts.phone;
if (opts.profile) params.profile = opts.profile;
if (opts.email) params.email = opts.email;
if (opts.token) params.token = opts.token;
if (opts.answers) params.answers = opts.answers;
var config = {
method: 'POST',
url: opts.url + '/v1/attestation/' + opts.type + '/update',
dataType: 'json',
data: params
};
var signedRequest = new SignedRequest(config);
var signed = signedRequest.signHmac(opts.auth_secret, opts.blob_id);
request.post(signed.url)
.send(signed.data)
.end(function(err, resp) {
if (err) {
log.error('attest:', err);
fn(new Error('attestation error - XHR error'));
} else if (resp.body && resp.body.result === 'success') {
if (resp.body.attestation) {
resp.body.decoded = BlobClient.parseAttestation(resp.body.attestation);
}
fn(null, resp.body);
} else if (resp.body) {
log.error('attestation:', resp.body);
fn(new Error('attestation error: ' + resp.body.message || ""));
} else {
fn(new Error('attestation error'));
}
});
};
/**
* parseAttestation
* @param {Object} attestation
*/
BlobClient.parseAttestation = function (attestation) {
var segments = decodeURIComponent(attestation).split('.');
var decoded;
// base64 decode and parse JSON
try {
decoded = {
header : JSON.parse(crypt.decodeBase64(segments[0])),
payload : JSON.parse(crypt.decodeBase64(segments[1])),
signature : segments[2]
};
} catch (e) {
console.log("invalid attestation:", e);
}
return decoded;
};
exports.BlobClient = BlobClient;

View File

@@ -322,4 +322,12 @@ Crypt.base64UrlToBase64 = function(encodedData) {
return encodedData;
};
/**
* base64 to UTF8
*/
Crypt.decodeBase64 = function (data) {
return sjcl.codec.utf8String.fromBits(sjcl.codec.base64.toBits(data));
}
exports.Crypt = Crypt;

View File

@@ -50,14 +50,10 @@ Currency.HEX_CURRENCY_BAD = '0000000000000000000000005852500000000000';
* \s*$ // end with any amount of whitespace
*
*/
Currency.prototype.human_RE = /^\s*([a-zA-Z]{3}|[0-9]{3})(\s*-\s*[- \w]+)?(\s*\(-?\d+\.?\d*%pa\))?\s*$/;
Currency.prototype.human_RE = /^\s*([a-zA-Z0-9]{3})(\s*-\s*[- \w]+)?(\s*\(-?\d+\.?\d*%pa\))?\s*$/;
Currency.from_json = function(j, shouldInterpretXrpAsIou) {
if (j instanceof this) {
return j.clone();
} else {
return (new this()).parse_json(j, shouldInterpretXrpAsIou);
}
return (new Currency()).parse_json(j, shouldInterpretXrpAsIou);
};
Currency.from_human = function(j, opts) {
@@ -71,12 +67,9 @@ Currency.prototype.parse_json = function(j, shouldInterpretXrpAsIou) {
switch (typeof j) {
case 'string':
if (!j || /^(0|XRP)$/.test(j)) {
if (shouldInterpretXrpAsIou) {
this.parse_hex(Currency.HEX_CURRENCY_BAD);
} else {
this.parse_hex(Currency.HEX_ZERO);
}
// if an empty string is given, fall back to XRP
if (!j || j === '0') {
this.parse_hex(shouldInterpretXrpAsIou ? Currency.HEX_CURRENCY_BAD : Currency.HEX_ZERO);
break;
}
@@ -86,6 +79,17 @@ Currency.prototype.parse_json = function(j, shouldInterpretXrpAsIou) {
if (matches) {
var currencyCode = matches[1];
// for the currency 'XRP' case
// we drop everything else that could have been provided
// e.g. 'XRP - Ripple'
if (!currencyCode || /^(0|XRP)$/.test(currencyCode)) {
this.parse_hex(shouldInterpretXrpAsIou ? Currency.HEX_CURRENCY_BAD : Currency.HEX_ZERO);
// early break, we can't have interest on XRP
break;
}
// the full currency is matched as it is part of the valid currency format, but not stored
// var full_currency = matches[2] || '';
var interest = matches[3] || '';
@@ -270,7 +274,7 @@ Currency.prototype.has_interest = function() {
* @returns {number} - interest for provided interval, can be negative for demurred currencies
*/
Currency.prototype.get_interest_at = function(referenceDate, decimals) {
if (!this.has_interest) {
if (!this.has_interest()) {
return 0;
}
@@ -316,17 +320,17 @@ Currency.prototype.to_json = function(opts) {
var opts = opts || {};
var currency;
var fullName = opts && opts.full_name ? " - " + opts.full_name : "";
var fullName = opts && opts.full_name ? ' - ' + opts.full_name : '';
opts.show_interest = opts.show_interest !== void(0) ? opts.show_interest : this.has_interest();
// Any currency with standard properties and a valid code can be abbreviated
// in the JSON wire format as the three character code.
if (!opts.force_hex && /^[A-Z0-9]{3}$/.test(this._iso_code) && !this.has_interest()) {
if (!opts.force_hex && /^[A-Z0-9]{3}$/.test(this._iso_code)) {
currency = this._iso_code + fullName;
if (opts.show_interest) {
var decimals = !isNaN(opts.decimals) ? opts.decimals : void(0);
var interestPercentage = this.has_interest() ? this.get_interest_percentage_at(this._interest_start + 3600 * 24 * 365, decimals) : 0;
currency += ' (' + interestPercentage + '%pa)';
}
// If there is interest, append the annual interest to the full currency name
} else if (!opts.force_hex && this.has_interest()) {
var decimals = opts ? opts.decimals : undefined;
currency = this._iso_code + fullName + " (" + this.get_interest_percentage_at(this._interest_start + 3600 * 24 * 365, decimals) + "%pa)";
} else {
// Fallback to returning the raw currency hex

View File

@@ -18,6 +18,7 @@ exports.RippleTxt = require('./rippletxt').RippleTxt;
exports.binformat = require('./binformat');
exports.utils = require('./utils');
exports.Server = require('./server').Server;
exports.Wallet = require('./wallet');
// Important: We do not guarantee any specific version of SJCL or for any
// specific features to be included. The version and configuration may change at

View File

@@ -77,33 +77,27 @@ function OrderBook(remote, getsC, getsI, paysC, paysI, key) {
listenersModified('remove', event);
});
this.on('unsubscribe', function() {
self._ownerFunds = { };
self._remote.removeListener('transaction', updateFundedAmounts);
self._remote.removeListener('transaction', updateTransferRate);
});
this._remote.on('prepare_subscribe', function() {
self.subscribe();
});
this._remote.on('disconnect', function() {
self._ownerFunds = { };
self._offerCounts = { };
self._synchronized = false;
});
function updateFundedAmounts(message) {
self.updateFundedAmounts(message);
function updateFundedAmounts(transaction) {
self.updateFundedAmounts(transaction);
};
this._remote.on('transaction', updateFundedAmounts);
function updateTransferRate(message) {
self.updateTransferRate(message);
};
this.on('unsubscribe', function() {
self.resetCache();
self._remote.removeListener('transaction', updateFundedAmounts);
});
this._remote.on('transaction', updateTransferRate);
this._remote.once('prepare_subscribe', function() {
self.subscribe();
});
this._remote.on('disconnect', function() {
self.resetCache();
self._remote.once('prepare_subscribe', function() {
self.subscribe();
});
});
return this;
};
@@ -114,30 +108,15 @@ util.inherits(OrderBook, EventEmitter);
* Events emitted from OrderBook
*/
OrderBook.EVENTS = [ 'transaction', 'model', 'trade', 'offer' ];
OrderBook.EVENTS = [
'transaction', 'model', 'trade',
'offer_added', 'offer_removed',
'offer_changed', 'offer_funds_changed'
];
OrderBook.DEFAULT_TRANSFER_RATE = 1000000000;
/**
* Whether the OrderBook is valid.
*
* Note: This only checks whether the parameters (currencies and issuer) are
* syntactically valid. It does not check anything against the ledger.
*
* @return {Boolean} is valid
*/
OrderBook.prototype.isValid =
OrderBook.prototype.is_valid = function() {
// XXX Should check for same currency (non-native) && same issuer
return (
this._currencyPays && this._currencyPays.is_valid() &&
(this._currencyPays.is_native() || UInt160.is_valid(this._issuerPays)) &&
this._currencyGets && this._currencyGets.is_valid() &&
(this._currencyGets.is_native() || UInt160.is_valid(this._issuerGets)) &&
!(this._currencyPays.is_native() && this._currencyGets.is_native())
);
};
OrderBook.IOU_SUFFIX = '/000/rrrrrrrrrrrrrrrrrrrrrhoLvTp';
/**
* Initialize orderbook. Get orderbook offers and subscribe to transactions
@@ -166,7 +145,7 @@ OrderBook.prototype.subscribe = function() {
}
];
async.series(steps, function(err) {
async.series(steps, function(err, res) {
//XXX What now?
});
};
@@ -195,6 +174,16 @@ OrderBook.prototype.unsubscribe = function() {
this.emit('unsubscribe');
};
/**
* Reset cached owner funds, offer counts
*/
OrderBook.prototype.resetCache = function() {
this._ownerFunds = { };
this._offerCounts = { };
this._synchronized = false;
};
/**
* Check that the funds for offer owner have been cached
*
@@ -297,8 +286,7 @@ OrderBook.prototype.applyTransferRate = function(balance, transferRate) {
return balance;
}
var iouSuffix = '/USD/rrrrrrrrrrrrrrrrrrrrBZbvji';
var adjustedBalance = Amount.from_json(balance + iouSuffix)
var adjustedBalance = Amount.from_json(balance + OrderBook.IOU_SUFFIX)
.divide(transferRate)
.multiply(Amount.from_json(OrderBook.DEFAULT_TRANSFER_RATE))
.to_json()
@@ -310,40 +298,41 @@ OrderBook.prototype.applyTransferRate = function(balance, transferRate) {
/**
* Request transfer rate for this orderbook's issuer
*
* @param [Function] calback
* @param {Function} callback
*/
OrderBook.prototype.requestTransferRate = function(callback) {
assert.strictEqual(typeof callback, 'function');
var self = this;
var issuer = this._issuerGets;
this.once('transfer_rate', function(rate) {
if (typeof callback === 'function') {
callback(null, rate);
}
});
if (this._currencyGets.is_native()) {
// Transfer rate is default
return this.emit('transfer_rate', OrderBook.DEFAULT_TRANSFER_RATE);
// Transfer rate is default (native currency)
callback(null, OrderBook.DEFAULT_TRANSFER_RATE);
return;
}
if (this._issuerTransferRate) {
// Transfer rate has been cached
return this.emit('transfer_rate', this._issuerTransferRate);
// Transfer rate has already been cached
callback(null, this._issuerTransferRate);
return;
}
this._remote.requestAccountInfo(issuer, function(err, info) {
this._remote.requestAccountInfo({ account: issuer }, function(err, info) {
if (err) {
// XXX What now?
return callback(err);
}
var transferRate = info.account_data.TransferRate
|| OrderBook.DEFAULT_TRANSFER_RATE;
var transferRate = info.account_data.TransferRate;
if (!transferRate) {
transferRate = OrderBook.DEFAULT_TRANSFER_RATE;
}
self._issuerTransferRate = transferRate;
self.emit('transfer_rate', transferRate);
callback(null, transferRate);
});
};
@@ -369,11 +358,10 @@ OrderBook.prototype.setFundedAmount = function(offer, fundedAmount) {
return offer;
}
var iouSuffix = '/' + this._currencyGets.to_json()
+ '/' + this._issuerGets;
offer.is_fully_funded = Amount.from_json(
this._currencyGets.is_native() ? fundedAmount : fundedAmount + iouSuffix
this._currencyGets.is_native()
? fundedAmount
: fundedAmount + OrderBook.IOU_SUFFIX
).compareTo(Amount.from_json(offer.TakerGets)) >= 0;
if (offer.is_fully_funded) {
@@ -384,40 +372,40 @@ OrderBook.prototype.setFundedAmount = function(offer, fundedAmount) {
offer.taker_gets_funded = fundedAmount;
var takerPaysValue = typeof offer.TakerPays === 'object'
var takerPaysValue = (typeof offer.TakerPays === 'object')
? offer.TakerPays.value
: offer.TakerPays;
var takerGetsValue = typeof offer.TakerGets === 'object'
var takerGetsValue = (typeof offer.TakerGets === 'object')
? offer.TakerGets.value
: offer.TakerGets;
var takerPays = Amount.from_json(
takerPaysValue + '/000/rrrrrrrrrrrrrrrrrrrrBZbvji'
);
var takerGets = Amount.from_json(
takerGetsValue + '/000/rrrrrrrrrrrrrrrrrrrrBZbvji'
);
var fundedPays = Amount.from_json(
fundedAmount + '/000/rrrrrrrrrrrrrrrrrrrrBZbvji'
);
var takerPays = Amount.from_json(takerPaysValue + OrderBook.IOU_SUFFIX);
var takerGets = Amount.from_json(takerGetsValue + OrderBook.IOU_SUFFIX);
var fundedPays = Amount.from_json(fundedAmount + OrderBook.IOU_SUFFIX);
var rate = takerPays.divide(takerGets);
fundedPays = fundedPays.multiply(rate);
if (fundedPays.compareTo(takerPays) < 0) {
offer.taker_pays_funded = fundedPays.to_json().value;
if (this._currencyPays.is_native()) {
fundedPays = String(parseInt(fundedPays.to_json().value, 10));
} else {
fundedPays = fundedPays.to_json().value;
}
} else {
offer.taker_pays_funded = takerPays.to_json().value;
fundedPays = takerPays.to_json().value;
}
offer.taker_pays_funded = fundedPays;
return offer;
};
/**
* DEPRECATED:
* Should only be called for old versions of rippled
*
* Determine what an account is funded to offer for orderbook's
* currency/issuer
*
@@ -436,7 +424,7 @@ OrderBook.prototype.requestFundedAmount = function(account, callback) {
}
function requestNativeBalance(callback) {
self._remote.requestAccountInfo(account, function(err, info) {
self._remote.requestAccountInfo({ account: account }, function(err, info) {
if (err) {
callback(err);
} else {
@@ -446,12 +434,11 @@ OrderBook.prototype.requestFundedAmount = function(account, callback) {
};
function requestLineBalance(callback) {
var request = self._remote.requestAccountLines(
account, // account
void(0), // account index
'VALIDATED', // ledger
self._issuerGets //peer
);
var request = self._remote.requestAccountLines({
account: account,
ledger: 'validated',
peer: self._issuerGets
});
request.request(function(err, res) {
if (err) {
@@ -590,10 +577,10 @@ OrderBook.prototype.isBalanceChange = function(node) {
* @param {Object} transaction
*/
OrderBook.prototype.updateFundedAmounts = function(message) {
OrderBook.prototype.updateFundedAmounts = function(transaction) {
var self = this;
var affectedAccounts = message.mmeta.getAffectedAccounts();
var affectedAccounts = transaction.mmeta.getAffectedAccounts();
var isOwnerAffected = affectedAccounts.some(function(account) {
return self.hasCachedFunds(account);
@@ -605,25 +592,23 @@ OrderBook.prototype.updateFundedAmounts = function(message) {
if (!this._currencyGets.is_native() && !this._issuerTransferRate) {
// Defer until transfer rate is requested
if (self._remote.trace) {
if (this._remote.trace) {
log.info('waiting for transfer rate');
}
this.once('transfer_rate', function() {
self.updateFundedAmounts(message);
this.requestTransferRate(function() {
self.updateFundedAmounts(transaction);
});
this.requestTransferRate();
return;
}
var nodes = message.mmeta.getNodes({
var affectedNodes = transaction.mmeta.getNodes({
nodeType: 'ModifiedNode',
entryType: this._currencyGets.is_native() ? 'AccountRoot' : 'RippleState'
});
for (var i=0; i<nodes.length; i++) {
var node = nodes[i];
for (var i=0, l=affectedNodes.length; i<l; i++) {
var node = affectedNodes[i];
if (!this.isBalanceChange(node)) {
continue;
@@ -631,39 +616,72 @@ OrderBook.prototype.updateFundedAmounts = function(message) {
var result = this.getBalanceChange(node);
if (result.isValid) {
if (this.hasCachedFunds(result.account)) {
this.updateOfferFunds(result.account, result.balance);
}
if (result.isValid && this.hasCachedFunds(result.account)) {
this.updateAccountFunds(result.account, result.balance);
}
}
};
/**
* Update issuer's TransferRate as it changes
* Normalize offers from book_offers and transaction stream
*
* @param {Object} transaction
* @param {Object} offer
* @return {Object} normalized
*/
OrderBook.prototype.updateTransferRate = function(message) {
var self = this;
OrderBook.offerRewrite = function(offer) {
var result = { };
var keys = Object.keys(offer);
var affectedAccounts = message.mmeta.getAffectedAccounts();
var isIssuerAffected = affectedAccounts.some(function(account) {
return account === self._issuerGets;
});
if (!isIssuerAffected) {
return;
for (var i=0, l=keys.length; i<l; i++) {
var key = keys[i];
switch (key) {
case 'PreviousTxnID':
case 'PreviousTxnLgrSeq':
case 'quality':
break;
default:
result[key] = offer[key];
}
}
// XXX Update transfer rate
//
// var nodes = message.mmeta.getNodes({
// nodeType: 'ModifiedNode',
// entryType: 'AccountRoot'
// });
result.Flags = result.Flags || 0;
result.OwnerNode = result.OwnerNode || new Array(16 + 1).join('0');
result.BookNode = result.BookNode || new Array(16 + 1).join('0');
return result;
};
/**
* Reset internal offers cache from book_offers request
*
* @param {Array} offers
* @api private
*/
OrderBook.prototype.setOffers = function(offers) {
assert(Array.isArray(offers));
var newOffers = [ ];
for (var i=0, l=offers.length; i<l; i++) {
var offer = OrderBook.offerRewrite(offers[i]);
var fundedAmount;
if (this.hasCachedFunds(offer.Account)) {
fundedAmount = this.getCachedFunds(offer.Account);
} else if (offer.hasOwnProperty('owner_funds')) {
fundedAmount = this.applyTransferRate(offer.owner_funds);
this.addCachedFunds(offer.Account, fundedAmount);
}
this.setFundedAmount(offer, fundedAmount);
this.incrementOfferCount(offer.Account);
newOffers.push(offer);
}
this._offers = newOffers;
};
/**
@@ -695,24 +713,8 @@ OrderBook.prototype.requestOffers = function(callback) {
log.info('requested offers', self._key, 'offers: ' + res.offers.length);
}
for (var i=0, l=res.offers.length; i<l; i++) {
var offer = res.offers[i];
var fundedAmount;
if (self.hasCachedFunds(offer.Account)) {
fundedAmount = self.getCachedFunds(offer.Account);
} else if (offer.hasOwnProperty('owner_funds')) {
fundedAmount = self.applyTransferRate(offer.owner_funds);
self.addCachedFunds(offer.Account, fundedAmount);
}
self.setFundedAmount(offer, fundedAmount);
self.incrementOfferCount(offer.Account);
self._offers.push(offer);
}
self.setOffers(res.offers);
self._synchronized = true;
self.emit('model', self._offers);
callback(null, self._offers);
@@ -824,6 +826,57 @@ OrderBook.prototype.getOffersSync = function() {
return this._offers;
};
/**
* Update offers whose account's funds have changed
*
* @param {String} account address
* @param {String|Object} offer funds
*/
OrderBook.prototype.updateAccountFunds = function(account, balance) {
assert(UInt160.is_valid(account), 'Account is invalid');
assert(!isNaN(balance), 'Funded amount is invalid');
if (this._remote.trace) {
log.info('updating offer funds', this._key, account, fundedAmount);
}
var fundedAmount = this.applyTransferRate(balance);
// Update cached account funds
this.addCachedFunds(account, fundedAmount);
for (var i=0, l=this._offers.length; i<l; i++) {
var offer = this._offers[i];
if (offer.Account !== account) {
continue;
}
var previousOffer = extend({ }, offer);
var previousFundedGets = Amount.from_json(
offer.taker_gets_funded + OrderBook.IOU_SUFFIX
);
offer.owner_funds = balance;
this.setFundedAmount(offer, fundedAmount);
var hasChangedFunds = !previousFundedGets.equals(
Amount.from_json(offer.taker_gets_funded + OrderBook.IOU_SUFFIX)
);
if (!hasChangedFunds) {
continue;
}
this.emit('offer_changed', previousOffer, offer);
this.emit('offer_funds_changed', offer,
previousOffer.taker_gets_funded,
offer.taker_gets_funded
);
}
};
/**
* Insert an offer into the orderbook
*
@@ -835,8 +888,8 @@ OrderBook.prototype.insertOffer = function(node, fundedAmount) {
log.info('inserting offer', this._key, node.fields);
}
var nodeFields = node.fields;
var nodeFields = OrderBook.offerRewrite(node.fields);
nodeFields.LedgerEntryType = node.entryType;
nodeFields.index = node.ledgerIndex;
if (!isNaN(fundedAmount)) {
@@ -887,7 +940,7 @@ OrderBook.prototype.modifyOffer = function(node, isDeletedNode) {
}
}
for (var i=0; i<this._offers.length; i++) {
for (var i=0, l=this._offers.length; i<l; i++) {
var offer = this._offers[i];
if (offer.index === node.ledgerIndex) {
if (isDeletedNode) {
@@ -906,57 +959,6 @@ OrderBook.prototype.modifyOffer = function(node, isDeletedNode) {
}
};
/**
* Update funded status on offers whose account's balance has changed
*
* Update cached account funds
*
* @param {String} account address
* @param {String|Object} offer funds
*/
OrderBook.prototype.updateOfferFunds = function(account, balance) {
assert(UInt160.is_valid(account), 'Account is invalid');
assert(!isNaN(balance), 'Funded amount is invalid');
if (this._remote.trace) {
log.info('updating offer funds', this._key, account, fundedAmount);
}
var fundedAmount = this.applyTransferRate(balance);
// Update cached account funds
this.addCachedFunds(account, fundedAmount);
for (var i=0; i<this._offers.length; i++) {
var offer = this._offers[i];
if (offer.Account !== account) {
continue;
}
var suffix = '/USD/rrrrrrrrrrrrrrrrrrrrBZbvji';
var previousOffer = extend({}, offer);
var previousFundedGets = Amount.from_json(offer.taker_gets_funded + suffix);
offer.owner_funds = balance;
this.setFundedAmount(offer, fundedAmount);
var hasChangedFunds = !previousFundedGets.equals(
Amount.from_json(offer.taker_gets_funded + suffix)
);
if (hasChangedFunds) {
this.emit('offer_changed', previousOffer, offer);
this.emit(
'offer_funds_changed', offer,
previousOffer.taker_gets_funded,
offer.taker_gets_funded
);
}
}
};
/**
* Notify orderbook of a relevant transaction
*
@@ -964,7 +966,7 @@ OrderBook.prototype.updateOfferFunds = function(account, balance) {
* @api private
*/
OrderBook.prototype.notify = function(message) {
OrderBook.prototype.notify = function(transaction) {
var self = this;
// Unsubscribed from OrderBook
@@ -972,7 +974,7 @@ OrderBook.prototype.notify = function(message) {
return;
}
var affectedNodes = message.mmeta.getNodes({
var affectedNodes = transaction.mmeta.getNodes({
entryType: 'Offer',
bookKey: this._key
});
@@ -982,7 +984,7 @@ OrderBook.prototype.notify = function(message) {
}
if (this._remote.trace) {
log.info('notifying', this._key, message.transaction.hash);
log.info('notifying', this._key, transaction.transaction.hash);
}
var tradeGets = Amount.from_json(
@@ -999,7 +1001,7 @@ OrderBook.prototype.notify = function(message) {
function handleNode(node, callback) {
var isDeletedNode = node.nodeType === 'DeletedNode';
var isOfferCancel = message.transaction.TransactionType === 'OfferCancel';
var isOfferCancel = transaction.transaction.TransactionType === 'OfferCancel';
switch (node.nodeType) {
case 'DeletedNode':
@@ -1026,7 +1028,7 @@ OrderBook.prototype.notify = function(message) {
case 'CreatedNode':
self.incrementOfferCount(node.fields.Account);
var fundedAmount = message.transaction.owner_funds;
var fundedAmount = transaction.transaction.owner_funds;
if (!isNaN(fundedAmount)) {
self.insertOffer(node, fundedAmount);
@@ -1048,7 +1050,7 @@ OrderBook.prototype.notify = function(message) {
};
async.eachSeries(affectedNodes, handleNode, function() {
self.emit('transaction', message);
self.emit('transaction', transaction);
self.emit('model', self._offers);
if (!tradeGets.is_zero()) {
self.emit('trade', tradePays, tradeGets);
@@ -1084,6 +1086,27 @@ OrderBook.prototype.to_json = function() {
return json;
};
/**
* Whether the OrderBook is valid.
*
* Note: This only checks whether the parameters (currencies and issuer) are
* syntactically valid. It does not check anything against the ledger.
*
* @return {Boolean} is valid
*/
OrderBook.prototype.isValid =
OrderBook.prototype.is_valid = function() {
// XXX Should check for same currency (non-native) && same issuer
return (
this._currencyPays && this._currencyPays.is_valid() &&
(this._currencyPays.is_native() || UInt160.is_valid(this._issuerPays)) &&
this._currencyGets && this._currencyGets.is_valid() &&
(this._currencyGets.is_native() || UInt160.is_valid(this._issuerGets)) &&
!(this._currencyPays.is_native() && this._currencyGets.is_native())
);
};
exports.OrderBook = OrderBook;
// vim:sw=2:sts=2:ts=8:et

View File

@@ -15,6 +15,7 @@
var EventEmitter = require('events').EventEmitter;
var util = require('util');
var assert = require('assert');
var LRU = require('lru-cache');
var Server = require('./server').Server;
var Request = require('./request').Request;
@@ -22,6 +23,7 @@ var Server = require('./server').Server;
var Amount = require('./amount').Amount;
var Currency = require('./currency').Currency;
var UInt160 = require('./uint160').UInt160;
var UInt256 = require('./uint256').UInt256;
var Transaction = require('./transaction').Transaction;
var Account = require('./account').Account;
var Meta = require('./meta').Meta;
@@ -91,7 +93,9 @@ function Remote(opts, trace) {
this.canonical_signing = (typeof opts.canonical_signing === 'boolean') ? opts.canonical_signing : true;
this.fee_cushion = (typeof opts.fee_cushion === 'number') ? opts.fee_cushion : 1.2;
this.max_fee = (typeof opts.max_fee === 'number') ? opts.max_fee : Infinity;
this.max_fee = (typeof opts.max_fee === 'number') ? opts.max_fee : 1000000; // default max fee is 1 XRP, 10^6 drops
this.max_attempts = (typeof opts.max_attempts === 'number') ? opts.max_attempts : 10;
this._ledger_current_index = void(0);
this._ledger_hash = void(0);
@@ -209,7 +213,7 @@ function Remote(opts, trace) {
function listenerAdded(type, listener) {
if (type === 'transaction_all') {
if (!self._transaction_subs && self._connected) {
if (!self._transaction_subs && self.isConnected()) {
self.request_subscribe('transactions').request();
}
self._transaction_subs += 1;
@@ -221,7 +225,7 @@ function Remote(opts, trace) {
function listenerRemoved(type, listener) {
if (type === 'transaction_all') {
self._transaction_subs -= 1;
if (!self._transaction_subs && self._connected) {
if (!self._transaction_subs && self.isConnected()) {
self.request_unsubscribe('transactions').request();
}
}
@@ -243,7 +247,7 @@ function Remote(opts, trace) {
};
if (opts.ping) {
this.once('connect', pingServers);
this.on('connect', pingServers);
}
function reconnect() {
@@ -338,13 +342,11 @@ Remote.isValidLedgerData = function(message) {
return (typeof message === 'object')
&& (typeof message.fee_base === 'number')
&& (typeof message.fee_ref === 'number')
&& (typeof message.fee_base === 'number')
&& (typeof message.ledger_hash === 'string')
&& (typeof message.ledger_index === 'number')
&& (typeof message.ledger_time === 'number')
&& (typeof message.reserve_base === 'number')
&& (typeof message.reserve_inc === 'number')
&& (typeof message.txn_count === 'number');
&& (typeof message.reserve_inc === 'number');
};
/**
@@ -514,12 +516,9 @@ Remote.prototype.reconnect = function() {
log.info('reconnecting');
;(function nextServer(i) {
self._servers[i].reconnect();
if (++i < self._servers.length) {
nextServer(i);
}
})(0);
this._servers.forEach(function(server) {
server.reconnect();
});
return this;
};
@@ -553,12 +552,9 @@ Remote.prototype.connect = function(online) {
this._should_connect = true;
;(function nextServer(i) {
self._servers[i].connect();
if (++i < self._servers.length) {
nextServer(i);
}
})(0);
this._servers.forEach(function(server) {
server.connect();
});
return this;
};
@@ -577,7 +573,7 @@ Remote.prototype.disconnect = function(callback) {
var callback = (typeof callback === 'function') ? callback : function(){};
if (!this._connected) {
if (!this.isConnected()) {
callback();
return this;
}
@@ -622,16 +618,16 @@ Remote.prototype._handleMessage = function(message, server) {
switch (message.type) {
case 'ledgerClosed':
this._handleLedgerClosed(message);
this._handleLedgerClosed(message, server);
break;
case 'serverStatus':
this._handleServerStatus(message);
this._handleServerStatus(message, server);
break;
case 'transaction':
this._handleTransaction(message);
this._handleTransaction(message, server);
break;
case 'path_find':
this._handlePathFind(message);
this._handlePathFind(message, server);
break;
default:
if (this.trace) {
@@ -647,7 +643,7 @@ Remote.prototype._handleMessage = function(message, server) {
* @param {Object} message
*/
Remote.prototype._handleLedgerClosed = function(message) {
Remote.prototype._handleLedgerClosed = function(message, server) {
var self = this;
// XXX If not trusted, need to verify we consider ledger closed.
@@ -660,11 +656,19 @@ Remote.prototype._handleLedgerClosed = function(message) {
var ledgerAdvanced = message.ledger_index >= this._ledger_current_index;
if (ledgerAdvanced) {
if (isNaN(this._ledger_current_index) || ledgerAdvanced) {
this._ledger_time = message.ledger_time;
this._ledger_hash = message.ledger_hash;
this._ledger_current_index = message.ledger_index + 1;
this.emit('ledger_closed', message);
if (this.isConnected()) {
this.emit('ledger_closed', message, server);
} else {
this.once('connect', function() {
// Delay until server is 'online'
self.emit('ledger_closed', message, server);
});
}
}
};
@@ -674,8 +678,8 @@ Remote.prototype._handleLedgerClosed = function(message) {
* @param {Object} message
*/
Remote.prototype._handleServerStatus = function(message) {
this.emit('server_status', message);
Remote.prototype._handleServerStatus = function(message, server) {
this.emit('server_status', message, server);
};
/**
@@ -684,7 +688,7 @@ Remote.prototype._handleServerStatus = function(message) {
* @param {Object} message
*/
Remote.prototype._handleTransaction = function(message) {
Remote.prototype._handleTransaction = function(message, server) {
var self = this;
// XXX If not trusted, need proof.
@@ -731,8 +735,8 @@ Remote.prototype._handleTransaction = function(message) {
});
}
this.emit('transaction', message);
this.emit('transaction_all', message);
this.emit('transaction', message, server);
this.emit('transaction_all', message, server);
};
/**
@@ -741,7 +745,7 @@ Remote.prototype._handleTransaction = function(message) {
* @param {Object} message
*/
Remote.prototype._handlePathFind = function(message) {
Remote.prototype._handlePathFind = function(message, server) {
var self = this;
// Pass the event to the currently open PathFind object
@@ -749,7 +753,7 @@ Remote.prototype._handlePathFind = function(message) {
this._cur_path_find.notify_update(message);
}
this.emit('path_find_all', message);
this.emit('path_find_all', message, server);
};
/**
@@ -819,6 +823,10 @@ Remote.prototype.getServer = function() {
}
var connectedServers = this.getConnectedServers();
if (connectedServers.length === 0 || !connectedServers[0]) {
return null;
}
var server = connectedServers[0];
var cScore = server._score + server._fee;
@@ -861,7 +869,7 @@ Remote.prototype.request = function(request) {
if (!this._servers.length) {
request.emit('error', new Error('No servers available'));
} else if (!this._connected) {
} else if (!this.isConnected()) {
this.once('connect', this.request.bind(this, request));
} else if (request.server === null) {
request.emit('error', new Error('Server does not exist'));
@@ -924,21 +932,22 @@ Remote.prototype.requestServerInfo = function(callback) {
* @return {Request} request
*/
Remote.prototype.requestLedger = function(ledger, options, callback) {
Remote.prototype.requestLedger = function(options, callback) {
// XXX This is a bad command. Some variants don't scale.
// XXX Require the server to be trusted.
//utils.assert(this.trusted);
var request = new Request(this, 'ledger');
if (ledger) {
// DEPRECATED: use .ledger_hash() or .ledger_index()
//console.log('request_ledger: ledger parameter is deprecated');
request.message.ledger = ledger;
}
switch (typeof options) {
case 'undefined': break;
case 'function':
callback = options;
break;
case 'object':
if (!options) break;
Object.keys(options).forEach(function(o) {
switch (o) {
case 'full':
@@ -947,21 +956,21 @@ Remote.prototype.requestLedger = function(ledger, options, callback) {
case 'accounts':
request.message[o] = true;
break;
case 'ledger_index':
case 'ledger_hash':
request.message[o] = options[o];
break;
case 'closed' :
case 'current' :
case 'validated' :
request.message.ledger_index = o;
break;
}
}, options);
break;
case 'function':
callback = options;
options = void(0);
break;
default:
//DEPRECATED
if (this.trace) {
log.info('request_ledger: full parameter is deprecated');
}
request.message.full = true;
request.ledgerSelect(options);
break;
}
@@ -1190,19 +1199,43 @@ Remote.prototype.requestTx = function(hash, callback) {
};
/**
* Account request abstraction
* Account Request
*
* @api private
* Optional paging with limit and marker options
* supported in rippled for 'account_lines' and 'account_offers'
*
* The paged responses aren't guaranteed to be reliable between
* ledger closes. You have to supply a ledger_index or ledger_hash
* when paging to ensure a complete response
*
* @param {String} type - request name, e.g. 'account_lines'
* @param {String} account - ripple address
* @param {Object} options - all optional
* @param {String} peer - ripple address
* @param [String|Number] ledger identifier
* @param [Number] limit - max results per response
* @param {String} marker - start position in response paging
* @param [Function] callback
* @return {Request}
* @throws {Error} if a marker is provided, but no ledger_index or ledger_hash
*/
Remote.accountRequest = function(type, options, callback) {
var account, ledger, peer, limit, marker;
Remote.accountRequest = function(type, account, accountIndex, ledger, peer, callback) {
if (typeof account === 'object') {
var options = account;
callback = accountIndex;
ledger = options.ledger;
accountIndex = options.account_index || options.accountIndex;
account = options.accountID || options.account;
peer = options.peer;
if (typeof options === 'object') {
account = options.account;
ledger = options.ledger;
peer = options.peer;
limit = options.limit;
marker = options.marker;
}
// if a marker is given, we need a ledger
// check if a valid ledger_index or ledger_hash is provided
if (marker) {
if (!(Number(ledger) > 0) && !UInt256.is_valid(ledger)) {
throw new Error('A ledger_index or ledger_hash must be provided when using a marker');
}
}
var lastArg = arguments[arguments.length - 1];
@@ -1212,37 +1245,55 @@ Remote.accountRequest = function(type, account, accountIndex, ledger, peer, call
}
var request = new Request(this, type);
var account = UInt160.json_rewrite(account);
request.message.ident = account; //DEPRECATED;
request.message.account = account;
if (typeof accountIndex === 'number') {
request.message.index = accountIndex;
if (account) {
account = UInt160.json_rewrite(account);
request.message.account = account;
}
if (!/^(undefined|function)$/.test(typeof ledger)) {
request.ledgerChoose(ledger);
}
request.ledgerSelect(ledger);
if (!/^(undefined|function)$/.test(typeof peer)) {
if (UInt160.is_valid(peer)) {
request.message.peer = UInt160.json_rewrite(peer);
}
request.callback(callback);
if (!isNaN(Number(limit))) {
limit = Number(limit);
// max for 32-bit unsigned int is 4294967295
// we'll clamp to 1e9
if (limit > 1e9) {
limit = 1e9;
}
// min for 32-bit unsigned int is 0
// we'll clamp to 0
if (limit < 0) {
limit = 0;
}
request.message.limit = limit;
}
if (marker) {
request.message.marker = marker;
}
request.callback(callback);
return request;
};
/**
* Request account_info
*
* @param {String} ripple address
* @param {Object} options
* @param {String} account - ripple address
* @param {String} peer - ripple address
* @param [String|Number] ledger identifier
* @param [Function] callback
* @return {Request}
*/
Remote.prototype.requestAccountInfo = function(account, callback) {
Remote.prototype.requestAccountInfo = function(options, callback) {
var args = Array.prototype.concat.apply(['account_info'], arguments);
return Remote.accountRequest.apply(this, args);
};
@@ -1250,12 +1301,15 @@ Remote.prototype.requestAccountInfo = function(account, callback) {
/**
* Request account_currencies
*
* @param {String} ripple address
* @param {Object} options
* @param {String} account - ripple address
* @param {String} peer - ripple address
* @param [String|Number] ledger identifier
* @param [Function] callback
* @return {Request}
*/
Remote.prototype.requestAccountCurrencies = function(account, callback) {
Remote.prototype.requestAccountCurrencies = function(options, callback) {
var args = Array.prototype.concat.apply(['account_currencies'], arguments);
return Remote.accountRequest.apply(this, args);
};
@@ -1263,15 +1317,24 @@ Remote.prototype.requestAccountCurrencies = function(account, callback) {
/**
* Request account_lines
*
* @param {String} ripple address
* @param {Number] sub-account index
* @param [String|Number] ledger
* @param [String] peer
* Requests for account_lines support paging, provide a limit and marker
* to page through responses.
*
* The paged responses aren't guaranteed to be reliable between
* ledger closes. You have to supply a ledger_index or ledger_hash
* when paging to ensure a complete response
*
* @param {Object} options
* @param {String} account - ripple address
* @param {String} peer - ripple address
* @param [String|Number] ledger identifier
* @param [Number] limit - max results per response
* @param {String} marker - start position in response paging
* @param [Function] callback
* @return {Request}
*/
Remote.prototype.requestAccountLines = function(account, accountIndex, ledger, peer, callback) {
Remote.prototype.requestAccountLines = function(options, callback) {
// XXX Does this require the server to be trusted?
//utils.assert(this.trusted);
var args = Array.prototype.concat.apply(['account_lines'], arguments);
@@ -1281,20 +1344,27 @@ Remote.prototype.requestAccountLines = function(account, accountIndex, ledger, p
/**
* Request account_offers
*
* @param {String} ripple address
* @param {Number] sub-account index
* @param [String|Number] ledger
* @param [String] peer
* Requests for account_offers support paging, provide a limit and marker
* to page through responses.
*
* The paged responses aren't guaranteed to be reliable between
* ledger closes. You have to supply a ledger_index or ledger_hash
* when paging to ensure a complete response
*
* @param {Object} options
* @param {String} account - ripple address
* @param [String|Number] ledger identifier
* @param [Number] limit - max results per response
* @param {String} marker - start position in response paging
* @param [Function] callback
* @return {Request}
*/
Remote.prototype.requestAccountOffers = function(account, accountIndex, ledger, callback) {
Remote.prototype.requestAccountOffers = function(options, callback) {
var args = Array.prototype.concat.apply(['account_offers'], arguments);
return Remote.accountRequest.apply(this, args);
};
/**
* Request account_tx
*
@@ -1310,9 +1380,6 @@ Remote.prototype.requestAccountOffers = function(account, accountIndex, ledger,
* @param [Number] offset, defaults to 0
* @param [Number] limit
*
* @param [Function] filter
* @param [Function] map
* @param [Function] reduce
* @param [Function] callback
* @return {Request}
*/
@@ -1332,6 +1399,10 @@ Remote.prototype.requestAccountTx = function(options, callback) {
options.ledger_index_max = options.max_ledger;
}
if (options.binary && options.parseBinary === void(0)) {
options.parseBinary = true;
}
Object.keys(options).forEach(function(o) {
switch (o) {
case 'account':
@@ -1351,101 +1422,32 @@ Remote.prototype.requestAccountTx = function(options, callback) {
}
}, options);
function propertiesFilter(obj, transaction) {
var properties = Object.keys(obj);
return function(transaction) {
var result = properties.every(function(property) {
return transaction.tx[property] === obj[property];
});
return result;
};
};
function parseBinaryTransaction(transaction) {
var tx = { validated: transaction.validated };
tx.meta = new SerializedObject(transaction.meta).to_json();
tx.tx = new SerializedObject(transaction.tx_blob).to_json();
tx.tx.ledger_index = transaction.ledger_index;
tx.tx.hash = Transaction.from_json(tx.tx).hash();
return tx;
};
function accountTxFilter(fn) {
if (typeof fn !== 'function') {
throw new Error('Missing filter function');
request.once('success', function(res) {
if (options.parseBinary) {
res.transactions = res.transactions.map(Remote.parseBinaryTransaction);
}
request.emit('transactions', res);
});
var self = this;
function filterHandler() {
var listeners = self.listeners('success');
self.removeAllListeners('success');
self.once('success', function(res) {
if (options.parseBinary) {
res.transactions = res.transactions.map(parseBinaryTransaction);
}
if (fn !== Boolean) {
res.transactions = res.transactions.filter(fn);
}
if (typeof options.map === 'function') {
res.transactions = res.transactions.map(options.map);
}
if (typeof options.reduce === 'function') {
res.transactions = res.transactions.reduce(options.reduce);
}
if (typeof options.pluck === 'string') {
res = res[options.pluck];
}
listeners.forEach(function(listener) {
listener.call(self, res);
});
});
};
this.once('request', filterHandler);
return this;
};
request.filter = accountTxFilter;
if (typeof options.parseBinary !== 'boolean') {
options.parseBinary = true;
}
if (options.binary || (options.map || options.reduce)) {
options.filter = options.filter || Boolean;
}
if (options.filter) {
switch (options.filter) {
case 'inbound':
request.filter(propertiesFilter({ Destination: options.account }));
break;
case 'outbound':
request.filter(propertiesFilter({ Account: options.account }));
break;
default:
if (typeof options.filter === 'object') {
options.filter = propertiesFilter(options.filter);
}
request.filter(options.filter);
}
}
request.callback(callback);
request.callback(callback, 'transactions');
return request;
};
/**
* @param {Object} transaction
* @return {Transaction}
*/
Remote.parseBinaryTransaction = function(transaction) {
var tx = { validated: transaction.validated };
tx.meta = new SerializedObject(transaction.meta).to_json();
tx.tx = new SerializedObject(transaction.tx_blob).to_json();
tx.tx.ledger_index = transaction.ledger_index;
tx.tx.hash = Transaction.from_json(tx.tx).hash();
return tx;
};
/**
* Request the overall transaction history.
*
@@ -1584,10 +1586,14 @@ Remote.prototype.requestSubmit = function(callback) {
* @api private
*/
Remote.prototype._serverPrepareSubscribe = function(callback) {
Remote.prototype._serverPrepareSubscribe = function(server, callback) {
var self = this;
var feeds = [ 'ledger', 'server' ];
if (typeof server === 'function') {
callback = server;
}
if (this._transaction_subs) {
feeds.push('transactions');
}
@@ -1608,16 +1614,17 @@ Remote.prototype._serverPrepareSubscribe = function(callback) {
self.emit('random', utils.hexToArray(message.random));
}
if (message.ledger_hash && message.ledger_index) {
self._ledger_time = message.ledger_time;
self._ledger_hash = message.ledger_hash;
self._ledger_current_index = message.ledger_index+1;
self.emit('ledger_closed', message);
}
self._handleLedgerClosed(message, server);
self.emit('subscribed');
};
request.on('error', function(err) {
if (self.trace) {
log.info('Initial server subscribe failed', err);
}
});
request.once('success', serverSubscribed);
self.emit('prepare_subscribe', request);
@@ -1652,12 +1659,13 @@ Remote.prototype.requestLedgerAccept = function(callback) {
request.callback(callback, 'ledger_closed');
request.request();
return this;
return request;
};
/**
* Account root request abstraction
*
* @this Remote
* @api private
*/
@@ -1677,7 +1685,7 @@ Remote.accountRootRequest = function(type, responseFilter, account, ledger, call
var request = this.requestLedgerEntry('account_root');
request.accountRoot(account);
request.ledgerChoose(ledger);
request.ledgerSelect(ledger);
request.once('success', function(message) {
request.emit(type, responseFilter(message));
@@ -2215,65 +2223,40 @@ Remote.prototype.requestConnect = function(ip, port, callback) {
/**
* Create a Transaction
*
* @param {String} source
* @param {String} TransactionType
* @param {Object} options
* @param [Function] callback
* @return {Request}
* @return {Transaction}
*/
Remote.prototype.transaction =
Remote.prototype.createTransaction = function(source, options, callback) {
Remote.prototype.createTransaction = function(type, options) {
if (arguments.length === 0) {
// Fallback
return new Transaction(this);
}
assert.strictEqual(typeof type, 'string', 'TransactionType must be a string');
assert.strictEqual(typeof options, 'object', 'Transaction options must be an object');
var transaction = new Transaction(this);
var transactionTypes = {
payment: 'payment',
accountset: 'accountSet',
trustset: 'trustSet',
offercreate: 'offerCreate',
offercancel: 'offerCancel',
claim: 'claim',
passwordfund: 'passwordFund',
passwordset: 'passwordSet',
setregularkey: 'setRegularKey',
walletadd: 'walletAdd',
sign: 'sign'
payment: 'payment',
accountset: 'accountSet',
trustset: 'trustSet',
offercreate: 'offerCreate',
offercancel: 'offerCancel',
setregularkey: 'setRegularKey',
sign: 'sign'
};
var transactionType;
var transactionConstructor = transactionTypes[type.toLowerCase()];
switch (typeof source) {
case 'object':
if (typeof source.type !== 'string') {
throw new Error('Missing transaction type');
}
transactionType = transactionTypes[source.type.toLowerCase()];
if (!transactionType) {
throw new Error('Invalid transaction type: ' + transactionType);
}
transaction = transaction[transactionType](source);
break;
case 'string':
transactionType = transactionTypes[source.toLowerCase()];
if (!transactionType) {
throw new Error('Invalid transaction type: ' + transactionType);
}
transaction = transaction[transactionType](options);
break;
if (!transactionConstructor) {
throw new Error('Invalid transaction type: ' + type);
}
var lastArg = arguments[arguments.length - 1];
if (typeof lastArg === 'function') {
transaction.submit(lastArg);
}
return transaction;
return transaction[transactionConstructor](options);
};
/**
@@ -2286,7 +2269,7 @@ Remote.prototype.createTransaction = function(source, options, callback) {
*/
Remote.prototype.feeTx = function(units) {
var server = this._getServer();
var server = this.getServer();
if (!server) {
throw new Error('No connected servers');
@@ -2305,7 +2288,7 @@ Remote.prototype.feeTx = function(units) {
*/
Remote.prototype.feeTxUnit = function() {
var server = this._getServer();
var server = this.getServer();
if (!server) {
throw new Error('No connected servers');
@@ -2324,7 +2307,7 @@ Remote.prototype.feeTxUnit = function() {
*/
Remote.prototype.reserve = function(owner_count) {
var server = this._getServer();
var server = this.getServer();
if (!server) {
throw new Error('No connected servers');

View File

@@ -208,6 +208,13 @@ Request.prototype.ledgerIndex = function(ledger_index) {
return this;
};
/**
* Set either ledger_index or ledger_hash based on heuristic
*
* @param {Number|String} ledger identifier
*/
Request.prototype.selectLedger =
Request.prototype.ledgerSelect = function(ledger) {
switch (ledger) {
case 'current':
@@ -217,10 +224,10 @@ Request.prototype.ledgerSelect = function(ledger) {
break;
default:
if (isNaN(ledger)) {
this.message.ledger_hash = ledger;
} else if ((ledger = Number(ledger))) {
this.message.ledger_index = ledger;
if (Number(ledger)) {
this.message.ledger_index = Number(ledger);
} else if (/^[A-F0-9]+$/.test(ledger)) {
this.message.ledger_hash = ledger;
}
break;
}

View File

@@ -33,8 +33,8 @@ Seed.prototype.parse_json = function (j) {
// XXX Should actually always try and continue if it failed.
} else if (j[0] === 's') {
this._value = Base.decode_check(Base.VER_FAMILY_SEED, j);
} else if (j.length === 32) {
this._value = this.parse_hex(j);
} else if (/^[0-9a-fA-f]{32}$/.test(j)) {
this.parse_hex(j);
// XXX Should also try 1751
} else {
this.parse_passphrase(j);
@@ -93,9 +93,14 @@ function SHA256_RIPEMD160(bits) {
*
* {Uint160} (from_json able), specifies the address matching the KeyPair
* that is desired.
*
* @param maxLoops (optional)
* {Number} specifies the amount of attempts taken to generate
* a matching KeyPair
*/
Seed.prototype.get_key = function (account) {
Seed.prototype.get_key = function (account, maxLoops) {
var account_number = 0, address;
var max_loops = maxLoops || 1;
if (!this.is_valid()) {
throw new Error('Cannot generate keys from invalid seed!');
@@ -103,6 +108,7 @@ Seed.prototype.get_key = function (account) {
if (account) {
if (typeof account === 'number') {
account_number = account;
max_loops = account_number+1;
} else {
address = UInt160.from_json(account);
}
@@ -121,9 +127,9 @@ Seed.prototype.get_key = function (account) {
var sec;
var key_pair;
var max_loops = 1000; // TODO
do {
i = 0;
do {
@@ -135,15 +141,15 @@ Seed.prototype.get_key = function (account) {
sec = sec.add(private_gen).mod(curve.r);
key_pair = KeyPair.from_bn_secret(sec);
if (--max_loops <= 0) {
if (max_loops-- <= 0) {
// We are almost certainly looking for an account that would take same
// value of $too_long {forever, ...}
throw new Error('Too many loops looking for KeyPair yielding '+
address.to_json() +' from ' + this.to_json());
};
} while (address && !key_pair.get_address().equals(address));
}
return key_pair;
} while (address && !key_pair.get_address().equals(address));
return key_pair;
};
exports.Seed = Seed;

View File

@@ -117,7 +117,7 @@ SerializedType.prototype.parse_varint = function (so) {
*/
function append_byte_array(so, val, bytes) {
if (!isNumber(val)) {
throw new Error('Value is not a number');
throw new Error('Value is not a number', bytes);
}
if (val < 0 || val >= Math.pow(256, bytes)) {
@@ -625,7 +625,13 @@ function serialize(so, field_name, value) {
// Get the serializer class (ST...) for a field based on the type bits.
var serialized_object_type = exports[binformat.types[type_bits]];
//do something with val[keys] and val[keys[i]];
serialized_object_type.serialize(so, value);
try {
serialized_object_type.serialize(so, value);
} catch (e) {
e.message += ' (' + field_name + ')';
throw e;
}
}
//Take the serialized object, figure out what type/field it is, and return the parsing of that.

View File

@@ -2,7 +2,6 @@ var util = require('util');
var url = require('url');
var EventEmitter = require('events').EventEmitter;
var Amount = require('./amount').Amount;
var Transaction = require('./transaction').Transaction;
var log = require('./log').internal.sub('server');
/**
@@ -134,7 +133,9 @@ function Server(remote, opts) {
}
});
self._request(self._remote.requestServerInfo());
var serverInfoRequest = self._remote.requestServerInfo();
serverInfoRequest.on('error', function() { });
self._request(serverInfoRequest);
});
};
@@ -184,7 +185,7 @@ Server.websocketConstructor = function() {
Server.prototype._setState = function(state) {
if (state !== this._state) {
if (this._remote.trace) {
log.info(this.getHostID(), 'set_state:', state);
log.info(this.getServerID(), 'set_state:', state);
}
this._state = state;
@@ -228,7 +229,7 @@ Server.prototype._checkActivity = function() {
if (delta > (1000 * 25)) {
if (this._remote.trace) {
log.info(this.getHostID(), 'reconnect: activity delta:', delta);
log.info(this.getServerID(), 'reconnect: activity delta:', delta);
}
this.reconnect();
}
@@ -274,7 +275,7 @@ Server.prototype._updateScore = function(type, data) {
if (this._score > 1e3) {
if (this._remote.trace) {
log.info(this.getHostID(), 'reconnect: score:', this._score);
log.info(this.getServerID(), 'reconnect: score:', this._score);
}
this.reconnect();
}
@@ -407,7 +408,7 @@ Server.prototype.connect = function() {
if (ws === self._ws) {
self.emit('socket_open');
// Subscribe to events
self._request(self._remote._serverPrepareSubscribe());
self._request(self._remote._serverPrepareSubscribe(self));
}
};
@@ -562,7 +563,7 @@ Server.prototype._handleServerStatus = function(message) {
this._remote.emit('load', message, this);
var loadChanged = message.load_base !== this._load_base
|| message.load_factor !== this._load_factor
|| message.load_factor !== this._load_factor;
if (loadChanged) {
this._load_base = message.load_base;
@@ -622,6 +623,7 @@ Server.prototype._handlePathFind = function(message) {
* Handle subscription response messages. Subscription response
* messages indicate that a connection to the server is ready
*
* @param {Object} message
* @api private
*/
@@ -632,18 +634,19 @@ Server.prototype._handleResponseSubscribe = function(message) {
// servers with incomplete history
return this.reconnect();
}
if (Server.isLoadStatus(message)) {
this._load_base = message.load_base || 256;
this._load_factor = message.load_factor || 256;
this._fee_ref = message.fee_ref;
this._fee_base = message.fee_base;
this._reserve_base = message.reserve_base;
this._reserve_inc = message.reserve_inc;
}
if (message.pubkey_node) {
// pubkey_node is used to identify the server
this._pubkey_node = message.pubkey_node;
}
if (~(Server.onlineStates.indexOf(message.server_status))) {
if (Server.isLoadStatus(message)) {
this._load_base = message.load_base || 256;
this._load_factor = message.load_factor || 256;
this._fee_ref = message.fee_ref || 10;
this._fee_base = message.fee_base || 10;
this._reserve_base = message.reserve_base;
this._reserve_inc = message.reserve_inc;
}
if (~Server.onlineStates.indexOf(message.server_status)) {
this._setState('online');
}
};
@@ -756,22 +759,16 @@ Server.prototype._isConnected = function() {
* Calculate transaction fee
*
* @param {Transaction|Number} Fee units for a provided transaction
* @return {Number} Final fee in XRP for specified number of fee units
* @return {String} Final fee in XRP for specified number of fee units
* @api private
*/
Server.prototype._computeFee = function(transaction) {
var units;
if (transaction instanceof Transaction) {
units = transaction._getFeeUnits();
} else if (typeof transaction === 'number') {
units = transaction;
} else {
Server.prototype._computeFee = function(feeUnits) {
if (isNaN(feeUnits)) {
throw new Error('Invalid argument');
}
return this._feeTx(units).to_json();
return this._feeTx(Number(feeUnits)).to_json();
};
/**

View File

@@ -60,7 +60,7 @@ function Transaction(remote) {
var self = this;
var remote = remote || { };
var remote = remote || void(0);
this.remote = remote;
@@ -69,7 +69,7 @@ function Transaction(remote) {
this._secret = void(0);
this._build_path = false;
this._maxFee = this.remote.max_fee;
this._maxFee = (typeof remote === 'object') ? this.remote.max_fee : void(0);
this.state = 'unsubmitted';
this.finalized = false;
@@ -241,7 +241,7 @@ Transaction.prototype.finalize = function(message) {
};
Transaction.prototype._accountSecret = function(account) {
return this.remote.secrets[account];
return this.remote ? this.remote.secrets[account] : void(0);
};
/**
@@ -266,13 +266,17 @@ Transaction.prototype.feeUnits = function() {
*/
Transaction.prototype._computeFee = function() {
if (!this.remote) {
return void(0);
}
var servers = this.remote._servers;
var fees = [ ];
for (var i=0; i<servers.length; i++) {
var server = servers[i];
if (server._connected) {
fees.push(Number(server._computeFee(this)));
fees.push(Number(server._computeFee(this._getFeeUnits())));
}
}
@@ -480,13 +484,30 @@ Transaction.prototype.clientID = function(id) {
};
Transaction.prototype.lastLedger = function(sequence) {
if (typeof sequence === 'number') {
if (typeof sequence === 'number' && isFinite(sequence)) {
this._setLastLedger = true;
this.tx_json.LastLedgerSequence = sequence;
}
return this;
};
/*
* Set the transaction's proposed fee. No op when fee parameter
* is not 0 or a positive number
*
* @param {Number} fee The proposed fee
*
* @returns {Transaction} calling instance for chaining
*/
Transaction.prototype.maxFee = function(fee) {
if (typeof fee === 'number' && fee >= 0) {
this._setMaxFee = true;
this._maxFee = fee;
}
return this;
};
Transaction._pathRewrite = function(path) {
if (!Array.isArray(path)) {
return;
@@ -898,6 +919,10 @@ Transaction.prototype.submit = function(callback) {
var account = this.tx_json.Account;
if (!this.remote) {
return this.emit('error', new Error('No remote found'));
}
if (!UInt160.is_valid(account)) {
return this.emit('error', new RippleError('tejInvalidAccount', 'Account is missing or invalid'));
}

View File

@@ -20,6 +20,7 @@ function TransactionManager(account) {
this._remote = account._remote;
this._nextSequence = void(0);
this._maxFee = this._remote.max_fee;
this._maxAttempts = this._remote.max_attempts;
this._submissionTimeout = this._remote._submission_timeout;
this._pending = new PendingQueue();
@@ -45,8 +46,16 @@ function TransactionManager(account) {
}
if (submission instanceof Transaction) {
// ND: A `success` handler will `finalize` this later
submission.emit('success', transaction);
switch (transaction.engine_result) {
case 'tesSUCCESS':
submission.emit('success', transaction);
break;
default:
submission.emit('error', transaction);
}
} else {
self._pending.addReceivedId(hash, transaction);
}
@@ -344,7 +353,7 @@ TransactionManager.prototype._request = function(tx) {
var self = this;
var remote = this._remote;
if (tx.attempts > 10) {
if (tx.attempts > this._maxAttempts) {
return tx.emit('error', new RippleError('tejAttemptsExceeded'));
}
@@ -356,8 +365,6 @@ TransactionManager.prototype._request = function(tx) {
return tx.emit('error', new RippleError('tejLocalSigningRequired', message));
}
tx.emit('presubmit');
if (tx.finalized) {
return;
}
@@ -412,8 +419,6 @@ TransactionManager.prototype._request = function(tx) {
if (tx.finalized) {
return;
}
tx.emit('error', message);
};
function transactionFailedLocal(message) {
@@ -550,9 +555,11 @@ TransactionManager.prototype._request = function(tx) {
return;
}
submitRequest.timeout(self._submissionTimeout, requestTimeout);
tx.submissions = submitRequest.broadcast();
tx.emit('presubmit');
submitRequest.timeout(self._submissionTimeout, requestTimeout);
tx.submissions = submitRequest.broadcast();
tx.attempts++;
tx.emit('postsubmit');
};

View File

@@ -575,8 +575,6 @@ VaultClient.prototype.generateDeviceID = function () {
VaultClient.prototype.resendEmail = blobClient.resendEmail;
VaultClient.prototype.updateProfile = blobClient.updateProfile;
VaultClient.prototype.recoverBlob = blobClient.recoverBlob;
VaultClient.prototype.deleteBlob = blobClient.deleteBlob;
@@ -585,5 +583,11 @@ VaultClient.prototype.requestToken = blobClient.requestToken;
VaultClient.prototype.verifyToken = blobClient.verifyToken;
VaultClient.prototype.getAttestation = blobClient.getAttestation;
VaultClient.prototype.updateAttestation = blobClient.updateAttestation;
VaultClient.prototype.getAttestationSummary = blobClient.getAttestationSummary;
//export by name
exports.VaultClient = VaultClient;

8
src/js/ripple/wallet.js Normal file
View File

@@ -0,0 +1,8 @@
var sjcl = require('./utils').sjcl;
var WalletGenerator = require('ripple-wallet-generator')({
sjcl: sjcl
});
module.exports = WalletGenerator;

View File

@@ -29,13 +29,15 @@ describe('Account', function(){
});
// XXX: clean up the stubbed out remote methods
describe('#publicKeyIsActive()', function(){
it('should respond true if the public key corresponds to the account address and the master key IS NOT disabled', function(){
var account = new Account({
on: function(){},
request_account_info: function(address, callback) {
requestAccountInfo: function(address, callback) {
if (address === 'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz') {
callback(null, { account_data: {
Account: 'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz',
@@ -56,7 +58,7 @@ describe('Account', function(){
var account = new Account({
on: function(){},
request_account_info: function(address, callback) {
requestAccountInfo: function(address, callback) {
if (address === 'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz') {
callback(null, { account_data: {
Account: 'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz',
@@ -77,7 +79,7 @@ describe('Account', function(){
var account = new Account({
on: function(){},
request_account_info: function(address, callback) {
requestAccountInfo: function(address, callback) {
if (address === 'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz') {
callback(null, { account_data: {
Account: 'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz',
@@ -99,7 +101,7 @@ describe('Account', function(){
var account = new Account({
on: function(){},
request_account_info: function(address, callback) {
requestAccountInfo: function(address, callback) {
if (address === 'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz') {
callback(null, { account_data: {
Account: 'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz',
@@ -121,7 +123,7 @@ describe('Account', function(){
var account = new Account({
on: function(){},
request_account_info: function(address, callback) {
requestAccountInfo: function(address, callback) {
if (address === 'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz') {
callback(null, { account_data: {
Account: 'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz',
@@ -142,7 +144,7 @@ describe('Account', function(){
var account = new Account({
on: function(){},
request_account_info: function(address, callback) {
requestAccountInfo: function(address, callback) {
if (address === 'rLdfp6eoR948KVxfn6EpaaNTKwfwXhzSeQ') {
callback({ error: 'remoteError',
error_message: 'Remote reported an error.',

View File

@@ -16,83 +16,256 @@ describe('Amount', function() {
assert(Amount.from_json('1').is_positive());
});
});
describe('Positives', function() {
it('Number 1', function() {
assert(Amount.from_json('1').is_positive());
});
});
// also tested extensively in other cases
describe('to_human', function() {
it('12345.6789 XAU', function() {
assert.strictEqual(Amount.from_human("12345.6789 XAU").to_human(), '12,345.6789');
});
it('12345.678901234 XAU', function() {
assert.strictEqual(Amount.from_human("12345.678901234 XAU").to_human(), '12,345.678901234');
});
it('to human, precision -1, should be ignored, precision needs to be >= 0', function() {
assert.strictEqual(Amount.from_human("12345.678901234 XAU").to_human({precision:-1}), '12,346');
});
it('to human, precision 0', function() {
assert.strictEqual(Amount.from_human("12345.678901234 XAU").to_human({precision:0}), '12,346');
});
it('to human, precision 1', function() {
assert.strictEqual(Amount.from_human("12345.678901234 XAU").to_human({precision:1}), '12,345.7');
});
it('to human, precision 2', function() {
assert.strictEqual(Amount.from_human("12345.678901234 XAU").to_human({precision:2}), '12,345.68');
});
it('to human, precision 3', function() {
assert.strictEqual(Amount.from_human("12345.678901234 XAU").to_human({precision:3}), '12,345.679');
});
it('to human, precision 4', function() {
assert.strictEqual(Amount.from_human("12345.678901234 XAU").to_human({precision:4}), '12,345.6789');
});
it('to human, precision 5', function() {
assert.strictEqual(Amount.from_human("12345.678901234 XAU").to_human({precision:5}), '12,345.67890');
});
it('to human, precision -1, should be ignored, precision needs to be >= 0', function() {
assert.strictEqual(Amount.from_human("0.00012345 XAU").to_human({precision:-1}), '0');
});
it('to human, precision 0', function() {
assert.strictEqual(Amount.from_human("0.00012345 XAU").to_human({precision:0}), '0');
});
it('to human, precision 1', function() {
assert.strictEqual(Amount.from_human("0.00012345 XAU").to_human({precision:1}), '0.0');
});
it('to human, precision 2', function() {
assert.strictEqual(Amount.from_human("0.00012345 XAU").to_human({precision:2}), '0.00');
});
it('to human, precision 5', function() {
assert.strictEqual(Amount.from_human("0.00012345 XAU").to_human({precision:5}), '0.00012');
});
it('to human, precision 6', function() {
assert.strictEqual(Amount.from_human("0.00012345 XAU").to_human({precision:6}), '0.000123');
});
it('to human, precision 16', function() {
assert.strictEqual(Amount.from_human("0.00012345 XAU").to_human({precision:16}), '0.00012345');
});
it('to human, precision 16, min_precision 16', function() {
assert.strictEqual(Amount.from_human("0.00012345 XAU").to_human({precision:16, min_precision:16}), '0.0001234500000000');
});
it('to human, precision 16, min_precision 12', function() {
assert.strictEqual(Amount.from_human("0.00012345 XAU").to_human({precision:16, min_precision:12}), '0.000123450000');
});
it('to human, precision 0, first decimal 4', function() {
assert.strictEqual(Amount.from_human("0.4 XAU").to_human({precision:0}), '0');
});
it('to human, precision 0, first decimal 5', function() {
assert.strictEqual(Amount.from_human("0.5 XAU").to_human({precision:0}), '1');
});
it('to human, precision 0, first decimal 8', function() {
assert.strictEqual(Amount.from_human("0.8 XAU").to_human({precision:0}), '1');
});
it('to human, precision 0, precision 16', function() {
assert.strictEqual(Amount.from_human("0.0 XAU").to_human({precision:16}), '0');
});
it('to human, precision 0, precision 8, min_precision 16', function() {
assert.strictEqual(Amount.from_human("0.0 XAU").to_human({precision:8, min_precision:16}), '0.0000000000000000');
});
it('to human, precision 0, first decimal 8', function() {
assert.strictEqual(Amount.from_human("0.8 XAU").to_human({precision:0}), '1');
});
it('to human, precision 6, min_precision 6, max_sig_digits 20', function() {
assert.strictEqual(Amount.from_human("0.0 XAU").to_human({precision: 6, min_precision: 6, max_sig_digits: 20}), '0.000000');
});
it('to human, precision 16, min_precision 6, max_sig_digits 20', function() {
assert.strictEqual(Amount.from_human("0.0 XAU").to_human({precision: 16, min_precision: 6, max_sig_digits: 20}), '0.000000');
});
it('to human rounding edge case, precision 2, 1', function() {
assert.strictEqual(Amount.from_human("0.99 XAU").to_human({precision:1}), '1.0');
});
it('to human rounding edge case, precision 2, 2', function() {
assert.strictEqual(Amount.from_human("0.99 XAU").to_human({precision:2}), '0.99');
});
it('to human rounding edge case, precision 2, 3', function() {
assert.strictEqual(Amount.from_human("0.99 XAU").to_human({precision:3}), '0.99');
});
it('to human rounding edge case, precision 2, 3 min precision 3', function() {
assert.strictEqual(Amount.from_human("0.99 XAU").to_human({precision:3, min_precision:3}), '0.990');
});
it('to human rounding edge case, precision 3, 2', function() {
assert.strictEqual(Amount.from_human("0.999 XAU").to_human({precision:2}), '1.00');
});
});
describe('from_human', function() {
it('1 XRP', function() {
assert.strictEqual(Amount.from_human("1 XRP").to_text_full(), '1/XRP');
});
it('1 XRP human', function() {
assert.strictEqual(Amount.from_human("1 XRP").to_human_full(), '1/XRP');
});
it('0.1 XRP', function() {
assert.strictEqual(Amount.from_human("0.1 XRP").to_text_full(), '0.1/XRP');
});
it('0.1 XRP human', function() {
assert.strictEqual(Amount.from_human("0.1 XRP").to_human_full(), '0.1/XRP');
});
it('0.1 USD', function() {
assert.strictEqual(Amount.from_human("0.1 USD").to_text_full(), '0.1/USD/NaN');
});
it('0.1 USD human', function() {
assert.strictEqual(Amount.from_human("0.1 USD").to_human_full(), '0.1/USD/NaN');
});
it('10000 USD', function() {
assert.strictEqual(Amount.from_human("10000 USD").to_text_full(), '10000/USD/NaN');
});
it('10000 USD human', function() {
assert.strictEqual(Amount.from_human("10000 USD").to_human_full(), '10,000/USD/NaN');
});
it('USD 10000', function() {
assert.strictEqual(Amount.from_human("USD 10000").to_text_full(), '10000/USD/NaN');
});
it('USD 10000 human', function() {
assert.strictEqual(Amount.from_human("USD 10000").to_human_full(), '10,000/USD/NaN');
});
it('12345.6789 XAU', function() {
assert.strictEqual(Amount.from_human("12345.6789 XAU").to_text_full(), '12345.6789/XAU/NaN');
});
it('12345.6789 XAU human', function() {
assert.strictEqual(Amount.from_human("12345.6789 XAU").to_human_full(), '12,345.6789/XAU/NaN');
});
it('12345.6789 015841551A748AD2C1F76FF6ECB0CCCD00000000', function() {
assert.strictEqual(Amount.from_human("12345.6789 015841551A748AD2C1F76FF6ECB0CCCD00000000").to_text_full(), '12345.6789/XAU (-0.5%pa)/NaN');
});
it('12345.6789 015841551A748AD2C1F76FF6ECB0CCCD00000000 human', function() {
assert.strictEqual(Amount.from_human("12345.6789 015841551A748AD2C1F76FF6ECB0CCCD00000000").to_human_full(), '12,345.6789/XAU (-0.5%pa)/NaN');
});
it('12345.6789 0000000000000000000000005553440000000000', function() {
assert.strictEqual(Amount.from_human("12345.6789 0000000000000000000000005553440000000000").to_text_full(), '12345.6789/USD/NaN');
});
it('12345.6789 0000000000000000000000005553440000000000 human', function() {
assert.strictEqual(Amount.from_human("12345.6789 0000000000000000000000005553440000000000").to_human_full(), '12,345.6789/USD/NaN');
});
it('10 0000000000000000000000005553440000000000', function() {
assert.strictEqual(Amount.from_human("10 0000000000000000000000005553440000000000").to_text_full(), '10/USD/NaN');
});
it('10 0000000000000000000000005553440000000000 human', function() {
assert.strictEqual(Amount.from_human("10 0000000000000000000000005553440000000000").to_human_full(), '10/USD/NaN');
});
it('100 0000000000000000000000005553440000000000', function() {
assert.strictEqual(Amount.from_human("100 0000000000000000000000005553440000000000").to_text_full(), '100/USD/NaN');
});
it('100 0000000000000000000000005553440000000000 human', function() {
assert.strictEqual(Amount.from_human("100 0000000000000000000000005553440000000000").to_human_full(), '100/USD/NaN');
});
it('1000 0000000000000000000000005553440000000000', function() {
assert.strictEqual(Amount.from_human("1000 0000000000000000000000005553440000000000").to_text_full(), '1000/USD/NaN');
});
it('1000 0000000000000000000000005553440000000000 human', function() {
assert.strictEqual(Amount.from_human("1000 0000000000000000000000005553440000000000").to_human_full(), '1,000/USD/NaN');
});
it('-100 0000000000000000000000005553440000000000', function() {
assert.strictEqual(Amount.from_human("-100 0000000000000000000000005553440000000000").to_text_full(), '-100/USD/NaN');
});
it('-100 0000000000000000000000005553440000000000 human', function() {
assert.strictEqual(Amount.from_human("-100 0000000000000000000000005553440000000000").to_human_full(), '-100/USD/NaN');
});
it('-1000 0000000000000000000000005553440000000000', function() {
assert.strictEqual(Amount.from_human("-1000 0000000000000000000000005553440000000000").to_text_full(), '-1000/USD/NaN');
});
it('-1000 0000000000000000000000005553440000000000 human', function() {
assert.strictEqual(Amount.from_human("-1000 0000000000000000000000005553440000000000").to_human_full(), '-1,000/USD/NaN');
});
it('-1000.001 0000000000000000000000005553440000000000', function() {
assert.strictEqual(Amount.from_human("-1000.001 0000000000000000000000005553440000000000").to_text_full(), '-1000.001/USD/NaN');
});
it('-1000.001 0000000000000000000000005553440000000000 human', function() {
assert.strictEqual(Amount.from_human("-1000.001 0000000000000000000000005553440000000000").to_human_full(), '-1,000.001/USD/NaN');
});
it('XAU 12345.6789', function() {
assert.strictEqual(Amount.from_human("XAU 12345.6789").to_text_full(), '12345.6789/XAU/NaN');
});
it('XAU 12345.6789 human', function() {
assert.strictEqual(Amount.from_human("XAU 12345.6789").to_human_full(), '12,345.6789/XAU/NaN');
});
it('101 12345.6789', function() {
assert.strictEqual(Amount.from_human("101 12345.6789").to_text_full(), '12345.6789/101/NaN');
});
it('101 12345.6789 human', function() {
assert.strictEqual(Amount.from_human("101 12345.6789").to_human_full(), '12,345.6789/101/NaN');
});
it('12345.6789 101', function() {
assert.strictEqual(Amount.from_human("12345.6789 101").to_text_full(), '12345.6789/101/NaN');
});
it('12345.6789 101 human', function() {
assert.strictEqual(Amount.from_human("12345.6789 101").to_human_full(), '12,345.6789/101/NaN');
});
});
describe('from_json', function() {
it('1 XRP', function() {
assert.strictEqual(Amount.from_json("1/XRP").to_text_full(), "1/XRP/NaN");
});
it('1 XRP human', function() {
assert.strictEqual(Amount.from_json("1/XRP").to_human_full(), "1/XRP/NaN");
});
});
describe('from_number', function() {
it('Number 1', function() {
assert.strictEqual(Amount.from_number(1).to_text_full(), '1/1/rrrrrrrrrrrrrrrrrrrrBZbvji');
});
it('Number 1 human', function() {
assert.strictEqual(Amount.from_number(1).to_human_full(), '1/1/rrrrrrrrrrrrrrrrrrrrBZbvji');
});
it('Number 2', function() {
assert.strictEqual(Amount.from_number(2).to_text_full(), '2/1/rrrrrrrrrrrrrrrrrrrrBZbvji');
});
it('Number 2 human', function() {
assert.strictEqual(Amount.from_number(2).to_human_full(), '2/1/rrrrrrrrrrrrrrrrrrrrBZbvji');
});
it('Multiply 2 "1" with 3 "1", by product_human', function () {
assert.strictEqual(Amount.from_number(2).product_human(Amount.from_number(3)).to_text_full(), '6/1/rrrrrrrrrrrrrrrrrrrrBZbvji');
});
it('Multiply 2 "1" with 3 "1", by product_human human', function () {
assert.strictEqual(Amount.from_number(2).product_human(Amount.from_number(3)).to_human_full(), '6/1/rrrrrrrrrrrrrrrrrrrrBZbvji');
});
it('Multiply 3 USD with 3 "1"', function () {
assert.strictEqual(Amount.from_json('3/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_number(3)).to_text_full(), '9/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
});
it('Multiply 3 USD with 3 "1" human', function () {
assert.strictEqual(Amount.from_json('3/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_number(3)).to_human_full(), '9/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
});
it('Multiply -1 "1" with 3 USD', function () {
assert.strictEqual(Amount.from_number(-1).multiply(Amount.from_json('3/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_text_full(), '-3/1/rrrrrrrrrrrrrrrrrrrrBZbvji');
});
it('Multiply -1 "1" with 3 USD human', function () {
assert.strictEqual(Amount.from_number(-1).multiply(Amount.from_json('3/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full(), '-3/1/rrrrrrrrrrrrrrrrrrrrBZbvji');
});
it('Multiply -1 "1" with 3 USD, by product_human', function () {
assert.strictEqual(Amount.from_number(-1).product_human(Amount.from_json('3/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_text_full(), '-3/1/rrrrrrrrrrrrrrrrrrrrBZbvji');
});
it('Multiply -1 "1" with 3 USD, by product_human human', function () {
assert.strictEqual(Amount.from_number(-1).product_human(Amount.from_json('3/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full(), '-3/1/rrrrrrrrrrrrrrrrrrrrBZbvji');
});
});
describe('text_full_rewrite', function() {
it('Number 1', function() {
@@ -162,12 +335,21 @@ describe('Amount', function() {
it('parse dem', function() {
assert.strictEqual(Amount.from_json('10/015841551A748AD2C1F76FF6ECB0CCCD00000000/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_text_full(), '10/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
});
it('parse dem human', function() {
assert.strictEqual(Amount.from_json('10/015841551A748AD2C1F76FF6ECB0CCCD00000000/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_human_full(), '10/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
});
it('parse dem', function() {
assert.strictEqual(Amount.from_json('10/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_text_full(), '10/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
});
it('parse dem human', function() {
assert.strictEqual(Amount.from_json('10/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_human_full(), '10/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
});
it('Parse 800/USD/mtgox', function () {
assert.strictEqual('800/USD/'+config.accounts['mtgox'].account, Amount.from_json('800/USD/mtgox').to_text_full());
});
it('Parse 800/USD/mtgox human', function () {
assert.strictEqual('800/USD/'+config.accounts['mtgox'].account, Amount.from_json('800/USD/mtgox').to_human_full());
});
it('Parse native 0', function () {
assert.strictEqual('0/XRP', Amount.from_json('0').to_text_full());
});
@@ -211,7 +393,52 @@ describe('Amount', function() {
assert.strictEqual('0/111/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('0/111/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_text_full());
});
it('Parse 0.0/12D/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', function () {
assert.strictEqual('0/XRP/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('0/12D/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_text_full());
assert.strictEqual('0/12D/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('0/12D/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_text_full());
});
it('Parse native 0 human', function () {
assert.strictEqual('0/XRP', Amount.from_json('0').to_human_full());
});
it('Parse native 0.0 human', function () {
assert.strictEqual('0/XRP', Amount.from_json('0.0').to_human_full());
});
it('Parse native -0 human', function () {
assert.strictEqual('0/XRP', Amount.from_json('-0').to_human_full());
});
it('Parse native -0.0 human', function () {
assert.strictEqual('0/XRP', Amount.from_json('-0.0').to_human_full());
});
it('Parse native 1000 human', function () {
assert.strictEqual('0.001/XRP', Amount.from_json('1000').to_human_full());
});
it('Parse native 12.3 human', function () {
assert.strictEqual('12.3/XRP', Amount.from_json('12.3').to_human_full());
});
it('Parse native -12.3 human', function () {
assert.strictEqual('-12.3/XRP', Amount.from_json('-12.3').to_human_full());
});
it('Parse 123./USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh human', function () {
assert.strictEqual('123/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('123./USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_human_full());
});
it('Parse 12300/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh human', function () {
assert.strictEqual('12,300/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('12300/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_human_full());
});
it('Parse 12.3/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh human', function () {
assert.strictEqual('12.3/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('12.3/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_human_full());
});
it('Parse 1.2300/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh human', function () {
assert.strictEqual('1.23/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('1.2300/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_human_full());
});
it('Parse -0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh human', function () {
assert.strictEqual('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('-0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_human_full());
});
it('Parse -0.0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh human', function () {
assert.strictEqual('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('-0.0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_human_full());
});
it('Parse 0.0/111/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh human', function () {
assert.strictEqual('0/111/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('0/111/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_human_full());
});
it('Parse 0.0/12D/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh human', function () {
assert.strictEqual('0/12D/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('0/12D/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_human_full());
});
});
describe('Amount to_json', function() {
@@ -370,6 +597,144 @@ describe('Amount', function() {
it('Divide EUR by XRP, neg, <1', function () {
assert.strictEqual('-0.05/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('-100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').divide(Amount.from_json('2000')).to_text_full());
});
it('Negate native 123 human', function () {
assert.strictEqual('-0.000123/XRP', Amount.from_json('123').negate().to_human_full());
});
it('Negate native -123 human', function () {
assert.strictEqual('0.000123/XRP', Amount.from_json('-123').negate().to_human_full());
});
it('Negate non-native 123 human', function () {
assert.strictEqual('-123/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('123/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').negate().to_human_full());
});
it('Negate non-native -123 human', function () {
assert.strictEqual('123/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('-123/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').negate().to_human_full());
});
it('Clone non-native -123 human', function () {
assert.strictEqual('-123/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('-123/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').clone().to_human_full());
});
it('Add XRP to XRP human', function () {
assert.strictEqual('0.0002/XRP', Amount.from_json('150').add(Amount.from_json('50')).to_human_full());
});
it('Add USD to USD human', function () {
assert.strictEqual('200.52/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('150.02/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').add(Amount.from_json('50.5/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Add 0 USD to 1 USD human', function() {
assert.strictEqual('1' , Amount.from_json('1/USD').add('0/USD').to_human());
});
it('Subtract USD from USD human', function() {
assert.strictEqual('99.52/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('150.02/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').subtract(Amount.from_json('50.5/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Multiply 0 XRP with 0 XRP human', function () {
assert.strictEqual('0/XRP', Amount.from_json('0').multiply(Amount.from_json('0')).to_human_full());
});
it('Multiply 0 USD with 0 XRP human', function () {
assert.strictEqual('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_json('0')).to_human_full());
});
it('Multiply 0 XRP with 0 USD human', function () {
assert.strictEqual('0/XRP', Amount.from_json('0').multiply(Amount.from_json('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Multiply 1 XRP with 0 XRP human', function () {
assert.strictEqual('0/XRP', Amount.from_json('1').multiply(Amount.from_json('0')).to_human_full());
});
it('Multiply 1 USD with 0 XRP human', function () {
assert.strictEqual('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_json('0')).to_human_full());
});
it('Multiply 1 XRP with 0 USD human', function () {
assert.strictEqual('0/XRP', Amount.from_json('1').multiply(Amount.from_json('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Multiply 0 XRP with 1 XRP human', function () {
assert.strictEqual('0/XRP', Amount.from_json('0').multiply(Amount.from_json('1')).to_human_full());
});
it('Multiply 0 USD with 1 XRP human', function () {
assert.strictEqual('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_json('1')).to_human_full());
});
it('Multiply 0 XRP with 1 USD human', function () {
assert.strictEqual('0/XRP', Amount.from_json('0').multiply(Amount.from_json('1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Multiply XRP with USD human', function () {
assert.equal('0.002/XRP', Amount.from_json('200').multiply(Amount.from_json('10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Multiply XRP with USD human', function () {
assert.strictEqual('0.2/XRP', Amount.from_json('20000').multiply(Amount.from_json('10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Multiply XRP with USD human', function () {
assert.strictEqual('20/XRP', Amount.from_json('2000000').multiply(Amount.from_json('10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Multiply XRP with USD, neg human', function () {
assert.strictEqual('-0.002/XRP', Amount.from_json('200').multiply(Amount.from_json('-10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Multiply XRP with USD, neg, frac human', function () {
assert.strictEqual('-0.222/XRP', Amount.from_json('-6000').multiply(Amount.from_json('37/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Multiply USD with USD human', function () {
assert.strictEqual('20,000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('2000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_json('10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Multiply USD with USD human', function () {
assert.strictEqual('200,000,000,000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('2000000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_json('100000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Multiply EUR with USD, result < 1 human', function () {
assert.strictEqual('100,000/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_json('1000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Multiply EUR with USD, neg human', function () {
assert.strictEqual('-48,000,000/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('-24000/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_json('2000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Multiply EUR with USD, neg, <1 human', function () {
assert.strictEqual('-100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('0.1/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_json('-1000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Multiply EUR with XRP, factor < 1 human', function () {
assert.strictEqual('100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('0.05/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_json('2000')).to_human_full());
});
it('Multiply EUR with XRP, neg human', function () {
assert.strictEqual('-500/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('-100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_json('5')).to_human_full());
});
it('Multiply EUR with XRP, neg, <1 human', function () {
assert.strictEqual('-100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('-0.05/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_json('2000')).to_human_full());
});
it('Multiply XRP with XRP human', function () {
assert.strictEqual('0.0001/XRP', Amount.from_json('10').multiply(Amount.from_json('10')).to_human_full());
});
it('Divide XRP by USD human', function () {
assert.strictEqual('0.00002/XRP', Amount.from_json('200').divide(Amount.from_json('10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Divide XRP by USD human', function () {
assert.strictEqual('0.002/XRP', Amount.from_json('20000').divide(Amount.from_json('10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Divide XRP by USD human', function () {
assert.strictEqual('0.2/XRP', Amount.from_json('2000000').divide(Amount.from_json('10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Divide XRP by USD, neg human', function () {
assert.strictEqual('-0.00002/XRP', Amount.from_json('200').divide(Amount.from_json('-10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Divide XRP by USD, neg, frac human', function () {
assert.strictEqual('-0.000162/XRP', Amount.from_json('-6000').divide(Amount.from_json('37/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Divide USD by USD human', function () {
assert.strictEqual('200/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('2000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').divide(Amount.from_json('10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Divide USD by USD, fractional human', function () {
assert.strictEqual('57,142.85714285714/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('2000000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').divide(Amount.from_json('35/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Divide USD by USD human', function () {
assert.strictEqual('20/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('2000000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').divide(Amount.from_json('100000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Divide EUR by USD, factor < 1 human', function () {
assert.strictEqual('0.1/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').divide(Amount.from_json('1000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Divide EUR by USD, neg human', function () {
assert.strictEqual('-12/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('-24000/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').divide(Amount.from_json('2000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Divide EUR by USD, neg, <1 human', function () {
assert.strictEqual('-0.1/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').divide(Amount.from_json('-1000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Divide EUR by XRP, result < 1 human', function () {
assert.strictEqual('0.05/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').divide(Amount.from_json('2000')).to_human_full());
});
it('Divide EUR by XRP, neg human', function () {
assert.strictEqual('-20/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('-100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').divide(Amount.from_json('5')).to_human_full());
});
it('Divide EUR by XRP, neg, <1 human', function () {
assert.strictEqual('-0.05/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('-100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').divide(Amount.from_json('2000')).to_human_full());
});
it('Divide by zero should throw', function() {
assert.throws(function() {
Amount.from_json(1).divide(Amount.from_json(0));
@@ -607,12 +972,87 @@ describe('Amount', function() {
it('Multiply USD with XAU (dem)', function () {
assert.strictEqual(Amount.from_json('2000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').product_human(Amount.from_json('10/015841551A748AD2C1F76FF6ECB0CCCD00000000/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'), {reference_date: 443845330 + 31535000}).to_text_full(), '19900.00316303882/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
});
it('Multiply 0 XRP with 0 XRP human', function () {
assert.strictEqual('0/XRP', Amount.from_json('0').product_human(Amount.from_json('0')).to_human_full());
});
it('Multiply 0 USD with 0 XRP human', function () {
assert.strictEqual('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').product_human(Amount.from_json('0')).to_human_full());
});
it('Multiply 0 XRP with 0 USD human', function () {
assert.strictEqual('0/XRP', Amount.from_json('0').product_human(Amount.from_json('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Multiply 1 XRP with 0 XRP human', function () {
assert.strictEqual('0/XRP', Amount.from_json('1').product_human(Amount.from_json('0')).to_human_full());
});
it('Multiply 1 USD with 0 XRP human', function () {
assert.strictEqual('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').product_human(Amount.from_json('0')).to_human_full());
});
it('Multiply 1 XRP with 0 USD human', function () {
assert.strictEqual('0/XRP', Amount.from_json('1').product_human(Amount.from_json('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Multiply 0 XRP with 1 XRP human', function () {
assert.strictEqual('0/XRP', Amount.from_json('0').product_human(Amount.from_json('1')).to_human_full());
});
it('Multiply 0 USD with 1 XRP human', function () {
assert.strictEqual('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').product_human(Amount.from_json('1')).to_human_full());
});
it('Multiply 0 XRP with 1 USD human', function () {
assert.strictEqual('0/XRP', Amount.from_json('0').product_human(Amount.from_json('1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Multiply XRP with USD human', function () {
assert.equal('0.002/XRP', Amount.from_json('200').product_human(Amount.from_json('10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Multiply XRP with USD human', function () {
assert.strictEqual('0.2/XRP', Amount.from_json('20000').product_human(Amount.from_json('10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Multiply XRP with USD human', function () {
assert.strictEqual('20/XRP', Amount.from_json('2000000').product_human(Amount.from_json('10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Multiply XRP with USD, neg human', function () {
assert.strictEqual('-0.002/XRP', Amount.from_json('200').product_human(Amount.from_json('-10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Multiply XRP with USD, neg, frac human', function () {
assert.strictEqual('-0.222/XRP', Amount.from_json('-6000').product_human(Amount.from_json('37/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Multiply USD with USD human', function () {
assert.strictEqual('20,000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('2000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').product_human(Amount.from_json('10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Multiply USD with USD human', function () {
assert.strictEqual('200,000,000,000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('2000000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').product_human(Amount.from_json('100000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Multiply EUR with USD, result < 1 human', function () {
assert.strictEqual('100,000/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').product_human(Amount.from_json('1000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full());
});
it('Multiply EUR with USD, neg human', function () {
assert.strictEqual(Amount.from_json('-24000/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').product_human(Amount.from_json('2000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full(), '-48,000,000/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
});
it('Multiply EUR with USD, neg, <1 human', function () {
assert.strictEqual(Amount.from_json('0.1/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').product_human(Amount.from_json('-1000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_human_full(), '-100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
});
it('Multiply EUR with XRP, factor < 1 human', function () {
assert.strictEqual(Amount.from_json('0.05/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').product_human(Amount.from_json('2000')).to_human_full(), '0.0001/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
});
it('Multiply EUR with XRP, neg human', function () {
assert.strictEqual(Amount.from_json('-100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').product_human(Amount.from_json('5')).to_human_full(), '-0.0005/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
});
it('Multiply EUR with XRP, neg, <1 human', function () {
assert.strictEqual(Amount.from_json('-0.05/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').product_human(Amount.from_json('2000')).to_human_full(), '-0.0001/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
});
it('Multiply XRP with XRP human', function () {
assert.strictEqual(Amount.from_json('10000000').product_human(Amount.from_json('10')).to_human_full(), '0.0001/XRP');
});
it('Multiply USD with XAU (dem) human', function () {
assert.strictEqual(Amount.from_json('2000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').product_human(Amount.from_json('10/015841551A748AD2C1F76FF6ECB0CCCD00000000/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'), {reference_date: 443845330 + 31535000}).to_human_full(), '19,900.00316303882/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
});
});
describe('ratio_human', function() {
it('Divide USD by XAU (dem)', function () {
assert.strictEqual(Amount.from_json('2000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').ratio_human(Amount.from_json('10/015841551A748AD2C1F76FF6ECB0CCCD00000000/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'), {reference_date: 443845330 + 31535000}).to_text_full(), '201.0049931765529/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
});
it('Divide USD by XAU (dem) human', function () {
assert.strictEqual(Amount.from_json('2000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').ratio_human(Amount.from_json('10/015841551A748AD2C1F76FF6ECB0CCCD00000000/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'), {reference_date: 443845330 + 31535000}).to_human_full(), '201.0049931765529/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
});
});
describe('_invert', function() {
@@ -625,6 +1065,15 @@ describe('Amount', function() {
it('Invert 0.02', function () {
assert.strictEqual(Amount.from_json('0.02/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').invert().to_text_full(), '50/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
});
it('Invert 1 human', function () {
assert.strictEqual(Amount.from_json('1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').invert().to_human_full(), '1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
});
it('Invert 20 human', function () {
assert.strictEqual(Amount.from_json('20/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').invert().to_human_full(), '0.05/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
});
it('Invert 0.02 human', function () {
assert.strictEqual(Amount.from_json('0.02/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').invert().to_human_full(), '50/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
});
});
describe('from_quality', function() {
@@ -658,6 +1107,36 @@ describe('Amount', function() {
it('USD/XAU(dem) inverse', function () {
assert.strictEqual(Amount.from_quality('CDFD3AFB2F8C5DBEF75B081F7C957FF5509563266F28F36C5704A0FB0BAD8800', '015841551A748AD2C1F76FF6ECB0CCCD00000000', 'rUyPiNcSFFj6uMR2gEaD8jUerQ59G1qvwN', {inverse: true, base_currency: 'USD', reference_date: 443845330 + 31535000}).to_text_full(), '0.007675186123263489/XAU (-0.5%pa)/rUyPiNcSFFj6uMR2gEaD8jUerQ59G1qvwN');
});
it('BTC/XRP human', function () {
assert.strictEqual(Amount.from_quality('7B73A610A009249B0CC0D4311E8BA7927B5A34D86634581C5F0FF9FF678E1000', 'XRP', NaN, {base_currency: 'BTC'}).to_human_full(), '44,970/XRP');
});
it('BTC/XRP inverse human', function () {
assert.strictEqual(Amount.from_quality('37AAC93D336021AE94310D0430FFA090F7137C97D473488C4A0918D0DEF8624E', 'XRP', NaN, {inverse: true, base_currency: 'BTC'}).to_human_full(), '39,053.954453/XRP');
});
it('XRP/USD human', function () {
assert.strictEqual(Amount.from_quality('DFA3B6DDAB58C7E8E5D944E736DA4B7046C30E4F460FD9DE4D05DCAA8FE12000', 'USD', 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', {base_currency: 'XRP'}).to_human_full(), '0.0165/USD/rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B');
});
it('XRP/USD inverse human', function () {
assert.strictEqual(Amount.from_quality('4627DFFCFF8B5A265EDBD8AE8C14A52325DBFEDAF4F5C32E5C22A840E27DCA9B', 'USD', 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', {inverse: true, base_currency: 'XRP'}).to_human_full(), '0.010251/USD/rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B');
});
it('BTC/USD human', function () {
assert.strictEqual(Amount.from_quality('6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC9858038D7EA4C68000', 'USD', 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', {base_currency: 'BTC'}).to_human_full(), '1,000/USD/rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B');
});
it('BTC/USD inverse human', function () {
assert.strictEqual(Amount.from_quality('20294C923E80A51B487EB9547B3835FD483748B170D2D0A455071AFD498D0000', 'USD', 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', {inverse: true, base_currency: 'BTC'}).to_human_full(), '0.5/USD/rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B');
});
it('XAU(dem)/XRP human', function () {
assert.strictEqual(Amount.from_quality('587322CCBDE0ABD01704769A73A077C32FB39057D813D4165F1FF973CAF997EF', 'XRP', NaN, {base_currency: '015841551A748AD2C1F76FF6ECB0CCCD00000000', reference_date: 443845330 + 31535000}).to_human_full(), '90,452.246928/XRP');
});
it('XAU(dem)/XRP inverse human', function () {
assert.strictEqual(Amount.from_quality('F72C7A9EAE4A45ED1FB547AD037D07B9B965C6E662BEBAFA4A03F2A976804235', 'XRP', NaN, {inverse: true, base_currency: '015841551A748AD2C1F76FF6ECB0CCCD00000000', reference_date: 443845330 + 31535000}).to_human_full(), '90,442.196677/XRP');
});
it('USD/XAU(dem) human', function () {
assert.strictEqual(Amount.from_quality('4743E58E44974B325D42FD2BB683A6E36950F350EE46DD3A521B644B99782F5F', '015841551A748AD2C1F76FF6ECB0CCCD00000000', 'rUyPiNcSFFj6uMR2gEaD8jUerQ59G1qvwN', {base_currency: 'USD', reference_date: 443845330 + 31535000}).to_human_full(), '0.007710100231303007/XAU (-0.5%pa)/rUyPiNcSFFj6uMR2gEaD8jUerQ59G1qvwN');
});
it('USD/XAU(dem) inverse human', function () {
assert.strictEqual(Amount.from_quality('CDFD3AFB2F8C5DBEF75B081F7C957FF5509563266F28F36C5704A0FB0BAD8800', '015841551A748AD2C1F76FF6ECB0CCCD00000000', 'rUyPiNcSFFj6uMR2gEaD8jUerQ59G1qvwN', {inverse: true, base_currency: 'USD', reference_date: 443845330 + 31535000}).to_human_full(), '0.007675186123263489/XAU (-0.5%pa)/rUyPiNcSFFj6uMR2gEaD8jUerQ59G1qvwN');
});
});
describe('apply interest', function() {
@@ -679,5 +1158,99 @@ describe('Amount', function() {
demAmount.set_issuer("rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh");
assert.strictEqual(demAmount.to_text_full(), '10.75853086191915/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
});
it ('from_json apply interest 10 XAU human', function() {
var demAmount = Amount.from_json('10/0158415500000000C1F76FF6ECB0BAC600000000/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
assert.strictEqual(demAmount.to_human_full(), '10/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
demAmount = demAmount.applyInterest(459990264);
assert.strictEqual(demAmount.to_human_full(), '9.294949401870435/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
});
it ('from_json apply interest XAU human', function() {
var demAmount = Amount.from_json('1235.5/0158415500000000C1F76FF6ECB0BAC600000000/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
assert.strictEqual(demAmount.to_human_full(), '1,235.5/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
demAmount = demAmount.applyInterest(459990264);
assert.strictEqual(demAmount.to_human_full(), '1,148.390998601092/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
});
it ('from_human with reference date human', function() {
var demAmount = Amount.from_human('10 0158415500000000C1F76FF6ECB0BAC600000000', {reference_date:459990264});
demAmount.set_issuer("rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh");
assert.strictEqual(demAmount.to_human_full(), '10.75853086191915/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
});
});
describe('amount limits', function() {
it ('max JSON wire limite', function() {
assert.strictEqual(Amount.bi_xns_max.toString(), '9000000000000000000');
});
it ('max JSON wire limite', function() {
assert.strictEqual(Amount.bi_xns_min.toString(), '-9000000000000000000');
});
it('max mantissa value', function() {
assert.strictEqual(Amount.bi_man_max_value.toString(), '9999999999999999');
});
it('min mantissa value', function() {
assert.strictEqual(Amount.bi_man_min_value.toString(), '1000000000000000');
});
it ('from_json minimum XRP', function() {
console.log('max', Amount.bi_xns_max.toString());
var amt = Amount.from_json('-9000000000000000000');
assert.strictEqual(amt.to_json(), '-9000000000000000000');
});
it ('from_json maximum XRP', function() {
var amt = Amount.from_json('-9000000000000000000');
assert.strictEqual(amt.to_json(), '-9000000000000000000');
});
it ('from_json less than minimum XRP', function() {
var amt = Amount.from_json('-9000000000000000001');
assert.strictEqual(amt.to_json(), '0');
});
it ('from_json more than maximum XRP', function() {
var amt = Amount.from_json('9000000000000000001');
assert.strictEqual(amt.to_json(), '0');
});
it ('from_json minimum IOU', function() {
var amt = Amount.from_json('-1e-81/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
assert.strictEqual(amt._value.toString(), Amount.bi_man_min_value.toString());
assert.strictEqual(amt.to_text(), '-1000000000000000e-96');
assert.strictEqual(amt.to_text(), Amount.min_value);
});
it('from_json exceed minimum IOU', function() {
assert.throws(function() {
Amount.from_json('-1e-82/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')
}, 'Exceeding min value of ' + Amount.min_value);
});
it ('from_json maximum IOU', function() {
var amt = Amount.from_json('9999999999999999e80/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
assert.strictEqual(amt._value.toString(), Amount.bi_man_max_value.toString());
assert.strictEqual(amt.to_text(), '9999999999999999e80');
});
it ('from_json exceed maximum IOU', function() {
assert.throws(function() {
Amount.from_json('9999999999999999e81/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')
}, 'Exceeding max value of ' + Amount.max_value);
});
it ('from_json normalize mantissa to valid max range, lost significant digits', function() {
var amt = Amount.from_json('99999999999999999999999999999999/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
assert.strictEqual(amt._value.toString(), Amount.bi_man_max_value.toString());
assert.strictEqual(amt.to_text(), '9999999999999999e16');
});
it ('from_json normalize mantissa to min valid range, lost significant digits', function() {
var amt = Amount.from_json('-0.0000000000000000000000001/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
assert.strictEqual(amt._value.toString(), Amount.bi_man_min_value.toString());
assert.strictEqual(amt.to_text(), '-1000000000000000e-40');
});
});
});

View File

@@ -1,6 +1,7 @@
var assert = require('assert');
var utils = require('./testutils');
var currency = utils.load_module('currency').Currency;
var timeUtil = utils.load_module('utils').time;
describe('Currency', function() {
describe('json_rewrite', function() {
@@ -16,11 +17,22 @@ describe('Currency', function() {
});
});
describe('from_json', function() {
it('from_json().to_json() == "XRP"', function() {
var r = currency.from_json();
assert(!r.is_valid());
assert.strictEqual('XRP', r.to_json());
});
it('from_json(NaN).to_json() == "XRP"', function() {
var r = currency.from_json(NaN);
assert(!r.is_valid());
assert.strictEqual('XRP', r.to_json());
});
it('from_json().to_json("") == "XRP"', function() {
var r = currency.from_json('');
assert(r.is_valid());
assert(r.is_native());
assert.strictEqual('XRP', r.to_json());
});
it('from_json("XRP").to_json() == "XRP"', function() {
var r = currency.from_json('XRP');
assert(r.is_valid());
@@ -40,8 +52,8 @@ describe('Currency', function() {
});
it('from_json("1D2").to_human()', function() {
var r = currency.from_json("1D2");
assert(!r.is_valid());
assert.strictEqual('XRP', r.to_json());
assert(r.is_valid());
assert.strictEqual('1D2', r.to_json());
});
it('from_json("XAU").to_json() hex', function() {
var r = currency.from_json("XAU");
@@ -82,6 +94,9 @@ describe('Currency', function() {
var cur = currency.from_human('EUR (0.5361%pa)');
assert.strictEqual(cur.to_json(), 'EUR (0.54%pa)');
assert.strictEqual(cur.to_json({decimals:4, full_name:'Euro'}), 'EUR - Euro (0.5361%pa)');
assert.strictEqual(cur.to_json({decimals:void(0), full_name:'Euro'}), 'EUR - Euro (0.54%pa)');
assert.strictEqual(cur.to_json({decimals:undefined, full_name:'Euro'}), 'EUR - Euro (0.54%pa)');
assert.strictEqual(cur.to_json({decimals:'henk', full_name:'Euro'}), 'EUR - Euro (0.54%pa)');
assert.strictEqual(cur.get_interest_percentage_at(undefined, 4), 0.5361);
});
it('From human "TYX - 30-Year Treasuries (1.5%pa)"', function() {
@@ -100,6 +115,16 @@ describe('Currency', function() {
var cur = currency.from_human('INR - 30 Indian Rupees');
assert.strictEqual(cur.to_json(), 'INR');
});
it('From human "XRP"', function() {
var cur = currency.from_human('XRP');
assert.strictEqual(cur.to_json(), 'XRP');
assert(cur.is_native(), true);
});
it('From human "XRP - Ripples"', function() {
var cur = currency.from_human('XRP - Ripples');
assert.strictEqual(cur.to_json(), 'XRP');
assert(cur.is_native(), true);
});
});
@@ -111,8 +136,28 @@ describe('Currency', function() {
assert.strictEqual('XRP', currency.from_json(NaN).to_human());
});
it('"015841551A748AD2C1F76FF6ECB0CCCD00000000") == "015841551A748AD2C1F76FF6ECB0CCCD00000000"', function() {
assert.strictEqual(currency.from_json("015841551A748AD2C1F76FF6ECB0CCCD00000000").to_human(),
'XAU (-0.5%pa)');
assert.strictEqual(currency.from_json("015841551A748AD2C1F76FF6ECB0CCCD00000000").to_human(), 'XAU (-0.5%pa)');
});
it('"015841551A748AD2C1F76FF6ECB0CCCD00000000") == "015841551A748AD2C1F76FF6ECB0CCCD00000000"', function() {
assert.strictEqual(currency.from_json("015841551A748AD2C1F76FF6ECB0CCCD00000000").to_human({full_name:'Gold'}), 'XAU - Gold (-0.5%pa)');
});
it('to_human interest XAU with full name, do not show interest', function() {
assert.strictEqual(currency.from_json("015841551A748AD2C1F76FF6ECB0CCCD00000000").to_human({full_name:'Gold', show_interest:false}), 'XAU - Gold');
});
it('to_human interest XAU with full name, show interest', function() {
assert.strictEqual(currency.from_json("015841551A748AD2C1F76FF6ECB0CCCD00000000").to_human({full_name:'Gold', show_interest:true}), 'XAU - Gold (-0.5%pa)');
});
it('to_human interest XAU, do show interest', function() {
assert.strictEqual(currency.from_json("015841551A748AD2C1F76FF6ECB0CCCD00000000").to_human({show_interest:true}), 'XAU (-0.5%pa)');
});
it('to_human interest XAU, do not show interest', function() {
assert.strictEqual(currency.from_json("015841551A748AD2C1F76FF6ECB0CCCD00000000").to_human({show_interest:false}), 'XAU');
});
it('to_human with full_name "USD - US Dollar show interest"', function() {
assert.strictEqual(currency.from_json('USD').to_human({full_name:'US Dollar', show_interest:true}), 'USD - US Dollar (0%pa)');
});
it('to_human with full_name "USD - US Dollar do not show interest"', function() {
assert.strictEqual(currency.from_json('USD').to_human({full_name:'US Dollar', show_interest:false}), 'USD - US Dollar');
});
it('to_human with full_name "USD - US Dollar"', function() {
assert.strictEqual('USD - US Dollar', currency.from_json('USD').to_human({full_name:'US Dollar'}));
@@ -128,6 +173,7 @@ describe('Currency', function() {
var cur = currency.from_json("TIM");
assert.strictEqual(cur.to_human({full_name: null}), "TIM");
});
});
describe('from_hex', function() {
@@ -138,10 +184,30 @@ describe('Currency', function() {
assert.strictEqual(cur.to_json(), cur.to_human());
});
});
describe('parse_json(currency obj)', function() {
assert.strictEqual('USD', new currency().parse_json(currency.from_json('USD')).to_json());
describe('parse_json', function() {
it('should parse a currency object', function() {
assert.strictEqual('USD', new currency().parse_json(currency.from_json('USD')).to_json());
assert.strictEqual('USD (0.5%pa)', new currency().parse_json(currency.from_json('USD (0.5%pa)')).to_json());
});
it('should clone for parse_json on itself', function() {
var cur = currency.from_json('USD');
var cur2 = currency.from_json(cur);
assert.strictEqual(cur.to_json(), cur2.to_json());
assert.strictEqual('USD (0.5%pa)', new currency().parse_json(currency.from_json('USD (0.5%pa)')).to_json());
cur = currency.from_hex('015841551A748AD2C1F76FF6ECB0CCCD00000000');
cur2 = currency.from_json(cur);
assert.strictEqual(cur.to_json(), cur2.to_json());
});
it('should parse json 0', function() {
var cur = currency.from_json(0);
assert.strictEqual(cur.to_json(), 'XRP');
assert.strictEqual(cur.get_iso(), 'XRP');
});
it('should parse json 0', function() {
var cur = currency.from_json('0');
assert.strictEqual(cur.to_json(), 'XRP');
assert.strictEqual(cur.get_iso(), 'XRP');
});
});
describe('is_valid', function() {
@@ -183,14 +249,16 @@ describe('Currency', function() {
return +(Math.round(num + "e+"+precision) + "e-"+precision);
}
describe('get_interest_at', function() {
it('returns demurred value for demurrage currency', function() {
it('should return demurred value for demurrage currency', function() {
var cur = currency.from_json('015841551A748AD2C1F76FF6ECB0CCCD00000000');
// At start, no demurrage should occur
assert.equal(1, cur.get_interest_at(443845330));
assert.equal(1, precision(cur.get_interest_at(new Date(timeUtil.fromRipple(443845330))), 14));
// After one year, 0.5% should have occurred
assert.equal(0.995, precision(cur.get_interest_at(443845330 + 31536000), 14));
assert.equal(0.995, precision(cur.get_interest_at(new Date(timeUtil.fromRipple(443845330 + 31536000))), 14));
// After one demurrage period, 1/e should have occurred
assert.equal(1/Math.E, cur.get_interest_at(443845330 + 6291418827.05));
@@ -201,6 +269,11 @@ describe('Currency', function() {
// One demurrage period before start, rate should be e
assert.equal(Math.E, cur.get_interest_at(443845330 - 6291418827.05));
});
it('should return 0 for currency without interest', function() {
var cur = currency.from_json('USD - US Dollar');
assert.equal(0, cur.get_interest_at(443845330));
assert.equal(0, cur.get_interest_at(443845330 + 31536000));
});
});
describe('get_iso', function() {
it('should get "XRP" iso_code', function() {

View File

@@ -82,8 +82,17 @@ describe('Message', function(){
});
it('should throw an error if given an invalid secret key', function(){
// Annoyingly non hex can be fed to the BigInteger(s, 16) constructor and
// it will parse as a number. Before the commit of this comment, this test
// involved a fixture of 32 chars, which was assumed to be hex. The test
// passed, but for the wrong wreasons. There was a bug in Seed.parse_json.
var secret_string = 'badsafRpB5euNL52PZPTSqrE9gvuFwTC';
// Seed.from_json only creates invalid seeds from empty strings or invalid
// base58 starting with an s, which it tries to base 58 decode/check sum.
// The rest will be assumed to be a passphrase.
// This is a bad b58 seed
var secret_string = 'sbadsafRpB5euNL52PZPTSqrE9gvuFwTC';
var hash = 'e865bcc63a86ef21585ac8340a7cc8590ed85175a2a718c6fb2bfb2715d13778';
assert.throws(function(){
@@ -261,7 +270,8 @@ describe('Message', function(){
//Remote.prototype.addServer = function(){};
var test_remote = new Remote();
test_remote.state = 'online';
test_remote.request_account_info = function(account, callback) {
test_remote.requestAccountInfo = function(options, callback) {
var account = options.account;
if (account === data.account) {
callback(null, {
"account_data": {
@@ -297,7 +307,8 @@ describe('Message', function(){
//Remote.prototype.addServer = function(){};
var test_remote = new Remote();
test_remote.state = 'online';
test_remote.request_account_info = function(account, callback) {
test_remote.requestAccountInfo = function(options, callback) {
var account = options.account;
if (account === data.account) {
callback(null, {
"account_data": {

View File

@@ -276,7 +276,6 @@ describe('OrderBook', function() {
assert.deepEqual(request.message, {
command: 'account_info',
id: void(0),
ident: 'rrrrrrrrrrrrrrrrrrrrBZbvji',
account: 'rrrrrrrrrrrrrrrrrrrrBZbvji'
});
request.emit('success', {
@@ -330,12 +329,12 @@ describe('OrderBook', function() {
});
});
it('Set funded amount - funded', function() {
it('Set funded amount - iou/xrp - funded', function() {
var remote = new Remote();
var book = remote.createOrderBook({
currency_gets: 'BTC',
currency_pays: 'XRP',
issuer_gets: 'rrrrrrrrrrrrrrrrrrrrBZbvji',
currency_gets: 'BTC'
issuer_gets: 'rrrrrrrrrrrrrrrrrrrrBZbvji'
});
var offer = {
@@ -360,7 +359,37 @@ describe('OrderBook', function() {
assert.deepEqual(offer, expected);
});
it('Set funded amount - unfunded', function() {
it('Set funded amount - iou/xrp - unfunded', function() {
var remote = new Remote();
var book = remote.createOrderBook({
currency_gets: 'BTC',
currency_pays: 'XRP',
issuer_gets: 'rrrrrrrrrrrrrrrrrrrrBZbvji'
});
var offer = {
TakerGets: {
value: '100',
currency: 'BTC',
issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji'
},
TakerPays: '123456'
};
book.setFundedAmount(offer, '99');
var expected = {
TakerGets: offer.TakerGets,
TakerPays: offer.TakerPays,
is_fully_funded: false,
taker_gets_funded: '99',
taker_pays_funded: '122221'
};
assert.deepEqual(offer, expected);
});
it('Set funded amount - xrp/iou - funded', function() {
var remote = new Remote();
var book = remote.createOrderBook({
currency_gets: 'XRP',
@@ -371,7 +400,37 @@ describe('OrderBook', function() {
var offer = {
TakerGets: '100',
TakerPays: {
value: '123456',
value: '123.456',
currency: 'BTC',
issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji'
}
};
book.setFundedAmount(offer, '100.1');
var expected = {
TakerGets: offer.TakerGets,
TakerPays: offer.TakerPays,
is_fully_funded: true,
taker_gets_funded: '100',
taker_pays_funded: '123.456'
};
assert.deepEqual(offer, expected);
});
it('Set funded amount - xrp/iou - unfunded', function() {
var remote = new Remote();
var book = remote.createOrderBook({
currency_gets: 'XRP',
issuer_pays: 'rrrrrrrrrrrrrrrrrrrrBZbvji',
currency_pays: 'BTC'
});
var offer = {
TakerGets: '100',
TakerPays: {
value: '123.456',
currency: 'BTC',
issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji'
}
@@ -384,67 +443,7 @@ describe('OrderBook', function() {
TakerPays: offer.TakerPays,
is_fully_funded: false,
taker_gets_funded: '99',
taker_pays_funded: '122221.44'
};
assert.deepEqual(offer, expected);
});
it('Set funded amount - native currency - funded', function() {
var remote = new Remote();
var book = remote.createOrderBook({
currency_gets: 'XRP',
issuer_pays: 'rrrrrrrrrrrrrrrrrrrrBZbvji',
currency_pays: 'BTC'
});
var offer = {
TakerGets: '100',
TakerPays: {
value: '100.1234',
currency: 'USD',
issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji'
}
};
book.setFundedAmount(offer, '100');
var expected = {
TakerGets: offer.TakerGets,
TakerPays: offer.TakerPays,
is_fully_funded: true,
taker_gets_funded: '100',
taker_pays_funded: '100.1234'
};
assert.deepEqual(offer, expected);
});
it('Set funded amount - native currency - unfunded', function() {
var remote = new Remote();
var book = remote.createOrderBook({
currency_gets: 'XRP',
issuer_pays: 'rrrrrrrrrrrrrrrrrrrrBZbvji',
currency_pays: 'USD'
});
var offer = {
TakerGets: {
value: '100.1234',
currency: 'USD',
issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji'
},
TakerPays: '123'
};
book.setFundedAmount(offer, '100');
var expected = {
TakerGets: offer.TakerGets,
TakerPays: offer.TakerPays,
is_fully_funded: false,
taker_gets_funded: '100',
taker_pays_funded: '122.8484050681459'
taker_pays_funded: '122.22144'
};
assert.deepEqual(offer, expected);
@@ -1360,7 +1359,6 @@ describe('OrderBook', function() {
assert.deepEqual(request.message, {
command: 'account_info',
id: undefined,
ident: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B',
account: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
});
@@ -1497,8 +1495,6 @@ describe('OrderBook', function() {
Flags: 131072,
LedgerEntryType: 'Offer',
OwnerNode: '0000000000000000',
PreviousTxnID: '9BB337CC8B34DC8D1A3FFF468556C8BA70977C37F7436439D8DA19610F214AD1',
PreviousTxnLgrSeq: 8342933,
Sequence: 195,
TakerGets: { currency: 'BTC',
issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B',
@@ -1511,7 +1507,6 @@ describe('OrderBook', function() {
},
index: 'B6BC3B0F87976370EE11F5575593FE63AA5DC1D602830DC96F04B2D597F044BF',
owner_funds: '0.1129267125000245',
quality: '496.5',
taker_gets_funded: '0.1127013098802639',
taker_pays_funded: '55.95620035555102',
is_fully_funded: false },
@@ -1523,8 +1518,6 @@ describe('OrderBook', function() {
Flags: 131072,
LedgerEntryType: 'Offer',
OwnerNode: '0000000000000144',
PreviousTxnID: 'C8296B9CCA6DC594C7CD271C5D8FD11FEE380021A07768B25935642CDB37048A',
PreviousTxnLgrSeq: 8342469,
Sequence: 29354,
TakerGets: {
currency: 'BTC',
@@ -1538,7 +1531,6 @@ describe('OrderBook', function() {
},
index: 'A437D85DF80D250F79308F2B613CF5391C7CF8EE9099BC4E553942651CD9FA86',
owner_funds: '0.950363009783092',
quality: '498.6116758238228',
is_fully_funded: true,
taker_gets_funded: '0.2',
taker_pays_funded: '99.72233516476456'
@@ -1546,7 +1538,7 @@ describe('OrderBook', function() {
]
book.once('model', function(model) {
book.on('model', function(model) {
assert.deepEqual(model, expected);
assert.strictEqual(book._synchronized, true);
done();

View File

@@ -5,7 +5,14 @@ var Remote = utils.load_module('remote').Remote;
var Server = utils.load_module('server').Server;
var Request = utils.load_module('request').Request;
var options, spy, mock, stub, remote, callback, database, tx;
var options, remote, callback, database, tx;
var ADDRESS = 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS';
var PEER_ADDRESS = 'rfYv1TXnwgDDK4WQNbFALykYuEBnrR4pDX';
var LEDGER_INDEX = 9592219;
var LEDGER_HASH = 'B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE';
var PAGING_MARKER = '29F992CC252056BF690107D1E8F2D9FBAFF29FF107B62B1D1F4E4E11ADF2CC73';
describe('Remote', function () {
beforeEach(function () {
@@ -28,19 +35,19 @@ describe('Remote', function () {
// 'bitcoin': 'localhost:3000'
// 'bitcoin': 'https://www.bitstamp.net/ripple/bridge/out/bitcoin/'
}
},
}
};
})
});
it('remote server initialization - url object', function() {
var remote = new Remote({
servers: [ { host: 's-west.ripple.com', port: 443, secure: true } ],
servers: [ { host: 's-west.ripple.com', port: 443, secure: true } ]
});
assert(Array.isArray(remote._servers));
assert(remote._servers[0] instanceof Server);
assert.strictEqual(remote._servers[0]._url, 'wss://s-west.ripple.com:443');
})
});
it('remote server initialization - url object - no secure property', function() {
var remote = new Remote({
@@ -49,7 +56,7 @@ describe('Remote', function () {
assert(Array.isArray(remote._servers));
assert(remote._servers[0] instanceof Server);
assert.strictEqual(remote._servers[0]._url, 'wss://s-west.ripple.com:443');
})
});
it('remote server initialization - url object - secure: false', function() {
var remote = new Remote({
@@ -67,7 +74,7 @@ describe('Remote', function () {
assert(Array.isArray(remote._servers));
assert(remote._servers[0] instanceof Server);
assert.strictEqual(remote._servers[0]._url, 'wss://s-west.ripple.com:443');
})
});
it('remote server initialization - url object - invalid host', function() {
assert.throws(
@@ -76,7 +83,7 @@ describe('Remote', function () {
servers: [ { host: '+', port: 443, secure: true } ]
});
}, Error);
})
});
it('remote server initialization - url object - invalid port', function() {
assert.throws(
@@ -144,7 +151,35 @@ describe('Remote', function () {
);
});
it('request constructors', function () {
it('remote server initialization - set max_fee - number', function() {
var remote = new Remote({
max_fee: 10
});
assert.strictEqual(remote.max_fee, 10);
remote = new Remote({
max_fee: 1234567890
});
assert.strictEqual(remote.max_fee, 1234567890);
});
it('remote server initialization - set max_fee - string fails, should be number', function() {
var remote = new Remote({
max_fee: '1234567890'
});
assert.strictEqual(remote.max_fee, 1e6);
});
it('remote server initialization - max_fee - default', function() {
var remote = new Remote({
max_fee: void(0)
});
assert.strictEqual(remote.max_fee, 1e6);
assert.strictEqual(remote.max_fee, 1000000);
assert.strictEqual((new Remote()).max_fee, 1e6);
});
describe('request constructors', function () {
beforeEach(function () {
callback = function () {}
remote = new Remote(options);
@@ -184,7 +219,222 @@ describe('Remote', function () {
var request = remote.request_unl_delete(null, {}, callback);
assert(request instanceof Request);
});
})
it('request account currencies with ledger index', function() {
var request = remote.requestAccountCurrencies({account: ADDRESS});
assert.strictEqual(request.message.command, 'account_currencies');
assert.strictEqual(request.message.account, ADDRESS);
});
it('request account info with ledger index', function() {
var request = remote.requestAccountInfo({account: ADDRESS, ledger: 9592219});
assert.strictEqual(request.message.command, 'account_info');
assert.strictEqual(request.message.account, ADDRESS);
assert.strictEqual(request.message.ledger_index, 9592219);
});
it('request account info with ledger hash', function() {
var request = remote.requestAccountInfo({account: ADDRESS, ledger: LEDGER_HASH});
assert.strictEqual(request.message.command, 'account_info');
assert.strictEqual(request.message.account, ADDRESS);
assert.strictEqual(request.message.ledger_hash, LEDGER_HASH);
});
it('request account info with ledger identifier', function() {
var request = remote.requestAccountInfo({account: ADDRESS, ledger: 'validated'});
assert.strictEqual(request.message.command, 'account_info');
assert.strictEqual(request.message.account, ADDRESS);
assert.strictEqual(request.message.ledger_index, 'validated');
});
it('request account balance with ledger index', function() {
var request = remote.requestAccountBalance(ADDRESS, 9592219);
assert.strictEqual(request.message.command, 'ledger_entry');
assert.strictEqual(request.message.account_root, ADDRESS);
assert.strictEqual(request.message.ledger_index, 9592219);
});
it('request account balance with ledger hash', function() {
var request = remote.requestAccountBalance(ADDRESS, LEDGER_HASH);
assert.strictEqual(request.message.command, 'ledger_entry');
assert.strictEqual(request.message.account_root, ADDRESS);
assert.strictEqual(request.message.ledger_hash, LEDGER_HASH);
});
it('request account balance with ledger identifier', function() {
var request = remote.requestAccountBalance(ADDRESS, 'validated');
assert.strictEqual(request.message.command, 'ledger_entry');
assert.strictEqual(request.message.account_root, ADDRESS);
assert.strictEqual(request.message.ledger_index, 'validated');
});
});
it('pagingAccountRequest', function() {
var request = Remote.accountRequest('account_lines', {account: ADDRESS});
assert.deepEqual(request.message, {
command: 'account_lines',
id: undefined,
account: ADDRESS
});
});
it('pagingAccountRequest - limit', function() {
var request = Remote.accountRequest('account_lines', {account: ADDRESS, limit: 100});
assert.deepEqual(request.message, {
command: 'account_lines',
id: undefined,
account: ADDRESS,
limit: 100
});
});
it('pagingAccountRequest - limit, marker', function() {
var request = Remote.accountRequest('account_lines', {account: ADDRESS, limit: 100, marker: PAGING_MARKER, ledger: 9592219});
assert.deepEqual(request.message, {
command: 'account_lines',
id: undefined,
account: ADDRESS,
limit: 100,
marker: PAGING_MARKER,
ledger_index: 9592219
});
assert(!request.requested);
});
it('accountRequest - limit min', function() {
assert.strictEqual(Remote.accountRequest('account_lines', {account: ADDRESS, limit: 0}).message.limit, 0);
assert.strictEqual(Remote.accountRequest('account_lines', {account: ADDRESS, limit: -1}).message.limit, 0);
assert.strictEqual(Remote.accountRequest('account_lines', {account: ADDRESS, limit: -1e9}).message.limit, 0);
assert.strictEqual(Remote.accountRequest('account_lines', {account: ADDRESS, limit: -1e24}).message.limit, 0);
});
it('accountRequest - limit max', function() {
assert.strictEqual(Remote.accountRequest('account_lines', {account: ADDRESS, limit: 1e9}).message.limit, 1e9);
assert.strictEqual(Remote.accountRequest('account_lines', {account: ADDRESS, limit: 1e9+1}).message.limit, 1e9);
assert.strictEqual(Remote.accountRequest('account_lines', {account: ADDRESS, limit: 1e10}).message.limit, 1e9);
assert.strictEqual(Remote.accountRequest('account_lines', {account: ADDRESS, limit: 1e24}).message.limit, 1e9);
});
it('accountRequest - a valid ledger is required when using a marker', function() {
assert.throws(function() {
Remote.accountRequest('account_lines', {account: ADDRESS, marker: PAGING_MARKER})
},'A ledger_index or ledger_hash must be provided when using a marker');
assert.throws(function() {
Remote.accountRequest('account_lines', {account: ADDRESS, marker: PAGING_MARKER, ledger:'validated'})
},'A ledger_index or ledger_hash must be provided when using a marker');
assert.throws(function() {
Remote.accountRequest('account_lines', {account: ADDRESS, marker: PAGING_MARKER, ledger:NaN})
},'A ledger_index or ledger_hash must be provided when using a marker');
assert.throws(function() {
Remote.accountRequest('account_lines', {account: ADDRESS, marker: PAGING_MARKER, ledger:LEDGER_HASH.substr(0,63)})
},'A ledger_index or ledger_hash must be provided when using a marker');
assert.throws(function() {
Remote.accountRequest('account_lines', {account: ADDRESS, marker: PAGING_MARKER, ledger:LEDGER_HASH+'F'})
},'A ledger_index or ledger_hash must be provided when using a marker');
});
it('requestAccountLines, account and callback', function() {
var callback = function() {};
var remote = new Remote({
servers: [ { host: 's-west.ripple.com', port: 443, secure: true } ]
});
var request = remote.requestAccountLines(
{account: ADDRESS},
callback
);
assert.deepEqual(request.message, {
command: 'account_lines',
id: undefined,
account: ADDRESS
});
assert(request.requested);
});
it('requestAccountLines, ledger, peer', function() {
var callback = function() {};
var remote = new Remote({
servers: [ { host: 's-west.ripple.com', port: 443, secure: true } ]
});
var request = remote.requestAccountLines(
{
account: ADDRESS,
ledger: LEDGER_HASH,
peer: PEER_ADDRESS
},
callback
);
assert.deepEqual(request.message, {
command: 'account_lines',
id: undefined,
account: ADDRESS,
ledger_hash: LEDGER_HASH,
peer: PEER_ADDRESS
});
assert(request.requested);
});
it('requestAccountLines, ledger, peer, limit and marker', function() {
var callback = function() {};
var remote = new Remote({
servers: [ { host: 's-west.ripple.com', port: 443, secure: true } ]
});
var request = remote.requestAccountLines(
{
account: ADDRESS,
ledger: LEDGER_INDEX,
peer: PEER_ADDRESS,
limit: 200,
marker: PAGING_MARKER
},
callback
);
assert.deepEqual(request.message, {
command: 'account_lines',
id: undefined,
account: ADDRESS,
ledger_index: LEDGER_INDEX,
peer: PEER_ADDRESS,
limit: 200,
marker: PAGING_MARKER
});
assert(request.requested);
});
it('requestAccountOffers, ledger, peer, limit and marker', function() {
var callback = function() {};
var remote = new Remote({
servers: [ { host: 's-west.ripple.com', port: 443, secure: true } ]
});
var request = remote.requestAccountOffers(
{
account: ADDRESS,
ledger: LEDGER_HASH,
peer: PEER_ADDRESS,
limit: 32,
marker: PAGING_MARKER
},
callback
);
assert.deepEqual(request.message, {
command: 'account_offers',
id: undefined,
account: ADDRESS,
ledger_hash: LEDGER_HASH,
peer: PEER_ADDRESS,
limit: 32,
marker: PAGING_MARKER
});
assert(request.requested);
});
it('create remote and get pending transactions', function() {
before(function() {
@@ -244,7 +494,7 @@ describe('Remote', function () {
callback(null, tx);
}
}
})
});
it('should set transaction members correct ', function(done) {
remote = new Remote(options);
@@ -267,9 +517,9 @@ describe('Remote', function () {
},
parseJson: function(json) {}
}
}
};
remote.getPendingTransactions();
})
})
})
});

View File

@@ -326,6 +326,7 @@ describe('Request', function() {
var request = new Request(remote, 'server_info');
request.ledgerChoose();
assert.strictEqual(request.message.ledger_hash, 'B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE');
assert.strictEqual(request.message.ledger_index, void(0));
});
it('Select ledger - identifier', function() {
@@ -335,6 +336,7 @@ describe('Request', function() {
var request = new Request(remote, 'server_info');
request.ledgerSelect('validated');
assert.strictEqual(request.message.ledger_index, 'validated');
assert.strictEqual(request.message.ledger_hash, void(0));
});
it('Select ledger - index', function() {
@@ -344,6 +346,7 @@ describe('Request', function() {
var request = new Request(remote, 'server_info');
request.ledgerSelect(7016915);
assert.strictEqual(request.message.ledger_index, 7016915);
assert.strictEqual(request.message.ledger_hash, void(0));
});
it('Select ledger - hash', function() {
@@ -353,15 +356,23 @@ describe('Request', function() {
var request = new Request(remote, 'server_info');
request.ledgerSelect('B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE');
assert.strictEqual(request.message.ledger_hash, 'B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE');
assert.strictEqual(request.message.ledger_index, void(0));
});
it('Select ledger - hash', function() {
it('Select ledger - undefined', function() {
var remote = new Remote();
remote._connected = true;
var request = new Request(remote, 'server_info');
request.ledgerSelect('B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE');
assert.strictEqual(request.message.ledger_hash, 'B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE');
request.ledgerSelect();
assert.strictEqual(request.message.ledger_hash, void(0));
assert.strictEqual(request.message.ledger_index, void(0));
request.ledgerSelect(null);
assert.strictEqual(request.message.ledger_hash, void(0));
assert.strictEqual(request.message.ledger_index, void(0));
request.ledgerSelect(NaN);
assert.strictEqual(request.message.ledger_hash, void(0));
assert.strictEqual(request.message.ledger_index, void(0));
});
it('Set account_root', function() {

View File

@@ -5,7 +5,6 @@ var config = require('./testutils').get_config();
describe('Seed', function() {
it('can generate many addresses', function () {
var seed = Seed.from_json("masterpassphrase");
var test_data = [
// Format:
@@ -28,10 +27,10 @@ describe('Seed', function() {
function assert_helper(seed_json, address_or_nth, expected) {
var seed = Seed.from_json(seed_json);
var keypair = seed.get_key(address_or_nth);
assert.strictEqual(keypair.to_hex_pub(),
expected);
var keypair = seed.get_key(address_or_nth, 500);
assert.strictEqual(keypair.to_hex_pub(), expected);
}
for (var nth = 0; nth < test_data.length; nth++) {
var seed_json = test_data[nth][0];
var address = test_data[nth][1];
@@ -47,7 +46,30 @@ describe('Seed', function() {
// This isn't too bad as it only needs to generate one keypair `seq`
assert_helper(seed_json, nth_for_seed, expected);
};
});
it('should return the key_pair for a valid account and secret pair', function() {
var address = 'r3GgMwvgvP8h4yVWvjH1dPZNvC37TjzBBE';
var seed = Seed.from_json('shsWGZcmZz6YsWWmcnpfr6fLTdtFV');
var keyPair = seed.get_key(address);
assert.strictEqual(keyPair.get_address().to_json(), address);
assert.strictEqual(keyPair.to_hex_pub(), '02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8');
});
it('should not find a KeyPair for a secret that does not belong to the given account', function() {
var address = 'r3GgMwvgvP8h4yVWvjH1dPZNvC37TjzBBE';
var secret = 'snoPBrXtMeMyMHUVTgbuqAfg1SUTb';
var seed = Seed.from_json('snoPBrXtMeMyMHUVTgbuqAfg1SUTb');
try {
seed.get_key(address);
assert(false, 'should throw an error');
} catch(e) {
assert.strictEqual(e.message, 'Too many loops looking for KeyPair yielding '+address+' from '+secret);
}
});
});
// vim:sw=2:sts=2:ts=8:et

View File

@@ -530,6 +530,51 @@ describe('Server', function() {
server.connect();
});
it('Connect - syncing state', function(done) {
// Test that fee and load defaults are not overwritten by
// undefined properties on server subscribe response
var wss = new ws.Server({ port: 5748 });
wss.once('connection', function(ws) {
ws.once('message', function(message) {
var m = JSON.parse(message);
assert.deepEqual(m, {
command: 'subscribe',
id: 0,
streams: [ 'ledger', 'server' ]
});
ws.send(JSON.stringify({
id: 0,
status: 'success',
type: 'response',
result: {
load_base: 256,
load_factor: 256,
server_status: 'syncing'
}
}));
wss.close();
});
});
var server = new Server(new Remote(), 'ws://localhost:5748');
server.once('connect', function() {
assert(server.isConnected());
assert.strictEqual(server._load_base, 256);
assert.strictEqual(server._load_factor, 256);
assert.strictEqual(server._fee_base, 10);
assert.strictEqual(server._fee_ref, 10);
done();
});
server.connect();
});
it('Reconnect', function(done) {
var server = new Server(new Remote(), 'ws://localhost:5748');
server._connected = true;
@@ -961,12 +1006,6 @@ describe('Server', function() {
assert(server._isConnected());
});
it('Compute fee - transaction', function() {
var server = new Server(new Remote(), 'ws://localhost:5748');
var transaction = new Transaction();
assert.strictEqual(server._computeFee(transaction), '12');
});
it('Compute fee - fee units', function() {
var server = new Server(new Remote(), 'ws://localhost:5748');
var transaction = new Transaction();
@@ -988,7 +1027,7 @@ describe('Server', function() {
server._load_factor = 256 * 4;
var transaction = new Transaction();
assert.strictEqual(server._computeFee(transaction), '48');
assert.strictEqual(server._computeFee(10), '48');
});
it('Compute reserve', function() {

View File

@@ -26,8 +26,9 @@ describe('Signing', function() {
assert(_isNaN(new Seed().parse_json('').to_json()));
});
it('hex string', function() {
// 32 0s is a valid hex repr of seed bytes
var str = new Array(33).join('0');
assert(_isNaN(new Seed().parse_json(str).to_json()));
assert.strictEqual((new Seed().parse_json(str).to_json()), 'sp6JS7f14BuwFY8Mw6bTtLKWauoUs');
});
it('passphrase', function() {
var str = new Array(60).join('0');

View File

@@ -229,6 +229,11 @@ describe('Transaction', function() {
assert.strictEqual(transaction._computeFee(), '72');
});
it('Compute fee, no remote', function() {
var transaction = new Transaction();
assert.strictEqual(transaction._computeFee(10), void(0));
});
it('Compute fee - no connected server', function() {
var remote = new Remote();
@@ -371,6 +376,16 @@ describe('Transaction', function() {
done();
});
it('Complete transaction, local signing, no remote', function(done) {
var transaction = new Transaction();
transaction._secret = 'sh2pTicynUEG46jjR4EoexHcQEoij';
transaction.tx_json.Account = 'rMWwx3Ma16HnqSd4H6saPisihX9aKpXxHJ';
assert(transaction.complete());
done();
});
it('Complete transaction - untrusted', function(done) {
var remote = new Remote();
var transaction = new Transaction(remote);
@@ -811,11 +826,29 @@ describe('Transaction', function() {
assert.strictEqual(transaction.tx_json.LastLedgerSequence, void(0));
assert(!transaction._setLastLedger);
transaction.lastLedger(NaN);
assert.strictEqual(transaction.tx_json.LastLedgerSequence, void(0));
assert(!transaction._setLastLedger);
transaction.lastLedger(12);
assert.strictEqual(transaction.tx_json.LastLedgerSequence, 12);
assert(transaction._setLastLedger);
});
it('Set Max Fee', function() {
var transaction = new Transaction();
transaction.maxFee('a');
assert(!transaction._setMaxFee);
transaction.maxFee(NaN);
assert(!transaction._setMaxFee);
transaction.maxFee(1000);
assert.strictEqual(transaction._maxFee, 1000);
assert.strictEqual(transaction._setMaxFee, true);
});
it('Rewrite transaction path', function() {
var transaction = new Transaction();
@@ -1501,6 +1534,18 @@ describe('Transaction', function() {
transaction.submit(submitCallback);
});
it('Submit transaction - submission error, no remote', function(done) {
var transaction = new Transaction();
transaction.once('error', function(error) {
assert(error);
assert.strictEqual(error.message, 'No remote found');
done();
});
transaction.submit();
});
it('Submit transaction - invalid account', function(done) {
var remote = new Remote();
var transaction = new Transaction(remote).accountSet('r36xtKNKR43SeXnGn7kN4r4JdQzcrkqpWe');
@@ -1515,33 +1560,34 @@ describe('Transaction', function() {
transaction.submit();
});
it.skip('Abort submission', function(done) {
it('Abort submission on presubmit', function(done) {
var remote = new Remote();
var transaction = new Transaction(remote).accountSet('r36xtKNKR43SeXnGn7kN4r4JdQzcrkqpWe');
var account = remote.addAccount('r36xtKNKR43SeXnGn7kN4r4JdQzcrkqpWe');
remote.setSecret('rJaT8TafQfYJqDm8aC5n3Yx5yWEL2Ery79', 'snPwFATthTkKnGjEW73q3TL4yci1Q');
var server = new Server(remote, 'wss://s1.ripple.com:443');
server._computeFee = function() { return '12'; };
server._connected = true;
remote._servers.push(server);
remote._connected = true;
remote._ledger_current_index = 1;
var transaction = new Transaction(remote).accountSet('rJaT8TafQfYJqDm8aC5n3Yx5yWEL2Ery79');
var account = remote.account('rJaT8TafQfYJqDm8aC5n3Yx5yWEL2Ery79');
account._transactionManager._nextSequence = 1;
account._transactionManager._request = function(tx) {
setTimeout(function() {
tx.emit('success', { });
}, 20);
};
transaction.once('presubmit', function() {
transaction.abort();
});
transaction.complete = function() {
return this;
};
function submitCallback(err, res) {
transaction.submit(function(err, res) {
setImmediate(function() {
assert(err);
assert.strictEqual(err.result, 'tejAbort');
done();
});
};
transaction.submit(submitCallback);
transaction.abort();
});
});
});

View File

@@ -20,6 +20,7 @@ var exampleData = {
email_token : '77825040-9096-4695-9cbc-76720f6a8649',
activateLink : 'https://staging.ripple.com/client/#/register/activate/',
device_id : "ac1b6f6dbca98190eb9687ba06f0e066",
identity_id : "17fddb71-a5c2-44ce-8b50-4b381339d4f2",
blob: {
url: 'https://id.staging.ripple.com',
id: 'ef203d3e76552c0592384f909e6f61f1d1f02f61f07643ce015d8b0c9710dd2f',
@@ -103,12 +104,29 @@ var recoverRes = {
result: 'success'
}
}
var getProfileRes = {
"result":"success",
"addresses":[],
"attributes":[{
"attribute_id":"4034e477-ffc9-48c4-bcbc-058293f081d8",
"identity_id":"17fddb71-a5c2-44ce-8b50-4b381339d4f2",
"name":"email",
"type":"default",
"domain":null,
"value":"example@example.com",
"visibility":"public",
"updated":null
}
]
};
var blob = new Blob();
blob.url = exampleData.blob.url;
blob.id = exampleData.blob.id;
blob.device_id = exampleData.device_id;
blob.key = exampleData.blob.key;
blob.identity_id = exampleData.blob.identity_id;
blob.data = exampleData.blob.data;
blob.revision = exampleData.blob.data.revision;
@@ -133,14 +151,12 @@ var mockDelete;
if (!online) {
mockRippleTxt = nock('https://ripple.com')
.persist()
.get('/ripple.txt')
.reply(200, rippleTxtRes, {
'Content-Type': 'text/plain'
});
mockRippleTxt2 = nock('https://' + exampleData.domain)
.persist()
.get('/ripple.txt')
.reply(200, rippleTxtRes, {
'Content-Type': 'text/plain'
@@ -153,21 +169,21 @@ if (!online) {
'Content-Type': 'text/plain'
});
mockRegister = nock('https://id.staging.ripple.com').persist();
mockRegister = nock('https://id.staging.ripple.com');
mockRegister.filteringPath(/(v1\/user\?signature(.+))/g, 'register/')
.post('/register/')
.reply(200, { result: 'error', message: 'User already exists' }, {
'Content-Type': 'application/json'
});
mockDelete = nock('https://id.staging.ripple.com').persist();
mockDelete = nock('https://id.staging.ripple.com');
mockDelete.filteringPath(/(v1\/user\/(.+))/g, 'delete/')
.delete('/delete/')
.reply(200, { result: 'success' }, {
'Content-Type': 'application/json'
});
mockBlob = nock('https://id.staging.ripple.com').persist();
mockBlob = nock('https://id.staging.ripple.com');
mockBlob.get('/v1/authinfo?domain=' + exampleData.domain + '&username=' + exampleData.username.toLowerCase())
.reply(200, JSON.stringify(authInfoRes.body), {
'Content-Type': 'application/json'
@@ -185,47 +201,40 @@ if (!online) {
'Content-Type': 'application/json'
});
mockRename = nock('https://id.staging.ripple.com/v1/user/').persist();
mockRename = nock('https://id.staging.ripple.com/v1/user/');
mockRename.filteringPath(/((.+)\/rename(.+))/g, 'rename/')
.post('rename/')
.reply(200, {result:'success',message:'rename'}, {
'Content-Type': 'application/json'
});
mockUpdate = nock('https://id.staging.ripple.com/v1/user/').persist();
mockUpdate.filteringPath(/((.+)\/update(.+))/g, 'update/')
mockUpdate = nock('https://id.staging.ripple.com/v1/user/');
mockUpdate.filteringPath(/((.+)\/updatekeys(.+))/g, 'update/')
.post('update/')
.reply(200, {result:'success',message:'updateKeys'}, {
'Content-Type': 'application/json'
});
mockRecover = nock('https://id.staging.ripple.com/').persist();
mockRecover = nock('https://id.staging.ripple.com/')
mockRecover.filteringPath(/((.+)user\/recov\/(.+))/g, 'recov/')
.get('recov/')
.reply(200, recoverRes.body, {
'Content-Type': 'application/json'
});
mockVerify = nock('https://id.staging.ripple.com/v1/user/').persist();
mockVerify = nock('https://id.staging.ripple.com/v1/user/');
mockVerify.filteringPath(/((.+)\/verify(.+))/g, 'verify/')
.get('verify/')
.reply(200, {result:'error', message:'invalid token'}, {
'Content-Type': 'application/json'
});
mockEmail = nock('https://id.staging.ripple.com/v1/user').persist();
mockEmail = nock('https://id.staging.ripple.com/v1/user');
mockEmail.filteringPath(/((.+)\/email(.+))/g, 'email/')
.post('email/')
.reply(200, {result:'success'}, {
'Content-Type': 'application/json'
});
mockProfile = nock('https://id.staging.ripple.com/v1/user').persist();
mockProfile.filteringPath(/((.+)\/profile(.+))/g, 'profile/')
.post('profile/')
.reply(200, {result:'success'}, {
'Content-Type': 'application/json'
});
}
describe('Ripple Txt', function () {
@@ -419,6 +428,7 @@ describe('VaultClient', function () {
});
});
/*
describe('#updateProfile', function () {
it('should update profile parameters associated with a blob', function (done) {
this.timeout(10000);
@@ -442,7 +452,7 @@ describe('VaultClient', function () {
});
});
});
*/
});
@@ -693,7 +703,95 @@ describe('Blob', function () {
});
});
});
describe('identityVault', function() {
it('#identity - Get Attestation', function (done) {
var options = {
url : blob.url,
auth_secret : blob.data.auth_secret,
blob_id : blob.id,
};
options.type = 'identity';
nock('https://id.staging.ripple.com')
.filteringPath(/(v1\/attestation\/identity(.+))/g, '')
.post('/')
.reply(200, {
result: 'success',
status: 'verified',
attestation: 'eyJ6IjoieiJ9.eyJ6IjoieiJ9.sig',
blinded:'eyJ6IjoieiJ9.eyJ6IjoieiJ9.sig'
}, {'Content-Type': 'application/json'});
client.getAttestation(options, function(err, resp) {
assert.ifError(err);
assert.strictEqual(resp.result, 'success');
assert.strictEqual(typeof resp.attestation, 'string');
assert.strictEqual(typeof resp.blinded, 'string');
assert.deepEqual(resp.decoded, {"header":{"z":"z"},"payload":{"z":"z"},"signature":"sig"})
done();
});
});
it('#identity - Update Attestation', function (done) {
var options = {
url : blob.url,
auth_secret : blob.data.auth_secret,
blob_id : blob.id,
};
options.type = 'identity';
nock('https://id.staging.ripple.com')
.filteringPath(/(v1\/attestation\/identity\/update(.+))/g, '')
.post('/')
.reply(200, {
result: 'success',
status: 'verified',
attestation: 'eyJ6IjoieiJ9.eyJ6IjoieiJ9.sig',
blinded:'eyJ6IjoieiJ9.eyJ6IjoieiJ9.sig'
}, {'Content-Type': 'application/json'});
client.updateAttestation(options, function(err, resp) {
assert.ifError(err);
assert.strictEqual(resp.result, 'success');
assert.strictEqual(typeof resp.attestation, 'string');
assert.strictEqual(typeof resp.blinded, 'string');
assert.deepEqual(resp.decoded, {"header":{"z":"z"},"payload":{"z":"z"},"signature":"sig"})
done();
});
});
it('#identity - Get Attestation Summary', function (done) {
var options = {
url : blob.url,
auth_secret : blob.data.auth_secret,
blob_id : blob.id,
};
nock('https://id.staging.ripple.com')
.filteringPath(/(v1\/attestation\/summary(.+))/g, '')
.get('/')
.reply(200, {
result: 'success',
attestation: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IjY2ZGI3MzgxIn0%3D.eyJwcm9maWxlX3ZlcmlmaWVkIjpmYWxzZSwiaWRlbnRpdHlfdmVyaWZpZWQiOmZhbHNlLCJpc3MiOiJodHRwczovL2lkLnJpcHBsZS5jb20iLCJzdWIiOiIwNDMzNTA0ZS0yYTRmLTQ1NjktODQwMi1lYWI2YTU0YTgzYjUiLCJleHAiOjE0MTI4MTc2NjksImlhdCI6MTQxMjgxNTgwOX0%3D.Jt14Y2TsM7fKqGWn0j16cPldlYqRr7%2F2dptBsdZuZhRGRTREO4TSpZZhBaU95WL3M9eXIfaoSs8f2pTOa%2BBGAYHZSZK4%2FLqeWdDH8zz8Bx9YFqGije1KmHQR%2FeoWSp1GTEfcq5Oho4nSHozHhGNN8IrDkl8woMvWb%2FE1938Y5Zl2vyv7wjlNUF4ND33XWzJkvQjzIK15uYfaB%2FUIsNW32udfHAdkigesdMDNm%2BRGBqHMDZeAMdVxzrDzE3m8oWKDMJXbcaLmk75COfJrLWYiZCHd7VcReyPEZegwEucetZJ9uDnoBcvw0%2B6hIRmjTN6Gy1eeBoJaiDYsWuOwInbIlw%3D%3D',
}, {'Content-Type': 'application/json'});
client.getAttestationSummary(options, function(err, resp) {
assert.ifError(err);
assert.strictEqual(resp.result, 'success');
assert.strictEqual(typeof resp.attestation, 'string');
assert.strictEqual(typeof resp.decoded.header, 'object');
assert.strictEqual(typeof resp.decoded.payload, 'object');
assert.strictEqual(typeof resp.decoded.signature, 'string');
done();
});
});
});
//only do these offline
if (!online) {