From df5089370dc69ed348a7d3a718f92a9a06ccab72 Mon Sep 17 00:00:00 2001 From: Tom Dickman Date: Sun, 27 May 2018 13:00:47 -0400 Subject: [PATCH] Many updates --- .gitignore | 3 +- crypto51attack/app.py | 40 +++++++++++++++++++++++--- crypto51attack/libs/mtc.py | 15 +++++----- crypto51attack/libs/nicehash.py | 30 ++++++++++---------- crypto51attack/render.py | 8 ++++++ src/about.html | 40 ++++++++++++++++++++++++++ src/coin.html | 12 ++++---- src/index.html | 50 ++------------------------------- {dist => src}/style.css | 0 9 files changed, 116 insertions(+), 82 deletions(-) create mode 100644 src/about.html rename {dist => src}/style.css (100%) diff --git a/.gitignore b/.gitignore index 1c3e725..89ffaaa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ results.json -dist/index.html -dist/coins/*.html +dist/ .env diff --git a/crypto51attack/app.py b/crypto51attack/app.py index 8f6f0df..83edcab 100644 --- a/crypto51attack/app.py +++ b/crypto51attack/app.py @@ -5,16 +5,46 @@ from crypto51attack.libs.nicehash import NiceHash from crypto51attack.libs.cmc import CMC +def get_pretty_hash_rate(hash_rate): + """Convert the given hash rate to a pretty value.""" + if hash_rate > (1000.0 ** 5): + return '{:,.0f} PH/s'.format(hash_rate / (1000.0 ** 5)) + elif hash_rate > (1000.0 ** 4): + return '{:,.0f} TH/s'.format(hash_rate / (1000.0 ** 4)) + elif hash_rate > (1000.0 ** 3): + return '{:,.0f} GH/s'.format(hash_rate / (1000.0 ** 3)) + elif hash_rate > (1000.0 ** 2): + return '{:,.0f} MH/s'.format(hash_rate / (1000.0 ** 2)) + elif hash_rate > (1000.0 ** 1): + return '{:,.0f} KH/s'.format(hash_rate / (1000.0 ** 1)) + else: + return '{:,.0f} H/s'.format(hash_rate / (1000.0 ** 0)) + + +def get_pretty_money(value): + """Conver the number to a pretty dollar value with units.""" + if value > (1000.0 ** 4): + return '${:,.2f} T'.format(value / (1000.0 ** 4)) + elif value > (1000.0 ** 3): + return '${:,.2f} B'.format(value / (1000.0 ** 3)) + elif value > (1000.0 ** 2): + return '${:,.2f} M'.format(value / (1000.0 ** 2)) + elif value > (1000.0 ** 0): + return '${:,.0f}'.format(value) + + if __name__ == '__main__': mtc = MTC() nh = NiceHash() cmc = CMC() listings = cmc.get_listings() + btc_price = listings['BTC']['price'] results = [] for coin in mtc.get_coins(): details = mtc.get_details(coin['link']) cost = nh.get_cost_global(details['algorithm'], details['hash_rate']) nh_hash_percentage = nh.get_hash_percentage(details['algorithm'], details['hash_rate']) + nh_hash_percentage = int(nh_hash_percentage * 100.0) / 100.0 if nh_hash_percentage and nh_hash_percentage > 100 else nh_hash_percentage if cost: print(coin) print(details) @@ -29,15 +59,17 @@ if __name__ == '__main__': if not listing or data['name'] == 'Bitgem': continue - data['nicehash_capacity'] = nh.get_capacity(details['algorithm']) + data['nicehash_capacity'] = get_pretty_hash_rate(nh.get_capacity(details['algorithm'])) data['nicehash_algorithm_name'] = nh.get_algorithm_name(details['algorithm']) data['nicehash_units'] = nh.get_units(details['algorithm']) - data['nicehash_price'] = nh.get_algorithm_price(details['algorithm']) - data['hour_cost'] = '${:,.0f}'.format(cost * listings['BTC']['price'] / 24.0) + data['nicehash_price_btc'] = nh.get_algorithm_price(details['algorithm']) + data['nicehash_price_usd_hour'] = '{:,.2f}'.format(data['nicehash_price_btc'] * btc_price / 24.0) + data['hour_cost'] = '${:,.0f}'.format(cost * btc_price / 24.0) data['nicehash_hash_percentage'] = '{:,.0f}%'.format(nh_hash_percentage * 100.0) - data['market_cap'] = '${:,.0f}'.format(listing['market_cap']) if listing['market_cap'] else None + data['market_cap'] = get_pretty_money(listing['market_cap']) if listing['market_cap'] else '-' data['rank'] = listing['rank'] data['cmc_slug'] = listing['website_slug'] + data['hash_rate_pretty'] = get_pretty_hash_rate(details['hash_rate']) results.append(data) # Sort by rank diff --git a/crypto51attack/libs/mtc.py b/crypto51attack/libs/mtc.py index 2f7be30..289d061 100644 --- a/crypto51attack/libs/mtc.py +++ b/crypto51attack/libs/mtc.py @@ -15,28 +15,27 @@ class MTC: } return [] - def _get_gh_hash_rate(self, text): - """Convert the hash rate string to a gh/s hash rate.""" + def _get_h_hash_rate(self, text): + """Convert the hash rate string to a h/s hash rate.""" value, units = text.split(' ') value = float(value.replace(',', '')) if units == 'KH/s': - return value / 1000000.0 + return value * (1000.0 ** 1) elif units == 'MH/s': - return value / 1000.0 + return value * (1000.0 ** 2) elif units == 'GH/s': - return value + return value * (1000.0 ** 3) elif units == 'TH/s': - return value * 1000.0 + return value * (1000.0 ** 4) raise Exception('Unknown units: {}'.format(units)) def get_details(self, link): resp = self._session.get(link) html = resp.html hash_rate_pretty = html.find('.stats tr')[2].find('td', first=True).text - hash_rate = self._get_gh_hash_rate(hash_rate_pretty) + hash_rate = self._get_h_hash_rate(hash_rate_pretty) return { 'market_cap': html.find('.stats tr')[3].find('td', first=True).text, - 'hash_rate_pretty': hash_rate_pretty, 'hash_rate': hash_rate, 'algorithm': html.find('.text-primary strong a', first=True).text } diff --git a/crypto51attack/libs/nicehash.py b/crypto51attack/libs/nicehash.py index 8d601a7..8a7f115 100644 --- a/crypto51attack/libs/nicehash.py +++ b/crypto51attack/libs/nicehash.py @@ -80,19 +80,19 @@ class NiceHash: return None def _get_in_nicehash_units(self, algorithm, value): - """Use the buy info endpoint to convert the given value from gh to the specified units in nicehash.""" + """Use the buy info endpoint to convert the given value from h/s to the specified units in nicehash.""" index = self._get_algorithm_index(algorithm) units = self._buy_info['result']['algorithms'][index]['speed_text'] if units == 'PH': - return value / 1000000.0 + return value / (1000.0 ** 5) elif units == 'TH': - return value / 1000.0 + return value / (1000.0 ** 4) elif units == 'GH': - return value + return value / (1000.0 ** 3) elif units in ['MSol', 'MH']: - return value * 1000.0 + return value / (1000.0 ** 2) elif units == 'KH': - return value * 1000000.0 + return value / 1000.0 raise Exception('Unknown units: {}'.format(units)) def get_units(self, algorithm): @@ -124,7 +124,7 @@ class NiceHash: def get_algorithm_price(self, algorithm): """Get the hashing cost (BTC) + units. - Value is returned in BTC/UNITS/DAY. + Value is returned in BTC/H/DAY. """ index = self._get_algorithm_index(algorithm) if index is None: @@ -132,7 +132,7 @@ class NiceHash: pricing = float(self._global_stats['result']['stats'][index]['price']) return pricing - def get_cost_global(self, algorithm, hash_rate_ghs): + def get_cost_global(self, algorithm, hash_rate): """Return the global pricing for the specified algorithm. Speed in gh/s, and price in btc per gh/s per day. @@ -141,7 +141,7 @@ class NiceHash: if index is None: return None # Convert hash rate to the units used by NiceHash. - hash_rate = self._get_in_nicehash_units(algorithm, hash_rate_ghs) + hash_rate = self._get_in_nicehash_units(algorithm, hash_rate) pricing = float(self._global_stats['result']['stats'][index]['price']) print(algorithm, hash_rate, pricing, pricing * hash_rate) return pricing * hash_rate @@ -150,16 +150,16 @@ class NiceHash: index = self._get_algorithm_index(algorithm) if index is None: return None - nicehash_speed = float(self._global_stats['result']['stats'][index]['speed']) + # Convert from giga + nicehash_speed = float(self._global_stats['result']['stats'][index]['speed']) * (1000.0 ** 3) return nicehash_speed - def get_hash_percentage(self, algorithm, hash_rate_ghs): + def get_hash_percentage(self, algorithm, hash_rate): """Return the percent of the network hash rate the hash_rate_ghs represents.""" index = self._get_algorithm_index(algorithm) if index is None: return None - # Convert hash rate to the units used by NiceHash. - hash_rate = self._get_in_nicehash_units(algorithm, hash_rate_ghs) - nicehash_speed = float(self._global_stats['result']['stats'][index]['speed']) + # Convert from giga + nicehash_speed = float(self._global_stats['result']['stats'][index]['speed']) * (1000.0 ** 3) print(algorithm, nicehash_speed, hash_rate) - return nicehash_speed / hash_rate_ghs + return nicehash_speed / hash_rate diff --git a/crypto51attack/render.py b/crypto51attack/render.py index 34a5e4f..729c79d 100644 --- a/crypto51attack/render.py +++ b/crypto51attack/render.py @@ -3,6 +3,14 @@ from jinja2 import Template def render(results): + with open('src/style.css', 'r') as f: + with open('dist/style.css', 'w') as g: + g.write(f.read()) + + with open('src/about.html', 'r') as f: + with open('dist/about.html', 'w') as g: + g.write(f.read()) + with open('src/index.html', 'r') as f: template = Template(f.read()) with open('dist/index.html', 'w') as g: diff --git a/src/about.html b/src/about.html new file mode 100644 index 0000000..ec13d62 --- /dev/null +++ b/src/about.html @@ -0,0 +1,40 @@ + + + + + + + + + About | 51Crypto + + + + + + + + + + +
+
51crypto
+ +
+ +
+

Why?

+
+ +
+

Test

+
+ + + + + + diff --git a/src/coin.html b/src/coin.html index 82e5a5e..d83a3cc 100644 --- a/src/coin.html +++ b/src/coin.html @@ -6,17 +6,13 @@ - Cost of a 51% Attack for Different Cryptocurrencies + {{ coin.name }} ({{ coin.symbol }})| 51Crypto - - - - @@ -50,7 +46,11 @@ Nicehash cost - {{ coin.nicehash_price }} BTC/{{ coin.nicehash_units }}/day + {{ coin.nicehash_price_btc }} BTC / {{ coin.nicehash_units }} / day + + + Nicehash cost / hr + ${{ coin.nicehash_price_usd_hour }} / {{ coin.nicehash_units }} / hour Estimated cost of 1 hour 51% attack diff --git a/src/index.html b/src/index.html index 7dc5d17..b542d85 100644 --- a/src/index.html +++ b/src/index.html @@ -6,17 +6,13 @@ - Cost of a 51% Attack for Different Cryptocurrencies + Cost of a 51% Attack for Different Cryptocurrencies | 51Crypto - - - - @@ -29,15 +25,14 @@
-

Vulnerable PoW Coins

-

This is a collection of coins that are vulnerable to a 51% attack + the price to complete it.

+

PoW Coin Risk

+

This is a collection of coins along and the cost to perform a 51% attack on the network.

- @@ -50,7 +45,6 @@ {% for coin in results.coins %} - @@ -63,44 +57,6 @@ {% endfor %}
Rank Name Symbol Market Cap
{{ coin.rank }} {{ coin.name }} {{ coin.symbol }}
- -
diff --git a/dist/style.css b/src/style.css similarity index 100% rename from dist/style.css rename to src/style.css