fix: node-fetch issue
MODIFY
package-lock.json
package-lock.json
"resolved": "https://registry.npmjs.org/aws4/-/aws4-1.10.0.tgz",
"integrity": "sha512-3YDiu347mtVtjpyV3u5kVqQLP242c06zwDOgpeRnybmXlYYsLbtTrUBUm8i8srONt+FWobl5aibnU1030PeeuA=="
},
+ "axios": {
+ "version": "0.21.1",
+ "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz",
+ "integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==",
+ "requires": {
+ "follow-redirects": "^1.10.0"
+ }
+ },
"backoff": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/backoff/-/backoff-2.5.0.tgz",
"integrity": "sha1-UhTXU3pNBqSjAcDMJi/rhBiAAuc=",
"dev": true
},
+ "follow-redirects": {
+ "version": "1.13.1",
+ "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.1.tgz",
+ "integrity": "sha512-SSG5xmZh1mkPGyKzjZP8zLjltIfpW32Y5QpdNJyjcfGxK3qo3NDDkZOZSFiGn1A6SclQxY9GzEwAHQ3dmYRWpg=="
+ },
"for-in": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz",
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-2.0.2.tgz",
"integrity": "sha512-Ntyt4AIXyaLIuMHF6IOoTakB3K+RWxwtsHNRxllEoA6vPwP9o4866g6YWDLUdnucilZhmkxiHwHr11gAENw+QA=="
},
- "node-fetch": {
- "version": "2.6.1",
- "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
- "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw=="
- },
"node-gyp-build": {
"version": "4.2.3",
"resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.2.3.tgz",

MODIFY
package.json
package.json
"@types/bluebird": "^3.5.29",
"@types/bn.js": "4.11.5",
"@types/web3": "1.0.19",
+ "axios": "^0.21.1",
"bluebird": "^3.7.1",
"bn.js": "5.0.0",
"debug": "^4.1.1",
"ethereumjs-tx": "1.3.7",
"ethereumjs-util": "^5.2.0",
"merkle-patricia-tree": "2.3.2",
- "node-fetch": "^2.6.1",
"query-string": "6.8.1",
"web3": "^1.3.0"
},

MODIFY
src/common/ExitManager.ts
src/common/ExitManager.ts
import BN from 'bn.js'
import assert from 'assert'
import ethUtils from 'ethereumjs-util'
-import fetch from 'node-fetch'
+import axios from 'axios'
import Web3Client from './Web3Client'
import ContractsBase from './ContractsBase'
@@ -87,17 +87,17 @@ export default class ExitManager extends ContractsBase {
new BN(lastChildBlock).gte(new BN(receipt.blockNumber)),
'Burn transaction has not been checkpointed as yet'
)
- let blockIncludedResponse = await fetch(this.networkApiUrl + '/block-included/' + receipt.blockNumber)
- let headerBlock = await blockIncludedResponse.json()
+ let blockIncludedResponse = await axios.get(this.networkApiUrl + '/block-included/' + receipt.blockNumber)
+ let headerBlock = await blockIncludedResponse.data
// build block proof
const start = parseInt(headerBlock.start, 10)
const end = parseInt(headerBlock.end, 10)
const number = parseInt(receipt.blockNumber + '', 10)
- let blockProofResponse = await fetch(
+ let blockProofResponse = await axios.get(
`${this.networkApiUrl}/block-proof?start=${start}&end=${end}&number=${number}`
)
- const blockProof = (await blockProofResponse.json()).proof
+ const blockProof = (await blockProofResponse.data).proof
const receiptProof: any = await Proofs.getReceiptProof(receipt, block, this.web3Client.getMaticWeb3())
const logIndex = receipt.logs.findIndex(log => log.topics[0].toLowerCase() == logEventSig.toLowerCase())

MODIFY
src/libs/ProofsUtil.ts
src/libs/ProofsUtil.ts
-import fetch from 'node-fetch'
-
+import axios from 'axios'
const BN = require('bn.js')
const bluebird = require('bluebird')
const Trie = require('merkle-patricia-tree')
@@ -45,9 +44,8 @@ export default class ProofsUtil {
}
static async buildBlockHeaderMerkleHermoine(start, end, networkApiUrl) {
- let response = await fetch(networkApiUrl + '/generate-proof?start=' + start + '&end=' + end)
- let logDetails = await response.json()
- let logs = logDetails.merkle_headerblocks
+ let logDetails = await axios.get(networkApiUrl + '/generate-proof?start=' + start + '&end=' + end)
+ let logs = logDetails.data.merkle_headerblocks
const headers = new Array(end - start + 1)
for (let i = 0; i < end - start + 1; i++) {
headers[i] = ProofsUtil.getBlockHeader(logs[i])

fix: node-fetch issue