コード例 #1
0
def scanned_distribution(logger, dbsession, web3, private_key_hex, sample_csv_file, sample_token):
    """Create some sample transactions so we can scan the token holder balances."""

    token_address = sample_token

    entries = read_csv(logger, sample_csv_file)

    new_distributes, old_distributes = distribute_tokens(logger,
                                                         dbsession,
                                                         "testing",
                                                         web3,
                                                         ethereum_abi_file=None,
                                                         ethereum_private_key=private_key_hex,
                                                         ethereum_gas_limit=None,
                                                         ethereum_gas_price=None,
                                                         token_address=token_address,
                                                         dists=entries)

    assert new_distributes == 2
    assert old_distributes == 0

    # Check they got mined
    # Send transactions to emphmereal test chain
    txs = broadcast(logger,
                    dbsession,
                    "testing",
                    web3,
                    ethereum_private_key=private_key_hex,
                    ethereum_gas_limit=None,
                    ethereum_gas_price=None,
                    )
    # Check they got mined
    txs = update_status(logger,
                        dbsession,
                        "testing",
                        web3,
                        ethereum_private_key=private_key_hex,
                        ethereum_gas_limit=None,
                        ethereum_gas_price=None,
                        )


    # Check that rerun does not recreate txs
    new_distributes, old_distributes = distribute_tokens(logger,
                                                         dbsession,
                                                         "testing",
                                                         web3,
                                                         ethereum_abi_file=None,
                                                         ethereum_private_key=private_key_hex,
                                                         ethereum_gas_limit=None,
                                                         ethereum_gas_price=None,
                                                         token_address=token_address,
                                                         dists=entries)

    assert new_distributes == 0
    assert old_distributes == 2
    token_scan(logger, dbsession, "testing", web3, None, token_address)
    return token_address
コード例 #2
0
ファイル: main.py プロジェクト: uivlis/sto
def distribute_multiple(config: BoardCommmadConfiguration, csv_input, address):
    """Distribute shares to multiple shareholders whose address info is read from a file."""

    logger = config.logger

    assert is_ethereum_network(config.network)  # Nothing else implemented yet
    dbsession = config.dbsession

    from sto.distribution import read_csv
    from sto.ethereum.distribution import distribute_tokens

    dists = read_csv(logger, csv_input)
    if not dists:
        sys.exit("Empty CSV file")

    new_txs, old_txs = distribute_tokens(
        logger,
        dbsession,
        config.network,
        ethereum_node_url=config.ethereum_node_url,
        ethereum_abi_file=config.ethereum_abi_file,
        ethereum_private_key=config.ethereum_private_key,
        ethereum_gas_limit=config.ethereum_gas_limit,
        ethereum_gas_price=config.ethereum_gas_price,
        token_address=address,
        dists=dists,
    )

    logger.info(
        "Distribution created %d new transactions and there was already %d old transactions in the database",
        new_txs, old_txs)

    # Write database
    dbsession.commit()

    logger.info(
        "Run %ssto tx-broadcast%s to send out distribured shares to the world",
        colorama.Fore.LIGHTCYAN_EX, colorama.Fore.RESET)
コード例 #3
0
ファイル: test_cli.py プロジェクト: uivlis/sto
def test_distribute(logger, dbsession, web3, private_key_hex, sample_csv_file):
    """Distribute tokens."""

    # Creating transactions
    txs = deploy_token_contracts(
       logger, dbsession, "testing", web3,
       ethereum_abi_file=None,
       ethereum_private_key=private_key_hex,
       ethereum_gas_limit=99999999,
       ethereum_gas_price=None,
       name="Moo Corp",
       symbol="MOO",
       url="https://tokenmarket.net",
       amount=9999,
       transfer_restriction="unrestricted"
    )

    token_address = txs[0].contract_address

    # Deploy contract transactions to emphmereal test chain
    broadcast(
        logger,
        dbsession,
        "testing",
        web3,
        ethereum_private_key=private_key_hex,
        ethereum_gas_limit=None,
        ethereum_gas_price=None,
    )

    # Check that we can view the token status
    status = contract_status(
        logger,
        dbsession,
        "testing",
        web3,
        ethereum_abi_file=None,
        ethereum_private_key=private_key_hex,
        ethereum_gas_limit=None,
        ethereum_gas_price=None,
        token_contract=token_address,
    )

    assert status["name"] == "Moo Corp"
    assert status["totalSupply"] == 9999 * 10 ** 18

    entries = read_csv(logger, sample_csv_file)

    new_distributes, old_distributes = distribute_tokens(
        logger,
        dbsession,
        "testing",
        web3,
        ethereum_abi_file=None,
        ethereum_private_key=private_key_hex,
        ethereum_gas_limit=None,
        ethereum_gas_price=None,
        token_address=token_address,
        dists=entries
    )

    assert new_distributes == 2
    assert old_distributes == 0

    # Check they got mined
    # Send transactions to emphmereal test chain
    txs = broadcast(
        logger,
        dbsession,
        "testing",
        web3,
        ethereum_private_key=private_key_hex,
        ethereum_gas_limit=None,
        ethereum_gas_price=None,
    )
    # Check they got mined
    txs = update_status(
        logger,
        dbsession,
        "testing",
        web3,
        ethereum_private_key=private_key_hex,
        ethereum_gas_limit=None,
        ethereum_gas_price=None,
    )
    assert len(txs) == 6
    for tx in txs:  # type: PreparedTransaction
        assert tx.result_transaction_success

    # Check that rerun does not recreate txs
    new_distributes, old_distributes = distribute_tokens(
        logger,
        dbsession,
        "testing",
        web3,
        ethereum_abi_file=None,
        ethereum_private_key=private_key_hex,
        ethereum_gas_limit=None,
        ethereum_gas_price=None,
        token_address=token_address,
        dists=entries
    )

    assert new_distributes == 0
    assert old_distributes == 2