Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

sync v16.x changes #463

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

## [16.0.7]

### Fixed

- Properly replace vulnerable dependency `request` with patched `@cypress/request` ([#459](https://github.com/MetaMask/web3-provider-engine/pull/459))

## [16.0.6]

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web3-provider-engine",
"version": "16.0.6",
"version": "16.0.7",
"description": "A JavaScript library for composing Ethereum provider objects using middleware modules",
"repository": "https://github.com/MetaMask/web3-provider-engine",
"main": "index.js",
Expand Down
24 changes: 12 additions & 12 deletions subproviders/etherscan.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* - eth_listTransactions (non-standard)
*/

const xhr = process.browser ? require('xhr') : require('request')
const xhr = process.browser ? require('xhr') : require('@cypress/request')
const inherits = require('util').inherits
const Subprovider = require('./subprovider.js')

Expand All @@ -38,18 +38,18 @@ function EtherscanProvider(opts) {
this.times = isNaN(opts.times) ? 4 : opts.times;
this.interval = isNaN(opts.interval) ? 1000 : opts.interval;
this.retryFailed = typeof opts.retryFailed === 'boolean' ? opts.retryFailed : true; // not built yet

setInterval(this.handleRequests, this.interval, this);
}

EtherscanProvider.prototype.handleRequests = function(self){
if(self.requests.length == 0) return;

//console.log('Handling the next ' + self.times + ' of ' + self.requests.length + ' requests');

for(var requestIndex = 0; requestIndex < self.times; requestIndex++) {
var requestItem = self.requests.shift()

if(typeof requestItem !== 'undefined')
handlePayload(requestItem.proto, requestItem.network, requestItem.payload, requestItem.next, requestItem.end)
}
Expand All @@ -58,15 +58,15 @@ EtherscanProvider.prototype.handleRequests = function(self){
EtherscanProvider.prototype.handleRequest = function(payload, next, end){
var requestObject = {proto: this.proto, network: this.network, payload: payload, next: next, end: end},
self = this;

if(this.retryFailed)
requestObject.end = function(err, result){
if(err === '403 - Forbidden: Access is denied.')
self.requests.push(requestObject);
else
end(err, result);
};

this.requests.push(requestObject);
}

Expand Down Expand Up @@ -189,7 +189,7 @@ function toQueryString(params) {

function etherscanXHR(useGetMethod, proto, network, module, action, params, end) {
var uri = proto + '://' + network + '.etherscan.io/api?' + toQueryString({ module: module, action: action }) + '&' + toQueryString(params)

xhr({
uri: uri,
method: useGetMethod ? 'GET' : 'POST',
Expand All @@ -202,19 +202,19 @@ function etherscanXHR(useGetMethod, proto, network, module, action, params, end)
// console.log('[etherscan] response: ', err)

if (err) return end(err)
/*console.log('[etherscan request]'

/*console.log('[etherscan request]'
+ ' method: ' + useGetMethod
+ ' proto: ' + proto
+ ' network: ' + network
+ ' module: ' + module
+ ' action: ' + action
+ ' params: ' + params
+ ' return body: ' + body);*/

if(body.indexOf('403 - Forbidden: Access is denied.') > -1)
return end('403 - Forbidden: Access is denied.')

var data
try {
data = JSON.parse(body)
Expand Down
2 changes: 1 addition & 1 deletion subproviders/rpc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const xhr = process.browser ? require('xhr') : require('request')
const xhr = process.browser ? require('xhr') : require('@cypress/request')
const inherits = require('util').inherits
const createPayload = require('../util/create-payload.js')
const Subprovider = require('./subprovider.js')
Expand Down