mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 20:25:48 +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
|
||||||
|
|||||||
303
test/api-test.js
303
test/api-test.js
@@ -160,157 +160,184 @@ describe('RippleAPI', function() {
|
|||||||
_.partial(checkResult, responses.getBalances, 'getBalances'));
|
_.partial(checkResult, responses.getBalances, 'getBalances'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('getTransaction - payment', function() {
|
describe('getTransaction', () => {
|
||||||
return this.api.getTransaction(hashes.VALID_TRANSACTION_HASH).then(
|
it('getTransaction - payment', function() {
|
||||||
_.partial(checkResult, responses.getTransaction.payment,
|
return this.api.getTransaction(hashes.VALID_TRANSACTION_HASH).then(
|
||||||
'getTransaction'));
|
_.partial(checkResult, responses.getTransaction.payment,
|
||||||
});
|
'getTransaction'));
|
||||||
|
|
||||||
it('getTransaction - settings', function() {
|
|
||||||
const hash =
|
|
||||||
'4FB3ADF22F3C605E23FAEFAA185F3BD763C4692CAC490D9819D117CD33BFAA1B';
|
|
||||||
return this.api.getTransaction(hash).then(
|
|
||||||
_.partial(checkResult, responses.getTransaction.settings,
|
|
||||||
'getTransaction'));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('getTransaction - order', function() {
|
|
||||||
const hash =
|
|
||||||
'10A6FB4A66EE80BED46AAE4815D7DC43B97E944984CCD5B93BCF3F8538CABC51';
|
|
||||||
return this.api.getTransaction(hash).then(
|
|
||||||
_.partial(checkResult, responses.getTransaction.order,
|
|
||||||
'getTransaction'));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('getTransaction - order cancellation', function() {
|
|
||||||
const hash =
|
|
||||||
'809335DD3B0B333865096217AA2F55A4DF168E0198080B3A090D12D88880FF0E';
|
|
||||||
return this.api.getTransaction(hash).then(
|
|
||||||
_.partial(checkResult, responses.getTransaction.orderCancellation,
|
|
||||||
'getTransaction'));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('getTransaction - trustline set', function() {
|
|
||||||
const hash =
|
|
||||||
'635A0769BD94710A1F6A76CDE65A3BC661B20B798807D1BBBDADCEA26420538D';
|
|
||||||
return this.api.getTransaction(hash).then(
|
|
||||||
_.partial(checkResult, responses.getTransaction.trustline,
|
|
||||||
'getTransaction'));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('getTransaction - trustline frozen off', function() {
|
|
||||||
const hash =
|
|
||||||
'FE72FAD0FA7CA904FB6C633A1666EDF0B9C73B2F5A4555D37EEF2739A78A531B';
|
|
||||||
return this.api.getTransaction(hash).then(
|
|
||||||
_.partial(checkResult, responses.getTransaction.trustlineFrozenOff,
|
|
||||||
'getTransaction'));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('getTransaction - trustline no quality', function() {
|
|
||||||
const hash =
|
|
||||||
'BAF1C678323C37CCB7735550C379287667D8288C30F83148AD3C1CB019FC9002';
|
|
||||||
return this.api.getTransaction(hash).then(
|
|
||||||
_.partial(checkResult, responses.getTransaction.trustlineNoQuality,
|
|
||||||
'getTransaction'));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('getTransaction - not validated', function() {
|
|
||||||
const hash =
|
|
||||||
'4FB3ADF22F3C605E23FAEFAA185F3BD763C4692CAC490D9819D117CD33BFAA10';
|
|
||||||
return this.api.getTransaction(hash).then(() => {
|
|
||||||
assert(false, 'Should throw NotFoundError');
|
|
||||||
}).catch(error => {
|
|
||||||
assert(error instanceof this.api.errors.NotFoundError);
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('getTransaction - tracking on', function() {
|
it('getTransaction - settings', function() {
|
||||||
const hash =
|
const hash =
|
||||||
'8925FC8844A1E930E2CC76AD0A15E7665AFCC5425376D548BB1413F484C31B8C';
|
'4FB3ADF22F3C605E23FAEFAA185F3BD763C4692CAC490D9819D117CD33BFAA1B';
|
||||||
return this.api.getTransaction(hash).then(
|
return this.api.getTransaction(hash).then(
|
||||||
_.partial(checkResult, responses.getTransaction.trackingOn,
|
_.partial(checkResult, responses.getTransaction.settings,
|
||||||
|
'getTransaction'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getTransaction - order', function() {
|
||||||
|
const hash =
|
||||||
|
'10A6FB4A66EE80BED46AAE4815D7DC43B97E944984CCD5B93BCF3F8538CABC51';
|
||||||
|
return this.api.getTransaction(hash).then(
|
||||||
|
_.partial(checkResult, responses.getTransaction.order,
|
||||||
'getTransaction'));
|
'getTransaction'));
|
||||||
});
|
|
||||||
|
|
||||||
it('getTransaction - tracking off', function() {
|
|
||||||
const hash =
|
|
||||||
'C8C5E20DFB1BF533D0D81A2ED23F0A3CBD1EF2EE8A902A1D760500473CC9C582';
|
|
||||||
return this.api.getTransaction(hash).then(
|
|
||||||
_.partial(checkResult, responses.getTransaction.trackingOff,
|
|
||||||
'getTransaction'));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('getTransaction - set regular key', function() {
|
|
||||||
const hash =
|
|
||||||
'278E6687C1C60C6873996210A6523564B63F2844FB1019576C157353B1813E60';
|
|
||||||
return this.api.getTransaction(hash).then(
|
|
||||||
_.partial(checkResult, responses.getTransaction.setRegularKey,
|
|
||||||
'getTransaction'));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('getTransaction - not found in range', function() {
|
|
||||||
const hash =
|
|
||||||
'809335DD3B0B333865096217AA2F55A4DF168E0198080B3A090D12D88880FF0E';
|
|
||||||
const options = {
|
|
||||||
minLedgerVersion: 32570,
|
|
||||||
maxLedgerVersion: 32571
|
|
||||||
};
|
|
||||||
return this.api.getTransaction(hash, options).then(() => {
|
|
||||||
assert(false, 'Should throw NotFoundError');
|
|
||||||
}).catch(error => {
|
|
||||||
assert(error instanceof this.api.errors.NotFoundError);
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('getTransaction - not found by hash', function() {
|
it('getTransaction - order cancellation', function() {
|
||||||
const hash = hashes.NOTFOUND_TRANSACTION_HASH;
|
const hash =
|
||||||
return this.api.getTransaction(hash).then(() => {
|
'809335DD3B0B333865096217AA2F55A4DF168E0198080B3A090D12D88880FF0E';
|
||||||
assert(false, 'Should throw NotFoundError');
|
return this.api.getTransaction(hash).then(
|
||||||
}).catch(error => {
|
_.partial(checkResult, responses.getTransaction.orderCancellation,
|
||||||
assert(error instanceof this.api.errors.NotFoundError);
|
'getTransaction'));
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('getTransaction - missing ledger history', function() {
|
it('getTransaction - trustline set', function() {
|
||||||
const hash = hashes.NOTFOUND_TRANSACTION_HASH;
|
const hash =
|
||||||
// make gaps in history
|
'635A0769BD94710A1F6A76CDE65A3BC661B20B798807D1BBBDADCEA26420538D';
|
||||||
this.api.remote.getServer().emit('message', ledgerClosed);
|
return this.api.getTransaction(hash).then(
|
||||||
return this.api.getTransaction(hash).then(() => {
|
_.partial(checkResult, responses.getTransaction.trustline,
|
||||||
assert(false, 'Should throw MissingLedgerHistoryError');
|
'getTransaction'));
|
||||||
}).catch(error => {
|
|
||||||
assert(error instanceof this.api.errors.MissingLedgerHistoryError);
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('getTransaction - ledger_index not found', function() {
|
it('getTransaction - trustline frozen off', function() {
|
||||||
const hash =
|
const hash =
|
||||||
'4FB3ADF22F3C605E23FAEFAA185F3BD763C4692CAC490D9819D117CD33BFAA11';
|
'FE72FAD0FA7CA904FB6C633A1666EDF0B9C73B2F5A4555D37EEF2739A78A531B';
|
||||||
return this.api.getTransaction(hash).then(() => {
|
return this.api.getTransaction(hash).then(
|
||||||
assert(false, 'Should throw NotFoundError');
|
_.partial(checkResult, responses.getTransaction.trustlineFrozenOff,
|
||||||
}).catch(error => {
|
'getTransaction'));
|
||||||
assert(error instanceof this.api.errors.NotFoundError);
|
|
||||||
assert(error.message.indexOf('ledger_index') !== -1);
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('getTransaction - transaction ledger not found', function() {
|
it('getTransaction - trustline no quality', function() {
|
||||||
const hash =
|
const hash =
|
||||||
'4FB3ADF22F3C605E23FAEFAA185F3BD763C4692CAC490D9819D117CD33BFAA12';
|
'BAF1C678323C37CCB7735550C379287667D8288C30F83148AD3C1CB019FC9002';
|
||||||
return this.api.getTransaction(hash).then(() => {
|
return this.api.getTransaction(hash).then(
|
||||||
assert(false, 'Should throw NotFoundError');
|
_.partial(checkResult, responses.getTransaction.trustlineNoQuality,
|
||||||
}).catch(error => {
|
'getTransaction'));
|
||||||
assert(error instanceof this.api.errors.NotFoundError);
|
|
||||||
assert(error.message.indexOf('ledger not found') !== -1);
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('getTransaction - ledger missing close time', function() {
|
it('getTransaction - not validated', function() {
|
||||||
const hash =
|
const hash =
|
||||||
'0F7ED9F40742D8A513AE86029462B7A6768325583DF8EE21B7EC663019DD6A04';
|
'4FB3ADF22F3C605E23FAEFAA185F3BD763C4692CAC490D9819D117CD33BFAA10';
|
||||||
return this.api.getTransaction(hash).then(() => {
|
return this.api.getTransaction(hash).then(() => {
|
||||||
assert(false, 'Should throw ApiError');
|
assert(false, 'Should throw NotFoundError');
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
assert(error instanceof this.api.errors.ApiError);
|
assert(error instanceof this.api.errors.NotFoundError);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getTransaction - tracking on', function() {
|
||||||
|
const hash =
|
||||||
|
'8925FC8844A1E930E2CC76AD0A15E7665AFCC5425376D548BB1413F484C31B8C';
|
||||||
|
return this.api.getTransaction(hash).then(
|
||||||
|
_.partial(checkResult, responses.getTransaction.trackingOn,
|
||||||
|
'getTransaction'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getTransaction - tracking off', function() {
|
||||||
|
const hash =
|
||||||
|
'C8C5E20DFB1BF533D0D81A2ED23F0A3CBD1EF2EE8A902A1D760500473CC9C582';
|
||||||
|
return this.api.getTransaction(hash).then(
|
||||||
|
_.partial(checkResult, responses.getTransaction.trackingOff,
|
||||||
|
'getTransaction'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getTransaction - set regular key', function() {
|
||||||
|
const hash =
|
||||||
|
'278E6687C1C60C6873996210A6523564B63F2844FB1019576C157353B1813E60';
|
||||||
|
return this.api.getTransaction(hash).then(
|
||||||
|
_.partial(checkResult, responses.getTransaction.setRegularKey,
|
||||||
|
'getTransaction'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getTransaction - not found in range', function() {
|
||||||
|
const hash =
|
||||||
|
'809335DD3B0B333865096217AA2F55A4DF168E0198080B3A090D12D88880FF0E';
|
||||||
|
const options = {
|
||||||
|
minLedgerVersion: 32570,
|
||||||
|
maxLedgerVersion: 32571
|
||||||
|
};
|
||||||
|
return this.api.getTransaction(hash, options).then(() => {
|
||||||
|
assert(false, 'Should throw NotFoundError');
|
||||||
|
}).catch(error => {
|
||||||
|
assert(error instanceof this.api.errors.NotFoundError);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getTransaction - not found by hash', function() {
|
||||||
|
const hash = hashes.NOTFOUND_TRANSACTION_HASH;
|
||||||
|
return this.api.getTransaction(hash).then(() => {
|
||||||
|
assert(false, 'Should throw NotFoundError');
|
||||||
|
}).catch(error => {
|
||||||
|
assert(error instanceof this.api.errors.NotFoundError);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getTransaction - missing ledger history', function() {
|
||||||
|
const hash = hashes.NOTFOUND_TRANSACTION_HASH;
|
||||||
|
// make gaps in history
|
||||||
|
this.api.remote.getServer().emit('message', ledgerClosed);
|
||||||
|
return this.api.getTransaction(hash).then(() => {
|
||||||
|
assert(false, 'Should throw MissingLedgerHistoryError');
|
||||||
|
}).catch(error => {
|
||||||
|
assert(error instanceof this.api.errors.MissingLedgerHistoryError);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
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() {
|
||||||
|
const hash =
|
||||||
|
'4FB3ADF22F3C605E23FAEFAA185F3BD763C4692CAC490D9819D117CD33BFAA11';
|
||||||
|
return this.api.getTransaction(hash).then(() => {
|
||||||
|
assert(false, 'Should throw NotFoundError');
|
||||||
|
}).catch(error => {
|
||||||
|
assert(error instanceof this.api.errors.NotFoundError);
|
||||||
|
assert(error.message.indexOf('ledger_index') !== -1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getTransaction - transaction ledger not found', function() {
|
||||||
|
const hash =
|
||||||
|
'4FB3ADF22F3C605E23FAEFAA185F3BD763C4692CAC490D9819D117CD33BFAA12';
|
||||||
|
return this.api.getTransaction(hash).then(() => {
|
||||||
|
assert(false, 'Should throw NotFoundError');
|
||||||
|
}).catch(error => {
|
||||||
|
assert(error instanceof this.api.errors.NotFoundError);
|
||||||
|
assert(error.message.indexOf('ledger not found') !== -1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getTransaction - ledger missing close time', function() {
|
||||||
|
const hash =
|
||||||
|
'0F7ED9F40742D8A513AE86029462B7A6768325583DF8EE21B7EC663019DD6A04';
|
||||||
|
return this.api.getTransaction(hash).then(() => {
|
||||||
|
assert(false, 'Should throw ApiError');
|
||||||
|
}).catch(error => {
|
||||||
|
assert(error instanceof this.api.errors.ApiError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user