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

Commit

Permalink
fix(etherscan,rpc): fix require of @cypress/request (#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
legobeat authored Oct 20, 2023
1 parent 5a95dc6 commit a3d4dd6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
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

0 comments on commit a3d4dd6

Please sign in to comment.