idx int64 0 63k | question stringlengths 61 4.03k | target stringlengths 6 1.23k |
|---|---|---|
36,500 | def stop_server ( working_dir , clean = False , kill = False ) : timeout = 1.0 dead = False for i in xrange ( 0 , 5 ) : pid_file = get_pidfile_path ( working_dir ) if not os . path . exists ( pid_file ) : dead = True break pid = read_pid_file ( pid_file ) if pid is not None : try : os . kill ( pid , signal . SIGTERM ) ... | Stop the blockstackd server . |
36,501 | def genesis_block_load ( module_path = None ) : if os . environ . get ( 'BLOCKSTACK_GENESIS_BLOCK_PATH' ) is not None : log . warning ( 'Using envar-given genesis block' ) module_path = os . environ [ 'BLOCKSTACK_GENESIS_BLOCK_PATH' ] genesis_block = None genesis_block_stages = None if module_path : log . debug ( 'Load... | Make sure the genesis block is good to go . Load and instantiate it . |
36,502 | def server_setup ( working_dir , port = None , api_port = None , indexer_enabled = None , indexer_url = None , api_enabled = None , recover = False ) : if not is_genesis_block_instantiated ( ) : genesis_block_load ( ) blockstack_opts = get_blockstack_opts ( ) blockstack_api_opts = get_blockstack_api_opts ( ) pid_file =... | Set up the server . Start all subsystems write pid file set up signal handlers set up DB . Returns a server instance . |
36,503 | def server_shutdown ( server_state ) : set_running ( False ) rpc_stop ( server_state ) api_stop ( server_state ) server_atlas_shutdown ( server_state ) gc_stop ( ) try : if os . path . exists ( server_state [ 'pid_file' ] ) : os . unlink ( server_state [ 'pid_file' ] ) except : pass return True | Shut down server subsystems . Remove PID file . |
36,504 | def run_server ( working_dir , foreground = False , expected_snapshots = GENESIS_SNAPSHOT , port = None , api_port = None , use_api = None , use_indexer = None , indexer_url = None , recover = False ) : global rpc_server global api_server indexer_log_path = get_logfile_path ( working_dir ) logfile = None if not foregro... | Run blockstackd . Optionally daemonize . Return 0 on success Return negative on error |
36,505 | def setup ( working_dir , interactive = False ) : log . debug ( "Working dir: {}" . format ( working_dir ) ) if not os . path . exists ( working_dir ) : os . makedirs ( working_dir , 0700 ) node_config = load_configuration ( working_dir ) if node_config is None : sys . exit ( 1 ) log . debug ( "config\n{}" . format ( j... | Do one - time initialization . Call this to set up global state . |
36,506 | def reconfigure ( working_dir ) : configure ( working_dir , force = True , interactive = True ) print "Blockstack successfully reconfigured." sys . exit ( 0 ) | Reconfigure blockstackd . |
36,507 | def verify_database ( trusted_consensus_hash , consensus_block_height , untrusted_working_dir , trusted_working_dir , start_block = None , expected_snapshots = { } ) : db = BlockstackDB . get_readwrite_instance ( trusted_working_dir ) consensus_impl = virtualchain_hooks return virtualchain . state_engine_verify ( trust... | Verify that a database is consistent with a known - good consensus hash . Return True if valid . Return False if not |
36,508 | def check_and_set_envars ( argv ) : special_flags = { '--debug' : { 'arg' : False , 'envar' : 'BLOCKSTACK_DEBUG' , 'exec' : True , } , '--verbose' : { 'arg' : False , 'envar' : 'BLOCKSTACK_DEBUG' , 'exec' : True , } , '--testnet-id' : { 'arg' : True , 'envar' : 'BLOCKSTACK_TESTNET_ID' , 'exec' : True , } , '--testnet-s... | Go through argv and find any special command - line flags that set environment variables that affect multiple modules . |
36,509 | def load_expected_snapshots ( snapshots_path ) : snapshots_path = os . path . expanduser ( snapshots_path ) expected_snapshots = { } try : with open ( snapshots_path , "r" ) as f : snapshots_json = f . read ( ) snapshots_data = json . loads ( snapshots_json ) assert 'snapshots' in snapshots_data . keys ( ) , "Not a val... | Load expected consensus hashes from a . snapshots file . Return the snapshots as a dict on success Return None on error |
36,510 | def do_genesis_block_audit ( genesis_block_path = None , key_id = None ) : signing_keys = GENESIS_BLOCK_SIGNING_KEYS if genesis_block_path is not None : genesis_block_load ( genesis_block_path ) if key_id is not None : gpg2_path = find_gpg2 ( ) assert gpg2_path , 'You need to install gpg2' p = subprocess . Popen ( [ gp... | Loads and audits the genesis block optionally using an alternative key |
36,511 | def setup_recovery ( working_dir ) : db = get_db_state ( working_dir ) bitcoind_session = get_bitcoind ( new = True ) assert bitcoind_session is not None _ , current_block = virtualchain . get_index_range ( 'bitcoin' , bitcoind_session , virtualchain_hooks , working_dir ) assert current_block , 'Failed to connect to bi... | Set up the recovery metadata so we can fully recover secondary state like subdomains . |
36,512 | def check_recovery ( working_dir ) : recovery_start_block , recovery_end_block = get_recovery_range ( working_dir ) if recovery_start_block is not None and recovery_end_block is not None : local_current_block = virtualchain_hooks . get_last_block ( working_dir ) if local_current_block <= recovery_end_block : return Tru... | Do we need to recover on start - up? |
36,513 | def success_response ( self , method_resp , ** kw ) : resp = { 'status' : True , 'indexing' : config . is_indexing ( self . working_dir ) , 'lastblock' : virtualchain_hooks . get_last_block ( self . working_dir ) , } resp . update ( kw ) resp . update ( method_resp ) if self . is_stale ( ) : resp [ 'stale' ] = True res... | Make a standard success response which contains some ancilliary data . |
36,514 | def load_name_info ( self , db , name_record ) : name = str ( name_record [ 'name' ] ) name_record = self . sanitize_rec ( name_record ) namespace_id = get_namespace_from_name ( name ) namespace_record = db . get_namespace ( namespace_id , include_history = False ) if namespace_record is None : namespace_record = db . ... | Get some extra name information given a db - loaded name record . Return the updated name_record |
36,515 | def get_name_DID_info ( self , name ) : db = get_db_state ( self . working_dir ) did_info = db . get_name_DID_info ( name ) if did_info is None : return { 'error' : 'No such name' , 'http_status' : 404 } return did_info | Get a name s DID info Returns None if not found |
36,516 | def rpc_get_name_DID ( self , name , ** con_info ) : did_info = None if check_name ( name ) : did_info = self . get_name_DID_info ( name ) elif check_subdomain ( name ) : did_info = self . get_subdomain_DID_info ( name ) else : return { 'error' : 'Invalid name or subdomain' , 'http_status' : 400 } if did_info is None :... | Given a name or subdomain return its DID . |
36,517 | def rpc_get_DID_record ( self , did , ** con_info ) : if not isinstance ( did , ( str , unicode ) ) : return { 'error' : 'Invalid DID: not a string' , 'http_status' : 400 } try : did_info = parse_DID ( did ) except : return { 'error' : 'Invalid DID' , 'http_status' : 400 } res = None if did_info [ 'name_type' ] == 'nam... | Given a DID return the name or subdomain it corresponds to |
36,518 | def rpc_get_blockstack_ops_at ( self , block_id , offset , count , ** con_info ) : if not check_block ( block_id ) : return { 'error' : 'Invalid block height' , 'http_status' : 400 } if not check_offset ( offset ) : return { 'error' : 'Invalid offset' , 'http_status' : 400 } if not check_count ( count , 10 ) : return {... | Get the name operations that occured in the given block . Does not include account operations . |
36,519 | def rpc_get_blockstack_ops_hash_at ( self , block_id , ** con_info ) : if not check_block ( block_id ) : return { 'error' : 'Invalid block height' , 'http_status' : 400 } db = get_db_state ( self . working_dir ) ops_hash = db . get_block_ops_hash ( block_id ) db . close ( ) return self . success_response ( { 'ops_hash'... | Get the hash over the sequence of names and namespaces altered at the given block . Used by SNV clients . |
36,520 | def get_bitcoind_info ( self ) : cached_bitcoind_info = self . get_cached_bitcoind_info ( ) if cached_bitcoind_info : return cached_bitcoind_info bitcoind_opts = default_bitcoind_opts ( virtualchain . get_config_filename ( virtualchain_hooks , self . working_dir ) , prefix = True ) bitcoind = get_bitcoind ( new_bitcoin... | Get bitcoind info . Try the cache and on cache miss fetch from bitcoind and cache . |
36,521 | def get_consensus_info ( self ) : cached_consensus_info = self . get_cached_consensus_info ( ) if cached_consensus_info : return cached_consensus_info db = get_db_state ( self . working_dir ) ch = db . get_current_consensus ( ) block = db . get_current_block ( ) db . close ( ) cinfo = { 'consensus_hash' : ch , 'block_h... | Get block height and consensus hash . Try the cache and on cache miss fetch from the db |
36,522 | def rpc_get_account_tokens ( self , address , ** con_info ) : if not check_account_address ( address ) : return { 'error' : 'Invalid address' , 'http_status' : 400 } if is_c32_address ( address ) : address = c32ToB58 ( address ) db = get_db_state ( self . working_dir ) token_list = db . get_account_tokens ( address ) d... | Get the types of tokens that an account owns Returns the list on success |
36,523 | def rpc_get_account_balance ( self , address , token_type , ** con_info ) : if not check_account_address ( address ) : return { 'error' : 'Invalid address' , 'http_status' : 400 } if not check_token_type ( token_type ) : return { 'error' : 'Invalid token type' , 'http_status' : 400 } if is_c32_address ( address ) : add... | Get the balance of an address for a particular token type Returns the value on success Returns 0 if the balance is 0 or if there is no address |
36,524 | def export_account_state ( self , account_state ) : return { 'address' : account_state [ 'address' ] , 'type' : account_state [ 'type' ] , 'credit_value' : '{}' . format ( account_state [ 'credit_value' ] ) , 'debit_value' : '{}' . format ( account_state [ 'debit_value' ] ) , 'lock_transfer_block_id' : account_state [ ... | Make an account state presentable to external consumers |
36,525 | def rpc_get_account_record ( self , address , token_type , ** con_info ) : if not check_account_address ( address ) : return { 'error' : 'Invalid address' , 'http_status' : 400 } if not check_token_type ( token_type ) : return { 'error' : 'Invalid token type' , 'http_status' : 400 } if is_c32_address ( address ) : addr... | Get the current state of an account |
36,526 | def rpc_get_account_at ( self , address , block_height , ** con_info ) : if not check_account_address ( address ) : return { 'error' : 'Invalid address' , 'http_status' : 400 } if not check_block ( block_height ) : return { 'error' : 'Invalid start block' , 'http_status' : 400 } if is_c32_address ( address ) : address ... | Get the account s statuses at a particular block height . Returns the sequence of history states on success |
36,527 | def rpc_get_consensus_hashes ( self , block_id_list , ** con_info ) : if type ( block_id_list ) != list : return { 'error' : 'Invalid block heights' , 'http_status' : 400 } if len ( block_id_list ) > 32 : return { 'error' : 'Too many block heights' , 'http_status' : 400 } for bid in block_id_list : if not check_block (... | Return the consensus hashes at multiple block numbers Return a dict mapping each block ID to its consensus hash . |
36,528 | def get_zonefile_data ( self , zonefile_hash , zonefile_dir ) : atlas_zonefile_data = get_atlas_zonefile_data ( zonefile_hash , zonefile_dir , check = False ) if atlas_zonefile_data is not None : zfh = get_zonefile_data_hash ( atlas_zonefile_data ) if zfh != zonefile_hash : log . debug ( "Invalid local zonefile %s" % z... | Get a zonefile by hash Return the serialized zonefile on success Return None on error |
36,529 | def rpc_get_zonefiles_by_block ( self , from_block , to_block , offset , count , ** con_info ) : conf = get_blockstack_opts ( ) if not is_atlas_enabled ( conf ) : return { 'error' : 'Not an atlas node' , 'http_status' : 400 } if not check_block ( from_block ) : return { 'error' : 'Invalid from_block height' , 'http_sta... | Get information about zonefiles announced in blocks [ |
36,530 | def peer_exchange ( self , peer_host , peer_port ) : peer_list = atlas_get_live_neighbors ( "%s:%s" % ( peer_host , peer_port ) ) if len ( peer_list ) > atlas_max_neighbors ( ) : random . shuffle ( peer_list ) peer_list = peer_list [ : atlas_max_neighbors ( ) ] log . info ( "Enqueue remote peer {}:{}" . format ( peer_h... | Exchange peers . Add the given peer to the list of new peers to consider . Return the list of healthy peers |
36,531 | def rpc_atlas_peer_exchange ( self , remote_peer , ** con_info ) : conf = get_blockstack_opts ( ) if not conf . get ( 'atlas' , False ) : return { 'error' : 'Not an atlas node' , 'http_status' : 404 } client_host = con_info [ 'client_host' ] client_port = con_info [ 'client_port' ] peer_host = None peer_port = None LOC... | Accept a remotely - given atlas peer and return our list of healthy peers . The remotely - given atlas peer will only be considered if the caller is localhost ; otherwise the caller s socket - given information will be used . This is to prevent a malicious node from filling up this node s peer table with junk . |
36,532 | def stop_server ( self ) : if self . rpc_server is not None : try : self . rpc_server . socket . shutdown ( socket . SHUT_RDWR ) except : log . warning ( "Failed to shut down server socket" ) self . rpc_server . shutdown ( ) | Stop serving . Also stops the thread . |
36,533 | def get_last_block ( working_dir ) : impl = sys . modules [ __name__ ] return BlockstackDB . get_lastblock ( impl , working_dir ) | Get the last block processed Return the integer on success Return None on error |
36,534 | def get_or_instantiate_db_state ( working_dir ) : new_db = BlockstackDB . borrow_readwrite_instance ( working_dir , - 1 ) BlockstackDB . release_readwrite_instance ( new_db , - 1 ) return get_db_state ( working_dir ) | Get a read - only handle to the DB . Instantiate it first if it doesn t exist . |
36,535 | def check_quirks ( block_id , block_op , db_state ) : if op_get_opcode_name ( block_op [ 'op' ] ) in OPCODE_NAME_NAMEOPS and op_get_opcode_name ( block_op [ 'op' ] ) not in OPCODE_NAME_STATE_PREORDER : assert 'last_creation_op' in block_op , 'QUIRK BUG: missing last_creation_op in {}' . format ( op_get_opcode_name ( bl... | Check that all serialization compatibility quirks have been preserved . Used primarily for testing . |
36,536 | def sync_blockchain ( working_dir , bt_opts , last_block , server_state , expected_snapshots = { } , ** virtualchain_args ) : subdomain_index = server_state [ 'subdomains' ] atlas_state = server_state [ 'atlas' ] impl = sys . modules [ __name__ ] log . info ( "Synchronizing database {} up to block {}" . format ( workin... | synchronize state with the blockchain . Return True on success Return False if we re supposed to stop indexing Abort on error |
36,537 | def url_protocol ( url , port = None ) : if not url . startswith ( 'http://' ) and not url . startswith ( 'https://' ) : return None urlinfo = urllib2 . urlparse . urlparse ( url ) assert urlinfo . scheme in [ 'http' , 'https' ] , 'Invalid URL scheme in {}' . format ( url ) return urlinfo . scheme | Get the protocol to use for a URL . return http or https or None |
36,538 | def make_DID ( name_type , address , index ) : if name_type not in [ 'name' , 'subdomain' ] : raise ValueError ( "Require 'name' or 'subdomain' for name_type" ) if name_type == 'name' : address = virtualchain . address_reencode ( address ) else : vb = keylib . b58check . b58check_version_byte ( address ) if vb == bitco... | Standard way of making a DID . name_type is name or subdomain |
36,539 | def process_request_thread ( self , request , client_address ) : from . . blockstackd import get_gc_thread try : self . finish_request ( request , client_address ) except Exception : self . handle_error ( request , client_address ) finally : self . shutdown_request ( request ) shutdown_thread = False with self . _threa... | Same as in BaseServer but as a thread . In addition exception handling is done here . |
36,540 | def get_request ( self ) : request , client_addr = super ( BoundedThreadingMixIn , self ) . get_request ( ) overload = False with self . _thread_guard : if self . _threads is not None and len ( self . _threads ) + 1 > MAX_RPC_THREADS : overload = True if overload : res = self . overloaded ( client_addr ) request . send... | Accept a request up to the given number of allowed threads . Defer to self . overloaded if there are already too many pending requests . |
36,541 | def get_epoch_config ( block_height ) : global EPOCHS epoch_number = get_epoch_number ( block_height ) if epoch_number < 0 or epoch_number >= len ( EPOCHS ) : log . error ( "FATAL: invalid epoch %s" % epoch_number ) os . abort ( ) return EPOCHS [ epoch_number ] | Get the epoch constants for the given block height |
36,542 | def get_epoch_namespace_lifetime_multiplier ( block_height , namespace_id ) : epoch_config = get_epoch_config ( block_height ) if epoch_config [ 'namespaces' ] . has_key ( namespace_id ) : return epoch_config [ 'namespaces' ] [ namespace_id ] [ 'NAMESPACE_LIFETIME_MULTIPLIER' ] else : return epoch_config [ 'namespaces'... | what s the namespace lifetime multipler for this epoch? |
36,543 | def get_epoch_namespace_lifetime_grace_period ( block_height , namespace_id ) : epoch_config = get_epoch_config ( block_height ) if epoch_config [ 'namespaces' ] . has_key ( namespace_id ) : return epoch_config [ 'namespaces' ] [ namespace_id ] [ 'NAMESPACE_LIFETIME_GRACE_PERIOD' ] else : return epoch_config [ 'namespa... | what s the namespace lifetime grace period for this epoch? |
36,544 | def get_epoch_namespace_prices ( block_height , units ) : assert units in [ 'BTC' , TOKEN_TYPE_STACKS ] , 'Invalid unit {}' . format ( units ) epoch_config = get_epoch_config ( block_height ) if units == 'BTC' : return epoch_config [ 'namespace_prices' ] else : return epoch_config [ 'namespace_prices_stacks' ] | get the list of namespace prices by block height |
36,545 | def op_get_opcode_name ( op_string ) : global OPCODE_NAMES if op_string == '{}:' . format ( NAME_REGISTRATION ) : return 'NAME_RENEWAL' op = op_string [ 0 ] if op not in OPCODE_NAMES : raise Exception ( 'No such operation "{}"' . format ( op ) ) return OPCODE_NAMES [ op ] | Get the name of an opcode given the op byte sequence of the operation . |
36,546 | def get_announce_filename ( working_dir ) : announce_filepath = os . path . join ( working_dir , get_default_virtualchain_impl ( ) . get_virtual_chain_name ( ) ) + '.announce' return announce_filepath | Get the path to the file that stores all of the announcements . |
36,547 | def is_indexing ( working_dir ) : indexing_path = get_indexing_lockfile ( working_dir ) if os . path . exists ( indexing_path ) : return True else : return False | Is the blockstack daemon synchronizing with the blockchain? |
36,548 | def set_indexing ( working_dir , flag ) : indexing_path = get_indexing_lockfile ( working_dir ) if flag : try : fd = open ( indexing_path , "w+" ) fd . close ( ) return True except : return False else : try : os . unlink ( indexing_path ) return True except : return False | Set a flag in the filesystem as to whether or not we re indexing . |
36,549 | def set_recovery_range ( working_dir , start_block , end_block ) : recovery_range_path = os . path . join ( working_dir , '.recovery' ) with open ( recovery_range_path , 'w' ) as f : f . write ( '{}\n{}\n' . format ( start_block , end_block ) ) f . flush ( ) os . fsync ( f . fileno ( ) ) | Set the recovery block range if we re restoring and reporcessing transactions from a backup . |
36,550 | def clear_recovery_range ( working_dir ) : recovery_range_path = os . path . join ( working_dir , '.recovery' ) if os . path . exists ( recovery_range_path ) : os . unlink ( recovery_range_path ) | Clear out our recovery hint |
36,551 | def is_atlas_enabled ( blockstack_opts ) : 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 'atlasdb_path' not in blockstack_opts : log . debug ( "Atlas is disabled: ... | Can we do atlas operations? |
36,552 | def is_subdomains_enabled ( blockstack_opts ) : 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_path' path set" ) return False return True | Can we do subdomain operations? |
36,553 | def store_announcement ( working_dir , announcement_hash , announcement_text , force = False ) : if not force : if announcement_hash in ANNOUNCEMENTS : return announce_filename = get_announce_filename ( working_dir ) announce_filename_tmp = announce_filename + ".tmp" announce_text = "" announce_cleanup_list = [ ] if os... | Store a new announcement locally atomically . |
36,554 | def default_blockstack_api_opts ( working_dir , config_file = None ) : from . util import url_to_host_port , url_protocol if config_file is None : config_file = virtualchain . get_config_filename ( get_default_virtualchain_impl ( ) , working_dir ) parser = SafeConfigParser ( ) parser . read ( config_file ) blockstack_a... | Get our default blockstack RESTful API opts from a config file or from sane defaults . |
36,555 | def interactive_prompt ( message , parameters , default_opts ) : lines = message . split ( '\n' ) max_line_len = max ( [ len ( l ) for l in lines ] ) print ( '-' * max_line_len ) print ( message ) print ( '-' * max_line_len ) ret = { } for param in parameters : formatted_param = param prompt_str = '{}: ' . format ( for... | Prompt the user for a series of parameters Return a dict mapping the parameter name to the user - given value . |
36,556 | def find_missing ( message , all_params , given_opts , default_opts , header = None , prompt_missing = True ) : missing_params = list ( set ( all_params ) - set ( given_opts ) ) num_prompted = 0 if not missing_params : return given_opts , missing_params , num_prompted if not prompt_missing : missing_values = set ( defa... | Find and interactively prompt the user for missing parameters given the list of all valid parameters and a dict of known options . |
36,557 | def opt_strip ( prefix , opts ) : ret = { } for opt_name , opt_value in opts . items ( ) : if opt_name . startswith ( prefix ) : opt_name = opt_name [ len ( prefix ) : ] ret [ opt_name ] = opt_value return ret | Given a dict of opts that start with prefix remove the prefix from each of them . |
36,558 | def opt_restore ( prefix , opts ) : return { prefix + name : value for name , value in opts . items ( ) } | Given a dict of opts add the given prefix to each key |
36,559 | def default_bitcoind_opts ( config_file = None , prefix = False ) : default_bitcoin_opts = virtualchain . get_bitcoind_config ( config_file = config_file ) default_bitcoin_opts = { k : v for k , v in default_bitcoin_opts . items ( ) if v is not None } if not prefix : default_bitcoin_opts = opt_strip ( 'bitcoind_' , def... | Get our default bitcoind options such as from a config file or from sane defaults |
36,560 | def default_working_dir ( ) : import nameset . virtualchain_hooks as virtualchain_hooks return os . path . expanduser ( '~/.{}' . format ( virtualchain_hooks . get_virtual_chain_name ( ) ) ) | Get the default configuration directory for blockstackd |
36,561 | def write_config_file ( opts , config_file ) : parser = SafeConfigParser ( ) if os . path . exists ( config_file ) : parser . read ( config_file ) for sec_name in opts : sec_opts = opts [ sec_name ] if parser . has_section ( sec_name ) : parser . remove_section ( sec_name ) parser . add_section ( sec_name ) for opt_nam... | Write our config file with the given options dict . Each key is a section name and each value is the list of options . |
36,562 | def load_configuration ( working_dir ) : import nameset . virtualchain_hooks as virtualchain_hooks opts = configure ( working_dir ) blockstack_opts = opts . get ( 'blockstack' , None ) blockstack_api_opts = opts . get ( 'blockstack-api' , None ) bitcoin_opts = opts [ 'bitcoind' ] config_server_version = blockstack_opts... | Load the system configuration and set global variables Return the configuration of the node on success . Return None on failure |
36,563 | def check ( state_engine , nameop , block_id , checked_ops ) : namespace_id = nameop [ 'namespace_id' ] sender = nameop [ 'sender' ] if not state_engine . is_namespace_revealed ( namespace_id ) : log . warning ( "Namespace '%s' is not revealed" % namespace_id ) return False revealed_namespace = state_engine . get_names... | 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 . |
36,564 | def int_to_charset ( val , charset ) : if val < 0 : raise ValueError ( '"val" must be a non-negative integer.' ) if val == 0 : return charset [ 0 ] output = "" while val > 0 : val , digit = divmod ( val , len ( charset ) ) output += charset [ digit ] return output [ : : - 1 ] | Turn a non - negative integer into a string . |
36,565 | def charset_to_int ( s , charset ) : output = 0 for char in s : output = output * len ( charset ) + charset . index ( char ) return output | Turn a string into a non - negative integer . |
36,566 | def change_charset ( s , original_charset , target_charset ) : 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 , target_charset ) return output_string | Convert a string from one charset to another . |
36,567 | def autofill ( * autofill_fields ) : def wrap ( reader ) : def wrapped_reader ( * args , ** kw ) : rec = reader ( * args , ** kw ) if rec is not None : for field in autofill_fields : if field == "opcode" and 'opcode' not in rec . keys ( ) : assert 'op' in rec . keys ( ) , "BUG: record is missing 'op'" rec [ 'opcode' ] ... | Decorator to automatically fill in extra useful fields that aren t stored in the db . |
36,568 | def get_readonly_instance ( cls , working_dir , expected_snapshots = { } ) : import virtualchain_hooks db_path = virtualchain . get_db_filename ( virtualchain_hooks , working_dir ) db = BlockstackDB ( db_path , DISPOSITION_RO , working_dir , get_genesis_block ( ) , expected_snapshots = { } ) rc = db . db_setup ( ) if n... | Get a read - only handle to the blockstack - specific name db . Multiple read - only handles may exist . |
36,569 | def make_opfields ( cls ) : opfields = { } for opname in SERIALIZE_FIELDS . keys ( ) : opcode = NAME_OPCODES [ opname ] opfields [ opcode ] = SERIALIZE_FIELDS [ opname ] return opfields | Calculate the virtulachain - required opfields dict . |
36,570 | def get_state_paths ( cls , impl , working_dir ) : return super ( BlockstackDB , cls ) . get_state_paths ( impl , working_dir ) + [ os . path . join ( working_dir , 'atlas.db' ) , os . path . join ( working_dir , 'subdomains.db' ) , os . path . join ( working_dir , 'subdomains.db.queue' ) ] | Get the paths to the relevant db files to back up |
36,571 | def close ( self ) : if self . db is not None : self . db . commit ( ) self . db . close ( ) self . db = None return | Close the db and release memory |
36,572 | def get_import_keychain_path ( cls , keychain_dir , namespace_id ) : cached_keychain = os . path . join ( keychain_dir , "{}.keychain" . format ( namespace_id ) ) return cached_keychain | Get the path to the import keychain |
36,573 | def build_import_keychain ( cls , keychain_dir , namespace_id , pubkey_hex ) : pubkey_addr = virtualchain . BitcoinPublicKey ( str ( pubkey_hex ) ) . address ( ) cached_keychain = cls . get_import_keychain_path ( keychain_dir , namespace_id ) if os . path . exists ( cached_keychain ) : child_addrs = [ ] try : lines = [... | Generate all possible NAME_IMPORT addresses from the NAMESPACE_REVEAL public key |
36,574 | def load_import_keychain ( cls , working_dir , namespace_id ) : 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... | Get an import keychain from disk . Return None if it doesn t exist . |
36,575 | def commit_finished ( self , block_id ) : self . db . commit ( ) 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 ) | Called when the block is finished . Commits all data . |
36,576 | 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 so... | Log a committed operation |
36,577 | 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 so... | Log a rejected operation |
36,578 | def sanitize_op ( self , op_data ) : op_data = super ( BlockstackDB , self ) . sanitize_op ( op_data ) to_remove = get_state_invariant_tags ( ) for tag in to_remove : if tag in op_data . keys ( ) : del op_data [ tag ] opcode_family = op_get_opcode_name ( op_data [ 'op' ] ) mutate_fields = op_get_mutate_fields ( opcode_... | 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 |
36,579 | 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 . |
36,580 | 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 ) | Given a namespace ID get the ready namespace op for it . |
36,581 | 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 = n... | Given a DID get the name Return None if not found or if the name was revoked Raise if the DID is invalid |
36,582 | 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 |
36,583 | 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 |
36,584 | 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 | What s the balance of an account? Aborts if its negative |
36,585 | 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 ) | Get the history of account transactions over a block range Returns a dict keyed by blocks which map to lists of account state transitions |
36,586 | 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 ) | Generate and return the sequence of of states a name record was in at a particular block number . |
36,587 | 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 ) | Generate and return the sequence of states a namespace record was in at a particular block number . |
36,588 | 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 |
36,589 | 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 | Get the historic states for a name grouped by block height . |
36,590 | 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? |
36,591 | 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 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 . |
36,592 | 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 |
36,593 | 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 |
36,594 | 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 | Get the set of names owned by a particular script - pubkey . |
36,595 | def get_num_names ( self , include_expired = False ) : cur = self . db . cursor ( ) return namedb_get_num_names ( cur , self . lastblock , include_expired = include_expired ) | Get the number of names that exist . |
36,596 | 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_expi... | Get the set of all registered names with optional pagination Returns the list of names . |
36,597 | 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 |
36,598 | 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 ... | Get the set of all registered names in a particular namespace . Returns the list of names . |
36,599 | 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 . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.