Browse Source

Many updates

master
Tom Dickman 6 years ago
parent
commit
df5089370d
  1. 3
      .gitignore
  2. 40
      crypto51attack/app.py
  3. 15
      crypto51attack/libs/mtc.py
  4. 30
      crypto51attack/libs/nicehash.py
  5. 8
      crypto51attack/render.py
  6. 40
      src/about.html
  7. 12
      src/coin.html
  8. 50
      src/index.html
  9. 0
      src/style.css

3
.gitignore

@ -1,4 +1,3 @@
results.json
dist/index.html
dist/coins/*.html
dist/
.env

40
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

15
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
}

30
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

8
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:

40
src/about.html

@ -0,0 +1,40 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>About | 51Crypto</title>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<!-- Custom styles for this template -->
<link href="style.css" rel="stylesheet">
</head>
<body>
<div class="d-flex flex-column flex-md-row align-items-center p-3 px-md-4 mb-3 bg-white border-bottom box-shadow">
<h5 class="my-0 mr-md-auto font-weight-normal"><a href="/">51crypto</a></h5>
<nav class="my-2 my-md-0 mr-md-3">
<a class="p-2 text-dark" href="#">About</a>
</nav>
</div>
<div class="pricing-header px-3 py-3 pt-md-5 pb-md-4 mx-auto text-center">
<h1 class="display-4">Why?</h1>
</div>
<div class="container">
<p>Test</p>
</div>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
</body>
</html>

12
src/coin.html

@ -6,17 +6,13 @@
<meta name="description" content="">
<meta name="author" content="">
<title>Cost of a 51% Attack for Different Cryptocurrencies</title>
<title>{{ coin.name }} ({{ coin.symbol }})| 51Crypto </title>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<!-- Custom styles for this template -->
<link href="style.css" rel="stylesheet">
<!-- Coin icons -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/cryptocoins-icons@2.7.0/webfont/cryptocoins.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/cryptocoins-icons@2.7.0/webfont/cryptocoins-colors.css">
</head>
<body>
@ -50,7 +46,11 @@
</tr>
<tr>
<td>Nicehash cost</td>
<td><a target="_blank" href="https://www.nicehash.com/marketplace/{{ coin.nicehash_algorithm_name }}">{{ coin.nicehash_price }} BTC/{{ coin.nicehash_units }}/day</a></td>
<td><a target="_blank" href="https://www.nicehash.com/marketplace/{{ coin.nicehash_algorithm_name }}">{{ coin.nicehash_price_btc }} BTC / {{ coin.nicehash_units }} / day</a></td>
</tr>
<tr>
<td>Nicehash cost / hr</td>
<td>${{ coin.nicehash_price_usd_hour }} / {{ coin.nicehash_units }} / hour</td>
</tr>
<tr>
<td>Estimated cost of 1 hour 51% attack</td>

50
src/index.html

@ -6,17 +6,13 @@
<meta name="description" content="">
<meta name="author" content="">
<title>Cost of a 51% Attack for Different Cryptocurrencies</title>
<title>Cost of a 51% Attack for Different Cryptocurrencies | 51Crypto </title>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<!-- Custom styles for this template -->
<link href="style.css" rel="stylesheet">
<!-- Coin icons -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/cryptocoins-icons@2.7.0/webfont/cryptocoins.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/cryptocoins-icons@2.7.0/webfont/cryptocoins-colors.css">
</head>
<body>
@ -29,15 +25,14 @@
</div>
<div class="pricing-header px-3 py-3 pt-md-5 pb-md-4 mx-auto text-center">
<h1 class="display-4">Vulnerable PoW Coins</h1>
<p class="lead">This is a collection of coins that are vulnerable to a 51% attack + the price to complete it.</p>
<h1 class="display-4">PoW Coin Risk</h1>
<p class="lead">This is a collection of coins along and the cost to perform a 51% attack on the network.</p>
</div>
<div class="container">
<table class="table">
<thead>
<tr>
<th scope="col">Rank</th>
<th scope="col">Name</th>
<th scope="col">Symbol</th>
<th scope="col">Market Cap</th>
@ -50,7 +45,6 @@
<tbody>
{% for coin in results.coins %}
<tr>
<th scope="row">{{ coin.rank }}</th>
<!-- <td><a href="{{ coin.cmc_link }}"><i class="cc {{coin.symbol }}"></i> {{ coin.name }}</a></td> -->
<td><a href="coins/{{ coin.symbol }}.html">{{ coin.name }}</a></td>
<td>{{ coin.symbol }}</td>
@ -63,44 +57,6 @@
{% endfor %}
</tbody>
</table>
<footer class="pt-4 my-md-5 pt-md-5 border-top">
<div class="row">
<div class="col-12 col-md">
<img class="mb-2" src="https://getbootstrap.com/assets/brand/bootstrap-solid.svg" alt="" width="24" height="24">
<small class="d-block mb-3 text-muted">&copy; 2017-2018</small>
</div>
<div class="col-6 col-md">
<h5>Features</h5>
<ul class="list-unstyled text-small">
<li><a class="text-muted" href="#">Cool stuff</a></li>
<li><a class="text-muted" href="#">Random feature</a></li>
<li><a class="text-muted" href="#">Team feature</a></li>
<li><a class="text-muted" href="#">Stuff for developers</a></li>
<li><a class="text-muted" href="#">Another one</a></li>
<li><a class="text-muted" href="#">Last time</a></li>
</ul>
</div>
<div class="col-6 col-md">
<h5>Resources</h5>
<ul class="list-unstyled text-small">
<li><a class="text-muted" href="#">Resource</a></li>
<li><a class="text-muted" href="#">Resource name</a></li>
<li><a class="text-muted" href="#">Another resource</a></li>
<li><a class="text-muted" href="#">Final resource</a></li>
</ul>
</div>
<div class="col-6 col-md">
<h5>About</h5>
<ul class="list-unstyled text-small">
<li><a class="text-muted" href="#">Team</a></li>
<li><a class="text-muted" href="#">Locations</a></li>
<li><a class="text-muted" href="#">Privacy</a></li>
<li><a class="text-muted" href="#">Terms</a></li>
</ul>
</div>
</div>
</footer>
</div>

0
dist/style.css → src/style.css

Loading…
Cancel
Save