Skip to content

Commit

Permalink
Merge pull request stacks-network#2 from blockstack/server
Browse files Browse the repository at this point in the history
Server
  • Loading branch information
muneeb-ali committed Aug 4, 2015
2 parents 9746bae + 41b7881 commit 807aae0
Show file tree
Hide file tree
Showing 18 changed files with 427 additions and 496 deletions.
2 changes: 1 addition & 1 deletion blockstack_cli/blockstack_registrar/LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014 Halfmoon Labs, Inc
Copyright (c) 2014 Halfmoon Labs, Inc.
Copyright (c) 2015 Blockstack.org

Permission is hereby granted, free of charge, to any person obtaining a copy of
Expand Down
18 changes: 9 additions & 9 deletions blockstack_cli/blockstack_registrar/README.md
@@ -1,28 +1,28 @@
registrar
==================

For registering and updating passnames and passcards
For registering and updating blockchain ID

## Setup Environment

BNS currently uses the Namecoind blockchain for storing data. You'll need to compile a Namecoin Daemon (namecoind) to register/update opennames and profiles. You can follow the instructions for [compiling namecoind on Debian](https://github.com/namesystem/registrar/blob/master/doc/build-debian.md).
Blockchain ID currently uses the Namecoind blockchain for storing data. You'll need to compile a Namecoin Daemon (namecoind) to register/update opennames and profiles. You can follow the instructions for [compiling namecoind on Debian](https://github.com/namesystem/registrar/blob/master/doc/build-debian.md).

We've also developed a Python RPC client, shipped with [pybitcoin](https://github.com/namesystem/pybitcoin/rpc) for easily interacting with namecoind. This RPC client can be used to register users and update their profiles once you've setup your own namecoind instance. See the [README](https://github.com/namesystem/pybitcoin/tree/master/pybitcoin/rpc) files for details.

We're in the process of releasing more tools/software for making this process easier for developers, so stay tuned!

## Passnames
## Blockchain ID

Passnames (usernames) may be up to 60 characters long and contain lowercase letters, numbers, and underscores.
Usernames may be up to 60 characters long and contain lowercase letters, numbers, and underscores.

**Note:** usernames with ANY uppercase letters will be ignored by crawlers, so make sure to only use lowercase letters when you register a name.

Regex: ^[a-z0-9_]{1,60}$

## Passcard Registration
## Registration

To register a passcard:
To register a blockchain ID:

1. choose an available passname
2. construct a valid JSON object that adheres to the [passcard schema specifications](https://github.com/namesystem/namesystem/wiki/Passcard-Schema-v2)
3. register the passname and passcard as an entry in the key-value store
1. choose an available username
2. construct a valid JSON object that adheres to the [profile schema specifications](https://github.com/blockstack/blockstack/wiki/Passcard-Schema-v2)
3. register the username and profile as an entry in the key-value store
10 changes: 0 additions & 10 deletions blockstack_cli/blockstack_registrar/encrypt/__init__.py

This file was deleted.

4 changes: 2 additions & 2 deletions blockstack_cli/blockstack_registrar/registrar/README.md
Expand Up @@ -6,6 +6,6 @@ For registering/updating users on the blockchain
Installation
=========

First install coinrpc (need to update this to pybitcoin)
First install pybitcoin

> pip install coinrpc
> pip install pybitcoin
69 changes: 38 additions & 31 deletions blockstack_cli/blockstack_registrar/registrar/activate.py
@@ -1,11 +1,14 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#-----------------------
# Copyright 2014 Halfmoon Labs, Inc.
# All Rights Reserved
#-----------------------
"""
registrar
~~~~~
from pybitcoin.rpc.namecoind_client import NamecoindClient as NamecoindServer
copyright: (c) 2014 by Halfmoon Labs, Inc.
copyright: (c) 2015 by Blockstack.org
license: MIT, see LICENSE for more details.
"""

from pybitcoin.rpc.namecoind_client import NamecoindClient as NamecoindServer

from config import MAIN_SERVER, LOAD_SERVERS

Expand All @@ -14,9 +17,10 @@

from time import sleep

from config import NAMECOIND_PORT, NAMECOIND_USER, NAMECOIND_PASSWD, NAMECOIND_WALLET_PASSPHRASE, NAMECOIND_USE_HTTPS, NAMECOIND_SERVER
from config import NAMECOIND_SERVER, NAMECOIND_PORT
from config import NAMECOIND_USER, NAMECOIND_PASSWD
from config import NAMECOIND_WALLET_PASSPHRASE, NAMECOIND_USE_HTTPS

#-----------------------------------
from pymongo import MongoClient
from config import AWSDB_URI
aws_db = MongoClient(AWSDB_URI)['blockdata']
Expand All @@ -32,33 +36,35 @@

from .nameops import slice_profile

#-----------------------------------
#get the latest value for key:value being registered

def refresh_value(entry):
"""get the latest value for key:value being registered
"""

username = entry['username']
user = users.find_one({"username":username})
user = users.find_one({"username": username})

if user is None:
return None
return None

profile = user['profile']
keys, values = slice_profile(username,profile)
keys, values = slice_profile(username, profile)

counter = 0
counter = 0
for key in keys:
if entry['key'] == key:
return values[counter]
return values[counter]
counter += 1

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

def clean_wallet():

for entry in register_queue.find():
if entry['tx_sent'] is True:
entry['tx_sent'] = False
register_queue.save(entry)

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

def do_name_firstupdate():

log.debug("Checking for new activations")
Expand Down Expand Up @@ -89,33 +95,35 @@ def do_name_firstupdate():

key = entry['key']
server = entry['server']
namecoind = NamecoindServer(server, NAMECOIND_PORT, NAMECOIND_USER, NAMECOIND_PASSWD, NAMECOIND_USE_HTTPS, NAMECOIND_WALLET_PASSPHRASE)
namecoind = NamecoindServer(server, NAMECOIND_PORT, NAMECOIND_USER,
NAMECOIND_PASSWD, NAMECOIND_USE_HTTPS,
NAMECOIND_WALLET_PASSPHRASE)

if 'tx_sent' in entry and entry['tx_sent'] is True:
log.debug('Already sent name_firstupdate: %s' % entry['key'])
continue

if 'wait_till_block' not in entry:
if 'wait_till_block' not in entry:

reply = namecoind.gettransaction(entry['txid'])

if 'code' in reply:
register_queue.remove(entry)
continue

if reply['confirmations'] > 1:
log.debug('Got confirmations on name_new: %s' % entry['key'])
entry['wait_till_block'] = namecoind.blocks() + (12 - reply['confirmations'])
register_queue.save(entry)
else:
log.debug('No confirmations on name_new: %s' % entry['key'])
continue
continue

if entry['wait_till_block'] <= blocks:

if server in ignore_servers:
continue

if pending_transactions(server) > MAX_PENDING_TX:
log.debug("Pending tx on server, try again")
ignore_servers.append(server)
Expand All @@ -124,16 +132,16 @@ def do_name_firstupdate():
update_value = None
if 'username' in entry:
update_value = get_string(refresh_value(entry))

if update_value is None:
update_value = get_string(entry['value'])
update_value = get_string(entry['value'])

log.debug("Activating entry: '%s' to point to '%s'" % (key, update_value))

output = namecoind.firstupdate(key,entry['rand'],update_value,entry['txid'])

log.debug(output)

if 'message' in output and output['message'] == "this name is already active":
register_queue.remove(entry)
elif 'message' in output and output['message'] == "previous transaction is not in the wallet":
Expand All @@ -153,7 +161,7 @@ def do_name_firstupdate():
log.debug("key %s already active" % (entry['key']))
register_queue.remove(entry)

print "Pending activations: %s" %counter_pending
print "Pending activations: %s" % counter_pending
current_block = namecoind.blocks()
while(1):
new_block = namecoind.blocks()
Expand All @@ -164,7 +172,6 @@ def do_name_firstupdate():
else:
break

#-----------------------------------
if __name__ == '__main__':

#clean_wallet()
Expand All @@ -175,4 +182,4 @@ def do_name_firstupdate():
try:
do_name_firstupdate()
except Exception as e:
print e
print e
16 changes: 6 additions & 10 deletions blockstack_cli/blockstack_registrar/registrar/config.py
@@ -1,13 +1,9 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -----------------------
# Copyright 2015 Halfmoon Labs, Inc.
# All Rights Reserved
# -----------------------

'''
configuration file
'''
"""
copyright: (c) 2014 by Halfmoon Labs, Inc.
copyright: (c) 2015 by Blockstack.org
license: MIT, see LICENSE for more details.
"""

try:
from config_local import *
Expand Down Expand Up @@ -40,4 +36,4 @@
MEMCACHED_PORT = '11211'
MEMCACHED_TIMEOUT = 15 * 60

FRONTEND_SECRET = os.environ['FRONTEND_SECRET']
FRONTEND_SECRET = os.environ['FRONTEND_SECRET']
20 changes: 9 additions & 11 deletions blockstack_cli/blockstack_registrar/registrar/loadbalancer.py
@@ -1,9 +1,12 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -----------------------
# Copyright 2015 Halfmoon Labs, Inc.
# All Rights Reserved
# -----------------------
"""
registrar
~~~~~
copyright: (c) 2014 by Halfmoon Labs, Inc.
copyright: (c) 2015 by Blockstack.org
license: MIT, see LICENSE for more details.
"""

from config import LOAD_SERVERS, MAX_PENDING_TX

Expand All @@ -13,7 +16,7 @@

from time import sleep

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

def load_balance(current_server):

counter = 0
Expand Down Expand Up @@ -41,8 +44,3 @@ def load_balance(current_server):
break

return LOAD_SERVERS[server_number]

# -----------------------------------
if __name__ == '__main__':

load_balance('named3')
13 changes: 8 additions & 5 deletions blockstack_cli/blockstack_registrar/registrar/nameops.py
@@ -1,9 +1,12 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -----------------------
# Copyright 2015 Halfmoon Labs, Inc.
# All Rights Reserved
# -----------------------
"""
registrar
~~~~~
copyright: (c) 2014 by Halfmoon Labs, Inc.
copyright: (c) 2015 by Blockstack.org
license: MIT, see LICENSE for more details.
"""

# 520 is the real limit
# hardcoded here instead of some config file
Expand Down
13 changes: 8 additions & 5 deletions blockstack_cli/blockstack_registrar/registrar/renew_names.py
@@ -1,9 +1,12 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -----------------------
# Copyright 2015 Halfmoon Labs, Inc.
# All Rights Reserved
# -----------------------
"""
registrar
~~~~~
copyright: (c) 2014 by Halfmoon Labs, Inc.
copyright: (c) 2015 by Blockstack.org
license: MIT, see LICENSE for more details.
"""

import json
from time import sleep
Expand Down

0 comments on commit 807aae0

Please sign in to comment.