Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allows to use both positional and named parameters
- Loading branch information
1 parent
8d8a850
commit 76866ab
Showing
10 changed files
with
456 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict'; | ||
|
||
const createHTTPServer = require('../src/index').createHTTPServer; | ||
const port = 5990; | ||
const serverUrl = 'wss://s1.ripple.com'; | ||
|
||
|
||
function main() { | ||
const server = createHTTPServer({server: serverUrl}, port); | ||
server.start().then(() => { | ||
console.log('Server started on port ' + String(port)); | ||
}); | ||
} | ||
|
||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* eslint-disable new-cap */ | ||
'use strict'; | ||
|
||
const assert = require('assert-diff'); | ||
const _ = require('lodash'); | ||
const jayson = require('jayson'); | ||
|
||
const RippleAPI = require('./api').RippleAPI; | ||
|
||
|
||
function createHTTPServer(options, httpPort) { | ||
const rippleAPI = new RippleAPI(options); | ||
|
||
const methodNames = _.filter(_.keys(RippleAPI.prototype), k => { | ||
return typeof RippleAPI.prototype[k] === 'function' | ||
&& k !== 'connect' | ||
&& k !== 'disconnect' | ||
&& k !== 'constructor' | ||
&& k !== 'RippleAPI'; | ||
}); | ||
|
||
function applyPromiseWithCallback(fnName, callback, args_) { | ||
try { | ||
let args = args_; | ||
if (!_.isArray(args_)) { | ||
const fnParameters = jayson.Utils.getParameterNames(rippleAPI[fnName]); | ||
args = fnParameters.map(name => args_[name]); | ||
const defaultArgs = _.omit(args_, fnParameters); | ||
assert(_.size(defaultArgs) <= 1, | ||
'Function must have no more than one default argument'); | ||
if (_.size(defaultArgs) > 0) { | ||
args.push(defaultArgs[_.keys(defaultArgs)[0]]); | ||
} | ||
} | ||
Promise.resolve(rippleAPI[fnName].apply(rippleAPI, args)) | ||
.then(res => callback(null, res)) | ||
.catch(err => { | ||
callback({code: 99, message: err.message, data: {name: err.name}}); | ||
}); | ||
} catch (err) { | ||
callback({code: 99, message: err.message, data: {name: err.name}}); | ||
} | ||
} | ||
|
||
const methods = {}; | ||
_.forEach(methodNames, fn => { | ||
methods[fn] = jayson.Method((args, cb) => { | ||
applyPromiseWithCallback(fn, cb, args); | ||
}, {collect: true}); | ||
}); | ||
|
||
const server = jayson.server(methods); | ||
let httpServer = null; | ||
|
||
return { | ||
server: server, | ||
start: function() { | ||
if (httpServer !== null) { | ||
return Promise.reject('Already started'); | ||
} | ||
return new Promise((resolve) => { | ||
rippleAPI.connect().then(() => { | ||
httpServer = server.http(); | ||
httpServer.listen(httpPort, resolve); | ||
}); | ||
}); | ||
}, | ||
stop: function() { | ||
if (httpServer === null) { | ||
return Promise.reject('Not started'); | ||
} | ||
return new Promise((resolve) => { | ||
rippleAPI.disconnect(); | ||
httpServer.close(() => { | ||
httpServer = null; | ||
resolve(); | ||
}); | ||
}); | ||
} | ||
}; | ||
} | ||
|
||
module.exports = { | ||
createHTTPServer | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
{ | ||
"jsonrpc": "2.0", | ||
"id": "2", | ||
"result": { | ||
"type": "order", | ||
"address": "rK5j9n8baXfL4gzUoZsfxBvvsv97P5swaV", | ||
"sequence": 7973823, | ||
"id": "4EB6B76237DEEE99F1EA16FAACED2D1E69C5F9CB54F727A4ECA51A08AD3AF466", | ||
"specification": { | ||
"direction": "buy", | ||
"quantity": { | ||
"currency": "USD", | ||
"value": "0.000709756467", | ||
"counterparty": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B" | ||
}, | ||
"totalPrice": { | ||
"currency": "JPY", | ||
"value": "0.086630181788", | ||
"counterparty": "r94s8px6kSw1uZ1MV98dhSRTvc6VMPoPcN" | ||
} | ||
}, | ||
"outcome": { | ||
"result": "tesSUCCESS", | ||
"timestamp": "2015-12-03T00:53:21.000Z", | ||
"fee": "0.010001", | ||
"balanceChanges": { | ||
"rK5j9n8baXfL4gzUoZsfxBvvsv97P5swaV": [ | ||
{ | ||
"currency": "XRP", | ||
"value": "-0.010001" | ||
} | ||
] | ||
}, | ||
"orderbookChanges": { | ||
"rK5j9n8baXfL4gzUoZsfxBvvsv97P5swaV": [ | ||
{ | ||
"direction": "buy", | ||
"quantity": { | ||
"currency": "USD", | ||
"counterparty": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", | ||
"value": "0.000709260645" | ||
}, | ||
"totalPrice": { | ||
"currency": "JPY", | ||
"counterparty": "r94s8px6kSw1uZ1MV98dhSRTvc6VMPoPcN", | ||
"value": "0.086665436143" | ||
}, | ||
"sequence": 7973725, | ||
"status": "cancelled", | ||
"makerExchangeRate": "0.008183892870852266" | ||
}, | ||
{ | ||
"direction": "buy", | ||
"quantity": { | ||
"currency": "USD", | ||
"counterparty": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", | ||
"value": "0.000709756467" | ||
}, | ||
"totalPrice": { | ||
"currency": "JPY", | ||
"counterparty": "r94s8px6kSw1uZ1MV98dhSRTvc6VMPoPcN", | ||
"value": "0.086630181788" | ||
}, | ||
"sequence": 7973823, | ||
"status": "created", | ||
"makerExchangeRate": "0.008192946757712049" | ||
} | ||
] | ||
}, | ||
"ledgerVersion": 17445469, | ||
"indexInLedger": 2 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
{ | ||
"jsonrpc": "2.0", | ||
"id": "3", | ||
"result": [ | ||
{ | ||
"type": "order", | ||
"address": "rpP2JgiMyTF5jR5hLG3xHCPi1knBb1v9cM", | ||
"sequence": 3372206, | ||
"id": "848397FA686BD4A59F91EC1F4DE717360470EE8BD67CAA01D5FD333EDA8D97B3", | ||
"specification": { | ||
"direction": "buy", | ||
"quantity": { | ||
"currency": "JPY", | ||
"value": "27865.90216965619", | ||
"counterparty": "rJRi8WW24gt9X85PHAxfWNPCizMMhqUQwg" | ||
}, | ||
"totalPrice": { | ||
"currency": "XRP", | ||
"value": "40000" | ||
} | ||
}, | ||
"outcome": { | ||
"result": "tesSUCCESS", | ||
"fee": "0.011", | ||
"balanceChanges": { | ||
"rpP2JgiMyTF5jR5hLG3xHCPi1knBb1v9cM": [ | ||
{ | ||
"currency": "XRP", | ||
"value": "-0.011" | ||
} | ||
] | ||
}, | ||
"orderbookChanges": { | ||
"rpP2JgiMyTF5jR5hLG3xHCPi1knBb1v9cM": [ | ||
{ | ||
"direction": "buy", | ||
"quantity": { | ||
"currency": "JPY", | ||
"counterparty": "rJRi8WW24gt9X85PHAxfWNPCizMMhqUQwg", | ||
"value": "27880.6855384734" | ||
}, | ||
"totalPrice": { | ||
"currency": "XRP", | ||
"value": "40000" | ||
}, | ||
"sequence": 3372204, | ||
"status": "cancelled", | ||
"makerExchangeRate": "0.697017138461835" | ||
}, | ||
{ | ||
"direction": "buy", | ||
"quantity": { | ||
"currency": "JPY", | ||
"counterparty": "rJRi8WW24gt9X85PHAxfWNPCizMMhqUQwg", | ||
"value": "27865.90216965619" | ||
}, | ||
"totalPrice": { | ||
"currency": "XRP", | ||
"value": "40000" | ||
}, | ||
"sequence": 3372206, | ||
"status": "created", | ||
"makerExchangeRate": "0.6966475542414048" | ||
} | ||
] | ||
}, | ||
"ledgerVersion": 17533547, | ||
"indexInLedger": 12 | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
getTransaction: require('./get-transaction'), | ||
getTransactions: require('./get-transactions') | ||
}; |
Oops, something went wrong.