def _get_trace(self) -> None: """Retrieves the stack trace via debug_traceTransaction and finds the return value, revert message and event logs in the trace. """ # check if trace has already been retrieved, or the tx warrants it if self._raw_trace is not None: return self._raw_trace = [] if self.input == "0x" and self.gas_used == 21000: self._modified_state = False self._trace = [] return try: trace = web3.provider.make_request( # type: ignore "debug_traceTransaction", (self.txid, {"disableStorage": CONFIG.mode != "console"}) ) except (requests.exceptions.Timeout, requests.exceptions.ConnectionError) as e: msg = f"Encountered a {type(e).__name__} while requesting " msg += "debug_traceTransaction. The local RPC client has likely crashed." if CONFIG.argv["coverage"]: msg += " If the error persists, add the skip_coverage fixture to this test." raise RPCRequestError(msg) from None if "error" in trace: self.modified_state = None raise RPCRequestError(trace["error"]["message"]) self._raw_trace = trace = trace["result"]["structLogs"] if not trace: self._modified_state = False elif self.status: self._confirmed_trace(trace) else: self._reverted_trace(trace)
def _request(method: str, args: List) -> int: try: response = web3.provider.make_request(method, args) # type: ignore if "result" in response: return response["result"] except (AttributeError, RequestsConnectionError): raise RPCRequestError("Web3 is not connected.") raise RPCRequestError(response["error"]["message"])
def _request(self, method: str, args: List) -> int: if not self.is_active(): raise SystemError("RPC is not active.") try: response = web3.provider.make_request(method, args) # type: ignore if "result" in response: return response["result"] except AttributeError: raise RPCRequestError("Web3 is not connected.") raise RPCRequestError(response["error"]["message"])
def _request(self, *args): if not self.is_active(): raise SystemError("RPC is not active.") try: response = web3.providers[0].make_request(*args) if 'result' in response: return response['result'] except IndexError: raise RPCRequestError("Web3 is not connected.") raise RPCRequestError(response['error']['message'])
def _get_trace(self): '''Retrieves the stack trace via debug_traceTransaction and finds the return value, revert message and event logs in the trace. ''' # check if trace has already been retrieved, or the tx warrants it if self._trace is not None: return self.return_value = None if 'revert_msg' not in self.__dict__: self.revert_msg = None self._trace = [] if (self.input == "0x" and self.gas_used == 21000) or self.contract_address: self.modified_state = bool(self.contract_address) self.trace = [] return try: trace = web3.providers[0].make_request( 'debug_traceTransaction', (self.txid, { 'disableStorage': ARGV['cli'] != "console" })) except (requests.exceptions.Timeout, requests.exceptions.ConnectionError) as e: msg = f"Encountered a {type(e).__name__} while requesting " msg += "debug_traceTransaction. The local RPC client has likely crashed." if ARGV['coverage']: msg += " If the error persists, import brownie.test.skipcoverage" msg += " and apply @skipcoverage to this test." raise RPCRequestError(msg) from None if 'error' in trace: self.modified_state = None raise RPCRequestError(trace['error']['message']) self._trace = trace = trace['result']['structLogs'] if not trace: self.modified_state = False elif self.status: self._confirmed_trace(trace) else: self._reverted_trace(trace)
def evm_compatible(self, version): '''Returns a boolean indicating if the given version is compatible with the currently active EVM version.''' if not self.is_active(): raise RPCRequestError("RPC is not active") try: return EVM_VERSIONS.index(version) <= EVM_VERSIONS.index( self.evm_version()) except ValueError: raise ValueError(f"Unknown EVM version: '{version}'") from None
def evm_compatible(self, version: str) -> bool: """Returns a boolean indicating if the given version is compatible with the currently active EVM version.""" if not self.is_active(): raise RPCRequestError("RPC is not active") version = EVM_EQUIVALENTS.get(version, version) try: return EVM_VERSIONS.index(version) <= EVM_VERSIONS.index( # type: ignore self.evm_version() ) except ValueError: raise ValueError(f"Unknown EVM version: '{version}'") from None
def get_gas_price(self) -> Generator[int, None, None]: query = "{ pending { transactions { gasPrice }}}" while True: response = requests.post(self.graphql_endpoint, json={"query": query}) response.raise_for_status() if "error" in response.json(): raise RPCRequestError("could not fetch mempool, run geth with `--graphql` flag") data = response.json()["data"]["pending"]["transactions"] prices = sorted((int(x["gasPrice"], 16) for x in data), reverse=True) yield prices[: self.position][-1]