From 0296c2b8401f0845c02612725bd51eade8d31ce4 Mon Sep 17 00:00:00 2001 From: Sebastian Pape <0xneo11@gmail.com> Date: Tue, 10 Sep 2024 16:49:59 +0200 Subject: [PATCH] v10.18.15: only rotate rpc provider if batch limit has been reached --- dev.html | 2 +- dist/esm/index.evm.js | 8 +++++--- dist/esm/index.js | 8 +++++--- dist/umd/index.evm.js | 8 +++++--- dist/umd/index.js | 8 +++++--- package.evm.json | 4 ++-- package.json | 6 +++--- package.solana.json | 4 ++-- src/clients/ethers/provider.js | 4 +++- yarn.lock | 8 ++++---- 10 files changed, 35 insertions(+), 25 deletions(-) diff --git a/dev.html b/dev.html index 3910016..33b30fe 100644 --- a/dev.html +++ b/dev.html @@ -8,7 +8,7 @@ - + diff --git a/dist/esm/index.evm.js b/dist/esm/index.evm.js index c892a79..a9deff8 100644 --- a/dist/esm/index.evm.js +++ b/dist/esm/index.evm.js @@ -131,7 +131,9 @@ class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider { ).then((response)=>{ if(response.ok) { response.json().then((parsedJson)=>{ - if(parsedJson.find((entry)=>_optionalChain$2([entry, 'optionalAccess', _ => _.error]))) { + if(parsedJson.find((entry)=>{ + return _optionalChain$2([entry, 'optionalAccess', _ => _.error]) && [-32062].includes(_optionalChain$2([entry, 'optionalAccess', _2 => _2.error, 'optionalAccess', _3 => _3.code])) + })) { if(attempt < MAX_RETRY) { reject('Error in batch found!'); } else { @@ -159,12 +161,12 @@ class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider { // on whether it was a success or error chunk.forEach((inflightRequest, index) => { const payload = result[index]; - if (_optionalChain$2([payload, 'optionalAccess', _2 => _2.error])) { + if (_optionalChain$2([payload, 'optionalAccess', _4 => _4.error])) { const error = new Error(payload.error.message); error.code = payload.error.code; error.data = payload.error.data; inflightRequest.reject(error); - } else if(_optionalChain$2([payload, 'optionalAccess', _3 => _3.result])) { + } else if(_optionalChain$2([payload, 'optionalAccess', _5 => _5.result])) { inflightRequest.resolve(payload.result); } else { inflightRequest.reject(); diff --git a/dist/esm/index.js b/dist/esm/index.js index 486caca..74dea39 100644 --- a/dist/esm/index.js +++ b/dist/esm/index.js @@ -74,7 +74,9 @@ class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider { ).then((response)=>{ if(response.ok) { response.json().then((parsedJson)=>{ - if(parsedJson.find((entry)=>_optionalChain$5([entry, 'optionalAccess', _ => _.error]))) { + if(parsedJson.find((entry)=>{ + return _optionalChain$5([entry, 'optionalAccess', _ => _.error]) && [-32062].includes(_optionalChain$5([entry, 'optionalAccess', _2 => _2.error, 'optionalAccess', _3 => _3.code])) + })) { if(attempt < MAX_RETRY$1) { reject('Error in batch found!'); } else { @@ -102,12 +104,12 @@ class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider { // on whether it was a success or error chunk.forEach((inflightRequest, index) => { const payload = result[index]; - if (_optionalChain$5([payload, 'optionalAccess', _2 => _2.error])) { + if (_optionalChain$5([payload, 'optionalAccess', _4 => _4.error])) { const error = new Error(payload.error.message); error.code = payload.error.code; error.data = payload.error.data; inflightRequest.reject(error); - } else if(_optionalChain$5([payload, 'optionalAccess', _3 => _3.result])) { + } else if(_optionalChain$5([payload, 'optionalAccess', _5 => _5.result])) { inflightRequest.resolve(payload.result); } else { inflightRequest.reject(); diff --git a/dist/umd/index.evm.js b/dist/umd/index.evm.js index a7e2e5a..168f47c 100644 --- a/dist/umd/index.evm.js +++ b/dist/umd/index.evm.js @@ -138,7 +138,9 @@ ).then((response)=>{ if(response.ok) { response.json().then((parsedJson)=>{ - if(parsedJson.find((entry)=>_optionalChain$2([entry, 'optionalAccess', _ => _.error]))) { + if(parsedJson.find((entry)=>{ + return _optionalChain$2([entry, 'optionalAccess', _ => _.error]) && [-32062].includes(_optionalChain$2([entry, 'optionalAccess', _2 => _2.error, 'optionalAccess', _3 => _3.code])) + })) { if(attempt < MAX_RETRY) { reject('Error in batch found!'); } else { @@ -166,12 +168,12 @@ // on whether it was a success or error chunk.forEach((inflightRequest, index) => { const payload = result[index]; - if (_optionalChain$2([payload, 'optionalAccess', _2 => _2.error])) { + if (_optionalChain$2([payload, 'optionalAccess', _4 => _4.error])) { const error = new Error(payload.error.message); error.code = payload.error.code; error.data = payload.error.data; inflightRequest.reject(error); - } else if(_optionalChain$2([payload, 'optionalAccess', _3 => _3.result])) { + } else if(_optionalChain$2([payload, 'optionalAccess', _5 => _5.result])) { inflightRequest.resolve(payload.result); } else { inflightRequest.reject(); diff --git a/dist/umd/index.js b/dist/umd/index.js index 3b50f81..60d5cc7 100644 --- a/dist/umd/index.js +++ b/dist/umd/index.js @@ -80,7 +80,9 @@ ).then((response)=>{ if(response.ok) { response.json().then((parsedJson)=>{ - if(parsedJson.find((entry)=>_optionalChain$5([entry, 'optionalAccess', _ => _.error]))) { + if(parsedJson.find((entry)=>{ + return _optionalChain$5([entry, 'optionalAccess', _ => _.error]) && [-32062].includes(_optionalChain$5([entry, 'optionalAccess', _2 => _2.error, 'optionalAccess', _3 => _3.code])) + })) { if(attempt < MAX_RETRY$1) { reject('Error in batch found!'); } else { @@ -108,12 +110,12 @@ // on whether it was a success or error chunk.forEach((inflightRequest, index) => { const payload = result[index]; - if (_optionalChain$5([payload, 'optionalAccess', _2 => _2.error])) { + if (_optionalChain$5([payload, 'optionalAccess', _4 => _4.error])) { const error = new Error(payload.error.message); error.code = payload.error.code; error.data = payload.error.data; inflightRequest.reject(error); - } else if(_optionalChain$5([payload, 'optionalAccess', _3 => _3.result])) { + } else if(_optionalChain$5([payload, 'optionalAccess', _5 => _5.result])) { inflightRequest.resolve(payload.result); } else { inflightRequest.reject(); diff --git a/package.evm.json b/package.evm.json index 4321df4..f698bd0 100644 --- a/package.evm.json +++ b/package.evm.json @@ -1,7 +1,7 @@ { "name": "@depay/web3-client-evm", "moduleName": "Web3Client", - "version": "10.18.14", + "version": "10.18.15", "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", @@ -23,7 +23,7 @@ "homepage": "https://depay.com", "private": false, "peerDependencies": { - "@depay/web3-blockchains": "^9.5.2", + "@depay/web3-blockchains": "^9.5.3", "ethers": "^5.7.1" }, "engines": { diff --git a/package.json b/package.json index eafa3ff..597ba60 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@depay/web3-client", "moduleName": "Web3Client", - "version": "10.18.14", + "version": "10.18.15", "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", @@ -34,7 +34,7 @@ "private": false, "peerDependencies": { "@depay/solana-web3.js": "^1.26.0", - "@depay/web3-blockchains": "^9.5.2", + "@depay/web3-blockchains": "^9.5.3", "ethers": "^5.7.1" }, "engines": { @@ -44,7 +44,7 @@ "@babel/core": "^7.12.9", "@babel/preset-env": "^7.12.7", "@depay/solana-web3.js": "^1.26.0", - "@depay/web3-blockchains": "^9.5.2", + "@depay/web3-blockchains": "^9.5.3", "@depay/web3-mock": "^14.18.0", "@rollup/plugin-commonjs": "^22.0.1", "@rollup/plugin-json": "^4.1.0", diff --git a/package.solana.json b/package.solana.json index 9933cbc..b9a2668 100644 --- a/package.solana.json +++ b/package.solana.json @@ -1,7 +1,7 @@ { "name": "@depay/web3-client-solana", "moduleName": "Web3Client", - "version": "10.18.14", + "version": "10.18.15", "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", @@ -23,7 +23,7 @@ "homepage": "https://depay.com", "private": false, "peerDependencies": { - "@depay/web3-blockchains": "^9.5.2", + "@depay/web3-blockchains": "^9.5.3", "@depay/solana-web3.js": "^1.26.0", "ethers": "^5.7.1" }, diff --git a/src/clients/ethers/provider.js b/src/clients/ethers/provider.js index aee3602..e8b0c7c 100644 --- a/src/clients/ethers/provider.js +++ b/src/clients/ethers/provider.js @@ -49,7 +49,9 @@ class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider { ).then((response)=>{ if(response.ok) { response.json().then((parsedJson)=>{ - if(parsedJson.find((entry)=>entry?.error)) { + if(parsedJson.find((entry)=>{ + return entry?.error && [-32062].includes(entry?.error?.code) + })) { if(attempt < MAX_RETRY) { reject('Error in batch found!') } else { diff --git a/yarn.lock b/yarn.lock index 88f1e2d..1aa1b9d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -908,10 +908,10 @@ resolved "https://registry.yarnpkg.com/@depay/web3-blockchains/-/web3-blockchains-9.1.4.tgz#f006c29c887c433e1824e2bfabf8f39ad13da907" integrity sha512-CQnXCNAt3sA1MphZDMPbrhAPtemzeQ/NKeHcd2aBF61nTjJCRUmSh1Ox8Z6rlSjgDP66842iy6JAoRiFDtlmFw== -"@depay/web3-blockchains@^9.5.2": - version "9.5.2" - resolved "https://registry.yarnpkg.com/@depay/web3-blockchains/-/web3-blockchains-9.5.2.tgz#f19d0ededa3b059f21af455e2d5b280f23f07575" - integrity sha512-GocEM5I9aBFGrQ0mRAFlZd65SNMKYLAGzYJAE+UnYxTt1gA3p7eYI90VMxAp1KF+T38VAGEZLElilIql9Gb0QQ== +"@depay/web3-blockchains@^9.5.3": + version "9.5.3" + resolved "https://registry.yarnpkg.com/@depay/web3-blockchains/-/web3-blockchains-9.5.3.tgz#6669bfe2cb4ea7708649393ac43e60a2b9a1dce5" + integrity sha512-ZVSMoHaLTJVRwSlegXFiySN7AXOZS4SvnVlOPuPsvZh0c4KE3fDncNMdACds/A/x8pa+adEROeouwCrOuFq7Dw== "@depay/web3-mock@^14.18.0": version "14.18.0"