mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-22 21:25:49 +00:00
Add PendingLedgerVersionError
MissingLedgerHistoryError - no minLedgerVersion or maxLedgerVersion There is a ledger gap, but a range should be provided to narrow down the range of the gap. MissingLedgerHistoryError When requesting a tx, if maxLedgerVersion and minLedgerVersion provided, this means there is a ledger gap in the provided range. PendingLedgerVersionError: If maxLedgerVersion provided, check if ledger is ahead of the server's last validated ledger.
This commit is contained in:
@@ -58,6 +58,13 @@ function MissingLedgerHistoryError(message) {
|
|||||||
MissingLedgerHistoryError.prototype = new RippleError();
|
MissingLedgerHistoryError.prototype = new RippleError();
|
||||||
MissingLedgerHistoryError.prototype.name = 'MissingLedgerHistoryError';
|
MissingLedgerHistoryError.prototype.name = 'MissingLedgerHistoryError';
|
||||||
|
|
||||||
|
function PendingLedgerVersionError(message) {
|
||||||
|
this.message = message ||
|
||||||
|
'maxLedgerVersion is greater than server\'s most recent validated ledger';
|
||||||
|
}
|
||||||
|
PendingLedgerVersionError.prototype = new RippleError();
|
||||||
|
PendingLedgerVersionError.prototype.name = 'PendingLedgerVersionError';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request timed out
|
* Request timed out
|
||||||
*/
|
*/
|
||||||
@@ -82,6 +89,7 @@ module.exports = {
|
|||||||
TransactionError,
|
TransactionError,
|
||||||
RippledNetworkError,
|
RippledNetworkError,
|
||||||
NotFoundError,
|
NotFoundError,
|
||||||
|
PendingLedgerVersionError,
|
||||||
MissingLedgerHistoryError,
|
MissingLedgerHistoryError,
|
||||||
TimeOutError,
|
TimeOutError,
|
||||||
ApiError,
|
ApiError,
|
||||||
|
|||||||
@@ -52,8 +52,8 @@ function getTransactionAsync(identifier: string, options: TransactionOptions,
|
|||||||
validate.getTransactionOptions(options);
|
validate.getTransactionOptions(options);
|
||||||
|
|
||||||
const remote = this.remote;
|
const remote = this.remote;
|
||||||
const maxLedgerVersion = Math.min(options.maxLedgerVersion || Infinity,
|
const maxLedgerVersion =
|
||||||
remote.getLedgerSequence());
|
options.maxLedgerVersion || remote.getLedgerSequence();
|
||||||
|
|
||||||
function callbackWrapper(error_?: Error, tx?: Object) {
|
function callbackWrapper(error_?: Error, tx?: Object) {
|
||||||
let error = error_;
|
let error = error_;
|
||||||
@@ -67,13 +67,19 @@ function getTransactionAsync(identifier: string, options: TransactionOptions,
|
|||||||
error = new errors.NotFoundError('Transaction not found');
|
error = new errors.NotFoundError('Transaction not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Missing complete ledger range
|
||||||
if (error instanceof errors.NotFoundError
|
if (error instanceof errors.NotFoundError
|
||||||
&& !utils.hasCompleteLedgerRange(remote,
|
&& !utils.hasCompleteLedgerRange(remote, options.minLedgerVersion,
|
||||||
options.minLedgerVersion, maxLedgerVersion)) {
|
maxLedgerVersion)) {
|
||||||
callback(new errors.MissingLedgerHistoryError('Transaction not found,'
|
if (utils.isPendingLedgerVersion(remote, maxLedgerVersion)) {
|
||||||
+ ' but the server\'s ledger history is incomplete'));
|
callback(new errors.PendingLedgerVersionError());
|
||||||
|
} else {
|
||||||
|
callback(new errors.MissingLedgerHistoryError());
|
||||||
|
}
|
||||||
|
// Transaction is found, but not in specified range
|
||||||
} else if (!error && tx && !isTransactionInRange(tx, options)) {
|
} else if (!error && tx && !isTransactionInRange(tx, options)) {
|
||||||
callback(new errors.NotFoundError('Transaction not found'));
|
callback(new errors.NotFoundError('Transaction not found'));
|
||||||
|
// Transaction is not found
|
||||||
} else if (error) {
|
} else if (error) {
|
||||||
convertErrors(callback)(error);
|
convertErrors(callback)(error);
|
||||||
} else if (!tx) {
|
} else if (!tx) {
|
||||||
|
|||||||
@@ -99,12 +99,19 @@ function compareTransactions(first: Outcome, second: Outcome): number {
|
|||||||
function hasCompleteLedgerRange(remote: Remote, minLedgerVersion?: number,
|
function hasCompleteLedgerRange(remote: Remote, minLedgerVersion?: number,
|
||||||
maxLedgerVersion?: number
|
maxLedgerVersion?: number
|
||||||
): boolean {
|
): boolean {
|
||||||
|
|
||||||
const firstLedgerVersion = 32570; // earlier versions have been lost
|
const firstLedgerVersion = 32570; // earlier versions have been lost
|
||||||
return remote.getServer().hasLedgerRange(
|
return remote.getServer().hasLedgerRange(
|
||||||
minLedgerVersion || firstLedgerVersion,
|
minLedgerVersion || firstLedgerVersion,
|
||||||
maxLedgerVersion || remote.getLedgerSequence());
|
maxLedgerVersion || remote.getLedgerSequence());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isPendingLedgerVersion(remote: Remote, maxLedgerVersion: ?number
|
||||||
|
): boolean {
|
||||||
|
const currentLedger = remote.getLedgerSequence();
|
||||||
|
return currentLedger < (maxLedgerVersion || 0);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getXRPBalance,
|
getXRPBalance,
|
||||||
compareTransactions,
|
compareTransactions,
|
||||||
@@ -112,6 +119,7 @@ module.exports = {
|
|||||||
renameCounterpartyToIssuerInOrder,
|
renameCounterpartyToIssuerInOrder,
|
||||||
getRecursive,
|
getRecursive,
|
||||||
hasCompleteLedgerRange,
|
hasCompleteLedgerRange,
|
||||||
|
isPendingLedgerVersion,
|
||||||
promisify: common.promisify,
|
promisify: common.promisify,
|
||||||
clamp: clamp,
|
clamp: clamp,
|
||||||
common: common
|
common: common
|
||||||
|
|||||||
@@ -160,6 +160,7 @@ describe('RippleAPI', function() {
|
|||||||
_.partial(checkResult, responses.getBalances, 'getBalances'));
|
_.partial(checkResult, responses.getBalances, 'getBalances'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('getTransaction', () => {
|
||||||
it('getTransaction - payment', function() {
|
it('getTransaction - payment', function() {
|
||||||
return this.api.getTransaction(hashes.VALID_TRANSACTION_HASH).then(
|
return this.api.getTransaction(hashes.VALID_TRANSACTION_HASH).then(
|
||||||
_.partial(checkResult, responses.getTransaction.payment,
|
_.partial(checkResult, responses.getTransaction.payment,
|
||||||
@@ -282,6 +283,31 @@ describe('RippleAPI', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('getTransaction - missing ledger history with ledger range', function() {
|
||||||
|
const hash = hashes.NOTFOUND_TRANSACTION_HASH;
|
||||||
|
const options = {
|
||||||
|
minLedgerVersion: 32569,
|
||||||
|
maxLedgerVersion: 32571
|
||||||
|
};
|
||||||
|
return this.api.getTransaction(hash, options).then(() => {
|
||||||
|
assert(false, 'Should throw MissingLedgerHistoryError');
|
||||||
|
}).catch(error => {
|
||||||
|
assert(error instanceof this.api.errors.MissingLedgerHistoryError);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getTransaction - not found - future maxLedgerVersion', function() {
|
||||||
|
const hash = hashes.NOTFOUND_TRANSACTION_HASH;
|
||||||
|
const options = {
|
||||||
|
maxLedgerVersion: 99999999999
|
||||||
|
};
|
||||||
|
return this.api.getTransaction(hash, options).then(() => {
|
||||||
|
assert(false, 'Should throw PendingLedgerVersionError');
|
||||||
|
}).catch(error => {
|
||||||
|
assert(error instanceof this.api.errors.PendingLedgerVersionError);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('getTransaction - ledger_index not found', function() {
|
it('getTransaction - ledger_index not found', function() {
|
||||||
const hash =
|
const hash =
|
||||||
'4FB3ADF22F3C605E23FAEFAA185F3BD763C4692CAC490D9819D117CD33BFAA11';
|
'4FB3ADF22F3C605E23FAEFAA185F3BD763C4692CAC490D9819D117CD33BFAA11';
|
||||||
@@ -313,6 +339,7 @@ describe('RippleAPI', function() {
|
|||||||
assert(error instanceof this.api.errors.ApiError);
|
assert(error instanceof this.api.errors.ApiError);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('getTransactions', function() {
|
it('getTransactions', function() {
|
||||||
const options = {types: ['payment', 'order'], initiated: true, limit: 2};
|
const options = {types: ['payment', 'order'], initiated: true, limit: 2};
|
||||||
|
|||||||
Reference in New Issue
Block a user