def add_dev_reward(controller_instance, address, amount): tx_hash = controller_instance.transact({ 'from': owner_account }).addDevReward(address, amount) wait_for_tx(tx_hash, w3, wait_message="Wait for add dev reward") new_reward = controller_instance.call().devRewards(address) print('{address} reward is now {new_reward}')
def increase_ico_endtime(controller_instance, new_endtime): tx_hash = controller_instance.transact({ 'from': owner_account }).increaseCurrentIcoEndTime(new_endtime) wait_for_tx(tx_hash, w3, wait_message="Wait for ico to increase time") print("Ico offer endtime updated: {}".format( datetime.utcfromtimestamp(new_endtime).strftime('%Y-%m-%d %H:%M:%S')))
def finish_ico(controller_instance): tx_hash = controller_instance.transact({ 'from': owner_account }).finishCrowdsale() wait_for_tx(tx_hash, w3, wait_message="Wait for finish function") tx_hash = controller_instance.transact({ 'from': owner_account }).finishCrowdsaleBurnUnused() wait_for_tx(tx_hash, w3, wait_message="Wait for burn function") print("Balance of escrow ICO is: {}".format( w3.eth.getBalance(controller_instance.call().escrowIco()))) print("Balance of holder ICO is: {}".format( w3.eth.getBalance(controller_instance.call().holder())))
def send_airdrop(controller_instance, drop_file_path): with open(drop_file_path, 'r') as csv_file: addresses, amounts = list(zip(*csv.reader(csv_file))) addresses, amounts = list(addresses), list(amounts) amounts = [int(am) for am in amounts] number_of_iterarions = math.ceil(len(addresses) / 125) for i in range(number_of_iterarions): tx_hash = controller_instance.transact({ 'from': owner_account }).sendAirdrop(addresses[i * 125:(i + 1) * 125], amounts[i * 125:(i + 1) * 125]) wait_for_tx(tx_hash, w3, wait_message="Wait for airdrop send {}".format(i))
def send_airdrop(token_instance, account, drop_file_path): with open(drop_file_path, 'r') as csv_file: addresses, amounts = list(zip(*csv.reader(csv_file))) addresses, amounts = [ w3.toChecksumAddress( addr.encode("ascii", "ignore").decode("ascii")) for addr in addresses ], list(amounts) amounts = [int(am) for am in amounts] number_of_iterarions = math.ceil(len(addresses) / ADDRESSES_PER_TX) with open('succesfuly_sent.csv', 'w') as csvfile: spamwriter = csv.writer(csvfile) spamwriter.writerow(['Address']) new_nonce = -1 prev_nonce = -1 for i in range(number_of_iterarions): addresses_batch = addresses[i * ADDRESSES_PER_TX:(i + 1) * ADDRESSES_PER_TX] amounts_batch = amounts[i * ADDRESSES_PER_TX:(i + 1) * ADDRESSES_PER_TX] new_nonce = w3.eth.getTransactionCount(account.address) while new_nonce <= prev_nonce: print("Nonce Error, please wait") time.sleep(5) new_nonce = w3.eth.getTransactionCount(account.address) transaction = token_instance.functions.sendAirdrops( addresses_batch, amounts_batch).buildTransaction({ 'from': account.address, 'nonce': new_nonce, 'gasPrice': w3.eth.gasPrice }) signed = account.signTransaction(transaction) tx_hash = w3.eth.sendRawTransaction(signed.rawTransaction) wait_for_tx(tx_hash, w3, wait_message="Wait for airdrop send {}".format(i), delay=7) spamwriter.writerow(addresses_batch) prev_nonce = new_nonce
def add_addresses(method_name): addresses = get_addresses(request) for i in range(ceil(len(addresses) / MAX_ADDRESSES_IN_TX)): method = getattr(controller_instance.functions, method_name) tx_hash = method( addresses[MAX_ADDRESSES_IN_TX * i:MAX_ADDRESSES_IN_TX * (i + 1)]).transact(tx) tx_receipt = wait_for_tx(tx_hash, web3) if tx_receipt['status'] != 1: return jsonify({'success': False}) return jsonify({'success': True})
def add_addresses_to_whitelist(address, file_path, controller_instance): if file_path: with open(file_path, 'r') as csv_file: addresses = list((addr[0] for addr in csv.reader(csv_file))) else: addresses = [address] number_of_iterarions = math.ceil(len(addresses) / 125) for i in range(number_of_iterarions): tx_hash = controller_instance.transact({ 'from': owner_account }).addBuyers(addresses[i * 125:(i + 1) * 125]) wait_for_tx( tx_hash, w3, wait_message="Wait for account to be added to whitelist {}".format( i)) print("\n\n successfully added to whitelist") with open('whitelisted.csv', 'at') as text_file: spamwriter = csv.writer(text_file, quoting=csv.QUOTE_MINIMAL) spamwriter.writerows(([address] for address in addresses))
def deploy_contract(compiled_source, account): token_interface = compiled_source['../contracts/Opet_coin.sol:OpetToken'] token_contract = w3.eth.contract(abi=token_interface['abi'], bytecode=token_interface['bin']) construct_txn = token_contract.constructor().buildTransaction({ 'from': account.address, 'nonce': w3.eth.getTransactionCount(account.address), 'gasPrice': w3.eth.gasPrice }) signed = acct.signTransaction(construct_txn) tx_hash = w3.eth.sendRawTransaction(signed.rawTransaction) reciept = wait_for_tx(tx_hash, w3, wait_message="Wait for contract deploy") print(reciept['contractAddress'])
bytecode=holder_interface['bin']) ico_controller_contract = w3.eth.contract( abi=ico_controller_interface['abi'], bytecode=ico_controller_interface['bin']) token_holder_contract = w3.eth.contract( abi=token_holder_interface['abi'], bytecode=token_holder_interface['bin']) holder_tx_hash = holder_contract.deploy( transaction={'from': DEPLOY_ACCOUNT}, args=(HOLDERS_ACCOUNTS, # List of accounts that control holder account REQUIRE, # Number of accounts needed to confirm changes ESCROW_ADDRESS) # Escrow account ) holder_receipt = wait_for_tx(holder_tx_hash, w3, wait_message="Wait for Holder contract to be deployed") holder_contract_address = holder_receipt['contractAddress'] controller_tx_hash = ico_controller_contract.deploy( transaction={'from': DEPLOY_ACCOUNT}, args=(holder_contract_address, ESCROW_ADDRESS) # Escrow account ) controller_receipt = wait_for_tx(controller_tx_hash, w3, wait_message="Wait for ICO controller contract to be deployed") controller_contract_address = controller_receipt['contractAddress'] controller_instance = ico_controller_contract(controller_contract_address) token_contract_address = controller_instance.call().token()
ico_rate = ico_instance.call().rate() print("Start time: %i" % ico_instance.call().startTime()) print("Current time: %i" % int(time.time())) print("End time: %i" % ico_instance.call().endTime()) print("Wallet: %s" % ico_instance.call().wallet()) ico_controller_instance = ico_controller_contract(ico_controller_address) for acc in w3.eth.accounts[ACCOUNT_INDENT:ACCOUNT_INDENT + NUMBER_OF_ACCOUNTS]: w3.personal.unlockAccount(acc, '1') for acc in w3.eth.accounts[ACCOUNT_INDENT:ACCOUNT_INDENT + NUMBER_OF_ACCOUNTS]: if not ico_controller_instance.call().isAddressWhitelisted(acc): wait_for_tx(ico_controller_instance.transact({ 'from': w3.eth.accounts[0] }).addBuyerToWhitelist(acc), w3, delay=3) value_eth = randint(1, 110) value = w3.toWei(value_eth, 'ether') wait_for_tx(w3.eth.sendTransaction({ 'from': acc, 'to': ico_address, 'value': value }), w3, delay=3) print("{} sends {} ETH".format(acc, value_eth)) expected_amount = get_expected_token_amount(value, ico_rate) account_db = get_or_create(session, Account, address=acc)