mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-24 22:25:48 +00:00
Convert server methods, add unit tests, and cleanup
This commit is contained in:
@@ -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
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user