id
int32
0
252k
repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
51
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
244,400
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.build_import_keychain
def build_import_keychain( cls, keychain_dir, namespace_id, pubkey_hex ): """ Generate all possible NAME_IMPORT addresses from the NAMESPACE_REVEAL public key """ pubkey_addr = virtualchain.BitcoinPublicKey(str(pubkey_hex)).address() # do we have a cached one on disk? cached_keychain = cls.get_import_keychain_path(keychain_dir, namespace_id) if os.path.exists( cached_keychain ): child_addrs = [] try: lines = [] with open(cached_keychain, "r") as f: lines = f.readlines() child_attrs = [l.strip() for l in lines] log.debug("Loaded cached import keychain for '%s' (%s)" % (pubkey_hex, pubkey_addr)) return child_attrs except Exception, e: log.exception(e) pass pubkey_hex = str(pubkey_hex) public_keychain = keychain.PublicKeychain.from_public_key( pubkey_hex ) child_addrs = [] for i in xrange(0, NAME_IMPORT_KEYRING_SIZE): public_child = public_keychain.child(i) public_child_address = public_child.address() # if we're on testnet, then re-encode as a testnet address if virtualchain.version_byte == 111: old_child_address = public_child_address public_child_address = virtualchain.hex_hash160_to_address( virtualchain.address_to_hex_hash160( public_child_address ) ) log.debug("Re-encode '%s' to '%s'" % (old_child_address, public_child_address)) child_addrs.append( public_child_address ) if i % 20 == 0 and i != 0: log.debug("%s children..." % i) # include this address child_addrs.append( pubkey_addr ) log.debug("Done building import keychain for '%s' (%s)" % (pubkey_hex, pubkey_addr)) # cache try: with open(cached_keychain, "w+") as f: for addr in child_addrs: f.write("%s\n" % addr) f.flush() log.debug("Cached keychain to '%s'" % cached_keychain) except Exception, e: log.exception(e) log.error("Unable to cache keychain for '%s' (%s)" % (pubkey_hex, pubkey_addr)) return child_addrs
python
def build_import_keychain( cls, keychain_dir, namespace_id, pubkey_hex ): pubkey_addr = virtualchain.BitcoinPublicKey(str(pubkey_hex)).address() # do we have a cached one on disk? cached_keychain = cls.get_import_keychain_path(keychain_dir, namespace_id) if os.path.exists( cached_keychain ): child_addrs = [] try: lines = [] with open(cached_keychain, "r") as f: lines = f.readlines() child_attrs = [l.strip() for l in lines] log.debug("Loaded cached import keychain for '%s' (%s)" % (pubkey_hex, pubkey_addr)) return child_attrs except Exception, e: log.exception(e) pass pubkey_hex = str(pubkey_hex) public_keychain = keychain.PublicKeychain.from_public_key( pubkey_hex ) child_addrs = [] for i in xrange(0, NAME_IMPORT_KEYRING_SIZE): public_child = public_keychain.child(i) public_child_address = public_child.address() # if we're on testnet, then re-encode as a testnet address if virtualchain.version_byte == 111: old_child_address = public_child_address public_child_address = virtualchain.hex_hash160_to_address( virtualchain.address_to_hex_hash160( public_child_address ) ) log.debug("Re-encode '%s' to '%s'" % (old_child_address, public_child_address)) child_addrs.append( public_child_address ) if i % 20 == 0 and i != 0: log.debug("%s children..." % i) # include this address child_addrs.append( pubkey_addr ) log.debug("Done building import keychain for '%s' (%s)" % (pubkey_hex, pubkey_addr)) # cache try: with open(cached_keychain, "w+") as f: for addr in child_addrs: f.write("%s\n" % addr) f.flush() log.debug("Cached keychain to '%s'" % cached_keychain) except Exception, e: log.exception(e) log.error("Unable to cache keychain for '%s' (%s)" % (pubkey_hex, pubkey_addr)) return child_addrs
[ "def", "build_import_keychain", "(", "cls", ",", "keychain_dir", ",", "namespace_id", ",", "pubkey_hex", ")", ":", "pubkey_addr", "=", "virtualchain", ".", "BitcoinPublicKey", "(", "str", "(", "pubkey_hex", ")", ")", ".", "address", "(", ")", "# do we have a cac...
Generate all possible NAME_IMPORT addresses from the NAMESPACE_REVEAL public key
[ "Generate", "all", "possible", "NAME_IMPORT", "addresses", "from", "the", "NAMESPACE_REVEAL", "public", "key" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L350-L413
244,401
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.load_import_keychain
def load_import_keychain( cls, working_dir, namespace_id ): """ Get an import keychain from disk. Return None if it doesn't exist. """ # do we have a cached one on disk? cached_keychain = os.path.join(working_dir, "%s.keychain" % namespace_id) if os.path.exists( cached_keychain ): log.debug("Load import keychain '%s'" % cached_keychain) child_addrs = [] try: lines = [] with open(cached_keychain, "r") as f: lines = f.readlines() child_attrs = [l.strip() for l in lines] log.debug("Loaded cached import keychain for '%s'" % namespace_id) return child_attrs except Exception, e: log.exception(e) log.error("FATAL: uncaught exception loading the import keychain") os.abort() else: log.debug("No import keychain at '%s'" % cached_keychain) return None
python
def load_import_keychain( cls, working_dir, namespace_id ): # do we have a cached one on disk? cached_keychain = os.path.join(working_dir, "%s.keychain" % namespace_id) if os.path.exists( cached_keychain ): log.debug("Load import keychain '%s'" % cached_keychain) child_addrs = [] try: lines = [] with open(cached_keychain, "r") as f: lines = f.readlines() child_attrs = [l.strip() for l in lines] log.debug("Loaded cached import keychain for '%s'" % namespace_id) return child_attrs except Exception, e: log.exception(e) log.error("FATAL: uncaught exception loading the import keychain") os.abort() else: log.debug("No import keychain at '%s'" % cached_keychain) return None
[ "def", "load_import_keychain", "(", "cls", ",", "working_dir", ",", "namespace_id", ")", ":", "# do we have a cached one on disk?", "cached_keychain", "=", "os", ".", "path", ".", "join", "(", "working_dir", ",", "\"%s.keychain\"", "%", "namespace_id", ")", "if", ...
Get an import keychain from disk. Return None if it doesn't exist.
[ "Get", "an", "import", "keychain", "from", "disk", ".", "Return", "None", "if", "it", "doesn", "t", "exist", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L417-L447
244,402
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.commit_finished
def commit_finished( self, block_id ): """ Called when the block is finished. Commits all data. """ self.db.commit() # NOTE: tokens vest for the *next* block in order to make the immediately usable assert block_id+1 in self.vesting, 'BUG: failed to vest at {}'.format(block_id) self.clear_collisions( block_id ) self.clear_vesting(block_id+1)
python
def commit_finished( self, block_id ): self.db.commit() # NOTE: tokens vest for the *next* block in order to make the immediately usable assert block_id+1 in self.vesting, 'BUG: failed to vest at {}'.format(block_id) self.clear_collisions( block_id ) self.clear_vesting(block_id+1)
[ "def", "commit_finished", "(", "self", ",", "block_id", ")", ":", "self", ".", "db", ".", "commit", "(", ")", "# NOTE: tokens vest for the *next* block in order to make the immediately usable", "assert", "block_id", "+", "1", "in", "self", ".", "vesting", ",", "'BUG...
Called when the block is finished. Commits all data.
[ "Called", "when", "the", "block", "is", "finished", ".", "Commits", "all", "data", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L458-L470
244,403
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.log_commit
def log_commit( self, block_id, vtxindex, op, opcode, op_data ): """ Log a committed operation """ debug_op = self.sanitize_op( op_data ) if 'history' in debug_op: del debug_op['history'] log.debug("COMMIT %s (%s) at (%s, %s) data: %s", opcode, op, block_id, vtxindex, ", ".join( ["%s='%s'" % (k, debug_op[k]) for k in sorted(debug_op.keys())] ) ) return
python
def log_commit( self, block_id, vtxindex, op, opcode, op_data ): debug_op = self.sanitize_op( op_data ) if 'history' in debug_op: del debug_op['history'] log.debug("COMMIT %s (%s) at (%s, %s) data: %s", opcode, op, block_id, vtxindex, ", ".join( ["%s='%s'" % (k, debug_op[k]) for k in sorted(debug_op.keys())] ) ) return
[ "def", "log_commit", "(", "self", ",", "block_id", ",", "vtxindex", ",", "op", ",", "opcode", ",", "op_data", ")", ":", "debug_op", "=", "self", ".", "sanitize_op", "(", "op_data", ")", "if", "'history'", "in", "debug_op", ":", "del", "debug_op", "[", ...
Log a committed operation
[ "Log", "a", "committed", "operation" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L489-L501
244,404
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.log_reject
def log_reject( self, block_id, vtxindex, op, op_data ): """ Log a rejected operation """ debug_op = self.sanitize_op( op_data ) if 'history' in debug_op: del debug_op['history'] log.debug("REJECT %s at (%s, %s) data: %s", op_get_opcode_name( op ), block_id, vtxindex, ", ".join( ["%s='%s'" % (k, debug_op[k]) for k in sorted(debug_op.keys())] )) return
python
def log_reject( self, block_id, vtxindex, op, op_data ): debug_op = self.sanitize_op( op_data ) if 'history' in debug_op: del debug_op['history'] log.debug("REJECT %s at (%s, %s) data: %s", op_get_opcode_name( op ), block_id, vtxindex, ", ".join( ["%s='%s'" % (k, debug_op[k]) for k in sorted(debug_op.keys())] )) return
[ "def", "log_reject", "(", "self", ",", "block_id", ",", "vtxindex", ",", "op", ",", "op_data", ")", ":", "debug_op", "=", "self", ".", "sanitize_op", "(", "op_data", ")", "if", "'history'", "in", "debug_op", ":", "del", "debug_op", "[", "'history'", "]",...
Log a rejected operation
[ "Log", "a", "rejected", "operation" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L504-L516
244,405
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.sanitize_op
def sanitize_op( self, op_data ): """ Remove unnecessary fields for an operation, i.e. prior to committing it. This includes any invariant tags we've added with our invariant decorators (such as @state_create or @state_transition). TODO: less ad-hoc way to do this """ op_data = super(BlockstackDB, self).sanitize_op(op_data) # remove invariant tags (i.e. added by our invariant state_* decorators) to_remove = get_state_invariant_tags() for tag in to_remove: if tag in op_data.keys(): del op_data[tag] # NOTE: this is called the opcode family, because # different operation names can have the same operation code # (such as NAME_RENEWAL and NAME_REGISTRATION). They must # have the same mutation fields. opcode_family = op_get_opcode_name( op_data['op'] ) # for each column in the appropriate state table, # if the column is not identified in the operation's # MUTATE_FIELDS list, then set it to None here. mutate_fields = op_get_mutate_fields( opcode_family ) for mf in mutate_fields: if not op_data.has_key( mf ): log.debug("Adding NULL mutate field '%s.%s'" % (opcode_family, mf )) op_data[mf] = None # TODO: less ad-hoc for extra_field in ['opcode']: if extra_field in op_data: del op_data[extra_field] return op_data
python
def sanitize_op( self, op_data ): op_data = super(BlockstackDB, self).sanitize_op(op_data) # remove invariant tags (i.e. added by our invariant state_* decorators) to_remove = get_state_invariant_tags() for tag in to_remove: if tag in op_data.keys(): del op_data[tag] # NOTE: this is called the opcode family, because # different operation names can have the same operation code # (such as NAME_RENEWAL and NAME_REGISTRATION). They must # have the same mutation fields. opcode_family = op_get_opcode_name( op_data['op'] ) # for each column in the appropriate state table, # if the column is not identified in the operation's # MUTATE_FIELDS list, then set it to None here. mutate_fields = op_get_mutate_fields( opcode_family ) for mf in mutate_fields: if not op_data.has_key( mf ): log.debug("Adding NULL mutate field '%s.%s'" % (opcode_family, mf )) op_data[mf] = None # TODO: less ad-hoc for extra_field in ['opcode']: if extra_field in op_data: del op_data[extra_field] return op_data
[ "def", "sanitize_op", "(", "self", ",", "op_data", ")", ":", "op_data", "=", "super", "(", "BlockstackDB", ",", "self", ")", ".", "sanitize_op", "(", "op_data", ")", "# remove invariant tags (i.e. added by our invariant state_* decorators)", "to_remove", "=", "get_sta...
Remove unnecessary fields for an operation, i.e. prior to committing it. This includes any invariant tags we've added with our invariant decorators (such as @state_create or @state_transition). TODO: less ad-hoc way to do this
[ "Remove", "unnecessary", "fields", "for", "an", "operation", "i", ".", "e", ".", "prior", "to", "committing", "it", ".", "This", "includes", "any", "invariant", "tags", "we", "ve", "added", "with", "our", "invariant", "decorators", "(", "such", "as" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L519-L556
244,406
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.put_collisions
def put_collisions( self, block_id, collisions ): """ Put collision state for a particular block. Any operations checked at this block_id that collide with the given collision state will be rejected. """ self.collisions[ block_id ] = copy.deepcopy( collisions )
python
def put_collisions( self, block_id, collisions ): self.collisions[ block_id ] = copy.deepcopy( collisions )
[ "def", "put_collisions", "(", "self", ",", "block_id", ",", "collisions", ")", ":", "self", ".", "collisions", "[", "block_id", "]", "=", "copy", ".", "deepcopy", "(", "collisions", ")" ]
Put collision state for a particular block. Any operations checked at this block_id that collide with the given collision state will be rejected.
[ "Put", "collision", "state", "for", "a", "particular", "block", ".", "Any", "operations", "checked", "at", "this", "block_id", "that", "collide", "with", "the", "given", "collision", "state", "will", "be", "rejected", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L625-L631
244,407
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.get_namespace
def get_namespace( self, namespace_id, include_history=True ): """ Given a namespace ID, get the ready namespace op for it. Return the dict with the parameters on success. Return None if the namespace has not yet been revealed. """ cur = self.db.cursor() return namedb_get_namespace_ready( cur, namespace_id, include_history=include_history )
python
def get_namespace( self, namespace_id, include_history=True ): cur = self.db.cursor() return namedb_get_namespace_ready( cur, namespace_id, include_history=include_history )
[ "def", "get_namespace", "(", "self", ",", "namespace_id", ",", "include_history", "=", "True", ")", ":", "cur", "=", "self", ".", "db", ".", "cursor", "(", ")", "return", "namedb_get_namespace_ready", "(", "cur", ",", "namespace_id", ",", "include_history", ...
Given a namespace ID, get the ready namespace op for it. Return the dict with the parameters on success. Return None if the namespace has not yet been revealed.
[ "Given", "a", "namespace", "ID", "get", "the", "ready", "namespace", "op", "for", "it", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L705-L714
244,408
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.get_DID_name
def get_DID_name(self, did): """ Given a DID, get the name Return None if not found, or if the name was revoked Raise if the DID is invalid """ did = str(did) did_info = None try: did_info = parse_DID(did) assert did_info['name_type'] == 'name' except Exception as e: if BLOCKSTACK_DEBUG: log.exception(e) raise ValueError("Invalid DID: {}".format(did)) cur = self.db.cursor() historic_name_info = namedb_get_historic_names_by_address(cur, did_info['address'], offset=did_info['index'], count=1) if historic_name_info is None: # no such name return None name = historic_name_info[0]['name'] block_height = historic_name_info[0]['block_id'] vtxindex = historic_name_info[0]['vtxindex'] log.debug("DID {} refers to {}-{}-{}".format(did, name, block_height, vtxindex)) name_rec = self.get_name(name, include_history=True, include_expired=True) if name_rec is None: # dead return None name_rec_latest = None found = False for height in sorted(name_rec['history'].keys()): if found: break if height < block_height: continue for state in name_rec['history'][height]: if height == block_height and state['vtxindex'] < vtxindex: # too soon continue if state['op'] == NAME_PREORDER: # looped to the next iteration of this name found = True break if state['revoked']: # revoked log.debug("DID {} refers to {}-{}-{}, which is revoked at {}-{}".format(did, name, block_height, vtxindex, height, state['vtxindex'])) return None name_rec_latest = state return name_rec_latest
python
def get_DID_name(self, did): did = str(did) did_info = None try: did_info = parse_DID(did) assert did_info['name_type'] == 'name' except Exception as e: if BLOCKSTACK_DEBUG: log.exception(e) raise ValueError("Invalid DID: {}".format(did)) cur = self.db.cursor() historic_name_info = namedb_get_historic_names_by_address(cur, did_info['address'], offset=did_info['index'], count=1) if historic_name_info is None: # no such name return None name = historic_name_info[0]['name'] block_height = historic_name_info[0]['block_id'] vtxindex = historic_name_info[0]['vtxindex'] log.debug("DID {} refers to {}-{}-{}".format(did, name, block_height, vtxindex)) name_rec = self.get_name(name, include_history=True, include_expired=True) if name_rec is None: # dead return None name_rec_latest = None found = False for height in sorted(name_rec['history'].keys()): if found: break if height < block_height: continue for state in name_rec['history'][height]: if height == block_height and state['vtxindex'] < vtxindex: # too soon continue if state['op'] == NAME_PREORDER: # looped to the next iteration of this name found = True break if state['revoked']: # revoked log.debug("DID {} refers to {}-{}-{}, which is revoked at {}-{}".format(did, name, block_height, vtxindex, height, state['vtxindex'])) return None name_rec_latest = state return name_rec_latest
[ "def", "get_DID_name", "(", "self", ",", "did", ")", ":", "did", "=", "str", "(", "did", ")", "did_info", "=", "None", "try", ":", "did_info", "=", "parse_DID", "(", "did", ")", "assert", "did_info", "[", "'name_type'", "]", "==", "'name'", "except", ...
Given a DID, get the name Return None if not found, or if the name was revoked Raise if the DID is invalid
[ "Given", "a", "DID", "get", "the", "name", "Return", "None", "if", "not", "found", "or", "if", "the", "name", "was", "revoked", "Raise", "if", "the", "DID", "is", "invalid" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L788-L849
244,409
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.get_account_tokens
def get_account_tokens(self, address): """ Get the list of tokens that this address owns """ cur = self.db.cursor() return namedb_get_account_tokens(cur, address)
python
def get_account_tokens(self, address): cur = self.db.cursor() return namedb_get_account_tokens(cur, address)
[ "def", "get_account_tokens", "(", "self", ",", "address", ")", ":", "cur", "=", "self", ".", "db", ".", "cursor", "(", ")", "return", "namedb_get_account_tokens", "(", "cur", ",", "address", ")" ]
Get the list of tokens that this address owns
[ "Get", "the", "list", "of", "tokens", "that", "this", "address", "owns" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L852-L857
244,410
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.get_account
def get_account(self, address, token_type): """ Get the state of an account for a given token type """ cur = self.db.cursor() return namedb_get_account(cur, address, token_type)
python
def get_account(self, address, token_type): cur = self.db.cursor() return namedb_get_account(cur, address, token_type)
[ "def", "get_account", "(", "self", ",", "address", ",", "token_type", ")", ":", "cur", "=", "self", ".", "db", ".", "cursor", "(", ")", "return", "namedb_get_account", "(", "cur", ",", "address", ",", "token_type", ")" ]
Get the state of an account for a given token type
[ "Get", "the", "state", "of", "an", "account", "for", "a", "given", "token", "type" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L860-L865
244,411
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.get_account_balance
def get_account_balance(self, account): """ What's the balance of an account? Aborts if its negative """ balance = namedb_get_account_balance(account) assert isinstance(balance, (int,long)), 'BUG: account balance of {} is {} (type {})'.format(account['address'], balance, type(balance)) return balance
python
def get_account_balance(self, account): balance = namedb_get_account_balance(account) assert isinstance(balance, (int,long)), 'BUG: account balance of {} is {} (type {})'.format(account['address'], balance, type(balance)) return balance
[ "def", "get_account_balance", "(", "self", ",", "account", ")", ":", "balance", "=", "namedb_get_account_balance", "(", "account", ")", "assert", "isinstance", "(", "balance", ",", "(", "int", ",", "long", ")", ")", ",", "'BUG: account balance of {} is {} (type {}...
What's the balance of an account? Aborts if its negative
[ "What", "s", "the", "balance", "of", "an", "account?", "Aborts", "if", "its", "negative" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L868-L875
244,412
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.get_account_history
def get_account_history(self, address, offset=None, count=None): """ Get the history of account transactions over a block range Returns a dict keyed by blocks, which map to lists of account state transitions """ cur = self.db.cursor() return namedb_get_account_history(cur, address, offset=offset, count=count)
python
def get_account_history(self, address, offset=None, count=None): cur = self.db.cursor() return namedb_get_account_history(cur, address, offset=offset, count=count)
[ "def", "get_account_history", "(", "self", ",", "address", ",", "offset", "=", "None", ",", "count", "=", "None", ")", ":", "cur", "=", "self", ".", "db", ".", "cursor", "(", ")", "return", "namedb_get_account_history", "(", "cur", ",", "address", ",", ...
Get the history of account transactions over a block range Returns a dict keyed by blocks, which map to lists of account state transitions
[ "Get", "the", "history", "of", "account", "transactions", "over", "a", "block", "range", "Returns", "a", "dict", "keyed", "by", "blocks", "which", "map", "to", "lists", "of", "account", "state", "transitions" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L893-L899
244,413
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.get_name_at
def get_name_at( self, name, block_number, include_expired=False ): """ Generate and return the sequence of of states a name record was in at a particular block number. """ cur = self.db.cursor() return namedb_get_name_at(cur, name, block_number, include_expired=include_expired)
python
def get_name_at( self, name, block_number, include_expired=False ): cur = self.db.cursor() return namedb_get_name_at(cur, name, block_number, include_expired=include_expired)
[ "def", "get_name_at", "(", "self", ",", "name", ",", "block_number", ",", "include_expired", "=", "False", ")", ":", "cur", "=", "self", ".", "db", ".", "cursor", "(", ")", "return", "namedb_get_name_at", "(", "cur", ",", "name", ",", "block_number", ","...
Generate and return the sequence of of states a name record was in at a particular block number.
[ "Generate", "and", "return", "the", "sequence", "of", "of", "states", "a", "name", "record", "was", "in", "at", "a", "particular", "block", "number", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L912-L918
244,414
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.get_namespace_at
def get_namespace_at( self, namespace_id, block_number ): """ Generate and return the sequence of states a namespace record was in at a particular block number. Includes expired namespaces by default. """ cur = self.db.cursor() return namedb_get_namespace_at(cur, namespace_id, block_number, include_expired=True)
python
def get_namespace_at( self, namespace_id, block_number ): cur = self.db.cursor() return namedb_get_namespace_at(cur, namespace_id, block_number, include_expired=True)
[ "def", "get_namespace_at", "(", "self", ",", "namespace_id", ",", "block_number", ")", ":", "cur", "=", "self", ".", "db", ".", "cursor", "(", ")", "return", "namedb_get_namespace_at", "(", "cur", ",", "namespace_id", ",", "block_number", ",", "include_expired...
Generate and return the sequence of states a namespace record was in at a particular block number. Includes expired namespaces by default.
[ "Generate", "and", "return", "the", "sequence", "of", "states", "a", "namespace", "record", "was", "in", "at", "a", "particular", "block", "number", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L921-L929
244,415
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.get_account_at
def get_account_at(self, address, block_number): """ Get the sequence of states an account was in at a given block. Returns a list of states """ cur = self.db.cursor() return namedb_get_account_at(cur, address, block_number)
python
def get_account_at(self, address, block_number): cur = self.db.cursor() return namedb_get_account_at(cur, address, block_number)
[ "def", "get_account_at", "(", "self", ",", "address", ",", "block_number", ")", ":", "cur", "=", "self", ".", "db", ".", "cursor", "(", ")", "return", "namedb_get_account_at", "(", "cur", ",", "address", ",", "block_number", ")" ]
Get the sequence of states an account was in at a given block. Returns a list of states
[ "Get", "the", "sequence", "of", "states", "an", "account", "was", "in", "at", "a", "given", "block", ".", "Returns", "a", "list", "of", "states" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L932-L938
244,416
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.get_name_history
def get_name_history( self, name, offset=None, count=None, reverse=False): """ Get the historic states for a name, grouped by block height. """ cur = self.db.cursor() name_hist = namedb_get_history( cur, name, offset=offset, count=count, reverse=reverse ) return name_hist
python
def get_name_history( self, name, offset=None, count=None, reverse=False): cur = self.db.cursor() name_hist = namedb_get_history( cur, name, offset=offset, count=count, reverse=reverse ) return name_hist
[ "def", "get_name_history", "(", "self", ",", "name", ",", "offset", "=", "None", ",", "count", "=", "None", ",", "reverse", "=", "False", ")", ":", "cur", "=", "self", ".", "db", ".", "cursor", "(", ")", "name_hist", "=", "namedb_get_history", "(", "...
Get the historic states for a name, grouped by block height.
[ "Get", "the", "historic", "states", "for", "a", "name", "grouped", "by", "block", "height", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L941-L947
244,417
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.is_name_zonefile_hash
def is_name_zonefile_hash(self, name, zonefile_hash): """ Was a zone file sent by a name? """ cur = self.db.cursor() return namedb_is_name_zonefile_hash(cur, name, zonefile_hash)
python
def is_name_zonefile_hash(self, name, zonefile_hash): cur = self.db.cursor() return namedb_is_name_zonefile_hash(cur, name, zonefile_hash)
[ "def", "is_name_zonefile_hash", "(", "self", ",", "name", ",", "zonefile_hash", ")", ":", "cur", "=", "self", ".", "db", ".", "cursor", "(", ")", "return", "namedb_is_name_zonefile_hash", "(", "cur", ",", "name", ",", "zonefile_hash", ")" ]
Was a zone file sent by a name?
[ "Was", "a", "zone", "file", "sent", "by", "a", "name?" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L950-L955
244,418
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.get_all_blockstack_ops_at
def get_all_blockstack_ops_at( self, block_number, offset=None, count=None, include_history=None, restore_history=None ): """ Get all name, namespace, and account records affected at a particular block, in the state they were at the given block number. Paginate if offset, count are given. """ if include_history is not None: log.warn("DEPRECATED use of include_history") if restore_history is not None: log.warn("DEPRECATED use of restore_history") log.debug("Get all accepted operations at %s in %s" % (block_number, self.db_filename)) recs = namedb_get_all_blockstack_ops_at( self.db, block_number, offset=offset, count=count ) # include opcode for rec in recs: assert 'op' in rec rec['opcode'] = op_get_opcode_name(rec['op']) return recs
python
def get_all_blockstack_ops_at( self, block_number, offset=None, count=None, include_history=None, restore_history=None ): if include_history is not None: log.warn("DEPRECATED use of include_history") if restore_history is not None: log.warn("DEPRECATED use of restore_history") log.debug("Get all accepted operations at %s in %s" % (block_number, self.db_filename)) recs = namedb_get_all_blockstack_ops_at( self.db, block_number, offset=offset, count=count ) # include opcode for rec in recs: assert 'op' in rec rec['opcode'] = op_get_opcode_name(rec['op']) return recs
[ "def", "get_all_blockstack_ops_at", "(", "self", ",", "block_number", ",", "offset", "=", "None", ",", "count", "=", "None", ",", "include_history", "=", "None", ",", "restore_history", "=", "None", ")", ":", "if", "include_history", "is", "not", "None", ":"...
Get all name, namespace, and account records affected at a particular block, in the state they were at the given block number. Paginate if offset, count are given.
[ "Get", "all", "name", "namespace", "and", "account", "records", "affected", "at", "a", "particular", "block", "in", "the", "state", "they", "were", "at", "the", "given", "block", "number", ".", "Paginate", "if", "offset", "count", "are", "given", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L958-L979
244,419
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.get_name_from_name_hash128
def get_name_from_name_hash128( self, name ): """ Get the name from a name hash """ cur = self.db.cursor() name = namedb_get_name_from_name_hash128( cur, name, self.lastblock ) return name
python
def get_name_from_name_hash128( self, name ): cur = self.db.cursor() name = namedb_get_name_from_name_hash128( cur, name, self.lastblock ) return name
[ "def", "get_name_from_name_hash128", "(", "self", ",", "name", ")", ":", "cur", "=", "self", ".", "db", ".", "cursor", "(", ")", "name", "=", "namedb_get_name_from_name_hash128", "(", "cur", ",", "name", ",", "self", ".", "lastblock", ")", "return", "name"...
Get the name from a name hash
[ "Get", "the", "name", "from", "a", "name", "hash" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L990-L996
244,420
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.get_num_historic_names_by_address
def get_num_historic_names_by_address( self, address ): """ Get the number of names historically owned by an address """ cur = self.db.cursor() count = namedb_get_num_historic_names_by_address( cur, address ) return count
python
def get_num_historic_names_by_address( self, address ): cur = self.db.cursor() count = namedb_get_num_historic_names_by_address( cur, address ) return count
[ "def", "get_num_historic_names_by_address", "(", "self", ",", "address", ")", ":", "cur", "=", "self", ".", "db", ".", "cursor", "(", ")", "count", "=", "namedb_get_num_historic_names_by_address", "(", "cur", ",", "address", ")", "return", "count" ]
Get the number of names historically owned by an address
[ "Get", "the", "number", "of", "names", "historically", "owned", "by", "an", "address" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L1019-L1025
244,421
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.get_names_owned_by_sender
def get_names_owned_by_sender( self, sender_pubkey, lastblock=None ): """ Get the set of names owned by a particular script-pubkey. """ cur = self.db.cursor() if lastblock is None: lastblock = self.lastblock names = namedb_get_names_by_sender( cur, sender_pubkey, lastblock ) return names
python
def get_names_owned_by_sender( self, sender_pubkey, lastblock=None ): cur = self.db.cursor() if lastblock is None: lastblock = self.lastblock names = namedb_get_names_by_sender( cur, sender_pubkey, lastblock ) return names
[ "def", "get_names_owned_by_sender", "(", "self", ",", "sender_pubkey", ",", "lastblock", "=", "None", ")", ":", "cur", "=", "self", ".", "db", ".", "cursor", "(", ")", "if", "lastblock", "is", "None", ":", "lastblock", "=", "self", ".", "lastblock", "nam...
Get the set of names owned by a particular script-pubkey.
[ "Get", "the", "set", "of", "names", "owned", "by", "a", "particular", "script", "-", "pubkey", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L1028-L1037
244,422
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.get_num_names
def get_num_names( self, include_expired=False ): """ Get the number of names that exist. """ cur = self.db.cursor() return namedb_get_num_names( cur, self.lastblock, include_expired=include_expired )
python
def get_num_names( self, include_expired=False ): cur = self.db.cursor() return namedb_get_num_names( cur, self.lastblock, include_expired=include_expired )
[ "def", "get_num_names", "(", "self", ",", "include_expired", "=", "False", ")", ":", "cur", "=", "self", ".", "db", ".", "cursor", "(", ")", "return", "namedb_get_num_names", "(", "cur", ",", "self", ".", "lastblock", ",", "include_expired", "=", "include_...
Get the number of names that exist.
[ "Get", "the", "number", "of", "names", "that", "exist", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L1040-L1045
244,423
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.get_all_names
def get_all_names( self, offset=None, count=None, include_expired=False ): """ Get the set of all registered names, with optional pagination Returns the list of names. """ if offset is not None and offset < 0: offset = None if count is not None and count < 0: count = None cur = self.db.cursor() names = namedb_get_all_names( cur, self.lastblock, offset=offset, count=count, include_expired=include_expired ) return names
python
def get_all_names( self, offset=None, count=None, include_expired=False ): if offset is not None and offset < 0: offset = None if count is not None and count < 0: count = None cur = self.db.cursor() names = namedb_get_all_names( cur, self.lastblock, offset=offset, count=count, include_expired=include_expired ) return names
[ "def", "get_all_names", "(", "self", ",", "offset", "=", "None", ",", "count", "=", "None", ",", "include_expired", "=", "False", ")", ":", "if", "offset", "is", "not", "None", "and", "offset", "<", "0", ":", "offset", "=", "None", "if", "count", "is...
Get the set of all registered names, with optional pagination Returns the list of names.
[ "Get", "the", "set", "of", "all", "registered", "names", "with", "optional", "pagination", "Returns", "the", "list", "of", "names", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L1048-L1061
244,424
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.get_num_names_in_namespace
def get_num_names_in_namespace( self, namespace_id ): """ Get the number of names in a namespace """ cur = self.db.cursor() return namedb_get_num_names_in_namespace( cur, namespace_id, self.lastblock )
python
def get_num_names_in_namespace( self, namespace_id ): cur = self.db.cursor() return namedb_get_num_names_in_namespace( cur, namespace_id, self.lastblock )
[ "def", "get_num_names_in_namespace", "(", "self", ",", "namespace_id", ")", ":", "cur", "=", "self", ".", "db", ".", "cursor", "(", ")", "return", "namedb_get_num_names_in_namespace", "(", "cur", ",", "namespace_id", ",", "self", ".", "lastblock", ")" ]
Get the number of names in a namespace
[ "Get", "the", "number", "of", "names", "in", "a", "namespace" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L1064-L1069
244,425
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.get_names_in_namespace
def get_names_in_namespace( self, namespace_id, offset=None, count=None ): """ Get the set of all registered names in a particular namespace. Returns the list of names. """ if offset is not None and offset < 0: offset = None if count is not None and count < 0: count = None cur = self.db.cursor() names = namedb_get_names_in_namespace( cur, namespace_id, self.lastblock, offset=offset, count=count ) return names
python
def get_names_in_namespace( self, namespace_id, offset=None, count=None ): if offset is not None and offset < 0: offset = None if count is not None and count < 0: count = None cur = self.db.cursor() names = namedb_get_names_in_namespace( cur, namespace_id, self.lastblock, offset=offset, count=count ) return names
[ "def", "get_names_in_namespace", "(", "self", ",", "namespace_id", ",", "offset", "=", "None", ",", "count", "=", "None", ")", ":", "if", "offset", "is", "not", "None", "and", "offset", "<", "0", ":", "offset", "=", "None", "if", "count", "is", "not", ...
Get the set of all registered names in a particular namespace. Returns the list of names.
[ "Get", "the", "set", "of", "all", "registered", "names", "in", "a", "particular", "namespace", ".", "Returns", "the", "list", "of", "names", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L1072-L1085
244,426
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.get_all_namespace_ids
def get_all_namespace_ids( self ): """ Get the set of all existing, READY namespace IDs. """ cur = self.db.cursor() namespace_ids = namedb_get_all_namespace_ids( cur ) return namespace_ids
python
def get_all_namespace_ids( self ): cur = self.db.cursor() namespace_ids = namedb_get_all_namespace_ids( cur ) return namespace_ids
[ "def", "get_all_namespace_ids", "(", "self", ")", ":", "cur", "=", "self", ".", "db", ".", "cursor", "(", ")", "namespace_ids", "=", "namedb_get_all_namespace_ids", "(", "cur", ")", "return", "namespace_ids" ]
Get the set of all existing, READY namespace IDs.
[ "Get", "the", "set", "of", "all", "existing", "READY", "namespace", "IDs", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L1088-L1094
244,427
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.get_all_revealed_namespace_ids
def get_all_revealed_namespace_ids( self ): """ Get all revealed namespace IDs that have not expired. """ cur = self.db.cursor() namespace_ids = namedb_get_all_revealed_namespace_ids( cur, self.lastblock ) return namespace_ids
python
def get_all_revealed_namespace_ids( self ): cur = self.db.cursor() namespace_ids = namedb_get_all_revealed_namespace_ids( cur, self.lastblock ) return namespace_ids
[ "def", "get_all_revealed_namespace_ids", "(", "self", ")", ":", "cur", "=", "self", ".", "db", ".", "cursor", "(", ")", "namespace_ids", "=", "namedb_get_all_revealed_namespace_ids", "(", "cur", ",", "self", ".", "lastblock", ")", "return", "namespace_ids" ]
Get all revealed namespace IDs that have not expired.
[ "Get", "all", "revealed", "namespace", "IDs", "that", "have", "not", "expired", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L1097-L1103
244,428
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.get_all_preordered_namespace_hashes
def get_all_preordered_namespace_hashes( self ): """ Get all oustanding namespace preorder hashes that have not expired. Used for testing """ cur = self.db.cursor() namespace_hashes = namedb_get_all_preordered_namespace_hashes( cur, self.lastblock ) return namespace_hashes
python
def get_all_preordered_namespace_hashes( self ): cur = self.db.cursor() namespace_hashes = namedb_get_all_preordered_namespace_hashes( cur, self.lastblock ) return namespace_hashes
[ "def", "get_all_preordered_namespace_hashes", "(", "self", ")", ":", "cur", "=", "self", ".", "db", ".", "cursor", "(", ")", "namespace_hashes", "=", "namedb_get_all_preordered_namespace_hashes", "(", "cur", ",", "self", ".", "lastblock", ")", "return", "namespace...
Get all oustanding namespace preorder hashes that have not expired. Used for testing
[ "Get", "all", "oustanding", "namespace", "preorder", "hashes", "that", "have", "not", "expired", ".", "Used", "for", "testing" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L1106-L1113
244,429
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.get_all_importing_namespace_hashes
def get_all_importing_namespace_hashes( self ): """ Get the set of all preordered and revealed namespace hashes that have not expired. """ cur = self.db.cursor() namespace_hashes = namedb_get_all_importing_namespace_hashes( cur, self.lastblock ) return namespace_hashes
python
def get_all_importing_namespace_hashes( self ): cur = self.db.cursor() namespace_hashes = namedb_get_all_importing_namespace_hashes( cur, self.lastblock ) return namespace_hashes
[ "def", "get_all_importing_namespace_hashes", "(", "self", ")", ":", "cur", "=", "self", ".", "db", ".", "cursor", "(", ")", "namespace_hashes", "=", "namedb_get_all_importing_namespace_hashes", "(", "cur", ",", "self", ".", "lastblock", ")", "return", "namespace_h...
Get the set of all preordered and revealed namespace hashes that have not expired.
[ "Get", "the", "set", "of", "all", "preordered", "and", "revealed", "namespace", "hashes", "that", "have", "not", "expired", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L1116-L1122
244,430
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.get_name_preorder
def get_name_preorder( self, name, sender_script_pubkey, register_addr, include_failed=False ): """ Get the current preorder for a name, given the name, the sender's script pubkey, and the registration address used to calculate the preorder hash. Return the preorder record on success. Return None if not found, or the preorder is already registered and not expired (even if revoked). NOTE: possibly returns an expired preorder (by design, so as to prevent someone from re-sending the same preorder with the same preorder hash). """ # name registered and not expired? name_rec = self.get_name( name ) if name_rec is not None and not include_failed: return None # what namespace are we in? namespace_id = get_namespace_from_name(name) namespace = self.get_namespace(namespace_id) if namespace is None: return None # isn't currently registered, or we don't care preorder_hash = hash_name(name, sender_script_pubkey, register_addr=register_addr) preorder = namedb_get_name_preorder( self.db, preorder_hash, self.lastblock ) if preorder is None: # doesn't exist or expired return None # preorder must be younger than the namespace lifetime # (otherwise we get into weird conditions where someone can preorder # a name before someone else, and register it after it expires) namespace_lifetime_multiplier = get_epoch_namespace_lifetime_multiplier( self.lastblock, namespace_id ) if preorder['block_number'] + (namespace['lifetime'] * namespace_lifetime_multiplier) <= self.lastblock: log.debug("Preorder is too old (accepted at {}, namespace lifetime is {}, current block is {})".format(preorder['block_number'], namespace['lifetime'] * namespace_lifetime_multiplier, self.lastblock)) return None return preorder
python
def get_name_preorder( self, name, sender_script_pubkey, register_addr, include_failed=False ): # name registered and not expired? name_rec = self.get_name( name ) if name_rec is not None and not include_failed: return None # what namespace are we in? namespace_id = get_namespace_from_name(name) namespace = self.get_namespace(namespace_id) if namespace is None: return None # isn't currently registered, or we don't care preorder_hash = hash_name(name, sender_script_pubkey, register_addr=register_addr) preorder = namedb_get_name_preorder( self.db, preorder_hash, self.lastblock ) if preorder is None: # doesn't exist or expired return None # preorder must be younger than the namespace lifetime # (otherwise we get into weird conditions where someone can preorder # a name before someone else, and register it after it expires) namespace_lifetime_multiplier = get_epoch_namespace_lifetime_multiplier( self.lastblock, namespace_id ) if preorder['block_number'] + (namespace['lifetime'] * namespace_lifetime_multiplier) <= self.lastblock: log.debug("Preorder is too old (accepted at {}, namespace lifetime is {}, current block is {})".format(preorder['block_number'], namespace['lifetime'] * namespace_lifetime_multiplier, self.lastblock)) return None return preorder
[ "def", "get_name_preorder", "(", "self", ",", "name", ",", "sender_script_pubkey", ",", "register_addr", ",", "include_failed", "=", "False", ")", ":", "# name registered and not expired?", "name_rec", "=", "self", ".", "get_name", "(", "name", ")", "if", "name_re...
Get the current preorder for a name, given the name, the sender's script pubkey, and the registration address used to calculate the preorder hash. Return the preorder record on success. Return None if not found, or the preorder is already registered and not expired (even if revoked). NOTE: possibly returns an expired preorder (by design, so as to prevent someone from re-sending the same preorder with the same preorder hash).
[ "Get", "the", "current", "preorder", "for", "a", "name", "given", "the", "name", "the", "sender", "s", "script", "pubkey", "and", "the", "registration", "address", "used", "to", "calculate", "the", "preorder", "hash", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L1166-L1203
244,431
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.get_names_with_value_hash
def get_names_with_value_hash( self, value_hash ): """ Get the list of names with the given value hash, at the current block height. This excludes revoked names and expired names. Return None if there are no such names """ cur = self.db.cursor() names = namedb_get_names_with_value_hash( cur, value_hash, self.lastblock ) return names
python
def get_names_with_value_hash( self, value_hash ): cur = self.db.cursor() names = namedb_get_names_with_value_hash( cur, value_hash, self.lastblock ) return names
[ "def", "get_names_with_value_hash", "(", "self", ",", "value_hash", ")", ":", "cur", "=", "self", ".", "db", ".", "cursor", "(", ")", "names", "=", "namedb_get_names_with_value_hash", "(", "cur", ",", "value_hash", ",", "self", ".", "lastblock", ")", "return...
Get the list of names with the given value hash, at the current block height. This excludes revoked names and expired names. Return None if there are no such names
[ "Get", "the", "list", "of", "names", "with", "the", "given", "value", "hash", "at", "the", "current", "block", "height", ".", "This", "excludes", "revoked", "names", "and", "expired", "names", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L1235-L1244
244,432
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.get_atlas_zonefile_info_at
def get_atlas_zonefile_info_at( self, block_id ): """ Get the blockchain-ordered sequence of names, value hashes, and txids. added at the given block height. The order will be in tx-order. Return [{'name': name, 'value_hash': value_hash, 'txid': txid}] """ nameops = self.get_all_blockstack_ops_at( block_id ) ret = [] for nameop in nameops: if nameop.has_key('op') and op_get_opcode_name(nameop['op']) in ['NAME_UPDATE', 'NAME_IMPORT', 'NAME_REGISTRATION', 'NAME_RENEWAL']: assert nameop.has_key('value_hash') assert nameop.has_key('name') assert nameop.has_key('txid') if nameop['value_hash'] is not None: ret.append( {'name': nameop['name'], 'value_hash': nameop['value_hash'], 'txid': nameop['txid']} ) return ret
python
def get_atlas_zonefile_info_at( self, block_id ): nameops = self.get_all_blockstack_ops_at( block_id ) ret = [] for nameop in nameops: if nameop.has_key('op') and op_get_opcode_name(nameop['op']) in ['NAME_UPDATE', 'NAME_IMPORT', 'NAME_REGISTRATION', 'NAME_RENEWAL']: assert nameop.has_key('value_hash') assert nameop.has_key('name') assert nameop.has_key('txid') if nameop['value_hash'] is not None: ret.append( {'name': nameop['name'], 'value_hash': nameop['value_hash'], 'txid': nameop['txid']} ) return ret
[ "def", "get_atlas_zonefile_info_at", "(", "self", ",", "block_id", ")", ":", "nameops", "=", "self", ".", "get_all_blockstack_ops_at", "(", "block_id", ")", "ret", "=", "[", "]", "for", "nameop", "in", "nameops", ":", "if", "nameop", ".", "has_key", "(", "...
Get the blockchain-ordered sequence of names, value hashes, and txids. added at the given block height. The order will be in tx-order. Return [{'name': name, 'value_hash': value_hash, 'txid': txid}]
[ "Get", "the", "blockchain", "-", "ordered", "sequence", "of", "names", "value", "hashes", "and", "txids", ".", "added", "at", "the", "given", "block", "height", ".", "The", "order", "will", "be", "in", "tx", "-", "order", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L1247-L1267
244,433
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.get_namespace_reveal
def get_namespace_reveal( self, namespace_id, include_history=True ): """ Given the name of a namespace, get it if it is currently being revealed. Return the reveal record on success. Return None if it is not being revealed, or is expired. """ cur = self.db.cursor() namespace_reveal = namedb_get_namespace_reveal( cur, namespace_id, self.lastblock, include_history=include_history ) return namespace_reveal
python
def get_namespace_reveal( self, namespace_id, include_history=True ): cur = self.db.cursor() namespace_reveal = namedb_get_namespace_reveal( cur, namespace_id, self.lastblock, include_history=include_history ) return namespace_reveal
[ "def", "get_namespace_reveal", "(", "self", ",", "namespace_id", ",", "include_history", "=", "True", ")", ":", "cur", "=", "self", ".", "db", ".", "cursor", "(", ")", "namespace_reveal", "=", "namedb_get_namespace_reveal", "(", "cur", ",", "namespace_id", ","...
Given the name of a namespace, get it if it is currently being revealed. Return the reveal record on success. Return None if it is not being revealed, or is expired.
[ "Given", "the", "name", "of", "a", "namespace", "get", "it", "if", "it", "is", "currently", "being", "revealed", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L1306-L1316
244,434
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.is_name_registered
def is_name_registered( self, name ): """ Given the fully-qualified name, is it registered, not revoked, and not expired at the current block? """ name_rec = self.get_name( name ) # won't return the name if expired if name_rec is None: return False if name_rec['revoked']: return False return True
python
def is_name_registered( self, name ): name_rec = self.get_name( name ) # won't return the name if expired if name_rec is None: return False if name_rec['revoked']: return False return True
[ "def", "is_name_registered", "(", "self", ",", "name", ")", ":", "name_rec", "=", "self", ".", "get_name", "(", "name", ")", "# won't return the name if expired", "if", "name_rec", "is", "None", ":", "return", "False", "if", "name_rec", "[", "'revoked'", "]", ...
Given the fully-qualified name, is it registered, not revoked, and not expired at the current block?
[ "Given", "the", "fully", "-", "qualified", "name", "is", "it", "registered", "not", "revoked", "and", "not", "expired", "at", "the", "current", "block?" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L1392-L1404
244,435
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.is_namespace_ready
def is_namespace_ready( self, namespace_id ): """ Given a namespace ID, determine if the namespace is ready at the current block. """ namespace = self.get_namespace( namespace_id ) if namespace is not None: return True else: return False
python
def is_namespace_ready( self, namespace_id ): namespace = self.get_namespace( namespace_id ) if namespace is not None: return True else: return False
[ "def", "is_namespace_ready", "(", "self", ",", "namespace_id", ")", ":", "namespace", "=", "self", ".", "get_namespace", "(", "namespace_id", ")", "if", "namespace", "is", "not", "None", ":", "return", "True", "else", ":", "return", "False" ]
Given a namespace ID, determine if the namespace is ready at the current block.
[ "Given", "a", "namespace", "ID", "determine", "if", "the", "namespace", "is", "ready", "at", "the", "current", "block", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L1407-L1416
244,436
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.is_namespace_preordered
def is_namespace_preordered( self, namespace_id_hash ): """ Given a namespace preorder hash, determine if it is preordered at the current block. """ namespace_preorder = self.get_namespace_preorder(namespace_id_hash) if namespace_preorder is None: return False else: return True
python
def is_namespace_preordered( self, namespace_id_hash ): namespace_preorder = self.get_namespace_preorder(namespace_id_hash) if namespace_preorder is None: return False else: return True
[ "def", "is_namespace_preordered", "(", "self", ",", "namespace_id_hash", ")", ":", "namespace_preorder", "=", "self", ".", "get_namespace_preorder", "(", "namespace_id_hash", ")", "if", "namespace_preorder", "is", "None", ":", "return", "False", "else", ":", "return...
Given a namespace preorder hash, determine if it is preordered at the current block.
[ "Given", "a", "namespace", "preorder", "hash", "determine", "if", "it", "is", "preordered", "at", "the", "current", "block", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L1419-L1428
244,437
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.is_namespace_revealed
def is_namespace_revealed( self, namespace_id ): """ Given the name of a namespace, has it been revealed but not made ready at the current block? """ namespace_reveal = self.get_namespace_reveal( namespace_id ) if namespace_reveal is not None: return True else: return False
python
def is_namespace_revealed( self, namespace_id ): namespace_reveal = self.get_namespace_reveal( namespace_id ) if namespace_reveal is not None: return True else: return False
[ "def", "is_namespace_revealed", "(", "self", ",", "namespace_id", ")", ":", "namespace_reveal", "=", "self", ".", "get_namespace_reveal", "(", "namespace_id", ")", "if", "namespace_reveal", "is", "not", "None", ":", "return", "True", "else", ":", "return", "Fals...
Given the name of a namespace, has it been revealed but not made ready at the current block?
[ "Given", "the", "name", "of", "a", "namespace", "has", "it", "been", "revealed", "but", "not", "made", "ready", "at", "the", "current", "block?" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L1431-L1440
244,438
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.is_name_owner
def is_name_owner( self, name, sender_script_pubkey ): """ Given the fully-qualified name and a sender's script pubkey, determine if the sender owns the name. The name must exist and not be revoked or expired at the current block. """ if not self.is_name_registered( name ): # no one owns it return False owner = self.get_name_owner( name ) if owner != sender_script_pubkey: return False else: return True
python
def is_name_owner( self, name, sender_script_pubkey ): if not self.is_name_registered( name ): # no one owns it return False owner = self.get_name_owner( name ) if owner != sender_script_pubkey: return False else: return True
[ "def", "is_name_owner", "(", "self", ",", "name", ",", "sender_script_pubkey", ")", ":", "if", "not", "self", ".", "is_name_registered", "(", "name", ")", ":", "# no one owns it ", "return", "False", "owner", "=", "self", ".", "get_name_owner", "(", "name", ...
Given the fully-qualified name and a sender's script pubkey, determine if the sender owns the name. The name must exist and not be revoked or expired at the current block.
[ "Given", "the", "fully", "-", "qualified", "name", "and", "a", "sender", "s", "script", "pubkey", "determine", "if", "the", "sender", "owns", "the", "name", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L1443-L1459
244,439
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.is_new_preorder
def is_new_preorder( self, preorder_hash, lastblock=None ): """ Given a preorder hash of a name, determine whether or not it is unseen before. """ if lastblock is None: lastblock = self.lastblock preorder = namedb_get_name_preorder( self.db, preorder_hash, lastblock ) if preorder is not None: return False else: return True
python
def is_new_preorder( self, preorder_hash, lastblock=None ): if lastblock is None: lastblock = self.lastblock preorder = namedb_get_name_preorder( self.db, preorder_hash, lastblock ) if preorder is not None: return False else: return True
[ "def", "is_new_preorder", "(", "self", ",", "preorder_hash", ",", "lastblock", "=", "None", ")", ":", "if", "lastblock", "is", "None", ":", "lastblock", "=", "self", ".", "lastblock", "preorder", "=", "namedb_get_name_preorder", "(", "self", ".", "db", ",", ...
Given a preorder hash of a name, determine whether or not it is unseen before.
[ "Given", "a", "preorder", "hash", "of", "a", "name", "determine", "whether", "or", "not", "it", "is", "unseen", "before", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L1462-L1473
244,440
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.is_new_namespace_preorder
def is_new_namespace_preorder( self, namespace_id_hash, lastblock=None ): """ Given a namespace preorder hash, determine whether or not is is unseen before. """ if lastblock is None: lastblock = self.lastblock preorder = namedb_get_namespace_preorder( self.db, namespace_id_hash, lastblock ) if preorder is not None: return False else: return True
python
def is_new_namespace_preorder( self, namespace_id_hash, lastblock=None ): if lastblock is None: lastblock = self.lastblock preorder = namedb_get_namespace_preorder( self.db, namespace_id_hash, lastblock ) if preorder is not None: return False else: return True
[ "def", "is_new_namespace_preorder", "(", "self", ",", "namespace_id_hash", ",", "lastblock", "=", "None", ")", ":", "if", "lastblock", "is", "None", ":", "lastblock", "=", "self", ".", "lastblock", "preorder", "=", "namedb_get_namespace_preorder", "(", "self", "...
Given a namespace preorder hash, determine whether or not is is unseen before.
[ "Given", "a", "namespace", "preorder", "hash", "determine", "whether", "or", "not", "is", "is", "unseen", "before", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L1476-L1487
244,441
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.is_name_revoked
def is_name_revoked( self, name ): """ Determine if a name is revoked at this block. """ name = self.get_name( name ) if name is None: return False if name['revoked']: return True else: return False
python
def is_name_revoked( self, name ): name = self.get_name( name ) if name is None: return False if name['revoked']: return True else: return False
[ "def", "is_name_revoked", "(", "self", ",", "name", ")", ":", "name", "=", "self", ".", "get_name", "(", "name", ")", "if", "name", "is", "None", ":", "return", "False", "if", "name", "[", "'revoked'", "]", ":", "return", "True", "else", ":", "return...
Determine if a name is revoked at this block.
[ "Determine", "if", "a", "name", "is", "revoked", "at", "this", "block", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L1490-L1501
244,442
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.get_value_hash_txids
def get_value_hash_txids(self, value_hash): """ Get the list of txids by value hash """ cur = self.db.cursor() return namedb_get_value_hash_txids(cur, value_hash)
python
def get_value_hash_txids(self, value_hash): cur = self.db.cursor() return namedb_get_value_hash_txids(cur, value_hash)
[ "def", "get_value_hash_txids", "(", "self", ",", "value_hash", ")", ":", "cur", "=", "self", ".", "db", ".", "cursor", "(", ")", "return", "namedb_get_value_hash_txids", "(", "cur", ",", "value_hash", ")" ]
Get the list of txids by value hash
[ "Get", "the", "list", "of", "txids", "by", "value", "hash" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L1511-L1516
244,443
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.nameop_set_collided
def nameop_set_collided( cls, nameop, history_id_key, history_id ): """ Mark a nameop as collided """ nameop['__collided__'] = True nameop['__collided_history_id_key__'] = history_id_key nameop['__collided_history_id__'] = history_id
python
def nameop_set_collided( cls, nameop, history_id_key, history_id ): nameop['__collided__'] = True nameop['__collided_history_id_key__'] = history_id_key nameop['__collided_history_id__'] = history_id
[ "def", "nameop_set_collided", "(", "cls", ",", "nameop", ",", "history_id_key", ",", "history_id", ")", ":", "nameop", "[", "'__collided__'", "]", "=", "True", "nameop", "[", "'__collided_history_id_key__'", "]", "=", "history_id_key", "nameop", "[", "'__collided_...
Mark a nameop as collided
[ "Mark", "a", "nameop", "as", "collided" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L1530-L1536
244,444
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.nameop_put_collision
def nameop_put_collision( cls, collisions, nameop ): """ Record a nameop as collided with another nameop in this block. """ # these are supposed to have been put here by nameop_set_collided history_id_key = nameop.get('__collided_history_id_key__', None) history_id = nameop.get('__collided_history_id__', None) try: assert cls.nameop_is_collided( nameop ), "Nameop not collided" assert history_id_key is not None, "Nameop missing collision info" assert history_id is not None, "Nameop missing collision info" except Exception, e: log.exception(e) log.error("FATAL: BUG: bad collision info") os.abort() if not collisions.has_key(history_id_key): collisions[history_id_key] = [history_id] else: collisions[history_id_key].append( history_id )
python
def nameop_put_collision( cls, collisions, nameop ): # these are supposed to have been put here by nameop_set_collided history_id_key = nameop.get('__collided_history_id_key__', None) history_id = nameop.get('__collided_history_id__', None) try: assert cls.nameop_is_collided( nameop ), "Nameop not collided" assert history_id_key is not None, "Nameop missing collision info" assert history_id is not None, "Nameop missing collision info" except Exception, e: log.exception(e) log.error("FATAL: BUG: bad collision info") os.abort() if not collisions.has_key(history_id_key): collisions[history_id_key] = [history_id] else: collisions[history_id_key].append( history_id )
[ "def", "nameop_put_collision", "(", "cls", ",", "collisions", ",", "nameop", ")", ":", "# these are supposed to have been put here by nameop_set_collided", "history_id_key", "=", "nameop", ".", "get", "(", "'__collided_history_id_key__'", ",", "None", ")", "history_id", "...
Record a nameop as collided with another nameop in this block.
[ "Record", "a", "nameop", "as", "collided", "with", "another", "nameop", "in", "this", "block", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L1548-L1568
244,445
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.extract_consensus_op
def extract_consensus_op(self, opcode, op_data, processed_op_data, current_block_number): """ Using the operation data extracted from parsing the virtualchain operation (@op_data), and the checked, processed operation (@processed_op_data), return a dict that contains (1) all of the consensus fields to snapshot this operation, and (2) all of the data fields that we need to store for the name record (i.e. quirk fields) """ ret = {} consensus_fields = op_get_consensus_fields(opcode) quirk_fields = op_get_quirk_fields(opcode) for field in consensus_fields + quirk_fields: try: # assert field in processed_op_data or field in op_data, 'Missing consensus field "{}"'.format(field) assert field in processed_op_data, 'Missing consensus field "{}"'.format(field) except Exception as e: # should NEVER happen log.exception(e) log.error("FATAL: BUG: missing consensus field {}".format(field)) log.error("op_data:\n{}".format(json.dumps(op_data, indent=4, sort_keys=True))) log.error("processed_op_data:\n{}".format(json.dumps(op_data, indent=4, sort_keys=True))) os.abort() ret[field] = processed_op_data[field] return ret
python
def extract_consensus_op(self, opcode, op_data, processed_op_data, current_block_number): ret = {} consensus_fields = op_get_consensus_fields(opcode) quirk_fields = op_get_quirk_fields(opcode) for field in consensus_fields + quirk_fields: try: # assert field in processed_op_data or field in op_data, 'Missing consensus field "{}"'.format(field) assert field in processed_op_data, 'Missing consensus field "{}"'.format(field) except Exception as e: # should NEVER happen log.exception(e) log.error("FATAL: BUG: missing consensus field {}".format(field)) log.error("op_data:\n{}".format(json.dumps(op_data, indent=4, sort_keys=True))) log.error("processed_op_data:\n{}".format(json.dumps(op_data, indent=4, sort_keys=True))) os.abort() ret[field] = processed_op_data[field] return ret
[ "def", "extract_consensus_op", "(", "self", ",", "opcode", ",", "op_data", ",", "processed_op_data", ",", "current_block_number", ")", ":", "ret", "=", "{", "}", "consensus_fields", "=", "op_get_consensus_fields", "(", "opcode", ")", "quirk_fields", "=", "op_get_q...
Using the operation data extracted from parsing the virtualchain operation (@op_data), and the checked, processed operation (@processed_op_data), return a dict that contains (1) all of the consensus fields to snapshot this operation, and (2) all of the data fields that we need to store for the name record (i.e. quirk fields)
[ "Using", "the", "operation", "data", "extracted", "from", "parsing", "the", "virtualchain", "operation", "(" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L1571-L1597
244,446
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.commit_operation
def commit_operation( self, input_op_data, accepted_nameop, current_block_number ): """ Commit an operation, thereby carrying out a state transition. Returns a dict with the new db record fields """ # have to have read-write disposition if self.disposition != DISPOSITION_RW: log.error("FATAL: borrowing violation: not a read-write connection") traceback.print_stack() os.abort() cur = self.db.cursor() canonical_op = None op_type_str = None # for debugging opcode = accepted_nameop.get('opcode', None) try: assert opcode is not None, "Undefined op '%s'" % accepted_nameop['op'] except Exception, e: log.exception(e) log.error("FATAL: unrecognized op '%s'" % accepted_nameop['op'] ) os.abort() if opcode in OPCODE_PREORDER_OPS: # preorder canonical_op = self.commit_state_preorder( accepted_nameop, current_block_number ) op_type_str = "state_preorder" elif opcode in OPCODE_CREATION_OPS: # creation canonical_op = self.commit_state_create( accepted_nameop, current_block_number ) op_type_str = "state_create" elif opcode in OPCODE_TRANSITION_OPS: # transition canonical_op = self.commit_state_transition( accepted_nameop, current_block_number ) op_type_str = "state_transition" elif opcode in OPCODE_TOKEN_OPS: # token operation canonical_op = self.commit_token_operation(accepted_nameop, current_block_number) op_type_str = "token_operation" else: raise Exception("Unknown operation {}".format(opcode)) if canonical_op is None: log.error("FATAL: no canonical op generated (for {})".format(op_type_str)) os.abort() log.debug("Extract consensus fields for {} in {}, as part of a {}".format(opcode, current_block_number, op_type_str)) consensus_op = self.extract_consensus_op(opcode, input_op_data, canonical_op, current_block_number) return consensus_op
python
def commit_operation( self, input_op_data, accepted_nameop, current_block_number ): # have to have read-write disposition if self.disposition != DISPOSITION_RW: log.error("FATAL: borrowing violation: not a read-write connection") traceback.print_stack() os.abort() cur = self.db.cursor() canonical_op = None op_type_str = None # for debugging opcode = accepted_nameop.get('opcode', None) try: assert opcode is not None, "Undefined op '%s'" % accepted_nameop['op'] except Exception, e: log.exception(e) log.error("FATAL: unrecognized op '%s'" % accepted_nameop['op'] ) os.abort() if opcode in OPCODE_PREORDER_OPS: # preorder canonical_op = self.commit_state_preorder( accepted_nameop, current_block_number ) op_type_str = "state_preorder" elif opcode in OPCODE_CREATION_OPS: # creation canonical_op = self.commit_state_create( accepted_nameop, current_block_number ) op_type_str = "state_create" elif opcode in OPCODE_TRANSITION_OPS: # transition canonical_op = self.commit_state_transition( accepted_nameop, current_block_number ) op_type_str = "state_transition" elif opcode in OPCODE_TOKEN_OPS: # token operation canonical_op = self.commit_token_operation(accepted_nameop, current_block_number) op_type_str = "token_operation" else: raise Exception("Unknown operation {}".format(opcode)) if canonical_op is None: log.error("FATAL: no canonical op generated (for {})".format(op_type_str)) os.abort() log.debug("Extract consensus fields for {} in {}, as part of a {}".format(opcode, current_block_number, op_type_str)) consensus_op = self.extract_consensus_op(opcode, input_op_data, canonical_op, current_block_number) return consensus_op
[ "def", "commit_operation", "(", "self", ",", "input_op_data", ",", "accepted_nameop", ",", "current_block_number", ")", ":", "# have to have read-write disposition ", "if", "self", ".", "disposition", "!=", "DISPOSITION_RW", ":", "log", ".", "error", "(", "\"FATAL: bo...
Commit an operation, thereby carrying out a state transition. Returns a dict with the new db record fields
[ "Commit", "an", "operation", "thereby", "carrying", "out", "a", "state", "transition", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L1600-L1654
244,447
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.commit_token_operation
def commit_token_operation(self, token_op, current_block_number): """ Commit a token operation that debits one account and credits another Returns the new canonicalized record (with all compatibility quirks preserved) DO NOT CALL THIS DIRECTLY """ # have to have read-write disposition if self.disposition != DISPOSITION_RW: log.error("FATAL: borrowing violation: not a read-write connection") traceback.print_stack() os.abort() cur = self.db.cursor() opcode = token_op.get('opcode', None) clean_token_op = self.sanitize_op(token_op) try: assert token_operation_is_valid(token_op), 'Invalid token operation' assert opcode is not None, 'No opcode given' assert 'txid' in token_op, 'No txid' assert 'vtxindex' in token_op, 'No vtxindex' except Exception as e: log.exception(e) log.error('FATAL: failed to commit token operation') self.db.rollback() os.abort() table = token_operation_get_table(token_op) account_payment_info = token_operation_get_account_payment_info(token_op) account_credit_info = token_operation_get_account_credit_info(token_op) # fields must be set try: for key in account_payment_info: assert account_payment_info[key] is not None, 'BUG: payment info key {} is None'.format(key) for key in account_credit_info: assert account_credit_info[key] is not None, 'BUG: credit info key {} is not None'.format(key) # NOTE: do not check token amount and type, since in the future we want to support converting # between tokens except Exception as e: log.exception(e) log.error("FATAL: invalid token debit or credit info") os.abort() self.log_accept(current_block_number, token_op['vtxindex'], token_op['op'], token_op) # NOTE: this code is single-threaded, but this code must be atomic self.commit_account_debit(token_op, account_payment_info, current_block_number, token_op['vtxindex'], token_op['txid']) self.commit_account_credit(token_op, account_credit_info, current_block_number, token_op['vtxindex'], token_op['txid']) namedb_history_save(cur, opcode, token_op['address'], None, None, current_block_number, token_op['vtxindex'], token_op['txid'], clean_token_op) return clean_token_op
python
def commit_token_operation(self, token_op, current_block_number): # have to have read-write disposition if self.disposition != DISPOSITION_RW: log.error("FATAL: borrowing violation: not a read-write connection") traceback.print_stack() os.abort() cur = self.db.cursor() opcode = token_op.get('opcode', None) clean_token_op = self.sanitize_op(token_op) try: assert token_operation_is_valid(token_op), 'Invalid token operation' assert opcode is not None, 'No opcode given' assert 'txid' in token_op, 'No txid' assert 'vtxindex' in token_op, 'No vtxindex' except Exception as e: log.exception(e) log.error('FATAL: failed to commit token operation') self.db.rollback() os.abort() table = token_operation_get_table(token_op) account_payment_info = token_operation_get_account_payment_info(token_op) account_credit_info = token_operation_get_account_credit_info(token_op) # fields must be set try: for key in account_payment_info: assert account_payment_info[key] is not None, 'BUG: payment info key {} is None'.format(key) for key in account_credit_info: assert account_credit_info[key] is not None, 'BUG: credit info key {} is not None'.format(key) # NOTE: do not check token amount and type, since in the future we want to support converting # between tokens except Exception as e: log.exception(e) log.error("FATAL: invalid token debit or credit info") os.abort() self.log_accept(current_block_number, token_op['vtxindex'], token_op['op'], token_op) # NOTE: this code is single-threaded, but this code must be atomic self.commit_account_debit(token_op, account_payment_info, current_block_number, token_op['vtxindex'], token_op['txid']) self.commit_account_credit(token_op, account_credit_info, current_block_number, token_op['vtxindex'], token_op['txid']) namedb_history_save(cur, opcode, token_op['address'], None, None, current_block_number, token_op['vtxindex'], token_op['txid'], clean_token_op) return clean_token_op
[ "def", "commit_token_operation", "(", "self", ",", "token_op", ",", "current_block_number", ")", ":", "# have to have read-write disposition ", "if", "self", ".", "disposition", "!=", "DISPOSITION_RW", ":", "log", ".", "error", "(", "\"FATAL: borrowing violation: not a re...
Commit a token operation that debits one account and credits another Returns the new canonicalized record (with all compatibility quirks preserved) DO NOT CALL THIS DIRECTLY
[ "Commit", "a", "token", "operation", "that", "debits", "one", "account", "and", "credits", "another" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L1935-L1990
244,448
blockstack/blockstack-core
blockstack/lib/nameset/namedb.py
BlockstackDB.commit_account_vesting
def commit_account_vesting(self, block_height): """ vest any tokens at this block height """ # save all state log.debug("Commit all database state before vesting") self.db.commit() if block_height in self.vesting: traceback.print_stack() log.fatal("Tried to vest tokens twice at {}".format(block_height)) os.abort() # commit all vesting in one transaction cur = self.db.cursor() namedb_query_execute(cur, 'BEGIN', ()) res = namedb_accounts_vest(cur, block_height) namedb_query_execute(cur, 'END', ()) self.vesting[block_height] = True return True
python
def commit_account_vesting(self, block_height): # save all state log.debug("Commit all database state before vesting") self.db.commit() if block_height in self.vesting: traceback.print_stack() log.fatal("Tried to vest tokens twice at {}".format(block_height)) os.abort() # commit all vesting in one transaction cur = self.db.cursor() namedb_query_execute(cur, 'BEGIN', ()) res = namedb_accounts_vest(cur, block_height) namedb_query_execute(cur, 'END', ()) self.vesting[block_height] = True return True
[ "def", "commit_account_vesting", "(", "self", ",", "block_height", ")", ":", "# save all state", "log", ".", "debug", "(", "\"Commit all database state before vesting\"", ")", "self", ".", "db", ".", "commit", "(", ")", "if", "block_height", "in", "self", ".", "...
vest any tokens at this block height
[ "vest", "any", "tokens", "at", "this", "block", "height" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/nameset/namedb.py#L1993-L2013
244,449
blockstack/blockstack-core
blockstack/lib/scripts.py
is_name_valid
def is_name_valid(fqn): """ Is a fully-qualified name acceptable? Return True if so Return False if not >>> is_name_valid('abcd') False >>> is_name_valid('abcd.') False >>> is_name_valid('.abcd') False >>> is_name_valid('Abcd.abcd') False >>> is_name_valid('abcd.abc.d') False >>> is_name_valid('abcd.abc+d') False >>> is_name_valid('a.b.c') False >>> is_name_valid(True) False >>> is_name_valid(123) False >>> is_name_valid(None) False >>> is_name_valid('') False >>> is_name_valid('abcdabcdabcdabcdabcdabcdabcdabcda.bcd') True >>> is_name_valid('abcdabcdabcdabcdabcdabcdabcdabcdab.bcd') False >>> is_name_valid('abcdabcdabcdabcdabcdabcdabcdabcdabc.d') True >>> is_name_valid('a+b.c') False >>> is_name_valid('a_b.c') True """ if not isinstance(fqn, (str,unicode)): return False if fqn.count( "." ) != 1: return False name, namespace_id = fqn.split(".") if len(name) == 0 or len(namespace_id) == 0: return False if not is_b40( name ) or "+" in name or "." in name: return False if not is_namespace_valid( namespace_id ): return False if len(fqn) > LENGTHS['blockchain_id_name']: # too long return False return True
python
def is_name_valid(fqn): if not isinstance(fqn, (str,unicode)): return False if fqn.count( "." ) != 1: return False name, namespace_id = fqn.split(".") if len(name) == 0 or len(namespace_id) == 0: return False if not is_b40( name ) or "+" in name or "." in name: return False if not is_namespace_valid( namespace_id ): return False if len(fqn) > LENGTHS['blockchain_id_name']: # too long return False return True
[ "def", "is_name_valid", "(", "fqn", ")", ":", "if", "not", "isinstance", "(", "fqn", ",", "(", "str", ",", "unicode", ")", ")", ":", "return", "False", "if", "fqn", ".", "count", "(", "\".\"", ")", "!=", "1", ":", "return", "False", "name", ",", ...
Is a fully-qualified name acceptable? Return True if so Return False if not >>> is_name_valid('abcd') False >>> is_name_valid('abcd.') False >>> is_name_valid('.abcd') False >>> is_name_valid('Abcd.abcd') False >>> is_name_valid('abcd.abc.d') False >>> is_name_valid('abcd.abc+d') False >>> is_name_valid('a.b.c') False >>> is_name_valid(True) False >>> is_name_valid(123) False >>> is_name_valid(None) False >>> is_name_valid('') False >>> is_name_valid('abcdabcdabcdabcdabcdabcdabcdabcda.bcd') True >>> is_name_valid('abcdabcdabcdabcdabcdabcdabcdabcdab.bcd') False >>> is_name_valid('abcdabcdabcdabcdabcdabcdabcdabcdabc.d') True >>> is_name_valid('a+b.c') False >>> is_name_valid('a_b.c') True
[ "Is", "a", "fully", "-", "qualified", "name", "acceptable?", "Return", "True", "if", "so", "Return", "False", "if", "not" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/scripts.py#L35-L96
244,450
blockstack/blockstack-core
blockstack/lib/scripts.py
is_namespace_valid
def is_namespace_valid( namespace_id ): """ Is a namespace ID valid? >>> is_namespace_valid('abcd') True >>> is_namespace_valid('+abcd') False >>> is_namespace_valid('abc.def') False >>> is_namespace_valid('.abcd') False >>> is_namespace_valid('abcdabcdabcdabcdabcd') False >>> is_namespace_valid('abcdabcdabcdabcdabc') True """ if not is_b40( namespace_id ) or "+" in namespace_id or namespace_id.count(".") > 0: return False if len(namespace_id) == 0 or len(namespace_id) > LENGTHS['blockchain_id_namespace_id']: return False return True
python
def is_namespace_valid( namespace_id ): if not is_b40( namespace_id ) or "+" in namespace_id or namespace_id.count(".") > 0: return False if len(namespace_id) == 0 or len(namespace_id) > LENGTHS['blockchain_id_namespace_id']: return False return True
[ "def", "is_namespace_valid", "(", "namespace_id", ")", ":", "if", "not", "is_b40", "(", "namespace_id", ")", "or", "\"+\"", "in", "namespace_id", "or", "namespace_id", ".", "count", "(", "\".\"", ")", ">", "0", ":", "return", "False", "if", "len", "(", "...
Is a namespace ID valid? >>> is_namespace_valid('abcd') True >>> is_namespace_valid('+abcd') False >>> is_namespace_valid('abc.def') False >>> is_namespace_valid('.abcd') False >>> is_namespace_valid('abcdabcdabcdabcdabcd') False >>> is_namespace_valid('abcdabcdabcdabcdabc') True
[ "Is", "a", "namespace", "ID", "valid?" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/scripts.py#L99-L122
244,451
blockstack/blockstack-core
blockstack/lib/scripts.py
price_namespace
def price_namespace( namespace_id, block_height, units ): """ Calculate the cost of a namespace. Returns the price on success Returns None if the namespace is invalid or if the units are invalid """ price_table = get_epoch_namespace_prices( block_height, units ) if price_table is None: return None if len(namespace_id) >= len(price_table) or len(namespace_id) == 0: return None return price_table[len(namespace_id)]
python
def price_namespace( namespace_id, block_height, units ): price_table = get_epoch_namespace_prices( block_height, units ) if price_table is None: return None if len(namespace_id) >= len(price_table) or len(namespace_id) == 0: return None return price_table[len(namespace_id)]
[ "def", "price_namespace", "(", "namespace_id", ",", "block_height", ",", "units", ")", ":", "price_table", "=", "get_epoch_namespace_prices", "(", "block_height", ",", "units", ")", "if", "price_table", "is", "None", ":", "return", "None", "if", "len", "(", "n...
Calculate the cost of a namespace. Returns the price on success Returns None if the namespace is invalid or if the units are invalid
[ "Calculate", "the", "cost", "of", "a", "namespace", ".", "Returns", "the", "price", "on", "success", "Returns", "None", "if", "the", "namespace", "is", "invalid", "or", "if", "the", "units", "are", "invalid" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/scripts.py#L311-L324
244,452
blockstack/blockstack-core
blockstack/lib/scripts.py
find_by_opcode
def find_by_opcode( checked_ops, opcode ): """ Given all previously-accepted operations in this block, find the ones that are of a particular opcode. @opcode can be one opcode, or a list of opcodes >>> find_by_opcode([{'op': '+'}, {'op': '>'}], 'NAME_UPDATE') [{'op': '+'}] >>> find_by_opcode([{'op': '+'}, {'op': '>'}], ['NAME_UPDATE', 'NAME_TRANSFER']) [{'op': '+'}, {'op': '>'}] >>> find_by_opcode([{'op': '+'}, {'op': '>'}], ':') [] >>> find_by_opcode([], ':') [] """ if type(opcode) != list: opcode = [opcode] ret = [] for opdata in checked_ops: if op_get_opcode_name(opdata['op']) in opcode: ret.append(opdata) return ret
python
def find_by_opcode( checked_ops, opcode ): if type(opcode) != list: opcode = [opcode] ret = [] for opdata in checked_ops: if op_get_opcode_name(opdata['op']) in opcode: ret.append(opdata) return ret
[ "def", "find_by_opcode", "(", "checked_ops", ",", "opcode", ")", ":", "if", "type", "(", "opcode", ")", "!=", "list", ":", "opcode", "=", "[", "opcode", "]", "ret", "=", "[", "]", "for", "opdata", "in", "checked_ops", ":", "if", "op_get_opcode_name", "...
Given all previously-accepted operations in this block, find the ones that are of a particular opcode. @opcode can be one opcode, or a list of opcodes >>> find_by_opcode([{'op': '+'}, {'op': '>'}], 'NAME_UPDATE') [{'op': '+'}] >>> find_by_opcode([{'op': '+'}, {'op': '>'}], ['NAME_UPDATE', 'NAME_TRANSFER']) [{'op': '+'}, {'op': '>'}] >>> find_by_opcode([{'op': '+'}, {'op': '>'}], ':') [] >>> find_by_opcode([], ':') []
[ "Given", "all", "previously", "-", "accepted", "operations", "in", "this", "block", "find", "the", "ones", "that", "are", "of", "a", "particular", "opcode", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/scripts.py#L327-L352
244,453
blockstack/blockstack-core
blockstack/lib/scripts.py
get_public_key_hex_from_tx
def get_public_key_hex_from_tx( inputs, address ): """ Given a list of inputs and the address of one of the inputs, find the public key. This only works for p2pkh scripts. We only really need this for NAMESPACE_REVEAL, but we included it in other transactions' consensus data for legacy reasons that now have to be supported forever :( """ ret = None for inp in inputs: input_scriptsig = inp['script'] input_script_code = virtualchain.btc_script_deserialize(input_scriptsig) if len(input_script_code) == 2: # signature pubkey pubkey_candidate = input_script_code[1] pubkey = None try: pubkey = virtualchain.BitcoinPublicKey(pubkey_candidate) except Exception as e: traceback.print_exc() log.warn("Invalid public key {}".format(pubkey_candidate)) continue if address != pubkey.address(): continue # success! return pubkey_candidate return None
python
def get_public_key_hex_from_tx( inputs, address ): ret = None for inp in inputs: input_scriptsig = inp['script'] input_script_code = virtualchain.btc_script_deserialize(input_scriptsig) if len(input_script_code) == 2: # signature pubkey pubkey_candidate = input_script_code[1] pubkey = None try: pubkey = virtualchain.BitcoinPublicKey(pubkey_candidate) except Exception as e: traceback.print_exc() log.warn("Invalid public key {}".format(pubkey_candidate)) continue if address != pubkey.address(): continue # success! return pubkey_candidate return None
[ "def", "get_public_key_hex_from_tx", "(", "inputs", ",", "address", ")", ":", "ret", "=", "None", "for", "inp", "in", "inputs", ":", "input_scriptsig", "=", "inp", "[", "'script'", "]", "input_script_code", "=", "virtualchain", ".", "btc_script_deserialize", "("...
Given a list of inputs and the address of one of the inputs, find the public key. This only works for p2pkh scripts. We only really need this for NAMESPACE_REVEAL, but we included it in other transactions' consensus data for legacy reasons that now have to be supported forever :(
[ "Given", "a", "list", "of", "inputs", "and", "the", "address", "of", "one", "of", "the", "inputs", "find", "the", "public", "key", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/scripts.py#L355-L388
244,454
blockstack/blockstack-core
blockstack/lib/scripts.py
check_name
def check_name(name): """ Verify the name is well-formed >>> check_name(123) False >>> check_name('') False >>> check_name('abc') False >>> check_name('abc.def') True >>> check_name('abc.def.ghi') False >>> check_name('abc.d-ef') True >>> check_name('abc.d+ef') False >>> check_name('.abc') False >>> check_name('abc.') False >>> check_name('abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.abcd') False >>> check_name('abcdabcdabcdabcdabcdabcdabcdabcdabc.d') True """ if type(name) not in [str, unicode]: return False if not is_name_valid(name): return False return True
python
def check_name(name): if type(name) not in [str, unicode]: return False if not is_name_valid(name): return False return True
[ "def", "check_name", "(", "name", ")", ":", "if", "type", "(", "name", ")", "not", "in", "[", "str", ",", "unicode", "]", ":", "return", "False", "if", "not", "is_name_valid", "(", "name", ")", ":", "return", "False", "return", "True" ]
Verify the name is well-formed >>> check_name(123) False >>> check_name('') False >>> check_name('abc') False >>> check_name('abc.def') True >>> check_name('abc.def.ghi') False >>> check_name('abc.d-ef') True >>> check_name('abc.d+ef') False >>> check_name('.abc') False >>> check_name('abc.') False >>> check_name('abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.abcd') False >>> check_name('abcdabcdabcdabcdabcdabcdabcdabcdabc.d') True
[ "Verify", "the", "name", "is", "well", "-", "formed" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/scripts.py#L391-L424
244,455
blockstack/blockstack-core
blockstack/lib/scripts.py
check_namespace
def check_namespace(namespace_id): """ Verify that a namespace ID is well-formed >>> check_namespace(123) False >>> check_namespace(None) False >>> check_namespace('') False >>> check_namespace('abcd') True >>> check_namespace('Abcd') False >>> check_namespace('a+bcd') False >>> check_namespace('.abcd') False >>> check_namespace('abcdabcdabcdabcdabcd') False >>> check_namespace('abcdabcdabcdabcdabc') True """ if type(namespace_id) not in [str, unicode]: return False if not is_namespace_valid(namespace_id): return False return True
python
def check_namespace(namespace_id): if type(namespace_id) not in [str, unicode]: return False if not is_namespace_valid(namespace_id): return False return True
[ "def", "check_namespace", "(", "namespace_id", ")", ":", "if", "type", "(", "namespace_id", ")", "not", "in", "[", "str", ",", "unicode", "]", ":", "return", "False", "if", "not", "is_namespace_valid", "(", "namespace_id", ")", ":", "return", "False", "ret...
Verify that a namespace ID is well-formed >>> check_namespace(123) False >>> check_namespace(None) False >>> check_namespace('') False >>> check_namespace('abcd') True >>> check_namespace('Abcd') False >>> check_namespace('a+bcd') False >>> check_namespace('.abcd') False >>> check_namespace('abcdabcdabcdabcdabcd') False >>> check_namespace('abcdabcdabcdabcdabc') True
[ "Verify", "that", "a", "namespace", "ID", "is", "well", "-", "formed" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/scripts.py#L427-L456
244,456
blockstack/blockstack-core
blockstack/lib/scripts.py
check_token_type
def check_token_type(token_type): """ Verify that a token type is well-formed >>> check_token_type('STACKS') True >>> check_token_type('BTC') False >>> check_token_type('abcdabcdabcd') True >>> check_token_type('abcdabcdabcdabcdabcd') False """ return check_string(token_type, min_length=1, max_length=LENGTHS['namespace_id'], pattern='^{}$|{}'.format(TOKEN_TYPE_STACKS, OP_NAMESPACE_PATTERN))
python
def check_token_type(token_type): return check_string(token_type, min_length=1, max_length=LENGTHS['namespace_id'], pattern='^{}$|{}'.format(TOKEN_TYPE_STACKS, OP_NAMESPACE_PATTERN))
[ "def", "check_token_type", "(", "token_type", ")", ":", "return", "check_string", "(", "token_type", ",", "min_length", "=", "1", ",", "max_length", "=", "LENGTHS", "[", "'namespace_id'", "]", ",", "pattern", "=", "'^{}$|{}'", ".", "format", "(", "TOKEN_TYPE_S...
Verify that a token type is well-formed >>> check_token_type('STACKS') True >>> check_token_type('BTC') False >>> check_token_type('abcdabcdabcd') True >>> check_token_type('abcdabcdabcdabcdabcd') False
[ "Verify", "that", "a", "token", "type", "is", "well", "-", "formed" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/scripts.py#L459-L472
244,457
blockstack/blockstack-core
blockstack/lib/scripts.py
check_subdomain
def check_subdomain(fqn): """ Verify that the given fqn is a subdomain >>> check_subdomain('a.b.c') True >>> check_subdomain(123) False >>> check_subdomain('a.b.c.d') False >>> check_subdomain('A.b.c') False >>> check_subdomain('abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.a.b') True >>> check_subdomain('a.abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.a') False >>> check_subdomain('a.b.cdabcdabcdabcdabcdabcdabcdabcdabcd') False >>> check_subdomain('a.b') False """ if type(fqn) not in [str, unicode]: return False if not is_subdomain(fqn): return False return True
python
def check_subdomain(fqn): if type(fqn) not in [str, unicode]: return False if not is_subdomain(fqn): return False return True
[ "def", "check_subdomain", "(", "fqn", ")", ":", "if", "type", "(", "fqn", ")", "not", "in", "[", "str", ",", "unicode", "]", ":", "return", "False", "if", "not", "is_subdomain", "(", "fqn", ")", ":", "return", "False", "return", "True" ]
Verify that the given fqn is a subdomain >>> check_subdomain('a.b.c') True >>> check_subdomain(123) False >>> check_subdomain('a.b.c.d') False >>> check_subdomain('A.b.c') False >>> check_subdomain('abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.a.b') True >>> check_subdomain('a.abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.a') False >>> check_subdomain('a.b.cdabcdabcdabcdabcdabcdabcdabcdabcd') False >>> check_subdomain('a.b') False
[ "Verify", "that", "the", "given", "fqn", "is", "a", "subdomain" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/scripts.py#L475-L502
244,458
blockstack/blockstack-core
blockstack/lib/scripts.py
check_block
def check_block(block_id): """ Verify that a block ID is valid >>> check_block(FIRST_BLOCK_MAINNET) True >>> check_block(FIRST_BLOCK_MAINNET-1) False >>> check_block(-1) False >>> check_block("abc") False >>> check_block(int(1e7) + 1) False >>> check_block(int(1e7) - 1) True """ if type(block_id) not in [int, long]: return False if BLOCKSTACK_TEST: if block_id <= 0: return False else: if block_id < FIRST_BLOCK_MAINNET: return False if block_id > 1e7: # 1 million blocks? not in my lifetime return False return True
python
def check_block(block_id): if type(block_id) not in [int, long]: return False if BLOCKSTACK_TEST: if block_id <= 0: return False else: if block_id < FIRST_BLOCK_MAINNET: return False if block_id > 1e7: # 1 million blocks? not in my lifetime return False return True
[ "def", "check_block", "(", "block_id", ")", ":", "if", "type", "(", "block_id", ")", "not", "in", "[", "int", ",", "long", "]", ":", "return", "False", "if", "BLOCKSTACK_TEST", ":", "if", "block_id", "<=", "0", ":", "return", "False", "else", ":", "i...
Verify that a block ID is valid >>> check_block(FIRST_BLOCK_MAINNET) True >>> check_block(FIRST_BLOCK_MAINNET-1) False >>> check_block(-1) False >>> check_block("abc") False >>> check_block(int(1e7) + 1) False >>> check_block(int(1e7) - 1) True
[ "Verify", "that", "a", "block", "ID", "is", "valid" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/scripts.py#L505-L537
244,459
blockstack/blockstack-core
blockstack/lib/scripts.py
check_offset
def check_offset(offset, max_value=None): """ Verify that an offset is valid >>> check_offset(0) True >>> check_offset(-1) False >>> check_offset(2, max_value=2) True >>> check_offset(0) True >>> check_offset(2, max_value=1) False >>> check_offset('abc') False """ if type(offset) not in [int, long]: return False if offset < 0: return False if max_value and offset > max_value: return False return True
python
def check_offset(offset, max_value=None): if type(offset) not in [int, long]: return False if offset < 0: return False if max_value and offset > max_value: return False return True
[ "def", "check_offset", "(", "offset", ",", "max_value", "=", "None", ")", ":", "if", "type", "(", "offset", ")", "not", "in", "[", "int", ",", "long", "]", ":", "return", "False", "if", "offset", "<", "0", ":", "return", "False", "if", "max_value", ...
Verify that an offset is valid >>> check_offset(0) True >>> check_offset(-1) False >>> check_offset(2, max_value=2) True >>> check_offset(0) True >>> check_offset(2, max_value=1) False >>> check_offset('abc') False
[ "Verify", "that", "an", "offset", "is", "valid" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/scripts.py#L540-L566
244,460
blockstack/blockstack-core
blockstack/lib/scripts.py
check_string
def check_string(value, min_length=None, max_length=None, pattern=None): """ verify that a string has a particular size and conforms to a particular alphabet >>> check_string(1) False >>> check_string(None) False >>> check_string(True) False >>> check_string({}) False >>> check_string([]) False >>> check_string((1,2)) False >>> check_string('abc') True >>> check_string('') True >>> check_string(u'') True >>> check_string('abc', min_length=0, max_length=3) True >>> check_string('abc', min_length=3, max_length=3) True >>> check_string('abc', min_length=4, max_length=5) False >>> check_string('abc', min_length=0, max_length=2) False >>> check_string('abc', pattern='^abc$') True >>> check_string('abc', pattern='^abd$') False """ if type(value) not in [str, unicode]: return False if min_length and len(value) < min_length: return False if max_length and len(value) > max_length: return False if pattern and not re.match(pattern, value): return False return True
python
def check_string(value, min_length=None, max_length=None, pattern=None): if type(value) not in [str, unicode]: return False if min_length and len(value) < min_length: return False if max_length and len(value) > max_length: return False if pattern and not re.match(pattern, value): return False return True
[ "def", "check_string", "(", "value", ",", "min_length", "=", "None", ",", "max_length", "=", "None", ",", "pattern", "=", "None", ")", ":", "if", "type", "(", "value", ")", "not", "in", "[", "str", ",", "unicode", "]", ":", "return", "False", "if", ...
verify that a string has a particular size and conforms to a particular alphabet >>> check_string(1) False >>> check_string(None) False >>> check_string(True) False >>> check_string({}) False >>> check_string([]) False >>> check_string((1,2)) False >>> check_string('abc') True >>> check_string('') True >>> check_string(u'') True >>> check_string('abc', min_length=0, max_length=3) True >>> check_string('abc', min_length=3, max_length=3) True >>> check_string('abc', min_length=4, max_length=5) False >>> check_string('abc', min_length=0, max_length=2) False >>> check_string('abc', pattern='^abc$') True >>> check_string('abc', pattern='^abd$') False
[ "verify", "that", "a", "string", "has", "a", "particular", "size", "and", "conforms", "to", "a", "particular", "alphabet" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/scripts.py#L606-L654
244,461
blockstack/blockstack-core
blockstack/lib/scripts.py
check_address
def check_address(address): """ verify that a string is a base58check address >>> check_address('16EMaNw3pkn3v6f2BgnSSs53zAKH4Q8YJg') True >>> check_address('16EMaNw3pkn3v6f2BgnSSs53zAKH4Q8YJh') False >>> check_address('mkkJsS22dnDJhD8duFkpGnHNr9uz3JEcWu') True >>> check_address('mkkJsS22dnDJhD8duFkpGnHNr9uz3JEcWv') False >>> check_address('MD8WooqTKmwromdMQfSNh8gPTPCSf8KaZj') True >>> check_address('SSXMcDiCZ7yFSQSUj7mWzmDcdwYhq97p2i') True >>> check_address('SSXMcDiCZ7yFSQSUj7mWzmDcdwYhq97p2j') False >>> check_address('16SuThrz') False >>> check_address('1TGKrgtrQjgoPjoa5BnUZ9Qu') False >>> check_address('1LPckRbeTfLjzrfTfnCtP7z2GxFTpZLafXi') True """ if not check_string(address, min_length=26, max_length=35, pattern=OP_ADDRESS_PATTERN): return False try: keylib.b58check_decode(address) return True except: return False
python
def check_address(address): if not check_string(address, min_length=26, max_length=35, pattern=OP_ADDRESS_PATTERN): return False try: keylib.b58check_decode(address) return True except: return False
[ "def", "check_address", "(", "address", ")", ":", "if", "not", "check_string", "(", "address", ",", "min_length", "=", "26", ",", "max_length", "=", "35", ",", "pattern", "=", "OP_ADDRESS_PATTERN", ")", ":", "return", "False", "try", ":", "keylib", ".", ...
verify that a string is a base58check address >>> check_address('16EMaNw3pkn3v6f2BgnSSs53zAKH4Q8YJg') True >>> check_address('16EMaNw3pkn3v6f2BgnSSs53zAKH4Q8YJh') False >>> check_address('mkkJsS22dnDJhD8duFkpGnHNr9uz3JEcWu') True >>> check_address('mkkJsS22dnDJhD8duFkpGnHNr9uz3JEcWv') False >>> check_address('MD8WooqTKmwromdMQfSNh8gPTPCSf8KaZj') True >>> check_address('SSXMcDiCZ7yFSQSUj7mWzmDcdwYhq97p2i') True >>> check_address('SSXMcDiCZ7yFSQSUj7mWzmDcdwYhq97p2j') False >>> check_address('16SuThrz') False >>> check_address('1TGKrgtrQjgoPjoa5BnUZ9Qu') False >>> check_address('1LPckRbeTfLjzrfTfnCtP7z2GxFTpZLafXi') True
[ "verify", "that", "a", "string", "is", "a", "base58check", "address" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/scripts.py#L657-L689
244,462
blockstack/blockstack-core
blockstack/lib/scripts.py
check_account_address
def check_account_address(address): """ verify that a string is a valid account address. Can be a b58-check address, a c32-check address, as well as the string "treasury" or "unallocated" or a string starting with 'not_distributed_' >>> check_account_address('16EMaNw3pkn3v6f2BgnSSs53zAKH4Q8YJg') True >>> check_account_address('16EMaNw3pkn3v6f2BgnSSs53zAKH4Q8YJh') False >>> check_account_address('treasury') True >>> check_account_address('unallocated') True >>> check_account_address('neither') False >>> check_account_address('not_distributed') False >>> check_account_address('not_distributed_') False >>> check_account_address('not_distributed_asdfasdfasdfasdf') True >>> check_account_address('SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7') True >>> check_account_address('SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ8') False """ if address == 'treasury' or address == 'unallocated': return True if address.startswith('not_distributed_') and len(address) > len('not_distributed_'): return True if re.match(OP_C32CHECK_PATTERN, address): try: c32addressDecode(address) return True except: pass return check_address(address)
python
def check_account_address(address): if address == 'treasury' or address == 'unallocated': return True if address.startswith('not_distributed_') and len(address) > len('not_distributed_'): return True if re.match(OP_C32CHECK_PATTERN, address): try: c32addressDecode(address) return True except: pass return check_address(address)
[ "def", "check_account_address", "(", "address", ")", ":", "if", "address", "==", "'treasury'", "or", "address", "==", "'unallocated'", ":", "return", "True", "if", "address", ".", "startswith", "(", "'not_distributed_'", ")", "and", "len", "(", "address", ")",...
verify that a string is a valid account address. Can be a b58-check address, a c32-check address, as well as the string "treasury" or "unallocated" or a string starting with 'not_distributed_' >>> check_account_address('16EMaNw3pkn3v6f2BgnSSs53zAKH4Q8YJg') True >>> check_account_address('16EMaNw3pkn3v6f2BgnSSs53zAKH4Q8YJh') False >>> check_account_address('treasury') True >>> check_account_address('unallocated') True >>> check_account_address('neither') False >>> check_account_address('not_distributed') False >>> check_account_address('not_distributed_') False >>> check_account_address('not_distributed_asdfasdfasdfasdf') True >>> check_account_address('SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7') True >>> check_account_address('SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ8') False
[ "verify", "that", "a", "string", "is", "a", "valid", "account", "address", ".", "Can", "be", "a", "b58", "-", "check", "address", "a", "c32", "-", "check", "address", "as", "well", "as", "the", "string", "treasury", "or", "unallocated", "or", "a", "str...
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/scripts.py#L692-L731
244,463
blockstack/blockstack-core
blockstack/lib/scripts.py
check_tx_output_types
def check_tx_output_types(outputs, block_height): """ Verify that the list of transaction outputs are acceptable """ # for now, we do not allow nonstandard outputs (all outputs must be p2pkh or p2sh outputs) # this excludes bech32 outputs, for example. supported_output_types = get_epoch_btc_script_types(block_height) for out in outputs: out_type = virtualchain.btc_script_classify(out['script']) if out_type not in supported_output_types: log.warning('Unsupported output type {} ({})'.format(out_type, out['script'])) return False return True
python
def check_tx_output_types(outputs, block_height): # for now, we do not allow nonstandard outputs (all outputs must be p2pkh or p2sh outputs) # this excludes bech32 outputs, for example. supported_output_types = get_epoch_btc_script_types(block_height) for out in outputs: out_type = virtualchain.btc_script_classify(out['script']) if out_type not in supported_output_types: log.warning('Unsupported output type {} ({})'.format(out_type, out['script'])) return False return True
[ "def", "check_tx_output_types", "(", "outputs", ",", "block_height", ")", ":", "# for now, we do not allow nonstandard outputs (all outputs must be p2pkh or p2sh outputs)", "# this excludes bech32 outputs, for example.", "supported_output_types", "=", "get_epoch_btc_script_types", "(", "...
Verify that the list of transaction outputs are acceptable
[ "Verify", "that", "the", "list", "of", "transaction", "outputs", "are", "acceptable" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/scripts.py#L734-L747
244,464
blockstack/blockstack-core
blockstack/lib/scripts.py
address_as_b58
def address_as_b58(addr): """ Given a b58check or c32check address, return the b58check encoding """ if is_c32_address(addr): return c32ToB58(addr) else: if check_address(addr): return addr else: raise ValueError('Address {} is not b58 or c32'.format(addr))
python
def address_as_b58(addr): if is_c32_address(addr): return c32ToB58(addr) else: if check_address(addr): return addr else: raise ValueError('Address {} is not b58 or c32'.format(addr))
[ "def", "address_as_b58", "(", "addr", ")", ":", "if", "is_c32_address", "(", "addr", ")", ":", "return", "c32ToB58", "(", "addr", ")", "else", ":", "if", "check_address", "(", "addr", ")", ":", "return", "addr", "else", ":", "raise", "ValueError", "(", ...
Given a b58check or c32check address, return the b58check encoding
[ "Given", "a", "b58check", "or", "c32check", "address", "return", "the", "b58check", "encoding" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/scripts.py#L770-L782
244,465
blockstack/blockstack-core
blockstack/lib/subdomains.py
verify
def verify(address, plaintext, scriptSigb64): """ Verify that a given plaintext is signed by the given scriptSig, given the address """ assert isinstance(address, str) assert isinstance(scriptSigb64, str) scriptSig = base64.b64decode(scriptSigb64) hash_hex = hashlib.sha256(plaintext).hexdigest() vb = keylib.b58check.b58check_version_byte(address) if vb == bitcoin_blockchain.version_byte: return verify_singlesig(address, hash_hex, scriptSig) elif vb == bitcoin_blockchain.multisig_version_byte: return verify_multisig(address, hash_hex, scriptSig) else: log.warning("Unrecognized address version byte {}".format(vb)) raise NotImplementedError("Addresses must be single-sig (version-byte = 0) or multi-sig (version-byte = 5)")
python
def verify(address, plaintext, scriptSigb64): assert isinstance(address, str) assert isinstance(scriptSigb64, str) scriptSig = base64.b64decode(scriptSigb64) hash_hex = hashlib.sha256(plaintext).hexdigest() vb = keylib.b58check.b58check_version_byte(address) if vb == bitcoin_blockchain.version_byte: return verify_singlesig(address, hash_hex, scriptSig) elif vb == bitcoin_blockchain.multisig_version_byte: return verify_multisig(address, hash_hex, scriptSig) else: log.warning("Unrecognized address version byte {}".format(vb)) raise NotImplementedError("Addresses must be single-sig (version-byte = 0) or multi-sig (version-byte = 5)")
[ "def", "verify", "(", "address", ",", "plaintext", ",", "scriptSigb64", ")", ":", "assert", "isinstance", "(", "address", ",", "str", ")", "assert", "isinstance", "(", "scriptSigb64", ",", "str", ")", "scriptSig", "=", "base64", ".", "b64decode", "(", "scr...
Verify that a given plaintext is signed by the given scriptSig, given the address
[ "Verify", "that", "a", "given", "plaintext", "is", "signed", "by", "the", "given", "scriptSig", "given", "the", "address" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L1727-L1745
244,466
blockstack/blockstack-core
blockstack/lib/subdomains.py
verify_singlesig
def verify_singlesig(address, hash_hex, scriptSig): """ Verify that a p2pkh address is signed by the given pay-to-pubkey-hash scriptsig """ try: sighex, pubkey_hex = virtualchain.btc_script_deserialize(scriptSig) except: log.warn("Wrong signature structure for {}".format(address)) return False # verify pubkey_hex corresponds to address if virtualchain.address_reencode(keylib.public_key_to_address(pubkey_hex)) != virtualchain.address_reencode(address): log.warn(("Address {} does not match signature script {}".format(address, scriptSig.encode('hex')))) return False sig64 = base64.b64encode(binascii.unhexlify(sighex)) return virtualchain.ecdsalib.verify_digest(hash_hex, pubkey_hex, sig64)
python
def verify_singlesig(address, hash_hex, scriptSig): try: sighex, pubkey_hex = virtualchain.btc_script_deserialize(scriptSig) except: log.warn("Wrong signature structure for {}".format(address)) return False # verify pubkey_hex corresponds to address if virtualchain.address_reencode(keylib.public_key_to_address(pubkey_hex)) != virtualchain.address_reencode(address): log.warn(("Address {} does not match signature script {}".format(address, scriptSig.encode('hex')))) return False sig64 = base64.b64encode(binascii.unhexlify(sighex)) return virtualchain.ecdsalib.verify_digest(hash_hex, pubkey_hex, sig64)
[ "def", "verify_singlesig", "(", "address", ",", "hash_hex", ",", "scriptSig", ")", ":", "try", ":", "sighex", ",", "pubkey_hex", "=", "virtualchain", ".", "btc_script_deserialize", "(", "scriptSig", ")", "except", ":", "log", ".", "warn", "(", "\"Wrong signatu...
Verify that a p2pkh address is signed by the given pay-to-pubkey-hash scriptsig
[ "Verify", "that", "a", "p2pkh", "address", "is", "signed", "by", "the", "given", "pay", "-", "to", "-", "pubkey", "-", "hash", "scriptsig" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L1748-L1764
244,467
blockstack/blockstack-core
blockstack/lib/subdomains.py
verify_multisig
def verify_multisig(address, hash_hex, scriptSig): """ verify that a p2sh address is signed by the given scriptsig """ script_parts = virtualchain.btc_script_deserialize(scriptSig) if len(script_parts) < 2: log.warn("Verfiying multisig failed, couldn't grab script parts") return False redeem_script = script_parts[-1] script_sigs = script_parts[1:-1] if virtualchain.address_reencode(virtualchain.btc_make_p2sh_address(redeem_script)) != virtualchain.address_reencode(address): log.warn(("Address {} does not match redeem script {}".format(address, redeem_script))) return False m, pubk_hexes = virtualchain.parse_multisig_redeemscript(redeem_script) if len(script_sigs) != m: log.warn("Failed to validate multi-sig, not correct number of signatures: have {}, require {}".format( len(script_sigs), m)) return False cur_pubk = 0 for cur_sig in script_sigs: sig64 = base64.b64encode(binascii.unhexlify(cur_sig)) sig_passed = False while not sig_passed: if cur_pubk >= len(pubk_hexes): log.warn("Failed to validate multi-signature, ran out of public keys to check") return False sig_passed = virtualchain.ecdsalib.verify_digest(hash_hex, pubk_hexes[cur_pubk], sig64) cur_pubk += 1 return True
python
def verify_multisig(address, hash_hex, scriptSig): script_parts = virtualchain.btc_script_deserialize(scriptSig) if len(script_parts) < 2: log.warn("Verfiying multisig failed, couldn't grab script parts") return False redeem_script = script_parts[-1] script_sigs = script_parts[1:-1] if virtualchain.address_reencode(virtualchain.btc_make_p2sh_address(redeem_script)) != virtualchain.address_reencode(address): log.warn(("Address {} does not match redeem script {}".format(address, redeem_script))) return False m, pubk_hexes = virtualchain.parse_multisig_redeemscript(redeem_script) if len(script_sigs) != m: log.warn("Failed to validate multi-sig, not correct number of signatures: have {}, require {}".format( len(script_sigs), m)) return False cur_pubk = 0 for cur_sig in script_sigs: sig64 = base64.b64encode(binascii.unhexlify(cur_sig)) sig_passed = False while not sig_passed: if cur_pubk >= len(pubk_hexes): log.warn("Failed to validate multi-signature, ran out of public keys to check") return False sig_passed = virtualchain.ecdsalib.verify_digest(hash_hex, pubk_hexes[cur_pubk], sig64) cur_pubk += 1 return True
[ "def", "verify_multisig", "(", "address", ",", "hash_hex", ",", "scriptSig", ")", ":", "script_parts", "=", "virtualchain", ".", "btc_script_deserialize", "(", "scriptSig", ")", "if", "len", "(", "script_parts", ")", "<", "2", ":", "log", ".", "warn", "(", ...
verify that a p2sh address is signed by the given scriptsig
[ "verify", "that", "a", "p2sh", "address", "is", "signed", "by", "the", "given", "scriptsig" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L1767-L1800
244,468
blockstack/blockstack-core
blockstack/lib/subdomains.py
is_subdomain_missing_zonefiles_record
def is_subdomain_missing_zonefiles_record(rec): """ Does a given parsed zone file TXT record encode a missing-zonefile vector? Return True if so Return False if not """ if rec['name'] != SUBDOMAIN_TXT_RR_MISSING: return False txt_entry = rec['txt'] if isinstance(txt_entry, list): return False missing = txt_entry.split(',') try: for m in missing: m = int(m) except ValueError: return False return True
python
def is_subdomain_missing_zonefiles_record(rec): if rec['name'] != SUBDOMAIN_TXT_RR_MISSING: return False txt_entry = rec['txt'] if isinstance(txt_entry, list): return False missing = txt_entry.split(',') try: for m in missing: m = int(m) except ValueError: return False return True
[ "def", "is_subdomain_missing_zonefiles_record", "(", "rec", ")", ":", "if", "rec", "[", "'name'", "]", "!=", "SUBDOMAIN_TXT_RR_MISSING", ":", "return", "False", "txt_entry", "=", "rec", "[", "'txt'", "]", "if", "isinstance", "(", "txt_entry", ",", "list", ")",...
Does a given parsed zone file TXT record encode a missing-zonefile vector? Return True if so Return False if not
[ "Does", "a", "given", "parsed", "zone", "file", "TXT", "record", "encode", "a", "missing", "-", "zonefile", "vector?", "Return", "True", "if", "so", "Return", "False", "if", "not" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L1810-L1830
244,469
blockstack/blockstack-core
blockstack/lib/subdomains.py
is_subdomain_record
def is_subdomain_record(rec): """ Does a given parsed zone file TXT record (@rec) encode a subdomain? Return True if so Return False if not """ txt_entry = rec['txt'] if not isinstance(txt_entry, list): return False has_parts_entry = False has_pk_entry = False has_seqn_entry = False for entry in txt_entry: if entry.startswith(SUBDOMAIN_ZF_PARTS + "="): has_parts_entry = True if entry.startswith(SUBDOMAIN_PUBKEY + "="): has_pk_entry = True if entry.startswith(SUBDOMAIN_N + "="): has_seqn_entry = True return (has_parts_entry and has_pk_entry and has_seqn_entry)
python
def is_subdomain_record(rec): txt_entry = rec['txt'] if not isinstance(txt_entry, list): return False has_parts_entry = False has_pk_entry = False has_seqn_entry = False for entry in txt_entry: if entry.startswith(SUBDOMAIN_ZF_PARTS + "="): has_parts_entry = True if entry.startswith(SUBDOMAIN_PUBKEY + "="): has_pk_entry = True if entry.startswith(SUBDOMAIN_N + "="): has_seqn_entry = True return (has_parts_entry and has_pk_entry and has_seqn_entry)
[ "def", "is_subdomain_record", "(", "rec", ")", ":", "txt_entry", "=", "rec", "[", "'txt'", "]", "if", "not", "isinstance", "(", "txt_entry", ",", "list", ")", ":", "return", "False", "has_parts_entry", "=", "False", "has_pk_entry", "=", "False", "has_seqn_en...
Does a given parsed zone file TXT record (@rec) encode a subdomain? Return True if so Return False if not
[ "Does", "a", "given", "parsed", "zone", "file", "TXT", "record", "(" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L1833-L1854
244,470
blockstack/blockstack-core
blockstack/lib/subdomains.py
get_subdomain_info
def get_subdomain_info(fqn, db_path=None, atlasdb_path=None, zonefiles_dir=None, check_pending=False, include_did=False): """ Static method for getting the state of a subdomain, given its fully-qualified name. Return the subdomain record on success. Return None if not found. """ opts = get_blockstack_opts() if not is_subdomains_enabled(opts): log.warn("Subdomain support is disabled") return None if db_path is None: db_path = opts['subdomaindb_path'] if zonefiles_dir is None: zonefiles_dir = opts['zonefiles'] if atlasdb_path is None: atlasdb_path = opts['atlasdb_path'] db = SubdomainDB(db_path, zonefiles_dir) try: subrec = db.get_subdomain_entry(fqn) except SubdomainNotFound: log.warn("No such subdomain: {}".format(fqn)) return None if check_pending: # make sure that all of the zone files between this subdomain's # domain's creation and this subdomain's zone file index are present, # minus the ones that are allowed to be missing. subrec.pending = db.subdomain_check_pending(subrec, atlasdb_path) if include_did: # include the DID subrec.did_info = db.get_subdomain_DID_info(fqn) return subrec
python
def get_subdomain_info(fqn, db_path=None, atlasdb_path=None, zonefiles_dir=None, check_pending=False, include_did=False): opts = get_blockstack_opts() if not is_subdomains_enabled(opts): log.warn("Subdomain support is disabled") return None if db_path is None: db_path = opts['subdomaindb_path'] if zonefiles_dir is None: zonefiles_dir = opts['zonefiles'] if atlasdb_path is None: atlasdb_path = opts['atlasdb_path'] db = SubdomainDB(db_path, zonefiles_dir) try: subrec = db.get_subdomain_entry(fqn) except SubdomainNotFound: log.warn("No such subdomain: {}".format(fqn)) return None if check_pending: # make sure that all of the zone files between this subdomain's # domain's creation and this subdomain's zone file index are present, # minus the ones that are allowed to be missing. subrec.pending = db.subdomain_check_pending(subrec, atlasdb_path) if include_did: # include the DID subrec.did_info = db.get_subdomain_DID_info(fqn) return subrec
[ "def", "get_subdomain_info", "(", "fqn", ",", "db_path", "=", "None", ",", "atlasdb_path", "=", "None", ",", "zonefiles_dir", "=", "None", ",", "check_pending", "=", "False", ",", "include_did", "=", "False", ")", ":", "opts", "=", "get_blockstack_opts", "("...
Static method for getting the state of a subdomain, given its fully-qualified name. Return the subdomain record on success. Return None if not found.
[ "Static", "method", "for", "getting", "the", "state", "of", "a", "subdomain", "given", "its", "fully", "-", "qualified", "name", ".", "Return", "the", "subdomain", "record", "on", "success", ".", "Return", "None", "if", "not", "found", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L1857-L1894
244,471
blockstack/blockstack-core
blockstack/lib/subdomains.py
get_subdomain_resolver
def get_subdomain_resolver(name, db_path=None, zonefiles_dir=None): """ Static method for determining the last-known resolver for a domain name. Returns the resolver URL on success Returns None on error """ opts = get_blockstack_opts() if not is_subdomains_enabled(opts): log.warn("Subdomain support is disabled") return None if db_path is None: db_path = opts['subdomaindb_path'] if zonefiles_dir is None: zonefiles_dir = opts['zonefiles'] db = SubdomainDB(db_path, zonefiles_dir) resolver_url = db.get_domain_resolver(name) return resolver_url
python
def get_subdomain_resolver(name, db_path=None, zonefiles_dir=None): opts = get_blockstack_opts() if not is_subdomains_enabled(opts): log.warn("Subdomain support is disabled") return None if db_path is None: db_path = opts['subdomaindb_path'] if zonefiles_dir is None: zonefiles_dir = opts['zonefiles'] db = SubdomainDB(db_path, zonefiles_dir) resolver_url = db.get_domain_resolver(name) return resolver_url
[ "def", "get_subdomain_resolver", "(", "name", ",", "db_path", "=", "None", ",", "zonefiles_dir", "=", "None", ")", ":", "opts", "=", "get_blockstack_opts", "(", ")", "if", "not", "is_subdomains_enabled", "(", "opts", ")", ":", "log", ".", "warn", "(", "\"S...
Static method for determining the last-known resolver for a domain name. Returns the resolver URL on success Returns None on error
[ "Static", "method", "for", "determining", "the", "last", "-", "known", "resolver", "for", "a", "domain", "name", ".", "Returns", "the", "resolver", "URL", "on", "success", "Returns", "None", "on", "error" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L1897-L1917
244,472
blockstack/blockstack-core
blockstack/lib/subdomains.py
get_subdomains_count
def get_subdomains_count(db_path=None, zonefiles_dir=None): """ Static method for getting count of all subdomains Return number of subdomains on success """ opts = get_blockstack_opts() if not is_subdomains_enabled(opts): log.warn("Subdomain support is disabled") return None if db_path is None: db_path = opts['subdomaindb_path'] if zonefiles_dir is None: zonefiles_dir = opts['zonefiles'] db = SubdomainDB(db_path, zonefiles_dir) return db.get_subdomains_count()
python
def get_subdomains_count(db_path=None, zonefiles_dir=None): opts = get_blockstack_opts() if not is_subdomains_enabled(opts): log.warn("Subdomain support is disabled") return None if db_path is None: db_path = opts['subdomaindb_path'] if zonefiles_dir is None: zonefiles_dir = opts['zonefiles'] db = SubdomainDB(db_path, zonefiles_dir) return db.get_subdomains_count()
[ "def", "get_subdomains_count", "(", "db_path", "=", "None", ",", "zonefiles_dir", "=", "None", ")", ":", "opts", "=", "get_blockstack_opts", "(", ")", "if", "not", "is_subdomains_enabled", "(", "opts", ")", ":", "log", ".", "warn", "(", "\"Subdomain support is...
Static method for getting count of all subdomains Return number of subdomains on success
[ "Static", "method", "for", "getting", "count", "of", "all", "subdomains", "Return", "number", "of", "subdomains", "on", "success" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L1920-L1937
244,473
blockstack/blockstack-core
blockstack/lib/subdomains.py
get_subdomain_DID_info
def get_subdomain_DID_info(fqn, db_path=None, zonefiles_dir=None): """ Get a subdomain's DID info. Return None if not found """ opts = get_blockstack_opts() if not is_subdomains_enabled(opts): log.warn("Subdomain support is disabled") return None if db_path is None: db_path = opts['subdomaindb_path'] if zonefiles_dir is None: zonefiles_dir = opts['zonefiles'] db = SubdomainDB(db_path, zonefiles_dir) try: subrec = db.get_subdomain_entry(fqn) except SubdomainNotFound: log.warn("No such subdomain: {}".format(fqn)) return None try: return db.get_subdomain_DID_info(fqn) except SubdomainNotFound: return None
python
def get_subdomain_DID_info(fqn, db_path=None, zonefiles_dir=None): opts = get_blockstack_opts() if not is_subdomains_enabled(opts): log.warn("Subdomain support is disabled") return None if db_path is None: db_path = opts['subdomaindb_path'] if zonefiles_dir is None: zonefiles_dir = opts['zonefiles'] db = SubdomainDB(db_path, zonefiles_dir) try: subrec = db.get_subdomain_entry(fqn) except SubdomainNotFound: log.warn("No such subdomain: {}".format(fqn)) return None try: return db.get_subdomain_DID_info(fqn) except SubdomainNotFound: return None
[ "def", "get_subdomain_DID_info", "(", "fqn", ",", "db_path", "=", "None", ",", "zonefiles_dir", "=", "None", ")", ":", "opts", "=", "get_blockstack_opts", "(", ")", "if", "not", "is_subdomains_enabled", "(", "opts", ")", ":", "log", ".", "warn", "(", "\"Su...
Get a subdomain's DID info. Return None if not found
[ "Get", "a", "subdomain", "s", "DID", "info", ".", "Return", "None", "if", "not", "found" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L1940-L1966
244,474
blockstack/blockstack-core
blockstack/lib/subdomains.py
get_DID_subdomain
def get_DID_subdomain(did, db_path=None, zonefiles_dir=None, atlasdb_path=None, check_pending=False): """ Static method for resolving a DID to a subdomain Return the subdomain record on success Return None on error """ opts = get_blockstack_opts() if not is_subdomains_enabled(opts): log.warn("Subdomain support is disabled") return None if db_path is None: db_path = opts['subdomaindb_path'] if zonefiles_dir is None: zonefiles_dir = opts['zonefiles'] if atlasdb_path is None: atlasdb_path = opts['atlasdb_path'] db = SubdomainDB(db_path, zonefiles_dir) try: subrec = db.get_DID_subdomain(did) except Exception as e: if BLOCKSTACK_DEBUG: log.exception(e) log.warn("Failed to load subdomain for {}".format(did)) return None if check_pending: # make sure that all of the zone files between this subdomain's # domain's creation and this subdomain's zone file index are present, # minus the ones that are allowed to be missing. subrec.pending = db.subdomain_check_pending(subrec, atlasdb_path) return subrec
python
def get_DID_subdomain(did, db_path=None, zonefiles_dir=None, atlasdb_path=None, check_pending=False): opts = get_blockstack_opts() if not is_subdomains_enabled(opts): log.warn("Subdomain support is disabled") return None if db_path is None: db_path = opts['subdomaindb_path'] if zonefiles_dir is None: zonefiles_dir = opts['zonefiles'] if atlasdb_path is None: atlasdb_path = opts['atlasdb_path'] db = SubdomainDB(db_path, zonefiles_dir) try: subrec = db.get_DID_subdomain(did) except Exception as e: if BLOCKSTACK_DEBUG: log.exception(e) log.warn("Failed to load subdomain for {}".format(did)) return None if check_pending: # make sure that all of the zone files between this subdomain's # domain's creation and this subdomain's zone file index are present, # minus the ones that are allowed to be missing. subrec.pending = db.subdomain_check_pending(subrec, atlasdb_path) return subrec
[ "def", "get_DID_subdomain", "(", "did", ",", "db_path", "=", "None", ",", "zonefiles_dir", "=", "None", ",", "atlasdb_path", "=", "None", ",", "check_pending", "=", "False", ")", ":", "opts", "=", "get_blockstack_opts", "(", ")", "if", "not", "is_subdomains_...
Static method for resolving a DID to a subdomain Return the subdomain record on success Return None on error
[ "Static", "method", "for", "resolving", "a", "DID", "to", "a", "subdomain", "Return", "the", "subdomain", "record", "on", "success", "Return", "None", "on", "error" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L1969-L2005
244,475
blockstack/blockstack-core
blockstack/lib/subdomains.py
is_subdomain_zonefile_hash
def is_subdomain_zonefile_hash(fqn, zonefile_hash, db_path=None, zonefiles_dir=None): """ Static method for getting all historic zone file hashes for a subdomain """ opts = get_blockstack_opts() if not is_subdomains_enabled(opts): return [] if db_path is None: db_path = opts['subdomaindb_path'] if zonefiles_dir is None: zonefiles_dir = opts['zonefiles'] db = SubdomainDB(db_path, zonefiles_dir) zonefile_hashes = db.is_subdomain_zonefile_hash(fqn, zonefile_hash) return zonefile_hashes
python
def is_subdomain_zonefile_hash(fqn, zonefile_hash, db_path=None, zonefiles_dir=None): opts = get_blockstack_opts() if not is_subdomains_enabled(opts): return [] if db_path is None: db_path = opts['subdomaindb_path'] if zonefiles_dir is None: zonefiles_dir = opts['zonefiles'] db = SubdomainDB(db_path, zonefiles_dir) zonefile_hashes = db.is_subdomain_zonefile_hash(fqn, zonefile_hash) return zonefile_hashes
[ "def", "is_subdomain_zonefile_hash", "(", "fqn", ",", "zonefile_hash", ",", "db_path", "=", "None", ",", "zonefiles_dir", "=", "None", ")", ":", "opts", "=", "get_blockstack_opts", "(", ")", "if", "not", "is_subdomains_enabled", "(", "opts", ")", ":", "return"...
Static method for getting all historic zone file hashes for a subdomain
[ "Static", "method", "for", "getting", "all", "historic", "zone", "file", "hashes", "for", "a", "subdomain" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L2008-L2024
244,476
blockstack/blockstack-core
blockstack/lib/subdomains.py
get_subdomain_history
def get_subdomain_history(fqn, offset=None, count=None, reverse=False, db_path=None, zonefiles_dir=None, json=False): """ Static method for getting all historic operations on a subdomain """ opts = get_blockstack_opts() if not is_subdomains_enabled(opts): return [] if db_path is None: db_path = opts['subdomaindb_path'] if zonefiles_dir is None: zonefiles_dir = opts['zonefiles'] db = SubdomainDB(db_path, zonefiles_dir) recs = db.get_subdomain_history(fqn, offset=offset, count=count) if json: recs = [rec.to_json() for rec in recs] ret = {} for rec in recs: if rec['block_number'] not in ret: ret[rec['block_number']] = [] ret[rec['block_number']].append(rec) if reverse: for block_height in ret: ret[block_height].sort(lambda r1, r2: -1 if r1['parent_zonefile_index'] > r2['parent_zonefile_index'] or (r1['parent_zonefile_index'] == r2['parent_zonefile_index'] and r1['zonefile_offset'] > r2['zonefile_offset']) else 1 if r1['parent_zonefile_index'] < r2['parent_zonefile_index'] or (r1['parent_zonefile_index'] == r2['parent_zonefile_index'] and r1['zonefile_offset'] < r2['zonefile_offset']) else 0) return ret else: return recs
python
def get_subdomain_history(fqn, offset=None, count=None, reverse=False, db_path=None, zonefiles_dir=None, json=False): opts = get_blockstack_opts() if not is_subdomains_enabled(opts): return [] if db_path is None: db_path = opts['subdomaindb_path'] if zonefiles_dir is None: zonefiles_dir = opts['zonefiles'] db = SubdomainDB(db_path, zonefiles_dir) recs = db.get_subdomain_history(fqn, offset=offset, count=count) if json: recs = [rec.to_json() for rec in recs] ret = {} for rec in recs: if rec['block_number'] not in ret: ret[rec['block_number']] = [] ret[rec['block_number']].append(rec) if reverse: for block_height in ret: ret[block_height].sort(lambda r1, r2: -1 if r1['parent_zonefile_index'] > r2['parent_zonefile_index'] or (r1['parent_zonefile_index'] == r2['parent_zonefile_index'] and r1['zonefile_offset'] > r2['zonefile_offset']) else 1 if r1['parent_zonefile_index'] < r2['parent_zonefile_index'] or (r1['parent_zonefile_index'] == r2['parent_zonefile_index'] and r1['zonefile_offset'] < r2['zonefile_offset']) else 0) return ret else: return recs
[ "def", "get_subdomain_history", "(", "fqn", ",", "offset", "=", "None", ",", "count", "=", "None", ",", "reverse", "=", "False", ",", "db_path", "=", "None", ",", "zonefiles_dir", "=", "None", ",", "json", "=", "False", ")", ":", "opts", "=", "get_bloc...
Static method for getting all historic operations on a subdomain
[ "Static", "method", "for", "getting", "all", "historic", "operations", "on", "a", "subdomain" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L2027-L2063
244,477
blockstack/blockstack-core
blockstack/lib/subdomains.py
get_all_subdomains
def get_all_subdomains(offset=None, count=None, min_sequence=None, db_path=None, zonefiles_dir=None): """ Static method for getting the list of all subdomains """ opts = get_blockstack_opts() if not is_subdomains_enabled(opts): return [] if db_path is None: db_path = opts['subdomaindb_path'] if zonefiles_dir is None: zonefiles_dir = opts['zonefiles'] db = SubdomainDB(db_path, zonefiles_dir) return db.get_all_subdomains(offset=offset, count=count, min_sequence=None)
python
def get_all_subdomains(offset=None, count=None, min_sequence=None, db_path=None, zonefiles_dir=None): opts = get_blockstack_opts() if not is_subdomains_enabled(opts): return [] if db_path is None: db_path = opts['subdomaindb_path'] if zonefiles_dir is None: zonefiles_dir = opts['zonefiles'] db = SubdomainDB(db_path, zonefiles_dir) return db.get_all_subdomains(offset=offset, count=count, min_sequence=None)
[ "def", "get_all_subdomains", "(", "offset", "=", "None", ",", "count", "=", "None", ",", "min_sequence", "=", "None", ",", "db_path", "=", "None", ",", "zonefiles_dir", "=", "None", ")", ":", "opts", "=", "get_blockstack_opts", "(", ")", "if", "not", "is...
Static method for getting the list of all subdomains
[ "Static", "method", "for", "getting", "the", "list", "of", "all", "subdomains" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L2066-L2081
244,478
blockstack/blockstack-core
blockstack/lib/subdomains.py
get_subdomain_ops_at_txid
def get_subdomain_ops_at_txid(txid, db_path=None, zonefiles_dir=None): """ Static method for getting the list of subdomain operations accepted at a given txid. Includes unaccepted subdomain operations """ opts = get_blockstack_opts() if not is_subdomains_enabled(opts): return [] if db_path is None: db_path = opts['subdomaindb_path'] if zonefiles_dir is None: zonefiles_dir = opts['zonefiles'] db = SubdomainDB(db_path, zonefiles_dir) return db.get_subdomain_ops_at_txid(txid)
python
def get_subdomain_ops_at_txid(txid, db_path=None, zonefiles_dir=None): opts = get_blockstack_opts() if not is_subdomains_enabled(opts): return [] if db_path is None: db_path = opts['subdomaindb_path'] if zonefiles_dir is None: zonefiles_dir = opts['zonefiles'] db = SubdomainDB(db_path, zonefiles_dir) return db.get_subdomain_ops_at_txid(txid)
[ "def", "get_subdomain_ops_at_txid", "(", "txid", ",", "db_path", "=", "None", ",", "zonefiles_dir", "=", "None", ")", ":", "opts", "=", "get_blockstack_opts", "(", ")", "if", "not", "is_subdomains_enabled", "(", "opts", ")", ":", "return", "[", "]", "if", ...
Static method for getting the list of subdomain operations accepted at a given txid. Includes unaccepted subdomain operations
[ "Static", "method", "for", "getting", "the", "list", "of", "subdomain", "operations", "accepted", "at", "a", "given", "txid", ".", "Includes", "unaccepted", "subdomain", "operations" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L2084-L2100
244,479
blockstack/blockstack-core
blockstack/lib/subdomains.py
get_subdomains_owned_by_address
def get_subdomains_owned_by_address(address, db_path=None, zonefiles_dir=None): """ Static method for getting the list of subdomains for a given address """ opts = get_blockstack_opts() if not is_subdomains_enabled(opts): return [] if db_path is None: db_path = opts['subdomaindb_path'] if zonefiles_dir is None: zonefiles_dir = opts['zonefiles'] db = SubdomainDB(db_path, zonefiles_dir) return db.get_subdomains_owned_by_address(address)
python
def get_subdomains_owned_by_address(address, db_path=None, zonefiles_dir=None): opts = get_blockstack_opts() if not is_subdomains_enabled(opts): return [] if db_path is None: db_path = opts['subdomaindb_path'] if zonefiles_dir is None: zonefiles_dir = opts['zonefiles'] db = SubdomainDB(db_path, zonefiles_dir) return db.get_subdomains_owned_by_address(address)
[ "def", "get_subdomains_owned_by_address", "(", "address", ",", "db_path", "=", "None", ",", "zonefiles_dir", "=", "None", ")", ":", "opts", "=", "get_blockstack_opts", "(", ")", "if", "not", "is_subdomains_enabled", "(", "opts", ")", ":", "return", "[", "]", ...
Static method for getting the list of subdomains for a given address
[ "Static", "method", "for", "getting", "the", "list", "of", "subdomains", "for", "a", "given", "address" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L2103-L2118
244,480
blockstack/blockstack-core
blockstack/lib/subdomains.py
get_subdomain_last_sequence
def get_subdomain_last_sequence(db_path=None, zonefiles_dir=None): """ Static method for getting the last sequence number in the database """ opts = get_blockstack_opts() if not is_subdomains_enabled(opts): return [] if db_path is None: db_path = opts['subdomaindb_path'] if zonefiles_dir is None: zonefiles_dir = opts['zonefiles'] db = SubdomainDB(db_path, zonefiles_dir) return db.get_last_sequence()
python
def get_subdomain_last_sequence(db_path=None, zonefiles_dir=None): opts = get_blockstack_opts() if not is_subdomains_enabled(opts): return [] if db_path is None: db_path = opts['subdomaindb_path'] if zonefiles_dir is None: zonefiles_dir = opts['zonefiles'] db = SubdomainDB(db_path, zonefiles_dir) return db.get_last_sequence()
[ "def", "get_subdomain_last_sequence", "(", "db_path", "=", "None", ",", "zonefiles_dir", "=", "None", ")", ":", "opts", "=", "get_blockstack_opts", "(", ")", "if", "not", "is_subdomains_enabled", "(", "opts", ")", ":", "return", "[", "]", "if", "db_path", "i...
Static method for getting the last sequence number in the database
[ "Static", "method", "for", "getting", "the", "last", "sequence", "number", "in", "the", "database" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L2121-L2136
244,481
blockstack/blockstack-core
blockstack/lib/subdomains.py
sign
def sign(privkey_bundle, plaintext): """ Sign a subdomain plaintext with a private key bundle Returns the base64-encoded scriptsig """ if virtualchain.is_singlesig(privkey_bundle): return sign_singlesig(privkey_bundle, plaintext) elif virtualchain.is_multisig(privkey_bundle): return sign_multisig(privkey_bundle, plaintext) else: raise ValueError("private key bundle is neither a singlesig nor multisig bundle")
python
def sign(privkey_bundle, plaintext): if virtualchain.is_singlesig(privkey_bundle): return sign_singlesig(privkey_bundle, plaintext) elif virtualchain.is_multisig(privkey_bundle): return sign_multisig(privkey_bundle, plaintext) else: raise ValueError("private key bundle is neither a singlesig nor multisig bundle")
[ "def", "sign", "(", "privkey_bundle", ",", "plaintext", ")", ":", "if", "virtualchain", ".", "is_singlesig", "(", "privkey_bundle", ")", ":", "return", "sign_singlesig", "(", "privkey_bundle", ",", "plaintext", ")", "elif", "virtualchain", ".", "is_multisig", "(...
Sign a subdomain plaintext with a private key bundle Returns the base64-encoded scriptsig
[ "Sign", "a", "subdomain", "plaintext", "with", "a", "private", "key", "bundle", "Returns", "the", "base64", "-", "encoded", "scriptsig" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L2152-L2162
244,482
blockstack/blockstack-core
blockstack/lib/subdomains.py
subdomains_init
def subdomains_init(blockstack_opts, working_dir, atlas_state): """ Set up subdomain state Returns a SubdomainIndex object that has been successfully connected to Atlas """ if not is_subdomains_enabled(blockstack_opts): return None subdomain_state = SubdomainIndex(blockstack_opts['subdomaindb_path'], blockstack_opts=blockstack_opts) atlas_node_add_callback(atlas_state, 'store_zonefile', subdomain_state.enqueue_zonefile) return subdomain_state
python
def subdomains_init(blockstack_opts, working_dir, atlas_state): if not is_subdomains_enabled(blockstack_opts): return None subdomain_state = SubdomainIndex(blockstack_opts['subdomaindb_path'], blockstack_opts=blockstack_opts) atlas_node_add_callback(atlas_state, 'store_zonefile', subdomain_state.enqueue_zonefile) return subdomain_state
[ "def", "subdomains_init", "(", "blockstack_opts", ",", "working_dir", ",", "atlas_state", ")", ":", "if", "not", "is_subdomains_enabled", "(", "blockstack_opts", ")", ":", "return", "None", "subdomain_state", "=", "SubdomainIndex", "(", "blockstack_opts", "[", "'sub...
Set up subdomain state Returns a SubdomainIndex object that has been successfully connected to Atlas
[ "Set", "up", "subdomain", "state", "Returns", "a", "SubdomainIndex", "object", "that", "has", "been", "successfully", "connected", "to", "Atlas" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L2220-L2231
244,483
blockstack/blockstack-core
blockstack/lib/subdomains.py
Subdomain.verify_signature
def verify_signature(self, addr): """ Given an address, verify whether or not it was signed by it """ return verify(virtualchain.address_reencode(addr), self.get_plaintext_to_sign(), self.sig)
python
def verify_signature(self, addr): return verify(virtualchain.address_reencode(addr), self.get_plaintext_to_sign(), self.sig)
[ "def", "verify_signature", "(", "self", ",", "addr", ")", ":", "return", "verify", "(", "virtualchain", ".", "address_reencode", "(", "addr", ")", ",", "self", ".", "get_plaintext_to_sign", "(", ")", ",", "self", ".", "sig", ")" ]
Given an address, verify whether or not it was signed by it
[ "Given", "an", "address", "verify", "whether", "or", "not", "it", "was", "signed", "by", "it" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L202-L206
244,484
blockstack/blockstack-core
blockstack/lib/subdomains.py
Subdomain.serialize_to_txt
def serialize_to_txt(self): """ Serialize this subdomain record to a TXT record. The trailing newline will be omitted """ txtrec = { 'name': self.fqn if self.independent else self.subdomain, 'txt': self.pack_subdomain()[1:] } return blockstack_zones.record_processors.process_txt([txtrec], '{txt}').strip()
python
def serialize_to_txt(self): txtrec = { 'name': self.fqn if self.independent else self.subdomain, 'txt': self.pack_subdomain()[1:] } return blockstack_zones.record_processors.process_txt([txtrec], '{txt}').strip()
[ "def", "serialize_to_txt", "(", "self", ")", ":", "txtrec", "=", "{", "'name'", ":", "self", ".", "fqn", "if", "self", ".", "independent", "else", "self", ".", "subdomain", ",", "'txt'", ":", "self", ".", "pack_subdomain", "(", ")", "[", "1", ":", "]...
Serialize this subdomain record to a TXT record. The trailing newline will be omitted
[ "Serialize", "this", "subdomain", "record", "to", "a", "TXT", "record", ".", "The", "trailing", "newline", "will", "be", "omitted" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L224-L232
244,485
blockstack/blockstack-core
blockstack/lib/subdomains.py
Subdomain.parse_subdomain_missing_zonefiles_record
def parse_subdomain_missing_zonefiles_record(cls, rec): """ Parse a missing-zonefiles vector given by the domain. Returns the list of zone file indexes on success Raises ParseError on unparseable records """ txt_entry = rec['txt'] if isinstance(txt_entry, list): raise ParseError("TXT entry too long for a missing zone file list") try: return [int(i) for i in txt_entry.split(',')] if txt_entry is not None and len(txt_entry) > 0 else [] except ValueError: raise ParseError('Invalid integers')
python
def parse_subdomain_missing_zonefiles_record(cls, rec): txt_entry = rec['txt'] if isinstance(txt_entry, list): raise ParseError("TXT entry too long for a missing zone file list") try: return [int(i) for i in txt_entry.split(',')] if txt_entry is not None and len(txt_entry) > 0 else [] except ValueError: raise ParseError('Invalid integers')
[ "def", "parse_subdomain_missing_zonefiles_record", "(", "cls", ",", "rec", ")", ":", "txt_entry", "=", "rec", "[", "'txt'", "]", "if", "isinstance", "(", "txt_entry", ",", "list", ")", ":", "raise", "ParseError", "(", "\"TXT entry too long for a missing zone file li...
Parse a missing-zonefiles vector given by the domain. Returns the list of zone file indexes on success Raises ParseError on unparseable records
[ "Parse", "a", "missing", "-", "zonefiles", "vector", "given", "by", "the", "domain", ".", "Returns", "the", "list", "of", "zone", "file", "indexes", "on", "success", "Raises", "ParseError", "on", "unparseable", "records" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L260-L273
244,486
blockstack/blockstack-core
blockstack/lib/subdomains.py
Subdomain.get_public_key
def get_public_key(self): """ Parse the scriptSig and extract the public key. Raises ValueError if this is a multisig-controlled subdomain. """ res = self.get_public_key_info() if 'error' in res: raise ValueError(res['error']) if res['type'] != 'singlesig': raise ValueError(res['error']) return res['public_keys'][0]
python
def get_public_key(self): res = self.get_public_key_info() if 'error' in res: raise ValueError(res['error']) if res['type'] != 'singlesig': raise ValueError(res['error']) return res['public_keys'][0]
[ "def", "get_public_key", "(", "self", ")", ":", "res", "=", "self", ".", "get_public_key_info", "(", ")", "if", "'error'", "in", "res", ":", "raise", "ValueError", "(", "res", "[", "'error'", "]", ")", "if", "res", "[", "'type'", "]", "!=", "'singlesig...
Parse the scriptSig and extract the public key. Raises ValueError if this is a multisig-controlled subdomain.
[ "Parse", "the", "scriptSig", "and", "extract", "the", "public", "key", ".", "Raises", "ValueError", "if", "this", "is", "a", "multisig", "-", "controlled", "subdomain", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L345-L357
244,487
blockstack/blockstack-core
blockstack/lib/subdomains.py
SubdomainIndex.close
def close(self): """ Close the index """ with self.subdomain_db_lock: self.subdomain_db.close() self.subdomain_db = None self.subdomain_db_path = None
python
def close(self): with self.subdomain_db_lock: self.subdomain_db.close() self.subdomain_db = None self.subdomain_db_path = None
[ "def", "close", "(", "self", ")", ":", "with", "self", ".", "subdomain_db_lock", ":", "self", ".", "subdomain_db", ".", "close", "(", ")", "self", ".", "subdomain_db", "=", "None", "self", ".", "subdomain_db_path", "=", "None" ]
Close the index
[ "Close", "the", "index" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L441-L448
244,488
blockstack/blockstack-core
blockstack/lib/subdomains.py
SubdomainIndex.make_new_subdomain_history
def make_new_subdomain_history(self, cursor, subdomain_rec): """ Recalculate the history for this subdomain from genesis up until this record. Returns the list of subdomain records we need to save. """ # what's the subdomain's history up until this subdomain record? hist = self.subdomain_db.get_subdomain_history(subdomain_rec.get_fqn(), include_unaccepted=True, end_sequence=subdomain_rec.n+1, end_zonefile_index=subdomain_rec.parent_zonefile_index+1, cur=cursor) assert len(hist) > 0, 'BUG: not yet stored: {}'.format(subdomain_rec) for i in range(0, len(hist)): hist[i].accepted = False hist.sort(lambda h1, h2: -1 if h1.n < h2.n or (h1.n == h2.n and h1.parent_zonefile_index < h2.parent_zonefile_index) \ else 0 if h1.n == h2.n and h1.parent_zonefile_index == h2.parent_zonefile_index \ else 1) if not self.check_initial_subdomain(hist[0]): log.debug("Reject initial {}".format(hist[0])) return hist else: log.debug("Accept initial {}".format(hist[0])) pass hist[0].accepted = True last_accepted = 0 for i in xrange(1, len(hist)): if self.check_subdomain_transition(hist[last_accepted], hist[i]): log.debug("Accept historic update {}".format(hist[i])) hist[i].accepted = True last_accepted = i else: log.debug("Reject historic update {}".format(hist[i])) hist[i].accepted = False return hist
python
def make_new_subdomain_history(self, cursor, subdomain_rec): # what's the subdomain's history up until this subdomain record? hist = self.subdomain_db.get_subdomain_history(subdomain_rec.get_fqn(), include_unaccepted=True, end_sequence=subdomain_rec.n+1, end_zonefile_index=subdomain_rec.parent_zonefile_index+1, cur=cursor) assert len(hist) > 0, 'BUG: not yet stored: {}'.format(subdomain_rec) for i in range(0, len(hist)): hist[i].accepted = False hist.sort(lambda h1, h2: -1 if h1.n < h2.n or (h1.n == h2.n and h1.parent_zonefile_index < h2.parent_zonefile_index) \ else 0 if h1.n == h2.n and h1.parent_zonefile_index == h2.parent_zonefile_index \ else 1) if not self.check_initial_subdomain(hist[0]): log.debug("Reject initial {}".format(hist[0])) return hist else: log.debug("Accept initial {}".format(hist[0])) pass hist[0].accepted = True last_accepted = 0 for i in xrange(1, len(hist)): if self.check_subdomain_transition(hist[last_accepted], hist[i]): log.debug("Accept historic update {}".format(hist[i])) hist[i].accepted = True last_accepted = i else: log.debug("Reject historic update {}".format(hist[i])) hist[i].accepted = False return hist
[ "def", "make_new_subdomain_history", "(", "self", ",", "cursor", ",", "subdomain_rec", ")", ":", "# what's the subdomain's history up until this subdomain record?", "hist", "=", "self", ".", "subdomain_db", ".", "get_subdomain_history", "(", "subdomain_rec", ".", "get_fqn",...
Recalculate the history for this subdomain from genesis up until this record. Returns the list of subdomain records we need to save.
[ "Recalculate", "the", "history", "for", "this", "subdomain", "from", "genesis", "up", "until", "this", "record", ".", "Returns", "the", "list", "of", "subdomain", "records", "we", "need", "to", "save", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L570-L605
244,489
blockstack/blockstack-core
blockstack/lib/subdomains.py
SubdomainIndex.make_new_subdomain_future
def make_new_subdomain_future(self, cursor, subdomain_rec): """ Recalculate the future for this subdomain from the current record until the latest known record. Returns the list of subdomain records we need to save. """ assert subdomain_rec.accepted, 'BUG: given subdomain record must already be accepted' # what's the subdomain's future after this record? fut = self.subdomain_db.get_subdomain_history(subdomain_rec.get_fqn(), include_unaccepted=True, start_sequence=subdomain_rec.n, start_zonefile_index=subdomain_rec.parent_zonefile_index, cur=cursor) for i in range(0, len(fut)): if fut[i].n == subdomain_rec.n and fut[i].parent_zonefile_index == subdomain_rec.parent_zonefile_index: fut.pop(i) break if len(fut) == 0: log.debug("At tip: {}".format(subdomain_rec)) return [] for i in range(0, len(fut)): fut[i].accepted = False fut = [subdomain_rec] + fut fut.sort(lambda h1, h2: -1 if h1.n < h2.n or (h1.n == h2.n and h1.parent_zonefile_index < h2.parent_zonefile_index) \ else 0 if h1.n == h2.n and h1.parent_zonefile_index == h2.parent_zonefile_index \ else 1) assert fut[0].accepted, 'BUG: initial subdomain record is not accepted: {}'.format(fut[0]) last_accepted = 0 for i in range(1, len(fut)): if self.check_subdomain_transition(fut[last_accepted], fut[i]): log.debug("Accept future update {}".format(fut[i])) fut[i].accepted = True last_accepted = i else: log.debug("Reject future update {}".format(fut[i])) fut[i].accepted = False return fut
python
def make_new_subdomain_future(self, cursor, subdomain_rec): assert subdomain_rec.accepted, 'BUG: given subdomain record must already be accepted' # what's the subdomain's future after this record? fut = self.subdomain_db.get_subdomain_history(subdomain_rec.get_fqn(), include_unaccepted=True, start_sequence=subdomain_rec.n, start_zonefile_index=subdomain_rec.parent_zonefile_index, cur=cursor) for i in range(0, len(fut)): if fut[i].n == subdomain_rec.n and fut[i].parent_zonefile_index == subdomain_rec.parent_zonefile_index: fut.pop(i) break if len(fut) == 0: log.debug("At tip: {}".format(subdomain_rec)) return [] for i in range(0, len(fut)): fut[i].accepted = False fut = [subdomain_rec] + fut fut.sort(lambda h1, h2: -1 if h1.n < h2.n or (h1.n == h2.n and h1.parent_zonefile_index < h2.parent_zonefile_index) \ else 0 if h1.n == h2.n and h1.parent_zonefile_index == h2.parent_zonefile_index \ else 1) assert fut[0].accepted, 'BUG: initial subdomain record is not accepted: {}'.format(fut[0]) last_accepted = 0 for i in range(1, len(fut)): if self.check_subdomain_transition(fut[last_accepted], fut[i]): log.debug("Accept future update {}".format(fut[i])) fut[i].accepted = True last_accepted = i else: log.debug("Reject future update {}".format(fut[i])) fut[i].accepted = False return fut
[ "def", "make_new_subdomain_future", "(", "self", ",", "cursor", ",", "subdomain_rec", ")", ":", "assert", "subdomain_rec", ".", "accepted", ",", "'BUG: given subdomain record must already be accepted'", "# what's the subdomain's future after this record?", "fut", "=", "self", ...
Recalculate the future for this subdomain from the current record until the latest known record. Returns the list of subdomain records we need to save.
[ "Recalculate", "the", "future", "for", "this", "subdomain", "from", "the", "current", "record", "until", "the", "latest", "known", "record", ".", "Returns", "the", "list", "of", "subdomain", "records", "we", "need", "to", "save", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L608-L647
244,490
blockstack/blockstack-core
blockstack/lib/subdomains.py
SubdomainIndex.subdomain_try_insert
def subdomain_try_insert(self, cursor, subdomain_rec, history_neighbors): """ Try to insert a subdomain record into its history neighbors. This is an optimization that handles the "usual" case. We can do this without having to rewrite this subdomain's past and future if (1) we can find a previously-accepted subdomain record, and (2) the transition from this subdomain record to a future subdomain record preserves its acceptance as True. In this case, the "far" past and "far" future are already consistent. Return True if we succeed in doing so. Return False if not. """ blockchain_order = history_neighbors['prev'] + history_neighbors['cur'] + history_neighbors['fut'] last_accepted = -1 for i in range(0, len(blockchain_order)): if blockchain_order[i].accepted: last_accepted = i break if blockchain_order[i].n > subdomain_rec.n or (blockchain_order[i].n == subdomain_rec.n and blockchain_order[i].parent_zonefile_index > subdomain_rec.parent_zonefile_index): # can't cheaply insert this subdomain record, # since none of its immediate ancestors are accepted. log.debug("No immediate ancestors are accepted on {}".format(subdomain_rec)) return False if last_accepted < 0: log.debug("No immediate ancestors or successors are accepted on {}".format(subdomain_rec)) return False # one ancestor was accepted. # work from there. chain_tip_status = blockchain_order[-1].accepted dirty = [] # to be written for i in range(last_accepted+1, len(blockchain_order)): cur_accepted = blockchain_order[i].accepted new_accepted = self.check_subdomain_transition(blockchain_order[last_accepted], blockchain_order[i]) if new_accepted != cur_accepted: blockchain_order[i].accepted = new_accepted log.debug("Changed from {} to {}: {}".format(cur_accepted, new_accepted, blockchain_order[i])) dirty.append(blockchain_order[i]) if new_accepted: last_accepted = i if chain_tip_status != blockchain_order[-1].accepted and len(history_neighbors['fut']) > 0: # deeper reorg log.debug("Immediate history chain tip altered from {} to {}: {}".format(chain_tip_status, blockchain_order[-1].accepted, blockchain_order[-1])) return False # localized change. Just commit the dirty entries for subrec in dirty: log.debug("Update to accepted={}: {}".format(subrec.accepted, subrec)) self.subdomain_db.update_subdomain_entry(subrec, cur=cursor) return True
python
def subdomain_try_insert(self, cursor, subdomain_rec, history_neighbors): blockchain_order = history_neighbors['prev'] + history_neighbors['cur'] + history_neighbors['fut'] last_accepted = -1 for i in range(0, len(blockchain_order)): if blockchain_order[i].accepted: last_accepted = i break if blockchain_order[i].n > subdomain_rec.n or (blockchain_order[i].n == subdomain_rec.n and blockchain_order[i].parent_zonefile_index > subdomain_rec.parent_zonefile_index): # can't cheaply insert this subdomain record, # since none of its immediate ancestors are accepted. log.debug("No immediate ancestors are accepted on {}".format(subdomain_rec)) return False if last_accepted < 0: log.debug("No immediate ancestors or successors are accepted on {}".format(subdomain_rec)) return False # one ancestor was accepted. # work from there. chain_tip_status = blockchain_order[-1].accepted dirty = [] # to be written for i in range(last_accepted+1, len(blockchain_order)): cur_accepted = blockchain_order[i].accepted new_accepted = self.check_subdomain_transition(blockchain_order[last_accepted], blockchain_order[i]) if new_accepted != cur_accepted: blockchain_order[i].accepted = new_accepted log.debug("Changed from {} to {}: {}".format(cur_accepted, new_accepted, blockchain_order[i])) dirty.append(blockchain_order[i]) if new_accepted: last_accepted = i if chain_tip_status != blockchain_order[-1].accepted and len(history_neighbors['fut']) > 0: # deeper reorg log.debug("Immediate history chain tip altered from {} to {}: {}".format(chain_tip_status, blockchain_order[-1].accepted, blockchain_order[-1])) return False # localized change. Just commit the dirty entries for subrec in dirty: log.debug("Update to accepted={}: {}".format(subrec.accepted, subrec)) self.subdomain_db.update_subdomain_entry(subrec, cur=cursor) return True
[ "def", "subdomain_try_insert", "(", "self", ",", "cursor", ",", "subdomain_rec", ",", "history_neighbors", ")", ":", "blockchain_order", "=", "history_neighbors", "[", "'prev'", "]", "+", "history_neighbors", "[", "'cur'", "]", "+", "history_neighbors", "[", "'fut...
Try to insert a subdomain record into its history neighbors. This is an optimization that handles the "usual" case. We can do this without having to rewrite this subdomain's past and future if (1) we can find a previously-accepted subdomain record, and (2) the transition from this subdomain record to a future subdomain record preserves its acceptance as True. In this case, the "far" past and "far" future are already consistent. Return True if we succeed in doing so. Return False if not.
[ "Try", "to", "insert", "a", "subdomain", "record", "into", "its", "history", "neighbors", ".", "This", "is", "an", "optimization", "that", "handles", "the", "usual", "case", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L684-L743
244,491
blockstack/blockstack-core
blockstack/lib/subdomains.py
SubdomainIndex.enqueue_zonefile
def enqueue_zonefile(self, zonefile_hash, block_height): """ Called when we discover a zone file. Queues up a request to reprocess this name's zone files' subdomains. zonefile_hash is the hash of the zonefile. block_height is the minimium block height at which this zone file occurs. This gets called by: * AtlasZonefileCrawler (as it's "store_zonefile" callback). * rpc_put_zonefiles() """ with self.serialized_enqueue_zonefile: log.debug("Append {} from {}".format(zonefile_hash, block_height)) queuedb_append(self.subdomain_queue_path, "zonefiles", zonefile_hash, json.dumps({'zonefile_hash': zonefile_hash, 'block_height': block_height}))
python
def enqueue_zonefile(self, zonefile_hash, block_height): with self.serialized_enqueue_zonefile: log.debug("Append {} from {}".format(zonefile_hash, block_height)) queuedb_append(self.subdomain_queue_path, "zonefiles", zonefile_hash, json.dumps({'zonefile_hash': zonefile_hash, 'block_height': block_height}))
[ "def", "enqueue_zonefile", "(", "self", ",", "zonefile_hash", ",", "block_height", ")", ":", "with", "self", ".", "serialized_enqueue_zonefile", ":", "log", ".", "debug", "(", "\"Append {} from {}\"", ".", "format", "(", "zonefile_hash", ",", "block_height", ")", ...
Called when we discover a zone file. Queues up a request to reprocess this name's zone files' subdomains. zonefile_hash is the hash of the zonefile. block_height is the minimium block height at which this zone file occurs. This gets called by: * AtlasZonefileCrawler (as it's "store_zonefile" callback). * rpc_put_zonefiles()
[ "Called", "when", "we", "discover", "a", "zone", "file", ".", "Queues", "up", "a", "request", "to", "reprocess", "this", "name", "s", "zone", "files", "subdomains", ".", "zonefile_hash", "is", "the", "hash", "of", "the", "zonefile", ".", "block_height", "i...
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L823-L835
244,492
blockstack/blockstack-core
blockstack/lib/subdomains.py
SubdomainIndex.index_blockchain
def index_blockchain(self, block_start, block_end): """ Go through the sequence of zone files discovered in a block range, and reindex the names' subdomains. """ log.debug("Processing subdomain updates for zonefiles in blocks {}-{}".format(block_start, block_end)) res = self.find_zonefile_subdomains(block_start, block_end) zonefile_subdomain_info = res['zonefile_info'] self.process_subdomains(zonefile_subdomain_info)
python
def index_blockchain(self, block_start, block_end): log.debug("Processing subdomain updates for zonefiles in blocks {}-{}".format(block_start, block_end)) res = self.find_zonefile_subdomains(block_start, block_end) zonefile_subdomain_info = res['zonefile_info'] self.process_subdomains(zonefile_subdomain_info)
[ "def", "index_blockchain", "(", "self", ",", "block_start", ",", "block_end", ")", ":", "log", ".", "debug", "(", "\"Processing subdomain updates for zonefiles in blocks {}-{}\"", ".", "format", "(", "block_start", ",", "block_end", ")", ")", "res", "=", "self", "...
Go through the sequence of zone files discovered in a block range, and reindex the names' subdomains.
[ "Go", "through", "the", "sequence", "of", "zone", "files", "discovered", "in", "a", "block", "range", "and", "reindex", "the", "names", "subdomains", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L838-L847
244,493
blockstack/blockstack-core
blockstack/lib/subdomains.py
SubdomainIndex.index_discovered_zonefiles
def index_discovered_zonefiles(self, lastblock): """ Go through the list of zone files we discovered via Atlas, grouped by name and ordered by block height. Find all subsequent zone files for this name, and process all subdomain operations contained within them. """ all_queued_zfinfos = [] # contents of the queue subdomain_zonefile_infos = {} # map subdomain fqn to list of zonefile info bundles, for process_subdomains name_blocks = {} # map domain name to the block at which we should reprocess its subsequent zone files offset = 0 while True: queued_zfinfos = queuedb_findall(self.subdomain_queue_path, "zonefiles", limit=100, offset=offset) if len(queued_zfinfos) == 0: # done! break offset += 100 all_queued_zfinfos += queued_zfinfos if len(all_queued_zfinfos) >= 1000: # only do so many zone files per block, so we don't stall the node break log.debug("Discovered {} zonefiles".format(len(all_queued_zfinfos))) for queued_zfinfo in all_queued_zfinfos: zfinfo = json.loads(queued_zfinfo['data']) zonefile_hash = zfinfo['zonefile_hash'] block_height = zfinfo['block_height'] # find out the names that sent this zone file at this block zfinfos = atlasdb_get_zonefiles_by_hash(zonefile_hash, block_height=block_height, path=self.atlasdb_path) if zfinfos is None: log.warn("Absent zonefile {}".format(zonefile_hash)) continue # find out for each name block height at which its zone file was discovered. # this is where we'll begin looking for more subdomain updates. for zfi in zfinfos: if zfi['name'] not in name_blocks: name_blocks[zfi['name']] = block_height else: name_blocks[zfi['name']] = min(block_height, name_blocks[zfi['name']]) for name in name_blocks: if name_blocks[name] >= lastblock: continue log.debug("Finding subdomain updates for {} at block {}".format(name, name_blocks[name])) # get the subdomains affected at this block by finding the zonefiles created here. res = self.find_zonefile_subdomains(name_blocks[name], lastblock, name=name) zonefile_subdomain_info = res['zonefile_info'] subdomain_index = res['subdomains'] # for each subdomain, find the list of zonefiles that contain records for it for fqn in subdomain_index: if fqn not in subdomain_zonefile_infos: subdomain_zonefile_infos[fqn] = [] for i in subdomain_index[fqn]: subdomain_zonefile_infos[fqn].append(zonefile_subdomain_info[i]) processed = [] for fqn in subdomain_zonefile_infos: subseq = filter(lambda szi: szi['zonefile_hash'] not in processed, subdomain_zonefile_infos[fqn]) if len(subseq) == 0: continue log.debug("Processing {} zone file entries found for {} and others".format(len(subseq), fqn)) subseq.sort(cmp=lambda z1, z2: -1 if z1['block_height'] < z2['block_height'] else 0 if z1['block_height'] == z2['block_height'] else 1) self.process_subdomains(subseq) processed += [szi['zonefile_hash'] for szi in subseq] # clear queue queuedb_removeall(self.subdomain_queue_path, all_queued_zfinfos) return True
python
def index_discovered_zonefiles(self, lastblock): all_queued_zfinfos = [] # contents of the queue subdomain_zonefile_infos = {} # map subdomain fqn to list of zonefile info bundles, for process_subdomains name_blocks = {} # map domain name to the block at which we should reprocess its subsequent zone files offset = 0 while True: queued_zfinfos = queuedb_findall(self.subdomain_queue_path, "zonefiles", limit=100, offset=offset) if len(queued_zfinfos) == 0: # done! break offset += 100 all_queued_zfinfos += queued_zfinfos if len(all_queued_zfinfos) >= 1000: # only do so many zone files per block, so we don't stall the node break log.debug("Discovered {} zonefiles".format(len(all_queued_zfinfos))) for queued_zfinfo in all_queued_zfinfos: zfinfo = json.loads(queued_zfinfo['data']) zonefile_hash = zfinfo['zonefile_hash'] block_height = zfinfo['block_height'] # find out the names that sent this zone file at this block zfinfos = atlasdb_get_zonefiles_by_hash(zonefile_hash, block_height=block_height, path=self.atlasdb_path) if zfinfos is None: log.warn("Absent zonefile {}".format(zonefile_hash)) continue # find out for each name block height at which its zone file was discovered. # this is where we'll begin looking for more subdomain updates. for zfi in zfinfos: if zfi['name'] not in name_blocks: name_blocks[zfi['name']] = block_height else: name_blocks[zfi['name']] = min(block_height, name_blocks[zfi['name']]) for name in name_blocks: if name_blocks[name] >= lastblock: continue log.debug("Finding subdomain updates for {} at block {}".format(name, name_blocks[name])) # get the subdomains affected at this block by finding the zonefiles created here. res = self.find_zonefile_subdomains(name_blocks[name], lastblock, name=name) zonefile_subdomain_info = res['zonefile_info'] subdomain_index = res['subdomains'] # for each subdomain, find the list of zonefiles that contain records for it for fqn in subdomain_index: if fqn not in subdomain_zonefile_infos: subdomain_zonefile_infos[fqn] = [] for i in subdomain_index[fqn]: subdomain_zonefile_infos[fqn].append(zonefile_subdomain_info[i]) processed = [] for fqn in subdomain_zonefile_infos: subseq = filter(lambda szi: szi['zonefile_hash'] not in processed, subdomain_zonefile_infos[fqn]) if len(subseq) == 0: continue log.debug("Processing {} zone file entries found for {} and others".format(len(subseq), fqn)) subseq.sort(cmp=lambda z1, z2: -1 if z1['block_height'] < z2['block_height'] else 0 if z1['block_height'] == z2['block_height'] else 1) self.process_subdomains(subseq) processed += [szi['zonefile_hash'] for szi in subseq] # clear queue queuedb_removeall(self.subdomain_queue_path, all_queued_zfinfos) return True
[ "def", "index_discovered_zonefiles", "(", "self", ",", "lastblock", ")", ":", "all_queued_zfinfos", "=", "[", "]", "# contents of the queue", "subdomain_zonefile_infos", "=", "{", "}", "# map subdomain fqn to list of zonefile info bundles, for process_subdomains", "name_blocks", ...
Go through the list of zone files we discovered via Atlas, grouped by name and ordered by block height. Find all subsequent zone files for this name, and process all subdomain operations contained within them.
[ "Go", "through", "the", "list", "of", "zone", "files", "we", "discovered", "via", "Atlas", "grouped", "by", "name", "and", "ordered", "by", "block", "height", ".", "Find", "all", "subsequent", "zone", "files", "for", "this", "name", "and", "process", "all"...
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L850-L929
244,494
blockstack/blockstack-core
blockstack/lib/subdomains.py
SubdomainDB.subdomain_row_factory
def subdomain_row_factory(cls, cursor, row): """ Dict row factory for subdomains """ d = {} for idx, col in enumerate(cursor.description): d[col[0]] = row[idx] return d
python
def subdomain_row_factory(cls, cursor, row): d = {} for idx, col in enumerate(cursor.description): d[col[0]] = row[idx] return d
[ "def", "subdomain_row_factory", "(", "cls", ",", "cursor", ",", "row", ")", ":", "d", "=", "{", "}", "for", "idx", ",", "col", "in", "enumerate", "(", "cursor", ".", "description", ")", ":", "d", "[", "col", "[", "0", "]", "]", "=", "row", "[", ...
Dict row factory for subdomains
[ "Dict", "row", "factory", "for", "subdomains" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L1000-L1008
244,495
blockstack/blockstack-core
blockstack/lib/subdomains.py
SubdomainDB._extract_subdomain
def _extract_subdomain(self, rowdata): """ Extract a single subdomain from a DB cursor Raise SubdomainNotFound if there are no valid rows """ name = str(rowdata['fully_qualified_subdomain']) domain = str(rowdata['domain']) n = str(rowdata['sequence']) encoded_pubkey = str(rowdata['owner']) zonefile_hash = str(rowdata['zonefile_hash']) sig = rowdata['signature'] block_height = int(rowdata['block_height']) parent_zonefile_hash = str(rowdata['parent_zonefile_hash']) parent_zonefile_index = int(rowdata['parent_zonefile_index']) zonefile_offset = int(rowdata['zonefile_offset']) txid = str(rowdata['txid']) missing = [int(i) for i in rowdata['missing'].split(',')] if rowdata['missing'] is not None and len(rowdata['missing']) > 0 else [] accepted = int(rowdata['accepted']) resolver = str(rowdata['resolver']) if rowdata['resolver'] is not None else None if accepted == 0: accepted = False else: accepted = True if sig == '' or sig is None: sig = None else: sig = str(sig) name = str(name) is_subdomain, _, _ = is_address_subdomain(name) if not is_subdomain: raise Exception("Subdomain DB lookup returned bad subdomain result {}".format(name)) zonefile_str = get_atlas_zonefile_data(zonefile_hash, self.zonefiles_dir) if zonefile_str is None: log.error("No zone file for {}".format(name)) raise SubdomainNotFound('{}: missing zone file {}'.format(name, zonefile_hash)) return Subdomain(str(name), str(domain), str(encoded_pubkey), int(n), str(zonefile_str), sig, block_height, parent_zonefile_hash, parent_zonefile_index, zonefile_offset, txid, domain_zonefiles_missing=missing, accepted=accepted, resolver=resolver)
python
def _extract_subdomain(self, rowdata): name = str(rowdata['fully_qualified_subdomain']) domain = str(rowdata['domain']) n = str(rowdata['sequence']) encoded_pubkey = str(rowdata['owner']) zonefile_hash = str(rowdata['zonefile_hash']) sig = rowdata['signature'] block_height = int(rowdata['block_height']) parent_zonefile_hash = str(rowdata['parent_zonefile_hash']) parent_zonefile_index = int(rowdata['parent_zonefile_index']) zonefile_offset = int(rowdata['zonefile_offset']) txid = str(rowdata['txid']) missing = [int(i) for i in rowdata['missing'].split(',')] if rowdata['missing'] is not None and len(rowdata['missing']) > 0 else [] accepted = int(rowdata['accepted']) resolver = str(rowdata['resolver']) if rowdata['resolver'] is not None else None if accepted == 0: accepted = False else: accepted = True if sig == '' or sig is None: sig = None else: sig = str(sig) name = str(name) is_subdomain, _, _ = is_address_subdomain(name) if not is_subdomain: raise Exception("Subdomain DB lookup returned bad subdomain result {}".format(name)) zonefile_str = get_atlas_zonefile_data(zonefile_hash, self.zonefiles_dir) if zonefile_str is None: log.error("No zone file for {}".format(name)) raise SubdomainNotFound('{}: missing zone file {}'.format(name, zonefile_hash)) return Subdomain(str(name), str(domain), str(encoded_pubkey), int(n), str(zonefile_str), sig, block_height, parent_zonefile_hash, parent_zonefile_index, zonefile_offset, txid, domain_zonefiles_missing=missing, accepted=accepted, resolver=resolver)
[ "def", "_extract_subdomain", "(", "self", ",", "rowdata", ")", ":", "name", "=", "str", "(", "rowdata", "[", "'fully_qualified_subdomain'", "]", ")", "domain", "=", "str", "(", "rowdata", "[", "'domain'", "]", ")", "n", "=", "str", "(", "rowdata", "[", ...
Extract a single subdomain from a DB cursor Raise SubdomainNotFound if there are no valid rows
[ "Extract", "a", "single", "subdomain", "from", "a", "DB", "cursor", "Raise", "SubdomainNotFound", "if", "there", "are", "no", "valid", "rows" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L1025-L1065
244,496
blockstack/blockstack-core
blockstack/lib/subdomains.py
SubdomainDB.get_subdomains_count
def get_subdomains_count(self, accepted=True, cur=None): """ Fetch subdomain names """ if accepted: accepted_filter = 'WHERE accepted=1' else: accepted_filter = '' get_cmd = "SELECT COUNT(DISTINCT fully_qualified_subdomain) as count FROM {} {};".format( self.subdomain_table, accepted_filter) cursor = cur if cursor is None: cursor = self.conn.cursor() db_query_execute(cursor, get_cmd, ()) try: rowdata = cursor.fetchone() return rowdata['count'] except Exception as e: if BLOCKSTACK_DEBUG: log.exception(e) return 0
python
def get_subdomains_count(self, accepted=True, cur=None): if accepted: accepted_filter = 'WHERE accepted=1' else: accepted_filter = '' get_cmd = "SELECT COUNT(DISTINCT fully_qualified_subdomain) as count FROM {} {};".format( self.subdomain_table, accepted_filter) cursor = cur if cursor is None: cursor = self.conn.cursor() db_query_execute(cursor, get_cmd, ()) try: rowdata = cursor.fetchone() return rowdata['count'] except Exception as e: if BLOCKSTACK_DEBUG: log.exception(e) return 0
[ "def", "get_subdomains_count", "(", "self", ",", "accepted", "=", "True", ",", "cur", "=", "None", ")", ":", "if", "accepted", ":", "accepted_filter", "=", "'WHERE accepted=1'", "else", ":", "accepted_filter", "=", "''", "get_cmd", "=", "\"SELECT COUNT(DISTINCT ...
Fetch subdomain names
[ "Fetch", "subdomain", "names" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L1068-L1092
244,497
blockstack/blockstack-core
blockstack/lib/subdomains.py
SubdomainDB.get_all_subdomains
def get_all_subdomains(self, offset=None, count=None, min_sequence=None, cur=None): """ Get and all subdomain names, optionally over a range """ get_cmd = 'SELECT DISTINCT fully_qualified_subdomain FROM {}'.format(self.subdomain_table) args = () if min_sequence is not None: get_cmd += ' WHERE sequence >= ?' args += (min_sequence,) if count is not None: get_cmd += ' LIMIT ?' args += (count,) if offset is not None: get_cmd += ' OFFSET ?' args += (offset,) get_cmd += ';' cursor = None if cur is None: cursor = self.conn.cursor() else: cursor = cur rows = db_query_execute(cursor, get_cmd, args) subdomains = [] for row in rows: subdomains.append(row['fully_qualified_subdomain']) return subdomains
python
def get_all_subdomains(self, offset=None, count=None, min_sequence=None, cur=None): get_cmd = 'SELECT DISTINCT fully_qualified_subdomain FROM {}'.format(self.subdomain_table) args = () if min_sequence is not None: get_cmd += ' WHERE sequence >= ?' args += (min_sequence,) if count is not None: get_cmd += ' LIMIT ?' args += (count,) if offset is not None: get_cmd += ' OFFSET ?' args += (offset,) get_cmd += ';' cursor = None if cur is None: cursor = self.conn.cursor() else: cursor = cur rows = db_query_execute(cursor, get_cmd, args) subdomains = [] for row in rows: subdomains.append(row['fully_qualified_subdomain']) return subdomains
[ "def", "get_all_subdomains", "(", "self", ",", "offset", "=", "None", ",", "count", "=", "None", ",", "min_sequence", "=", "None", ",", "cur", "=", "None", ")", ":", "get_cmd", "=", "'SELECT DISTINCT fully_qualified_subdomain FROM {}'", ".", "format", "(", "se...
Get and all subdomain names, optionally over a range
[ "Get", "and", "all", "subdomain", "names", "optionally", "over", "a", "range" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L1095-L1127
244,498
blockstack/blockstack-core
blockstack/lib/subdomains.py
SubdomainDB.get_subdomain_ops_at_txid
def get_subdomain_ops_at_txid(self, txid, cur=None): """ Given a txid, get all subdomain operations at that txid. Include unaccepted operations. Order by zone file index """ get_cmd = 'SELECT * FROM {} WHERE txid = ? ORDER BY zonefile_offset'.format(self.subdomain_table) cursor = None if cur is None: cursor = self.conn.cursor() else: cursor = cur db_query_execute(cursor, get_cmd, (txid,)) try: return [x for x in cursor.fetchall()] except Exception as e: if BLOCKSTACK_DEBUG: log.exception(e) return []
python
def get_subdomain_ops_at_txid(self, txid, cur=None): get_cmd = 'SELECT * FROM {} WHERE txid = ? ORDER BY zonefile_offset'.format(self.subdomain_table) cursor = None if cur is None: cursor = self.conn.cursor() else: cursor = cur db_query_execute(cursor, get_cmd, (txid,)) try: return [x for x in cursor.fetchall()] except Exception as e: if BLOCKSTACK_DEBUG: log.exception(e) return []
[ "def", "get_subdomain_ops_at_txid", "(", "self", ",", "txid", ",", "cur", "=", "None", ")", ":", "get_cmd", "=", "'SELECT * FROM {} WHERE txid = ? ORDER BY zonefile_offset'", ".", "format", "(", "self", ".", "subdomain_table", ")", "cursor", "=", "None", "if", "cu...
Given a txid, get all subdomain operations at that txid. Include unaccepted operations. Order by zone file index
[ "Given", "a", "txid", "get", "all", "subdomain", "operations", "at", "that", "txid", ".", "Include", "unaccepted", "operations", ".", "Order", "by", "zone", "file", "index" ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L1202-L1224
244,499
blockstack/blockstack-core
blockstack/lib/subdomains.py
SubdomainDB.get_subdomains_owned_by_address
def get_subdomains_owned_by_address(self, owner, cur=None): """ Get the list of subdomain names that are owned by a given address. """ get_cmd = "SELECT fully_qualified_subdomain, MAX(sequence) FROM {} WHERE owner = ? AND accepted=1 GROUP BY fully_qualified_subdomain".format(self.subdomain_table) cursor = None if cur is None: cursor = self.conn.cursor() else: cursor = cur db_query_execute(cursor, get_cmd, (owner,)) try: return [ x['fully_qualified_subdomain'] for x in cursor.fetchall() ] except Exception as e: if BLOCKSTACK_DEBUG: log.exception(e) return []
python
def get_subdomains_owned_by_address(self, owner, cur=None): get_cmd = "SELECT fully_qualified_subdomain, MAX(sequence) FROM {} WHERE owner = ? AND accepted=1 GROUP BY fully_qualified_subdomain".format(self.subdomain_table) cursor = None if cur is None: cursor = self.conn.cursor() else: cursor = cur db_query_execute(cursor, get_cmd, (owner,)) try: return [ x['fully_qualified_subdomain'] for x in cursor.fetchall() ] except Exception as e: if BLOCKSTACK_DEBUG: log.exception(e) return []
[ "def", "get_subdomains_owned_by_address", "(", "self", ",", "owner", ",", "cur", "=", "None", ")", ":", "get_cmd", "=", "\"SELECT fully_qualified_subdomain, MAX(sequence) FROM {} WHERE owner = ? AND accepted=1 GROUP BY fully_qualified_subdomain\"", ".", "format", "(", "self", "...
Get the list of subdomain names that are owned by a given address.
[ "Get", "the", "list", "of", "subdomain", "names", "that", "are", "owned", "by", "a", "given", "address", "." ]
1dcfdd39b152d29ce13e736a6a1a0981401a0505
https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/subdomains.py#L1227-L1247