Ejemplo n.º 1
0
def setup_house(request):
    """Setup different networks supported by the instance.

    Setup house wallets on each network.

    Setup ETH giveaway on testnet and private testnet.
    """

    dbsession = request.dbsession

    services = ServiceCore.parse_network_config(request)
    networks = services.keys()

    for network_name in networks:

        print("Setting up house wallet on ", network_name)

        network = get_eth_network(dbsession, network_name)
        assert is_network_alive(network), "Network was dead when we started to create address {}".format(network)

        dbsession.flush()
        house_address = get_house_address(network)

        if not house_address:
            create_house_address(network)

        if not "initial_assets" in network.other_data:
            network.other_data["initial_assets"] = {}

        if network_name == "testnet":
            network.other_data["human_friendly_name"] = "Ethereum Testnet"

        # Setup testnet ETH give away
        if network_name in ("testnet", "private testnet"):
            network.other_data["initial_assets"]["eth_amount"] = "5.0"
Ejemplo n.º 2
0
def ensure_networks_online(request):
    """Give time to ethereum-service process to catch up.

    Don't go forward until we have confirmed that Ethereum service is alive and talking to us.
    """
    services = ServiceCore.parse_network_config(request)
    networks = services.keys()

    while True:
        remaining_networks = []
        network_stats = []

        for network_name in networks:
            with transaction.manager:
                network = get_eth_network(request.dbsession, network_name)
                if not is_network_alive(network):
                    remaining_networks.append(network_name)
                    network_stats.append(dump_network_heartbeat(network))

        if remaining_networks:
            print("Waiting ethereum-service to wake up for networks ", network_stats)
            time.sleep(15)
            networks = remaining_networks
        else:
            break

    print("All networks green")
Ejemplo n.º 3
0
def setup_house(request):
    """Setup different networks supported by the instance.

    Setup house wallets on each network.

    Setup ETH giveaway on testnet and private testnet.
    """

    dbsession = request.dbsession

    services = ServiceCore.parse_network_config(request)
    networks = services.keys()

    for network_name in networks:

        print("Setting up house wallet on ", network_name)

        network = get_eth_network(dbsession, network_name)
        assert is_network_alive(network), "Network was dead when we started to create address {}".format(network)

        dbsession.flush()
        house_address = get_house_address(network)

        if not house_address:
            create_house_address(network)

        if not "initial_assets" in network.other_data:
            network.other_data["initial_assets"] = {}

        if network_name == "testnet":
            network.other_data["human_friendly_name"] = "Ethereum Testnet"

        # Setup testnet ETH give away
        if network_name in ("testnet", "private testnet"):
            network.other_data["initial_assets"]["eth_amount"] = "5.0"
Ejemplo n.º 4
0
def ensure_networks_online(request):
    """Give time to ethereum-service process to catch up.

    Don't go forward until we have confirmed that Ethereum service is alive and talking to us.
    """
    services = ServiceCore.parse_network_config(request)
    networks = services.keys()

    while True:
        remaining_networks = []
        network_stats = []

        for network_name in networks:
            with transaction.manager:
                network = get_eth_network(request.dbsession, network_name)
                if not is_network_alive(network):
                    remaining_networks.append(network_name)
                    network_stats.append(dump_network_heartbeat(network))

        if remaining_networks:
            print("Waiting ethereum-service to wake up for networks ", network_stats)
            time.sleep(15)
            networks = remaining_networks
        else:
            break

    print("All networks green")
Ejemplo n.º 5
0
def testnet_network_id(dbsession):
    """Get id for Ethereum test AssetNetwork."""

    asset_network_name = "testnet"

    with transaction.manager:
        network = get_eth_network(dbsession, asset_network_name)
        return network.id
Ejemplo n.º 6
0
def setup_networks(request):
    """Setup network objects.
    """

    dbsession = request.dbsession
    for network_name in ["ethereum", "testnet", "private testnet"]:
        network = get_eth_network(dbsession, network_name)
        print("Network database created ", network)
Ejemplo n.º 7
0
def testnet_network_id(dbsession):
    """Get id for Ethereum test AssetNetwork."""

    asset_network_name = "testnet"

    with transaction.manager:
        network = get_eth_network(dbsession, asset_network_name)
        return network.id
Ejemplo n.º 8
0
def setup_networks(request):
    """Setup network objects.
    """

    dbsession = request.dbsession
    for network_name in ["ethereum", "testnet", "private testnet"]:
        network = get_eth_network(dbsession, network_name)
        print("Network database created ", network)
Ejemplo n.º 9
0
def setup_toybox(request):
    """Setup TOYBOX asset for testing."""

    print("Setting up TOYBOX asset")

    dbsession = request.dbsession
    network = get_eth_network(dbsession, "testnet")
    toybox = get_toy_box(network)
    if toybox:
        return

    # Roll out toybox contract
    asset = create_token(network, "Toybox", "TOYBOX", 10222333, get_house_address(network))

    # setup toybox give away data for primary network
    network.other_data["initial_assets"]["toybox"] = str(asset.id)
    network.other_data["initial_assets"]["toybox_amount"] = 50
Ejemplo n.º 10
0
def setup_toybox(request):
    """Setup TOYBOX asset for testing."""

    print("Setting up TOYBOX asset")

    dbsession = request.dbsession
    network = get_eth_network(dbsession, "testnet")
    toybox = get_toy_box(network)
    if toybox:
        return

    # Roll out toybox contract
    asset = create_token(network, "Toybox", "TOYBOX", 10222333, get_house_address(network))

    # setup toybox give away data for primary network
    network.other_data["initial_assets"]["toybox"] = str(asset.id)
    network.other_data["initial_assets"]["toybox_amount"] = 50
Ejemplo n.º 11
0
    def setup(self, dbsession=None):
        request = self.request

        if not dbsession:
            dbsession = create_dbsession(request.registry)

        logger.info("Setting up Ethereum service %s with dbsession %s", self, dbsession)

        self.web3 = self.create_web3()

        with dbsession.transaction_manager:
            network = get_eth_network(dbsession, self.name)
            network_id = network.id

        self.geth = self.start_geth()
        self.service = EthereumService(self.web3, network_id, dbsession, request.registry)
        self.do_unlock()

        logger.info("setup() complete")
Ejemplo n.º 12
0
def eth_network_id(dbsession):
    """Get id for Ethereum primary AssetNetwork."""
    with transaction.manager:
        network = get_eth_network(dbsession)
        # Used by create_address op in MockEthereumService
        network.other_data["test_address_pool"] = [
            "0x2f70d3d26829e412a602e83fe8eebf80255aeea5",
            "0x5589C14FbC92A73809fBCfF33Ab40eFc7E8E8467",
            "0x7bd2f95cefada49141a7f467f40c42f94e3c7338"
        ]

        network.other_data["test_txid_pool"] = [
            "0x00df829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcf",
            "0x00df829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dce",
            "0x00df829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcd",
            "0x00df829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcc",
            "0x00df829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcb",
        ]

        return network.id
Ejemplo n.º 13
0
def eth_network_id(dbsession):
    """Get id for Ethereum primary AssetNetwork."""
    with transaction.manager:
        network = get_eth_network(dbsession)
        # Used by create_address op in MockEthereumService
        network.other_data["test_address_pool"] = [
            "0x2f70d3d26829e412a602e83fe8eebf80255aeea5",
            "0x5589C14FbC92A73809fBCfF33Ab40eFc7E8E8467",
            "0x7bd2f95cefada49141a7f467f40c42f94e3c7338"
        ]

        network.other_data["test_txid_pool"] = [
            "0x00df829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcf",
            "0x00df829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dce",
            "0x00df829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcd",
            "0x00df829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcc",
            "0x00df829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcb",
        ]

        return network.id
Ejemplo n.º 14
0
def get_default_balance(request):
    """Get ETH balance in Ethereum network."""

    user = request.user

    if not user:
        return None

    asset = get_ether_asset(request.dbsession)
    network = get_eth_network(request.dbsession)
    default_address = UserCryptoAddress.get_default(user, network)
    if not default_address:
        return format_asset_amount(Decimal(0), asset.asset_class)

    account = default_address.get_crypto_account(asset)

    if account:
        return format_asset_amount(account.account.get_balance(), asset.asset_class)
    else:
        return format_asset_amount(Decimal(0), asset.asset_class)
Ejemplo n.º 15
0
    def setup(self, dbsession=None):
        request = self.request

        if not dbsession:
            dbsession = create_dbsession(request.registry)

        logger.info("Setting up Ethereum service %s with dbsession %s", self, dbsession)

        host = self.config["host"]
        port = int(self.config["port"])
        self.web3 = web3 = Web3(KeepAliveRPCProvider(host, port, connection_timeout=20, network_timeout=20))

        with dbsession.transaction_manager:
            network = get_eth_network(dbsession, self.name)
            network_id = network.id

        self.geth = self.start_geth()
        self.service = EthereumService(web3, network_id, dbsession, request.registry)
        self.do_unlock()

        logger.info("setup() complete")
Ejemplo n.º 16
0
def get_default_balance(request):
    """Get ETH balance in Ethereum network."""

    return "0"

    # TODO: Breaks test_scan_crowdsale_payments_one_participant_paid_with_email

    user = request.user

    if not user:
        return None

    asset = get_ether_asset(request.dbsession)
    network = get_eth_network(request.dbsession)
    default_address = UserCryptoAddress.get_default(user, network)
    if not default_address:
        return format_asset_amount(Decimal(0), asset.asset_class)

    account = default_address.get_crypto_account(asset)

    if account:
        return format_asset_amount(account.account.get_balance(), asset.asset_class)
    else:
        return format_asset_amount(Decimal(0), asset.asset_class)