Example #1
0
def broadcast(name, data, private_key,
              blockchain_client=BlockchainInfoClient(), testset=False):
    nulldata = build(name, data_hash=hex_hash160(data), testset=testset)
    response = embed_data_in_blockchain(
        nulldata, private_key, blockchain_client, format='hex')
    response.update({'data': nulldata})
    return response
Example #2
0
def broadcast(name,
              data,
              private_key,
              blockchain_client=BlockchainInfoClient(),
              testset=False):
    nulldata = build(name, data_hash=hex_hash160(data), testset=testset)
    response = embed_data_in_blockchain(nulldata,
                                        private_key,
                                        blockchain_client,
                                        format='hex')
    response.update({'data': nulldata})
    return response
Example #3
0
    def get(self, key, default=None):
        self.cull()
        if key in self.data:
            value = self[key]
            hash = coinkit.hex_hash160(value)

            test_key = digest(hash)

            if key != test_key:
                self.log.info("hash(value) doesn't match, ignoring value")
                return default

            return self[key]

        return default
Example #4
0
    def get(self, key, default=None):
        self.cull()
        if key in self.data:
            value = self[key]
            hash = coinkit.hex_hash160(value)

            test_key = digest(hash)

            if key != test_key:
                self.log.info("hash(value) doesn't match, ignoring value")
                return default

            return self[key]

        return default
Example #5
0
def build(name, data_hash=None, data=None, testset=False):
    """ Takes in the name to update the data for and the data update itself.
    """
    hex_name = b40_to_hex(name)
    name_len = len(hex_name)/2

    if not data_hash:
        if not data:
            raise ValueError('A data hash or data string is required.')
        data_hash = hex_hash160(data)
    elif not (is_hex(data_hash) and len(data_hash) == 40):
        raise ValueError('Data hash must be a 20 byte hex string.')

    readable_script = 'NAME_UPDATE %i %s %s' % (name_len, hex_name, data_hash)
    hex_script = name_script_to_hex(readable_script)
    packaged_script = add_magic_bytes(hex_script, testset=testset)

    return packaged_script
Example #6
0
def build(name, data_hash=None, data=None, testset=False):
    """ Takes in the name to update the data for and the data update itself.
    """
    hex_name = b40_to_hex(name)
    name_len = len(hex_name) / 2

    if not data_hash:
        if not data:
            raise ValueError('A data hash or data string is required.')
        data_hash = hex_hash160(data)
    elif not (is_hex(data_hash) and len(data_hash) == 40):
        raise ValueError('Data hash must be a 20 byte hex string.')

    readable_script = 'NAME_UPDATE %i %s %s' % (name_len, hex_name, data_hash)
    hex_script = name_script_to_hex(readable_script)
    packaged_script = add_magic_bytes(hex_script, testset=testset)

    return packaged_script
Example #7
0
    def __setitem__(self, key, value):

        try:
            test_value = json.loads(value)
        except:
            self.log.info("value not JSON, not storing")
            return

        hash = coinkit.hex_hash160(value)
        test_key = digest(hash)

        if key != test_key:
            self.log.info("hash(value) doesn't match, not storing")
            return

        if key in self.data:
            del self.data[key]

        self.data[key] = (time.time(), value)
        self.cull()
Example #8
0
    def __setitem__(self, key, value):

        try:
            test_value = json.loads(value)
        except:
            self.log.info("value not JSON, not storing")
            return

        hash = coinkit.hex_hash160(value)
        test_key = digest(hash)

        if key != test_key:
            self.log.info("hash(value) doesn't match, not storing")
            return

        if key in self.data:
            del self.data[key]

        self.data[key] = (time.time(), value)
        self.cull()
Example #9
0
    def jsonrpc_set(self, key, value):
        """
        """

        reply = {}

        try:
            test_value = json.loads(value)
        except Exception as e:
            print e
            reply['error'] = "value not JSON, not storing"
            return reply

        hash = coinkit.hex_hash160(value)
        test_key = hash

        if key != test_key:
            reply['error'] = "hash(value) doesn't match, not storing"
            return reply

        return self.dht_server.set(key, value)
Example #10
0
    def jsonrpc_set(self, key, value):
        """
        """

        reply = {}

        try:
            test_value = json.loads(value)
        except Exception as e:
            print e
            reply['error'] = "value not JSON, not storing"
            return reply

        hash = coinkit.hex_hash160(value)
        test_key = hash

        if key != test_key:
            reply['error'] = "hash(value) doesn't match, not storing"
            return reply

        return self.dht_server.set(key, value)
Example #11
0
def run_cli():
    """ run cli
    """
    parser = argparse.ArgumentParser(
        description='Blockstore Cli version {}'.format(config.VERSION))

    parser.add_argument(
        '--blockstored-server',
        help="""the hostname or IP address of the blockstored RPC server
                (default: {})""".format(config.BLOCKSTORED_SERVER))
    parser.add_argument('--blockstored-port',
                        type=int,
                        help="""the blockstored RPC port to connect to
                (default: {})""".format(config.BLOCKSTORED_PORT))

    subparsers = parser.add_subparsers(dest='action',
                                       help='the action to be taken')

    subparser = subparsers.add_parser(
        'getinfo', help='get basic info from the blockstored server')

    subparser = subparsers.add_parser(
        'ping', help='check if the blockstored server is up')

    # ------------------------------------
    subparser = subparsers.add_parser(
        'preorder', help='<name> <privatekey> | preorder a name')
    subparser.add_argument('name',
                           type=str,
                           help='the name that you want to preorder')
    subparser.add_argument(
        'privatekey',
        type=str,
        help='the private key of the Bitcoin address that will own the name')

    # ------------------------------------
    subparser = subparsers.add_parser(
        'register', help='<name> <privatekey> | register/claim a name')
    subparser.add_argument('name',
                           type=str,
                           help='the name that you want to register/claim')
    subparser.add_argument(
        'privatekey',
        type=str,
        help='the private key of the Bitcoin address that will own the name')

    # ------------------------------------
    subparser = subparsers.add_parser(
        'update', help='<name> <data or datahash> <privatekey> | update data')
    subparser.add_argument('name',
                           type=str,
                           help='the name that you want to update')
    subparser.add_argument(
        'data',
        type=str,
        help='data associated with name (value part of key-value) or datahash')
    subparser.add_argument('privatekey',
                           type=str,
                           help='the privatekey of the owner Bitcoin address')

    # ------------------------------------
    subparser = subparsers.add_parser(
        'transfer', help='<name> <address> <privatekey> | transfer a name')
    subparser.add_argument('name',
                           type=str,
                           help='the name that you want to register/claim')
    subparser.add_argument('address',
                           type=str,
                           help='the new owner Bitcoin address')
    subparser.add_argument('privatekey',
                           type=str,
                           help='the privatekey of the owner Bitcoin address')

    # ------------------------------------
    subparser = subparsers.add_parser(
        'renew', help='<name> <privatekey> | renew a name')
    subparser.add_argument('name',
                           type=str,
                           help='the name that you want to renew')
    subparser.add_argument('privatekey',
                           type=str,
                           help='the privatekey of the owner Bitcoin address')

    # ------------------------------------
    subparser = subparsers.add_parser(
        'storedata', help='<data> | data value to store in DHT')
    subparser.add_argument('data', type=str, help='the data to store in DHT')

    # ------------------------------------
    subparser = subparsers.add_parser(
        'getdata', help='<hash> | get the data from DHT for given hash')
    subparser.add_argument(
        'hash',
        type=str,
        help='the hash of the data, used as lookup key for DHT')

    subparser = subparsers.add_parser(
        'lookup', help='<name> | get the record for a given name')
    subparser.add_argument('name', type=str, help='the name to look up')

    # Print default help message, if no argument is given
    if len(sys.argv) == 1:
        parser.print_help()
        sys.exit(1)

    args = parser.parse_args()

    if args.action == 'getinfo':
        client = proxy.callRemote('getinfo')

    elif args.action == 'ping':
        client = proxy.callRemote('ping')

    elif args.action == 'preorder':
        logger.debug('Preordering %s', args.name)
        client = proxy.callRemote('preorder', str(args.name),
                                  str(args.privatekey))

    elif args.action == 'register':
        logger.debug('Registering %s', args.name)
        client = proxy.callRemote('register', args.name, args.privatekey)

    elif args.action == 'update':
        logger.debug('Updating %s', args.name)
        client = proxy.callRemote('update', args.name, args.data,
                                  args.privatekey)

    elif args.action == 'transfer':
        logger.debug('Transfering %s', args.name)
        client = proxy.callRemote('transfer', args.name, args.address,
                                  args.privatekey)

    elif args.action == 'renew':
        logger.debug('Renewing %s', args.name)
        client = proxy.callRemote('renew', args.name, args.privatekey)

    elif args.action == 'storedata':
        reply = {}
        value = args.data

        key = coinkit.hex_hash160(value)
        logger.debug('Storing %s', value)

        client = proxy.callRemote('set', key, value)

    elif args.action == 'getdata':
        logger.debug('Getting %s', args.hash)

        client = proxy.callRemote('get', args.hash)
        client.addCallback(getFormat)

    elif args.action == 'lookup':
        logger.debug('Looking up %s', args.name)
        client = proxy.callRemote('lookup', args.name)

    client.addCallback(printValue).addErrback(printError).addBoth(shutDown)
    reactor.run()
def run_cli():
    """ run cli
    """
    parser = argparse.ArgumentParser(
        description='Blockstore Cli version {}'.format(config.VERSION))

    parser.add_argument(
        '--blockstored-server',
        help="""the hostname or IP address of the blockstored RPC server
                (default: {})""".format(config.BLOCKSTORED_SERVER))
    parser.add_argument(
        '--blockstored-port', type=int,
        help="""the blockstored RPC port to connect to
                (default: {})""".format(config.BLOCKSTORED_PORT))

    subparsers = parser.add_subparsers(
        dest='action',
        help='the action to be taken')

    subparser = subparsers.add_parser(
        'getinfo',
        help='get basic info from the blockstored server')

    subparser = subparsers.add_parser(
        'ping',
        help='check if the blockstored server is up')

    # ------------------------------------
    subparser = subparsers.add_parser(
        'preorder',
        help='<name> <privatekey> | preorder a name')
    subparser.add_argument(
        'name', type=str,
        help='the name that you want to preorder')
    subparser.add_argument(
        'privatekey', type=str,
        help='the private key of the Bitcoin address that will own the name')

    # ------------------------------------
    subparser = subparsers.add_parser(
        'register',
        help='<name> <privatekey> | register/claim a name')
    subparser.add_argument(
        'name', type=str,
        help='the name that you want to register/claim')
    subparser.add_argument(
        'privatekey', type=str,
        help='the private key of the Bitcoin address that will own the name')

    # ------------------------------------
    subparser = subparsers.add_parser(
        'update',
        help='<name> <data or datahash> <privatekey> | update data')
    subparser.add_argument(
        'name', type=str,
        help='the name that you want to update')
    subparser.add_argument(
        'data', type=str,
        help='data associated with name (value part of key-value) or datahash')
    subparser.add_argument(
        'privatekey', type=str,
        help='the privatekey of the owner Bitcoin address')

    # ------------------------------------
    subparser = subparsers.add_parser(
        'transfer',
        help='<name> <address> <privatekey> | transfer a name')
    subparser.add_argument(
        'name', type=str,
        help='the name that you want to register/claim')
    subparser.add_argument(
        'address', type=str,
        help='the new owner Bitcoin address')
    subparser.add_argument(
        'privatekey', type=str,
        help='the privatekey of the owner Bitcoin address')

    # ------------------------------------
    subparser = subparsers.add_parser(
        'renew',
        help='<name> <privatekey> | renew a name')
    subparser.add_argument(
        'name', type=str,
        help='the name that you want to renew')
    subparser.add_argument(
        'privatekey', type=str,
        help='the privatekey of the owner Bitcoin address')

    # ------------------------------------
    subparser = subparsers.add_parser(
        'storedata',
        help='<data> | data value to store in DHT')
    subparser.add_argument(
        'data', type=str,
        help='the data to store in DHT')

    # ------------------------------------
    subparser = subparsers.add_parser(
        'getdata',
        help='<hash> | get the data from DHT for given hash')
    subparser.add_argument(
        'hash', type=str,
        help='the hash of the data, used as lookup key for DHT')

    subparser = subparsers.add_parser(
        'lookup',
        help='<name> | get the record for a given name')
    subparser.add_argument(
        'name', type=str,
        help='the name to look up')

    # Print default help message, if no argument is given
    if len(sys.argv) == 1:
        parser.print_help()
        sys.exit(1)

    args = parser.parse_args()

    if args.action == 'getinfo':
        client = proxy.callRemote('getinfo')

    elif args.action == 'ping':
        client = proxy.callRemote('ping')

    elif args.action == 'preorder':
        logger.debug('Preordering %s', args.name)
        client = proxy.callRemote(
            'preorder', str(args.name), str(args.privatekey))

    elif args.action == 'register':
        logger.debug('Registering %s', args.name)
        client = proxy.callRemote('register', args.name, args.privatekey)

    elif args.action == 'update':
        logger.debug('Updating %s', args.name)
        client = proxy.callRemote('update', args.name, args.data,
                                  args.privatekey)

    elif args.action == 'transfer':
        logger.debug('Transfering %s', args.name)
        client = proxy.callRemote('transfer', args.name, args.address,
                                  args.privatekey)

    elif args.action == 'renew':
        logger.debug('Renewing %s', args.name)
        client = proxy.callRemote('renew', args.name, args.privatekey)

    elif args.action == 'storedata':
        reply = {}
        value = args.data

        key = coinkit.hex_hash160(value)
        logger.debug('Storing %s', value)

        client = proxy.callRemote('set', key, value)

    elif args.action == 'getdata':
        logger.debug('Getting %s', args.hash)

        client = proxy.callRemote('get', args.hash)
        client.addCallback(getFormat)

    elif args.action == 'lookup':
        logger.debug('Looking up %s', args.name)
        client = proxy.callRemote('lookup', args.name)

    client.addCallback(printValue).addErrback(printError).addBoth(shutDown)
    reactor.run()
Example #13
0
def hash_name(name, script_pubkey):
    bin_name = b40_to_bin(name)
    name_and_pubkey = bin_name + unhexlify(script_pubkey)
    return hex_hash160(name_and_pubkey)
Example #14
0
from twisted.internet import reactor
from twisted.python import log

from kademlia.network import Server

import sys
import coinkit
import json

log.startLogging(sys.stdout)

#key = 'u/muneeb'
#value = "temp"

value = '{"name": "Muneeb Ali Khan"}'
key = coinkit.hex_hash160(value)

print key
print value

hold_display = None

from storage import BlockStorage


def done(result):
    print "Key result: ", result
    print "Found: ", hold_display
    reactor.stop()

Example #15
0
def hash_name(name, script_pubkey):
    bin_name = b40_to_bin(name)
    name_and_pubkey = bin_name + unhexlify(script_pubkey)
    return hex_hash160(name_and_pubkey)
Example #16
0
from twisted.internet import reactor
from twisted.python import log

from kademlia.network import Server

import sys
import coinkit
import json

log.startLogging(sys.stdout)

#key = 'u/muneeb'
#value = "temp"

value = '{"name": "Muneeb Ali Khan"}'
key = coinkit.hex_hash160(value)

print key
print value

hold_display = None

from storage import BlockStorage


def done(result):
    print "Key result: ", result
    print "Found: ", hold_display
    reactor.stop()