def create_invoice_user (email):
	BMMySQL().db.ping(True)
	cur = BMMySQL().db.cursor(MySQLdb.cursors.DictCursor)
	cur.execute ("SELECT bm, masterpubkey_btc, offset_btc, feeamount, feecurrency FROM user WHERE email = %s AND active = 1", (email))
	result = False
	for row in cur.fetchall():
		result = row
	if result:
		if result['masterpubkey_btc'][0:4] == "xpub":
			# BIP44
			dpk1 = pybitcointools.bip32_ckd(result['masterpubkey_btc'], 0)
			dpk2 = pybitcointools.bip32_ckd(dpk1, result['offset_btc'])
			pubkey = pybitcointools.bip32_extract_key(dpk2)
		else:
			# Electrum 1.x
			pubkey = pybitcointools.electrum_pubkey(result['masterpubkey_btc'], result['offset_btc'])
		address = pybitcointools.pubkey_to_address(pubkey)
		cur.execute ("UPDATE user SET offset_btc = offset_btc + 1 WHERE email = %s AND active = 1 AND masterpubkey_btc = %s", (email, result['masterpubkey_btc']))
		if result['feecurrency'] in ("USD", "GBP", "EUR"):
			result['feeamount'] /= decimal.Decimal(get_bitcoin_price(result['feecurrency']))
		cur.execute ("INSERT INTO invoice (issuer, address, coin, amount, type, paid) VALUES (%s, %s, 'BTC', %s, 1, 0)", (result['bm'], address, result['feeamount']))
		bitcoind_importaddress(address)
		cur.close()
		return address, result['feeamount'];
	cur.close()
	return False
def create_invoice_domain (domain, payer):
	BMMySQL().db.ping(True)
	cur = BMMySQL().db.cursor(MySQLdb.cursors.DictCursor)
	filterwarnings('ignore', category = MySQLdb.Warning)
	cur.execute ("SELECT bm, masterpubkey_btc, offset_btc, feeamount, feecurrency FROM domain WHERE name = %s AND active = 1", (domain))
	result = False
	for row in cur.fetchall():
		result = row
	while result:
		if result['masterpubkey_btc'][0:4] == "xpub":
			# BIP44
			dpk1 = pybitcointools.bip32_ckd(result['masterpubkey_btc'], 0)
			dpk2 = pybitcointools.bip32_ckd(dpk1, result['offset_btc'])
			pubkey = pybitcointools.bip32_extract_key(dpk2)
		else:
			# Electrum 1.x
			pubkey = pybitcointools.electrum_pubkey(result['masterpubkey_btc'], result['offset_btc'])
		address = pybitcointools.pubkey_to_address(pubkey)
		cur.execute ("UPDATE domain SET offset_btc = offset_btc + 1 WHERE name = %s AND active = 1 AND masterpubkey_btc = %s", (domain, result['masterpubkey_btc']))
		if result['feecurrency'] in ("USD", "GBP", "EUR"):
			result['feeamount'] /= decimal.Decimal(get_bitcoin_price(result['feecurrency']))
		cur.execute ("INSERT IGNORE INTO invoice (issuer, payer, address, coin, amount, type, paid) VALUES (%s, %s, %s, 'BTC', %s, 0, 0)", (result['bm'], payer, address, result['feeamount']))

		# invoice already exists for that address, increment
		if cur.rowcount == 0:
			cur.execute ("SELECT bm, masterpubkey_btc, offset_btc, feeamount, feecurrency FROM domain WHERE name = %s AND active = 1", (domain))
			result = False
			for row in cur.fetchall():
				result = row
			continue
		
		bitcoind_importaddress(address)
		cur.close()
		return address, result['feeamount'];
	cur.close()
	return False
Beispiel #3
0
def gen_descendent_keys(priv_parent, descendent_path,
                        parent_path=[], keyprint=False):
    if len(descendent_path) == 0:
        pub_parent = bip32_privtopub(priv_parent)
        print_keys(priv_parent, pub_parent, "m/" + "/".join(parent_path))
        return priv_parent, pub_parent

    index = extract_index_number(descendent_path[0])

    priv_child = bip32_ckd(priv_parent, index)
    pub_child = bip32_privtopub(priv_child)

    new_parent_path = parent_path + [str(descendent_path[0])]
    new_descendent_path = descendent_path[1:]

    return gen_descendent_keys(
        priv_child, new_descendent_path, parent_path=new_parent_path,
        keyprint=keyprint)
Beispiel #4
0
 def extended_private_key(self, bip32_path: str) -> str:
     self.unlock()
     xprv = self.root_priv
     for child_id in bip32_sequence(bip32_path):
         xprv = bip32_ckd(xprv, child_id)
     return str(xprv)