Convert server methods, add unit tests, and cleanup

This commit is contained in:
Chris Clark
2015-07-01 15:42:32 -07:00
parent 4efe0b920e
commit 32ca23a00b
14 changed files with 77 additions and 223 deletions

View File

@@ -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 isConnected() {
return common.server.isConnected(this.remote);
function disconnect(callback) {
this.remote.disconnect(callback);
}
function getServerStatus(callback) {
common.server.getStatus(this.remote, function(error, status) {
function isUpToDate(remote) {
const server = remote.getServer();
return Boolean(server) && (remote._stand_alone
|| (Date.now() - server._lastLedgerClose) <= CONNECTION_TIMEOUT);
}
function isConnected() {
return Boolean(this.remote._ledger_current_index) && isUpToDate(this.remote);
}
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
};