def __init__(self): self.logger = logging.getLogger('Env') self.logger.setLevel(logging.INFO) coin_name = self.default('COIN', 'Bitcoin') network = self.default('NETWORK', 'mainnet') self.coin = Coin.lookup_coin_class(coin_name, network) self.db_dir = self.required('DB_DIRECTORY') self.cache_MB = self.integer('CACHE_MB', 1000) self.hist_MB = self.integer('HIST_MB', 250) self.rpc_url = self.build_rpc_url()
def __init__(self): super().__init__() self.obsolete(['UTXO_MB', 'HIST_MB', 'NETWORK']) coin_name = self.default('COIN', 'Bitcoin') network = self.default('NET', 'mainnet') self.coin = Coin.lookup_coin_class(coin_name, network) self.db_dir = self.required('DB_DIRECTORY') self.cache_MB = self.integer('CACHE_MB', 1200) self.host = self.default('HOST', 'localhost') self.reorg_limit = self.integer('REORG_LIMIT', self.coin.REORG_LIMIT) self.daemon_url = self.required('DAEMON_URL') # Server stuff self.tcp_port = self.integer('TCP_PORT', None) self.ssl_port = self.integer('SSL_PORT', None) if self.ssl_port: self.ssl_certfile = self.required('SSL_CERTFILE') self.ssl_keyfile = self.required('SSL_KEYFILE') self.rpc_port = self.integer('RPC_PORT', 8000) self.max_subscriptions = self.integer('MAX_SUBSCRIPTIONS', 10000) self.banner_file = self.default('BANNER_FILE', None) self.anon_logs = self.default('ANON_LOGS', False) self.log_sessions = self.integer('LOG_SESSIONS', 3600) # The electrum client takes the empty string as unspecified self.donation_address = self.default('DONATION_ADDRESS', '') self.db_engine = self.default('DB_ENGINE', 'leveldb') # Server limits to help prevent DoS self.max_send = self.integer('MAX_SEND', 1000000) self.max_subs = self.integer('MAX_SUBS', 250000) self.max_sessions = self.integer('MAX_SESSIONS', 1000) self.max_session_subs = self.integer('MAX_SESSION_SUBS', 50000) self.bandwidth_limit = self.integer('BANDWIDTH_LIMIT', 2000000) self.session_timeout = self.integer('SESSION_TIMEOUT', 600) # IRC self.irc = self.default('IRC', False) self.irc_nick = self.default('IRC_NICK', None) self.identity = NetIdentity( self.default('REPORT_HOST', self.host), self.integer('REPORT_TCP_PORT', self.tcp_port) or None, self.integer('REPORT_SSL_PORT', self.ssl_port) or None, '') self.tor_identity = NetIdentity( self.default('REPORT_HOST_TOR', ''), # must be a string self.integer( 'REPORT_TCP_PORT_TOR', self.identity.tcp_port if self.identity.tcp_port else self.tcp_port) or None, self.integer( 'REPORT_SSL_PORT_TOR', self.identity.ssl_port if self.identity.ssl_port else self.ssl_port) or None, '_tor') if self.irc: if not self.identity.host.strip(): raise self.Error('IRC host is empty') if self.identity.tcp_port == self.identity.ssl_port: raise self.Error('IRC TCP and SSL ports are the same')
def __init__(self): super().__init__() self.obsolete(['UTXO_MB', 'HIST_MB', 'NETWORK']) self.allow_root = self.boolean('ALLOW_ROOT', False) self.db_dir = self.required('DB_DIRECTORY') self.daemon_url = self.required('DAEMON_URL') coin_name = self.required('COIN').strip() network = self.default('NET', 'mainnet').strip() self.coin = Coin.lookup_coin_class(coin_name, network) self.cache_MB = self.integer('CACHE_MB', 1200) self.host = self.default('HOST', 'localhost') self.reorg_limit = self.integer('REORG_LIMIT', self.coin.REORG_LIMIT) # Server stuff self.tcp_port = self.integer('TCP_PORT', None) self.ssl_port = self.integer('SSL_PORT', None) if self.ssl_port: self.ssl_certfile = self.required('SSL_CERTFILE') self.ssl_keyfile = self.required('SSL_KEYFILE') self.rpc_host = self.default('RPC_HOST', 'localhost') self.rpc_port = self.integer('RPC_PORT', 8000) self.max_subscriptions = self.integer('MAX_SUBSCRIPTIONS', 10000) self.banner_file = self.default('BANNER_FILE', None) self.tor_banner_file = self.default('TOR_BANNER_FILE', self.banner_file) self.anon_logs = self.boolean('ANON_LOGS', False) self.log_sessions = self.integer('LOG_SESSIONS', 3600) # Peer discovery self.peer_discovery = self.boolean('PEER_DISCOVERY', True) self.peer_announce = self.boolean('PEER_ANNOUNCE', True) self.force_proxy = self.boolean('FORCE_PROXY', False) self.tor_proxy_host = self.default('TOR_PROXY_HOST', 'localhost') self.tor_proxy_port = self.integer('TOR_PROXY_PORT', None) # The electrum client takes the empty string as unspecified self.donation_address = self.default('DONATION_ADDRESS', '') self.db_engine = self.default('DB_ENGINE', 'leveldb') # Server limits to help prevent DoS self.max_send = self.integer('MAX_SEND', 1000000) self.max_subs = self.integer('MAX_SUBS', 250000) self.max_sessions = self.sane_max_sessions() self.max_session_subs = self.integer('MAX_SESSION_SUBS', 50000) self.bandwidth_limit = self.integer('BANDWIDTH_LIMIT', 2000000) self.session_timeout = self.integer('SESSION_TIMEOUT', 600) self.loop_policy = self.event_loop_policy() # IRC self.irc = self.boolean('IRC', False) self.irc_nick = self.default('IRC_NICK', None) # Identities clearnet_identity = self.clearnet_identity() tor_identity = self.tor_identity(clearnet_identity) self.identities = [ identity for identity in (clearnet_identity, tor_identity) if identity is not None ]
def _from_extended_key(ekey): '''Return a PubKey or PrivKey from an extended key raw bytes.''' if not isinstance(ekey, (bytes, bytearray)): raise TypeError('extended key must be raw bytes') if len(ekey) != 78: raise ValueError('extended key must have length 78') is_public, coin = Coin.lookup_xverbytes(ekey[:4]) depth = ekey[4] fingerprint = ekey[5:9] # Not used n, = struct.unpack('>I', ekey[9:13]) chain_code = ekey[13:45] if is_public: pubkey = ekey[45:] key = PubKey(pubkey, chain_code, n, depth) else: if ekey[45] is not 0: raise ValueError('invalid extended private key prefix byte') privkey = ekey[46:] key = PrivKey(privkey, chain_code, n, depth) return key, coin
import pytest from lib.coins import Coin from lib.hash import hex_str_to_hash BLOCKS_DIR = os.path.join( os.path.dirname(os.path.realpath(__file__)), 'blocks') # Find out which db engines to test # Those that are not installed will be skipped blocks = [] for name in os.listdir(BLOCKS_DIR): try: name_parts = name.split("_") coin = Coin.lookup_coin_class(name_parts[0], name_parts[1]) with open(os.path.join(BLOCKS_DIR, name)) as f: blocks.append((coin, json.load(f))) except Exception as e: blocks.append(pytest.fail(name)) @pytest.fixture(params=blocks) def block_details(request): return request.param def test_block(block_details): coin, block_info = block_details block = unhexlify(block_info['block'])
def __init__(self): super().__init__() self.obsolete(['UTXO_MB', 'HIST_MB', 'NETWORK']) coin_name = self.default('COIN', 'Bitcoin') network = self.default('NET', 'mainnet') self.coin = Coin.lookup_coin_class(coin_name, network) self.db_dir = self.required('DB_DIRECTORY') self.cache_MB = self.integer('CACHE_MB', 1200) self.host = self.default('HOST', 'localhost') self.reorg_limit = self.integer('REORG_LIMIT', self.coin.REORG_LIMIT) self.daemon_url = self.required('DAEMON_URL') # Server stuff self.tcp_port = self.integer('TCP_PORT', None) self.ssl_port = self.integer('SSL_PORT', None) if self.ssl_port: self.ssl_certfile = self.required('SSL_CERTFILE') self.ssl_keyfile = self.required('SSL_KEYFILE') self.rpc_port = self.integer('RPC_PORT', 8000) self.max_subscriptions = self.integer('MAX_SUBSCRIPTIONS', 10000) self.banner_file = self.default('BANNER_FILE', None) self.tor_banner_file = self.default('TOR_BANNER_FILE', self.banner_file) self.anon_logs = self.default('ANON_LOGS', False) self.log_sessions = self.integer('LOG_SESSIONS', 3600) # Peer discovery self.peer_discovery = bool(self.default('PEER_DISCOVERY', True)) self.peer_announce = bool(self.default('PEER_ANNOUNCE', True)) self.tor_proxy_host = self.default('TOR_PROXY_HOST', 'localhost') self.tor_proxy_port = self.integer('TOR_PROXY_PORT', None) # The electrum client takes the empty string as unspecified self.donation_address = self.default('DONATION_ADDRESS', '') self.db_engine = self.default('DB_ENGINE', 'leveldb') # Server limits to help prevent DoS self.max_send = self.integer('MAX_SEND', 1000000) self.max_subs = self.integer('MAX_SUBS', 250000) self.max_sessions = self.sane_max_sessions() self.max_session_subs = self.integer('MAX_SESSION_SUBS', 50000) self.bandwidth_limit = self.integer('BANDWIDTH_LIMIT', 2000000) self.session_timeout = self.integer('SESSION_TIMEOUT', 600) # IRC self.irc = self.default('IRC', False) self.irc_nick = self.default('IRC_NICK', None) # Identities report_host = self.default('REPORT_HOST', self.host) self.check_report_host(report_host) main_identity = NetIdentity( report_host, self.integer('REPORT_TCP_PORT', self.tcp_port) or None, self.integer('REPORT_SSL_PORT', self.ssl_port) or None, '' ) if not main_identity.host.strip(): raise self.Error('REPORT_HOST host is empty') if main_identity.tcp_port == main_identity.ssl_port: raise self.Error('REPORT_TCP_PORT and REPORT_SSL_PORT are both {}' .format(main_identity.tcp_port)) self.identities = [main_identity] tor_host = self.default('REPORT_HOST_TOR', '') if tor_host.endswith('.onion'): self.identities.append(NetIdentity( tor_host, self.integer('REPORT_TCP_PORT_TOR', main_identity.tcp_port if main_identity.tcp_port else self.tcp_port) or None, self.integer('REPORT_SSL_PORT_TOR', main_identity.ssl_port if main_identity.ssl_port else self.ssl_port) or None, '_tor', ))
def __init__(self): super().__init__() self.obsolete(['UTXO_MB', 'HIST_MB', 'NETWORK']) #检查环境变量(?过时) self.db_dir = self.required('DB_DIRECTORY') #获取DB_DIRECTORY环境变量 self.db_engine = self.default( 'DB_ENGINE', 'leveldb') #获取DB_DIRECTORY环境变量,如果‘DB_ENGINE’不存在就返回默认的‘leveldb’ self.daemon_url = self.required('DAEMON_URL') coin_name = self.required( 'COIN').strip() #获取环境变量COIN,调用字符串方法strip去除首尾的空格 network = self.default('NET', 'mainnet').strip() self.coin = Coin.lookup_coin_class( coin_name, network ) #返回类似 -》 {'NAME':coin_name,'NET':network,'TX_COUNT':'','TX_COUNT_HEIGHT':'','TX_PER_BLOCK':'',REORG_LIMIT:''} self.cache_MB = self.integer( 'CACHE_MB', 1200) #获取CACHE_MB环境变量,如果‘CACHE_MB’不存在就返回默认的‘1200’[是一个整型] self.host = self.default('HOST', 'localhost') self.reorg_limit = self.integer('REORG_LIMIT', self.coin.REORG_LIMIT) # Server stuff self.tcp_port = self.integer('TCP_PORT', None) self.ssl_port = self.integer('SSL_PORT', None) if self.ssl_port: self.ssl_certfile = self.required('SSL_CERTFILE') self.ssl_keyfile = self.required('SSL_KEYFILE') self.rpc_port = self.integer('RPC_PORT', 8000) self.max_subscriptions = self.integer('MAX_SUBSCRIPTIONS', 10000) self.banner_file = self.default('BANNER_FILE', None) self.tor_banner_file = self.default('TOR_BANNER_FILE', self.banner_file) self.anon_logs = self.boolean('ANON_LOGS', False) #获取系统是否存在环境变量‘ANON_LOGS’【boolean】 self.log_sessions = self.integer( 'LOG_SESSIONS', 3600) #获取系统是否存在环境变量‘ANON_LOGS’【boolean -> true】 # Peer discovery self.peer_discovery = self.peer_discovery_enum( ) #返回环境变量PEER_DISCOVERY的状态,默认返回2 self.peer_announce = self.boolean('PEER_ANNOUNCE', True) self.force_proxy = self.boolean('FORCE_PROXY', False) self.tor_proxy_host = self.default('TOR_PROXY_HOST', 'localhost') self.tor_proxy_port = self.integer('TOR_PROXY_PORT', None) # The electrum client takes the empty string as unspecified self.donation_address = self.default('DONATION_ADDRESS', '') # Server limits to help prevent DoS self.max_send = self.integer('MAX_SEND', 1000000) self.max_subs = self.integer('MAX_SUBS', 250000) self.max_sessions = self.sane_max_sessions( ) #返回获取环境变量MAX_SESSIONS的值,获取Python(库)配置文件中nofile_limit的值(-350);返回二者最小值【或者0】。 self.max_session_subs = self.integer('MAX_SESSION_SUBS', 50000) self.bandwidth_limit = self.integer('BANDWIDTH_LIMIT', 2000000) self.session_timeout = self.integer('SESSION_TIMEOUT', 600) self.drop_client = self.custom( "DROP_CLIENT", None, re.compile ) # 如果环境变量DROP_CLIENT不存在,就返回None,否则返回re.compile(os.environ.get('DROP_CLIENT'))[是一个正则] # Identities clearnet_identity = self.clearnet_identity( ) #返回NetIdentity(host=host, tcp_port=tcp_port, ssl_port=ssl_port, nick_suffix='') -> 类 tor_identity = self.tor_identity( clearnet_identity ) #返回NetIdentity(host=host, tcp_port=tcp_port, ssl_port=ssl_port, nick_suffix='_tor') -> 类 self.identities = [ identity for identity in (clearnet_identity, tor_identity) if identity is not None ] #两个类(class1[clearnet_identity],class2[tor_identity])