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
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)
def cap_table(config: BoardCommmadConfiguration, token_address, identity_file, order_by, order_direction, include_empty, max_entries, accuracy): """Print out token holder cap table. The token holder data must have been scanned earlier using token-scan command. You can supply optional CSV file that contains Ethereum address mappings to individual token holder names. """ assert is_ethereum_network(config.network) logger = config.logger from sto.generic.captable import generate_cap_table, print_cap_table from sto.identityprovider import read_csv, NullIdentityProvider, CSVIdentityProvider from sto.models.implementation import TokenScanStatus, TokenHolderAccount dbsession = config.dbsession if identity_file: entries = read_csv(logger, identity_file) provider = CSVIdentityProvider(entries) else: provider = NullIdentityProvider() cap_table = generate_cap_table(logger, dbsession, token_address=token_address, identity_provider=provider, order_by=order_by, order_direction=order_direction, include_empty=include_empty, TokenScanStatus=TokenScanStatus, TokenHolderAccount=TokenHolderAccount) print_cap_table(cap_table, max_entries, accuracy)
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
def scanned_distribution(logger, dbsession, web3, private_key_hex, sample_csv_file, sample_token, click_runner, db_path, monkeypatch_create_web3): """Create some sample transactions so we can scan the token holder balances.""" token_address = sample_token entries = read_csv(logger, sample_csv_file) for entry in entries: # whitelist customers result = click_runner.invoke(cli, [ '--database-file', db_path, '--ethereum-private-key', private_key_hex, '--ethereum-gas-limit', 999999999, 'kyc-manage', '--whitelist-address', entry.address ]) assert result.exit_code == 0 result = click_runner.invoke(cli, [ '--database-file', db_path, '--ethereum-private-key', private_key_hex, '--ethereum-gas-limit', 999999999, "distribute-multiple", '--csv-input', sample_csv_file, '--address', token_address ]) assert result.exit_code == 0 result = click_runner.invoke(cli, [ '--database-file', db_path, '--ethereum-private-key', private_key_hex, '--ethereum-gas-limit', 999999999, 'tx-broadcast', ]) assert result.exit_code == 0 # Check they got mined # Send transactions to emphmereal test chain result = click_runner.invoke(cli, [ '--database-file', db_path, '--ethereum-private-key', private_key_hex, '--ethereum-gas-limit', 999999999, 'tx-broadcast', ]) assert result.exit_code == 0 # 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 result = click_runner.invoke(cli, [ '--database-file', db_path, '--ethereum-private-key', private_key_hex, '--ethereum-gas-limit', 999999999, "distribute-multiple", '--csv-input', sample_csv_file, '--address', token_address ]) assert result.exit_code == 0 result = click_runner.invoke(cli, [ '--database-file', db_path, '--ethereum-private-key', private_key_hex, '--ethereum-gas-limit', 999999999, 'tx-broadcast', ]) assert result.exit_code == 0 token_scan(logger, dbsession, "testing", web3, None, token_address) return token_address