-
Notifications
You must be signed in to change notification settings - Fork 503
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #392 from clark800/server
Convert server methods, add unit tests, and cleanup
- Loading branch information
Showing
14 changed files
with
76 additions
and
222 deletions.
There are no files selected for viewing
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 was deleted.
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 was deleted.
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
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 |
---|---|---|
@@ -1,33 +1,45 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
|
||
// If a ledger is not received in this time, consider the connection offline | ||
const CONNECTION_TIMEOUT = 1000 * 30; | ||
|
||
function connect(callback) { | ||
this.remote.connect(callback); | ||
} | ||
|
||
function disconnect(callback) { | ||
this.remote.disconnect(callback); | ||
} | ||
|
||
function isUpToDate(remote) { | ||
const server = remote.getServer(); | ||
return Boolean(server) && (remote._stand_alone | ||
|| (Date.now() - server._lastLedgerClose) <= CONNECTION_TIMEOUT); | ||
} | ||
|
||
function isConnected() { | ||
return common.server.isConnected(this.remote); | ||
return Boolean(this.remote._ledger_current_index) && isUpToDate(this.remote); | ||
} | ||
|
||
function getServerStatus(callback) { | ||
common.server.getStatus(this.remote, function(error, status) { | ||
function getServerInfo(callback) { | ||
this.remote.requestServerInfo((error, info) => { | ||
if (error) { | ||
callback(new common.errors.RippledNetworkError(error.message)); | ||
} else { | ||
callback(null, status); | ||
callback(null, info); | ||
} | ||
}); | ||
} | ||
|
||
function getFee(callback) { | ||
const fee = this.remote.createTransaction()._computeFee(); | ||
callback(null, {fee: common.dropsToXrp(fee)}); | ||
function getFee() { | ||
return common.dropsToXrp(this.remote.createTransaction()._computeFee()); | ||
} | ||
|
||
|
||
module.exports = { | ||
connect: connect, | ||
disconnect: disconnect, | ||
isConnected: isConnected, | ||
getServerStatus: getServerStatus, | ||
getServerInfo: getServerInfo, | ||
getFee: getFee | ||
}; |
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
Oops, something went wrong.