_id
stringlengths
2
7
title
stringlengths
1
88
partition
stringclasses
3 values
text
stringlengths
75
19.8k
language
stringclasses
1 value
meta_information
dict
q225900
set_recovery_range
train
def set_recovery_range(working_dir, start_block, end_block): """ Set the recovery block range if we're restoring and reporcessing transactions from a backup. Writes the recovery range to the working directory if the working directory is given and persist is True """ recovery_range_path = os.pat...
python
{ "resource": "" }
q225901
clear_recovery_range
train
def clear_recovery_range(working_dir): """ Clear out our recovery hint """ recovery_range_path = os.path.join(working_dir, '.recovery') if os.path.exists(recovery_range_path): os.unlink(recovery_range_path)
python
{ "resource": "" }
q225902
is_atlas_enabled
train
def is_atlas_enabled(blockstack_opts): """ Can we do atlas operations? """ if not blockstack_opts['atlas']: log.debug("Atlas is disabled") return False if 'zonefiles' not in blockstack_opts: log.debug("Atlas is disabled: no 'zonefiles' path set") return False if...
python
{ "resource": "" }
q225903
is_subdomains_enabled
train
def is_subdomains_enabled(blockstack_opts): """ Can we do subdomain operations? """ if not is_atlas_enabled(blockstack_opts): log.debug("Subdomains are disabled") return False if 'subdomaindb_path' not in blockstack_opts: log.debug("Subdomains are disabled: no 'subdomaindb_p...
python
{ "resource": "" }
q225904
store_announcement
train
def store_announcement( working_dir, announcement_hash, announcement_text, force=False ): """ Store a new announcement locally, atomically. """ if not force: # don't store unless we haven't seen it before if announcement_hash in ANNOUNCEMENTS: return announce_filename = get_ann...
python
{ "resource": "" }
q225905
default_blockstack_api_opts
train
def default_blockstack_api_opts(working_dir, config_file=None): """ Get our default blockstack RESTful API opts from a config file, or from sane defaults. """ from .util import url_to_host_port, url_protocol if config_file is None: config_file = virtualchain.get_config_filename(get_default_vir...
python
{ "resource": "" }
q225906
interactive_prompt
train
def interactive_prompt(message, parameters, default_opts): """ Prompt the user for a series of parameters Return a dict mapping the parameter name to the user-given value. """ # pretty-print the message lines = message.split('\n') max_line_len = max([len(l) for l in lines]) print('...
python
{ "resource": "" }
q225907
find_missing
train
def find_missing(message, all_params, given_opts, default_opts, header=None, prompt_missing=True): """ Find and interactively prompt the user for missing parameters, given the list of all valid parameters and a dict of known options. Return the (updated dict of known options, missing, num_prompted), wi...
python
{ "resource": "" }
q225908
opt_strip
train
def opt_strip(prefix, opts): """ Given a dict of opts that start with prefix, remove the prefix from each of them. """ ret = {} for opt_name, opt_value in opts.items(): # remove prefix if opt_name.startswith(prefix): opt_name = opt_name[len(prefix):] ret[opt...
python
{ "resource": "" }
q225909
opt_restore
train
def opt_restore(prefix, opts): """ Given a dict of opts, add the given prefix to each key """ return {prefix + name: value for name, value in opts.items()}
python
{ "resource": "" }
q225910
default_bitcoind_opts
train
def default_bitcoind_opts(config_file=None, prefix=False): """ Get our default bitcoind options, such as from a config file, or from sane defaults """ default_bitcoin_opts = virtualchain.get_bitcoind_config(config_file=config_file) # drop dict values that are None default_bitcoin_opts = {k...
python
{ "resource": "" }
q225911
default_working_dir
train
def default_working_dir(): """ Get the default configuration directory for blockstackd """ import nameset.virtualchain_hooks as virtualchain_hooks return os.path.expanduser('~/.{}'.format(virtualchain_hooks.get_virtual_chain_name()))
python
{ "resource": "" }
q225912
write_config_file
train
def write_config_file(opts, config_file): """ Write our config file with the given options dict. Each key is a section name, and each value is the list of options. If the file exists, do not remove unaffected sections. Instead, merge the sections in opts into the file. Return True on success ...
python
{ "resource": "" }
q225913
load_configuration
train
def load_configuration(working_dir): """ Load the system configuration and set global variables Return the configuration of the node on success. Return None on failure """ import nameset.virtualchain_hooks as virtualchain_hooks # acquire configuration, and store it globally opts = conf...
python
{ "resource": "" }
q225914
check
train
def check( state_engine, nameop, block_id, checked_ops ): """ Verify the validity of a NAMESPACE_READY operation. It is only valid if it has been imported by the same sender as the corresponding NAMESPACE_REVEAL, and the namespace is still in the process of being imported. """ namespace_id ...
python
{ "resource": "" }
q225915
int_to_charset
train
def int_to_charset(val, charset): """ Turn a non-negative integer into a string. >>> int_to_charset(0, B40_CHARS) '0' >>> int_to_charset(658093, B40_CHARS) 'abcd' >>> int_to_charset(40, B40_CHARS) '10' >>> int_to_charset(149190078205533, B40_CHARS) 'muneeb.id' >>> int_to_charset...
python
{ "resource": "" }
q225916
charset_to_int
train
def charset_to_int(s, charset): """ Turn a string into a non-negative integer. >>> charset_to_int('0', B40_CHARS) 0 >>> charset_to_int('10', B40_CHARS) 40 >>> charset_to_int('abcd', B40_CHARS) 658093 >>> charset_to_int('', B40_CHARS) 0 >>> charset_to_int('muneeb.id', B40_CHARS) ...
python
{ "resource": "" }
q225917
change_charset
train
def change_charset(s, original_charset, target_charset): """ Convert a string from one charset to another. """ if not isinstance(s, str): raise ValueError('"s" must be a string.') intermediate_integer = charset_to_int(s, original_charset) output_string = int_to_charset(intermediate_integer,...
python
{ "resource": "" }
q225918
autofill
train
def autofill(*autofill_fields): """ Decorator to automatically fill in extra useful fields that aren't stored in the db. """ def wrap( reader ): def wrapped_reader( *args, **kw ): rec = reader( *args, **kw ) if rec is not None: for field in autofill_fi...
python
{ "resource": "" }
q225919
BlockstackDB.get_readonly_instance
train
def get_readonly_instance(cls, working_dir, expected_snapshots={}): """ Get a read-only handle to the blockstack-specific name db. Multiple read-only handles may exist. Returns the handle on success. Returns None on error """ import virtualchain_hooks db_...
python
{ "resource": "" }
q225920
BlockstackDB.make_opfields
train
def make_opfields( cls ): """ Calculate the virtulachain-required opfields dict. """ # construct fields opfields = {} for opname in SERIALIZE_FIELDS.keys(): opcode = NAME_OPCODES[opname] opfields[opcode] = SERIALIZE_FIELDS[opname] return ...
python
{ "resource": "" }
q225921
BlockstackDB.get_state_paths
train
def get_state_paths(cls, impl, working_dir): """ Get the paths to the relevant db files to back up """ return super(BlockstackDB, cls).get_state_paths(impl, working_dir) + [ os.path.join(working_dir, 'atlas.db'), os.path.join(working_dir, 'subdomains.db')...
python
{ "resource": "" }
q225922
BlockstackDB.close
train
def close( self ): """ Close the db and release memory """ if self.db is not None: self.db.commit() self.db.close() self.db = None return
python
{ "resource": "" }
q225923
BlockstackDB.get_import_keychain_path
train
def get_import_keychain_path( cls, keychain_dir, namespace_id ): """ Get the path to the import keychain """ cached_keychain = os.path.join( keychain_dir, "{}.keychain".format(namespace_id) ) return cached_keychain
python
{ "resource": "" }
q225924
BlockstackDB.build_import_keychain
train
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? c...
python
{ "resource": "" }
q225925
BlockstackDB.load_import_keychain
train
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.ex...
python
{ "resource": "" }
q225926
BlockstackDB.commit_finished
train
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 {}'.f...
python
{ "resource": "" }
q225927
BlockstackDB.log_commit
train
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...
python
{ "resource": "" }
q225928
BlockstackDB.log_reject
train
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,...
python
{ "resource": "" }
q225929
BlockstackDB.sanitize_op
train
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 ...
python
{ "resource": "" }
q225930
BlockstackDB.put_collisions
train
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
{ "resource": "" }
q225931
BlockstackDB.get_namespace
train
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 ...
python
{ "resource": "" }
q225932
BlockstackDB.get_DID_name
train
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...
python
{ "resource": "" }
q225933
BlockstackDB.get_account_tokens
train
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
{ "resource": "" }
q225934
BlockstackDB.get_account
train
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
{ "resource": "" }
q225935
BlockstackDB.get_account_balance
train
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, ...
python
{ "resource": "" }
q225936
BlockstackDB.get_account_history
train
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...
python
{ "resource": "" }
q225937
BlockstackDB.get_name_at
train
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_e...
python
{ "resource": "" }
q225938
BlockstackDB.get_namespace_at
train
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...
python
{ "resource": "" }
q225939
BlockstackDB.get_account_at
train
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
{ "resource": "" }
q225940
BlockstackDB.get_name_history
train
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
{ "resource": "" }
q225941
BlockstackDB.is_name_zonefile_hash
train
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
{ "resource": "" }
q225942
BlockstackDB.get_all_blockstack_ops_at
train
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 ...
python
{ "resource": "" }
q225943
BlockstackDB.get_name_from_name_hash128
train
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
{ "resource": "" }
q225944
BlockstackDB.get_num_historic_names_by_address
train
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
{ "resource": "" }
q225945
BlockstackDB.get_names_owned_by_sender
train
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_pu...
python
{ "resource": "" }
q225946
BlockstackDB.get_num_names
train
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
{ "resource": "" }
q225947
BlockstackDB.get_all_names
train
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:...
python
{ "resource": "" }
q225948
BlockstackDB.get_num_names_in_namespace
train
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
{ "resource": "" }
q225949
BlockstackDB.get_names_in_namespace
train
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 < ...
python
{ "resource": "" }
q225950
BlockstackDB.get_all_namespace_ids
train
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
{ "resource": "" }
q225951
BlockstackDB.get_all_revealed_namespace_ids
train
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
{ "resource": "" }
q225952
BlockstackDB.get_all_preordered_namespace_hashes
train
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 namespa...
python
{ "resource": "" }
q225953
BlockstackDB.get_all_importing_namespace_hashes
train
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
{ "resource": "" }
q225954
BlockstackDB.get_name_preorder
train
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. ...
python
{ "resource": "" }
q225955
BlockstackDB.get_names_with_value_hash
train
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_ge...
python
{ "resource": "" }
q225956
BlockstackDB.get_atlas_zonefile_info_at
train
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}] """ nameo...
python
{ "resource": "" }
q225957
BlockstackDB.get_namespace_reveal
train
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.curso...
python
{ "resource": "" }
q225958
BlockstackDB.is_name_registered
train
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 ...
python
{ "resource": "" }
q225959
BlockstackDB.is_namespace_ready
train
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
{ "resource": "" }
q225960
BlockstackDB.is_namespace_preordered
train
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...
python
{ "resource": "" }
q225961
BlockstackDB.is_namespace_revealed
train
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 ...
python
{ "resource": "" }
q225962
BlockstackDB.is_name_owner
train
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_register...
python
{ "resource": "" }
q225963
BlockstackDB.is_new_preorder
train
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...
python
{ "resource": "" }
q225964
BlockstackDB.is_new_namespace_preorder
train
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, names...
python
{ "resource": "" }
q225965
BlockstackDB.is_name_revoked
train
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
{ "resource": "" }
q225966
BlockstackDB.get_value_hash_txids
train
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
{ "resource": "" }
q225967
BlockstackDB.nameop_set_collided
train
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
{ "resource": "" }
q225968
BlockstackDB.nameop_put_collision
train
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 = name...
python
{ "resource": "" }
q225969
BlockstackDB.extract_consensus_op
train
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 conse...
python
{ "resource": "" }
q225970
BlockstackDB.commit_operation
train
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 != DISPOS...
python
{ "resource": "" }
q225971
BlockstackDB.commit_token_operation
train
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-wr...
python
{ "resource": "" }
q225972
BlockstackDB.commit_account_vesting
train
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() l...
python
{ "resource": "" }
q225973
is_name_valid
train
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....
python
{ "resource": "" }
q225974
is_namespace_valid
train
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') Fal...
python
{ "resource": "" }
q225975
price_namespace
train
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: ...
python
{ "resource": "" }
q225976
find_by_opcode
train
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_...
python
{ "resource": "" }
q225977
get_public_key_hex_from_tx
train
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 reason...
python
{ "resource": "" }
q225978
check_name
train
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...
python
{ "resource": "" }
q225979
check_namespace
train
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...
python
{ "resource": "" }
q225980
check_token_type
train
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_...
python
{ "resource": "" }
q225981
check_subdomain
train
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('abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdab...
python
{ "resource": "" }
q225982
check_block
train
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) -...
python
{ "resource": "" }
q225983
check_offset
train
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 ...
python
{ "resource": "" }
q225984
check_string
train
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 >>...
python
{ "resource": "" }
q225985
check_address
train
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('mk...
python
{ "resource": "" }
q225986
check_account_address
train
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') Tr...
python
{ "resource": "" }
q225987
check_tx_output_types
train
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_scri...
python
{ "resource": "" }
q225988
address_as_b58
train
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'.for...
python
{ "resource": "" }
q225989
verify
train
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).hexdig...
python
{ "resource": "" }
q225990
verify_singlesig
train
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)) ...
python
{ "resource": "" }
q225991
verify_multisig
train
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 Fals...
python
{ "resource": "" }
q225992
is_subdomain_missing_zonefiles_record
train
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)...
python
{ "resource": "" }
q225993
is_subdomain_record
train
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_e...
python
{ "resource": "" }
q225994
get_subdomain_info
train
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_block...
python
{ "resource": "" }
q225995
get_subdomain_resolver
train
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("Su...
python
{ "resource": "" }
q225996
get_subdomains_count
train
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 ...
python
{ "resource": "" }
q225997
get_subdomain_DID_info
train
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: ...
python
{ "resource": "" }
q225998
get_DID_subdomain
train
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): ...
python
{ "resource": "" }
q225999
is_subdomain_zonefile_hash
train
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['su...
python
{ "resource": "" }