add option to not create fresh APIs for every read
This commit is contained in:
+9
-2
@@ -14,6 +14,13 @@ export type PublicKey = string
|
||||
export type Amount = number
|
||||
export type TxHash = string
|
||||
export type Options = {
|
||||
debug: boolean,
|
||||
connectionTimeout: number
|
||||
debug?: boolean
|
||||
connectionTimeout?: number
|
||||
readFreshApi?: boolean
|
||||
}
|
||||
|
||||
export const defaultOptions = {
|
||||
debug: false,
|
||||
connectionTimeout: 100000,
|
||||
readFreshApi: true
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Memo, Options } from '../util/types'
|
||||
import { defaultOptions, Memo, Options } from '../util/types'
|
||||
import { Client, Payment, TxResponse, Wallet } from 'xrpl'
|
||||
|
||||
import * as zlib from 'zlib'
|
||||
@@ -18,11 +18,13 @@ export class xrpIO {
|
||||
|
||||
constructor(
|
||||
private server: string,
|
||||
private options: Options = {
|
||||
debug: false,
|
||||
connectionTimeout: 100000
|
||||
}
|
||||
private options: Options = defaultOptions
|
||||
) {
|
||||
|
||||
this.options.debug = this.options.debug ? Boolean(this.options.debug) : defaultOptions.debug
|
||||
this.options.connectionTimeout = this.options.connectionTimeout ? Number(this.options.connectionTimeout) : defaultOptions.connectionTimeout
|
||||
this.options.readFreshApi = this.options.readFreshApi ? Boolean(this.options.readFreshApi) : defaultOptions.readFreshApi
|
||||
|
||||
this.api = new Client(server, {
|
||||
connectionTimeout: this.options.connectionTimeout
|
||||
})
|
||||
@@ -101,8 +103,9 @@ export class xrpIO {
|
||||
|
||||
private async getTransaction(hash: string): Promise<TxResponse> {
|
||||
this.dbg("Getting Tx", hash)
|
||||
let _api = await this.cloneApi()
|
||||
|
||||
if (this.options.readFreshApi) {
|
||||
let _api = await this.cloneApi()
|
||||
while (true) {
|
||||
try {
|
||||
const response = await _api.request({
|
||||
@@ -117,6 +120,12 @@ export class xrpIO {
|
||||
_api = await this.cloneApi()
|
||||
}
|
||||
}
|
||||
}else{
|
||||
return await this.api.request({
|
||||
command: 'tx',
|
||||
transaction: hash,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
public async readRaw(hash: string): Promise<Memo> {
|
||||
|
||||
@@ -9,8 +9,6 @@ let sendWallet: Wallet
|
||||
let receiveWallet: Wallet
|
||||
let api: xrpIO
|
||||
|
||||
const ONLY_LARGE_TESTS = true
|
||||
|
||||
describe('XRPIO', () => {
|
||||
before(async function(){
|
||||
this.timeout(15000)
|
||||
|
||||
Reference in New Issue
Block a user