|
@@ -21,9 +21,10 @@ export class xrpIO {
|
21
|
21
|
private options: Options = defaultOptions
|
22
|
22
|
) {
|
23
|
23
|
|
24
|
|
- this.options.debug = this.options.debug ? Boolean(this.options.debug) : defaultOptions.debug
|
25
|
|
- this.options.connectionTimeout = this.options.connectionTimeout ? Number(this.options.connectionTimeout) : defaultOptions.connectionTimeout
|
26
|
|
- this.options.readFreshApi = this.options.readFreshApi ? Boolean(this.options.readFreshApi) : defaultOptions.readFreshApi
|
|
24
|
+ this.options.debug = options.debug ? Boolean(options.debug) : defaultOptions.debug
|
|
25
|
+ this.options.connectionTimeout = options.connectionTimeout ? Number(options.connectionTimeout) : defaultOptions.connectionTimeout
|
|
26
|
+ this.options.readMaxRetry = options.readMaxRetry ? Number(options.readMaxRetry) : defaultOptions.readMaxRetry
|
|
27
|
+ this.options.readRetryTimeout = options.readRetryTimeout ? Number(options.readRetryTimeout) : defaultOptions.readRetryTimeout
|
27
|
28
|
|
28
|
29
|
this.api = new Client(server, {
|
29
|
30
|
connectionTimeout: this.options.connectionTimeout
|
|
@@ -101,30 +102,22 @@ export class xrpIO {
|
101
|
102
|
return tx.result.hash
|
102
|
103
|
}
|
103
|
104
|
|
104
|
|
- private async getTransaction(hash: string): Promise<TxResponse> {
|
|
105
|
+ private async getTransaction(hash: string, retry=0): Promise<TxResponse> {
|
105
|
106
|
this.dbg("Getting Tx", hash)
|
106
|
|
-
|
107
|
|
- if (this.options.readFreshApi) {
|
108
|
|
- let _api = await this.cloneApi()
|
109
|
|
- while (true) {
|
110
|
|
- try {
|
111
|
|
- const response = await _api.request({
|
112
|
|
- command: 'tx',
|
113
|
|
- transaction: hash,
|
114
|
|
- })
|
115
|
|
- await _api.disconnect()
|
116
|
|
- return response
|
117
|
|
- } catch (e) {
|
118
|
|
- this.dbg("Retrying to get", hash)
|
119
|
|
- await _api.disconnect()
|
120
|
|
- _api = await this.cloneApi()
|
121
|
|
- }
|
122
|
|
- }
|
123
|
|
- }else{
|
|
107
|
+ try{
|
124
|
108
|
return await this.api.request({
|
125
|
109
|
command: 'tx',
|
126
|
110
|
transaction: hash,
|
127
|
111
|
})
|
|
112
|
+ }catch(e){
|
|
113
|
+ this.dbg(e)
|
|
114
|
+ if(this.options.readMaxRetry != -1){
|
|
115
|
+ if(retry >= this.options.readMaxRetry)
|
|
116
|
+ console.error("Retry limit exceeded for", hash, ". this is an irrecoverable error")
|
|
117
|
+ throw e
|
|
118
|
+ }
|
|
119
|
+ await new Promise(res => setTimeout(res, this.options.readRetryTimeout))
|
|
120
|
+ return await this.getTransaction(hash, retry+1)
|
128
|
121
|
}
|
129
|
122
|
}
|
130
|
123
|
|