Пример #1
0
def deploy_contract(config, contract_name, constructor_args=()):
    tx = get_contract_deployed_tx(config.dbsession, contract_name)
    if tx:
        config.logger.error('contract already deployed at address: {}'.format(
            tx.contract_address))
        return

    from sto.ethereum.txservice import EthereumStoredTXService
    from sto.models.implementation import BroadcastAccount, PreparedTransaction

    assert is_ethereum_network(config.network)

    check_good_private_key(config.ethereum_private_key)

    abi = get_abi(config.ethereum_abi_file)

    for dependency in abi[contract_name]['ordered_full_dependencies']:
        deploy_contract(config, dependency, None)

    abi[contract_name]['bytecode'] = _link_bytecode(
        config.dbsession, abi[contract_name]['bytecode'],
        abi[contract_name]['linkrefs'])
    abi[contract_name]['bytecode_runtime'] = _link_bytecode(
        config.dbsession,
        abi[contract_name]['bytecode_runtime'],
        abi[contract_name]['linkrefs_runtime'],
    )

    web3 = create_web3(config.ethereum_node_url)
    service = EthereumStoredTXService(config.network, config.dbsession, web3,
                                      config.ethereum_private_key,
                                      config.ethereum_gas_price,
                                      config.ethereum_gas_limit,
                                      BroadcastAccount, PreparedTransaction)
    note = "Deploying contract {}".format(contract_name)
    service.deploy_contract(contract_name=contract_name,
                            abi=abi,
                            note=note,
                            constructor_args=constructor_args)
    # Write database
    dbsession = config.dbsession
    dbsession.commit()
    # deploy on ethereum network
    broadcast(config)
Пример #2
0
def deploy_token_contracts(
        logger: Logger, dbsession: Session, network: str,
        ethereum_node_url: Union[str, Web3], ethereum_abi_file: Optional[str],
        ethereum_private_key: Optional[str], ethereum_gas_limit: Optional[int],
        ethereum_gas_price: Optional[int], name: str, symbol: str, url: str,
        amount: int, transfer_restriction: str):
    """Issue out a new Ethereum token."""

    assert type(amount) == int
    decimals = 18  # Everything else is bad idea

    check_good_private_key(ethereum_private_key)

    abi = get_abi(ethereum_abi_file)

    web3 = create_web3(ethereum_node_url)

    # We do not have anything else implemented yet
    assert transfer_restriction == "unrestricted"

    service = EthereumStoredTXService(network, dbsession, web3,
                                      ethereum_private_key, ethereum_gas_price,
                                      ethereum_gas_limit, BroadcastAccount,
                                      PreparedTransaction)

    # Deploy security token
    note = "Deploying token contract for {}".format(name)
    deploy_tx1 = service.deploy_contract("SecurityToken",
                                         abi,
                                         note,
                                         constructor_args={
                                             "_name": name,
                                             "_symbol": symbol,
                                             "_url": url
                                         })  # See SecurityToken.sol

    # Deploy transfer agent
    note = "Deploying unrestricted transfer policy for {}".format(name)
    deploy_tx2 = service.deploy_contract("UnrestrictedTransferAgent", abi,
                                         note)

    # Set transfer agent
    note = "Making transfer restriction policy for {} effective".format(name)
    contract_address = deploy_tx1.contract_address
    update_tx1 = service.interact_with_contract(
        "SecurityToken", abi, contract_address, note, "setTransactionVerifier",
        {"newVerifier": deploy_tx2.contract_address})

    # Issue out initial shares
    note = "Creating {} initial shares for {}".format(amount, name)
    contract_address = deploy_tx1.contract_address
    amount_18 = int(amount * 10**decimals)
    update_tx2 = service.interact_with_contract("SecurityToken", abi,
                                                contract_address, note,
                                                "issueTokens",
                                                {"value": amount_18})

    logger.info("Prepared transactions for broadcasting for network %s",
                network)
    logger.info("STO token contract address will be %s%s%s",
                colorama.Fore.LIGHTGREEN_EX, deploy_tx1.contract_address,
                colorama.Fore.RESET)
    return [deploy_tx1, deploy_tx2, update_tx1, update_tx2]