mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-21 04:35:49 +00:00
Check for ledger gaps in getTransactions
This commit is contained in:
@@ -52,7 +52,8 @@ NotFoundError.prototype = new RippleError();
|
||||
NotFoundError.prototype.name = 'NotFoundError';
|
||||
|
||||
function MissingLedgerHistoryError(message) {
|
||||
this.message = message;
|
||||
this.message = message ||
|
||||
'Server is missing ledger history in the specified range';
|
||||
}
|
||||
MissingLedgerHistoryError.prototype = new RippleError();
|
||||
MissingLedgerHistoryError.prototype.name = 'MissingLedgerHistoryError';
|
||||
|
||||
@@ -5,14 +5,6 @@ const utils = require('./utils');
|
||||
const parseTransaction = require('./parse/transaction');
|
||||
const validate = utils.common.validate;
|
||||
const errors = utils.common.errors;
|
||||
const MIN_LEDGER_VERSION = 32570; // earlier versions have been completely lost
|
||||
|
||||
function hasCompleteLedgerRange(remote, options) {
|
||||
const minLedgerVersion = options.minLedgerVersion || MIN_LEDGER_VERSION;
|
||||
const maxLedgerVersion = options.maxLedgerVersion
|
||||
|| remote.getLedgerSequence();
|
||||
return remote.getServer().hasLedgerRange(minLedgerVersion, maxLedgerVersion);
|
||||
}
|
||||
|
||||
function attachTransactionDate(remote, tx, callback) {
|
||||
if (tx.date) {
|
||||
@@ -50,7 +42,8 @@ function getTransaction(identifier, options, callback) {
|
||||
|
||||
function callbackWrapper(error, tx) {
|
||||
if (error instanceof errors.NotFoundError
|
||||
&& !hasCompleteLedgerRange(remote, options)) {
|
||||
&& !utils.hasCompleteLedgerRange(remote,
|
||||
options.minLedgerVersion, options.maxLedgerVersion)) {
|
||||
callback(new errors.MissingLedgerHistoryError('Transaction not found,'
|
||||
+ ' but the server\'s ledger history is incomplete'));
|
||||
} else if (!error && !isTransactionInRange(tx, options)) {
|
||||
|
||||
@@ -77,6 +77,11 @@ function getTransactions(address, options, callback) {
|
||||
validate.getTransactionsOptions(options);
|
||||
|
||||
const remote = this.remote;
|
||||
if (!utils.hasCompleteLedgerRange(remote, options.minLedgerVersion,
|
||||
options.maxLedgerVersion)) {
|
||||
callback(new utils.common.errors.MissingLedgerHistoryError());
|
||||
}
|
||||
|
||||
if (options.start) {
|
||||
getTransaction.bind(this)(options.start, {}, (error, tx) => {
|
||||
if (error) {
|
||||
|
||||
@@ -71,12 +71,20 @@ function compareTransactions(first, second) {
|
||||
return Number(first.ledgerVersion) < Number(second.ledgerVersion) ? -1 : 1;
|
||||
}
|
||||
|
||||
function hasCompleteLedgerRange(remote, minLedgerVersion, maxLedgerVersion) {
|
||||
const firstLedgerVersion = 32570; // earlier versions have been lost
|
||||
return remote.getServer().hasLedgerRange(
|
||||
minLedgerVersion || firstLedgerVersion,
|
||||
maxLedgerVersion || remote.getLedgerSequence());
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getXRPBalance: getXRPBalance,
|
||||
compareTransactions: compareTransactions,
|
||||
renameCounterpartyToIssuer: renameCounterpartyToIssuer,
|
||||
renameCounterpartyToIssuerInOrder: renameCounterpartyToIssuerInOrder,
|
||||
getRecursive: getRecursive,
|
||||
getXRPBalance,
|
||||
compareTransactions,
|
||||
renameCounterpartyToIssuer,
|
||||
renameCounterpartyToIssuerInOrder,
|
||||
getRecursive,
|
||||
hasCompleteLedgerRange,
|
||||
wrapCatch: common.wrapCatch,
|
||||
common: common
|
||||
};
|
||||
|
||||
@@ -513,15 +513,14 @@ Remote.prototype._handleMessage = function(message, server) {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Remote.prototype.getLedgerSequence = function() {
|
||||
if (!this._ledger_current_index) {
|
||||
throw new Error('Ledger sequence has not yet been initialized');
|
||||
}
|
||||
return this._ledger_current_index;
|
||||
// the "current" ledger is the one after the most recently closed ledger
|
||||
return this._ledger_current_index - 1;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Handle server ledger_closed event
|
||||
*
|
||||
|
||||
@@ -192,6 +192,6 @@ describe('RippleAPI', function() {
|
||||
});
|
||||
|
||||
it('getLedgerVersion', function() {
|
||||
assert.strictEqual(this.api.getLedgerVersion(), 8819952);
|
||||
assert.strictEqual(this.api.getLedgerVersion(), 8819951);
|
||||
});
|
||||
});
|
||||
|
||||
2
test/fixtures/order-response.json
vendored
2
test/fixtures/order-response.json
vendored
@@ -2,7 +2,7 @@
|
||||
"Account": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
|
||||
"Fee": "12",
|
||||
"Flags": 131072,
|
||||
"LastLedgerSequence": 8820052,
|
||||
"LastLedgerSequence": 8820051,
|
||||
"Sequence": 23,
|
||||
"TakerGets": "2000000",
|
||||
"TakerPays": {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"TransactionType": "OfferCancel",
|
||||
"Account": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
|
||||
"OfferSequence": 23,
|
||||
"LastLedgerSequence": 8820052,
|
||||
"LastLedgerSequence": 8820051,
|
||||
"Fee": "12",
|
||||
"Sequence": 23
|
||||
}
|
||||
|
||||
2
test/fixtures/payment-response.json
vendored
2
test/fixtures/payment-response.json
vendored
@@ -8,7 +8,7 @@
|
||||
"currency": "USD",
|
||||
"issuer": "rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM"
|
||||
},
|
||||
"LastLedgerSequence": 8820052,
|
||||
"LastLedgerSequence": 8820051,
|
||||
"SendMax": {
|
||||
"currency": "USD",
|
||||
"issuer": "rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM",
|
||||
|
||||
2
test/fixtures/settings-response.json
vendored
2
test/fixtures/settings-response.json
vendored
@@ -4,7 +4,7 @@
|
||||
"Account": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
|
||||
"Domain": "726970706C652E636F6D",
|
||||
"Flags": 0,
|
||||
"LastLedgerSequence": 8820052,
|
||||
"LastLedgerSequence": 8820051,
|
||||
"Fee": "12",
|
||||
"Sequence": 23
|
||||
}
|
||||
|
||||
2
test/fixtures/trustline-response.json
vendored
2
test/fixtures/trustline-response.json
vendored
@@ -9,7 +9,7 @@
|
||||
},
|
||||
"QualityIn": 500000000,
|
||||
"QualityOut": 500000000,
|
||||
"LastLedgerSequence": 8820052,
|
||||
"LastLedgerSequence": 8820051,
|
||||
"Fee": "12",
|
||||
"Sequence": 23
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user