Esempio n. 1
0
    def transfer_users(self, spam_protection=False, reprocess_username=None):
        """
            Process new transfer from the webapp
        """

        counter = 0
        self.registrar_server.reset_flag()

        for new_user in self.exports.find(no_cursor_timeout=True):

            user = get_db_user_from_id(new_user, self.users)

            if user is None:
                continue

            # add spam protection here

            # mode for reprocessing a single user, ignore others
            if reprocess_username is not None:
                if user['username'] != reprocess_username:
                    continue

            fqu = user['username'] + "." + DEFAULT_NAMESPACE

            transfer_address = new_user['recipient_address']

            try:
                encrypted_privkey = new_user['encrypted_private_key']
                hex_privkey = bip38_decrypt(str(encrypted_privkey),
                                            WALLET_SECRET)
            except:
                log.debug("no private key")
                #self.exports.remove({"user_id": new_user['user_id']})
            else:
                log.debug("To export: %s to %s" % (fqu, transfer_address))

            if nameRegistered(fqu):

                if ownerName(fqu, transfer_address):
                    log.debug("Name transferred, removing: %s" % fqu)
                    self.exports.remove({"user_id": new_user['user_id']})

                    refresh_resolver(user['username'])
                else:
                    log.debug("Processing: %s, %s" % (fqu, user['email']))
                    #try:
                    self.registrar_server.process_subsidized_nameop(
                        fqu,
                        owner_privkey=hex_privkey,
                        transfer_address=transfer_address,
                        nameop='transfer',
                        profile="")
                    #except Exception as e:
                    #    log.debug(e)
            else:

                log.debug("Not registered: %s" % fqu)
    def transfer_users(self, spam_protection=False, reprocess_username=None):
        """
            Process new transfer from the webapp
        """

        counter = 0
        self.registrar_server.reset_flag()

        for new_user in self.exports.find(no_cursor_timeout=True):

            user = get_db_user_from_id(new_user, self.users)

            if user is None:
                continue

            # add spam protection here

            # mode for reprocessing a single user, ignore others
            if reprocess_username is not None:
                if user['username'] != reprocess_username:
                    continue

            fqu = user['username'] + "." + DEFAULT_NAMESPACE

            transfer_address = new_user['recipient_address']

            try:
                encrypted_privkey = new_user['encrypted_private_key']
                hex_privkey = bip38_decrypt(str(encrypted_privkey), WALLET_SECRET)
            except:
                log.debug("no private key")
                #self.exports.remove({"user_id": new_user['user_id']})
            else:
                log.debug("To export: %s to %s" % (fqu, transfer_address))

            if nameRegistered(fqu):

                if ownerName(fqu, transfer_address):
                    log.debug("Name transferred, removing: %s" % fqu)
                    self.exports.remove({"user_id": new_user['user_id']})

                    refresh_resolver(user['username'])
                else:
                    log.debug("Processing: %s, %s" % (fqu, user['email']))
                    #try:
                    self.registrar_server.process_subsidized_nameop(fqu,
                                                                owner_privkey=hex_privkey,
                                                                transfer_address=transfer_address,
                                                                nameop='transfer', profile="")
                    #except Exception as e:
                    #    log.debug(e)
            else:

                log.debug("Not registered: %s" % fqu)
Esempio n. 3
0
    def display_current_states(self):
        """
            Display current states of all pending registrations
        """

        counter_register = 0
        counter_update = 0
        counter_dht = 0
        counter_transfer = 0

        for new_user in self.registrations.find(no_cursor_timeout=True):

            user = get_db_user_from_id(new_user, self.users)

            if not self.validUser(user, new_user):
                continue

            fqu = user['username'] + "." + DEFAULT_NAMESPACE
            transfer_address = nmc_to_btc_address(user['namecoin_address'])
            profile = user['profile']

            if not nameRegistered(fqu):
                counter_register += 1

            elif not profileonBlockchain(fqu, profile):
                counter_update += 1

            elif not profileonDHT(fqu, profile):
                counter_dht += 1

            elif not ownerName(fqu, transfer_address):
                counter_transfer += 1

        log.debug("Pending registrations: %s" % counter_register)
        log.debug("Pending updates: %s" % counter_update)
        log.debug("Pending DHT writes: %s" % counter_dht)
        log.debug("Pending transfers: %s" % counter_transfer)
Esempio n. 4
0
    def display_current_states(self):
        """
            Display current states of all pending registrations
        """

        counter_register = 0
        counter_update = 0
        counter_dht = 0
        counter_transfer = 0

        for new_user in self.registrations.find(no_cursor_timeout=True):

            user = get_db_user_from_id(new_user, self.users)

            if not self.validUser(user, new_user):
                continue

            fqu = user['username'] + "." + DEFAULT_NAMESPACE
            transfer_address = nmc_to_btc_address(user['namecoin_address'])
            profile = user['profile']

            if not nameRegistered(fqu):
                counter_register += 1

            elif not profileonBlockchain(fqu, profile):
                counter_update += 1

            elif not profileonDHT(fqu, profile):
                counter_dht += 1

            elif not ownerName(fqu, transfer_address):
                counter_transfer += 1

        log.debug("Pending registrations: %s" % counter_register)
        log.debug("Pending updates: %s" % counter_update)
        log.debug("Pending DHT writes: %s" % counter_dht)
        log.debug("Pending transfers: %s" % counter_transfer)
Esempio n. 5
0
def tests_for_update_and_transfer(fqu, transfer_address=None):
    """ Any update or transfer operation
        should pass these tests
    """

    if not nameRegistered(fqu):
        exit_with_error("%s is not registered yet." % fqu)

    payment_address, owner_address = get_addresses_from_file()

    if not ownerName(fqu, owner_address):
        exit_with_error("%s is not in your possession." % fqu)

    tx_fee_satoshi = approx_tx_fees(num_tx=1)
    tx_fee = satoshis_to_btc(tx_fee_satoshi)

    if not hasEnoughBalance(payment_address, tx_fee):
        msg = "Address %s doesn't have enough balance." % payment_address
        exit_with_error(msg)

    if dontuseAddress(payment_address):
        msg = "Address %s has pending transactions." % payment_address
        msg += " Wait and try later."
        exit_with_error(msg)

    if transfer_address is not None:

        try:
            resp = is_b58check_address(str(transfer_address))
        except:
            msg = "Address %s is not a valid Bitcoin address." % transfer_address
            exit_with_error(msg)

        if recipientNotReady(transfer_address):
            msg = "Address %s owns too many names already." % transfer_address
            exit_with_error(msg)