Example #1
0
def deploy_file(contract, compiled_contracts, client):
    libraries = dict()
    filename, _, name = contract.partition(":")
    log.info(f"Deploying {name}")
    proxy = client.deploy_solidity_contract(
        name,
        compiled_contracts,
        libraries,
        '',
        contract_path=filename,
    )
    log.info(
        f"Deployed {name} @ {is_normalized_address(proxy.contract_address)}")
    libraries[contract] = is_normalized_address(proxy.contract_address)[2:]
    return libraries
def test_to_address_from_public_key(private_key):
    address = private_key.public_key.to_address()
    assert is_normalized_address(address)
    assert is_same_address(address, ADDRESS)
def checkTransfer(transfer):

 	if not transfer['tokensym'] in tokens:
		raise Exception("Token "+transfer['tokensym']+"' not known.")

	if len(transfer['return'])>0 and len(transfer['txid'])<10:
		isnormalized = eth_utils.is_normalized_address(transfer['return'])
		ischecksum   = eth_utils.is_checksum_address(transfer['return'])

	#	if not isnormalized and not ischecksum:
	#		print "ERROR BadAddess "+transfer['return']
	#	elif isnormalized and not ischecksum:
	#		print "WARN NotChecksumed "+transfer['return']

		balance = web3.eth.getBalance(transfer['return'])
		if balance == 0:
			print "WARN ReturnAddr "+transfer['return']+" has "+str(balance)+" eth"

	if len(transfer['return'])>0 and len(transfer['txid'])>10:

   		tokenFrom = 0
   		tokenTo = "0x"
   		token = "NONE"
   		tokenValue = 0

   		# get ERC20 transfer and amount
		receipt = web3.eth.getTransactionReceipt(transfer['txid'])
		if receipt is None:
			print "TXID recipt "+transfer['txid']+" is not ready"
			time.sleep(1)
			checkTransfer(transfer)
			return

		for log in receipt['logs']:
			if log['topics'][0] == TOPIC_ERC20TRANSFER:
				tokenFrom = '0x'+log['topics'][1][26:].lower()
				checkAddrFormat(tokenFrom)
				tokenTo = '0x'+log['topics'][2][26:].lower()
				checkAddrFormat(tokenTo)
				token = log['address']
				tokenValue = int(log['data'][2:], 16)

   		# get ETH transfer value and amount
		tx = web3.eth.getTransaction(transfer['txid'])
		if tx is None:
			print "TXID "+transfer['txid']+" is not ready"
			time.sleep(1)
			checkTransfer(transfer)
			return

		ethFrom = tx['from']
		ethTo = tx['to']
		ethValue = tx['value']

		block = web3.eth.getBlock(receipt['blockNumber'])
		timestamp = int(block['timestamp'])
		elapsed = str(round((time.time() - timestamp)/60))

		# check transfers from HWG_ADDR to destination
		if transfer['tokensym'] == ETH_TOKEN:
	   		if ethFrom != HWG_ADDR:
	   			print 'WARN '+transfer['txid']+' tokenTo!='+transfer['token']
	   		if ethTo != transfer['return']:
	   			print 'WARN '+transfer['txid']+' ethTo!='+transfer['return']
	   		if ethValue != int(transfer['amount']):
	   			print 'WARN '+transfer['txid']+' ethValue('+ethValue+')!='+transfer['amount']
	   		if tokenValue > 0:
	   			print 'WARN '+transfer['txid']+' tokenValue>0'
	   		print elapsed+"m ago\t> "+transfer['return']+" "+ \
	   			"{:,}".format(ethValue/1000000000000000000.0)+" ETH"
	   	else:
	   		decimals = erc20decimals[transfer['tokensym']]

	   		if tokenFrom != HWG_ADDR:
	   			print 'WARN '+transfer['txid']+' tokenFrom!='+HWG_ADDR
	   		if token != tokens[transfer['tokensym']]:
	   			print 'WARN '+transfer['txid']+' token!='+tokens[transfer['tokensym']]
	   		if tokenTo != transfer['return']:
	   			print 'WARN '+transfer['txid']+' tokenTo('+tokenTo+')!='+transfer['return']
	   		if tokenValue != int(transfer['amount']):
	   			print 'WARN '+transfer['txid']+' tokenValue('+str(tokenValue)+')!='+transfer['amount']
			if ethValue > 0:
				print 'WARN '+transfer['txid']+' ethValue>0'
	   		print elapsed+"m ago\t> "+transfer['return']+" "+\
	   			"{:,}".format(int(transfer['amount'])/float(pow(10,decimals)))+\
	   			" "+transfer['tokensym'].upper()+" d="+str(decimals)