prepareTransaction should not overwrite Sequence (#990)

* Cleans up some code and fixes some type errors

* Clarify how null settings work

* Document updated RippledError

* Updates per review by @mDuo13
This commit is contained in:
Elliot Lee
2019-03-18 15:55:42 -07:00
committed by GitHub
parent 8213861ab7
commit d82703f41b
30 changed files with 614 additions and 118 deletions

View File

@@ -4,6 +4,7 @@ import parseTransaction from './parse/transaction'
import {validate, errors} from '../common'
import {Connection} from '../common'
import {FormattedTransactionType} from '../transaction/types'
import {RippledError} from '../common/errors'
export type TransactionOptions = {
minLedgerVersion?: number,
@@ -59,10 +60,16 @@ function isTransactionInRange(tx: any, options: TransactionOptions) {
}
function convertError(connection: Connection, options: TransactionOptions,
error: Error
error: RippledError
): Promise<Error> {
const _error = (error.message === 'txnNotFound') ?
new errors.NotFoundError('Transaction not found') : error
let shouldUseNotFoundError = false
if ((error.data && error.data.error === 'txnNotFound') || error.message === 'txnNotFound') {
shouldUseNotFoundError = true
}
// In the future, we should deprecate this error, instead passing through the one from rippled.
const _error = shouldUseNotFoundError ? new errors.NotFoundError('Transaction not found') : error
if (_error instanceof errors.NotFoundError) {
return utils.hasCompleteLedgerRange(connection, options.minLedgerVersion,
options.maxLedgerVersion).then(hasCompleteLedgerRange => {