def generate_bitcoin_keypairs(number_of_addresses=50): """ This function: 1) generates new bitcoin keypairs 2) saves encrypted private keys private keys are encrypted with SECRET_KEY """ if registrar_addresses.find().count() >= number_of_addresses: log.debug("Already have enough addresses") return no_of_new_addresses = number_of_addresses - registrar_addresses.find().count() for count in range(1, no_of_new_addresses + 1): privkey = BitcoinPrivateKey() hex_privkey = privkey.to_hex() encrypted_privkey = aes_encrypt(hex_privkey, SECRET_KEY) address = get_address_from_privkey(hex_privkey) log.debug("Creating new address (count, address): (%s, %s):" % (count, address)) new_entry = {} new_entry['encrypted_privkey'] = encrypted_privkey new_entry['address'] = address registrar_addresses.save(new_entry)
def add_migration_user(username, profile): check_entry = migration_users.find_one({"username": username}) if check_entry is not None: print "already in migration DB" return new_entry = {} new_entry['username'] = username new_entry['profile'] = profile new_entry['profile_hash'] = get_hash(profile) privkey = BitcoinPrivateKey() hex_privkey = privkey.to_hex() new_entry['encrypted_privkey'] = aes_encrypt(hex_privkey, SECRET_KEY) #hex_privkey_test = aes_decrypt(new_entry['encrypted_privkey'], SECRET_KEY) #print hex_privkey #print hex_privkey_test nmc_address, btc_address = get_addresses_from_privkey(hex_privkey) new_entry['nmc_address'] = nmc_address new_entry['btc_address'] = btc_address print new_entry migration_users.save(new_entry)
def generate_bitcoin_keypairs(number_of_addresses=50): """ This function: 1) generates new bitcoin keypairs 2) saves encrypted private keys private keys are encrypted with SECRET_KEY """ if registrar_addresses.find().count() >= number_of_addresses: log.debug("Already have enough addresses") return no_of_new_addresses = number_of_addresses - registrar_addresses.find( ).count() for count in range(1, no_of_new_addresses + 1): privkey = BitcoinPrivateKey() hex_privkey = privkey.to_hex() encrypted_privkey = aes_encrypt(hex_privkey, SECRET_KEY) address = get_address_from_privkey(hex_privkey) log.debug("Creating new address (count, address): (%s, %s):" % (count, address)) new_entry = {} new_entry['encrypted_privkey'] = encrypted_privkey new_entry['address'] = address registrar_addresses.save(new_entry)