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 Amount = number
|
||||||
export type TxHash = string
|
export type TxHash = string
|
||||||
export type Options = {
|
export type Options = {
|
||||||
debug: boolean,
|
debug?: boolean
|
||||||
connectionTimeout: number
|
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 { Client, Payment, TxResponse, Wallet } from 'xrpl'
|
||||||
|
|
||||||
import * as zlib from 'zlib'
|
import * as zlib from 'zlib'
|
||||||
@@ -18,11 +18,13 @@ export class xrpIO {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private server: string,
|
private server: string,
|
||||||
private options: Options = {
|
private options: Options = defaultOptions
|
||||||
debug: false,
|
|
||||||
connectionTimeout: 100000
|
|
||||||
}
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
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, {
|
this.api = new Client(server, {
|
||||||
connectionTimeout: this.options.connectionTimeout
|
connectionTimeout: this.options.connectionTimeout
|
||||||
})
|
})
|
||||||
@@ -101,8 +103,9 @@ export class xrpIO {
|
|||||||
|
|
||||||
private async getTransaction(hash: string): Promise<TxResponse> {
|
private async getTransaction(hash: string): Promise<TxResponse> {
|
||||||
this.dbg("Getting Tx", hash)
|
this.dbg("Getting Tx", hash)
|
||||||
let _api = await this.cloneApi()
|
|
||||||
|
|
||||||
|
if (this.options.readFreshApi) {
|
||||||
|
let _api = await this.cloneApi()
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
const response = await _api.request({
|
const response = await _api.request({
|
||||||
@@ -117,6 +120,12 @@ export class xrpIO {
|
|||||||
_api = await this.cloneApi()
|
_api = await this.cloneApi()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
return await this.api.request({
|
||||||
|
command: 'tx',
|
||||||
|
transaction: hash,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async readRaw(hash: string): Promise<Memo> {
|
public async readRaw(hash: string): Promise<Memo> {
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ let sendWallet: Wallet
|
|||||||
let receiveWallet: Wallet
|
let receiveWallet: Wallet
|
||||||
let api: xrpIO
|
let api: xrpIO
|
||||||
|
|
||||||
const ONLY_LARGE_TESTS = true
|
|
||||||
|
|
||||||
describe('XRPIO', () => {
|
describe('XRPIO', () => {
|
||||||
before(async function(){
|
before(async function(){
|
||||||
this.timeout(15000)
|
this.timeout(15000)
|
||||||
|
|||||||
Reference in New Issue
Block a user