Files
stacks-puppet-node/blockstore/lib/operations/revoke.py
2015-09-15 22:09:04 -04:00

92 lines
2.9 KiB
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Blockstore
~~~~~
copyright: (c) 2014 by Halfmoon Labs, Inc.
copyright: (c) 2015 by Blockstack.org
This file is part of Blockstore
Blockstore is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Blockstore is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Blockstore. If not, see <http://www.gnu.org/licenses/>.
"""
from pybitcoin import embed_data_in_blockchain, BlockchainInfoClient
from utilitybelt import is_hex
from binascii import hexlify, unhexlify
from ..b40 import b40_to_hex, bin_to_b40, is_b40
from ..config import *
from ..scripts import blockstore_script_to_hex, add_magic_bytes
def build(name, testset=False):
"""
Takes in the name, including the namespace ID (but not the id: scheme)
Returns a hex string representing up to LENGTHS['blockchain_id_name'] bytes.
Record format:
0 2 3 39
|----|--|-----------------------------|
magic op name.ns_id (37 bytes)
"""
if not is_b40( name ) or "+" in name or name.count(".") > 1:
raise Exception("Name '%s' has non-base-38 characters" % name)
name_hex = hexlify(name)
if len(name_hex) > LENGTHS['blockchain_id_name'] * 2:
# too long
raise Exception("Name '%s' too long (exceeds %d bytes)" % (fqn, LENGTHS['blockchain_id_name']))
readable_script = "NAME_REVOKE 0x%s" % (hexlify(name))
hex_script = blockstore_script_to_hex(readable_script)
packaged_script = add_magic_bytes(hex_script, testset=testset)
return packaged_script
def broadcast(name, private_key, blockchain_client, testset=False):
nulldata = build(name, testset=testset)
# response = {'success': True }
response = embed_data_in_blockchain( nulldata, private_key, blockchain_client, format='hex')
response.update({'data': nulldata})
return response
def parse(bin_payload):
"""
Interpret a block's nulldata back into a name. The first three bytes (2 magic + 1 opcode)
will not be present in bin_payload.
The name will be directly represented by the bytes given.
"""
fqn = bin_payload
return {
'opcode': 'NAME_REVOKE',
'name': fqn
}
def serialize( nameop ):
"""
Convert the set of data obtained from parsing the revoke into a unique string.
"""
return NAME_REVOKE + ":" + nameop['name']