def replay_attack(request, fork_coin=None, block_to_replay=None): if request.method == 'POST': errors, response_dict = _cached_fetch( "get_block", "fallback", currency=fork_coin, block_args={'block_number': block_to_replay}, random_mode=True) block = response_dict['block'] def block_fetcher(currency, txid): errors, response_dict = _cached_fetch("single_transaction", "fallback", currency=currency, txid=txid, random_mode=True) return response_dict['transaction'] results = [] for r in replay_block(fork_coin, block, verbose=False, block_fetcher=block_fetcher, limit=3): print(r) results.append(r) return http.JsonResponse({'results': results}) first_pass = [[x, d['forked_from']] for x, d in crypto_data.items() if 'forked_from' in d] attack_candidates = [["%s ⇆ %s" % (x[0], x[1][0]), x[1][1]] for x in first_pass] return TemplateResponse(request, "replay_attack.html", locals())
def get_wallet_currencies(): """ Returns currencies that have full wallet functionalities. This includes push_tx, a service for getting unspent outputs, and a registered BIP44 coin type. """ ret = [] for currency, data in crypto_data.items(): if not hasattr(data, 'get'): continue bip44 = data.get('bip44_coin_type', None) address_byte = data.get('address_version_byte', None) priv_byte = data.get('private_key_prefix', None) services = data.get('services', {}) pushtx = services.get("push_tx", []) unspent = services.get("unspent_outputs", []) sc = settings.WALLET_SUPPORTED_CRYPTOS ignored = currency.lower() in settings.IGNORE_WALLET_CRYPTOS is_supported = (not ignored) and ((not sc) or (currency.lower() in sc)) if pushtx and unspent and bip44 and priv_byte and is_supported: ret.append({ 'code': currency, 'name': data['name'], 'bip44': bip44, 'private_key_prefix': priv_byte, 'address_byte': address_byte, 'logo': "logos/%s-logo_100x100.png" % currency, }) return ret
def make_crypto_data_json(): """ Go through all supported cryptocurrencies in moneywagon, and make a json encoded object containing all the supported services and magic bytes. """ ret = {} for currency, data in crypto_data.items(): ret[currency] = {} if not hasattr(data, 'get') or not currency: del ret[currency] continue ret[currency]['address_version_byte'] = data.get('address_version_byte', None) for mode in service_modes: services = data.get('services', {}).get(mode, []) if not services: continue if mode == 'current_price': ret[currency][mode] = list(set( [item.service_id for sublist in services.values() for item in sublist] )) else: ret[currency][mode] = [s.service_id for s in services] if not ret[currency]: # no services defined del ret[currency] return json.dumps(ret)
def get_watch_only_currencies(): """ Returns currencies that have balance and price services, and have bip44 sequence defined. """ fully_supported = [x['code'] for x in get_wallet_currencies()] ret = [] for currency, data in crypto_data.items(): if not hasattr(data, 'get'): continue bip44 = data.get('bip44_coin_type', None) address_byte = data.get('address_version_byte', None) priv_byte = data.get('private_key_prefix', None) services = data.get('services', {}) balance = services.get("address_balance", []) price = services.get("current_price", []) if price and balance and bip44 and priv_byte and currency not in fully_supported: ret.append({ 'code': currency, 'name': data['name'], 'bip44': bip44, 'private_key_prefix': priv_byte, 'address_byte': address_byte, 'logo': "logos/%s-logo_100x100.png" % currency, }) return ret
def replay_attack(request, fork_coin=None, block_to_replay=None): if request.method == 'POST': errors, response_dict = _cached_fetch( "get_block", "fallback", currency=fork_coin, block_args={'block_number': block_to_replay}, random_mode=True ) block = response_dict['block'] def block_fetcher(currency, txid): errors, response_dict = _cached_fetch( "single_transaction", "fallback", currency=currency, txid=txid, random_mode=True ) return response_dict['transaction'] results = [] for r in replay_block(fork_coin, block, verbose=False, block_fetcher=block_fetcher, limit=3): print(r) results.append(r) return http.JsonResponse({'results': results}) first_pass = [[x, d['forked_from']] for x,d in crypto_data.items() if 'forked_from' in d] attack_candidates = [["%s ⇆ %s" % (x[0], x[1][0]), x[1][1]] for x in first_pass] return TemplateResponse(request, "replay_attack.html", locals())
def _get_all_services(crypto=None): """ Go through the crypto_data structure and return all list of all (unique) installed services. Optionally filter by crypto-currency. """ from moneywagon.crypto_data import crypto_data if not crypto: # no currency specified, get all services to_iterate = crypto_data.items() else: # limit to one currency to_iterate = [(crypto, crypto_data[crypto])] services = [] for currency, data in to_iterate: if 'services' not in data: continue if currency == '': continue # template # price services are defined as dictionaries, all other services # are defined as a list. price_services = data['services']['current_price'] del data['services']['current_price'] all_services = list(data['services'].values()) + list( price_services.values()) data['services']['current_price'] = price_services services.append([item for sublist in all_services for item in sublist]) return sorted(set([item for sublist in services for item in sublist]), key=lambda x: x.__name__)
def get_block_currencies(): """ Returns currencies that have block info services defined. """ ret = [] for currency, data in crypto_data.items(): if hasattr(data, 'get') and data.get('services', {}).get("get_block", []): ret.append({'code': currency, 'name': data['name']}) return ret
def get_balance_currencies(): """ Returns currencies that have address balance services defined. """ ret = [] for currency, data in crypto_data.items(): if hasattr(data, 'get') and data.get('services', {}).get("address_balance", []): ret.append({ 'code': currency, 'name': data['name'], 'logo': "logos/%s-logo_100x100.png" % currency, }) return ret
def get_block_currencies(): """ Returns a list of all curencies (by code) that have a service defined that implements `get_block`. """ return ['btc', 'ltc', 'ppc', 'dash', 'doge', 'ric'] currencies = [] for currency, data in crypto_data.items(): if type(data) is list: continue block_services = data.get('services', {}).get('get_block', []) if len(block_services) > 0 and not all([x.get_block.by_latest for x in block_services]): currencies.append(currency) return currencies
def get_currency_by_order(order): #print("getting currency for order: %s" % order) bip44 = order + 0x80000000 for currency, data in crypto_data.items(): if data['bip44_coin_type'] == bip44: #print("found %s" % currency) return currency try: #print("not a moneywagon currency, crawling slip44") coins = crawl_SLIP44() for currency, data in coins.items(): if data[0] == order: #print("found %s at order %s" % (currency, order)) return currency except: pass raise CurrencyNotSupported("Currency order %s not found" % order)
def get_paper_wallet_currencies(): ret = [] for currency, data in crypto_data.items(): if not hasattr(data, 'get'): continue address_byte = data.get('address_version_byte', None) priv_byte = data.get('private_key_prefix', None) addr_enc = data.get('address_encoding', None) if address_byte is not None and priv_byte is not None and addr_enc in ['base58', None]: ret.append({ 'code': currency, 'name': data['name'], 'private_key_prefix': priv_byte, 'address_byte': address_byte, 'logo': "logos/%s-logo_100x100.png" % currency, }) return ret
def _get_all_services(crypto=None, just_exchange=False): """ Go through the crypto_data structure and return all list of all (unique) installed services. Optionally filter by crypto-currency. """ from moneywagon.crypto_data import crypto_data if not crypto: # no currency specified, get all services to_iterate = crypto_data.items() else: # limit to one currency to_iterate = [(crypto, crypto_data[crypto])] services = [] for currency, data in to_iterate: if 'services' not in data: continue if currency == '': continue # template # price services are defined as dictionaries, all other services # are defined as a list. price_services = data['services']['current_price'] del data['services']['current_price'] all_services = list(price_services.values()) if not just_exchange: all_services += list(data['services'].values()) # replace data['services']['current_price'] = price_services services.append([ item for sublist in all_services for item in sublist ]) return sorted( set([item for sublist in services for item in sublist]), key=lambda x: x.__name__ )
def needs_bip44(): """ Lists all currencies that have full wallet support from moneywagon, but have no defined BIP44 sequence. """ ret = [] for currency, data in crypto_data.items(): if not hasattr(data, 'get'): continue bip44 = data['bip44_coin_type'] address_byte = data['address_version_byte'] priv_byte = data['private_key_prefix'] services = data.get('services', {}) pushtx = services.get("push_tx", []) unspent = services.get("unspent_outputs", []) if pushtx and unspent and not bip44 and priv_byte: ret.append(currency) return ret
def get_wallet_currencies(): """ Returns currencies that have full wallet functionalities. This includes push_tx, a service for getting unspent outputs, and a registered BIP44 coin type. """ ret = [] for currency, data in crypto_data.items(): if not hasattr(data, 'get'): continue bip44 = data.get('bip44_coin_type', None) address_byte = data.get('address_version_byte', None) priv_byte = data.get('private_key_prefix', None) script_hash_byte = data.get('script_hash_byte', None) services = data.get('services', {}) pushtx = services.get("push_tx", []) unspent = services.get("unspent_outputs", []) hist = services.get("historical_transactions", []) price = services.get("current_price", []) sc = settings.WALLET_SUPPORTED_CRYPTOS ignored = currency.lower() in settings.IGNORE_WALLET_CRYPTOS is_supported = (not ignored) and ((not sc) or (currency.lower() in sc)) if hist and pushtx and price and unspent and bip44 and priv_byte and is_supported: ret.append({ 'code': currency, 'name': data['name'], 'bip44': bip44, 'private_key_prefix': priv_byte, 'address_byte': address_byte, 'script_hash_byte': script_hash_byte, 'logo': "logos/%s-logo_100x100.png" % currency, }) return ret
def sorted_crypto_data(self): return sorted(crypto_data.items(), key=lambda x: x[1]['name'])
def get_currency_by_order(order): bip44 = order + 0x80000000 for currency, data in crypto_data.items(): if data['bip44_coin_type'] == bip44: return currency raise Exception("Currency order %s not found" % order)