コード例 #1
0
ファイル: smartcontracts.py プロジェクト: realflash7/raiden
def deploy_token(
    deploy_client: JSONRPCClient,
    contract_manager: ContractManager,
    initial_amount: typing.TokenAmount,
    decimals: int,
    token_name: str,
    token_symbol: str,
) -> ContractProxy:
    token_address = deploy_contract_web3(
        contract_name=CONTRACT_HUMAN_STANDARD_TOKEN,
        deploy_client=deploy_client,
        contract_manager=contract_manager,
        constructor_arguments=(
            initial_amount,
            decimals,
            token_name,
            token_symbol,
        ),
    )

    contract_abi = contract_manager.get_contract_abi(
        CONTRACT_HUMAN_STANDARD_TOKEN)
    return deploy_client.new_contract_proxy(
        contract_interface=contract_abi,
        contract_address=token_address,
    )
コード例 #2
0
ファイル: blockchain.py プロジェクト: christianbrb/raiden
def unregistered_token(token_amount, deploy_client,
                       contract_manager) -> TokenAddress:
    return TokenAddress(
        deploy_contract_web3(
            CONTRACT_HUMAN_STANDARD_TOKEN,
            deploy_client,
            contract_manager=contract_manager,
            constructor_arguments=(token_amount, 2, "raiden", "Rd"),
        ))
コード例 #3
0
ファイル: smartcontracts.py プロジェクト: realflash7/raiden
def deploy_tokens_and_fund_accounts(
    token_amount: int,
    number_of_tokens: int,
    deploy_service: BlockChainService,
    participants: typing.List[typing.Address],
    contract_manager: ContractManager,
) -> typing.List[typing.TokenAddress]:
    """ Deploy `number_of_tokens` ERC20 token instances with `token_amount` minted and
    distributed among `blockchain_services`. Optionally the instances will be registered with
    the raiden registry.

    Args:
        token_amount (int): number of units that will be created per token
        number_of_tokens (int): number of token instances that will be created
        deploy_service (BlockChainService): the blockchain connection that will deploy
        participants (list(address)): participant addresses that will receive tokens
    """
    result = list()
    for _ in range(number_of_tokens):
        token_address = deploy_contract_web3(
            CONTRACT_HUMAN_STANDARD_TOKEN,
            deploy_service.client,
            contract_manager=contract_manager,
            constructor_arguments=(
                token_amount,
                2,
                'raiden',
                'Rd',
            ),
        )

        result.append(token_address)

        # only the creator of the token starts with a balance (deploy_service),
        # transfer from the creator to the other nodes
        for transfer_to in participants:
            deploy_service.token(token_address).transfer(
                to_address=transfer_to,
                amount=token_amount // len(participants),
                given_block_identifier='latest',
            )

    return result
コード例 #4
0
    def create_token(
            self,
            registry_address,
            initial_alloc=10 ** 6,
            name='raidentester',
            symbol='RDT',
            decimals=2,
            timeout=60,
            auto_register=True,
    ):
        """ Create a proxy for a new HumanStandardToken (ERC20), that is
        initialized with Args(below).
        Per default it will be registered with 'raiden'.

        Args:
            initial_alloc (int): amount of initial tokens.
            name (str): human readable token name.
            symbol (str): token shorthand symbol.
            decimals (int): decimal places.
            timeout (int): timeout in seconds for creation.
            auto_register (boolean): if True(default), automatically register
                the token with raiden.

        Returns:
            token_address_hex: the hex encoded address of the new token/token.
        """
        with gevent.Timeout(timeout):
            token_address = deploy_contract_web3(
                CONTRACT_HUMAN_STANDARD_TOKEN,
                self._chain.client,
                contract_manager=self._raiden.contract_manager,
                constructor_arguments=(initial_alloc, name, decimals, symbol),
            )

        token_address_hex = to_checksum_address(token_address)
        if auto_register:
            self.register_token(registry_address, token_address_hex)
        print("Successfully created {}the token '{}'.".format(
            'and registered ' if auto_register else ' ',
            name,
        ))
        return token_address_hex
コード例 #5
0
    def create_token(
        self,
        registry_address_hex: AddressHex,
        initial_alloc: int = 10**6,
        name: str = "raidentester",
        symbol: str = "RDT",
        decimals: int = 2,
        timeout: int = 60,
        auto_register: bool = True,
    ) -> AddressHex:
        """ Create a proxy for a new HumanStandardToken (ERC20), that is
        initialized with Args(below).
        Per default it will be registered with 'raiden'.

        Args:
            registry_address_hex: a hex encoded registry address.
            initial_alloc: amount of initial tokens.
            name: human readable token name.
            symbol: token shorthand symbol.
            decimals: decimal places.
            timeout: timeout in seconds for creation.
            auto_register: if True(default), automatically register
                the token with raiden.

        Returns:
            token_address_hex: the hex encoded address of the new token/token.
        """
        with gevent.Timeout(timeout):
            token_address = deploy_contract_web3(
                CONTRACT_HUMAN_STANDARD_TOKEN,
                self._raiden.rpc_client,
                contract_manager=self._raiden.contract_manager,
                constructor_arguments=(initial_alloc, name, decimals, symbol),
            )

        token_address_hex = to_checksum_address(token_address)
        if auto_register:
            self.register_token(registry_address_hex, token_address_hex)

        print("Successfully created {}the token '{}'.".format(
            "and registered " if auto_register else "", name))
        return token_address_hex
コード例 #6
0
def deploy_token(
    deploy_client: JSONRPCClient,
    contract_manager: ContractManager,
    initial_amount: TokenAmount,
    decimals: int,
    token_name: str,
    token_symbol: str,
    token_contract_name: str,
) -> ContractProxy:
    token_address = deploy_contract_web3(
        contract_name=token_contract_name,
        deploy_client=deploy_client,
        contract_manager=contract_manager,
        constructor_arguments=(initial_amount, decimals, token_name,
                               token_symbol),
    )

    contract_abi = contract_manager.get_contract_abi(token_contract_name)
    return deploy_client.new_contract_proxy(abi=contract_abi,
                                            contract_address=token_address)
コード例 #7
0
def deploy_tokens_and_fund_accounts(
    token_amount: TokenAmount,
    number_of_tokens: int,
    proxy_manager: ProxyManager,
    participants: List[Address],
    contract_manager: ContractManager,
    token_contract_name: str,
) -> List[TokenAddress]:
    """ Deploy `number_of_tokens` ERC20 token instances with `token_amount` minted and
    distributed among `blockchain_services`. Optionally the instances will be registered with
    the raiden registry.

    Args:
        token_amount: number of units that will be created per token
        number_of_tokens: number of token instances that will be created
        proxy_manager: the proxy manager used to create the token proxy
        participants: participant addresses that will receive tokens
    """
    result = list()
    for _ in range(number_of_tokens):
        token_address = TokenAddress(
            deploy_contract_web3(
                contract_name=token_contract_name,
                deploy_client=proxy_manager.client,
                contract_manager=contract_manager,
                constructor_arguments=(token_amount, 2, "raiden", "Rd"),
            ))

        result.append(token_address)

        # only the creator of the token starts with a balance (deploy_service),
        # transfer from the creator to the other nodes
        for transfer_to in participants:
            proxy_manager.token(token_address).transfer(
                to_address=transfer_to,
                amount=TokenAmount(token_amount // len(participants)))

    return result