Exemplo n.º 1
0
def get_web3(network: str = config["network"],
             provider: str = config["provider"]) -> Web3:
    """
    Get XinFin Web3 instance.

    :param network: XinFin network, defaults to ``mainnet``.
    :type network: str
    :param provider: XinFin network provider, defaults to ``http``.
    :type provider: str

    :returns: Web3 -- XinFin Web3 instance.

    >>> from swap.providers.xinfin.rpc import get_web3
    >>> get_web3(network="testnet", provider="http")
    <web3.main.Web3 object at 0x000001DDECCD0640>
    """

    # Check parameter instances
    if not is_network(network=network):
        raise NetworkError(
            f"Invalid XinFin '{network}' network",
            "choose only 'mainnet', 'apothem' or 'testnet' networks.")

    if provider == "http":
        web3: Web3 = Web3(
            HTTPProvider(endpoint_uri=URI(config[network]["http"]),
                         request_kwargs={"timeout": config["timeout"]}))
        return web3
    elif provider == "websocket":
        web3: Web3 = Web3(
            WebsocketProvider(endpoint_uri=URI(config[network]["websocket"])))
        return web3
    else:
        raise ValueError(f"Invalid XinFin '{provider}' provider",
                         "choose only 'http' or 'websocket' providers.")
Exemplo n.º 2
0
def create_provider_from_config(rpc_config: MutableMapping):
    uri = rpc_config.get("uri", None)
    if uri is not None:
        logger.info(f"Autodetect provider from uri {uri}")
        provider = load_provider_from_uri(uri)
        logger.info(f"Autodetected {provider.__class__.__name__}")
        return provider

    provider_type = rpc_config["type"]
    if provider_type is ProviderType.HTTP:
        url = "{}://{}:{}".format(
            "https" if rpc_config["use_ssl"] else "http",
            rpc_config["host"],
            rpc_config["port"],
        )
        logger.info("Using HTTP provider with URL {}".format(url))
        return HTTPProvider(URI(url))
    elif provider_type is ProviderType.WEBSOCKET:
        url = "{}://{}:{}".format(
            "wss" if rpc_config["use_ssl"] else "ws",
            rpc_config["host"],
            rpc_config["port"],
        )
        logger.info("Using websocket provider with URL {}".format(url))
        return WebsocketProvider(URI(url))
    elif provider_type is ProviderType.IPC:
        file_path = rpc_config["file_path"]
        logger.info("Using IPC provider with file path {}".format(file_path))
        return IPCProvider(file_path)
    else:
        raise ValueError(f"Unknown web3 provider type: {provider_type}")
Exemplo n.º 3
0
def get_web3(network: str = config["network"], provider: str = config["provider"],
             token: Optional[str] = None) -> Web3:
    """
    Get Ethereum Web3 instance.

    :param network: Ethereum network, defaults to ``mainnet``.
    :type network: str
    :param provider: Ethereum network provider, defaults to ``http``.
    :type provider: str
    :param token: Infura API endpoint token, defaults to ``4414fea5f7454211956b1627621450b4``.
    :type token: str

    :returns: Web3 -- Ethereum Web3 instance.

    >>> from swap.providers.ethereum.rpc import get_web3
    >>> get_web3(network="testnet", provider="http", token="infura endpoint token ...")
    <web3.main.Web3 object at 0x000001DDECCD0640>
    """

    # Check parameter instances
    if not is_network(network=network):
        raise NetworkError(f"Invalid Ethereum '{network}' network",
                           "choose only 'mainnet', 'ropsten', 'kovan', 'rinkeby' or 'testnet' networks.")

    endpoint: str = "ganache-cli" if network == "testnet" else "infura"
    token: str = token if token else config[network][endpoint]["token"]

    if provider == "http":
        web3: Web3 = Web3(HTTPProvider(
                URI(
                    f"{config[network]['infura']['http']}/{token}"
                    if token else config[network][endpoint]["http"]
                ),
                request_kwargs={
                    "timeout": config["timeout"]
                }
            )
        )
        return web3
    elif provider == "websocket":
        web3: Web3 = Web3(WebsocketProvider(
                URI(
                    f"{config[network]['infura']['websocket']}/{token}"
                    if token else config[network][endpoint]["websocket"]
                )
            )
        )
        return web3
    else:
        raise ValueError(f"Invalid Ethereum '{provider}' provider",
                         "choose only 'http' or 'websocket' providers.")
Exemplo n.º 4
0
def build_infura_url(domain: str) -> URI:
    scheme = os.environ.get('WEB3_INFURA_SCHEME', WEBSOCKET_SCHEME)
    key = load_api_key()
    secret = load_secret()

    if scheme == WEBSOCKET_SCHEME and secret != '':
        return URI("%s://:%s@%s/ws/v3/%s" % (scheme, secret, domain, key))
    elif scheme == WEBSOCKET_SCHEME and secret == '':
        return URI("%s://%s/ws/v3/%s" % (scheme, domain, key))
    elif scheme == HTTP_SCHEME:
        return URI("%s://%s/v3/%s" % (scheme, domain, key))
    else:
        raise ValidationError("Cannot connect to Infura with scheme %r" %
                              scheme)
Exemplo n.º 5
0
def build_infura_url(domain: str) -> URI:
    scheme = os.environ.get('WEB3_INFURA_SCHEME', WEBSOCKET_SCHEME)
    key = load_api_key()
    secret = load_secret()

    if scheme == WEBSOCKET_SCHEME and secret != '':
        return URI(f"{scheme}://:{secret}@{domain}/ws/v3/{key}")
    elif scheme == WEBSOCKET_SCHEME and secret == '':
        return URI(f"{scheme}://{domain}/ws/v3/{key}")
    elif scheme == HTTP_SCHEME:
        return URI(f"{scheme}://{domain}/v3/{key}")
    else:
        raise ValidationError(
            f"Cannot connect to Infura with scheme {scheme!r}")
Exemplo n.º 6
0
def rpc_normalized_endpoint(eth_rpc_endpoint: str) -> URI:
    parsed_eth_rpc_endpoint = urlparse(eth_rpc_endpoint)

    if "infura.io" in eth_rpc_endpoint:
        # Infura needs to have the https scheme
        return URI(f"https://{parsed_eth_rpc_endpoint.netloc}{parsed_eth_rpc_endpoint.path}")

    if parsed_eth_rpc_endpoint.scheme:
        return URI(eth_rpc_endpoint)

    scheme = "http://"
    if eth_rpc_endpoint.startswith("//"):
        scheme = "http:"

    return URI(f"{scheme}{eth_rpc_endpoint}")
Exemplo n.º 7
0
def get_w3() -> Web3:
    """Set up the web3 provider for serving transactions to the ethereum network.

    >>> w3 = get_w3()
    >>> type(w3)
    <class 'web3.main.Web3'>
    >>> type(w3.provider)
    <class 'web3.providers.rpc.HTTPProvider'>

    >>> os.environ["HMT_ETH_SERVER"] = "wss://localhost:8546"
    >>> w3 = get_w3()
    >>> type(w3)
    <class 'web3.main.Web3'>
    >>> type(w3.provider)
    <class 'web3.providers.websocket.WebsocketProvider'>
    >>> del os.environ["HMT_ETH_SERVER"]

    Returns:
        Web3: returns the web3 provider.

    """
    endpoint = os.getenv("HMT_ETH_SERVER", "http://localhost:8545")
    if not endpoint:
        LOG.error("Using EthereumTesterProvider as we have no HMT_ETH_SERVER")

    provider = (load_provider_from_uri(URI(endpoint))
                if endpoint else EthereumTesterProvider())

    w3 = Web3(provider)
    w3.middleware_onion.inject(geth_poa_middleware, layer=0)
    return w3
Exemplo n.º 8
0
def patched_web3():
    web3 = Web3(HTTPProvider(URI("http://domain/")))
    monkey_patch_web3(web3=web3, gas_price_strategy=rpc_gas_price_strategy)
    original_get_block = Eth.getBlock
    Eth.getBlock = make_patched_web3_get_block(Eth.getBlock)
    yield web3
    Eth.getBlock = original_get_block
Exemplo n.º 9
0
    def __init__(self, token_name: str = 'ETH'):

        self.block_count_to_wait_confirm = ETH_BLOCK_TO_WAIT_FOR_CONFIRM

        self.token_name = token_name

        self.logger = get_default_logger(log_level=logging.INFO)

        engine = create_engine(MYSQL_CONNECT_INFO, max_overflow=0, pool_size=5)
        Session = sessionmaker(bind=engine, autocommit=True, autoflush=False)

        self.session = Session()
        self.redis = redis.Redis(host=REDIS_HOST,
                                 port=REDIS_PORT,
                                 db=REDIS_ADDRESS_POOL_DB_NAME,
                                 decode_responses=True)
        self.myweb3 = Web3(provider=HTTPProvider(
            endpoint_uri=URI(ETH_FULL_NODE_RPC_URL)))

        if not g_IS_MAINNET and ETH_CHAIN_ID == 4:
            self.myweb3.middleware_onion.inject(element=geth_poa_middleware,
                                                layer=0)

        super().__init__()
        pass
Exemplo n.º 10
0
 def __init__(
     self,
     endpoint_uri: Optional[Union[URI, str]] = None,
     websocket_kwargs: Any = None,
     websocket_timeout: int = DEFAULT_WEBSOCKET_TIMEOUT,
 ) -> None:
     self.endpoint_uri = URI(endpoint_uri)
     self.websocket_timeout = websocket_timeout
     if self.endpoint_uri is None:
         self.endpoint_uri = get_default_endpoint()
     if WebsocketProvider._loop is None:
         WebsocketProvider._loop = _get_threaded_loop()
     if websocket_kwargs is None:
         websocket_kwargs = {}
     else:
         found_restricted_keys = set(websocket_kwargs.keys()).intersection(
             RESTRICTED_WEBSOCKET_KWARGS)
         if found_restricted_keys:
             raise ValidationError(
                 '{0} are not allowed in websocket_kwargs, '
                 'found: {1}'.format(RESTRICTED_WEBSOCKET_KWARGS,
                                     found_restricted_keys))
     self.conn = PersistentWebSocket(self.endpoint_uri,
                                     WebsocketProvider._loop,
                                     websocket_kwargs)
     super().__init__()
Exemplo n.º 11
0
 def fetch_uri_contents(self, uri: URI, package_name: str,
                        package_version: str) -> URI:
     manifest = build_etherscan_manifest(uri, package_name, package_version)
     ipfs_backend = get_ipfs_backend()
     ipfs_data = builder.build(manifest, builder.validate(),
                               builder.pin_to_ipfs(backend=ipfs_backend))
     return URI(f"ipfs://{ipfs_data[0]['Hash']}")
Exemplo n.º 12
0
def handle_offchain_lookup(
    offchain_lookup_payload: Dict[str, Any],
    transaction: TxParams,
) -> bytes:
    formatted_sender = to_hex_if_bytes(
        offchain_lookup_payload['sender']).lower()
    formatted_data = to_hex_if_bytes(
        offchain_lookup_payload['callData']).lower()

    if formatted_sender != to_hex_if_bytes(transaction['to']).lower():
        raise ValidationError(
            'Cannot handle OffchainLookup raised inside nested call. Returned `sender` value does '
            'not equal `to` address in transaction.')

    for url in offchain_lookup_payload['urls']:
        formatted_url = URI(
            str(url).replace('{sender}', str(formatted_sender)).replace(
                '{data}', str(formatted_data)))

        try:
            if '{data}' in url and '{sender}' in url:
                response = get_response_from_get_request(formatted_url)
            elif '{sender}' in url:
                response = get_response_from_post_request(formatted_url,
                                                          data={
                                                              "data":
                                                              formatted_data,
                                                              "sender":
                                                              formatted_sender,
                                                          })
            else:
                raise ValidationError('url not formatted properly.')
        except Exception:
            continue  # try next url if timeout or issues making the request

        if 400 <= response.status_code <= 499:  # if request returns 400 error, raise exception
            response.raise_for_status()
        if not 200 <= response.status_code <= 299:  # if not 400 error, try next url
            continue

        result = response.json()

        if 'data' not in result.keys():
            raise ValidationError(
                "Improperly formatted response for offchain lookup HTTP request - missing 'data' "
                "field.")

        encoded_data_with_function_selector = b''.join([
            # 4-byte callback function selector
            to_bytes_if_hex(offchain_lookup_payload['callbackFunction']),

            # encode the `data` from the result and the `extraData` as bytes
            encode_abi(['bytes', 'bytes'], [
                to_bytes_if_hex(result['data']),
                to_bytes_if_hex(offchain_lookup_payload['extraData']),
            ])
        ])

        return encoded_data_with_function_selector
    raise MultipleFailedRequests("Offchain lookup failed for supplied urls.")
Exemplo n.º 13
0
def create_BIP122_uri(
    chain_id: HexStr, resource_type: str, resource_identifier: HexStr
) -> URI:
    """
    See: https://github.com/bitcoin/bips/blob/master/bip-0122.mediawiki
    """
    if resource_type != BLOCK:
        raise ValueError("Invalid resource_type.  Must be one of 'block'")
    elif not is_block_or_transaction_hash(resource_identifier):
        raise ValueError(
            "Invalid resource_identifier.  Must be a hex encoded 32 byte value"
        )
    elif not is_block_or_transaction_hash(chain_id):
        raise ValueError("Invalid chain_id.  Must be a hex encoded 32 byte value")

    return URI(
        parse.urlunsplit(
            [
                "blockchain",
                remove_0x_prefix(chain_id),
                f"{resource_type}/{remove_0x_prefix(resource_identifier)}",
                "",
                "",
            ]
        )
    )
Exemplo n.º 14
0
 def __init__(self, address: str, privkey: str):
     self._address = address
     self._privkey = privkey
     self._web3 = Web3(WebsocketProvider(endpoint_uri=URI(CLIENT_API_URL)))
     checked_contract_address = self._web3.toChecksumAddress(CONTRACT_ADDRESS)
     abi = loads(ABI)
     self._contract = self._web3.eth.contract(abi=abi, address=checked_contract_address)
Exemplo n.º 15
0
 def __init__(self,
              endpoint_uri: Optional[Union[URI, str]] = None,
              request_kwargs: Any = None) -> None:
     if endpoint_uri is None:
         self.endpoint_uri = get_default_endpoint()
     else:
         self.endpoint_uri = URI(endpoint_uri)
     self._request_kwargs = request_kwargs or {}
     super().__init__()
Exemplo n.º 16
0
def setup_testchain(eth_client: EthClient, free_port_generator: Iterator[Port],
                    base_datadir: str,
                    base_logdir: str) -> Iterator[Dict[str, Any]]:

    ensure_executable(eth_client.value)

    rpc_port = next(free_port_generator)
    p2p_port = next(free_port_generator)

    eth_rpc_endpoint = URI(f"http://127.0.0.1:{rpc_port}")
    web3 = Web3(HTTPProvider(endpoint_uri=eth_rpc_endpoint))
    web3.middleware_onion.inject(make_sane_poa_middleware, layer=0)

    eth_nodes = [
        EthNodeDescription(
            private_key=TEST_PRIVKEY,
            rpc_port=rpc_port,
            p2p_port=p2p_port,
            miner=True,
            extra_config={},
            blockchain_type=eth_client.value,
        )
    ]

    random_marker = remove_0x_prefix(HexStr(hex(random.getrandbits(100))))
    genesis_description = GenesisDescription(
        prefunded_accounts=[
            AccountDescription(TEST_ACCOUNT_ADDRESS, DEFAULT_BALANCE)
        ],
        random_marker=random_marker,
        chain_id=CHAINNAME_TO_ID["smoketest"],
    )

    datadir = eth_node_to_datadir(privatekey_to_address(TEST_PRIVKEY),
                                  base_datadir)
    if eth_client is EthClient.GETH:
        keystore = geth_keystore(datadir)
    elif eth_client is EthClient.PARITY:
        keystore = parity_keystore(datadir)

    eth_node_runner = run_private_blockchain(
        web3=web3,
        eth_nodes=eth_nodes,
        base_datadir=base_datadir,
        log_dir=base_logdir,
        verbosity="info",
        genesis_description=genesis_description,
    )
    with eth_node_runner as node_executors:
        yield dict(
            eth_client=eth_client,
            base_datadir=base_datadir,
            eth_rpc_endpoint=eth_rpc_endpoint,
            keystore=keystore,
            node_executors=node_executors,
            web3=web3,
        )
Exemplo n.º 17
0
def erc20_transfer(priv_key : str, from_addr : str,  contract_addr: str,  token_recipient_addr : str,
                   token_amount : float) \
        -> TransferFuncResponse:

    myweb3 = Web3(provider=HTTPProvider(
        endpoint_uri=URI(ETH_FULL_NODE_RPC_URL)))

    # https://web3py.readthedocs.io/en/stable/web3.eth.account.html?highlight=transaction#sign-a-contract-transaction

    chksum_contract_address = to_checksum_address(contract_addr)

    contract = myweb3.eth.contract(address=chksum_contract_address,
                                   abi=EIP20_ABI)

    symbol = contract.functions.symbol().call()
    print(symbol)

    #判断是否是 USDT
    assert str(symbol) == 'USDT', 'only support  USDT'

    decimals = contract.functions.decimals().call()
    print(decimals)

    # myweb3.eth.gasPriceStrategy
    # myweb3.eth.generateGasPrice()
    # myweb3.eth.setGasPriceStrategy()

    from_address = to_checksum_address(from_addr)
    block_identifier = HexStr('pending')
    nonce = myweb3.eth.getTransactionCount(from_address,
                                           block_identifier=block_identifier)

    cur_gas_price = myweb3.eth.gasPrice  # 获取实时手续费
    if cur_gas_price > Web3.toWei(500, 'gwei'):  # 防止手续费过高
        cur_gas_price = Web3.toWei(500, 'gwei')
    elif cur_gas_price < Web3.toWei(50, 'gwei'):  # 防止手续费过小
        cur_gas_price = Web3.toWei(50, 'gwei')

    # assert isinstance(contract.functions, ContractFunctions)
    chksum_token_recipient = to_checksum_address(token_recipient_addr)
    erc20_unsigned_tx = contract.functions.transfer(
        chksum_token_recipient,
        # !!! 注意 : 只支持 ERC20_USDT
        myweb3.toWei(token_amount, 'mwei')) \
        .buildTransaction({
        'chainId': ETH_CHAIN_ID,
        'gas': ERC20_GAS_LIMIT,
        'gasPrice': cur_gas_price,
        'nonce': nonce
    })

    print(erc20_unsigned_tx)

    private_key = priv_key
    return sign_and_sendtransaction(myweb3=myweb3,
                                    unsigned_tranaction=erc20_unsigned_tx,
                                    private_key=private_key)
Exemplo n.º 18
0
 def __init__(self, name: str, rpc_address: str, chain_id: int, b64_private_key: str):
     self.blockchain = "ethereum"
     self.name = name
     self.rpc_address = rpc_address
     self.chain_id = chain_id
     self.priv_key = eth_keys.keys.PrivateKey(base64.b64decode(b64_private_key))
     self.address = self.priv_key.public_key.to_checksum_address()
     self.w3 = web3.Web3(web3.HTTPProvider(URI(self.rpc_address)))
     # Set gas strategy
     self.w3.eth.setGasPriceStrategy(web3.gas_strategies.time_based.medium_gas_price_strategy)
Exemplo n.º 19
0
def pin_local_manifest(manifest_path: Path) -> Tuple[str, str, URI]:
    manifest_output = json.loads(manifest_path.read_text())
    validate_manifest_against_schema(manifest_output)
    package_name = manifest_output["package_name"]
    package_version = manifest_output["version"]

    ipfs_backend = get_ipfs_backend()
    ipfs_data = ipfs_backend.pin_assets(manifest_path)

    manifest_uri = URI(f"ipfs://{ipfs_data[0]['Hash']}")
    return (package_name, package_version, manifest_uri)
Exemplo n.º 20
0
 def fetch_uri_contents(self, uri: str) -> URI:
     """
     Return content-addressed URI stored at registry URI.
     """
     address, chain_id, pkg_name, pkg_version, _ = parse_registry_uri(uri)
     if chain_id != '1':
         # todo: support all testnets
         raise CannotHandleURI(
             "Currently only mainnet registry uris are supported.")
     self.w3.enable_unstable_package_management_api()
     self.w3.pm.set_registry(address)
     _, _, manifest_uri = self.w3.pm.get_release_data(pkg_name, pkg_version)
     return URI(manifest_uri)
Exemplo n.º 21
0
def test_connection_issues() -> None:
    # 641 is a port registered with IANA for this service:
    #
    # repcmd            641/tcp
    # repcmd            641/udp
    #
    # This is a comcast utility agent that is unlikely to be running. The numbe
    # was chosen with. `sum(ord(c) for c in 'random')`

    web3 = Web3(HTTPProvider(URI("http://localhost:641")))

    with pytest.raises(RequestsConnectionError):
        JSONRPCClient(web3=web3, privkey=make_privatekey_bin())
Exemplo n.º 22
0
    def get_package(self, package_name: str, version: str) -> Package:
        """
        Returns a ``Package`` instance, generated by the ``manifest_uri`` associated with the
        given package name and version, if they are published to the currently set registry.

        * Parameters:
            * ``name``: Must be a valid package name.
            * ``version``: Must be a valid package version.
        """
        validate_package_name(package_name)
        validate_package_version(version)
        self._validate_set_registry()
        release_data = self.get_release_data(package_name, version)
        return self.get_package_from_uri(URI(release_data.manifest_uri))
Exemplo n.º 23
0
    def __init__(self,
                 endpoint_uri: Optional[Union[URI, str]] = None,
                 request_kwargs: Optional[Any] = None,
                 session: Optional[Any] = None) -> None:
        if endpoint_uri is None:
            self.endpoint_uri = get_default_endpoint()
        else:
            self.endpoint_uri = URI(endpoint_uri)

        self._request_kwargs = request_kwargs or {}

        if session:
            cache_session(self.endpoint_uri, session)

        super().__init__()
Exemplo n.º 24
0
def web3(
    deploy_key,
    eth_nodes_configuration,
    private_keys,
    account_genesis_eth_balance,
    random_marker,
    tmpdir,
    chain_id,
    logs_storage,
    blockchain_type,
):
    """ Starts a private chain with accounts funded. """
    # include the deploy key in the list of funded accounts
    keys_to_fund = sorted(set(private_keys + [deploy_key]))

    host = "127.0.0.1"
    rpc_port = eth_nodes_configuration[0].rpc_port
    endpoint = f"http://{host}:{rpc_port}"
    web3 = Web3(HTTPProvider(URI(endpoint)))

    accounts_to_fund = [
        AccountDescription(privatekey_to_address(key), account_genesis_eth_balance)
        for key in keys_to_fund
    ]

    # The private chain data is always discarded on the CI
    base_datadir = str(tmpdir)

    # Save the Ethereum node's log for debugging
    base_logdir = os.path.join(logs_storage, blockchain_type)

    genesis_description = GenesisDescription(
        prefunded_accounts=accounts_to_fund, chain_id=chain_id, random_marker=random_marker
    )
    eth_node_runner = run_private_blockchain(
        web3=web3,
        eth_nodes=eth_nodes_configuration,
        base_datadir=base_datadir,
        log_dir=base_logdir,
        verbosity="info",
        genesis_description=genesis_description,
    )
    with eth_node_runner:
        yield web3

    cleanup_tasks()
Exemplo n.º 25
0
def deploy_registry(config: Config, alias: str = None) -> str:
    if not config.private_key:
        raise AuthorizationError(
            "To deploy a registry, you must provide the password for your local keyfile."
        )
    chain_id = config.w3.eth.chainId
    chain_name = SUPPORTED_CHAIN_IDS[chain_id]
    cli_logger.info(
        f"Deploying a new registry to {chain_name}, this may take a minute...")
    # todo: handle tx timeout error gracefully
    registry_address = config.w3.pm.deploy_and_set_registry()
    cli_logger.info(
        f"New registry deployed to {registry_address} on {chain_name}.")
    registry_uri = URI(f"erc1319://{registry_address}:{chain_id}")
    add_registry(registry_uri, alias, config)
    activate_registry(registry_uri, config)
    return registry_address
Exemplo n.º 26
0
def main() -> None:
    tmpdir = tempfile.mkdtemp()

    geth_nodes = []
    for i in range(NUM_GETH_NODES):
        is_miner = i == 0
        node_key = PrivateKey(keccak(f"node:{i}".encode()))
        p2p_port = Port(START_PORT + i)
        rpc_port = Port(START_RPCPORT + i)

        description = EthNodeDescription(
            private_key=node_key,
            rpc_port=rpc_port,
            p2p_port=p2p_port,
            miner=is_miner,
            extra_config={},
        )

        geth_nodes.append(description)

    rpc_endpoint = URI(f"http://127.0.0.1:{START_RPCPORT}")
    web3 = Web3(HTTPProvider(rpc_endpoint))

    random_marker = remove_0x_prefix(HexStr(hex(random.getrandbits(100))))
    genesis_description = GenesisDescription(
        prefunded_accounts=DEFAULT_ACCOUNTS,
        random_marker=random_marker,
        chain_id=ChainID(CHAINNAME_TO_ID["smoketest"]),
    )
    private_chain: ContextManager[
        List[JSONRPCExecutor]] = run_private_blockchain(
            web3=web3,
            eth_nodes=geth_nodes,
            base_datadir=tmpdir,
            log_dir=tmpdir,
            verbosity="info",
            genesis_description=genesis_description,
        )

    with private_chain:
        from IPython import embed

        embed()
Exemplo n.º 27
0
from scenario_player.utils.configuration.settings import (
    EnvironmentConfig,
    PFSSettingsConfig,
    ServiceSettingsConfig,
    SettingsConfig,
    UDCSettingsConfig,
    UDCTokenSettings,
)

dummy_env = EnvironmentConfig(
    pfs_fee=FeeAmount(100),
    environment_file_name="tests",
    environment_type="development",
    matrix_servers=[],
    transfer_token=TokenAddress(bytes([1] * 20)),
    pfs_with_fee=URI("http://www.example.com"),
    eth_rpc_endpoints=[URI("http://www.example.com")],
    ms_reward_with_margin=TokenAmount(1),
    settlement_timeout_min=BlockTimeout(100),
    raiden_client="raiden",
    wait_short=5,
    wait_long=10,
)


class TestSettingsConfig:
    @pytest.mark.parametrize("key", ["timeout", "gas_price"])
    def test_class_returns_expected_default_for_key(
        self, key, expected_defaults, minimal_definition_dict
    ):
        """If supported  keys are absent, sensible defaults are returned for them when accessing
Exemplo n.º 28
0
def get_default_endpoint() -> URI:
    return URI(
        os.environ.get('WEB3_HTTP_PROVIDER_URI', 'http://localhost:8545'))
Exemplo n.º 29
0
def get_default_endpoint() -> URI:
    return URI(
        os.environ.get("FLASHBOTS_HTTP_PROVIDER_URI",
                       "https://relay.flashbots.net"))
Exemplo n.º 30
0
def load_provider_from_environment() -> BaseProvider:
    uri_string = URI(os.environ.get('WEB3_PROVIDER_URI', ''))
    if not uri_string:
        return None

    return load_provider_from_uri(uri_string)