Browse Source

Updated with coin specific pages

master
Tom Dickman 6 years ago
parent
commit
de8343e520
  1. 1
      .gitignore
  2. 6
      crypto51attack/app.py
  3. 30
      crypto51attack/libs/nicehash.py
  4. 6
      crypto51attack/render.py
  5. 76
      src/coin.html
  6. 20
      src/index.html

1
.gitignore

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

6
crypto51attack/app.py

@ -29,8 +29,12 @@ if __name__ == '__main__':
if not listing or data['name'] == 'Bitgem': if not listing or data['name'] == 'Bitgem':
continue continue
data['nicehash_capacity'] = 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['hour_cost'] = '${:,.0f}'.format(cost * listings['BTC']['price'] / 24.0)
data['nh_hash_percentage'] = '{:,.0f}%'.format(nh_hash_percentage * 100.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'] = '${:,.0f}'.format(listing['market_cap']) if listing['market_cap'] else None
data['rank'] = listing['rank'] data['rank'] = listing['rank']
data['cmc_slug'] = listing['website_slug'] data['cmc_slug'] = listing['website_slug']

30
crypto51attack/libs/nicehash.py

@ -95,6 +95,11 @@ class NiceHash:
return value * 1000000.0 return value * 1000000.0
raise Exception('Unknown units: {}'.format(units)) raise Exception('Unknown units: {}'.format(units))
def get_units(self, algorithm):
index = self._get_algorithm_index(algorithm)
units = self._buy_info['result']['algorithms'][index]['speed_text']
return units
def get_orders(self, algorithm): def get_orders(self, algorithm):
index = self._get_algorithm_index(algorithm) index = self._get_algorithm_index(algorithm)
if index is None: if index is None:
@ -102,8 +107,13 @@ class NiceHash:
resp = requests.get('https://api.nicehash.com/api?method=orders.get&location=1&algo={}'.format(index)) resp = requests.get('https://api.nicehash.com/api?method=orders.get&location=1&algo={}'.format(index))
return resp.json()['result']['orders'] return resp.json()['result']['orders']
def _get_algorithm_index(self, algorithm): def get_algorithm_name(self, algorithm):
"""Get the cleaned up algorithm name that nicehash uses."""
algorithm = algorithm.replace('-', '').replace('(', '').replace(')', '').replace(' ', '').lower() algorithm = algorithm.replace('-', '').replace('(', '').replace(')', '').replace(' ', '').lower()
return algorithm
def _get_algorithm_index(self, algorithm):
algorithm = self.get_algorithm_name(algorithm)
algorithm = remap_algorithms.get(algorithm, algorithm) algorithm = remap_algorithms.get(algorithm, algorithm)
try: try:
index = algorithms.index(algorithm) index = algorithms.index(algorithm)
@ -111,6 +121,17 @@ class NiceHash:
return None return None
return index return index
def get_algorithm_price(self, algorithm):
"""Get the hashing cost (BTC) + units.
Value is returned in BTC/UNITS/DAY.
"""
index = self._get_algorithm_index(algorithm)
if index is None:
return None
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_ghs):
"""Return the global pricing for the specified algorithm. """Return the global pricing for the specified algorithm.
@ -125,6 +146,13 @@ class NiceHash:
print(algorithm, hash_rate, pricing, pricing * hash_rate) print(algorithm, hash_rate, pricing, pricing * hash_rate)
return pricing * hash_rate return pricing * hash_rate
def get_capacity(self, algorithm):
index = self._get_algorithm_index(algorithm)
if index is None:
return None
nicehash_speed = float(self._global_stats['result']['stats'][index]['speed'])
return nicehash_speed
def get_hash_percentage(self, algorithm, hash_rate_ghs): def get_hash_percentage(self, algorithm, hash_rate_ghs):
"""Return the percent of the network hash rate the hash_rate_ghs represents.""" """Return the percent of the network hash rate the hash_rate_ghs represents."""
index = self._get_algorithm_index(algorithm) index = self._get_algorithm_index(algorithm)

6
crypto51attack/render.py

@ -8,6 +8,12 @@ def render(results):
with open('dist/index.html', 'w') as g: with open('dist/index.html', 'w') as g:
g.write(template.render(results={'coins': results})) g.write(template.render(results={'coins': results}))
with open('src/coin.html', 'r') as f:
template = Template(f.read())
for details in results:
with open('dist/coins/{}.html'.format(details['symbol']), 'w') as g:
g.write(template.render(coin=details))
if __name__ == '__main__': if __name__ == '__main__':
with open('results.json', 'r') as f: with open('results.json', 'r') as f:

76
src/coin.html

@ -0,0 +1,76 @@
<!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>Cost of a 51% Attack for Different Cryptocurrencies</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>
<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">{{ coin.name }} ({{ coin.symbol}})</h1>
<p class="lead">Cost for a 51% attack</p>
</div>
<div class="container">
<table class="table">
<tbody>
<tr>
<td>Market cap</td>
<td>{{ coin.market_cap }}</td>
</tr>
<tr>
<td>Mining algorithm</td>
<td>{{ coin.algorithm }}</td>
</tr>
<tr>
<td>Network hash rate</td>
<td>{{ coin.hash_rate_pretty }}</td>
</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>
</tr>
<tr>
<td>Estimated cost of 1 hour 51% attack</td>
<td>{{ coin.hour_cost }}</td>
</tr>
<tr>
<td>Nicehash capacity</td>
<td>{{ coin.nicehash_capacity }}</td>
</tr>
<tr>
<td>Nicehash percentage of network</td>
<td>{{ coin.nicehash_hash_percentage }}</td>
</tr>
</tbody>
</table>
</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>

20
src/index.html

@ -5,9 +5,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content=""> <meta name="description" content="">
<meta name="author" content=""> <meta name="author" content="">
<link rel="icon" href="../../../../favicon.ico">
<title>Cryptocurrencies that are Vulnerable to a 51% Attack</title> <title>Cost of a 51% Attack for Different Cryptocurrencies</title>
<!-- Bootstrap core CSS --> <!-- 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"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
@ -23,7 +22,7 @@
<body> <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"> <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">51crypto</h5> <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"> <nav class="my-2 my-md-0 mr-md-3">
<a class="p-2 text-dark" href="#">About</a> <a class="p-2 text-dark" href="#">About</a>
</nav> </nav>
@ -53,13 +52,13 @@
<tr> <tr>
<th scope="row">{{ coin.rank }}</th> <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="{{ coin.cmc_link }}"><i class="cc {{coin.symbol }}"></i> {{ coin.name }}</a></td> -->
<td><a href="https://www.coinmarketcap.com/currencies/{{ coin.cmc_slug }}">{{ coin.name }}</a></td> <td><a href="coins/{{ coin.symbol }}.html">{{ coin.name }}</a></td>
<td>{{ coin.symbol }}</td> <td>{{ coin.symbol }}</td>
<td>{{ coin.market_cap }}</td> <td>{{ coin.market_cap }}</td>
<td>{{ coin.algorithm }}</td> <td>{{ coin.algorithm }}</td>
<td>{{ coin.hash_rate_pretty }}</td> <td>{{ coin.hash_rate_pretty }}</td>
<td>{{ coin.hour_cost }}</td> <td>{{ coin.hour_cost }}</td>
<td>{{ coin.nh_hash_percentage }}</td> <td>{{ coin.nicehash_hash_percentage }}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
@ -109,16 +108,5 @@
================================================== --> ================================================== -->
<!-- Placed at the end of the document so the pages load faster --> <!-- 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> <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script>window.jQuery || document.write('<script src="../../../../assets/js/vendor/jquery-slim.min.js"><\/script>')</script>
<script src="../../../../assets/js/vendor/popper.min.js"></script>
<script src="../../../../dist/js/bootstrap.min.js"></script>
<script src="../../../../assets/js/vendor/holder.min.js"></script>
<script>
Holder.addTheme('thumb', {
bg: '#55595c',
fg: '#eceeef',
text: 'Thumbnail'
});
</script>
</body> </body>
</html> </html>

Loading…
Cancel
Save