Пример #1
0
def cleanup_diff_db():

    for entry in state_diff.find():

        username = entry['username']
        profile = get_dht_profile(username)

        if profile is None:
            #print "Not registered: %s" % username
            continue

        dht_profile_hash = get_hash(profile)

        check_user = users.find_one({"username": username})
        try:
            db_profile_hash = get_hash(check_user['profile'])
        except:
            db_profile_hash = None
            print "ERROR: %s not in DB" % username

        if dht_profile_hash == db_profile_hash:
            print "registered: %s" % username
            state_diff.remove({"username": username})
        else:
            print "profile hash doesn't match: %s" % username
def cleanup_diff_db():

    for entry in state_diff.find():

        username = entry['username']
        profile = get_dht_profile(username)

        if profile is None:
            #print "Not registered: %s" % username
            continue

        dht_profile_hash = get_hash(profile)

        check_user = users.find_one({"username": username})
        try:
            db_profile_hash = get_hash(check_user['profile'])
        except:
            db_profile_hash = None
            print "ERROR: %s not in DB" % username

        if dht_profile_hash == db_profile_hash:
            print "registered: %s" % username
            state_diff.remove({"username": username})
        else:
            print "profile hash doesn't match: %s" % username
def insert_state_diff(username, profile, nmc_address):

    check_diff = state_diff.find_one({"username": username})

    if check_diff is None:
        new_entry = {}
        new_entry['username'] = username
        new_entry['btc_address'] = address_to_new_cryptocurrency(nmc_address, 0)
        new_entry['profile'] = profile
        new_entry['profile_hash'] = get_hash(profile)

        print "inserting in diff: %s" % username
        state_diff.insert(new_entry)
    else:
        print "already in diff: %s" % username
Пример #4
0
def insert_state_diff(username, profile, nmc_address):

    check_diff = state_diff.find_one({"username": username})

    if check_diff is None:
        new_entry = {}
        new_entry['username'] = username
        new_entry['btc_address'] = address_to_new_cryptocurrency(
            nmc_address, 0)
        new_entry['profile'] = profile
        new_entry['profile_hash'] = get_hash(profile)

        print "inserting in diff: %s" % username
        state_diff.insert(new_entry)
    else:
        print "already in diff: %s" % username
Пример #5
0
def update_user(username):

    reply = {}

    try:
        user = get_authenticated_user(request.authorization)
    except Exception as e:
        raise GenericError(str(e))

    try:
        hex_privkey = aes_decrypt(user.encrypted_privkey, SECRET_KEY)
    except Exception as e:
        raise GenericError(str(e))

    wallet = HDWallet(hex_privkey)
    data = json.loads(request.data)

    fqu = username + "." + DEFAULT_NAMESPACE
    profile = data['profile']
    profile_hash = get_hash(profile)
    owner_pubkey = data['owner_pubkey']

    try:
        blockchain_record = bs_client.get_name_blockchain_record(fqu)
    except Exception as e:
        raise GenericError(str(e))

    if 'value_hash' not in blockchain_record:
        raise GenericError("Not yet registered %s" % fqu)

    owner_address = blockchain_record['address']

    check_address = get_address_from_pubkey(str(owner_pubkey))

    if check_address != owner_address:
        raise GenericError("Given pubkey/address doesn't own this name.")

    if USE_DEFAULT_PAYMENT and PAYMENT_PRIVKEY is not None:

        payment_privkey = BitcoinPrivateKey(PAYMENT_PRIVKEY)
        payment_privkey = payment_privkey.to_hex()
    else:
        pubkey, payment_privkey = wallet.get_next_keypair()

        if payment_privkey is None:
            raise PaymentError(
                addresses=wallet.get_keypairs(DEFAULT_CHILD_ADDRESSES))

    resp = {}

    try:
        resp = bs_client.update_subsidized(fqu,
                                           profile_hash,
                                           public_key=owner_pubkey,
                                           subsidy_key=payment_privkey)
    except Exception as e:
        reply['error'] = str(e)
        return jsonify(reply), 200

    if 'subsidized_tx' in resp:
        reply['unsigned_tx'] = resp['subsidized_tx']
    else:
        if 'error' in resp:
            reply['error'] = resp['error']
        else:
            reply['error'] = resp

    return jsonify(reply), 200