async def _get_block_bodies( self, peer: ETHPeer, headers: Tuple[BlockHeader, ...], ) -> Tuple[Tuple[BlockBodyBundle, ...], Tuple[BlockHeader, ...]]: """ Request and return block bodies, pairing them with the associated headers. Store the bodies for later use, during block import (or persist). Note the difference from _request_block_bodies, which only issues the request, and doesn't pair the results with the associated block headers that were successfully delivered. """ block_body_bundles = await self.wait( self._request_block_bodies(peer, headers)) if len(block_body_bundles) == 0: self.logger.debug( "Got block bodies for 0/%d headers from %s, from %r..%r", len(headers), peer, headers[0], headers[-1], ) return tuple(), tuple() bodies_by_root = { (transaction_root, uncles_hash): block_body for block_body, (transaction_root, _), uncles_hash in block_body_bundles } header_roots = { header: (header.transaction_root, header.uncles_hash) for header in headers } completed_header_roots = valfilter(lambda root: root in bodies_by_root, header_roots) completed_headers = tuple(completed_header_roots.keys()) # store bodies for later usage, during block import pending_bodies = { header: bodies_by_root[root] for header, root in completed_header_roots.items() } self._pending_bodies = merge(self._pending_bodies, pending_bodies) self.logger.debug( "Got block bodies for %d/%d headers from %s, from %r..%r", len(completed_header_roots), len(headers), peer, headers[0], headers[-1], ) return block_body_bundles, completed_headers
def filter_params(self) -> FilterParams: params = { "topics": self.topics, "fromBlock": self.fromBlock, "toBlock": self.toBlock, "address": self.address } return valfilter(lambda x: x is not None, params)
def test_signed_transaction(w3, fund_account, transaction, expected, key_object, from_): w3.middleware_onion.add(construct_sign_and_send_raw_middleware(key_object)) # Drop any falsy addresses to_from = valfilter(bool, {'to': w3.eth.accounts[0], 'from': from_}) _transaction = merge(transaction, to_from) if isinstance(expected, type) and issubclass(expected, Exception): with pytest.raises(expected): w3.eth.send_transaction(_transaction) else: start_balance = w3.eth.get_balance( _transaction.get('from', w3.eth.accounts[0])) w3.eth.send_transaction(_transaction) assert w3.eth.get_balance( _transaction.get('from')) <= start_balance + expected
def validate_abi(abi): """ Helper function for validating an ABI """ if not is_list_like(abi): raise ValueError("'abi' is not a list") if not all(is_dict(e) for e in abi): raise ValueError("'abi' is not a list of dictionaries") functions = filter_by_type('function', abi) selectors = groupby(compose(encode_hex, function_abi_to_4byte_selector), functions) duplicates = valfilter(lambda funcs: len(funcs) > 1, selectors) if duplicates: raise ValueError('Abi contains functions with colliding selectors. ' 'Functions {0}'.format( _prepare_selector_collision_msg(duplicates)))
def drop_items_with_none_value(params: Dict[str, Any]) -> Dict[str, Any]: return valfilter(lambda x: x is not None, params)
def drop_items_with_none_value(params): return valfilter(lambda x: x is not None, params)
def copy(self): combined = merge(self.wrapped_db, self.cache) return valfilter(lambda val: val is not DELETED, combined)