import ProviderEngine from 'web3-provider-engine' ; import Web3Subprovider from 'web3-provider-engine/subproviders/provider.js' ; import Web3 from 'web3' ; export default class HttpProvider { constructor ( url ) { let engine = new ProviderEngine ( ) ; engine . _blockTracker . _setSkipCacheFlag = false ; let httpProvider = new Web3 . providers . HttpProvider ( url ) ; httpProvider . sendAsync = httpProvider . send ; let subprovider = new Web3Subprovider ( httpProvider ) ; subprovider . handleRequest = function ( payload , _next , end ) { if ( typeof payload . skipCache !== 'undefined' ) { delete payload . skipCache ; } this . provider . sendAsync ( payload , function ( err , response ) { if ( err ) { return end ( err ) ; } if ( response . error ) { return end ( new Error ( `error: ${ response . error . message }, received from payload ${ JSON . stringify ( payload ) }` ) ) ; } end ( null , response . result ) ; } ) ; } . bind ( subprovider ) ; engine . addProvider ( subprovider ) ; engine . send = engine . sendAsync ; engine . start ( ) ; return engine ; } }