Skip to content

Commit

Permalink
v10.18.2: handle failing chunk requests (evm)
Browse files Browse the repository at this point in the history
  • Loading branch information
10xSebastian committed Sep 8, 2023
1 parent 4177c55 commit f6ca90d
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 151 deletions.
68 changes: 38 additions & 30 deletions dist/esm/index.evm.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,38 +80,46 @@ class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider {
}

requestChunk(chunk, endpoint) {

const request = chunk.map((inflight) => inflight.request);

return ethers.utils.fetchJson(endpoint, JSON.stringify(request))
.then((result) => {
// For each result, feed it to the correct Promise, depending
// on whether it was a success or error
chunk.forEach((inflightRequest, index) => {
const payload = result[index];
if (_optionalChain$1([payload, 'optionalAccess', _ => _.error])) {
const error = new Error(payload.error.message);
error.code = payload.error.code;
error.data = payload.error.data;
inflightRequest.reject(error);
} else if(_optionalChain$1([payload, 'optionalAccess', _2 => _2.result])) {
inflightRequest.resolve(payload.result);

try {

const request = chunk.map((inflight) => inflight.request);
return ethers.utils.fetchJson(endpoint, JSON.stringify(request))
.then((result) => {
// For each result, feed it to the correct Promise, depending
// on whether it was a success or error
chunk.forEach((inflightRequest, index) => {
const payload = result[index];
if (_optionalChain$1([payload, 'optionalAccess', _ => _.error])) {
const error = new Error(payload.error.message);
error.code = payload.error.code;
error.data = payload.error.data;
inflightRequest.reject(error);
} else if(_optionalChain$1([payload, 'optionalAccess', _2 => _2.result])) {
inflightRequest.resolve(payload.result);
} else {
inflightRequest.reject();
}
});
}).catch((error) => {
if(error && error.code == 'SERVER_ERROR') {
const index = this._endpoints.indexOf(this._endpoint)+1;
this._failover();
this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index];
this.requestChunk(chunk, this._endpoint);
} else {
inflightRequest.reject();
chunk.forEach((inflightRequest) => {
inflightRequest.reject(error);
});
}
});
}).catch((error) => {
if(error && error.code == 'SERVER_ERROR') {
const index = this._endpoints.indexOf(this._endpoint)+1;
this._failover();
this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index];
this.requestChunk(chunk, this._endpoint);
} else {
chunk.forEach((inflightRequest) => {
inflightRequest.reject(error);
});
}
})
})

} catch (e) {

chunk.forEach((inflightRequest) => {
inflightRequest.reject();
});
}
}

send(method, params) {
Expand Down
68 changes: 38 additions & 30 deletions dist/esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,38 +46,46 @@ class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider {
}

requestChunk(chunk, endpoint) {

const request = chunk.map((inflight) => inflight.request);

return ethers.utils.fetchJson(endpoint, JSON.stringify(request))
.then((result) => {
// For each result, feed it to the correct Promise, depending
// on whether it was a success or error
chunk.forEach((inflightRequest, index) => {
const payload = result[index];
if (_optionalChain$3([payload, 'optionalAccess', _ => _.error])) {
const error = new Error(payload.error.message);
error.code = payload.error.code;
error.data = payload.error.data;
inflightRequest.reject(error);
} else if(_optionalChain$3([payload, 'optionalAccess', _2 => _2.result])) {
inflightRequest.resolve(payload.result);

try {

const request = chunk.map((inflight) => inflight.request);
return ethers.utils.fetchJson(endpoint, JSON.stringify(request))
.then((result) => {
// For each result, feed it to the correct Promise, depending
// on whether it was a success or error
chunk.forEach((inflightRequest, index) => {
const payload = result[index];
if (_optionalChain$3([payload, 'optionalAccess', _ => _.error])) {
const error = new Error(payload.error.message);
error.code = payload.error.code;
error.data = payload.error.data;
inflightRequest.reject(error);
} else if(_optionalChain$3([payload, 'optionalAccess', _2 => _2.result])) {
inflightRequest.resolve(payload.result);
} else {
inflightRequest.reject();
}
});
}).catch((error) => {
if(error && error.code == 'SERVER_ERROR') {
const index = this._endpoints.indexOf(this._endpoint)+1;
this._failover();
this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index];
this.requestChunk(chunk, this._endpoint);
} else {
inflightRequest.reject();
chunk.forEach((inflightRequest) => {
inflightRequest.reject(error);
});
}
});
}).catch((error) => {
if(error && error.code == 'SERVER_ERROR') {
const index = this._endpoints.indexOf(this._endpoint)+1;
this._failover();
this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index];
this.requestChunk(chunk, this._endpoint);
} else {
chunk.forEach((inflightRequest) => {
inflightRequest.reject(error);
});
}
})
})

} catch (e) {

chunk.forEach((inflightRequest) => {
inflightRequest.reject();
});
}
}

send(method, params) {
Expand Down
68 changes: 38 additions & 30 deletions dist/umd/index.evm.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,38 +87,46 @@
}

requestChunk(chunk, endpoint) {

const request = chunk.map((inflight) => inflight.request);

return ethers.ethers.utils.fetchJson(endpoint, JSON.stringify(request))
.then((result) => {
// For each result, feed it to the correct Promise, depending
// on whether it was a success or error
chunk.forEach((inflightRequest, index) => {
const payload = result[index];
if (_optionalChain$1([payload, 'optionalAccess', _ => _.error])) {
const error = new Error(payload.error.message);
error.code = payload.error.code;
error.data = payload.error.data;
inflightRequest.reject(error);
} else if(_optionalChain$1([payload, 'optionalAccess', _2 => _2.result])) {
inflightRequest.resolve(payload.result);

try {

const request = chunk.map((inflight) => inflight.request);
return ethers.ethers.utils.fetchJson(endpoint, JSON.stringify(request))
.then((result) => {
// For each result, feed it to the correct Promise, depending
// on whether it was a success or error
chunk.forEach((inflightRequest, index) => {
const payload = result[index];
if (_optionalChain$1([payload, 'optionalAccess', _ => _.error])) {
const error = new Error(payload.error.message);
error.code = payload.error.code;
error.data = payload.error.data;
inflightRequest.reject(error);
} else if(_optionalChain$1([payload, 'optionalAccess', _2 => _2.result])) {
inflightRequest.resolve(payload.result);
} else {
inflightRequest.reject();
}
});
}).catch((error) => {
if(error && error.code == 'SERVER_ERROR') {
const index = this._endpoints.indexOf(this._endpoint)+1;
this._failover();
this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index];
this.requestChunk(chunk, this._endpoint);
} else {
inflightRequest.reject();
chunk.forEach((inflightRequest) => {
inflightRequest.reject(error);
});
}
});
}).catch((error) => {
if(error && error.code == 'SERVER_ERROR') {
const index = this._endpoints.indexOf(this._endpoint)+1;
this._failover();
this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index];
this.requestChunk(chunk, this._endpoint);
} else {
chunk.forEach((inflightRequest) => {
inflightRequest.reject(error);
});
}
})
})

} catch (e) {

chunk.forEach((inflightRequest) => {
inflightRequest.reject();
});
}
}

send(method, params) {
Expand Down
68 changes: 38 additions & 30 deletions dist/umd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,38 +52,46 @@
}

requestChunk(chunk, endpoint) {

const request = chunk.map((inflight) => inflight.request);

return ethers.ethers.utils.fetchJson(endpoint, JSON.stringify(request))
.then((result) => {
// For each result, feed it to the correct Promise, depending
// on whether it was a success or error
chunk.forEach((inflightRequest, index) => {
const payload = result[index];
if (_optionalChain$3([payload, 'optionalAccess', _ => _.error])) {
const error = new Error(payload.error.message);
error.code = payload.error.code;
error.data = payload.error.data;
inflightRequest.reject(error);
} else if(_optionalChain$3([payload, 'optionalAccess', _2 => _2.result])) {
inflightRequest.resolve(payload.result);

try {

const request = chunk.map((inflight) => inflight.request);
return ethers.ethers.utils.fetchJson(endpoint, JSON.stringify(request))
.then((result) => {
// For each result, feed it to the correct Promise, depending
// on whether it was a success or error
chunk.forEach((inflightRequest, index) => {
const payload = result[index];
if (_optionalChain$3([payload, 'optionalAccess', _ => _.error])) {
const error = new Error(payload.error.message);
error.code = payload.error.code;
error.data = payload.error.data;
inflightRequest.reject(error);
} else if(_optionalChain$3([payload, 'optionalAccess', _2 => _2.result])) {
inflightRequest.resolve(payload.result);
} else {
inflightRequest.reject();
}
});
}).catch((error) => {
if(error && error.code == 'SERVER_ERROR') {
const index = this._endpoints.indexOf(this._endpoint)+1;
this._failover();
this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index];
this.requestChunk(chunk, this._endpoint);
} else {
inflightRequest.reject();
chunk.forEach((inflightRequest) => {
inflightRequest.reject(error);
});
}
});
}).catch((error) => {
if(error && error.code == 'SERVER_ERROR') {
const index = this._endpoints.indexOf(this._endpoint)+1;
this._failover();
this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index];
this.requestChunk(chunk, this._endpoint);
} else {
chunk.forEach((inflightRequest) => {
inflightRequest.reject(error);
});
}
})
})

} catch (e) {

chunk.forEach((inflightRequest) => {
inflightRequest.reject();
});
}
}

send(method, params) {
Expand Down
2 changes: 1 addition & 1 deletion package.evm.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@depay/web3-client-evm",
"moduleName": "Web3Client",
"version": "10.18.1",
"version": "10.18.2",
"description": "A web3 client to fetch blockchain data just like you are used to with HTTP clients.",
"main": "dist/umd/index.evm.js",
"module": "dist/esm/index.evm.js",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@depay/web3-client",
"moduleName": "Web3Client",
"version": "10.18.1",
"version": "10.18.2",
"description": "A web3 client to fetch blockchain data just like you are used to with HTTP clients.",
"main": "dist/umd/index.js",
"module": "dist/esm/index.js",
Expand Down
2 changes: 1 addition & 1 deletion package.solana.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@depay/web3-client-solana",
"moduleName": "Web3Client",
"version": "10.18.1",
"version": "10.18.2",
"description": "A web3 client to fetch blockchain data just like you are used to with HTTP clients.",
"main": "dist/umd/index.solana.js",
"module": "dist/esm/index.solana.js",
Expand Down
Loading

0 comments on commit f6ca90d

Please sign in to comment.