Compare commits

...

242 Commits

Author SHA1 Message Date
Geert Weening
fcc9bacb4e bump version to 0.13.0-rc10 2015-09-22 18:33:48 -07:00
wltsmrz
9a5e8fd2ba Merge pull request #558 from clark800/wss
Add pattern for servers option
2015-09-22 18:25:17 -07:00
Chris Clark
c213b98329 Add pattern for servers option 2015-09-21 17:34:39 -07:00
Alan Cohen
27d2e6e519 Merge pull request #557 from clark800/ledger-close
Add ledgerClosed event
2015-09-21 15:33:44 -07:00
Chris Clark
7ee368965c Add ledgerClosed event 2015-09-21 14:38:51 -07:00
Alan Cohen
d8b5b825b3 Update verison to 0.13.0-rc9 2015-09-21 10:48:03 -07:00
Chris Clark
60c604fbe6 Merge pull request #536 from sentientwaffle/dj/suspay
suspended payments
2015-09-18 10:58:10 -07:00
sentientwaffle
2f6d25ed01 lint 2015-09-18 10:52:00 -07:00
sentientwaffle
b134081293 Add SuspendedPayment{Create,Finish,Cancel}
* Add SusPay core tests
* Rename SusPay -> SuspendedPayment (code review)
* Rename cancelAfter -> allowCancelAfter
* Rename suspendedPayment{Finish,Execution}
2015-09-18 10:51:34 -07:00
Chris Clark
a0528d7f9c Merge pull request #553 from darkdarkdragon/develop-master-merge
Merge OrderBook optimizations from master to develop
2015-09-18 10:41:22 -07:00
Alan Cohen
348335ddf0 Merge pull request #556 from clark800/tel-fix
Remove "tel" errors from submit's immediate failure category
2015-09-17 17:20:42 -07:00
Ivan Tivonenko
01752e5486 fix eslint errors 2015-09-18 03:15:09 +03:00
Chris Clark
3e758e1b86 Remove "tel" errors from submit's immediate failure category 2015-09-17 17:06:12 -07:00
Chris Clark
fb0b30a9a7 Merge pull request #555 from lumberj/add-data-to-error
RippleAPI: Add data property to error object
2015-09-17 16:29:12 -07:00
Alan Cohen
0c9aea454e RippleAPI: Add data property to error object 2015-09-17 16:05:43 -07:00
Ivan Tivonenko
20fa8bc953 optimize AutobridgeCalculator and Amount for speed 2015-09-17 19:06:47 +03:00
Alan Cohen
778f59b4fd Merge pull request #535 from clark800/submit-error
Return promise error if submit result is an immediate failure
2015-09-16 17:53:35 -07:00
Chris Clark
49623cb4dd Merge pull request #550 from lumberj/max-ledger-sequence
Set default maxLedgerVersion to last closed ledger when requesting ac…
2015-09-16 17:11:11 -07:00
Alan Cohen
90b53002aa Set default maxLedgerVersion to last closed ledger when requesting account_tx 2015-09-16 16:45:25 -07:00
Alan Cohen
93c12af305 Merge pull request #548 from lumberj/check-disjoint
Add PendingLedgerVersionError
2015-09-16 16:29:46 -07:00
Alan Cohen
60f2419b5c Add PendingLedgerVersionError
MissingLedgerHistoryError - no minLedgerVersion or maxLedgerVersion
There is a ledger gap, but a range should be provided to narrow down the range
of the gap.

MissingLedgerHistoryError
When requesting a tx, if maxLedgerVersion and minLedgerVersion provided, this
means there is a ledger gap in the provided range.

PendingLedgerVersionError:
If maxLedgerVersion provided, check if ledger is ahead of the server's last
validated ledger.
2015-09-16 15:57:55 -07:00
Chris Clark
80494ad813 Return promise error if submit result is an immediate failure 2015-09-16 15:56:24 -07:00
Alan Cohen
b43c4a7ad4 Merge pull request #549 from lumberj/validated-tx
Do not return non-validated transaction from RippleAPI#getTransaction
2015-09-16 12:29:23 -07:00
Alan Cohen
3c608de5bb Do not return non-validated transaction from RippleAPI#getTransaction 2015-09-16 12:19:20 -07:00
Chris Clark
fe5bc1d215 Merge pull request #538 from darkdarkdragon/develop-negative-error
shows event that leads to "Offer total cannot be negative" error
2015-09-16 10:26:19 -07:00
Ivan Tivonenko
580bf9a755 shows event that leads to "Offer total cannot be negative" error 2015-09-16 09:57:51 +03:00
Ivan Tivonenko
c7df5df163 make tests pass 2015-09-15 09:14:12 +03:00
Ivan Tivonenko
a08c52af55 Merge branch 'master' into develop-master-merge 2015-09-15 06:29:26 +03:00
Chris Clark
e11db0f0f3 Merge pull request #547 from vhpoet/develop
Remote: Add LowFreeze, HighFreeze flags
2015-09-14 16:59:20 -07:00
Vahe Hovhannisyan
c6e0582729 Remote: Add LowFreeze, HighFreeze flags 2015-09-14 16:57:13 -07:00
wltsmrz
6e98629f9b Merge pull request #543 from darkdarkdragon/develop-reconnect
resend request in case server was disconnected after request was sent
2015-09-13 02:14:22 -07:00
sublimator
2243760442 Merge pull request #541 from wltsmrz/add-tecOVERSIZE
Add tecOVERSIZE transaction result
2015-09-13 16:11:26 +07:00
wltsmrz
91dd6877aa Add tecOVERSIZE transaction result 2015-09-13 02:07:53 -07:00
sublimator
e73bcd8fc1 Merge pull request #545 from wltsmrz/add-multisign
Add multisign helpers
2015-09-13 15:10:19 +07:00
wltsmrz
7e886b3260 Add multisign helpers 2015-09-13 00:59:27 -07:00
Ivan Tivonenko
5c9451d3ed allow Request.request(callback) 2015-09-12 22:18:52 +03:00
wltsmrz
c6c2dcc6c0 Merge pull request #533 from clark800/webpack-net-fix
Fix browser build
2015-09-11 13:15:58 -07:00
wltsmrz
0bdd37090e Merge pull request #537 from darkdarkdragon/master-performance
Optimize performance (for 0.12 master branch)
2015-09-10 17:04:16 -07:00
Ivan Tivonenko
c745faaaf0 optimize baseconverter , OrderBook and AutobridgeCalculator for speed 2015-09-11 02:34:48 +03:00
Alan Cohen
9ad03ca873 Bump version to 0.13.0-rc8 2015-09-09 13:22:18 -07:00
wltsmrz
138914384e Merge pull request #531 from clark800/fix-pathfind-queue
Fix queueing of pathfind requests
2015-09-09 13:09:34 -07:00
Ivan Tivonenko
77068667e4 move reconnect logic from Request.callback to Request.request 2015-09-09 21:16:10 +03:00
Ivan Tivonenko
c57cef4a21 resend request in case server was disconnected after request was sent 2015-09-09 02:22:02 +03:00
Alan Cohen
50acc4c708 Merge pull request #542 from lumberj/fix-destination_currencies
Fix: Check for destination_currencies property
2015-09-08 16:04:54 -07:00
Alan Cohen
b5f8ba4817 Fix: Check for destination_currencies property
Example stack:

TypeError: Cannot read property 'join' of undefined
    at formatResponse
    (ripple-lib/dist/npm/api/ledger/pathfind.js:75:187)
2015-09-08 16:02:23 -07:00
Alan Cohen
a53249ccd7 Bump version to 0.13.-rc7 2015-09-03 14:04:07 -07:00
Ivan Tivonenko
0c62fa2112 remove Firefox warning about prototype overwrite 2015-09-01 01:34:59 +03:00
Ivan Tivonenko
806547dd15 fix Amount compare bug
return 0 if values not comparable
2015-09-01 01:29:37 +03:00
Chris Clark
fb1669b2b3 Merge pull request #534 from clark800/prepare
Return instructions in prepare responses
2015-08-28 15:31:59 -07:00
Chris Clark
0cda15f2b5 Update is-my-json-valid depedency to fix webpack issue 2015-08-28 14:18:02 -07:00
Chris Clark
b88e9370c6 Return instructions in prepare responses 2015-08-28 14:11:02 -07:00
Chris Clark
e343f3beb8 Remove usage of fs module because it does not work in browser 2015-08-28 11:53:45 -07:00
Chris Clark
a13bfae714 Merge pull request #528 from mDuo13/min_value_abs
remove redundant abs from MIN_IOU_VALUE
2015-08-27 14:27:33 -07:00
mDuo13
877c6bbb2a amount min/max - more tests 2015-08-27 14:06:47 -07:00
Chris Clark
30d5134394 Fix require failure in browser code due to proxy library 2015-08-27 11:57:15 -07:00
Chris Clark
fae5c74487 Merge pull request #530 from clark800/remove-methods
Remove computeLedgerHash and isValidAddress from API
2015-08-26 17:57:15 -07:00
Chris Clark
255332ea2e Fix queueing of pathfind requests 2015-08-26 17:38:11 -07:00
Chris Clark
15c0e6db19 Remove computeLedgerHash and isValidAddress from API 2015-08-26 17:19:09 -07:00
mDuo13
2b600a1e4e more amount minimum abs test fixes 2015-08-26 12:26:47 -07:00
mDuo13
297fb2483d fix test for amount min 2015-08-25 17:38:32 -07:00
mDuo13
5049822415 remove redundant abs from MIN_IOU_VALUE 2015-08-25 17:14:33 -07:00
Chris Clark
e3787e0f4f Merge pull request #527 from clark800/fix-getpaths
Use maxAmount in getPaths results so they can be passed to preparePayment
2015-08-25 15:18:21 -07:00
Chris Clark
683199044b Use maxAmount in getPaths results so they can be passed to preparePayment 2015-08-25 15:14:06 -07:00
sublimator
4f3c3e9f66 Merge pull request #524 from wltsmrz/deprecate-positional-api
Deprecate positional request constructor API
2015-08-25 20:52:59 +07:00
wltsmrz
fc0240c06b Deprecate positional request constructor API 2015-08-25 06:42:47 -07:00
sublimator
6bfa284bac Merge pull request #526 from sublimator/update-legacy-support
Update legacy-support & JSDoc comments
2015-08-25 20:18:06 +07:00
Nicholas Dudfield
dfee9bc578 Update legacy-support & JSDoc comments 2015-08-25 20:14:14 +07:00
Chris Clark
0838a0e865 Merge pull request #525 from clark800/test-compiled
Fix testing of compiled library
2015-08-24 17:57:50 -07:00
Chris Clark
5f61d80e2d Fix bugs in compiled library 2015-08-24 17:38:30 -07:00
Chris Clark
c4fa4c237c Compile test cases to run tests without using Babel 2015-08-24 16:58:50 -07:00
Geert Weening
44d00d5ef4 Bump version to 0.13.0-rc6 2015-08-24 14:24:48 -07:00
Geert Weening
d4d3efcb65 Update releas notes 2015-08-24 14:24:40 -07:00
Geert Weening
f23e105240 Merge branch 'develop' into release 2015-08-24 13:47:00 -07:00
Chris Clark
5a396a7060 Merge pull request #517 from darkdarkdragon/develop-RLJS-463
Add schema for RippleAPI constructor options
2015-08-24 11:39:21 -07:00
Ivan Tivonenko
513632299f Add schema for RippleAPI constructor options 2015-08-24 21:29:50 +03:00
Chris Clark
0d40558f1e Merge pull request #522 from clark800/srcActNotFound-pathfind
Fix: Emit error events and return error on pathfind
2015-08-21 14:26:19 -07:00
Alan Cohen
1ccbaf6776 Fix: Emit error events and return error on pathfind 2015-08-21 14:24:13 -07:00
sublimator
ba6c703163 Merge pull request #518 from darkdarkdragon/develop-RLJS-467
Allow to specify server url without explicit port number
2015-08-21 20:41:25 +07:00
sublimator
3b9eb02bbb Merge pull request #520 from sublimator/ledger-select
Update ledgerSelect to throw if ledger arg is unrecognized
2015-08-21 17:34:35 +07:00
Nicholas Dudfield
bca7382015 Update ledgerSelect to throw if ledger arg is unrecognized 2015-08-21 15:31:14 +07:00
wltsmrz
67672bd389 Merge pull request #519 from sublimator/hackz
Move positional args wrappers into legacy-support module
2015-08-21 14:19:50 +07:00
Nicholas Dudfield
232017d9a2 Move positional args wrappers into legacy-support module 2015-08-21 14:06:32 +07:00
Ivan Tivonenko
23653f67f0 Allow to specify server url without explicit port number 2015-08-21 06:39:48 +03:00
Chris Clark
e3b688d1dd Merge pull request #516 from darkdarkdragon/develop-server-info-schema-fix
fix get-server-info.json schema
2015-08-20 17:40:03 -07:00
Ivan Tivonenko
a94b21ca3c fix get-server-info.json schema 2015-08-21 03:36:04 +03:00
Geert Weening
9c9be3e6e4 Bump version to 0.13.0-rc5 2015-08-20 13:46:11 -07:00
Chris Clark
062561686e Update release notes 2015-08-20 11:49:04 -07:00
Geert Weening
761682c206 Merge branch 'develop' into release 2015-08-20 10:18:22 -07:00
Chris Clark
39c48d631c Merge pull request #513 from darkdarkdragon/develop-parse-trustline-fix
fix parseTrustline for case when no QualityIn or QualityOut are set i…
2015-08-19 11:20:32 -07:00
Ivan Tivonenko
a55d26a726 fix parseTrustline for case when no QualityIn or QualityOut are set in transaction 2015-08-19 21:17:50 +03:00
Chris Clark
597ae157b3 Merge pull request #515 from darkdarkdragon/develop-isvalidaddress-fix
in isValidAddress check that address starting with 'r'
2015-08-19 10:56:40 -07:00
wltsmrz
c1c7458914 Merge pull request #514 from sublimator/eslint-1.2.0
Update eslint to 1.2.0
2015-08-19 16:28:14 +07:00
Ivan Tivonenko
0e97f269ab in isValidAddress check that address starting with 'r'
because UInt160 considers valid hex values
2015-08-19 05:26:08 +03:00
Nicholas Dudfield
bbe4cd63a1 Update eslint to 1.2.0 2015-08-19 08:41:35 +07:00
Chris Clark
2515d17a85 Merge pull request #509 from clark800/generate-address
Rename generateWallet to generateAddress
2015-08-18 18:11:22 -07:00
Chris Clark
d8e95a3c3b Rename generateWallet to generateAddress 2015-08-18 17:44:10 -07:00
Chris Clark
98f6bed8c9 Merge pull request #511 from darkdarkdragon/develop-filter-fix
fix transactionFilter
2015-08-18 17:21:17 -07:00
Ivan Tivonenko
bd000c2662 fix transactionFilter 2015-08-19 03:15:10 +03:00
Chris Clark
a46141111a Merge pull request #512 from clark800/validate-address
Add isValidAddress
2015-08-18 14:48:44 -07:00
Chris Clark
f57c89c6e9 Add isValidAddress 2015-08-18 14:46:11 -07:00
Chris Clark
6d4cac948d Merge pull request #504 from clark800/get-ledger
Add getLedger method, remove getLedgerHeader method
2015-08-18 10:01:22 -07:00
Chris Clark
1f54b3a0cf Rename ledger "account" to "state" 2015-08-17 18:41:22 -07:00
Chris Clark
2f8655dc23 Add getLedger method, remove getLedgerHeader method 2015-08-17 18:39:34 -07:00
sublimator
d624923cd8 Merge pull request #510 from clark800/underscore-fixes
Fix snake case method calls
2015-08-18 07:33:56 +07:00
Chris Clark
2180c076dd Fix snake case method calls 2015-08-17 17:28:16 -07:00
Chris Clark
0dbdf0a21a Merge pull request #503 from darkdarkdragon/develop-RLJS-444-01
annotate api functions with types
2015-08-17 14:34:12 -07:00
Ivan Tivonenko
5cb63a258c annotate api functions with types 2015-08-17 20:51:03 +03:00
Chris Clark
39ac6caaef Merge pull request #506 from sublimator/uint-scraggles
Remove UInt#from_bn
2015-08-17 10:04:18 -07:00
Chris Clark
de4ef8b2b4 Merge pull request #505 from sublimator/reserve
[WIP] Fix reserve calculation
2015-08-17 10:01:10 -07:00
Nicholas Dudfield
99cba09a4a Remove UInt#from_bn 2015-08-16 21:31:46 +07:00
Nicholas Dudfield
300967f0f3 [WIP] Fix lint issues 2015-08-15 18:15:36 +07:00
Nicholas Dudfield
52879febb9 [WIP] Fix reserve calculation 2015-08-15 18:11:43 +07:00
Chris Clark
f077a563c4 Merge pull request #498 from clark800/compute-ledger-hash
Add computeLedgerHash method
2015-08-14 14:43:57 -07:00
Chris Clark
92fbc61f47 Add computeLedgerHash method 2015-08-14 14:25:56 -07:00
Chris Clark
5ac1bcc414 Merge pull request #502 from sublimator/hash.js
Remove sjcl-extended/ripple-wallet-generator. Use hash.js & sjcl-codec.
2015-08-14 11:14:33 -07:00
Nicholas Dudfield
5837aa23ea Remove sjcl-extended/ripple-wallet-generator. Use hash.js & sjcl-codec. 2015-08-14 09:31:49 +07:00
Chris Clark
8c431b4ec3 Merge pull request #499 from clark800/validated-ledger
Get validated ledger in getSettings and getAccountInfo
2015-08-13 13:20:55 -07:00
sublimator
25086a7944 Merge pull request #501 from sublimator/bn.js
Replace sjcl.bn with bn.js
2015-08-14 01:38:13 +07:00
Nicholas Dudfield
b0889b4afe Replace sjcl.bn with bn.js 2015-08-14 01:33:59 +07:00
wltsmrz
ed971bc41c Merge pull request #500 from clark800/get-ledger-header
Add getLedgerHeader method
2015-08-13 07:57:45 +07:00
Chris Clark
728595dc96 Add getLedgerHeader method 2015-08-12 17:37:13 -07:00
Chris Clark
7fc6adb776 Get validated ledger in getSettings and getAccountInfo 2015-08-12 15:58:47 -07:00
Chris Clark
002102ce62 Merge pull request #494 from clark800/streaming-pathfinding
Use streaming pathfinding: rippled path_find instead of ripple_path_find
2015-08-12 13:14:13 -07:00
Chris Clark
bf9da80d46 Fix lint errors in remote.js and pathfind.js 2015-08-12 12:34:12 -07:00
Chris Clark
dda9994869 Use streaming pathfinding: rippled path_find instead of ripple_path_find 2015-08-12 12:34:08 -07:00
sublimator
4c76ad159e Merge pull request #495 from sublimator/ripple-keypairs
Use ripple-keypairs and ripple-address-codec
2015-08-12 13:01:56 +07:00
Nicholas Dudfield
f76a8daca8 Update babel, eslint & co 2015-08-12 12:54:33 +07:00
Nicholas Dudfield
3263629ebe Use ripple-keypairs and ripple-address-codec 2015-08-12 12:54:30 +07:00
Chris Clark
fcbe7d3c98 Merge pull request #493 from clark800/max-amount-2
Rename source.amount to source.maxAmount
2015-08-10 14:29:47 -07:00
Chris Clark
a6662ccdff Rename source.amount to source.maxAmount 2015-08-10 14:15:30 -07:00
Chris Clark
854fe85151 Check for duplicate schema titles 2015-08-10 11:35:41 -07:00
Geert Weening
2b2fdf1b11 Bump version to 0.13.0-rc4 2015-08-07 15:32:21 -07:00
Geert Weening
cbe44d6a96 Update release notes 2015-08-07 15:32:21 -07:00
Geert Weening
420346faea Bump version to 0.13.0-rc3 2015-08-07 15:32:20 -07:00
Geert Weening
6220162852 Update release notes 2015-08-07 15:32:20 -07:00
Geert Weening
37198bde66 Bump version to 0.13.0-rc4 2015-08-07 15:31:56 -07:00
Geert Weening
281c056f6c Update release notes 2015-08-07 15:31:24 -07:00
Geert Weening
49a513cd07 Merge branch 'release' into develop 2015-08-07 14:47:26 -07:00
Alan Cohen
7a95aabbf4 Merge pull request #491 from lumberj/empty-paths
Don't set empty paths
2015-08-07 10:35:41 -07:00
Alan Cohen
83874ec096 Don't set empty paths
"The Paths field must not be an empty array, nor an array whose members are all
empty arrays."
https://ripple.com/build/transactions/#paths

Fix test file lint errors
2015-08-07 10:26:45 -07:00
Chris Clark
9270d0a33d Merge pull request #490 from clark800/test-dist
Clean up package.json
2015-08-06 15:30:09 -07:00
Chris Clark
30295efdb4 Clean up package.json 2015-08-06 15:09:49 -07:00
Chris Clark
f1342c1456 Merge pull request #489 from clark800/test-compiled
Test compiled code in dist/npm on CI server
2015-08-06 15:02:56 -07:00
Chris Clark
194b73c293 Test compiled code in dist/npm on CI server 2015-08-06 14:59:48 -07:00
Chris Clark
89e5f79bbb Merge pull request #487 from clark800/orderbook-changes
Switch to direction/quantity/totalPrice for orderbookChanges
2015-08-06 14:53:18 -07:00
Chris Clark
82d7ce7ac2 Switch to direction/quantity/totalPrice for orderbookChanges 2015-08-06 12:27:03 -07:00
Geert Weening
0cc4c704f8 Merge pull request #482 from clark800/deprecate
Deprecate core
2015-08-06 11:35:12 -07:00
Chris Clark
dde762a1d6 Merge pull request #483 from clark800/fix-prepare-trustline
Fix prepareTrustline with no quality setting
2015-08-06 10:40:34 -07:00
Chris Clark
1c86e246c7 Merge pull request #484 from darkdarkdragon/develop-schema-fix
small adjustment.json schema fix
2015-08-05 16:31:27 -07:00
Ivan Tivonenko
2d173c8e69 small adjustment.json schema fix 2015-08-06 02:25:59 +03:00
Chris Clark
600fd34d30 Fix prepareTrustline with no quality setting 2015-08-05 15:42:48 -07:00
Geert Weening
4cb9cf801c Bump version to 0.13.0-rc3 2015-08-04 17:20:25 -07:00
Geert Weening
50fb8789b4 Update release notes 2015-08-04 17:06:57 -07:00
Chris Clark
fb8dc44ec1 Deprecate core 2015-08-04 16:57:39 -07:00
Geert Weening
0781caa8bc Merge pull request #481 from clark800/pathfind-fix
Add test case for createPathFind and convert snake case function calls to camel case
2015-08-04 16:57:18 -07:00
Chris Clark
2cdb23f0dd Fix lint errors in pathfind.js 2015-08-04 15:51:52 -07:00
Chris Clark
8e536c00b9 Add test case for createPathFind and convert snake case function calls to camel case 2015-08-04 15:51:18 -07:00
Geert Weening
8ff154cc2d Merge pull request #480 from clark800/promise-docs
Update RippleAPI documentation for promises
2015-08-04 15:29:08 -07:00
Chris Clark
daaae6e01e Update RippleAPI documentation for promises 2015-08-04 14:53:46 -07:00
Chris Clark
a64a4e697a Merge pull request #478 from clark800/promises
Convert API to promises
2015-08-04 11:32:52 -07:00
wltsmrz
3f51d8cc12 Merge pull request #479 from wltsmrz/fix-validated-ledgers-single-ledger
Fix RangeSet for validated_ledger as single ledger
2015-08-05 00:48:48 +07:00
wltsmrz
9f9e76f8b9 Fix RangeSet for validated_ledger as single ledger 2015-08-04 10:45:29 -07:00
sublimator
5b51db158d Merge pull request #476 from clark800/badge
Replace Travis badge with CircleCI badge
2015-08-04 07:44:59 +07:00
Chris Clark
a4d1509448 Replace Travis badge with CircleCI badge 2015-08-03 17:39:01 -07:00
Chris Clark
bbd51a03b6 Convert API to promises 2015-08-03 17:22:17 -07:00
sublimator
b55b82b2fd Merge pull request #474 from shekenahglory/develop
add 'DeliveredAmount' as optional metadata field
2015-08-01 06:30:36 +07:00
Matthew Fettig
fdb0f101bd add 'DeliveredAmount' as optional metadata field 2015-07-31 16:21:18 -07:00
Chris Clark
0afca5633d Merge pull request #473 from clark800/remove-slippage
Remove slippage parameter
2015-07-31 11:06:32 -07:00
Chris Clark
7c0d9a7172 Remove slippage parameter 2015-07-31 10:43:39 -07:00
sublimator
f6b7e27c67 Merge pull request #472 from clark800/offline
Add unit test for offline prepare and sign
2015-07-31 08:47:29 +07:00
Chris Clark
b8624bc55f Add unit test for offline prepare and sign 2015-07-30 18:19:52 -07:00
sublimator
2eec30756d Merge pull request #471 from clark800/no-xrp-paths
Don't set paths for XRP to XRP payment
2015-07-31 06:46:12 +07:00
sublimator
6b44ce8973 Merge pull request #458 from clark800/fix-pathfind
Fix counterparty logic in pathfind parsing
2015-07-31 06:26:58 +07:00
Chris Clark
ed0b501716 Don't set paths for XRP to XRP payment 2015-07-30 13:43:44 -07:00
Geert Weening
0fd391af72 bump version to 0.13.0.rc2 2015-07-30 12:18:48 -07:00
Chris Clark
fe9c1ada88 Fix counterparty logic in pathfind parsing 2015-07-30 11:55:52 -07:00
Alan Cohen
4c1f4ef58c Merge pull request #470 from clark800/remove-asyncify
Remove simple-asyncify dependency
2015-07-30 11:47:03 -07:00
Chris Clark
10afc770ff Remove simple-asyncify dependency 2015-07-30 11:38:46 -07:00
Alan Cohen
8543e60f86 Merge pull request #469 from lumberj/update-flow
Update Flow to 0.14
2015-07-30 11:09:57 -07:00
Alan Cohen
116d7e0f29 Update Flow to 0.14
Fixes issue with fs.readFileSync return type
See: https://github.com/facebook/flow/issues/416
https://github.com/facebook/flow/compare/v0.13.1...v0.14.0
2015-07-30 10:06:53 -07:00
Chris Clark
68adaec55b Merge pull request #467 from darkdarkdragon/develop-RLJS-440
change snake_case to camelCase in responses from api.submit and api.g…
2015-07-29 17:31:36 -07:00
Ivan Tivonenko
03640efef5 change snake_case to camelCase in responses from api.submit and api.getServerInfo and add schema for it 2015-07-30 03:10:10 +03:00
Alan Cohen
c6f450842e Merge pull request #466 from lumberj/continue-flowing
Typecheck remaining files in src/api
2015-07-29 16:03:15 -07:00
Alan Cohen
e583eb4592 Typecheck remaining files in src/api 2015-07-29 15:59:07 -07:00
Chris Clark
7fffbe0c64 Merge pull request #465 from darkdarkdragon/develop-RLJS-370-12
more unit tests coverage
2015-07-29 11:22:06 -07:00
Ivan Tivonenko
63e3b71eb5 cover api/common/errors.js with tests 2015-07-29 21:15:28 +03:00
Ivan Tivonenko
823ef738fe cover api/common/utils.js with tests 2015-07-29 17:40:59 +03:00
Ivan Tivonenko
0977ef0ec2 cover api/common/validate.js with tests 2015-07-29 17:15:34 +03:00
Ivan Tivonenko
cecf3f3d22 cover api/ledger/parse/utils.js with tests 2015-07-29 16:42:23 +03:00
Ivan Tivonenko
472fbce23a cover api/ledger/parse/trustline.js with tests 2015-07-29 15:46:15 +03:00
sublimator
e44aea1767 Merge pull request #464 from wltsmrz/add-delivermin
Add DeliverMin setter
2015-07-29 14:52:56 +07:00
wltsmrz
d682d90d86 Add DeliverMin setter 2015-07-29 00:25:27 -07:00
Chris Clark
141aa17dfc Merge pull request #463 from darkdarkdragon/develop-RLJS-370-11
cover api/common/schema-validator.js with tests
2015-07-28 17:40:48 -07:00
Ivan Tivonenko
0b09e53479 cover api/common/schema-validator.js with tests 2015-07-29 03:22:17 +03:00
Chris Clark
528d8bf25d Merge pull request #457 from darkdarkdragon/develop-sign-with-regular-key
allow to sign transaction in api.sign using regular key
2015-07-28 15:53:37 -07:00
Ivan Tivonenko
03a2109e24 allow to sign transaction in api.sign using regular key
make Seed.parse_json try different input types instead
of stopping on first failing
2015-07-29 01:49:25 +03:00
Chris Clark
b38b9bced6 Merge pull request #462 from darkdarkdragon/develop-RLJS-370-10
cover api/ledger/parse/settings.js with tests
2015-07-28 14:05:04 -07:00
Ivan Tivonenko
ea063d0c95 cover api/ledger/parse/settings.js with tests 2015-07-28 22:21:25 +03:00
Chris Clark
7f93929014 Merge pull request #461 from lumberj/update-parser
Update ripple-lib-transactionparser to 0.4
2015-07-28 11:23:06 -07:00
Alan Cohen
4cd10ecb87 Update ripple-lib-transactionparser to 0.4 2015-07-28 09:55:01 -07:00
sublimator
6ef30debd2 Merge pull request #459 from wltsmrz/fix-transaction-constructor
Fix transaction construction for SetRegularKey transactions
2015-07-28 14:50:58 +07:00
wltsmrz
4766bace4e Fix transaction construction for SetRegularKey transactions 2015-07-28 00:47:30 -07:00
sublimator
261500a3a4 Merge pull request #460 from wltsmrz/fix-transaction-sequencing
Fix transaction sequencing
2015-07-28 14:37:32 +07:00
wltsmrz
fae22b7023 Fix transaction sequencing 2015-07-27 23:17:05 -07:00
Chris Clark
4568b39997 Merge pull request #450 from clark800/api-names
Rename API parameters
2015-07-27 17:06:14 -07:00
Chris Clark
4a218cacfa Merge pull request #449 from clark800/numbers
Express trustline quality and account transferRate as floats
2015-07-27 17:02:35 -07:00
Chris Clark
34a4dd3077 Express transferRate as a float 2015-07-27 16:59:58 -07:00
Chris Clark
a383bd7e52 Express trustline quality as a float 2015-07-27 16:56:46 -07:00
Chris Clark
e76e693bdb Merge pull request #452 from darkdarkdragon/develop-RLJS-370-9-1
Increase tests coverage even more
2015-07-27 16:35:59 -07:00
Ivan Tivonenko
2c52e4aa69 more unit tests coverage 2015-07-28 02:24:27 +03:00
Ivan Tivonenko
13dee36e93 propagate message from remote error to RippledNetworkError 2015-07-28 02:17:40 +03:00
Ivan Tivonenko
6e180439d1 cover api/ledger/transaction.js with unit tests 2015-07-28 02:17:38 +03:00
Ivan Tivonenko
e8d0c1ae95 make api.getTransaction return NotFound error in case of transaction not found
instead of core.RippleError
2015-07-28 02:16:30 +03:00
Ivan Tivonenko
068bda0c95 cover api/ledger/transactions.js with unit tests 2015-07-28 02:16:28 +03:00
Ivan Tivonenko
ab694381d5 fix some api functions to work with parsed version of transaction 2015-07-28 02:13:54 +03:00
Chris Clark
dc2a6c75cf Merge pull request #456 from clark800/docs
Update api.html doc
2015-07-27 14:57:13 -07:00
Chris Clark
98dbba8f27 Add api.html doc 2015-07-27 14:54:15 -07:00
Chris Clark
9a1b80d77a Merge pull request #451 from clark800/sample
Add sample API usage for getting balances and making a payment
2015-07-27 14:46:59 -07:00
Chris Clark
a655be30d6 Merge pull request #455 from clark800/doc
Add api.html
2015-07-27 14:46:50 -07:00
Chris Clark
e5aabc3072 Add api.html 2015-07-27 14:42:29 -07:00
Chris Clark
2cd32d58ad Merge pull request #454 from clark800/response-schemas
Add response schemas and small fixes
2015-07-27 14:22:55 -07:00
Chris Clark
0c02b92717 Add response schemas and small fixes 2015-07-27 14:20:09 -07:00
Geert Weening
c58a077a2f Merge branch 'release' into develop 2015-07-24 15:39:50 -07:00
Geert Weening
6e7dc9d7d3 Merge branch 'master' into release
Conflicts:
	npm-shrinkwrap.json
	package.json
2015-07-24 15:39:00 -07:00
Geert Weening
572c945274 Bump version to 0.12.6 2015-07-24 15:32:07 -07:00
Geert Weening
c605efab61 Update release notes 2015-07-24 15:31:59 -07:00
wltsmrz
2695f4302a Merge pull request #436 from wltsmrz/fix-orderbook-notification
Fix orderbook notification while disconnected
2015-07-25 06:25:31 +08:00
Chris Clark
a17011243e Fix webpack require failure due to "./" notation 2015-07-24 15:24:40 -07:00
Geert Weening
9a533ab807 Merge branch 'develop' into release 2015-07-24 15:22:35 -07:00
wltsmrz
a037952493 Fix orderbook notification while disconnected 2015-07-24 15:22:21 -07:00
Geert Weening
dc96795a02 Merge pull request #453 from clark800/webpack-fix
Fix webpack require failure due to "./" notation
2015-07-24 15:03:44 -07:00
Chris Clark
8d9746d7b1 Fix webpack require failure due to "./" notation 2015-07-24 14:59:25 -07:00
Chris Clark
00342c4239 Merge pull request #446 from darkdarkdragon/develop-RLJS-370-8
Increase tests coverage
2015-07-23 16:47:42 -07:00
Chris Clark
e48df2c1fd Add sample API usage for getting balances and making a payment 2015-07-23 15:51:15 -07:00
Ivan Tivonenko
6ade0f6554 cover api/ledger/pathfind.js with tests 2015-07-24 01:34:54 +03:00
Ivan Tivonenko
a88157bb92 change pathfind scheme so destination can be specified without counterparty 2015-07-24 01:34:51 +03:00
Ivan Tivonenko
00f318284f cover api/transaction/utils.js with tests 2015-07-24 01:34:49 +03:00
Chris Clark
2e12dc6d53 Merge pull request #445 from darkdarkdragon/develop-RLJS-370-7
fix settings.json schema to allow empty stings to
2015-07-23 15:27:50 -07:00
Chris Clark
34435d4d05 Rename API parameters 2015-07-23 14:24:11 -07:00
Ivan Tivonenko
a99452b773 fix settings.json schema to allow null to
'walletSize', 'transferRate', 'emailHash' and
'walletLocator' fields so they
can be cleared

cover api/transaction/settings.js with tests
2015-07-23 23:29:00 +03:00
Geert Weening
a05cb39ab0 Merge pull request #447 from geertweening/develop
Remove `src/js`
2015-07-23 11:12:21 -07:00
Geert Weening
0c69f7f10e Remove src/js 2015-07-23 11:06:12 -07:00
229 changed files with 9130 additions and 3736 deletions

View File

@@ -26,6 +26,9 @@ function webpackConfig(extension, overrides) {
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader?optional=runtime'
}, {
test: /\.json/,
loader: 'json-loader'
}]
}
};

View File

@@ -1,3 +1,18 @@
##0.13.0 (release candidate)
+ [Fix: Emit error events and return error on pathfind](https://github.com/ripple/ripple-lib/commit/1ccbaf677631a1944eb05d90f7afc5f3690a03dd)
+ [Deprecate core and remove snake case method copying](https://github.com/ripple/ripple-lib/commit/fb8dc44ec1d49bb05cd0cdbe6dd4ab211195868a)
+ Add new RippleAPI interface
- [RippleAPI README and samples](https://github.com/ripple/ripple-lib/tree/develop/docs/samples)
- [Method documentation](https://rawgit.com/ripple/ripple-lib/develop/docs/api.html)
+ [Fix RangeSet for validated_ledger as single ledger](https://github.com/ripple/ripple-lib/commit/9f9e76f8b933201651af59307135f67cfa7d60e8)
+ [Fix bug where the paths would be set with an empty array](https://github.com/ripple/ripple-lib/commit/83874ec0962da311b76f2385623e51c68bc39035)
+ [Fix reserve calculation](https://github.com/ripple/ripple-lib/commit/52879febb92d876f01f2e4d70871baa07af631fb)
##0.12.6
+ [Fix webpack require failure due to "./" notation](https://github.com/ripple/ripple-lib/commit/8d9746d7b10be203ee613df523c2522012ff1baf)
##0.12.15
+ [Add offer autobridging](https://github.com/ripple/ripple-lib/commit/c7bbce83719c1e8c6a4fae5ca850e7515db1a4a5)

View File

@@ -2,7 +2,7 @@
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)
[![Circle CI](https://circleci.com/gh/ripple/ripple-lib/tree/develop.svg?style=svg)](https://circleci.com/gh/ripple/ripple-lib/tree/develop) [![Coverage Status](https://coveralls.io/repos/ripple/ripple-lib/badge.png?branch=develop)](https://coveralls.io/r/ripple/ripple-lib?branch=develop)
[![NPM](https://nodei.co/npm/ripple-lib.png)](https://www.npmjs.org/package/ripple-lib)

View File

@@ -5,19 +5,32 @@ TOTAL_NODES="$2"
typecheck() {
npm install -g flow-bin
flow --version
npm run typecheck
}
lint() {
echo "eslint $(node_modules/.bin/eslint --version)"
npm list babel-eslint | grep babel-eslint
REPO_URL="https://raw.githubusercontent.com/ripple/javascript-style-guide"
curl "$REPO_URL/es6/eslintrc" > ./eslintrc
echo "plugins: [flowtype]" >> ./eslintrc
node_modules/.bin/eslint --reset -c ./eslintrc $(git --no-pager diff --name-only -M100% --diff-filter=AM --relative $(git merge-base FETCH_HEAD origin/HEAD) FETCH_HEAD | grep "\.js$")
echo "parser: babel-eslint" >> ./eslintrc
node_modules/.bin/eslint -c ./eslintrc $(git --no-pager diff --name-only -M100% --diff-filter=AM --relative $(git merge-base FETCH_HEAD origin/HEAD) FETCH_HEAD | grep "\.js$")
}
unittest() {
# test "src"
npm test --coverage
npm run coveralls
# test compiled version in "dist/npm"
babel -D --optional runtime --ignore "**/node_modules/**" -d test-compiled/ test/
echo "--reporter spec --timeout 5000 --slow 500" > test-compiled/mocha.opts
mkdir -p test-compiled/node_modules
ln -nfs ../../dist/npm/core test-compiled/node_modules/ripple-lib
ln -nfs ../../dist/npm test-compiled/node_modules/ripple-api
mocha --opts test-compiled/mocha.opts test-compiled
rm -rf test-compiled
}
oneNode() {

358
docs/api.html Normal file
View File

@@ -0,0 +1,358 @@
<html>
<head>
<style>
a {
text-decoration: none;
}
.method {
margin-bottom: 10px;
}
.details {
font-family: "Courier New", monospace;
white-space: pre;
display: none;
}
</style>
<script type="text/javascript">
function toggle(element) {
var results = element.parentElement.getElementsByClassName('details');
if (results.length > 0) {
var style = results[0].style;
style.display = (style.display === 'block') ? 'none' : 'block';
}
}
</script>
</head>
<body>
<h2><a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/index.js">RippleAPI</a></h2>
<div class="method">
connect()
</div>
<div class="method">
disconnect()
</div>
<div class="method">
isConnected()
</div>
<div class="method">
getServerInfo()
</div>
<div class="method">
getFee()
</div>
<div class="method">
getLedgerVersion()
</div>
<div class="method">
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/get-transaction.json">getTransaction</a>(
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/hash256.json">identifier</a>[,
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/transaction-options.json">options</a>]
)
<a href="#" onclick="javascript:toggle(this)">+</a>
<div class="details">
identifier: txhash
options: {minLedgerVersion: int, maxLedgerVersion: int}
</div>
</div>
<div class="method">
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/get-transactions.json">getTransactions</a>(
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/address.json">account</a>[,
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/transactions-options.json">options</a>]
)
<a href="#" onclick="javascript:toggle(this)">+</a>
<div class="details">
options: {
start: txhash,
limit: int,
minLedgerVersion: int,
maxLedgerVersion: int,
earliestFirst: bool,
excludeFailures: bool,
initiated: bool,
counterparty: address,
types: [string],
binary: bool
}
</div>
</div>
<div class="method">
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/get-trustlines.json">getTrustlines</a>(
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/address.json">account</a>[,
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/trustlines-options.json">options</a>]
)
<a href="#" onclick="javascript:toggle(this)">+</a>
<div class="details">
options: {counterparty: address, currency: string, limit: int, ledgerVersion: int}
</div>
</div>
<div class="method">
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/get-balances.json">getBalances</a>(
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/address.json">account</a>[,
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/trustlines-options.json">options</a>]
)
<a href="#" onclick="javascript:toggle(this)">+</a>
<div class="details">
options: {counterparty: address, currency: string, limit: int, ledgerVersion: int}
</div>
</div>
<div class="method">
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/get-paths.json">getPaths</a>(
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/pathfind.json">pathfind</a>
)
<a href="#" onclick="javascript:toggle(this)">+</a>
<div class="details">
pathfind: {
source: {
address: address,
currencies: [{
currency: string,
counterparty: address
}]
},
destination: adjustment
}
adjustment = {address: address, amount: amount, tag?: int}
amount = {currency: string, counterparty: address, value: floatstr}
</div>
</div>
<div class="method">
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/get-orders.json">getOrders</a>(
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/address.json">account</a>[,
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/orders-options.json">options</a>]
)
<a href="#" onclick="javascript:toggle(this)">+</a>
<div class="details">
options: {limit: int, ledverVersion: int}
</div>
</div>
<div class="method">
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/get-orderbook.json">getOrderbook</a>(
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/address.json">account</a>,
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/orderbook.json">orderbook</a>[,
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/orders-options.json">options</a>]
)
<a href="#" onclick="javascript:toggle(this)">+</a>
<div class="details">
orderbook: {
base: {
currency,
counterparty
},
counter: {
currency,
counterparty
}
}
options: {limit: int, ledverVersion: int}
</div>
</div>
<div class="method">
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/get-settings.json">getSettings</a>(
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/address.json">account</a>[,
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/settings-options.json">options</a>]
)
<a href="#" onclick="javascript:toggle(this)">+</a>
<div class="details">
options: {ledgerVersion: int}
</div>
</div>
<div class="method">
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/get-account-info.json">getAccountInfo</a>(
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/address.json">account</a>[,
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/settings-options.json">options</a>]
)
<a href="#" onclick="javascript:toggle(this)">+</a>
<div class="details">
options: {ledgerVersion: int}
</div>
</div>
<div class="method">
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/tx.json">preparePayment</a>(
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/address.json">account</a>,
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/payment.json">payment</a>[,
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/instructions.json">instructions</a>]
)
<a href="#" onclick="javascript:toggle(this)">+</a>
<div class="details">
payment: {
source: adjustment,
destination: adjustment,
paths?: string,
slippage?: strfloat,
memos?: [{
type: string,
format: string,
data: string
}],
invoiceID?: hash256,
allowPartialPayment?: bool,
noDirectRipple?: bool,
limitQuality?: bool
}
adjustment = {address: address, amount: amount, tag?: int}
amount = {currency: string, counterparty: address, value: floatstr}
instructions: {
sequence: int,
fee: floatstr,
maxFee: floatstr,
maxLedgerVersion: int,
maxLedgerVersionOffset: int
}
</div>
</div>
<div class="method">
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/tx.json">prepareTrustline</a>(
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/address.json">account</a>,
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/trustline.json">trustline</a>[,
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/instructions.json">instructions</a>]
)
<a href="#" onclick="javascript:toggle(this)">+</a>
<div class="details">
trustline: {
currency: string,
counterparty: address,
limit: strfloat,
qualityIn?: float,
qualityOut?: float,
allowRippling?: bool,
authorized?: bool,
frozen?: bool
}
instructions: {
sequence: int,
fee: floatstr,
maxFee: floatstr,
maxLedgerVersion: int,
maxLedgerVersionOffset: int
}
</div>
</div>
<div class="method">
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/tx.json">prepareOrder</a>(
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/address.json">account</a>,
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/order.json">order</a>[,
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/instructions.json">instructions</a>]
)
<a href="#" onclick="javascript:toggle(this)">+</a>
<div class="details">
order: {
direction: ("buy"|"sell"),
quantity: amount,
totalPrice: amount,
immediateOrCancel?: bool,
fillOrKill?: bool,
passive?: bool
}
amount = {currency: string, counterparty: address, value: floatstr}
instructions: {
sequence: int,
fee: floatstr,
maxFee: floatstr,
maxLedgerVersion: int,
maxLedgerVersionOffset: int
}
</div>
</div>
<div class="method">
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/tx.json">prepareOrderCancellation</a>(
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/address.json">account</a>,
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/sequence.json">sequence</a>[,
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/instructions.json">instructions</a>]
)
<a href="#" onclick="javascript:toggle(this)">+</a>
<div class="details">
sequence: int
instructions: {
sequence: int,
fee: floatstr,
maxFee: floatstr,
maxLedgerVersion: int,
maxLedgerVersionOffset: int
}
</div>
</div>
<div class="method">
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/tx.json">prepareSettings</a>(
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/address.json">account</a>,
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/settings.json">settings</a>[,
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/instructions.json">instructions</a>]
)
<a href="#" onclick="javascript:toggle(this)">+</a>
<div class="details">
settings: {
passwordSpent: bool,
requireDestinationTag: bool,
requireAuthorization: bool,
disallowIncomingXRP: bool,
disableMasterKey: bool,
enableTransactionIDTracking: bool,
noFreeze: bool,
globalFreeze: bool,
defaultRipple: bool,
emailHash: hash128,
walletLocator: hash256,
walletSize: int,
messageKey: string,
domain: string,
transferRate: float,
signers: string,
regularKey: address
}
instructions: {
sequence: int,
fee: floatstr,
maxFee: floatstr,
maxLedgerVersion: int,
maxLedgerVersionOffset: int
}
</div>
</div>
<div class="method">
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/sign.json">sign</a>(
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/tx.json">txJSON</a>,
secret)
</div>
<div class="method">
submit(
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/schemas/blob.json">txBlob</a>
)
</div>
<div class="method">
generateWallet()
</div>
<a href="https://github.com/ripple/ripple-lib/blob/develop/src/api/common/errors.js">errors</a>
</body>
</html>

3
docs/samples/README Normal file
View File

@@ -0,0 +1,3 @@
Usage:
babel-node balances.js
babel-node payment.js (requires setting address and secret in source file first)

12
docs/samples/balances.js Normal file
View File

@@ -0,0 +1,12 @@
'use strict';
const RippleAPI = require('../../src').RippleAPI; // require('ripple-lib')
const api = new RippleAPI({servers: ['wss://s1.ripple.com:443']});
const address = 'r3kmLJN5D28dHuH8vZNUZpMC43pEHpaocV';
api.connect().then(() => {
api.getBalances(address).then(balances => {
console.log(JSON.stringify(balances, null, 2));
process.exit();
});
});

41
docs/samples/payment.js Normal file
View File

@@ -0,0 +1,41 @@
'use strict';
const RippleAPI = require('../../src').RippleAPI; // require('ripple-lib')
const address = 'INSERT ADDRESS HERE';
const secret = 'INSERT SECRET HERE';
const api = new RippleAPI({servers: ['wss://s1.ripple.com:443']});
const instructions = {maxLedgerVersionOffset: 5};
const payment = {
source: {
address: address,
amount: {
value: '0.01',
currency: 'XRP'
}
},
destination: {
address: 'rKmBGxocj9Abgy25J51Mk1iqFzW9aVF9Tc',
amount: {
value: '0.01',
currency: 'XRP'
}
}
};
api.connect().then(() => {
console.log('Connected...');
api.preparePayment(address, payment, instructions).then(txJSON => {
console.log('Payment transaction prepared...');
const signedTransaction = api.sign(txJSON, secret).signedTransaction;
console.log('Payment transaction signed...');
api.submit(signedTransaction).then(response => {
console.log(response);
process.exit(0);
}).catch(error => {
console.log(error);
process.exit(1);
});
});
});

114
npm-shrinkwrap.json generated
View File

@@ -1,20 +1,20 @@
{
"name": "ripple-lib",
"version": "0.13.0-rc1",
"version": "0.13.0-rc10",
"npm-shrinkwrap-version": "5.4.0",
"node-version": "v0.12.6",
"node-version": "v0.12.7",
"dependencies": {
"async": {
"version": "0.9.2",
"resolved": "https://registry.npmjs.org/async/-/async-0.9.2.tgz"
},
"babel-runtime": {
"version": "5.8.3",
"resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-5.8.3.tgz",
"version": "5.8.24",
"resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-5.8.24.tgz",
"dependencies": {
"core-js": {
"version": "0.9.18",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-0.9.18.tgz"
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-1.1.4.tgz"
}
}
},
@@ -22,21 +22,45 @@
"version": "2.0.7",
"resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-2.0.7.tgz"
},
"bn.js": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/bn.js/-/bn.js-3.1.2.tgz"
},
"es6-promisify": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/es6-promisify/-/es6-promisify-2.0.0.tgz",
"dependencies": {
"es6-promise": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-2.3.0.tgz"
}
}
},
"extend": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/extend/-/extend-1.2.1.tgz"
},
"hash.js": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/hash.js/-/hash.js-1.0.3.tgz",
"dependencies": {
"inherits": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz"
}
}
},
"https-proxy-agent": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-1.0.0.tgz",
"dependencies": {
"agent-base": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/agent-base/-/agent-base-2.0.0.tgz",
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/agent-base/-/agent-base-2.0.1.tgz",
"dependencies": {
"semver": {
"version": "4.3.6",
"resolved": "https://registry.npmjs.org/semver/-/semver-4.3.6.tgz"
"version": "5.0.3",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.0.3.tgz"
}
}
},
@@ -57,8 +81,8 @@
}
},
"is-my-json-valid": {
"version": "2.12.0",
"resolved": "https://registry.npmjs.org/is-my-json-valid/-/is-my-json-valid-2.12.0.tgz",
"version": "2.12.2",
"resolved": "https://registry.npmjs.org/is-my-json-valid/-/is-my-json-valid-2.12.2.tgz",
"dependencies": {
"generate-function": {
"version": "2.0.0",
@@ -75,8 +99,8 @@
}
},
"jsonpointer": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/jsonpointer/-/jsonpointer-1.1.0.tgz"
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/jsonpointer/-/jsonpointer-2.0.0.tgz"
},
"xtend": {
"version": "4.0.0",
@@ -85,16 +109,52 @@
}
},
"lodash": {
"version": "3.10.0",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-3.10.0.tgz"
"version": "3.10.1",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-3.10.1.tgz"
},
"lru-cache": {
"version": "2.5.2",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.5.2.tgz"
},
"ripple-address-codec": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/ripple-address-codec/-/ripple-address-codec-1.6.0.tgz",
"dependencies": {
"x-address-codec": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/x-address-codec/-/x-address-codec-0.6.0.tgz",
"dependencies": {
"base-x": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/base-x/-/base-x-1.0.1.tgz"
}
}
}
}
},
"ripple-keypairs": {
"version": "0.8.0",
"resolved": "https://registry.npmjs.org/ripple-keypairs/-/ripple-keypairs-0.8.0.tgz",
"dependencies": {
"brorand": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/brorand/-/brorand-1.0.5.tgz"
},
"elliptic": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/elliptic/-/elliptic-5.1.0.tgz",
"dependencies": {
"inherits": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz"
}
}
}
}
},
"ripple-lib-transactionparser": {
"version": "0.3.2",
"resolved": "https://registry.npmjs.org/ripple-lib-transactionparser/-/ripple-lib-transactionparser-0.3.2.tgz",
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/ripple-lib-transactionparser/-/ripple-lib-transactionparser-0.5.0.tgz",
"dependencies": {
"bignumber.js": {
"version": "1.4.1",
@@ -102,23 +162,9 @@
}
}
},
"ripple-wallet-generator": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/ripple-wallet-generator/-/ripple-wallet-generator-1.0.3.tgz"
},
"simple-asyncify": {
"sjcl-codec": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/simple-asyncify/-/simple-asyncify-0.1.0.tgz"
},
"sjcl-extended": {
"version": "1.0.3",
"resolved": "git://github.com/ripple/sjcl-extended.git#d8cf8b22e7d97193c54e1f65113e3edcf200ca17",
"dependencies": {
"sjcl": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/sjcl/-/sjcl-1.0.3.tgz"
}
}
"resolved": "https://registry.npmjs.org/sjcl-codec/-/sjcl-codec-0.1.0.tgz"
},
"ws": {
"version": "0.7.2",

View File

@@ -1,6 +1,6 @@
{
"name": "ripple-lib",
"version": "0.13.0-rc1",
"version": "0.13.0-rc10",
"license": "ISC",
"description": "A JavaScript API for interacting with Ripple in Node.js and the browser",
"files": [
@@ -18,33 +18,37 @@
"async": "~0.9.0",
"babel-runtime": "^5.5.4",
"bignumber.js": "^2.0.3",
"bn.js": "^3.1.1",
"es6-promisify": "^2.0.0",
"extend": "~1.2.1",
"hash.js": "^1.0.3",
"https-proxy-agent": "^1.0.0",
"is-my-json-valid": "^2.12.0",
"is-my-json-valid": "^2.12.2",
"lodash": "^3.1.0",
"lru-cache": "~2.5.0",
"ripple-lib-transactionparser": "^0.3.2",
"ripple-wallet-generator": "^1.0.3",
"simple-asyncify": "^0.1.0",
"sjcl-extended": "ripple/sjcl-extended#1.0.3",
"ripple-address-codec": "^1.6.0",
"ripple-keypairs": "^0.8.0",
"ripple-lib-transactionparser": "^0.5.0",
"sjcl-codec": "0.1.0",
"ws": "~0.7.1"
},
"devDependencies": {
"assert-diff": "^1.0.1",
"babel": "^5.5.4",
"babel-core": "^5.5.4",
"babel-eslint": "^3.1.23",
"babel-loader": "^5.0.0",
"babel": "^5.8.21",
"babel-core": "^5.8.22",
"babel-eslint": "^4.0.5",
"babel-loader": "^5.3.2",
"coveralls": "~2.10.0",
"eslint": "^0.24.0",
"eslint": "^1.3.0",
"eslint-plugin-flowtype": "^1.0.0",
"eventemitter2": "^0.4.14",
"flow-bin": "^0.13.1",
"flow-bin": "^0.14",
"gulp": "~3.8.10",
"gulp-bump": "~0.1.13",
"gulp-rename": "~1.2.0",
"gulp-uglify": "~1.1.0",
"istanbul": "~0.3.5",
"json-loader": "^0.5.2",
"mocha": "~2.1.0",
"webpack": "~1.5.3",
"yargs": "~1.3.1"
@@ -53,12 +57,13 @@
"build": "gulp",
"clean": "rm -rf dist/npm && rm -rf build/flow",
"typecheck": "babel --optional runtime --blacklist flow -d build/flow/ src/ && flow check",
"compile": "babel --optional runtime -d dist/npm/ src/ && cp -r src/api/common/schemas/ dist/npm/api/common/schemas/",
"compile-with-source-maps": "babel --optional runtime -s -t -d dist/npm/ src/",
"compile": "babel -D --optional runtime -d dist/npm/ src/",
"watch": "babel -w -D --optional runtime -d dist/npm/ src/",
"compile-with-source-maps": "babel -D --optional runtime -s -t -d dist/npm/ src/",
"prepublish": "npm run clean && npm run compile",
"test": "istanbul test _mocha",
"coveralls": "cat ./coverage/lcov.info | coveralls",
"lint": "if ! [ -f eslintrc ]; then curl -o eslintrc 'https://raw.githubusercontent.com/ripple/javascript-style-guide/es6/eslintrc'; echo 'plugins:\n - flowtype' >> eslintrc; fi; eslint --reset -c eslintrc src/",
"lint": "if ! [ -f eslintrc ]; then curl -o eslintrc 'https://raw.githubusercontent.com/ripple/javascript-style-guide/es6/eslintrc'; echo 'parser: babel-eslint' >> eslintrc; fi; eslint -c eslintrc src/",
"perf": "./scripts/perf_test.sh"
},
"repository": {

View File

@@ -2,12 +2,13 @@
'use strict';
var fs = require('fs');
var Amount = require('../dist/npm').Amount;
var Ledger = require('../dist/npm').Ledger;
var ripple = require('../dist/npm')._DEPRECATED;
var Amount = ripple.Amount;
var Ledger = ripple.Ledger;
function parse_options(from, flags) {
var argv = from.slice(),
opts_ = {argv: argv};
var argv = from.slice();
var opts_ = {argv: argv};
flags.forEach(function(f) {
// Do we have the flag?

View File

@@ -33,7 +33,7 @@ const AccountFields = {
WalletSize: {name: 'walletSize', defaults: 0},
MessageKey: {name: 'messageKey'},
Domain: {name: 'domain', encoding: 'hex'},
TransferRate: {name: 'transferRate', defaults: 0},
TransferRate: {name: 'transferRate', defaults: 0, shift: 9},
Signers: {name: 'signers'}
};

View File

@@ -58,6 +58,13 @@ function MissingLedgerHistoryError(message) {
MissingLedgerHistoryError.prototype = new RippleError();
MissingLedgerHistoryError.prototype.name = 'MissingLedgerHistoryError';
function PendingLedgerVersionError(message) {
this.message = message ||
'maxLedgerVersion is greater than server\'s most recent validated ledger';
}
PendingLedgerVersionError.prototype = new RippleError();
PendingLedgerVersionError.prototype.name = 'PendingLedgerVersionError';
/**
* Request timed out
*/
@@ -77,13 +84,14 @@ ApiError.prototype = new RippleError();
ApiError.prototype.name = 'ApiError';
module.exports = {
ValidationError: ValidationError,
NetworkError: NetworkError,
TransactionError: TransactionError,
RippledNetworkError: RippledNetworkError,
NotFoundError: NotFoundError,
MissingLedgerHistoryError: MissingLedgerHistoryError,
TimeOutError: TimeOutError,
ApiError: ApiError,
RippleError: RippleError
ValidationError,
NetworkError,
TransactionError,
RippledNetworkError,
NotFoundError,
PendingLedgerVersionError,
MissingLedgerHistoryError,
TimeOutError,
ApiError,
RippleError
};

View File

@@ -9,7 +9,12 @@ module.exports = {
dropsToXrp: utils.dropsToXrp,
xrpToDrops: utils.xrpToDrops,
toRippledAmount: utils.toRippledAmount,
wrapCatch: utils.wrapCatch,
generateAddress: utils.generateAddress,
composeAsync: utils.composeAsync,
convertExceptions: utils.convertExceptions
wrapCatch: utils.wrapCatch,
convertErrors: utils.convertErrors,
convertExceptions: utils.convertExceptions,
convertKeysFromSnakeCaseToCamelCase:
utils.convertKeysFromSnakeCaseToCamelCase,
promisify: utils.promisify
};

View File

@@ -1,36 +1,92 @@
// flow is disabled for this file until support for requiring json is added:
// https://github.com/facebook/flow/issues/167
'use strict';
const _ = require('lodash');
const fs = require('fs');
const path = require('path');
const assert = require('assert');
const validator = require('is-my-json-valid');
const core = require('./utils').core;
const ValidationError = require('./errors').ValidationError;
let SCHEMAS = {};
function isValidAddress(address) {
return core.UInt160.is_valid(address);
function isValidAddress(address: string): boolean {
return typeof address === 'string' && address.length > 0 &&
address[0] === 'r' &&
core.UInt160.is_valid(address);
}
function isValidLedgerHash(ledgerHash) {
return core.UInt256.is_valid(ledgerHash);
}
function loadSchema(filepath) {
try {
return JSON.parse(fs.readFileSync(filepath, 'utf8'));
} catch (e) {
throw new Error('Failed to parse schema: ' + filepath);
}
}
function endsWith(str, suffix) {
return str.indexOf(suffix, str.length - suffix.length) !== -1;
}
function loadSchemas(dir) {
const filenames = fs.readdirSync(dir).filter(name => endsWith(name, '.json'));
const schemas = filenames.map(name => loadSchema(path.join(dir, name)));
function loadSchemas() {
// listed explicitly for webpack (instead of scanning schemas directory)
const schemas = [
require('./schemas/address.json'),
require('./schemas/adjustment.json'),
require('./schemas/amount.json'),
require('./schemas/amountbase.json'),
require('./schemas/balance.json'),
require('./schemas/blob.json'),
require('./schemas/currency.json'),
require('./schemas/get-account-info.json'),
require('./schemas/get-balances.json'),
require('./schemas/get-ledger.json'),
require('./schemas/get-orderbook.json'),
require('./schemas/get-orders.json'),
require('./schemas/get-paths.json'),
require('./schemas/get-server-info.json'),
require('./schemas/get-settings.json'),
require('./schemas/get-transaction.json'),
require('./schemas/get-transactions.json'),
require('./schemas/get-trustlines.json'),
require('./schemas/hash128.json'),
require('./schemas/hash256.json'),
require('./schemas/instructions.json'),
require('./schemas/issue.json'),
require('./schemas/ledger-options.json'),
require('./schemas/ledgerversion.json'),
require('./schemas/max-adjustment.json'),
require('./schemas/memo.json'),
require('./schemas/order-cancellation-transaction.json'),
require('./schemas/order-cancellation.json'),
require('./schemas/order-change.json'),
require('./schemas/order-transaction.json'),
require('./schemas/order.json'),
require('./schemas/orderbook-orders.json'),
require('./schemas/orderbook.json'),
require('./schemas/orders-options.json'),
require('./schemas/outcome.json'),
require('./schemas/pathfind.json'),
require('./schemas/payment-transaction.json'),
require('./schemas/payment.json'),
require('./schemas/quality.json'),
require('./schemas/remote-options.json'),
require('./schemas/sequence.json'),
require('./schemas/settings-options.json'),
require('./schemas/settings-transaction.json'),
require('./schemas/settings.json'),
require('./schemas/sign.json'),
require('./schemas/signed-value.json'),
require('./schemas/submit.json'),
require('./schemas/suspended-payment-cancellation.json'),
require('./schemas/suspended-payment-execution.json'),
require('./schemas/suspended-payment-creation.json'),
require('./schemas/timestamp.json'),
require('./schemas/transaction-options.json'),
require('./schemas/transactions-options.json'),
require('./schemas/trustline-transaction.json'),
require('./schemas/trustline.json'),
require('./schemas/trustlines-options.json'),
require('./schemas/tx.json'),
require('./schemas/uint32.json'),
require('./schemas/value.json'),
require('./schemas/prepare.json'),
require('./schemas/ledger-closed.json')
];
const titles = _.map(schemas, schema => schema.title);
const duplicates = _.keys(_.pick(_.countBy(titles), count => count > 1));
assert(duplicates.length === 0, 'Duplicate schemas for: ' + duplicates);
return _.indexBy(schemas, 'title');
}
@@ -43,7 +99,7 @@ function formatSchemaErrors(errors) {
return errors.map(formatSchemaError).join(', ');
}
function schemaValidate(schemaName, object) {
function schemaValidate(schemaName: string, object: any): void {
const formats = {address: isValidAddress,
ledgerHash: isValidLedgerHash};
const options = {schemas: SCHEMAS, formats: formats,
@@ -59,5 +115,8 @@ function schemaValidate(schemaName, object) {
}
}
SCHEMAS = loadSchemas(path.join(__dirname, './schemas'));
module.exports = schemaValidate;
SCHEMAS = loadSchemas();
module.exports = {
schemaValidate: schemaValidate,
SCHEMAS: SCHEMAS
};

View File

@@ -4,7 +4,16 @@
"type": "object",
"properties": {
"address": {"$ref": "address"},
"amount": {"$ref": "amount"},
"amount": {
"type": "object",
"properties": {
"currency": {"$ref": "currency"},
"counterparty": {"$ref": "address"},
"value": {"$ref": "value"}
},
"required": ["currency", "value"],
"additionalProperties": false
},
"tag": {
"description": "A string representing an unsigned 32-bit integer most commonly used to refer to a sender's hosted account at a Ripple gateway",
"$ref": "uint32"

View File

@@ -0,0 +1,44 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "balance",
"description": "Balance amount",
"type": "object",
"properties": {
"value": {
"description": "The balance on the trustline",
"$ref": "signedValue"
},
"currency": {
"description": "The three-character code or hex string used to denote currencies",
"$ref": "currency"
},
"counterparty": {
"description": "The Ripple account address of the currency's issuer or gateway",
"$ref": "address"
}
},
"additionalProperties": false,
"required": ["currency", "value"],
"oneOf": [
{
"properties": {
"currency": {
"not": {
"enum": ["XRP"]
}
}
},
"required": ["counterparty"]
},
{
"properties": {
"currency": {
"enum": ["XRP"]
}
},
"not": {
"required": ["counterparty"]
}
}
]
}

View File

@@ -0,0 +1,21 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "getAccountInfo",
"type": "object",
"properties": {
"sequence": {"$ref": "sequence"},
"xrpBalance": {"$ref": "value"},
"ownerCount": {"type": "integer", "minimum": 0},
"previousInitiatedTransactionID": {"$ref": "hash256"},
"previousAffectingTransactionID": {"$ref": "hash256"},
"previousAffectingTransactionLedgerVersion": {"$ref": "ledgerVersion"}
},
"required": [
"sequence",
"xrpBalance",
"ownerCount",
"previousAffectingTransactionID",
"previousAffectingTransactionLedgerVersion"
],
"additionalProperties": false
}

View File

@@ -0,0 +1,6 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "getBalances",
"type": "array",
"items": {"$ref": "balance"}
}

View File

@@ -0,0 +1,39 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "getLedger",
"type": "object",
"properties": {
"accepted": {"type": "boolean"},
"closed": {"type": "boolean"},
"stateHash": {"$ref": "hash256"},
"closeTime": {"type": "integer", "minimum": 0},
"closeTimeResolution": {"type": "integer", "minimum": 1},
"closeFlags": {"type": "integer", "minimum": 0},
"ledgerHash": {"$ref": "hash256"},
"ledgerVersion": {"$ref": "ledgerVersion"},
"parentLedgerHash": {"$ref": "hash256"},
"parentCloseTime": {"type": "integer", "minimum": 0},
"totalDrops": {"$ref": "value"},
"transactionHash": {"$ref": "hash256"},
"transactions": {"type": "array", "items": {"type": "object"}},
"rawTransactions": {"type": "string"},
"transactionHashes": {"type": "array", "items": {"$ref": "hash256"}},
"rawState": {"type": "string"},
"stateHashes": {"type": "array", "items": {"$ref": "hash256"}}
},
"required": [
"accepted",
"closed",
"stateHash",
"closeTime",
"closeTimeResolution",
"closeFlags",
"ledgerHash",
"ledgerVersion",
"parentLedgerHash",
"parentCloseTime",
"totalDrops",
"transactionHash"
],
"additionalProperties": false
}

View File

@@ -0,0 +1,11 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "getOrderbook",
"type": "object",
"properties": {
"bids": {"$ref": "orderbookOrders"},
"asks": {"$ref": "orderbookOrders"}
},
"required": ["bids", "asks"],
"additionalProperties": false
}

View File

@@ -0,0 +1,23 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "getOrders",
"type": "array",
"items": {
"type": "object",
"properties": {
"specification": {"$ref": "order"},
"properties": {
"type": "object",
"properties": {
"maker": {"$ref": "address"},
"sequence": {"$ref": "sequence"},
"makerExchangeRate": {"$ref": "value"}
},
"required": ["maker", "sequence", "makerExchangeRate"],
"addtionalProperties": false
}
},
"required": ["specification", "properties"],
"additionalProperties": false
}
}

View File

@@ -0,0 +1,15 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "getPaths",
"type": "array",
"items": {
"type": "object",
"properties": {
"source": {"$ref": "maxAdjustment"},
"destination": {"$ref": "adjustment"},
"paths": {"type": "string"}
},
"required": ["source", "destination", "paths"],
"additionalProperties": false
}
}

View File

@@ -0,0 +1,49 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "getServerInfo",
"type": "object",
"properties": {
"buildVersion": {"type": "string"},
"completeLedgers": {"type": "string", "pattern": "[0-9,-]+"},
"hostid": {"type": "string"},
"ioLatencyMs": {"type": "number"},
"load": {
"type": "object",
"properties": {
"jobTypes": {
"type": "array",
"items": {"type": "object"}
},
"threads": {"type": "number"}
}
},
"lastClose": {
"type": "object",
"properties": {
"convergeTimeS": {"type": "number"},
"proposers": {"type": "integer", "minimum": 0}
}
},
"loadFactor": {"type": "number"},
"peers": {"type": "integer", "minimum": 0},
"pubkeyNode": {"type": "string"},
"pubkeyValidator": {"type": "string"},
"serverState": {
"type": "string",
"enum": ["disconnected", "connected", "syncing", "tracking", "full", "validating", "proposing"]
},
"validatedLedger": {
"type": "object",
"properties": {
"age": {"type": "integer", "minimum": 0},
"baseFeeXrp": {"type": "number"},
"hash": {"$ref": "hash256"},
"reserveBaseXrp": {"type": "integer", "minimum": 0},
"reserveIncXrp": {"type": "integer", "minimum": 0},
"seq": {"type": "integer", "minimum": 0}
}
},
"validationQuorum": {"type": "number"}
},
"additionalProperties": false
}

View File

@@ -0,0 +1,40 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "getSettings",
"type": "object",
"properties": {
"passwordSpent": {"type": "boolean"},
"requireDestinationTag": {"type": "boolean"},
"requireAuthorization": {"type": "boolean"},
"disallowIncomingXRP": {"type": "boolean"},
"disableMasterKey": {"type": "boolean"},
"enableTransactionIDTracking": {"type": "boolean"},
"noFreeze": {"type": "boolean"},
"globalFreeze": {"type": "boolean"},
"defaultRipple": {"type": "boolean"},
"emailHash": {
"oneOf": [
{"type": "null"},
{"$ref": "hash128"}
]
},
"walletLocator": {
"oneOf": [
{"type": "null"},
{"$ref": "hash256"}
]
},
"walletSize": {"type": ["integer", "null"]},
"messageKey": {"type": "string"},
"domain": {"type": "string"},
"transferRate": {
"oneOf": [
{"type": "null"},
{"type": "number", "minimum": 1, "maximum": 4.294967295}
]
},
"signers": {"type": "string"},
"regularKey": {"$ref": "address"}
},
"additionalProperties": false
}

View File

@@ -0,0 +1,11 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "getTransaction",
"oneOf": [
{"$ref": "paymentTransaction"},
{"$ref": "orderTransaction"},
{"$ref": "orderCancellationTransaction"},
{"$ref": "trustlineTransaction"},
{"$ref": "settingsTransaction"}
]
}

View File

@@ -0,0 +1,6 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "getTransactions",
"type": "array",
"items": {"$ref": "getTransaction"}
}

View File

@@ -0,0 +1,29 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "getTrustlines",
"type": "array",
"items": {
"properties": {
"specification": {"$ref": "trustline"},
"counterparty": {
"properties": {
"limit": {"$ref": "value"},
"ripplingDisabled": {"type": "boolean"},
"frozen": {"type": "boolean"},
"authorized": {"type": "boolean"}
},
"required": ["limit"],
"additionalProperties": false
},
"state": {
"properties": {
"balance": {"$ref": "value"}
},
"required": ["balance"],
"additionalProperties": false
}
},
"required": ["specification", "counterparty", "state"],
"additionalProperties": false
}
}

View File

@@ -0,0 +1,21 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "ledgerClosed",
"description": "A ledgerClosed event message",
"type": "object",
"properties": {
"feeBase": {"type": "integer", "minimum": 0},
"feeReference": {"type": "integer", "minimum": 0},
"ledgerHash": {"$ref": "ledgerHash"},
"ledgerVersion": {"$ref": "ledgerVersion"},
"ledgerTimestamp": {"type": "string", "format": "date-time"},
"reserveBase": {"type": "integer", "minimum": 0},
"reserveIncrement": {"type": "integer", "minimum": 0},
"transactionCount": {"type": "integer", "minimum": 0},
"validatedLedgerVersions": {"type": "string"}
},
"addtionalProperties": false,
"required": ["feeBase", "feeReference", "ledgerHash", "ledgerTimestamp",
"reserveBase", "reserveIncrement", "transactionCount",
"ledgerVersion", "validatedLedgerVersions"]
}

View File

@@ -0,0 +1,13 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "ledger-options",
"description": "Options for getLedger",
"type": "object",
"properties": {
"ledgerVersion": {"$ref": "ledgerVersion"},
"includeAllData": {"type": "boolean"},
"includeTransactions": {"type": "boolean"},
"includeState": {"type": "boolean"}
},
"additionalProperties": false
}

View File

@@ -0,0 +1,24 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "maxAdjustment",
"type": "object",
"properties": {
"address": {"$ref": "address"},
"maxAmount": {
"type": "object",
"properties": {
"currency": {"$ref": "currency"},
"counterparty": {"$ref": "address"},
"value": {"$ref": "value"}
},
"required": ["currency", "value"],
"additionalProperties": false
},
"tag": {
"description": "A string representing an unsigned 32-bit integer most commonly used to refer to a sender's hosted account at a Ripple gateway",
"$ref": "uint32"
}
},
"required": ["address", "maxAmount"],
"additionalProperties": false
}

View File

@@ -0,0 +1,15 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "orderCancellationTransaction",
"type": "object",
"properties": {
"type": {"enum": ["orderCancellation"]},
"specification": {"$ref": "orderCancellation"},
"outcome": {"$ref": "outcome"},
"id": {"$ref": "hash256"},
"address": {"$ref": "address"},
"sequence": {"$ref": "sequence"}
},
"required": ["type", "id", "address", "sequence", "specification", "outcome"],
"additionalProperties": false
}

View File

@@ -1,6 +1,6 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "cancellation",
"title": "orderCancellation",
"type": "object",
"properties": {
"orderSequence": {"$ref": "sequence"}

View File

@@ -0,0 +1,17 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "orderChange",
"type": "object",
"properties": {
"direction": {
"type": "string",
"enum": ["buy", "sell"]
},
"quantity": {"$ref": "balance"},
"totalPrice": {"$ref": "balance"},
"sequence": {"$ref": "sequence"},
"status": {"enum": ["created", "open", "closed", "canceled"]}
},
"required": ["direction", "quantity", "totalPrice", "sequence", "status"],
"additionalProperties": false
}

View File

@@ -0,0 +1,15 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "orderTransaction",
"type": "object",
"properties": {
"type": {"enum": ["order"]},
"specification": {"$ref": "order"},
"outcome": {"$ref": "outcome"},
"id": {"$ref": "hash256"},
"address": {"$ref": "address"},
"sequence": {"$ref": "sequence"}
},
"required": ["type", "id", "address", "sequence", "specification", "outcome"],
"additionalProperties": false
}

View File

@@ -0,0 +1,32 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "orderbookOrders",
"type": "array",
"items": {
"type": "object",
"properties": {
"specification": {"$ref": "order"},
"properties": {
"type": "object",
"properties": {
"maker": {"$ref": "address"},
"sequence": {"$ref": "sequence"},
"makerExchangeRate": {"$ref": "value"}
},
"required": ["maker", "sequence", "makerExchangeRate"],
"addtionalProperties": false
},
"state": {
"type": "object",
"properties": {
"fundedAmount": {"$ref": "amount"},
"priceOfFundedAmount": {"$ref": "amount"}
},
"required": ["fundedAmount", "priceOfFundedAmount"],
"additionalProperties": false
}
},
"required": ["specification", "properties"],
"additionalProperties": false
}
}

View File

@@ -0,0 +1,31 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "outcome",
"type": "object",
"properties": {
"result": {"type": "string"},
"timestamp": {"type": "string", "format": "date-time"},
"fee": {"$ref": "value"},
"balanceChanges": {
"type": "object",
"description": "Key is the ripple address; value is an array of changes",
"additionalProperties": {
"type": "array",
"items": {"$ref": "balance"}
}
},
"orderbookChanges": {
"type": "object",
"description": "Key is the maker's ripple address; value is an array of changes",
"additionalProperties": {
"type": "array",
"items": {"$ref": "orderChange"}
}
},
"ledgerVersion": {"$ref": "ledgerVersion"},
"indexInLedger": {"type": "integer", "minimum": 0}
},
"required": ["result", "fee", "balanceChanges",
"orderbookChanges", "ledgerVersion", "indexInLedger"],
"additionalProperties": false
}

View File

@@ -0,0 +1,15 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "paymentTransaction",
"type": "object",
"properties": {
"type": {"enum": ["payment"]},
"specification": {"$ref": "payment"},
"outcome": {"$ref": "outcome"},
"id": {"$ref": "hash256"},
"address": {"$ref": "address"},
"sequence": {"$ref": "sequence"}
},
"required": ["type", "id", "address", "sequence", "specification", "outcome"],
"additionalProperties": false
}

View File

@@ -3,13 +3,9 @@
"title": "payment",
"type": "object",
"properties": {
"source": {"$ref": "adjustment"},
"source": {"$ref": "maxAdjustment"},
"destination": {"$ref": "adjustment"},
"paths": {"type": "string"},
"slippage": {
"description": "An optional cushion for the source_amount to increase the likelihood that the payment will succeed. The source_account will never be charged more than source_amount.value + source_slippage",
"$ref": "value"
},
"memos": {
"type": "array",
"items": {

View File

@@ -0,0 +1,21 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "prepare",
"description": "Result of prepare function",
"type": "object",
"properties": {
"txJSON": {"type": "string"},
"instructions": {
"type": "object",
"properties": {
"fee": {"$ref": "value"},
"sequence": {"$ref": "sequence"},
"maxLedgerVersion": {"$ref": "ledgerVersion"}
},
"additionalProperties": false,
"required": ["fee", "sequence"]
}
},
"additionalProperties": false,
"required": ["txJSON", "instructions"]
}

View File

@@ -1,8 +1,8 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "quality",
"description": "Ratio for incoming/outgoing transit fees represented in billionths. (For example, a value of 500 million represents a 0.5:1 ratio.) As a special case, 0 is treated as a 1:1 ratio.",
"type": "integer",
"minimum": 0,
"maximum": 1000000000
"description": "Ratio for incoming/outgoing transit fees.",
"type": "number",
"minimum": 0.000000001,
"maximum": 4.294967295
}

View File

@@ -0,0 +1,17 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "remote-options",
"type": "object",
"properties": {
"trace": {"type": "boolean"},
"servers": {
"type": "array",
"items": {
"type": "string",
"format": "uri",
"pattern": "^wss?://"
}
}
},
"additionalProperties": false
}

View File

@@ -0,0 +1,15 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "settingsTransaction",
"type": "object",
"properties": {
"type": {"enum": ["settings"]},
"specification": {"$ref": "getSettings"},
"outcome": {"$ref": "outcome"},
"id": {"$ref": "hash256"},
"address": {"$ref": "address"},
"sequence": {"$ref": "sequence"}
},
"required": ["type", "id", "address", "sequence", "specification"],
"additionalProperties": false
}

View File

@@ -1,27 +1,13 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "settings",
"type": "object",
"properties": {
"passwordSpent": {"type": "boolean"},
"requireDestinationTag": {"type": "boolean"},
"requireAuthorization": {"type": "boolean"},
"disallowIncomingXRP": {"type": "boolean"},
"disableMasterKey": {"type": "boolean"},
"enableTransactionIDTracking": {"type": "boolean"},
"noFreeze": {"type": "boolean"},
"globalFreeze": {"type": "boolean"},
"defaultRipple": {"type": "boolean"},
"emailHash": {"$ref": "hash128"},
"walletLocator": {"$ref": "hash256"},
"walletSize": {"type": "integer"},
"messageKey": {"type": "string"},
"domain": {"type": "string"},
"transferRate": {"type": "integer"},
"signers": {"type": "string"},
"regularKey": {"$ref": "address"}
},
"minProperties": 1,
"maxProperties": 1,
"additionalProperties": false
"allOf": [
{
"$ref": "getSettings"
},
{
"minProperties": 1,
"maxProperties": 1
}
]
}

View File

@@ -0,0 +1,14 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "sign",
"type": "object",
"properties": {
"signedTransaction": {
"type": "string",
"pattern": "^[A-F0-9]+$"
},
"id": {"$ref": "hash256"}
},
"required": ["signedTransaction", "id"],
"additionalProperties": false
}

View File

@@ -0,0 +1,7 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "signedValue",
"description": "A string representation of a floating point number",
"type": "string",
"pattern": "^[-]?[0-9]*[.]?[0-9]+([eE][-+]?[0-9]+)?$"
}

View File

@@ -0,0 +1,15 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "submit",
"type": "object",
"properties": {
"success": {"type": "boolean"},
"engineResult": {"type": "string"},
"engineResultCode": {"type": "integer"},
"engineResultMessage": {"type": "string"},
"txBlob": {"type": "string"},
"txJson": {"type": "object"}
},
"required": ["success", "engineResult", "engineResultCode"],
"additionalProperties": false
}

View File

@@ -0,0 +1,17 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "suspended-payment-cancellation",
"type": "object",
"properties": {
"memos": {
"type": "array",
"items": {
"$ref": "memo"
}
},
"owner": {"$ref": "address"},
"paymentSequence": {"$ref": "uint32"}
},
"required": ["owner", "paymentSequence"],
"additionalProperties": false
}

View File

@@ -0,0 +1,28 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "suspended-payment-creation",
"type": "object",
"properties": {
"source": {"$ref": "maxAdjustment"},
"destination": {"$ref": "adjustment"},
"memos": {
"type": "array",
"items": {
"$ref": "memo"
}
},
"digest": {"$ref": "hash256"},
"allowCancelAfter": {
"type": "integer",
"minimum": 0,
"description": "milliseconds since unix epoch"
},
"allowExecuteAfter": {
"type": "integer",
"minimum": 0,
"description": "milliseconds since unix epoch"
}
},
"required": ["source", "destination"],
"additionalProperties": false
}

View File

@@ -0,0 +1,20 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "suspended-payment-execution",
"type": "object",
"properties": {
"memos": {
"type": "array",
"items": {
"$ref": "memo"
}
},
"owner": {"$ref": "address"},
"paymentSequence": {"$ref": "uint32"},
"method": {"type": "integer", "minimum": 0, "maximum": 255},
"digest": {"$ref": "hash256"},
"proof": {"type": "string"}
},
"required": ["owner", "paymentSequence"],
"additionalProperties": false
}

View File

@@ -0,0 +1,15 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "trustlineTransaction",
"type": "object",
"properties": {
"type": {"enum": ["trustline"]},
"specification": {"$ref": "trustline"},
"outcome": {"$ref": "outcome"},
"id": {"$ref": "hash256"},
"address": {"$ref": "address"},
"sequence": {"$ref": "sequence"}
},
"required": ["type", "id", "address", "sequence", "specification", "outcome"],
"additionalProperties": false
}

View File

@@ -8,7 +8,7 @@
"limit": {"$ref": "value"},
"qualityIn": {"$ref": "quality"},
"qualityOut": {"$ref": "quality"},
"allowRippling": {"type": "boolean"},
"ripplingDisabled": {"type": "boolean"},
"authorized": {"type": "boolean"},
"frozen": {"type": "boolean"}
},

View File

@@ -1,17 +1,23 @@
/* @flow */
'use strict';
const _ = require('lodash');
const BigNumber = require('bignumber.js');
const core = require('../../core');
const errors = require('./errors');
const es6promisify = require('es6-promisify');
const keypairs = require('ripple-keypairs');
function dropsToXrp(drops) {
type Amount = {currency: string, issuer: string, value: string}
function dropsToXrp(drops: string): string {
return (new BigNumber(drops)).dividedBy(1000000.0).toString();
}
function xrpToDrops(xrp) {
function xrpToDrops(xrp: string): string {
return (new BigNumber(xrp)).times(1000000.0).floor().toString();
}
function toRippledAmount(amount) {
function toRippledAmount(amount: Amount): string|Amount {
if (amount.currency === 'XRP') {
return xrpToDrops(amount.value);
}
@@ -22,7 +28,14 @@ function toRippledAmount(amount) {
};
}
function wrapCatch(asyncFunction: () => void): () => void {
function generateAddress(options?: Object): Object {
const {accountID, seed} = keypairs.generateWallet(options);
return {secret: seed, address: accountID};
}
type AsyncFunction = (...x: any) => void
function wrapCatch(asyncFunction: AsyncFunction): AsyncFunction {
return function() {
try {
asyncFunction.apply(this, arguments);
@@ -33,10 +46,13 @@ function wrapCatch(asyncFunction: () => void): () => void {
};
}
function composeAsync(wrapper, callback) {
type Callback = (err: any, data: any) => void
type Wrapper = (data: any) => any
function composeAsync(wrapper: Wrapper, callback: Callback): Callback {
return function(error, data) {
if (error) {
callback(error);
callback(error, data);
return;
}
let result;
@@ -50,7 +66,22 @@ function composeAsync(wrapper, callback) {
};
}
function convertExceptions(f) {
function convertErrors(callback: Callback): () => void {
return function(error, data) {
if (error && !(error instanceof errors.RippleError)) {
const error_ = new errors.RippleError(error);
error_.data = data;
callback(error_, data);
} else if (error) {
error.data = data;
callback(error, data);
} else {
callback(error, data);
}
};
}
function convertExceptions<T>(f: () => T): () => T {
return function() {
try {
return f.apply(this, arguments);
@@ -60,12 +91,36 @@ function convertExceptions(f) {
};
}
const FINDSNAKE = /([a-zA-Z]_[a-zA-Z])/g;
function convertKeysFromSnakeCaseToCamelCase(obj: any): any {
if (typeof obj === 'object') {
let newKey;
return _.reduce(obj, (result, value, key) => {
newKey = key;
if (FINDSNAKE.test(key)) {
newKey = key.replace(FINDSNAKE, r => r[0] + r[2].toUpperCase());
}
result[newKey] = convertKeysFromSnakeCaseToCamelCase(value);
return result;
}, {});
}
return obj;
}
function promisify(asyncFunction: AsyncFunction): Function {
return es6promisify(wrapCatch(asyncFunction));
}
module.exports = {
core,
dropsToXrp,
xrpToDrops,
toRippledAmount,
wrapCatch,
generateAddress,
composeAsync,
convertExceptions
wrapCatch,
convertExceptions,
convertErrors,
convertKeysFromSnakeCaseToCamelCase,
promisify
};

View File

@@ -1,26 +1,38 @@
/* @flow */
'use strict';
const _ = require('lodash');
const core = require('./utils').core;
const ValidationError = require('./errors').ValidationError;
const schemaValidate = require('./schema-validator');
const schemaValidate = require('./schema-validator').schemaValidate;
function error(text) {
return new ValidationError(text);
}
function validateAddressAndSecret(obj) {
function validateAddressAndSecret(obj: {address: string, secret: string}
): void {
const address = obj.address;
const secret = obj.secret;
schemaValidate('address', address);
if (!secret) {
throw error('Parameter missing: secret');
}
try {
if (!core.Seed.from_json(secret).get_key(address)) {
throw error('secret does not match address');
}
} catch (exception) {
throw error('secret does not match address');
if (!core.Seed.from_json(secret).is_valid()) {
throw error('secret is invalid');
}
}
function validateSecret(secret: string): void {
if (!secret) {
throw error('Parameter missing: secret');
}
if (typeof secret !== 'string' || secret[0] !== 's') {
throw error('Invalid parameter');
}
const seed = new core.Seed().parse_base58(secret);
if (!seed.is_valid()) {
throw error('invalid seed');
}
}
@@ -41,12 +53,20 @@ function validateOptions(schema, options) {
module.exports = {
address: _.partial(schemaValidate, 'address'),
addressAndSecret: validateAddressAndSecret,
secret: validateSecret,
currency: _.partial(schemaValidate, 'currency'),
identifier: _.partial(schemaValidate, 'hash256'),
ledgerVersion: _.partial(schemaValidate, 'ledgerVersion'),
sequence: _.partial(schemaValidate, 'sequence'),
order: _.partial(schemaValidate, 'order'),
orderbook: _.partial(schemaValidate, 'orderbook'),
payment: _.partial(schemaValidate, 'payment'),
suspendedPaymentCreation:
_.partial(schemaValidate, 'suspended-payment-creation'),
suspendedPaymentExecution:
_.partial(schemaValidate, 'suspended-payment-execution'),
suspendedPaymentCancellation:
_.partial(schemaValidate, 'suspended-payment-cancellation'),
pathfind: _.partial(schemaValidate, 'pathfind'),
settings: _.partial(schemaValidate, 'settings'),
trustline: _.partial(schemaValidate, 'trustline'),
@@ -60,6 +80,8 @@ module.exports = {
getOrdersOptions: _.partial(validateOptions, 'orders-options'),
getOrderbookOptions: _.partial(validateOptions, 'orders-options'),
getTransactionOptions: _.partial(validateOptions, 'transaction-options'),
getLedgerOptions: _.partial(validateOptions, 'ledger-options'),
options: _.partial(validateOptions, 'options'),
remoteOptions: _.partial(schemaValidate, 'remote-options'),
instructions: _.partial(schemaValidate, 'instructions')
};

View File

@@ -2,7 +2,9 @@
'use strict';
const _ = require('lodash');
const core = require('./common').core;
const util = require('util');
const EventEmitter = require('events').EventEmitter;
const common = require('./common');
const server = require('./server/server');
const connect = server.connect;
const disconnect = server.disconnect;
@@ -23,19 +25,36 @@ const preparePayment = require('./transaction/payment');
const prepareTrustline = require('./transaction/trustline');
const prepareOrder = require('./transaction/order');
const prepareOrderCancellation = require('./transaction/ordercancellation');
const prepareSuspendedPaymentCreation =
require('./transaction/suspended-payment-creation');
const prepareSuspendedPaymentExecution =
require('./transaction/suspended-payment-execution');
const prepareSuspendedPaymentCancellation =
require('./transaction/suspended-payment-cancellation');
const prepareSettings = require('./transaction/settings');
const sign = require('./transaction/sign');
const submit = require('./transaction/submit');
const errors = require('./common').errors;
const convertExceptions = require('./common').convertExceptions;
const generateWallet = convertExceptions(core.Wallet.generate);
const generateAddress = convertExceptions(common.generateAddress);
const computeLedgerHash = require('./offline/ledgerhash');
const getLedger = require('./ledger/ledger');
function RippleAPI(options: {}) {
common.validate.remoteOptions(options);
if (EventEmitter instanceof Function) { // always true, needed for flow
EventEmitter.call(this);
}
const _options = _.assign({}, options, {automatic_resubmission: false});
this.remote = new core.Remote(_options);
this.remote = new common.core.Remote(_options);
this.remote.on('ledger_closed', message => {
this.emit('ledgerClosed', server.formatLedgerClose(message));
});
}
RippleAPI.prototype = {
util.inherits(RippleAPI, EventEmitter);
_.assign(RippleAPI.prototype, {
connect,
disconnect,
isConnected,
@@ -52,17 +71,29 @@ RippleAPI.prototype = {
getOrderbook,
getSettings,
getAccountInfo,
getLedger,
preparePayment,
prepareTrustline,
prepareOrder,
prepareOrderCancellation,
prepareSuspendedPaymentCreation,
prepareSuspendedPaymentExecution,
prepareSuspendedPaymentCancellation,
prepareSettings,
sign,
submit,
generateWallet,
generateAddress,
errors
});
// these are exposed only for use by unit tests; they are not part of the API
RippleAPI._PRIVATE = {
common,
computeLedgerHash,
ledgerUtils: require('./ledger/utils'),
schemaValidator: require('./common/schema-validator')
};
module.exports = RippleAPI;

View File

@@ -5,8 +5,45 @@ const utils = require('./utils');
const removeUndefined = require('./parse/utils').removeUndefined;
const validate = utils.common.validate;
const composeAsync = utils.common.composeAsync;
const convertErrors = utils.common.convertErrors;
function formatAccountInfo(response) {
type AccountData = {
Sequence: number,
Account: string,
Balance: string,
Flags: number,
LedgerEntryType: string,
OwnerCount: number,
PreviousTxnID: string,
AccountTxnID?: string,
PreviousTxnLgrSeq: number,
index: string
}
type AccountDataResponse = {
account_data: AccountData,
ledger_current_index?: number,
ledger_hash?: string,
ledger_index: number,
validated: boolean
}
type AccountInfoOptions = {
ledgerVersion?: number
}
type AccountInfoCallback = (err: any, data: AccountInfoResponse) => void
type AccountInfoResponse = {
sequence: number,
xrpBalance: string,
ownerCount: number,
previousInitiatedTransactionID: string,
previousAffectingTransactionID: string,
previousAffectingTransactionLedgerVersion: number
}
function formatAccountInfo(response: AccountDataResponse) {
const data = response.account_data;
return removeUndefined({
sequence: data.Sequence,
@@ -18,17 +55,24 @@ function formatAccountInfo(response) {
});
}
function getAccountInfo(account, options, callback) {
function getAccountInfoAsync(account: string, options: AccountInfoOptions,
callback: AccountInfoCallback
) {
validate.address(account);
validate.getAccountInfoOptions(options);
const request = {
account: account,
ledger: options.ledgerVersion
ledger: options.ledgerVersion || 'validated'
};
this.remote.requestAccountInfo(request,
composeAsync(formatAccountInfo, callback));
composeAsync(formatAccountInfo, convertErrors(callback)));
}
module.exports = utils.wrapCatch(getAccountInfo);
function getAccountInfo(account: string, options: AccountInfoOptions = {}
): Promise<AccountInfoResponse> {
return utils.promisify(getAccountInfoAsync).call(this, account, options);
}
module.exports = getAccountInfo;

View File

@@ -6,6 +6,7 @@ const utils = require('./utils');
const getTrustlines = require('./trustlines');
const validate = utils.common.validate;
const composeAsync = utils.common.composeAsync;
const convertErrors = utils.common.convertErrors;
function getTrustlineBalanceAmount(trustline) {
return {
@@ -24,7 +25,13 @@ function formatBalances(balances) {
balances.trustlines.map(getTrustlineBalanceAmount));
}
function getBalances(account, options, callback) {
function getTrustlinesAsync(account, options, callback) {
getTrustlines.call(this, account, options)
.then(data => callback(null, data))
.catch(callback);
}
function getBalancesAsync(account, options, callback) {
validate.address(account);
validate.getBalancesOptions(options);
@@ -32,8 +39,12 @@ function getBalances(account, options, callback) {
|| this.remote.getLedgerSequence();
async.parallel({
xrp: _.partial(utils.getXRPBalance, this.remote, account, ledgerVersion),
trustlines: _.partial(getTrustlines.bind(this), account, options)
}, composeAsync(formatBalances, callback));
trustlines: _.partial(getTrustlinesAsync.bind(this), account, options)
}, composeAsync(formatBalances, convertErrors(callback)));
}
module.exports = utils.wrapCatch(getBalances);
function getBalances(account: string, options = {}) {
return utils.promisify(getBalancesAsync).call(this, account, options);
}
module.exports = getBalances;

28
src/api/ledger/ledger.js Normal file
View File

@@ -0,0 +1,28 @@
/* @flow */
'use strict';
const utils = require('./utils');
const validate = utils.common.validate;
const composeAsync = utils.common.composeAsync;
const convertErrors = utils.common.convertErrors;
const parseLedger = require('./parse/ledger');
function getLedgerAsync(options, callback) {
validate.getLedgerOptions(options);
const request = {
ledger: options.ledgerVersion || 'validated',
expand: options.includeAllData,
transactions: options.includeTransactions,
accounts: options.includeState
};
this.remote.requestLedger(request,
composeAsync(response => parseLedger(response.ledger),
convertErrors(callback)));
}
function getLedger(options = {}) {
return utils.promisify(getLedgerAsync).call(this, options);
}
module.exports = getLedger;

View File

@@ -3,21 +3,23 @@
const _ = require('lodash');
const async = require('async');
const utils = require('./utils');
const parseOrderbookOrder = require('./parse/orderbook-order');
const validate = utils.common.validate;
const composeAsync = utils.common.composeAsync;
const convertErrors = utils.common.convertErrors;
const parseOrderbookOrder = require('./parse/orderbook-order');
// account is to specify a "perspective", which affects which unfunded offers
// are returned
function getBookOffers(remote, account, ledgerVersion, limit,
takerGets, takerPays, callback) {
takerGets, takerPays, callback
) {
remote.requestBookOffers(utils.renameCounterpartyToIssuerInOrder({
taker_gets: takerGets,
taker_pays: takerPays,
ledger: ledgerVersion || 'validated',
limit: limit,
taker: account
}), composeAsync(data => data.offers, callback));
}), composeAsync(data => data.offers, convertErrors(callback)));
}
function isSameIssue(a, b) {
@@ -62,7 +64,7 @@ function formatBidsAndAsks(orderbook, offers) {
return {bids, asks};
}
function getOrderbook(account, orderbook, options, callback) {
function getOrderbookAsync(account, orderbook, options, callback) {
validate.address(account);
validate.orderbook(orderbook);
validate.getOrderbookOptions(options);
@@ -76,4 +78,9 @@ function getOrderbook(account, orderbook, options, callback) {
callback));
}
module.exports = utils.wrapCatch(getOrderbook);
function getOrderbook(account: string, orderbook: Object, options = {}) {
return utils.promisify(getOrderbookAsync).call(this,
account, orderbook, options);
}
module.exports = getOrderbook;

View File

@@ -4,10 +4,12 @@ const _ = require('lodash');
const utils = require('./utils');
const validate = utils.common.validate;
const composeAsync = utils.common.composeAsync;
const convertErrors = utils.common.convertErrors;
const parseAccountOrder = require('./parse/account-order');
function requestAccountOffers(remote, address, ledgerVersion, options,
marker, limit, callback) {
function requestAccountOffers(remote, address, ledgerVersion, marker, limit,
callback
) {
remote.requestAccountOffers({
account: address,
marker: marker,
@@ -17,20 +19,24 @@ function requestAccountOffers(remote, address, ledgerVersion, options,
composeAsync((data) => ({
marker: data.marker,
results: data.offers.map(_.partial(parseAccountOrder, address))
}), callback));
}), convertErrors(callback)));
}
function getOrders(account, options, callback) {
function getOrdersAsync(account, options, callback) {
validate.address(account);
validate.getOrdersOptions(options);
const ledgerVersion = options.ledgerVersion
|| this.remote.getLedgerSequence();
const getter = _.partial(requestAccountOffers, this.remote, account,
ledgerVersion, options);
ledgerVersion);
utils.getRecursive(getter, options.limit,
composeAsync((orders) => _.sortBy(orders,
(order) => order.properties.sequence), callback));
}
module.exports = utils.wrapCatch(getOrders);
function getOrders(account: string, options = {}) {
return utils.promisify(getOrdersAsync).call(this, account, options);
}
module.exports = getOrders;

View File

@@ -1,11 +1,15 @@
/* @flow */
'use strict';
const BigNumber = require('bignumber.js');
const AccountFields = require('./utils').constants.AccountFields;
function parseField(info, value) {
if (info.encoding === 'hex' && !info.length) {
return new Buffer(value, 'hex').toString('ascii');
}
if (info.shift) {
return (new BigNumber(value)).shift(-info.shift).toNumber();
}
return value;
}

View File

@@ -0,0 +1,50 @@
/* @flow */
'use strict';
const _ = require('lodash');
const removeUndefined = require('./utils').removeUndefined;
const parseTransaction = require('./transaction');
function parseTransactions(transactions) {
if (_.isEmpty(transactions)) {
return {};
}
if (_.isString(transactions[0])) {
return {transactionHashes: transactions};
}
return {
transactions: _.map(transactions, parseTransaction),
rawTransactions: JSON.stringify(transactions)
};
}
function parseState(state) {
if (_.isEmpty(state)) {
return {};
}
if (_.isString(state[0])) {
return {stateHashes: state};
}
return {rawState: JSON.stringify(state)};
}
function parseLedger(ledger: Object): Object {
return removeUndefined(_.assign({
accepted: ledger.accepted,
closed: ledger.closed,
stateHash: ledger.account_hash,
closeTime: ledger.close_time,
closeTimeResolution: ledger.close_time_resolution,
closeFlags: ledger.close_flags,
ledgerHash: ledger.hash || ledger.ledger_hash,
ledgerVersion: parseInt(ledger.ledger_index || ledger.seqNum, 10),
parentLedgerHash: ledger.parent_hash,
parentCloseTime: ledger.parent_close_time,
totalDrops: ledger.total_coins || ledger.totalCoins,
transactionHash: ledger.transaction_hash
},
parseTransactions(ledger.transactions),
parseState(ledger.accountState)
));
}
module.exports = parseLedger;

View File

@@ -9,12 +9,13 @@ function parsePaths(paths) {
}
function parsePathfind(sourceAddress: string,
destinationAmount: Object, pathfindResult: Object): Object {
destinationAmount: Object, pathfindResult: Object
): Object {
return pathfindResult.alternatives.map(function(alternative) {
return {
source: {
address: sourceAddress,
amount: parseAmount(alternative.source_amount)
maxAmount: parseAmount(alternative.source_amount)
},
destination: {
address: pathfindResult.destination_account,

View File

@@ -1,5 +1,6 @@
/* @flow */
'use strict';
const _ = require('lodash');
const assert = require('assert');
const utils = require('./utils');
const parseAmount = require('./amount');
@@ -17,17 +18,9 @@ function isQualityLimited(tx) {
return (tx.Flags & Transaction.flags.Payment.LimitQuality) !== 0;
}
function parsePaymentMemos(tx) {
if (!Array.isArray(tx.Memos) || tx.Memos.length === 0) {
return undefined;
}
return tx.Memos.map((m) => {
return utils.removeUndefined({
type: m.Memo.parsed_memo_type,
format: m.Memo.parsed_memo_format,
data: m.Memo.parsed_memo_data
});
});
function removeGenericCounterparty(amount, address) {
return amount.counterparty === address ?
_.omit(amount, 'counterparty') : amount;
}
function parsePayment(tx: Object): Object {
@@ -35,20 +28,21 @@ function parsePayment(tx: Object): Object {
const source = {
address: tx.Account,
amount: parseAmount(tx.SendMax || tx.Amount),
maxAmount: removeGenericCounterparty(
parseAmount(tx.SendMax || tx.Amount), tx.Account),
tag: tx.SourceTag
};
const destination = {
address: tx.Destination,
amount: parseAmount(tx.Amount),
amount: removeGenericCounterparty(parseAmount(tx.Amount), tx.Destination),
tag: tx.DestinationTag
};
return utils.removeUndefined({
source: utils.removeUndefined(source),
destination: utils.removeUndefined(destination),
memos: parsePaymentMemos(tx),
memos: utils.parseMemos(tx),
invoiceID: tx.InvoiceID,
paths: tx.Paths ? JSON.stringify(tx.Paths) : undefined,
allowPartialPayment: isPartialPayment(tx) || undefined,

View File

@@ -0,0 +1,16 @@
/* @flow */
'use strict';
const assert = require('assert');
const utils = require('./utils');
function parseSuspendedPaymentCancellation(tx: Object): Object {
assert(tx.TransactionType === 'SuspendedPaymentCancel');
return utils.removeUndefined({
memos: utils.parseMemos(tx),
owner: tx.Owner,
paymentSequence: tx.OfferSequence
});
}
module.exports = parseSuspendedPaymentCancellation;

View File

@@ -0,0 +1,39 @@
/* @flow */
'use strict';
const _ = require('lodash');
const assert = require('assert');
const utils = require('./utils');
const parseAmount = require('./amount');
function removeGenericCounterparty(amount, address) {
return amount.counterparty === address ?
_.omit(amount, 'counterparty') : amount;
}
function parseSuspendedPaymentCreation(tx: Object): Object {
assert(tx.TransactionType === 'SuspendedPaymentCreate');
const source = {
address: tx.Account,
maxAmount: removeGenericCounterparty(
parseAmount(tx.SendMax || tx.Amount), tx.Account),
tag: tx.SourceTag
};
const destination = {
address: tx.Destination,
amount: removeGenericCounterparty(parseAmount(tx.Amount), tx.Destination),
tag: tx.DestinationTag
};
return utils.removeUndefined({
source: utils.removeUndefined(source),
destination: utils.removeUndefined(destination),
memos: utils.parseMemos(tx),
digest: tx.Digest,
allowCancelAfter: tx.CancelAfter,
allowExecuteAfter: tx.FinishAfter
});
}
module.exports = parseSuspendedPaymentCreation;

View File

@@ -0,0 +1,25 @@
/* @flow */
'use strict';
const assert = require('assert');
const sjclcodec = require('sjcl-codec');
const utils = require('./utils');
function convertHexToString(hexString) {
const bits = sjclcodec.hex.toBits(hexString);
return sjclcodec.utf8String.fromBits(bits);
}
function parseSuspendedPaymentExecution(tx: Object): Object {
assert(tx.TransactionType === 'SuspendedPaymentFinish');
return utils.removeUndefined({
memos: utils.parseMemos(tx),
owner: tx.Owner,
paymentSequence: tx.OfferSequence,
method: tx.Method,
digest: tx.Digest,
proof: tx.Proof ? convertHexToString(tx.Proof) : undefined
});
}
module.exports = parseSuspendedPaymentExecution;

View File

@@ -7,6 +7,10 @@ const parseTrustline = require('./trustline');
const parseOrder = require('./order');
const parseOrderCancellation = require('./cancellation');
const parseSettings = require('./settings');
const parseSuspendedPaymentCreation = require('./suspended-payment-creation');
const parseSuspendedPaymentExecution = require('./suspended-payment-execution');
const parseSuspendedPaymentCancellation =
require('./suspended-payment-cancellation');
function parseTransactionType(type) {
const mapping = {
@@ -15,7 +19,10 @@ function parseTransactionType(type) {
OfferCreate: 'order',
OfferCancel: 'orderCancellation',
AccountSet: 'settings',
SetRegularKey: 'settings'
SetRegularKey: 'settings',
SuspendedPaymentCreate: 'suspendedPaymentCreation',
SuspendedPaymentFinish: 'suspendedPaymentExecution',
SuspendedPaymentCancel: 'suspendedPaymentCancellation'
};
return mapping[type] || null;
}
@@ -27,7 +34,10 @@ function parseTransaction(tx: Object): Object {
'trustline': parseTrustline,
'order': parseOrder,
'orderCancellation': parseOrderCancellation,
'settings': parseSettings
'settings': parseSettings,
'suspendedPaymentCreation': parseSuspendedPaymentCreation,
'suspendedPaymentExecution': parseSuspendedPaymentExecution,
'suspendedPaymentCancellation': parseSuspendedPaymentCancellation
};
const parser = mapping[type];
assert(parser !== undefined, 'Unrecognized transaction type');

View File

@@ -3,6 +3,7 @@
const assert = require('assert');
const utils = require('./utils');
const flags = utils.core.Transaction.flags.TrustSet;
const BigNumber = require('bignumber.js');
function parseFlag(flagsValue, trueValue, falseValue) {
if (flagsValue & trueValue) {
@@ -14,6 +15,13 @@ function parseFlag(flagsValue, trueValue, falseValue) {
return undefined;
}
function parseQuality(quality?: number) {
if (typeof quality === 'number') {
return (new BigNumber(quality)).shift(-9).toNumber();
}
return undefined;
}
function parseTrustline(tx: Object): Object {
assert(tx.TransactionType === 'TrustSet');
@@ -21,8 +29,8 @@ function parseTrustline(tx: Object): Object {
limit: tx.LimitAmount.value,
currency: tx.LimitAmount.currency,
counterparty: tx.LimitAmount.issuer,
qualityIn: tx.QualityIn,
qualityOut: tx.QualityOut,
qualityIn: parseQuality(tx.QualityIn),
qualityOut: parseQuality(tx.QualityOut),
ripplingDisabled: parseFlag(
tx.Flags, flags.SetNoRipple, flags.ClearNoRipple),
frozen: parseFlag(tx.Flags, flags.SetFreeze, flags.ClearFreeze),

View File

@@ -6,8 +6,9 @@ const toTimestamp = require('../../../core/utils').toTimestamp;
const utils = require('../utils');
const BigNumber = require('bignumber.js');
function adjustQualityForXRP(quality: string, takerGetsCurrency: string,
takerPaysCurrency: string) {
function adjustQualityForXRP(
quality: string, takerGetsCurrency: string, takerPaysCurrency: string
) {
// quality = takerPays.value/takerGets.value
// using drops (1e-6 XRP) for XRP values
const numeratorShift = (takerPaysCurrency === 'XRP' ? -6 : 0);
@@ -51,7 +52,7 @@ function parseOutcome(tx: Object): ?Object {
}
const balanceChanges = transactionParser.parseBalanceChanges(tx.meta);
const orderbookChanges = transactionParser.parseOrderBookChanges(tx.meta);
const orderbookChanges = transactionParser.parseOrderbookChanges(tx.meta);
removeEmptyCounterpartyInBalanceChanges(balanceChanges);
removeEmptyCounterpartyInOrderbookChanges(orderbookChanges);
@@ -66,8 +67,22 @@ function parseOutcome(tx: Object): ?Object {
};
}
function parseMemos(tx: Object): ?Array<Object> {
if (!Array.isArray(tx.Memos) || tx.Memos.length === 0) {
return undefined;
}
return tx.Memos.map((m) => {
return removeUndefined({
type: m.Memo.parsed_memo_type,
format: m.Memo.parsed_memo_format,
data: m.Memo.parsed_memo_data
});
});
}
module.exports = {
parseOutcome,
parseMemos,
removeUndefined,
adjustQualityForXRP,
dropsToXrp: utils.common.dropsToXrp,

View File

@@ -8,6 +8,7 @@ const validate = utils.common.validate;
const parsePathfind = require('./parse/pathfind');
const NotFoundError = utils.common.errors.NotFoundError;
const composeAsync = utils.common.composeAsync;
const convertErrors = utils.common.convertErrors;
type PathFindParams = {
src_currencies?: Array<string>, src_account: string, dst_amount: string,
@@ -46,8 +47,8 @@ function requestPathFind(remote, pathfind: PathFind, callback) {
_.omit(utils.common.toRippledAmount(amount), 'value'));
}
remote.requestRipplePathFind(params,
composeAsync(_.partial(addParams, params), callback));
remote.createPathFind(params,
composeAsync(_.partial(addParams, params), convertErrors(callback)));
}
function addDirectXrpPath(paths, xrpBalance) {
@@ -83,7 +84,8 @@ function formatResponse(pathfind, paths) {
const address = pathfind.source.address;
return parsePathfind(address, pathfind.destination.amount, paths);
}
if (!_.includes(paths.destination_currencies,
if (paths.destination_currencies !== undefined &&
!_.includes(paths.destination_currencies,
pathfind.destination.amount.currency)) {
throw new NotFoundError('No paths found. ' +
'The destination_account does not accept ' +
@@ -103,7 +105,7 @@ function formatResponse(pathfind, paths) {
}
}
function getPaths(pathfind, callback) {
function getPathsAsync(pathfind, callback) {
validate.pathfind(pathfind);
const address = pathfind.source.address;
@@ -113,4 +115,8 @@ function getPaths(pathfind, callback) {
], composeAsync(_.partial(formatResponse, pathfind), callback));
}
module.exports = utils.wrapCatch(getPaths);
function getPaths(pathfind: Object) {
return utils.promisify(getPathsAsync).call(this, pathfind);
}
module.exports = getPaths;

View File

@@ -6,6 +6,7 @@ const validate = utils.common.validate;
const parseFields = require('./parse/fields');
const composeAsync = utils.common.composeAsync;
const AccountFlags = utils.common.constants.AccountFlags;
const convertErrors = utils.common.convertErrors;
function parseFlags(value) {
const settings = {};
@@ -24,17 +25,21 @@ function formatSettings(response) {
return _.assign({}, parsedFlags, parsedFields);
}
function getSettings(account, options, callback) {
function getSettingsAsync(account, options, callback) {
validate.address(account);
validate.getSettingsOptions(options);
const request = {
account: account,
ledger: options.ledgerVersion
ledger: options.ledgerVersion || 'validated'
};
this.remote.requestAccountInfo(request,
composeAsync(formatSettings, callback));
composeAsync(formatSettings, convertErrors(callback)));
}
module.exports = utils.wrapCatch(getSettings);
function getSettings(account: string, options = {}) {
return utils.promisify(getSettingsAsync).call(this, account, options);
}
module.exports = getSettings;

View File

@@ -0,0 +1,147 @@
/* @flow */
'use strict';
type Outcome = {
result: string,
timestamp?: string,
fee: string,
balanceChanges: Object,
orderbookChanges: Object,
ledgerVersion: number,
indexInLedger: number
}
type Adjustment = {
address: string,
amount: {
currency: string,
counterparty?: string,
value: string
},
tag?: number
}
type Trustline = {
currency: string,
counterparty: string,
limit: string,
qualityIn?: number,
qualityOut?: number,
ripplingDisabled?: boolean,
authorized?: boolean,
frozen?: boolean
}
type Settings = {
passwordSpent?: boolean,
requireDestinationTag?: boolean,
requireAuthorization?: boolean,
disallowIncomingXRP?: boolean,
disableMasterKey?: boolean,
enableTransactionIDTracking?: boolean,
noFreeze?: boolean,
globalFreeze?: boolean,
defaultRipple?: boolean,
emailHash?: string,
walletLocator?: string,
walletSize?: number,
messageKey?: string,
domain?: string,
transferRate?: number,
signers?: string,
regularKey?: string
}
type OrderCancellation = {
orderSequence: number
}
type Memo = {
type?: string,
format?: string,
data?: string
}
type Amount = {
value: string,
currency: string,
counterparty?: string
}
type Payment = {
source: Adjustment,
destination: Adjustment,
paths?: string,
memos?: Array<Memo>,
invoiceID?: string,
allowPartialPayment?: boolean,
noDirectRipple?: boolean,
limitQuality?: boolean
}
type PaymentTransaction = {
type: string,
specification: Payment,
outcome: Outcome,
id: string,
address: string,
sequence: number
}
type Order = {
direction: string,
quantity: Amount,
totalPrice: Amount,
immediateOrCancel?: boolean,
fillOrKill?: boolean,
passive?: boolean
}
type OrderTransaction = {
type: string,
specification: Order,
outcome: Outcome,
id: string,
address: string,
sequence: number
}
type OrderCancellationTransaction = {
type: string,
specification: OrderCancellation,
outcome: Outcome,
id: string,
address: string,
sequence: number
}
type TrustlineTransaction = {
type: string,
specification: Trustline,
outcome: Outcome,
id: string,
address: string,
sequence: number
}
type SettingsTransaction = {
type: string,
specification: Settings,
outcome: Outcome,
id: string,
address: string,
sequence: number
}
export type TransactionOptions = {
minLedgerVersion?: number,
maxLedgerVersion?: number
}
export type GetTransactionResponse = PaymentTransaction | OrderTransaction |
OrderCancellationTransaction | TrustlineTransaction | SettingsTransaction
export type GetTransactionResponseCallback =
(err?: ?Error, data?: GetTransactionResponse) => void
export type CallbackType = (err?: ?Error, data?: Object) => void

View File

@@ -6,8 +6,18 @@ const utils = require('./utils');
const parseTransaction = require('./parse/transaction');
const validate = utils.common.validate;
const errors = utils.common.errors;
const convertErrors = utils.common.convertErrors;
const RippleError = require('../../core/rippleerror').RippleError;
function attachTransactionDate(remote, tx, callback) {
import type {Remote} from '../../core/remote';
import type {CallbackType, GetTransactionResponse,
GetTransactionResponseCallback, TransactionOptions}
from './transaction-types';
function attachTransactionDate(remote: Remote, tx: Object,
callback: CallbackType
) {
if (tx.date) {
callback(null, tx);
return;
@@ -28,40 +38,68 @@ function attachTransactionDate(remote, tx, callback) {
});
}
function isTransactionInRange(tx, options) {
function isTransactionInRange(tx: Object, options: TransactionOptions) {
return (!options.minLedgerVersion
|| tx.ledger_index >= options.minLedgerVersion)
&& (!options.maxLedgerVersion
|| tx.ledger_index <= options.maxLedgerVersion);
}
function getTransaction(identifier, options, callback) {
function getTransactionAsync(identifier: string, options: TransactionOptions,
callback: GetTransactionResponseCallback
) {
validate.identifier(identifier);
validate.getTransactionOptions(options);
const remote = this.remote;
const maxLedgerVersion = Math.min(options.maxLedgerVersion,
remote.getLedgerSequence());
const maxLedgerVersion =
options.maxLedgerVersion || remote.getLedgerSequence();
function callbackWrapper(error, tx) {
function callbackWrapper(error_?: Error, tx?: Object) {
let error = error_;
if (!error && tx && tx.validated !== true) {
return callback(new errors.NotFoundError('Transaction not found'));
}
if (error instanceof RippleError && error.remote &&
error.remote.error === 'txnNotFound') {
error = new errors.NotFoundError('Transaction not found');
}
// Missing complete ledger range
if (error instanceof errors.NotFoundError
&& !utils.hasCompleteLedgerRange(remote,
options.minLedgerVersion, maxLedgerVersion)) {
callback(new errors.MissingLedgerHistoryError('Transaction not found,'
+ ' but the server\'s ledger history is incomplete'));
} else if (!error && !isTransactionInRange(tx, options)) {
&& !utils.hasCompleteLedgerRange(remote, options.minLedgerVersion,
maxLedgerVersion)) {
if (utils.isPendingLedgerVersion(remote, maxLedgerVersion)) {
callback(new errors.PendingLedgerVersionError());
} else {
callback(new errors.MissingLedgerHistoryError());
}
// Transaction is found, but not in specified range
} else if (!error && tx && !isTransactionInRange(tx, options)) {
callback(new errors.NotFoundError('Transaction not found'));
// Transaction is not found
} else if (error) {
callback(error);
convertErrors(callback)(error);
} else if (!tx) {
callback(new errors.ApiError('Internal error'));
} else {
callback(error, parseTransaction(tx));
}
}
async.waterfall([
_.partial(remote.requestTx.bind(remote), {hash: identifier, binary: false}),
_.partial(remote.requestTx.bind(remote),
{hash: identifier, binary: false}),
_.partial(attachTransactionDate, remote)
], callbackWrapper);
}
module.exports = utils.wrapCatch(getTransaction);
function getTransaction(identifier: string,
options: TransactionOptions = {}
): Promise<GetTransactionResponse> {
return utils.promisify(getTransactionAsync).call(this, identifier, options);
}
module.exports = getTransaction;

View File

@@ -1,4 +1,5 @@
/* @flow */
/* eslint-disable max-params */
'use strict';
const _ = require('lodash');
const utils = require('./utils');
@@ -6,6 +7,7 @@ const parseTransaction = require('./parse/transaction');
const getTransaction = require('./transaction');
const validate = utils.common.validate;
const composeAsync = utils.common.composeAsync;
const convertErrors = utils.common.convertErrors;
function parseAccountTxTransaction(tx) {
// rippled uses a different response format for 'account_tx' than 'tx'
@@ -14,6 +16,21 @@ function parseAccountTxTransaction(tx) {
return parseTransaction(tx.tx);
}
function counterpartyFilter(filters, tx) {
if (!filters.counterparty) {
return true;
}
if (tx.address === filters.counterparty || (
tx.specification && (
(tx.specification.destination &&
tx.specification.destination.address === filters.counterparty) ||
(tx.specification.counterparty === filters.counterparty)
))) {
return true;
}
return false;
}
function transactionFilter(address, filters, tx) {
if (filters.excludeFailures && tx.outcome.result !== 'tesSUCCESS') {
return false;
@@ -27,8 +44,7 @@ function transactionFilter(address, filters, tx) {
if (filters.initiated === false && tx.address === address) {
return false;
}
if (filters.counterparty && tx.address !== filters.counterparty
&& tx.Destination !== filters.counterparty) {
if (filters.counterparty && !counterpartyFilter(filters, tx)) {
return false;
}
return true;
@@ -40,27 +56,31 @@ function orderFilter(options, tx) {
utils.compareTransactions(tx, options.startTx) < 0);
}
function formatPartialResponse(address, options, data) {
return {
marker: data.marker,
results: data.transactions
.filter((tx) => tx.validated)
.map(parseAccountTxTransaction)
.filter(_.partial(transactionFilter, address, options))
.filter(_.partial(orderFilter, options))
};
}
function getAccountTx(remote, address, options, marker, limit, callback) {
const params = {
account: address,
ledger_index_min: options.minLedgerVersion || -1,
ledger_index_max: options.maxLedgerVersion || -1,
ledger_index_max: options.maxLedgerVersion || remote.getLedgerSequence(),
forward: options.earliestFirst,
binary: options.binary,
limit: utils.clamp(limit, 10, 400),
marker: marker
};
remote.requestAccountTx(params, (error, data) => {
return error ? callback(error) : callback(null, {
marker: data.marker,
results: data.transactions
.filter((tx) => tx.validated)
.map(parseAccountTxTransaction)
.filter(_.partial(transactionFilter, address, options))
.filter(_.partial(orderFilter, options))
});
});
remote.requestAccountTx(params,
composeAsync(_.partial(formatPartialResponse, address, options),
convertErrors(callback)));
}
function checkForLedgerGaps(remote, options, transactions) {
@@ -97,27 +117,27 @@ function getTransactionsInternal(remote, address, options, callback) {
utils.getRecursive(getter, options.limit, composeAsync(format, callback));
}
function getTransactions(address, options, callback) {
validate.address(address);
function getTransactionsAsync(account, options, callback) {
validate.address(account);
validate.getTransactionsOptions(options);
const defaults = {maxLedgerVersion: this.remote.getLedgerSequence()};
if (options.start) {
getTransaction.bind(this)(options.start, {}, (error, tx) => {
if (error) {
callback(error);
return;
}
getTransaction.call(this, options.start).then(tx => {
const ledgerVersion = tx.outcome.ledgerVersion;
const bound = options.earliestFirst ?
{minLedgerVersion: ledgerVersion} : {maxLedgerVersion: ledgerVersion};
const newOptions = _.assign(defaults, options, {startTx: tx}, bound);
getTransactionsInternal(this.remote, address, newOptions, callback);
});
getTransactionsInternal(this.remote, account, newOptions, callback);
}).catch(callback);
} else {
const newOptions = _.assign(defaults, options);
getTransactionsInternal(this.remote, address, newOptions, callback);
getTransactionsInternal(this.remote, account, newOptions, callback);
}
}
module.exports = utils.wrapCatch(getTransactions);
function getTransactions(account: string, options = {}) {
return utils.promisify(getTransactionsAsync).call(this, account, options);
}
module.exports = getTransactions;

View File

@@ -3,14 +3,25 @@
const _ = require('lodash');
const utils = require('./utils');
const validate = utils.common.validate;
const composeAsync = utils.common.composeAsync;
const convertErrors = utils.common.convertErrors;
const parseAccountTrustline = require('./parse/account-trustline');
function currencyFilter(currency, trustline) {
return currency === null || trustline.specification.currency === currency;
}
function formatResponse(options, data) {
return {
marker: data.marker,
results: data.lines.map(parseAccountTrustline)
.filter(_.partial(currencyFilter, options.currency || null))
};
}
function getAccountLines(remote, address, ledgerVersion, options, marker, limit,
callback) {
callback
) {
const requestOptions = {
account: address,
ledger: ledgerVersion,
@@ -19,19 +30,15 @@ function getAccountLines(remote, address, ledgerVersion, options, marker, limit,
peer: options.counterparty
};
remote.requestAccountLines(requestOptions, (error, data) => {
return error ? callback(error) :
callback(null, {
marker: data.marker,
results: data.lines.map(parseAccountTrustline)
.filter(_.partial(currencyFilter, options.currency || null))
});
});
remote.requestAccountLines(requestOptions,
composeAsync(_.partial(formatResponse, options),
convertErrors(callback)));
}
function getTrustlines(account: string, options: {currency: string,
function getTrustlinesAsync(account: string, options: {currency: string,
counterparty: string, limit: number, ledgerVersion: number},
callback: () => void): void {
callback: () => void
): void {
validate.address(account);
validate.getTrustlinesOptions(options);
@@ -42,4 +49,8 @@ function getTrustlines(account: string, options: {currency: string,
utils.getRecursive(getter, options.limit, callback);
}
module.exports = utils.wrapCatch(getTrustlines);
function getTrustlines(account: string, options = {}) {
return utils.promisify(getTrustlinesAsync).call(this, account, options);
}
module.exports = getTrustlines;

View File

@@ -1,23 +1,33 @@
/* @flow */
'use strict';
const _ = require('lodash');
const assert = require('assert');
const common = require('../common');
const dropsToXrp = common.dropsToXrp;
const composeAsync = common.composeAsync;
import type {Remote} from '../../core/remote';
function clamp(value, min, max) {
type Callback = (err: any, data: any) => void
function clamp(value: number, min: number, max: number): number {
assert(min <= max, 'Illegal clamp bounds');
return Math.min(Math.max(value, min), max);
}
function getXRPBalance(remote, address, ledgerVersion, callback) {
function getXRPBalance(remote: Remote, address: string, ledgerVersion?: number,
callback: Callback
): void {
remote.requestAccountInfo({account: address, ledger: ledgerVersion},
composeAsync((data) => dropsToXrp(data.account_data.Balance), callback));
}
type Getter = (marker: ?string, limit: number, callback: Callback) => void
// If the marker is omitted from a response, you have reached the end
// getter(marker, limit, callback), callback(error, {marker, results})
function getRecursiveRecur(getter, marker, limit, callback) {
function getRecursiveRecur(getter: Getter, marker?: string, limit: number,
callback: Callback
): void {
getter(marker, limit, (error, data) => {
if (error) {
return callback(error);
@@ -34,11 +44,13 @@ function getRecursiveRecur(getter, marker, limit, callback) {
});
}
function getRecursive(getter, limit, callback) {
function getRecursive(getter: Getter, limit?: number, callback: Callback) {
getRecursiveRecur(getter, undefined, limit || Infinity, callback);
}
function renameCounterpartyToIssuer(amount) {
type Amount = {counterparty?: string, issuer?: string, value: string}
function renameCounterpartyToIssuer(amount?: Amount): ?{issuer?: string} {
if (amount === undefined) {
return undefined;
}
@@ -48,7 +60,9 @@ function renameCounterpartyToIssuer(amount) {
return _.omit(withIssuer, 'counterparty');
}
function renameCounterpartyToIssuerInOrder(order) {
type Order = {taker_gets: Amount, taker_pays: Amount}
function renameCounterpartyToIssuerInOrder(order: Order) {
const taker_gets = renameCounterpartyToIssuer(order.taker_gets);
const taker_pays = renameCounterpartyToIssuer(order.taker_pays);
const changes = {taker_gets: taker_gets, taker_pays: taker_pays};
@@ -70,20 +84,34 @@ function signum(num) {
* @returns {Number} [-1, 0, 1]
*/
function compareTransactions(first, second) {
if (first.ledgerVersion === second.ledgerVersion) {
return signum(Number(first.indexInLedger) - Number(second.indexInLedger));
type Outcome = {outcome: {ledgerVersion: number, indexInLedger: number}};
function compareTransactions(first: Outcome, second: Outcome): number {
if (!first.outcome || !second.outcome) {
return 0;
}
return Number(first.ledgerVersion) < Number(second.ledgerVersion) ? -1 : 1;
if (first.outcome.ledgerVersion === second.outcome.ledgerVersion) {
return signum(first.outcome.indexInLedger - second.outcome.indexInLedger);
}
return first.outcome.ledgerVersion < second.outcome.ledgerVersion ? -1 : 1;
}
function hasCompleteLedgerRange(remote, minLedgerVersion, maxLedgerVersion) {
function hasCompleteLedgerRange(remote: Remote, minLedgerVersion?: number,
maxLedgerVersion?: number
): boolean {
const firstLedgerVersion = 32570; // earlier versions have been lost
return remote.getServer().hasLedgerRange(
minLedgerVersion || firstLedgerVersion,
maxLedgerVersion || remote.getLedgerSequence());
}
function isPendingLedgerVersion(remote: Remote, maxLedgerVersion: ?number
): boolean {
const currentLedger = remote.getLedgerSequence();
return currentLedger < (maxLedgerVersion || 0);
}
module.exports = {
getXRPBalance,
compareTransactions,
@@ -91,7 +119,8 @@ module.exports = {
renameCounterpartyToIssuerInOrder,
getRecursive,
hasCompleteLedgerRange,
wrapCatch: common.wrapCatch,
isPendingLedgerVersion,
promisify: common.promisify,
clamp: clamp,
common: common
};

View File

@@ -0,0 +1,74 @@
/* @flow */
'use strict';
const _ = require('lodash');
const common = require('../common');
function convertLedgerHeader(header) {
return {
accepted: header.accepted,
closed: header.closed,
account_hash: header.stateHash,
close_time: header.closeTime,
close_time_resolution: header.closeTimeResolution,
close_flags: header.closeFlags,
hash: header.ledgerHash,
ledger_hash: header.ledgerHash,
ledger_index: header.ledgerVersion.toString(),
seqNum: header.ledgerVersion.toString(),
parent_hash: header.parentLedgerHash,
parent_close_time: header.parentCloseTime,
total_coins: header.totalDrops,
totalCoins: header.totalDrops,
transaction_hash: header.transactionHash
};
}
function hashLedgerHeader(ledgerHeader) {
const header = convertLedgerHeader(ledgerHeader);
return common.core.Ledger.calculateLedgerHash(header);
}
function computeTransactionHash(ledger) {
if (ledger.rawTransactions === undefined) {
return ledger.transactionHash;
}
const transactions = JSON.parse(ledger.rawTransactions);
const txs = _.map(transactions, tx => {
const mergeTx = _.assign({}, _.omit(tx, 'tx'), tx.tx || {});
const renameMeta = _.assign({}, _.omit(mergeTx, 'meta'),
tx.meta ? {metaData: tx.meta} : {});
return renameMeta;
});
const ledgerObject = common.core.Ledger.from_json({transactions: txs});
const transactionHash = ledgerObject.calc_tx_hash().to_hex();
if (ledger.transactionHash !== undefined
&& ledger.transactionHash !== transactionHash) {
throw new common.errors.ValidationError('transactionHash in header'
+ ' does not match computed hash of transactions');
}
return transactionHash;
}
function computeStateHash(ledger) {
if (ledger.rawState === undefined) {
return ledger.stateHash;
}
const state = JSON.parse(ledger.rawState);
const ledgerObject = common.core.Ledger.from_json({accountState: state});
const stateHash = ledgerObject.calc_account_hash().to_hex();
if (ledger.stateHash !== undefined && ledger.stateHash !== stateHash) {
throw new common.errors.ValidationError('stateHash in header'
+ ' does not match computed hash of state');
}
return stateHash;
}
function computeLedgerHash(ledger: Object): string {
const hashes = {
transactionHash: computeTransactionHash(ledger),
stateHash: computeStateHash(ledger)
};
return hashLedgerHeader(_.assign({}, ledger, hashes));
}
module.exports = computeLedgerHash;

View File

@@ -2,20 +2,43 @@
'use strict';
const _ = require('lodash');
const common = require('../common');
import type {Remote} from '../../core/remote';
// If a ledger is not received in this time, consider the connection offline
const CONNECTION_TIMEOUT = 1000 * 30;
function connect(callback: (err: any, data: any) => void): void {
this.remote.connect(callback);
type GetServerInfoResponse = {
buildVersion: string,
completeLedgers: string,
hostid: string,
ioLatencyMs: number,
load?: {
jobTypes: Array<Object>,
threads: number
},
lastClose: {
convergeTimeS: number,
proposers: number
},
loadFactor: number,
peers: number,
pubkeyNode: string,
pubkeyValidator?: string,
serverState: string,
validatedLedger: {
age: number,
baseFeeXrp: number,
hash: string,
reserveBaseXrp: number,
reserveIncXrp: number,
seq: number
},
validationQuorum: number
}
function disconnect(callback: (err: any, data: any) => void): void {
this.remote.disconnect(callback);
}
function isUpToDate(remote): boolean {
function isUpToDate(remote: Remote): boolean {
const server = remote.getServer();
return Boolean(server) && (remote._stand_alone
|| (Date.now() - server._lastLedgerClose) <= CONNECTION_TIMEOUT);
@@ -25,12 +48,17 @@ function isConnected(): boolean {
return Boolean(this.remote._ledger_current_index) && isUpToDate(this.remote);
}
function getServerInfo(callback: (err: any, data: any) => void): void {
function getServerInfoAsync(
callback: (err: any, data?: GetServerInfoResponse) => void
): void {
this.remote.requestServerInfo((error, response) => {
if (error) {
callback(new common.errors.RippledNetworkError(error.message));
const message =
_.get(error, ['remote', 'error_message'], error.message);
callback(new common.errors.RippledNetworkError(message));
} else {
callback(null, response.info);
callback(null,
common.convertKeysFromSnakeCaseToCamelCase(response.info));
}
});
}
@@ -43,11 +71,46 @@ function getLedgerVersion(): number {
return this.remote.getLedgerSequence();
}
function connect(): Promise<void> {
return common.promisify(callback => {
this.remote.connect(() => callback(null));
})();
}
function disconnect(): Promise<void> {
return common.promisify(callback => {
this.remote.disconnect(() => callback(null));
})();
}
function getServerInfo(): Promise<GetServerInfoResponse> {
return common.promisify(getServerInfoAsync.bind(this))();
}
function rippleTimeToISO8601(rippleTime: string): string {
return new Date(common.core.utils.toTimestamp(rippleTime)).toISOString();
}
function formatLedgerClose(ledgerClose: Object): Object {
return {
feeBase: ledgerClose.fee_base,
feeReference: ledgerClose.fee_ref,
ledgerHash: ledgerClose.ledger_hash,
ledgerVersion: ledgerClose.ledger_index,
ledgerTimestamp: rippleTimeToISO8601(ledgerClose.ledger_time),
reserveBase: ledgerClose.reserve_base,
reserveIncrement: ledgerClose.reserve_inc,
transactionCount: ledgerClose.txn_count,
validatedLedgerVersions: ledgerClose.validated_ledgers
};
}
module.exports = {
connect,
disconnect,
isConnected,
getServerInfo,
getFee,
getLedgerVersion
getLedgerVersion,
formatLedgerClose
};

View File

@@ -30,9 +30,14 @@ function createOrderTransaction(account, order) {
return transaction;
}
function prepareOrder(account, order, instructions, callback) {
function prepareOrderAsync(account, order, instructions, callback) {
const transaction = createOrderTransaction(account, order);
utils.createTxJSON(transaction, this.remote, instructions, callback);
utils.prepareTransaction(transaction, this.remote, instructions, callback);
}
module.exports = utils.wrapCatch(prepareOrder);
function prepareOrder(account: string, order: Object, instructions = {}) {
return utils.promisify(prepareOrderAsync.bind(this))(
account, order, instructions);
}
module.exports = prepareOrder;

View File

@@ -13,9 +13,18 @@ function createOrderCancellationTransaction(account, sequence) {
return transaction;
}
function prepareOrderCancellation(account, sequence, instructions, callback) {
function prepareOrderCancellationAsync(account, sequence, instructions,
callback
) {
const transaction = createOrderCancellationTransaction(account, sequence);
utils.createTxJSON(transaction, this.remote, instructions, callback);
utils.prepareTransaction(transaction, this.remote, instructions, callback);
}
module.exports = utils.wrapCatch(prepareOrderCancellation);
function prepareOrderCancellation(account: string, sequence: number,
instructions = {}
) {
return utils.promisify(prepareOrderCancellationAsync.bind(this))(
account, sequence, instructions);
}
module.exports = prepareOrderCancellation;

View File

@@ -1,21 +1,15 @@
/* @flow */
'use strict';
const _ = require('lodash');
const BigNumber = require('bignumber.js');
const utils = require('./utils');
const validate = utils.common.validate;
const toRippledAmount = utils.common.toRippledAmount;
const Transaction = utils.common.core.Transaction;
function isSendMaxAllowed(payment) {
const srcAmt = payment.source.amount;
const dstAmt = payment.destination.amount;
// Don't set SendMax for XRP->XRP payment
// temREDUNDANT_SEND_MAX removed in:
// https://github.com/ripple/rippled/commit/
// c522ffa6db2648f1d8a987843e7feabf1a0b7de8/
return srcAmt && !(srcAmt.currency === 'XRP' && dstAmt.currency === 'XRP');
function isXRPToXRPPayment(payment) {
const sourceCurrency = _.get(payment, 'source.maxAmount.currency');
const destinationCurrency = _.get(payment, 'destination.amount.currency');
return sourceCurrency === 'XRP' && destinationCurrency === 'XRP';
}
function isIOUWithoutCounterparty(amount) {
@@ -29,8 +23,8 @@ function applyAnyCounterpartyEncoding(payment) {
// https://ripple.com/build/transactions/
// #special-issuer-values-for-sendmax-and-amount
// https://ripple.com/build/ripple-rest/#counterparties-in-payments
if (isIOUWithoutCounterparty(payment.source.amount)) {
payment.source.amount.counterparty = payment.source.address;
if (isIOUWithoutCounterparty(payment.source.maxAmount)) {
payment.source.maxAmount.counterparty = payment.source.address;
}
if (isIOUWithoutCounterparty(payment.destination.amount)) {
payment.destination.amount.counterparty = payment.destination.address;
@@ -58,9 +52,6 @@ function createPaymentTransaction(account, payment) {
if (payment.destination.tag) {
transaction.destinationTag(payment.destination.tag);
}
if (payment.paths) {
transaction.paths(JSON.parse(payment.paths));
}
if (payment.memos) {
_.forEach(payment.memos, memo =>
transaction.addMemo(memo.type, memo.format, memo.data)
@@ -75,19 +66,29 @@ function createPaymentTransaction(account, payment) {
if (payment.limitQuality) {
transaction.setFlags(['LimitQuality']);
}
if (isSendMaxAllowed(payment)) {
const maxValue = new BigNumber(payment.source.amount.value)
.plus(payment.source.slippage || 0).toString();
const maxAmount = _.assign({}, payment.source.amount, {value: maxValue});
transaction.sendMax(toRippledAmount(maxAmount));
if (!isXRPToXRPPayment(payment)) {
// Don't set SendMax for XRP->XRP payment
// temREDUNDANT_SEND_MAX removed in:
// https://github.com/ripple/rippled/commit/
// c522ffa6db2648f1d8a987843e7feabf1a0b7de8/
transaction.sendMax(toRippledAmount(payment.source.maxAmount));
if (payment.paths) {
transaction.paths(JSON.parse(payment.paths));
}
}
return transaction;
}
function preparePayment(account, payment, instructions, callback) {
function preparePaymentAsync(account, payment, instructions, callback) {
const transaction = createPaymentTransaction(account, payment);
utils.createTxJSON(transaction, this.remote, instructions, callback);
utils.prepareTransaction(transaction, this.remote, instructions, callback);
}
module.exports = utils.wrapCatch(preparePayment);
function preparePayment(account: string, payment: Object, instructions = {}) {
return utils.promisify(preparePaymentAsync.bind(this))(
account, payment, instructions);
}
module.exports = preparePayment;

View File

@@ -1,7 +1,7 @@
/* @flow */
'use strict';
const _ = require('lodash');
const assert = require('assert');
const BigNumber = require('bignumber.js');
const utils = require('./utils');
const validate = utils.common.validate;
const AccountFlagIndices = utils.common.constants.AccountFlagIndices;
@@ -9,7 +9,7 @@ const AccountFields = utils.common.constants.AccountFields;
const Transaction = utils.common.core.Transaction;
// Emptry string passed to setting will clear it
const CLEAR_SETTING = '';
const CLEAR_SETTING = null;
function setTransactionFlags(transaction, values) {
const keys = Object.keys(values);
@@ -64,7 +64,7 @@ function setTransactionFields(transaction, input) {
*/
function convertTransferRate(transferRate) {
return _.isNumber(transferRate) ? transferRate * 1e9 : transferRate;
return (new BigNumber(transferRate)).shift(9).toNumber();
}
function createSettingsTransaction(account, settings) {
@@ -90,9 +90,14 @@ function createSettingsTransaction(account, settings) {
return transaction;
}
function prepareSettings(account, settings, instructions, callback) {
function prepareSettingsAsync(account, settings, instructions, callback) {
const transaction = createSettingsTransaction(account, settings);
utils.createTxJSON(transaction, this.remote, instructions, callback);
utils.prepareTransaction(transaction, this.remote, instructions, callback);
}
module.exports = utils.wrapCatch(prepareSettings);
function prepareSettings(account: string, settings: Object, instructions = {}) {
return utils.promisify(prepareSettingsAsync.bind(this))(
account, settings, instructions);
}
module.exports = prepareSettings;

View File

@@ -15,15 +15,13 @@ const validate = utils.common.validate;
* some arbitrary string. For example "TXN".
*/
const HASH_TX_ID = 0x54584E00; // 'TXN'
const HASH_TX_SIGN = 0x53545800; // 'STX'
const HASH_TX_SIGN_TESTNET = 0x73747800; // 'stx'
function getKeyPair(address, secret) {
return core.Seed.from_json(secret).get_key(address);
function getKeyPair(secret) {
return core.Seed.from_json(secret).get_key();
}
function getPublicKeyHex(keypair) {
return keypair.to_hex_pub();
return keypair.pubKeyHex();
}
function serialize(txJSON) {
@@ -34,31 +32,26 @@ function hashSerialization(serialized, prefix) {
return serialized.hash(prefix || HASH_TX_ID).to_hex();
}
function hashJSON(txJSON, prefix) {
return hashSerialization(serialize(txJSON), prefix);
}
function signingHash(txJSON, isTestNet=false) {
return hashJSON(txJSON, isTestNet ? HASH_TX_SIGN_TESTNET : HASH_TX_SIGN);
function signingData(txJSON) {
return core.Transaction.from_json(txJSON).signingData().buffer;
}
function computeSignature(txJSON, keypair) {
const signature = keypair.sign(signingHash(txJSON));
return core.sjcl.codec.hex.fromBits(signature).toUpperCase();
return keypair.signHex(signingData(txJSON));
}
function sign(txJSON: {Account: string; SigningPubKey: string,
TxnSignature: string}, secret: string):
{signedTransaction: string; id: string} {
validate.txJSON(txJSON);
validate.addressAndSecret({address: txJSON.Account, secret: secret});
function sign(txJSON: string, secret: string
): {signedTransaction: string; id: string} {
const tx = JSON.parse(txJSON);
validate.txJSON(tx);
validate.secret(secret);
const keypair = getKeyPair(txJSON.Account, secret);
if (txJSON.SigningPubKey === undefined) {
txJSON.SigningPubKey = getPublicKeyHex(keypair);
const keypair = getKeyPair(secret);
if (tx.SigningPubKey === undefined) {
tx.SigningPubKey = getPublicKeyHex(keypair);
}
txJSON.TxnSignature = computeSignature(txJSON, keypair);
const serialized = serialize(txJSON);
tx.TxnSignature = computeSignature(tx, keypair);
const serialized = serialize(tx);
return {
signedTransaction: serialized.to_hex(),
id: hashSerialization(serialized, HASH_TX_ID)

View File

@@ -1,15 +1,44 @@
/* @flow */
'use strict';
const _ = require('lodash');
const utils = require('./utils');
const validate = utils.common.validate;
const Request = utils.common.core.Request;
const convertErrors = utils.common.convertErrors;
function submit(tx_blob: string,
callback: (err: any, data: any) => void): void {
validate.blob(tx_blob);
function isImmediateRejection(engineResult) {
// note: "tel" errors mean the local server refused to process the
// transaction *at that time*, but it could potentially buffer the
// transaction and then process it at a later time, for example
// if the required fee changes (this does not occur at the time of
// this writing, but it could change in the future)
// all other error classes can potentially result in transcation validation
return _.startsWith(engineResult, 'tem') || _.startsWith(engineResult, 'tej');
}
function convertSubmitErrors(callback) {
return function(error, data) {
if (isImmediateRejection(data.engineResult)) {
callback(new utils.common.errors.RippleError('Submit failed'), data);
} else {
callback(error, data);
}
};
}
function submitAsync(txBlob: string, callback: (err: any, data: any) => void
): void {
validate.blob(txBlob);
const request = new Request(this.remote, 'submit');
request.message.tx_blob = tx_blob;
request.request(null, callback);
request.message.tx_blob = txBlob;
request.request(null,
utils.common.composeAsync(
data => utils.common.convertKeysFromSnakeCaseToCamelCase(data),
convertSubmitErrors(convertErrors(callback))));
}
function submit(txBlob: string) {
return utils.promisify(submitAsync.bind(this))(txBlob);
}
module.exports = submit;

View File

@@ -0,0 +1,40 @@
/* @flow */
'use strict';
const _ = require('lodash');
const utils = require('./utils');
const validate = utils.common.validate;
const Transaction = utils.common.core.Transaction;
function createSuspendedPaymentCancellationTransaction(account, payment) {
validate.address(account);
validate.suspendedPaymentCancellation(payment);
const transaction = new Transaction();
transaction.suspendedPaymentCancel({
account: account,
owner: payment.owner,
paymentSequence: payment.paymentSequence
});
if (payment.memos) {
_.forEach(payment.memos, memo =>
transaction.addMemo(memo.type, memo.format, memo.data)
);
}
return transaction;
}
function prepareSuspendedPaymentCancellationAsync(account, payment,
instructions, callback) {
const transaction =
createSuspendedPaymentCancellationTransaction(account, payment);
utils.prepareTransaction(transaction, this.remote, instructions, callback);
}
function prepareSuspendedPaymentCancellation(account: string, payment: Object,
instructions = {}) {
return utils.promisify(prepareSuspendedPaymentCancellationAsync)
.call(this, account, payment, instructions);
}
module.exports = prepareSuspendedPaymentCancellation;

View File

@@ -0,0 +1,57 @@
/* @flow */
'use strict';
const _ = require('lodash');
const utils = require('./utils');
const validate = utils.common.validate;
const toRippledAmount = utils.common.toRippledAmount;
const Transaction = utils.common.core.Transaction;
function createSuspendedPaymentCreationTransaction(account, payment) {
validate.address(account);
validate.suspendedPaymentCreation(payment);
const transaction = new Transaction();
transaction.suspendedPaymentCreate({
account: account,
destination: payment.destination.address,
amount: toRippledAmount(payment.destination.amount)
});
if (payment.digest) {
transaction.setDigest(payment.digest);
}
if (payment.allowCancelAfter) {
transaction.setAllowCancelAfter(payment.allowCancelAfter);
}
if (payment.allowExecuteAfter) {
transaction.setAllowExecuteAfter(payment.allowExecuteAfter);
}
if (payment.source.tag) {
transaction.sourceTag(payment.source.tag);
}
if (payment.destination.tag) {
transaction.destinationTag(payment.destination.tag);
}
if (payment.memos) {
_.forEach(payment.memos, memo =>
transaction.addMemo(memo.type, memo.format, memo.data)
);
}
return transaction;
}
function prepareSuspendedPaymentCreationAsync(account, payment, instructions,
callback) {
const transaction =
createSuspendedPaymentCreationTransaction(account, payment);
utils.prepareTransaction(transaction, this.remote, instructions, callback);
}
function prepareSuspendedPaymentCreation(account: string, payment: Object,
instructions = {}) {
return utils.promisify(prepareSuspendedPaymentCreationAsync)
.call(this, account, payment, instructions);
}
module.exports = prepareSuspendedPaymentCreation;

View File

@@ -0,0 +1,50 @@
/* @flow */
'use strict';
const _ = require('lodash');
const utils = require('./utils');
const validate = utils.common.validate;
const Transaction = utils.common.core.Transaction;
function createSuspendedPaymentExecutionTransaction(account, payment) {
validate.address(account);
validate.suspendedPaymentExecution(payment);
const transaction = new Transaction();
transaction.suspendedPaymentFinish({
account: account,
owner: payment.owner,
paymentSequence: payment.paymentSequence
});
if (payment.method) {
transaction.setMethod(payment.method);
}
if (payment.digest) {
transaction.setDigest(payment.digest);
}
if (payment.proof) {
transaction.setProof(payment.proof);
}
if (payment.memos) {
_.forEach(payment.memos, memo =>
transaction.addMemo(memo.type, memo.format, memo.data)
);
}
return transaction;
}
function prepareSuspendedPaymentExecutionAsync(account, payment, instructions,
callback) {
const transaction =
createSuspendedPaymentExecutionTransaction(account, payment);
utils.prepareTransaction(transaction, this.remote, instructions, callback);
}
function prepareSuspendedPaymentExecution(account: string, payment: Object,
instructions = {}) {
return utils.promisify(prepareSuspendedPaymentExecutionAsync)
.call(this, account, payment, instructions);
}
module.exports = prepareSuspendedPaymentExecution;

View File

@@ -3,13 +3,19 @@
const utils = require('./utils');
const validate = utils.common.validate;
const Transaction = utils.common.core.Transaction;
const BigNumber = require('bignumber.js');
const TrustSetFlags = {
authorized: {set: 'SetAuth'},
allowRippling: {set: 'ClearNoRipple', unset: 'NoRipple'},
ripplingDisabled: {set: 'NoRipple', unset: 'ClearNoRipple'},
frozen: {set: 'SetFreeze', unset: 'ClearFreeze'}
};
function convertQuality(quality) {
return quality === undefined ? undefined :
(new BigNumber(quality)).shift(9).truncated().toNumber();
}
function createTrustlineTransaction(account, trustline) {
validate.address(account);
validate.trustline(trustline);
@@ -21,15 +27,21 @@ function createTrustlineTransaction(account, trustline) {
};
const transaction = new Transaction();
transaction.trustSet(account, limit,
trustline.qualityIn, trustline.qualityOut);
transaction.trustSet(account, limit, convertQuality(trustline.qualityIn),
convertQuality(trustline.qualityOut));
utils.setTransactionBitFlags(transaction, trustline, TrustSetFlags);
return transaction;
}
function prepareTrustline(account, trustline, instructions, callback) {
function prepareTrustlineAsync(account, trustline, instructions, callback) {
const transaction = createTrustlineTransaction(account, trustline);
utils.createTxJSON(transaction, this.remote, instructions, callback);
utils.prepareTransaction(transaction, this.remote, instructions, callback);
}
module.exports = utils.wrapCatch(prepareTrustline);
function prepareTrustline(account: string, trustline: Object, instructions = {}
) {
return utils.promisify(prepareTrustlineAsync.bind(this))(
account, trustline, instructions);
}
module.exports = prepareTrustline;

View File

@@ -1,10 +1,11 @@
/* @flow */
'use strict';
const _ = require('lodash');
const BigNumber = require('bignumber.js');
const common = require('../common');
function setTransactionBitFlags(transaction: any, values: any, flags: any):
void {
function setTransactionBitFlags(transaction: any, values: any, flags: any
): void {
for (const flagName in flags) {
const flagValue = values[flagName];
const flagConversions = flags[flagName];
@@ -23,8 +24,22 @@ function getFeeDrops(remote) {
return remote.feeTx(feeUnits).to_text();
}
function createTxJSON(transaction: any, remote: any, instructions: any,
callback: (err: ?(typeof Error), data: {tx_json: any}) => void): void {
function formatPrepareResponse(txJSON) {
const instructions = {
fee: txJSON.Fee,
sequence: txJSON.Sequence,
maxLedgerVersion: txJSON.LastLedgerSequence
};
return {
txJSON: JSON.stringify(txJSON),
instructions: _.omit(instructions, _.isUndefined)
};
}
type Callback = (err: ?(typeof Error),
data: {txJSON: string, instructions: any}) => void;
function prepareTransaction(transaction: any, remote: any, instructions: any,
callback: Callback): void {
common.validate.instructions(instructions);
transaction.complete();
@@ -53,18 +68,18 @@ function createTxJSON(transaction: any, remote: any, instructions: any,
if (instructions.sequence !== undefined) {
txJSON.Sequence = parseInt(instructions.sequence, 10);
callback(null, txJSON);
callback(null, formatPrepareResponse(txJSON));
} else {
remote.findAccount(account).getNextSequence(function(error, sequence) {
txJSON.Sequence = sequence;
callback(null, txJSON);
callback(error, formatPrepareResponse(txJSON));
});
}
}
module.exports = {
setTransactionBitFlags: setTransactionBitFlags,
createTxJSON: createTxJSON,
wrapCatch: common.wrapCatch,
common: common
setTransactionBitFlags,
prepareTransaction,
common,
promisify: common.promisify
};

View File

@@ -12,13 +12,14 @@
const _ = require('lodash');
const async = require('async');
const util = require('util');
const extend = require('extend');
const EventEmitter = require('events').EventEmitter;
const UInt160 = require('./uint160').UInt160;
const TransactionManager = require('./transactionmanager').TransactionManager;
const sjcl = require('./utils').sjcl;
const Base = require('./base').Base;
const util = require('util');
const {createAccountID} = require('ripple-keypairs');
const {encodeAccountID} = require('ripple-address-codec');
const {EventEmitter} = require('events');
const {hexToArray} = require('./utils');
const {TransactionManager} = require('./transactionmanager');
const {UInt160} = require('./uint160');
/**
* @constructor Account
@@ -41,7 +42,7 @@ function Account(remote, account) {
this._entry = { };
function listenerAdded(type) {
if (~Account.subscribeEvents.indexOf(type)) {
if (_.includes(Account.subscribeEvents, type)) {
if (!self._subs && self._remote._connected) {
self._remote.requestSubscribe()
.addAccount(self._account_id)
@@ -54,7 +55,7 @@ function Account(remote, account) {
this.on('newListener', listenerAdded);
function listenerRemoved(type) {
if (~Account.subscribeEvents.indexOf(type)) {
if (_.includes(Account.subscribeEvents, type)) {
self._subs -= 1;
if (!self._subs && self._remote._connected) {
self._remote.requestUnsubscribe()
@@ -68,7 +69,7 @@ function Account(remote, account) {
function attachAccount(request) {
if (self._account.is_valid() && self._subs) {
request.add_account(self._account_id);
request.addAccount(self._account_id);
}
}
@@ -376,12 +377,7 @@ Account.prototype.publicKeyIsActive = function(public_key, callback) {
Account._publicKeyToAddress = function(public_key) {
// Based on functions in /src/js/ripple/keypair.js
function hexToUInt160(publicKey) {
const bits = sjcl.codec.hex.toBits(publicKey);
const hash = sjcl.hash.ripemd160.hash(sjcl.hash.sha256.hash(bits));
const address = UInt160.from_bits(hash);
address.set_version(Base.VER_ACCOUNT_ID);
return address.to_json();
return encodeAccountID(createAccountID(hexToArray(publicKey)));
}
if (UInt160.is_valid(public_key)) {

View File

@@ -49,13 +49,13 @@ const consts = {
// Maximum possible amount for non-XRP currencies using the maximum mantissa
// with maximum exponent. Corresponds to hex 0xEC6386F26FC0FFFF.
max_value: '9999999999999999e80',
// Minimum possible amount for non-XRP currencies.
min_value: '-1000000000000000e-96'
// Minimum nonzero absolute value for non-XRP currencies.
min_value: '1000000000000000e-96'
};
const MAX_XRP_VALUE = new XRPValue(1e11);
const MAX_IOU_VALUE = new IOUValue(consts.max_value);
const MIN_IOU_VALUE = new IOUValue(consts.min_value).abs();
const MIN_IOU_VALUE = new IOUValue(consts.min_value);
const bi_xns_unit = new IOUValue(1e6);
@@ -105,6 +105,19 @@ Amount.NaN = function() {
return result; // but let's be careful
};
Amount.from_components_unsafe = function(value: Value, currency: Currency,
issuer: UInt160, isNative: boolean
) {
const result = new Amount(value);
result._is_native = isNative;
result._currency = currency;
result._issuer = issuer;
result._value = value.isZero() && value.isNegative() ?
value.negate() : value;
return result;
};
// be sure that _is_native is set properly BEFORE calling _set_value
Amount.prototype._set_value = function(value: Value) {
@@ -122,27 +135,30 @@ Amount.prototype.abs = function() {
};
Amount.prototype.add = function(addend) {
const addendAmount = Amount.from_json(addend);
const addendAmount = addend instanceof Amount ?
addend : Amount.from_json(addend);
if (!this.is_comparable(addendAmount)) {
return new Amount();
}
return this._copy(this._value.add(addendAmount._value));
};
Amount.prototype.subtract = function(subtrahend) {
// Correctness over speed, less code has less bugs, reuse add code.
return this.add(Amount.from_json(subtrahend).negate());
const subsAmount = subtrahend instanceof Amount ?
subtrahend : Amount.from_json(subtrahend);
return this.add(subsAmount.negate());
};
// XXX Diverges from cpp.
Amount.prototype.multiply = function(multiplicand) {
const multiplicandValue = multiplicand instanceof Amount ?
multiplicand._value :
Amount.from_json(multiplicand)._value;
const multiplicandAmount = Amount.from_json(multiplicand);
return this._copy(this._value.multiply(multiplicandAmount._value));
return this._copy(this._value.multiply(multiplicandValue));
};
@@ -151,9 +167,11 @@ Amount.prototype.scale = function(scaleFactor) {
};
Amount.prototype.divide = function(divisor) {
const divisorAmount = Amount.from_json(divisor);
const divisorValue = divisor instanceof Amount ?
divisor._value :
Amount.from_json(divisor)._value;
return this._copy(this._value.divide(divisorAmount._value));
return this._copy(this._value.divide(divisorValue));
};
/**
@@ -344,7 +362,7 @@ Amount.prototype._check_limits = function() {
};
Amount.prototype.clone = function(negate) {
return this.copyTo(new Amount(), negate);
return this.copyTo(new Amount(this._value), negate);
};
Amount.prototype._copy = function(value) {
@@ -354,9 +372,10 @@ Amount.prototype._copy = function(value) {
};
Amount.prototype.compareTo = function(to) {
const toAmount = Amount.from_json(to);
const toAmount = to instanceof Amount ? to : Amount.from_json(to);
if (!this.is_comparable(toAmount)) {
return new Amount();
throw new Error('Not comparable');
}
return this._value.comparedTo(toAmount._value);
};
@@ -730,6 +749,14 @@ Amount.prototype.to_number = function() {
return Number(this.to_text());
};
// this one is needed because Value.abs creates new BigNumber,
// and BigNumber constructor is very slow, so we want to
// call it only if absolutely necessary
function absValue(value: Value): Value {
return value.isNegative() ? value.abs() : value;
}
// Convert only value to JSON wire format.
Amount.prototype.to_text = function() {
if (!this.is_valid()) {
@@ -743,8 +770,8 @@ Amount.prototype.to_text = function() {
// not native
const offset = this._value.getExponent() - 15;
const sign = this._value.isNegative() ? '-' : '';
const mantissa = utils.getMantissa16FromString(
this._value.abs().toString());
const mantissa =
utils.getMantissa16FromString(absValue(this._value).toString());
if (offset !== 0 && (offset < -25 || offset > -4)) {
// Use e notation.
// XXX Clamp output.

View File

@@ -18,17 +18,24 @@ function assertValidLegOneOffer(legOneOffer, message) {
}
function AutobridgeCalculator(currencyGets, currencyPays,
legOneOffers, legTwoOffers, issuerGets, issuerPays) {
legOneOffers, legTwoOffers, issuerGets, issuerPays
) {
this._currencyGets = currencyGets;
this._currencyPays = currencyPays;
this._currencyGetsHex = currencyGets.to_hex();
this._currencyPaysHex = currencyPays.to_hex();
this._issuerGets = issuerGets;
this._issuerGetsObj = UInt160.from_json(issuerGets);
this._issuerPays = issuerPays;
this._issuerPaysObj = UInt160.from_json(issuerPays);
this.legOneOffers = _.cloneDeep(legOneOffers);
this.legTwoOffers = _.cloneDeep(legTwoOffers);
this._ownerFundsLeftover = {};
}
const NULL_AMOUNT = Utils.normalizeAmount('0');
/**
* Calculates an ordered array of autobridged offers by quality
*
@@ -36,10 +43,13 @@ function AutobridgeCalculator(currencyGets, currencyPays,
*/
AutobridgeCalculator.prototype.calculate = function() {
const oldMode = Amount.strict_mode;
Amount.strict_mode = false;
let legOnePointer = 0;
let legTwoPointer = 0;
let offersAutobridged = [];
const offersAutobridged = [];
this.clearOwnerFundsLeftover();
@@ -55,8 +65,10 @@ AutobridgeCalculator.prototype.calculate = function() {
this.adjustLegOneFundedAmount(legOneOffer);
}
const legOneTakerGetsFunded = Utils.getOfferTakerGetsFunded(legOneOffer);
const legTwoTakerPaysFunded = Utils.getOfferTakerPaysFunded(legTwoOffer);
const legOneTakerGetsFunded = Utils.getOfferTakerGetsFunded(legOneOffer,
this._currencyPays, this._issuerPaysObj);
const legTwoTakerPaysFunded = Utils.getOfferTakerPaysFunded(legTwoOffer,
this._currencyGets, this._issuerGetsObj);
if (legOneTakerGetsFunded.is_zero()) {
legOnePointer++;
@@ -70,14 +82,17 @@ AutobridgeCalculator.prototype.calculate = function() {
continue;
}
if (legOneTakerGetsFunded.compareTo(legTwoTakerPaysFunded) > 0) {
// using private fields for speed
if (legOneTakerGetsFunded._value.comparedTo(
legTwoTakerPaysFunded._value) > 0) {
autobridgedOffer = this.getAutobridgedOfferWithClampedLegOne(
legOneOffer,
legTwoOffer
);
legTwoPointer++;
} else if (legTwoTakerPaysFunded.compareTo(legOneTakerGetsFunded) > 0) {
} else if (legTwoTakerPaysFunded._value.comparedTo(
legOneTakerGetsFunded._value) > 0) {
autobridgedOffer = this.getAutobridgedOfferWithClampedLegTwo(
legOneOffer,
legTwoOffer
@@ -97,6 +112,7 @@ AutobridgeCalculator.prototype.calculate = function() {
offersAutobridged.push(autobridgedOffer);
}
Amount.strict_mode = oldMode;
return offersAutobridged;
};
@@ -112,15 +128,20 @@ AutobridgeCalculator.prototype.calculate = function() {
AutobridgeCalculator.prototype.getAutobridgedOfferWithClampedLegOne =
function(legOneOffer, legTwoOffer) {
const legOneTakerGetsFunded = Utils.getOfferTakerGetsFunded(legOneOffer);
const legTwoTakerPaysFunded = Utils.getOfferTakerPaysFunded(legTwoOffer);
const legOneQuality = Utils.getOfferQuality(legOneOffer, this._currencyGets);
const legOneTakerGetsFunded = Utils.getOfferTakerGetsFunded(legOneOffer,
this._currencyPays, this._issuerPaysObj);
const legTwoTakerPaysFunded = Utils.getOfferTakerPaysFunded(legTwoOffer,
this._currencyGets, this._issuerGetsObj);
const legOneQuality = Utils.getOfferQuality(legOneOffer, this._currencyGets,
this._currencyPays, this._issuerPaysObj);
const autobridgedTakerGets = Utils.getOfferTakerGetsFunded(legTwoOffer);
const autobridgedTakerGets = Utils.getOfferTakerGetsFunded(legTwoOffer,
this._currencyGets, this._issuerGetsObj);
const autobridgedTakerPays = legTwoTakerPaysFunded.multiply(legOneQuality);
if (legOneOffer.Account === legTwoOffer.Account) {
const legOneTakerGets = Utils.getOfferTakerGets(legOneOffer);
const legOneTakerGets = Utils.getOfferTakerGets(legOneOffer,
this._currencyPays, this._issuerPaysObj);
const updatedTakerGets = legOneTakerGets.subtract(legTwoTakerPaysFunded);
this.setLegOneTakerGets(legOneOffer, updatedTakerGets);
@@ -152,15 +173,20 @@ function(legOneOffer, legTwoOffer) {
AutobridgeCalculator.prototype.getAutobridgedOfferWithClampedLegTwo =
function(legOneOffer, legTwoOffer) {
const legOneTakerGetsFunded = Utils.getOfferTakerGetsFunded(legOneOffer);
const legTwoTakerPaysFunded = Utils.getOfferTakerPaysFunded(legTwoOffer);
const legTwoQuality = Utils.getOfferQuality(legTwoOffer, this._currencyGets);
const legOneTakerGetsFunded = Utils.getOfferTakerGetsFunded(legOneOffer,
this._currencyPays, this._issuerPaysObj);
const legTwoTakerPaysFunded = Utils.getOfferTakerPaysFunded(legTwoOffer,
this._currencyGets, this._issuerGetsObj);
const legTwoQuality = Utils.getOfferQuality(legTwoOffer, this._currencyGets,
this._currencyGets, this._issuerGetsObj);
const autobridgedTakerGets = legOneTakerGetsFunded.divide(legTwoQuality);
const autobridgedTakerPays = Utils.getOfferTakerPaysFunded(legOneOffer);
const autobridgedTakerPays = Utils.getOfferTakerPaysFunded(legOneOffer,
this._currencyPays, this._issuerPaysObj);
// Update funded amount since leg two offer was not completely consumed
legTwoOffer.taker_gets_funded = Utils.getOfferTakerGetsFunded(legTwoOffer)
legTwoOffer.taker_gets_funded = Utils.getOfferTakerGetsFunded(legTwoOffer,
this._currencyGets, this._issuerGetsObj)
.subtract(autobridgedTakerGets)
.to_text();
legTwoOffer.taker_pays_funded = legTwoTakerPaysFunded
@@ -184,8 +210,10 @@ function(legOneOffer, legTwoOffer) {
AutobridgeCalculator.prototype.getAutobridgedOfferWithoutClamps =
function(legOneOffer, legTwoOffer) {
const autobridgedTakerGets = Utils.getOfferTakerGetsFunded(legTwoOffer);
const autobridgedTakerPays = Utils.getOfferTakerPaysFunded(legOneOffer);
const autobridgedTakerGets = Utils.getOfferTakerGetsFunded(legTwoOffer,
this._currencyGets, this._issuerGetsObj);
const autobridgedTakerPays = Utils.getOfferTakerPaysFunded(legOneOffer,
this._currencyPays, this._issuerPaysObj);
return this.formatAutobridgedOffer(
autobridgedTakerGets,
@@ -210,9 +238,7 @@ AutobridgeCalculator.prototype.clearOwnerFundsLeftover = function() {
*/
AutobridgeCalculator.prototype.resetOwnerFundsLeftover = function(account) {
assert(UInt160.is_valid(account), 'Account is invalid');
this._ownerFundsLeftover[account] = Utils.normalizeAmount('0');
this._ownerFundsLeftover[account] = NULL_AMOUNT.clone();
return this._ownerFundsLeftover[account];
};
@@ -226,12 +252,10 @@ AutobridgeCalculator.prototype.resetOwnerFundsLeftover = function(account) {
*/
AutobridgeCalculator.prototype.getLeftoverOwnerFunds = function(account) {
assert(UInt160.is_valid(account), 'Account is invalid');
let amount = this._ownerFundsLeftover[account];
if (!amount) {
amount = Utils.normalizeAmount('0');
amount = NULL_AMOUNT.clone();
}
return amount;
@@ -248,7 +272,6 @@ AutobridgeCalculator.prototype.getLeftoverOwnerFunds = function(account) {
AutobridgeCalculator.prototype.addLeftoverOwnerFunds =
function(account, amount) {
assert(UInt160.is_valid(account), 'Account is invalid');
assert(amount instanceof Amount, 'Amount is invalid');
this._ownerFundsLeftover[account] = this.getLeftoverOwnerFunds(account)
@@ -266,7 +289,6 @@ function(account, amount) {
AutobridgeCalculator.prototype.setLeftoverOwnerFunds =
function(account, amount) {
assert(UInt160.is_valid(account), 'Account is invalid');
assert(amount instanceof Amount, 'Amount is invalid');
this._ownerFundsLeftover[account] = amount;
@@ -291,13 +313,13 @@ function(takerGets, takerPays) {
autobridgedOffer.TakerGets = {
value: takerGets.to_text(),
currency: this._currencyGets.to_hex(),
currency: this._currencyGetsHex,
issuer: this._issuerGets
};
autobridgedOffer.TakerPays = {
value: takerPays.to_text(),
currency: this._currencyPays.to_hex(),
currency: this._currencyPaysHex,
issuer: this._issuerPays
};
@@ -308,7 +330,9 @@ function(takerGets, takerPays) {
autobridgedOffer.autobridged = true;
autobridgedOffer.BookDirectory = Utils.convertOfferQualityToHex(quality);
autobridgedOffer.BookDirectory =
Utils.convertOfferQualityToHexFromText(autobridgedOffer.quality);
autobridgedOffer.qualityHex = autobridgedOffer.BookDirectory;
return autobridgedOffer;
};
@@ -325,11 +349,13 @@ function(takerGets, takerPays) {
AutobridgeCalculator.prototype.unclampLegOneOwnerFunds = function(legOneOffer) {
assertValidLegOneOffer(legOneOffer, 'Leg one offer is invalid');
legOneOffer.initTakerGetsFunded = Utils.getOfferTakerGetsFunded(legOneOffer);
legOneOffer.initTakerGetsFunded = Utils.getOfferTakerGetsFunded(legOneOffer,
this._currencyPays, this._issuerPaysObj);
this.setLegOneTakerGetsFunded(
legOneOffer,
Utils.getOfferTakerGets(legOneOffer)
Utils.getOfferTakerGets(legOneOffer, this._currencyPays,
this._issuerPaysObj)
);
};
@@ -350,7 +376,8 @@ AutobridgeCalculator.prototype.unclampLegOneOwnerFunds = function(legOneOffer) {
AutobridgeCalculator.prototype.clampLegOneOwnerFunds = function(legOneOffer) {
assertValidLegOneOffer(legOneOffer, 'Leg one offer is invalid');
const takerGets = Utils.getOfferTakerGets(legOneOffer);
const takerGets = Utils.getOfferTakerGets(legOneOffer, this._currencyPays,
this._issuerPaysObj);
if (takerGets.compareTo(legOneOffer.initTakerGetsFunded) > 0) {
// After clamping, TakerGets is still greater than initial funded amount
@@ -375,12 +402,16 @@ function(legOneOffer) {
assertValidLegOneOffer(legOneOffer, 'Leg one offer is invalid');
assert(!legOneOffer.is_fully_funded, 'Leg one offer cannot be fully funded');
const fundedSum = Utils.getOfferTakerGetsFunded(legOneOffer)
const fundedSum = Utils.getOfferTakerGetsFunded(legOneOffer,
this._currencyPays, this._issuerPaysObj)
.add(this.getLeftoverOwnerFunds(legOneOffer.Account));
if (fundedSum.compareTo(Utils.getOfferTakerGets(legOneOffer)) >= 0) {
if (fundedSum.compareTo(Utils.getOfferTakerGets(legOneOffer,
this._currencyPays, this._issuerPaysObj)) >= 0
) {
// There are enough extra funds to fully fund the offer
const legOneTakerGets = Utils.getOfferTakerGets(legOneOffer);
const legOneTakerGets = Utils.getOfferTakerGets(legOneOffer,
this._currencyPays, this._issuerPaysObj);
const updatedLeftover = fundedSum.subtract(legOneTakerGets);
this.setLegOneTakerGetsFunded(legOneOffer, legOneTakerGets);
@@ -407,8 +438,9 @@ function setLegOneTakerGetsFunded(legOneOffer, takerGetsFunded) {
legOneOffer.taker_gets_funded = takerGetsFunded.to_text();
legOneOffer.taker_pays_funded = takerGetsFunded
.multiply(Utils.getOfferQuality(legOneOffer, this._currencyGets))
.to_text();
.multiply(Utils.getOfferQuality(legOneOffer, this._currencyGets,
this._currencyPays, this._issuerPaysObj))
.to_text();
if (legOneOffer.taker_gets_funded === legOneOffer.TakerGets.value) {
legOneOffer.is_fully_funded = true;
@@ -428,10 +460,11 @@ function(legOneOffer, takerGets) {
assertValidLegOneOffer(legOneOffer, 'Leg one offer is invalid');
assert(takerGets instanceof Amount, 'Taker gets funded is invalid');
const legOneQuality = Utils.getOfferQuality(legOneOffer, this._currencyGets);
const legOneQuality = Utils.getOfferQuality(legOneOffer, this._currencyGets,
this._currencyPays, this._issuerPaysObj);
legOneOffer.TakerGets = takerGets.to_text();
legOneOffer.TakerPays = takerGets.multiply(legOneQuality);
legOneOffer.TakerPays = takerGets.multiply(legOneQuality).to_json();
};
module.exports = AutobridgeCalculator;

View File

@@ -1,18 +1,11 @@
'use strict';
const _ = require('lodash');
const sjcl = require('./utils').sjcl;
const utils = require('./utils');
const BN = require('bn.js');
const extend = require('extend');
const convertBase = require('./baseconverter');
const {encode, decode} = require('ripple-address-codec');
const Base = {};
const alphabets = Base.alphabets = {
ripple: 'rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz',
tipple: 'RPShNAF39wBUDnEGHJKLM4pQrsT7VWXYZ2bcdeCg65jkm8ofqi1tuvaxyz',
bitcoin: '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
};
extend(Base, {
VER_NONE: 1,
VER_NODE_PUBLIC: 28,
@@ -21,134 +14,44 @@ extend(Base, {
VER_ACCOUNT_PUBLIC: 35,
VER_ACCOUNT_PRIVATE: 34,
VER_FAMILY_GENERATOR: 41,
VER_FAMILY_SEED: 33
});
function sha256(bytes) {
return sjcl.codec.bytes.fromBits(
sjcl.hash.sha256.hash(sjcl.codec.bytes.toBits(bytes)));
}
function encodeString(alphabet, input) {
if (input.length === 0) {
return '';
}
const leadingZeros = _.takeWhile(input, function(d) {
return d === 0;
});
const out = convertBase(input, 256, 58).map(function(digit) {
if (digit < 0 || digit >= alphabet.length) {
throw new Error('Value ' + digit + ' is out of bounds for encoding');
}
return alphabet[digit];
});
const prefix = leadingZeros.map(function() {
return alphabet[0];
});
return prefix.concat(out).join('');
}
function decodeString(indexes, input) {
if (input.length === 0) {
return [];
}
const input58 = input.split('').map(function(c) {
const charCode = c.charCodeAt(0);
if (charCode >= indexes.length || indexes[charCode] === -1) {
throw new Error('Character ' + c + ' is not valid for encoding');
}
return indexes[charCode];
});
const leadingZeros = _.takeWhile(input58, function(d) {
return d === 0;
});
const out = convertBase(input58, 58, 256);
return leadingZeros.concat(out);
}
function Base58(alphabet) {
const indexes = utils.arraySet(128, -1);
for (let i = 0; i < alphabet.length; i++) {
indexes[alphabet.charCodeAt(i)] = i;
}
return {
decode: decodeString.bind(null, indexes),
encode: encodeString.bind(null, alphabet)
};
}
Base.encoders = {};
Object.keys(alphabets).forEach(function(alphabet) {
Base.encoders[alphabet] = new Base58(alphabets[alphabet]);
VER_FAMILY_SEED: 33,
VER_ED25519_SEED: [0x01, 0xE1, 0x4B]
});
// --> input: big-endian array of bytes.
// <-- string at least as long as input.
Base.encode = function(input, alpha) {
return this.encoders[alpha || 'ripple'].encode(input);
Base.encode = function(input, alphabet) {
return encode(input, {alphabet});
};
// --> input: String
// <-- array of bytes or undefined.
Base.decode = function(input, alpha) {
Base.decode = function(input, alphabet) {
if (typeof input !== 'string') {
return undefined;
}
try {
return this.encoders[alpha || 'ripple'].decode(input);
return decode(input, {alphabet});
} catch (e) {
return undefined;
}
};
Base.verify_checksum = function(bytes) {
const computed = sha256(sha256(bytes.slice(0, -4))).slice(0, 4);
const checksum = bytes.slice(-4);
return _.isEqual(computed, checksum);
};
// --> input: Array
// <-- String
Base.encode_check = function(version, input, alphabet) {
const buffer = [].concat(version, input);
const check = sha256(sha256(buffer)).slice(0, 4);
return Base.encode([].concat(buffer, check), alphabet);
return encode(input, {version, alphabet});
};
// --> input : String
// <-- NaN || sjcl.bn
// <-- NaN || BN
Base.decode_check = function(version, input, alphabet) {
const buffer = Base.decode(input, alphabet);
if (!buffer || buffer.length < 5) {
try {
const decoded = decode(input, {version, alphabet});
return new BN(decoded);
} catch (e) {
return NaN;
}
// Single valid version
if (typeof version === 'number' && buffer[0] !== version) {
return NaN;
}
// Multiple allowed versions
if (Array.isArray(version) && _.every(version, function(v) {
return v !== buffer[0];
})) {
return NaN;
}
if (!Base.verify_checksum(buffer)) {
return NaN;
}
// We'll use the version byte to add a leading zero, this ensures JSBN doesn't
// intrepret the value as a negative number
buffer[0] = 0;
return sjcl.bn.fromBits(
sjcl.codec.bytes.toBits(buffer.slice(0, -4)));
};
exports.Base = Base;

View File

@@ -1,28 +1,41 @@
'use strict';
function normalize(digitArray) {
while (digitArray[0] === 0) {
digitArray.shift();
let i = 0;
while (digitArray[i] === 0) {
++i;
}
if (i > 0) {
digitArray.splice(0, i);
}
return digitArray;
}
function divmod(digitArray, base, divisor) {
var remainder = 0;
var quotient = [];
for (var j = 0; j < digitArray.length; j++) {
var temp = remainder * base + parseInt(digitArray[j], 10);
quotient.push(Math.floor(temp / divisor));
let remainder = 0;
let temp;
let divided;
let j = -1;
const length = digitArray.length;
const quotient = new Array(length);
while (++j < length) {
temp = remainder * base + digitArray[j];
divided = temp / divisor;
quotient[j] = divided << 0;
remainder = temp % divisor;
}
return {quotient: normalize(quotient), remainder: remainder};
}
function convertBase(digitArray, fromBase, toBase) {
var result = [];
var dividend = digitArray;
const result = [];
let dividend = digitArray;
let qr;
while (dividend.length > 0) {
var qr = divmod(dividend, fromBase, toBase);
qr = divmod(dividend, fromBase, toBase);
result.unshift(qr.remainder);
dividend = qr.quotient;
}

View File

@@ -1,6 +1,8 @@
'use strict';
/*eslint no-multi-spaces:0,space-in-brackets:0,key-spacing:0,comma-spacing:0*/
/*eslint-disable max-len,spaced-comment,array-bracket-spacing,key-spacing*/
/*eslint-disable no-multi-spaces,comma-spacing*/
/*eslint-disable no-multi-spaces:0,space-in-brackets:0,key-spacing:0,comma-spacing:0*/
/**
* Data type map.
@@ -52,7 +54,8 @@ const FIELDS_MAP = exports.fields = {
// Common types
1: { // Int16
1: 'LedgerEntryType',
2: 'TransactionType'
2: 'TransactionType',
3: 'SignerWeight'
},
2: { // Int32
2: 'Flags',
@@ -87,7 +90,11 @@ const FIELDS_MAP = exports.fields = {
31: 'ReserveBase',
32: 'ReserveIncrement',
33: 'SetFlag',
34: 'ClearFlag'
34: 'ClearFlag',
35: 'SignerQuorum',
36: 'CancelAfter',
37: 'FinishAfter',
38: 'SignerListID'
},
3: { // Int64
1: 'IndexNext',
@@ -116,7 +123,8 @@ const FIELDS_MAP = exports.fields = {
17: 'InvoiceID',
18: 'Nickname',
19: 'Amendment',
20: 'TicketID'
20: 'TicketID',
21: 'Digest'
},
6: { // Amount
1: 'Amount',
@@ -146,7 +154,8 @@ const FIELDS_MAP = exports.fields = {
11: 'CreateCode',
12: 'MemoType',
13: 'MemoData',
14: 'MemoFormat'
14: 'MemoFormat',
17: 'Proof'
},
8: { // Account
1: 'Account',
@@ -166,13 +175,15 @@ const FIELDS_MAP = exports.fields = {
7: 'FinalFields',
8: 'NewFields',
9: 'TemplateEntry',
10: 'Memo'
10: 'Memo',
11: 'SignerEntry',
16: 'Signer'
},
15: { // Array
1: undefined, // end of Array
2: 'SigningAccounts',
3: 'TxnSignatures',
4: 'Signatures',
3: 'Signers',
4: 'SignerEntries',
5: 'Template',
6: 'Necessary',
7: 'Sufficient',
@@ -183,7 +194,7 @@ const FIELDS_MAP = exports.fields = {
// Uncommon types
16: { // Int8
1: 'CloseResolution',
2: 'TemplateEntryType',
2: 'Method',
3: 'TransactionResult'
},
17: { // Hash160
@@ -202,17 +213,17 @@ const FIELDS_MAP = exports.fields = {
}
};
let INVERSE_FIELDS_MAP = exports.fieldsInverseMap = { };
const INVERSE_FIELDS_MAP = exports.fieldsInverseMap = { };
Object.keys(FIELDS_MAP).forEach(function(k1) {
Object.keys(FIELDS_MAP[k1]).forEach(function(k2) {
INVERSE_FIELDS_MAP[FIELDS_MAP[k1][k2]] = [ Number(k1), Number(k2) ];
INVERSE_FIELDS_MAP[FIELDS_MAP[k1][k2]] = [Number(k1), Number(k2)];
});
});
const REQUIRED = exports.REQUIRED = 0,
OPTIONAL = exports.OPTIONAL = 1,
DEFAULT = exports.DEFAULT = 2;
const REQUIRED = exports.REQUIRED = 0;
const OPTIONAL = exports.OPTIONAL = 1;
const DEFAULT = exports.DEFAULT = 2;
const base = [
[ 'TransactionType' , REQUIRED ],
@@ -226,76 +237,100 @@ const base = [
[ 'SigningPubKey' , REQUIRED ],
[ 'TxnSignature' , OPTIONAL ],
[ 'AccountTxnID' , OPTIONAL ],
[ 'Memos' , OPTIONAL ]
[ 'Memos' , OPTIONAL ],
[ 'Signers' , OPTIONAL ]
];
exports.tx = {
AccountSet: [3].concat(base, [
[ 'EmailHash' , OPTIONAL ],
[ 'WalletLocator' , OPTIONAL ],
[ 'WalletSize' , OPTIONAL ],
[ 'MessageKey' , OPTIONAL ],
[ 'Domain' , OPTIONAL ],
[ 'TransferRate' , OPTIONAL ],
[ 'SetFlag' , OPTIONAL ],
[ 'ClearFlag' , OPTIONAL ]
['EmailHash' , OPTIONAL],
['WalletLocator' , OPTIONAL],
['WalletSize' , OPTIONAL],
['MessageKey' , OPTIONAL],
['Domain' , OPTIONAL],
['TransferRate' , OPTIONAL],
['SetFlag' , OPTIONAL],
['ClearFlag' , OPTIONAL]
]),
TrustSet: [20].concat(base, [
[ 'LimitAmount' , OPTIONAL ],
[ 'QualityIn' , OPTIONAL ],
[ 'QualityOut' , OPTIONAL ]
['LimitAmount' , OPTIONAL],
['QualityIn' , OPTIONAL],
['QualityOut' , OPTIONAL]
]),
OfferCreate: [7].concat(base, [
[ 'TakerPays' , REQUIRED ],
[ 'TakerGets' , REQUIRED ],
[ 'Expiration' , OPTIONAL ],
[ 'OfferSequence' , OPTIONAL ]
['TakerPays' , REQUIRED],
['TakerGets' , REQUIRED],
['Expiration' , OPTIONAL],
['OfferSequence' , OPTIONAL]
]),
OfferCancel: [8].concat(base, [
[ 'OfferSequence' , REQUIRED ]
['OfferSequence' , REQUIRED]
]),
SetRegularKey: [5].concat(base, [
[ 'RegularKey' , OPTIONAL ]
['RegularKey' , OPTIONAL]
]),
Payment: [0].concat(base, [
[ 'Destination' , REQUIRED ],
[ 'Amount' , REQUIRED ],
[ 'SendMax' , OPTIONAL ],
[ 'Paths' , DEFAULT ],
[ 'InvoiceID' , OPTIONAL ],
[ 'DestinationTag' , OPTIONAL ]
['Destination' , REQUIRED],
['Amount' , REQUIRED],
['SendMax' , OPTIONAL],
['Paths' , DEFAULT],
['InvoiceID' , OPTIONAL],
['DestinationTag' , OPTIONAL]
]),
Contract: [9].concat(base, [
[ 'Expiration' , REQUIRED ],
[ 'BondAmount' , REQUIRED ],
[ 'StampEscrow' , REQUIRED ],
[ 'RippleEscrow' , REQUIRED ],
[ 'CreateCode' , OPTIONAL ],
[ 'FundCode' , OPTIONAL ],
[ 'RemoveCode' , OPTIONAL ],
[ 'ExpireCode' , OPTIONAL ]
['Expiration' , REQUIRED],
['BondAmount' , REQUIRED],
['StampEscrow' , REQUIRED],
['RippleEscrow' , REQUIRED],
['CreateCode' , OPTIONAL],
['FundCode' , OPTIONAL],
['RemoveCode' , OPTIONAL],
['ExpireCode' , OPTIONAL]
]),
RemoveContract: [10].concat(base, [
[ 'Target' , REQUIRED ]
['Target' , REQUIRED]
]),
EnableFeature: [100].concat(base, [
[ 'Feature' , REQUIRED ]
['Feature' , REQUIRED]
]),
EnableAmendment: [100].concat(base, [
[ 'Amendment' , REQUIRED ]
['Amendment' , REQUIRED]
]),
SetFee: [101].concat(base, [
[ 'BaseFee' , REQUIRED ],
[ 'ReferenceFeeUnits' , REQUIRED ],
[ 'ReserveBase' , REQUIRED ],
[ 'ReserveIncrement' , REQUIRED ]
['BaseFee' , REQUIRED],
['ReferenceFeeUnits' , REQUIRED],
['ReserveBase' , REQUIRED],
['ReserveIncrement' , REQUIRED]
]),
TicketCreate: [10].concat(base, [
[ 'Target' , OPTIONAL ],
[ 'Expiration' , OPTIONAL ]
['Target' , OPTIONAL],
['Expiration' , OPTIONAL]
]),
TicketCancel: [11].concat(base, [
[ 'TicketID' , REQUIRED ]
['TicketID' , REQUIRED]
]),
SignerListSet: [12].concat(base, [
['SignerQuorum', REQUIRED],
['SignerEntries', OPTIONAL]
]),
SuspendedPaymentCreate: [1].concat(base, [
['Destination' , REQUIRED],
['Amount' , REQUIRED],
['Digest' , OPTIONAL],
['CancelAfter' , OPTIONAL],
['FinishAfter' , OPTIONAL],
['DestinationTag' , OPTIONAL]
]),
SuspendedPaymentFinish: [2].concat(base, [
['Owner' , REQUIRED],
['OfferSequence' , REQUIRED],
['Method' , OPTIONAL],
['Digest' , OPTIONAL],
['Proof' , OPTIONAL]
]),
SuspendedPaymentCancel: [4].concat(base, [
['Owner' , REQUIRED],
['OfferSequence' , REQUIRED]
])
};
@@ -396,13 +431,22 @@ exports.ledger = {
['LedgerIndex', OPTIONAL],
['Balance', REQUIRED],
['LowLimit', REQUIRED],
['HighLimit', REQUIRED]])
['HighLimit', REQUIRED]]),
SignerList: [83].concat(sleBase,[
['OwnerNode', REQUIRED],
['SignerQuorum', REQUIRED],
['SignerEntries', REQUIRED],
['SignerListID', REQUIRED],
['PreviousTxnID', REQUIRED],
['PreviousTxnLgrSeq', REQUIRED]
])
};
exports.metadata = [
[ 'TransactionIndex' , REQUIRED ],
[ 'TransactionResult' , REQUIRED ],
[ 'AffectedNodes' , REQUIRED ]
['DeliveredAmount' , OPTIONAL],
['TransactionIndex' , REQUIRED],
['TransactionResult' , REQUIRED],
['AffectedNodes' , REQUIRED]
];
exports.ter = {
@@ -422,7 +466,7 @@ exports.ter = {
tecNO_LINE_REDUNDANT : 127,
tecPATH_DRY : 128,
tecUNFUNDED : 129, // Deprecated, old ambiguous unfunded.
tecMASTER_DISABLED : 130,
tecNO_ALTERNATIVE_KEY : 130,
tecNO_REGULAR_KEY : 131,
tecOWNERS : 132,
tecNO_ISSUER : 133,
@@ -436,5 +480,6 @@ exports.ter = {
tecINSUFFICIENT_RESERVE : 141,
tecNEED_MASTER_KEY : 142,
tecDST_TAG_NEEDED : 143,
tecINTERNAL : 144
tecINTERNAL : 144,
tecOVERSIZE : 145
};

View File

@@ -1,15 +1,15 @@
'use strict';
var extend = require('extend');
var UInt160 = require('./uint160').UInt160;
var utils = require('./utils');
var Float = require('./ieee754').Float;
const extend = require('extend');
const UInt160 = require('./uint160').UInt160;
const utils = require('./utils');
const Float = require('./ieee754').Float;
//
// Currency support
//
var Currency = extend(function() {
const Currency = extend(function() {
// Internal form: 0 = XRP. 3 letter-code.
// XXX Internal should be 0 or hex with three letter annotation when valid.
@@ -22,7 +22,7 @@ var Currency = extend(function() {
this._update();
}, UInt160);
Currency.prototype = extend({}, UInt160.prototype);
Currency.prototype = Object.create(extend({}, UInt160.prototype));
Currency.prototype.constructor = Currency;
Currency.HEX_CURRENCY_BAD = '0000000000000000000000005852500000000000';
@@ -61,12 +61,12 @@ Currency.HEX_CURRENCY_BAD = '0000000000000000000000005852500000000000';
*
*/
/*eslint-disable max-len*/
/* eslint-disable max-len*/
Currency.prototype.human_RE = /^\s*([a-zA-Z0-9\<\>\(\)\{\}\[\]\|\?\!\@\#\$\%\^\&]{3})(\s*-\s*[- \w]+)?(\s*\(-?\d+\.?\d*%pa\))?\s*$/;
/*eslint-enable max-len*/
/* eslint-enable max-len*/
Currency.from_json = function(j, shouldInterpretXrpAsIou) {
return (new Currency()).parse_json(j, shouldInterpretXrpAsIou);
return (new Currency()).parse_json(j, shouldInterpretXrpAsIou);
};
Currency.from_human = function(j, opts) {
@@ -78,7 +78,7 @@ Currency.prototype.parse_json = function(j, shouldInterpretXrpAsIou) {
this._value = NaN;
if (j instanceof Currency) {
this._value = j.copyTo({})._value;
this._value = j._value;
this._update();
return this;
}
@@ -111,10 +111,10 @@ Currency.prototype.parse_json = function(j, shouldInterpretXrpAsIou) {
}
// match the given string to see if it's in an allowed format
var matches = j.match(this.human_RE);
const matches = j.match(this.human_RE);
if (matches) {
var currencyCode = matches[1];
let currencyCode = matches[1];
// for the currency 'XRP' case
// we drop everything else that could have been provided
@@ -131,14 +131,14 @@ Currency.prototype.parse_json = function(j, shouldInterpretXrpAsIou) {
// 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] || '';
const interest = matches[3] || '';
// interest is defined as interest per year, per annum (pa)
var percentage = interest.match(/(-?\d+\.?\d+)/);
let percentage = interest.match(/(-?\d+\.?\d+)/);
currencyCode = currencyCode.toUpperCase();
var currencyData = utils.arraySet(20, 0);
const currencyData = utils.arraySet(20, 0);
if (percentage) {
/*
@@ -164,15 +164,15 @@ Currency.prototype.parse_json = function(j, shouldInterpretXrpAsIou) {
// the interest or demurrage is expressed as a yearly (per annum)
// value
var secondsPerYear = 31536000; // 60 * 60 * 24 * 365
const secondsPerYear = 31536000; // 60 * 60 * 24 * 365
// Calculating the interest e-fold
// 0.5% demurrage is expressed 0.995, 0.005 less than 1
// 0.5% interest is expressed as 1.005, 0.005 more than 1
var interestEfold = secondsPerYear / Math.log(1 + percentage / 100);
var bytes = Float.toIEEE754Double(interestEfold);
const interestEfold = secondsPerYear / Math.log(1 + percentage / 100);
const bytes = Float.toIEEE754Double(interestEfold);
for (var i = 0; i <= bytes.length; i++) {
for (let i = 0; i <= bytes.length; i++) {
currencyData[8 + i] = bytes[i] & 0xff;
}
@@ -204,10 +204,10 @@ Currency.prototype.parse_human = function(j) {
*/
Currency.prototype._update = function() {
var bytes = this.to_bytes();
const bytes = this.to_bytes();
// is it 0 everywhere except 12, 13, 14?
var isZeroExceptInStandardPositions = true;
let isZeroExceptInStandardPositions = true;
if (!bytes) {
return;
@@ -219,7 +219,7 @@ Currency.prototype._update = function() {
this._interest_period = NaN;
this._iso_code = '';
for (var i = 0; i < 20; i++) {
for (let i = 0; i < 20; i++) {
isZeroExceptInStandardPositions = isZeroExceptInStandardPositions
&& (i === 12 || i === 13 || i === 14 || bytes[i] === 0);
}
@@ -249,6 +249,34 @@ Currency.prototype._update = function() {
}
};
/**
* Returns copy.
*
* This copies code from UInt.copyTo so we do not call _update,
* bvecause to_bytes is very expensive.
*/
Currency.prototype.copyTo = function(d) {
d._value = this._value;
if (this._version_byte !== undefined) {
d._version_byte = this._version_byte;
}
if (!d.is_valid()) {
return d;
}
d._native = this._native;
d._type = this._type;
d._interest_start = this._interest_start;
d._interest_period = this._interest_period;
d._iso_code = this._iso_code;
return d;
};
// XXX Probably not needed anymore?
/*
Currency.prototype.parse_bytes = function(byte_array) {
@@ -300,18 +328,20 @@ Currency.prototype.has_interest = function() {
/**
*
* @param {number} referenceDate number of seconds since the Ripple Epoch
* @param {number} referenceDate_ number of seconds since the Ripple Epoch
* (0:00 on January 1, 2000 UTC) used to calculate the
* interest over provided interval pass in one years
* worth of seconds to ge the yearly interest
* @returns {number} interest for provided interval, can be negative for
* demurred currencies
*/
Currency.prototype.get_interest_at = function(referenceDate) {
Currency.prototype.get_interest_at = function(referenceDate_) {
if (!this.has_interest()) {
return 0;
}
let referenceDate = referenceDate_;
// use one year as a default period
if (!referenceDate) {
referenceDate = this._interest_start + 3600 * 24 * 365;
@@ -326,13 +356,14 @@ Currency.prototype.get_interest_at = function(referenceDate) {
/ this._interest_period);
};
Currency.prototype.get_interest_percentage_at
= function(referenceDate, decimals) {
var interest = this.get_interest_at(referenceDate, decimals);
Currency.prototype.get_interest_percentage_at = function(referenceDate,
decimals
) {
let interest = this.get_interest_at(referenceDate, decimals);
// convert to percentage
interest = (interest * 100) - 100;
var decimalMultiplier = decimals ? Math.pow(10, decimals) : 100;
const decimalMultiplier = decimals ? Math.pow(10, decimals) : 100;
// round to two decimals behind the dot
return Math.round(interest * decimalMultiplier) / decimalMultiplier;
@@ -347,18 +378,14 @@ Currency.prototype.get_interest_percentage_at
// return UInt.prototype.is_valid() && ...;
// };
Currency.prototype.to_json = function(opts) {
Currency.prototype.to_json = function(opts = {}) {
if (!this.is_valid()) {
// XXX This is backwards compatible behavior, but probably not very good.
return 'XRP';
}
if (!opts) {
opts = {};
}
var currency;
var fullName = opts && opts.full_name ? ' - ' + opts.full_name : '';
let currency;
const fullName = opts && opts.full_name ? ' - ' + opts.full_name : '';
opts.show_interest = opts.show_interest !== undefined
? opts.show_interest
: this.has_interest();
@@ -366,8 +393,8 @@ Currency.prototype.to_json = function(opts) {
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 : undefined;
var interestPercentage = this.has_interest()
const decimals = !isNaN(opts.decimals) ? opts.decimals : undefined;
const interestPercentage = this.has_interest()
? this.get_interest_percentage_at(
this._interest_start + 3600 * 24 * 365, decimals
)

View File

@@ -30,6 +30,8 @@ exports.HASH_LEAF_NODE = 0x4D4C4E00; // 'MLN'
exports.HASH_TX_SIGN = 0x53545800; // 'STX'
// inner transaction to sign (TESTNET)
exports.HASH_TX_SIGN_TESTNET = 0x73747800; // 'stx'
// inner transaction to multisign
exports.HASH_TX_MULTISIGN = 0x534D5400; // 'SMT'
Object.keys(exports).forEach(function(k) {
exports[k + '_BYTES'] = toBytes(exports[k]);

View File

@@ -21,47 +21,12 @@ exports.TransactionQueue = require('./transactionqueue').TransactionQueue;
exports.convertBase = require('./baseconverter');
exports._test = {
IOUValue: require('./iouvalue').IOUValue,
Log: require('./log'),
PathFind: require('./pathfind').PathFind,
TransactionManager: require('./transactionmanager').TransactionManager,
RangeSet: require('./rangeset').RangeSet
RangeSet: require('./rangeset').RangeSet,
HashPrefixes: require('./hashprefixes')
};
// 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
// any time without warning.
//
// However, for programs that are tied to a specific version of ripple.js like
// the official client, it makes sense to expose the SJCL instance so we don't
// have to include it twice.
exports.sjcl = require('./utils').sjcl;
exports.Wallet = require('ripple-wallet-generator')({sjcl: exports.sjcl});
exports.types = require('./serializedtypes');
// camelCase to under_scored API conversion
function attachUnderscored(name) {
const o = exports[name];
Object.keys(o.prototype).forEach(function(key) {
const UPPERCASE = /([A-Z]{1})[a-z]+/g;
if (!UPPERCASE.test(key)) {
return;
}
const underscored = key.replace(UPPERCASE, function(c) {
return '_' + c.toLowerCase();
});
o.prototype[underscored] = o.prototype[key];
});
}
['Remote',
'Request',
'Transaction',
'Account',
'Server'
].forEach(attachUnderscored);
// vim:sw=2:sts=2:ts=8:et

View File

@@ -1,102 +0,0 @@
'use strict';
/*eslint new-cap: 1*/
var sjcl = require('./utils').sjcl;
var UInt160 = require('./uint160').UInt160;
var UInt256 = require('./uint256').UInt256;
var Base = require('./base').Base;
function KeyPair() {
this._curve = sjcl.ecc.curves.k256;
this._secret = null;
this._pubkey = null;
}
KeyPair.from_bn_secret = function(j) {
return (j instanceof this) ? j.clone() : (new this()).parse_bn_secret(j);
};
KeyPair.prototype.parse_bn_secret = function(j) {
this._secret = new sjcl.ecc.ecdsa.secretKey(sjcl.ecc.curves.k256, j);
return this;
};
/**
* @private
*
* @return {sjcl.ecc.ecdsa.publicKey} public key
*/
KeyPair.prototype._pub = function() {
var curve = this._curve;
if (!this._pubkey && this._secret) {
var exponent = this._secret._exponent;
this._pubkey = new sjcl.ecc.ecdsa.publicKey(curve, curve.G.mult(exponent));
}
return this._pubkey;
};
/**
* @private
*
* @return {sjcl.bitArray} public key bits in compressed form
*/
KeyPair.prototype._pub_bits = function() {
var pub = this._pub();
if (!pub) {
return null;
}
var point = pub._point, y_even = point.y.mod(2).equals(0);
return sjcl.bitArray.concat(
[sjcl.bitArray.partial(8, y_even ? 0x02 : 0x03)],
point.x.toBits(this._curve.r.bitLength())
);
};
/**
* @return {String} public key bytes in compressed form, hex encoded.
*/
KeyPair.prototype.to_hex_pub = function() {
var bits = this._pub_bits();
if (!bits) {
return null;
}
return sjcl.codec.hex.fromBits(bits).toUpperCase();
};
function sha256_ripemd160(bits) {
return sjcl.hash.ripemd160.hash(sjcl.hash.sha256.hash(bits));
}
KeyPair.prototype.get_address = function() {
var bits = this._pub_bits();
if (!bits) {
return null;
}
var hash = sha256_ripemd160(bits);
var address = UInt160.from_bits(hash);
address.set_version(Base.VER_ACCOUNT_ID);
return address;
};
KeyPair.prototype.sign = function(hash) {
var PARANOIA_256_BITS = 6; // sjcl constant for ensuring 256 bits of entropy
hash = UInt256.from_json(hash);
var sig = this._secret.sign(hash.to_bits(), PARANOIA_256_BITS);
sig = this._secret.canonicalizeSignature(sig);
return this._secret.encodeDER(sig);
};
exports.KeyPair = KeyPair;

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