예제 #1
0
    def _run_funding(self, configuration_file: RaidenConfigurationFile):
        network = Network.get_by_name(settings.network)

        if not network.FAUCET_AVAILABLE:
            self._send_error_message(
                f"Can not run automatic funding for {network.capitalized_name}"
            )
            return

        account = configuration_file.account
        w3 = make_web3_provider(
            configuration_file.ethereum_client_rpc_endpoint, account)
        self._send_status_update(
            f"Obtaining {network.capitalized_name} ETH through faucet")
        network.fund(account)
        balance = account.wait_for_ethereum_funds(
            w3=w3, expected_amount=EthereumAmount(0.01))
        self._send_status_update(f"Account funded with {balance.formatted}")

        if settings.service_token.mintable:
            service_token = Erc20Token.find_by_ticker(
                settings.service_token.ticker)
            self._send_status_update(f"Minting {service_token.ticker}")
            mint_tokens(w3, account, service_token)

        if settings.transfer_token.mintable:
            transfer_token = Erc20Token.find_by_ticker(
                settings.transfer_token.ticker)
            self._send_status_update(f"Minting {transfer_token.ticker}")
            mint_tokens(w3, account, transfer_token)
예제 #2
0
    def _run_setup(self, **kw):
        form = QuickSetupForm(endpoint=kw.get("endpoint"))
        if form.validate():
            self._send_status_update(
                "Generating new wallet and configuration file for raiden")

            network = Network.get_by_name(form.data["network"])
            url_or_infura_id = form.data["endpoint"].strip()

            if Infura.is_valid_project_id(url_or_infura_id):
                ethereum_rpc_provider = Infura.make(network, url_or_infura_id)
            else:
                ethereum_rpc_provider = EthereumRPCProvider(url_or_infura_id)

            account = Account.create()

            conf_file = RaidenConfigurationFile(
                account,
                network,
                ethereum_rpc_provider.url,
                routing_mode="pfs" if form.data["use_rsb"] else "local",
                enable_monitoring=form.data["use_rsb"],
            )
            conf_file.save()

            if network.FAUCET_AVAILABLE:
                self._run_funding(configuration_file=conf_file)
                self._send_redirect(
                    self.reverse_url("launch", conf_file.file_name))
            else:
                self._send_redirect(
                    self.reverse_url("account", conf_file.file_name))
        else:
            self._send_error_message(
                f"Failed to create account. Error: {form.errors}")
예제 #3
0
    def _run_setup(self, **kw):
        account_file = kw.get("account_file")
        account = Account(account_file, passphrase=get_passphrase())
        form = QuickSetupForm(
            meta=dict(network=self.installer_settings.network),
            endpoint=kw.get("endpoint"))
        if form.validate():
            self._send_status_update(
                "Generating new wallet and configuration file for raiden")

            network = Network.get_by_name(self.installer_settings.network)
            infura_url_or_id = form.data["endpoint"].strip()
            ethereum_rpc_provider = Infura.make(network, infura_url_or_id)

            try:
                check_eth_node_responsivity(ethereum_rpc_provider.url)
            except ValueError as e:
                self._send_error_message(f"Ethereum node unavailable: {e}.")
                return

            conf_file = RaidenConfigurationFile(
                account.keystore_file_path,
                self.installer_settings,
                ethereum_rpc_provider.url,
                routing_mode=self.installer_settings.routing_mode,
                enable_monitoring=self.installer_settings.monitoring_enabled,
            )
            conf_file.save()

            self._send_redirect(
                self.reverse_url("account", conf_file.file_name))
        else:
            self._send_error_message(
                f"Failed to create account. Error: {form.errors}")
예제 #4
0
    def __init__(self, url):
        super().__init__(url)
        if not Infura.is_valid_project_id(self.project_id):
            raise ValueError(f"{url} is not a valid URL and/or infura project")

        if self.network.name not in Network.get_network_names():
            raise ValueError(f"{self.network.name} is no valid ethereum network")
예제 #5
0
    def setUp(self):
        assert INFURA_PROJECT_ID

        self.account = Account.create(TESTING_KEYSTORE_FOLDER,
                                      "test_raiden_integration")
        self.network = Network.get_by_name(self.__class__.NETWORK_NAME)
        self.infura = Infura.make(self.network, INFURA_PROJECT_ID)
        self.w3 = make_web3_provider(self.infura.url, self.account)
예제 #6
0
    def setUp(self):
        assert INFURA_PROJECT_ID

        Account.DEFAULT_KEYSTORE_FOLDER = Path(tempfile.gettempdir())
        self.account = Account.create("test_raiden_integration")
        self.network = Network.get_by_name(self.__class__.NETWORK_NAME)
        self.infura = Infura.make(self.network, INFURA_PROJECT_ID)
        self.w3 = make_web3_provider(self.infura.url, self.account)
 def test_make_infura_provider(self):
     project_id = "36b457de4c103495ada08dc0658db9c3"
     network = Network.get_by_name("mainnet")
     infura = Infura.make(network, project_id)
     self.assertEqual(
         infura.url,
         f"https://{network.name}.infura.io:443/v3/{project_id}")
     self.assertEqual(infura.project_id, project_id)
     self.assertEqual(infura.network.name, network.name)
예제 #8
0
 def render(self, template_name, **context_data):
     network = Network.get_by_name(self.installer_settings.network)
     required = RequiredAmounts.from_settings(self.installer_settings)
     context_data.update({
         "network": network,
         "ethereum_required": required.eth,
         "ethereum_required_after_swap": required.eth_after_swap,
         "service_token_required": required.service_token,
         "transfer_token_required": required.transfer_token,
         "eip20_abi": json.dumps(EIP20_ABI),
     })
     return super().render(template_name, **context_data)
예제 #9
0
 def __init__(self, account_filename: Union[Path, str], settings: Settings,
              ethereum_client_rpc_endpoint: str, **kw):
     self.account = Account(account_filename)
     self.account_filename = account_filename
     self.settings = settings
     self.network = Network.get_by_name(self.settings.network)
     self.ethereum_client_rpc_endpoint = ethereum_client_rpc_endpoint
     self.accept_disclaimer = kw.get("accept_disclaimer", True)
     self.enable_monitoring = kw.get("enable_monitoring",
                                     self.settings.monitoring_enabled)
     self.routing_mode = kw.get("routing_mode", self.settings.routing_mode)
     self.services_version = self.settings.services_version
     self._initial_funding_txhash = kw.get("_initial_funding_txhash")
예제 #10
0
    def setUp(self):
        RaidenConfigurationFile.FOLDER_PATH = TESTING_TEMP_FOLDER.joinpath(
            "config")

        self.account = Account.create(TESTING_KEYSTORE_FOLDER,
                                      passphrase="test_raiden_config")
        self.network = Network.get_by_name("goerli")
        self.settings = load_settings("demo_env")

        self.configuration_file = RaidenConfigurationFile(
            self.account.keystore_file_path,
            self.settings,
            "http://localhost:8545",
        )
예제 #11
0
 def render(self, template_name, **context_data):
     configuration_file = context_data.get('configuration_file')
     if configuration_file:
         network = configuration_file.network
     else:
         network = Network.get_by_name(default_settings.network)
     required = RequiredAmounts.for_network(network.name)
     context_data.update({
         "network": network,
         "ethereum_required": required.eth,
         "service_token_required": required.service_token,
         "transfer_token_required": required.transfer_token,
         "eip20_abi": json.dumps(EIP20_ABI),
     })
     return super().render(template_name, **context_data)
예제 #12
0
    def setUp(self):
        temp_folder_path = Path(tempfile.gettempdir())
        RaidenConfigurationFile.FOLDER_PATH = temp_folder_path

        self.account = Account.create(passphrase="test_raiden_config")
        self.network = Network.get_by_name("goerli")
        self.ethereum_client_rpc_endpoint = "http://localhost:8545"

        self.configuration_file = RaidenConfigurationFile(
            account=self.account,
            network=self.network,
            ethereum_client_rpc_endpoint=self.ethereum_client_rpc_endpoint,
        )

        passphrase_file = PassphraseFile(self.configuration_file.passphrase_file_path)
        passphrase_file.store(self.account.passphrase)
예제 #13
0
def prompt_network_selection(network_list=None):
    networks = network_list or Network.all()
    return single_question_prompt({
        "name":
        "network",
        "type":
        "list",
        "message":
        Messages.input_network_select,
        "choices": [{
            "name": network.capitalized_name,
            "value": network
        } for network in networks],
        "default":
        DEFAULT_NETWORK if DEFAULT_NETWORK in networks else None,
    })
예제 #14
0
    def _run_setup(self, **kw):
        account_file = kw.get("account_file")
        account = Account(account_file)
        passphrase_path = RaidenConfigurationFile.FOLDER_PATH.joinpath(
            f"{account.address}.passphrase.txt")
        passphrase_file = PassphraseFile(passphrase_path)
        passphrase = passphrase_file.retrieve()
        account.passphrase = passphrase
        form = QuickSetupForm(endpoint=kw.get("endpoint"),
                              network=kw.get("network"))
        if form.validate():
            self._send_status_update(
                "Generating new wallet and configuration file for raiden")

            network = Network.get_by_name(form.data["network"])
            url_or_infura_id = form.data["endpoint"].strip()

            if Infura.is_valid_project_id_or_endpoint(url_or_infura_id):
                ethereum_rpc_provider = Infura.make(network, url_or_infura_id)
            else:
                ethereum_rpc_provider = EthereumRPCProvider(url_or_infura_id)

            try:
                check_eth_node_responsivity(ethereum_rpc_provider.url)
            except ValueError as e:
                self._send_error_message(f"Ethereum node unavailable: {e}.")
                return

            conf_file = RaidenConfigurationFile(
                account,
                network,
                ethereum_rpc_provider.url,
                routing_mode="pfs" if form.data["use_rsb"] else "local",
                enable_monitoring=form.data["use_rsb"],
            )
            conf_file.save()

            if network.FAUCET_AVAILABLE:
                self._run_funding(configuration_file=conf_file)
                self._send_redirect(
                    self.reverse_url("launch", conf_file.file_name))
            else:
                self._send_redirect(
                    self.reverse_url("account", conf_file.file_name))
        else:
            self._send_error_message(
                f"Failed to create account. Error: {form.errors}")
예제 #15
0
    def load(cls, file_path: Path):
        file_name, _ = os.path.splitext(os.path.basename(file_path))

        _, _, network_name = file_name.split("-")

        with file_path.open() as config_file:
            data = toml.load(config_file)
            passphrase = PassphraseFile(Path(data["password-file"])).retrieve()
            account = Account(data["keystore-file-path"],
                              passphrase=passphrase)
            return cls(
                account=account,
                ethereum_client_rpc_endpoint=data["eth-rpc-endpoint"],
                network=Network.get_by_name(network_name),
                routing_mode=data["routing-mode"],
                enable_monitoring=data["enable-monitoring"],
            )
예제 #16
0
    def load(cls, file_path: Path):
        file_name, _ = os.path.splitext(os.path.basename(file_path))

        _, _, network_name = file_name.split("-")

        with file_path.open() as config_file:
            data = toml.load(config_file)
            keystore_file_path = Account.find_keystore_file_path(
                data["address"], Path(data["keystore-path"]))
            return cls(
                account_filename=keystore_file_path,
                ethereum_client_rpc_endpoint=data["eth-rpc-endpoint"],
                network=Network.get_by_name(network_name),
                routing_mode=data["routing-mode"],
                enable_monitoring=data["enable-monitoring"],
                _initial_funding_txhash=data.get("_initial_funding_txhash"),
            )
예제 #17
0
 def test_get_network_by_chain_id(self):
     for name, cid in CHAIN_ID_MAPPING.items():
         network = Network.get_by_chain_id(cid)
         self.assertEqual(network.name, name)
         self.assertEqual(network.chain_id, cid)
예제 #18
0
    RequiredAmounts,
    SwapAmounts,
    TokenAmount,
    Wei,
)
from raiden_installer.transactions import (
    get_token_balance,
    get_token_deposit,
    get_total_token_owned,
)
from raiden_installer.utils import TransactionTimeoutError, wait_for_transaction

SETTINGS = "mainnet"

NETWORKS_WITH_TOKEN_SWAP = [
    Network.get_by_name(n) for n in ["mainnet", "goerli"]
]


class TokenExchangeForm(Form):
    exchange = wtforms.SelectField(choices=[("kyber",
                                             "Kyber"), ("uniswap", "Uniswap")])
    network = wtforms.SelectField(choices=[(n.name, n.capitalized_name)
                                           for n in NETWORKS_WITH_TOKEN_SWAP])
    token_ticker = wtforms.StringField()
    token_amount = wtforms.IntegerField()


class MainAsyncTaskHandler(AsyncTaskHandler):
    def initialize(self):
        super().initialize()
예제 #19
0
from raiden_installer.constants import WEB3_TIMEOUT
from raiden_installer.ethereum_rpc import Infura, make_web3_provider
from raiden_installer.network import Network
from raiden_installer.token_exchange import ExchangeError, Uniswap
from raiden_installer.tokens import Erc20Token, EthereumAmount, TokenAmount
from raiden_installer.transactions import approve, get_token_balance, mint_tokens
from raiden_installer.uniswap.web3 import contracts as uniswap_contracts
from raiden_installer.utils import send_raw_transaction, wait_for_transaction
from tests.constants import TESTING_KEYSTORE_FOLDER
from tests.fixtures import create_account, test_account, test_password
from tests.utils import empty_account

INFURA_PROJECT_ID = os.getenv("TEST_RAIDEN_INSTALLER_INFURA_PROJECT_ID")

NETWORK = Network.get_by_name("goerli")
WIZ_TOKEN = Erc20Token.find_by_ticker("WIZ", NETWORK.name)
GAS_LIMIT = 120_000


pytestmark = pytest.mark.skipif(not INFURA_PROJECT_ID, reason="missing configuration for infura")


def fund_account(account, w3):
    NETWORK.fund(account)
    account.wait_for_ethereum_funds(w3, EthereumAmount(0.01))


def generateDeadline(w3):
    current_timestamp = w3.eth.getBlock('latest')['timestamp']
    return current_timestamp + WEB3_TIMEOUT
예제 #20
0
 def _get_network(self):
     return Network.get_by_name(settings.network)
예제 #21
0
 def infura(self, test_account, network_name):
     assert INFURA_PROJECT_ID
     network = Network.get_by_name(network_name)
     return Infura.make(network, INFURA_PROJECT_ID)
예제 #22
0
from whaaaaat import ValidationError, Validator, prompt

from raiden_contracts.constants import CONTRACT_USER_DEPOSIT
from raiden_installer.account import Account
from raiden_installer.base import RaidenConfigurationFile
from raiden_installer.ethereum_rpc import EthereumRPCProvider, Infura, make_web3_provider
from raiden_installer.raiden import RaidenClient
from raiden_installer.network import FundingError, Network
from raiden_installer.token_exchange import Exchange
from raiden_installer.tokens import Erc20Token, Wei, TokenAmount
from raiden_installer.utils import get_contract_address

ETHEREUM_RPC_ENDPOINTS = []
DEFAULT_INFURA_PROJECT_ID = os.getenv("RAIDEN_INSTALLER_INFURA_PROJECT_ID")

DEFAULT_NETWORK = Network.get_default()

RELEASE_MAP = RaidenClient.get_all_releases()

if DEFAULT_INFURA_PROJECT_ID:
    ETHEREUM_RPC_ENDPOINTS.append(
        Infura.make(DEFAULT_NETWORK, DEFAULT_INFURA_PROJECT_ID))


class Messages:
    action_launch_raiden = "Launch raiden"
    action_account_create = "Create new ethereum account"
    action_account_list = "List existing ethereum accounts"
    action_account_fund = "Add funds to account"
    action_configuration_setup = "Create new raiden setup"
    action_configuration_list = "List existing raiden setups"
예제 #23
0
    Wei,
)
from raiden_installer.transactions import (
    deposit_service_tokens,
    get_token_balance,
    get_token_deposit,
    get_total_token_owned,
    mint_tokens,
)
from raiden_installer.utils import check_eth_node_responsivity

DEBUG = "RAIDEN_INSTALLER_DEBUG" in os.environ
PORT = 8080

AVAILABLE_NETWORKS = [
    Network.get_by_name(n) for n in ["mainnet", "ropsten", "goerli"]
]
NETWORKS_WITH_TOKEN_SWAP = [
    Network.get_by_name(n) for n in ["mainnet", "ropsten", "goerli"]
]
DEFAULT_NETWORK = Network.get_default()

RESOURCE_FOLDER_PATH = get_resource_folder_path()


class QuickSetupForm(Form):
    network = wtforms.HiddenField("Network", default=DEFAULT_NETWORK.name)
    use_rsb = wtforms.HiddenField("Use Raiden Service Bundle",
                                  default=default_settings.monitoring_enabled)
    endpoint = wtforms.StringField("Infura Project ID/RPC Endpoint")
예제 #24
0
 def test_cannot_run_funding_on_mainnet(self):
     network = Network.get_by_name("mainnet")
     with self.assertRaises(NotImplementedError):
         network.fund(self.account)
예제 #25
0
 def test_get_network_names(self):
     self.assertEqual(Network.get_network_names(), list(CHAIN_ID_MAPPING.keys()))
예제 #26
0
    get_token_deposit,
    get_total_token_owned,
)
from raiden_installer.utils import (
    check_eth_node_responsivity,
    recover_ld_library_env_path,
    wait_for_transaction,
)

DEBUG = "RAIDEN_INSTALLER_DEBUG" in os.environ

RESOURCE_FOLDER_PATH = get_resource_folder_path()

EIP20_ABI = ContractManager(
    contracts_precompiled_path()).get_contract_abi("StandardToken")
AVAILABLE_NETWORKS = [Network.get_by_name(n) for n in ["mainnet", "goerli"]]

PASSPHRASE: Optional[str] = None


def get_passphrase() -> Optional[str]:
    return PASSPHRASE


def set_passphrase(passphrase: Optional[str]):
    global PASSPHRASE
    PASSPHRASE = passphrase


def try_unlock(account):
    passphrase = get_passphrase()
예제 #27
0
 def network(self):
     network_name = urlparse(self.url).netloc.split(".")[0]
     return Network.get_by_name(network_name.lower())
예제 #28
0
 def network(self):
     return Network.get_by_chain_id(self.chain_id)
예제 #29
0
)
from raiden_installer.transactions import (
    deposit_service_tokens,
    get_token_balance,
    get_total_token_owned,
    get_token_deposit,
    mint_tokens,
)
from raiden_installer.utils import check_eth_node_responsivity


DEBUG = "RAIDEN_INSTALLER_DEBUG" in os.environ
PORT = 8080


AVAILABLE_NETWORKS = [Network.get_by_name(n) for n in ["mainnet", "ropsten", "goerli"]]
NETWORKS_WITH_TOKEN_SWAP = [Network.get_by_name(n) for n in ["mainnet", "ropsten"]]
DEFAULT_NETWORK = Network.get_default()
RAIDEN_CLIENT = RaidenClient.get_client()

RESOURCE_FOLDER_PATH = get_resource_folder_path()


class QuickSetupForm(Form):
    network = wtforms.HiddenField("Network", default=DEFAULT_NETWORK.name)
    use_rsb = wtforms.HiddenField("Use Raiden Service Bundle", default=settings.monitoring_enabled)
    endpoint = wtforms.StringField("Infura Project ID/RPC Endpoint")

    def validate_network(self, field):
        network_name = field.data
        if network_name not in [n.name for n in AVAILABLE_NETWORKS]: