Skip to content

Commit

Permalink
Merge pull request #6 from onenameio/register
Browse files Browse the repository at this point in the history
updates to the name transfer method
  • Loading branch information
muneeb-ali committed Jul 2, 2015
2 parents 62ef8f7 + 5837afa commit 85250b5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 54 deletions.
48 changes: 24 additions & 24 deletions blockstack_registrar/registrar/nameops.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
mc = pylibmc.Client([DEFAULT_HOST + ':' + MEMCACHED_PORT], binary=True)


# -----------------------------------
def register_name(key, value, server=NAMECOIND_SERVER, username=None):

reply = {}
Expand Down Expand Up @@ -83,28 +82,34 @@ def register_name(key, value, server=NAMECOIND_SERVER, username=None):
return reply


# -----------------------------------
def update_name(key, value):
def get_namecoind(key):

reply = {}
server = NAMECOIND_SERVER

cache_reply = mc.get("name_update_" + str(key))
serverinfo = get_server(key, MAIN_SERVER, LOAD_SERVERS)

if cache_reply is None:
if 'registered' in serverinfo and serverinfo['registered']:
server = serverinfo['server']

server = NAMECOIND_SERVER
log.debug(server)
log.debug(key)

serverinfo = get_server(key, MAIN_SERVER, LOAD_SERVERS)
namecoind = NamecoindClient(server, NAMECOIND_PORT, NAMECOIND_USER,
NAMECOIND_PASSWD, NAMECOIND_USE_HTTPS,
NAMECOIND_WALLET_PASSPHRASE)

if 'registered' in serverinfo and serverinfo['registered']:
server = serverinfo['server']
return namecoind

log.debug(server)
log.debug(value)

namecoind = NamecoindClient(server, NAMECOIND_PORT, NAMECOIND_USER,
NAMECOIND_PASSWD, NAMECOIND_USE_HTTPS,
NAMECOIND_WALLET_PASSPHRASE)
def update_name(key, value):

reply = {}

cache_reply = mc.get("name_update_" + str(key))

if cache_reply is None:

namecoind = get_namecoind(key)

info = namecoind.name_update(key, json.dumps(value))

Expand All @@ -121,17 +126,14 @@ def update_name(key, value):
log.debug('-' * 5)


# -----------------------------------
def _max_size(username):
return VALUE_MAX_LIMIT - len('next: i-' + username + '000000')


# -----------------------------------
def _get_key(key_counter, username):
return 'i/' + username.lower() + '-' + str(key_counter)


# -----------------------------------
def _splitter(remaining, username):

split = {}
Expand Down Expand Up @@ -165,9 +167,9 @@ def _splitter(remaining, username):
return split, remaining


# -----------------------------------
# if a next key is already registered, returns next one
def slice_profile(username, profile):
'''if a next key is already registered, returns next one
'''

keys = []
values = []
Expand Down Expand Up @@ -205,9 +207,9 @@ def slice_profile(username, profile):
return keys, values


# -----------------------------------
# returns keys without checking if they're already registered
def slice_profile_update(username, profile):
'''returns keys without checking if they're already registered
'''

keys = []
values = []
Expand Down Expand Up @@ -236,7 +238,6 @@ def slice_profile_update(username, profile):
return keys, values


# -----------------------------------
def process_user(username, profile, server=NAMECOIND_SERVER):

master_key = 'u/' + username
Expand Down Expand Up @@ -266,7 +267,6 @@ def process_user(username, profile, server=NAMECOIND_SERVER):
process_additional_keys(keys, values, server, username)


# -----------------------------------
def process_additional_keys(keys, values, server, username):

# register/update remaining keys
Expand Down
44 changes: 14 additions & 30 deletions blockstack_registrar/registrar/transfer.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#-----------------------
# Copyright 2014 Halfmoon Labs, Inc.
# -----------------------
# Copyright 2015 Halfmoon Labs, Inc.
# All Rights Reserved
#-----------------------
# -----------------------

import json
from coinrpc import namecoind
from .register import process_user
from pymongo import MongoClient
from config import MONGODB_URI
from .nameops import get_namecoind

users = MongoClient(MONGODB_URI).get_default_database().user


# -----------------------------------
def test_private_key(passphrase, nmc_address):

from coinkit.keypair import NamecoinKeypair
Expand All @@ -33,28 +26,18 @@ def test_private_key(passphrase, nmc_address):
return False


# -----------------------------------
def do_name_transfer(username, live=False):
def name_transfer(passname, transfer_address, live=False):

try:
entry = users.find({'username': username})
for i in entry:
user = i
break
nmc_address = user['namecoin_address']
except Exception as e:
print e
print "No such user in DB"
return
key = 'u/' + passname
namecoind = get_namecoind(key)

# -----------------------------
def name_transfer_inner(key):

print key, nmc_address
if(live):
print namecoind.transfer(key, nmc_address)

key = 'u/' + username
print namecoind.name_transfer(key, transfer_address)
else:
print "Will transfer %s, to %s" % (key, transfer_address)

name_transfer_inner(key)

Expand All @@ -65,18 +48,19 @@ def name_transfer_inner(key):

try:
next_blob = value['next']
except:
except Exception as e:
break

if next_blob is not None:
key = next_blob
name_transfer_inner(key)

# -----------------------------------

if __name__ == '__main__':

live = False

username = "clone66"
address = 'NCinvalid'

do_name_transfer(username, live)
name_transfer(username, address, live)

0 comments on commit 85250b5

Please sign in to comment.