Skip to content

Commit

Permalink
Merge 7a95bd0 into 0e6fbfd
Browse files Browse the repository at this point in the history
  • Loading branch information
marctheshark3 authored Oct 8, 2024
2 parents 0e6fbfd + 7a95bd0 commit 8649b3a
Show file tree
Hide file tree
Showing 45 changed files with 22,213 additions and 1,521 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Ignore Jupyter Notebook checkpoint files
.log
.ipynb_checkpoints/
*flask_session
*_files/
Expand Down
6 changes: 4 additions & 2 deletions conf/conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ default_values:
url: 'https://api.ergo.aap.cornell.edu/api/v1/boxes/unspent/byAddress/'
token_ls: 'https://api.ergo.aap.cornell.edu/api/v1/tokens'
base_api: 'http://15.204.211.130:4000/api/pools/ErgoSigmanauts'
api: 'http://37.27.198.175:8000'
# api: 'http://37.27.198.175:8000'
# api: 'http://188.245.66.57:8000'
api: 'http://5.78.102.130:8000'
# api: 'http://localhost:8000'
db_name: 'localhost'
stats_cols: [
'fee NUMERIC', # Numeric type for precision
Expand Down Expand Up @@ -65,4 +67,4 @@ default_values:
'ttf NUMERIC', 'last_block_found VARCHAR(100)']

performance_headers: ['worker VARCHAR(250)', 'hashrate NUMERIC', 'shares_per_second NUMERIC',
'created TIMESTAMP', 'miner VARCHAR(250)', 'insert_time_stamp TIMESTAMP']
'created TIMESTAMP', 'miner VARCHAR(250)', 'insert_time_stamp TIMESTAMP']
27 changes: 25 additions & 2 deletions conf/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,36 @@ http {
server {
listen 80;
server_name ergominers.com;
return 301 https://$server_name$request_uri; # Redirect HTTP to HTTPS
}

server {
listen 443 ssl;
server_name ergominers.com;

ssl_certificate /etc/nginx/ssl/fullchain.pem; # Path to your SSL certificate
ssl_certificate_key /etc/nginx/ssl/privkey.pem; # Path to your SSL private key

# SSL settings (you may want to adjust these based on your security requirements)
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;

location / {
proxy_pass http://app:8050;
proxy_pass http://ui:8050;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}

server {
listen 80 default_server;
listen 443 ssl default_server;
server_name _;
ssl_certificate /etc/nginx/ssl/fullchain.pem; # Path to your SSL certificate
ssl_certificate_key /etc/nginx/ssl/privkey.pem; # Path to your SSL private key
return 444;
}
}
52 changes: 24 additions & 28 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,7 @@
version: '3.8'

services:
# database:
# image: postgres:latest
# environment:
# POSTGRES_DB: mining_db
# POSTGRES_USER: marctheshark
# POSTGRES_PASSWORD: password
# volumes:
# - mining_db:/var/lib/postgresql/data
# restart: unless-stopped
# ports:
# - "5431:5432"
# healthcheck:
# test: ["CMD-SHELL", "pg_isready -U marctheshark -d mining_db"]
# interval: 10s
# timeout: 5s
# retries: 5

app:
ui:
image: ghcr.io/marctheshark3/sigmanaut-mining-pool-ui:main
# environment:
# POSTGRES_DB: mining_db
# POSTGRES_USER: marctheshark
# POSTGRES_PASSWORD: password
# POSTGRES_HOST: database
# PGDATA: /data/postgres
build:
context: .
dockerfile: Dockerfile
Expand All @@ -34,7 +10,27 @@ services:
ports:
- "8050:8050"
restart: unless-stopped
# depends_on:
# database:
# condition: service_healthy

miner-id-minter:
build:
context: ./off-chain
dockerfile: Dockerfile
volumes:
- ./off-chain:/app
ports:
- "3000:3000"
restart: unless-stopped
depends_on:
- ui

nginx:
image: nginx:latest
ports:
- "80:80"
- "443:443" # Add HTTPS port
volumes:
- ./conf/nginx.conf:/etc/nginx/nginx.conf:ro
- ./ssl:/etc/nginx/ssl:ro # Add SSL certificates directory
depends_on:
- ui
restart: unless-stopped
70 changes: 60 additions & 10 deletions layouts/front_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from utils.shark_api import ApiReader
import pandas as pd
from utils.calculate import calculate_mining_effort, calculate_time_to_find_block


import uuid
import os
from utils.get_erg_prices import PriceReader

priceapi = PriceReader()
Expand Down Expand Up @@ -82,18 +82,41 @@ def create_row_card(image, h2_text, p_text):
html.P(p_text)]), style={'marginRight': 'auto', 'marginLeft': 'auto'}, width=4,)

def setup_front_page_callbacks(app, sharkapi):
@app.callback(
Output('link-container', 'children'),
Input('generate-url-button', 'n_clicks'),
)
# def generate_link(n_clicks):
# id = uuid.uuid4()
# custom_part = 'sigma-NFT-minter-{}'.format(id)
# custom_url = f'http://0.0.0.0:3000/{custom_part}'
# return html.A(html.Button('Mint NFT'), href=custom_url, target='_blank')

def generate_link(n_clicks):
id = uuid.uuid4()
custom_part = f'sigma-NFT-minter-{id}'

# Use environment variable or default to the production domain
base_url = os.environ.get('BASE_URL', 'http://dev.ergominers.com')
#base_url = os.environ.get('BASE_URL', 'http://188.245.66.57')



custom_url = f'{base_url}/miner-id-minter/{id}'
return html.A(html.Button('Mint NFT'), href=custom_url, target='_blank')

@app.callback([Output('metric-1', 'children')],
[Input('fp-int-4', 'n_intervals')])

def update_first_row(n):
data = sharkapi.get_pool_stats()

data['poolhashrate'] = round(data['poolhashrate'] / 1e9, 2)
data['hashrate'] = round(data['poolhashrate'] / 1e9, 2)
data['price'] = round(priceapi.get()[1], 3)
ergo = data['price'] #.item()
ergo = data['price']

n_miners = '{}'.format(data['connectedminers'])
hashrate = '{} GH/s'.format(data['poolhashrate'])
hashrate = '{} GH/s'.format(data['hashrate'])

row_1 = dbc.Row(justify='center', align='stretch',
children=[create_row_card('assets/boltz.png', hashrate, 'Pool Hashrate'),
Expand All @@ -110,17 +133,21 @@ def update_metrics(n):
data = sharkapi.get_pool_stats()
block_data = sharkapi.get_block_stats()
block_df = pd.DataFrame(block_data)
latest_block_time = max(block_df.created)
try:
latest_block_time = max(block_df.created)
data['pooleffort'] = calculate_mining_effort(data['networkdifficulty'], data['networkhashrate'],
data['poolhashrate'], latest_block_time)
except Exception:
data['pooleffort'] = 0


data['minimumpayment'] = 0.5
data['fee'] = 0.9
data['paid'] = sharkapi.get_payment_stats()
data['payoutscheme'] = 'PPLNS'
data['pooleffort'] = calculate_mining_effort(data['networkdifficulty'], data['networkhashrate'],
data['poolhashrate'], latest_block_time)

blocks_found = len(block_data)

blocks_found = len(block_df)
data['blocks'] = blocks_found

md = 4
Expand Down Expand Up @@ -359,7 +386,7 @@ def get_layout(sharkapi):
'width': '97.5%',
})
]),

html.Div(
[
html.Div(
Expand Down Expand Up @@ -433,6 +460,29 @@ def get_layout(sharkapi):
style_header=table_style,
style_data=table_style,),

# html.H1('MINER ID', style={'color': large_text_color, 'textAlign': 'center',}),
html.H1('Mint Miner Config NFT', style={'textAlign': 'center',}),
html.Div(id='generate-url-button'),
html.Div(id='link-container'),
dbc.Col(style={'padding': '10px'}, children=[
dbc.Card(style=bottom_row_style, children=[
dcc.Markdown('''
#### How it works - Reward Token Swap
1. Mint Miner ID NFT - Choose the ratio of tokens you would like to have as well as minimum payout
2. Once minted you will see your parameters in your mining dashboard
3. When your minimum payout is reached, price data is checked on ErgoDex to calculate how much of the token(s) you recieve based on the given tokens ratio in the miner ID.
#### Changing your miner ID
1. If you want to change your miner ID it is recommended to burn your current ID but is not necessary. Our system will check for the latest miner ID.
2. Mint the NFT as you have done so before.
### Dev Fees
There is a 3 ERG applied to mint the Miner ID token''')

]),]),




# html.H1('CONNECTING TO THE POOL',
# style={'color': 'white', 'textAlign': 'center', 'padding': '10px',}),
Expand Down
58 changes: 52 additions & 6 deletions layouts/mining_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from flask_login import LoginManager, UserMixin, login_user
from flask import Flask, request, session, redirect, url_for
from flask_session import Session

from utils.find_miner_id import ReadTokens
from utils.shark_api import ApiReader
from utils.get_erg_prices import PriceReader
from utils.calculate import calculate_mining_effort, calculate_time_to_find_block
Expand All @@ -35,6 +35,45 @@
}

def setup_mining_page_callbacks(app, sharkapi):

@app.callback([Output('s4', 'children'), Output('s5', 'children'), Output('s6', 'children'),],
[Input('mp-interval-7', 'n')],
[State('url', 'pathname')])

def update_miner_id(n, pathname):
print('GETTING IDs')
miner = unquote(pathname.lstrip('/'))
bins = [[] for _ in range(3)]
find_tokens = ReadTokens()
token = find_tokens.get_latest_miner_id(miner)
if token == None:
payout_text = 'Min Payout: 0.5 ERG'
min_payout = create_image_text_block(text=payout_text, image='min-payout.png')
ad_1_text = 'Consider minting a MINER ID'
ad_1 = create_image_text_block(text=ad_1_text, image='min-payout.png')
ad_2_text = 'Swap to ERG Native Tokens'
ad_2 = create_image_text_block(text=ad_2_text, image='min-payout.png')
return [min_payout, ad_1, ad_2]
miner_id = find_tokens.get_token_description(token['tokenId'])
print(miner_id)

payout_text = 'Minimum Payout: {}'.format(miner_id['minimumPayout'])
tokens = miner_id['tokens']
header = html.H1('Miner ID Parameters', style={'color': 'white', 'textAlign': 'center',})

tokens_swap = [create_image_text_block(text=payout_text, image='min-payout.png')]
for token in tokens:
temp_text = '{}: {}%'.format(token['token'], token['value'])
img = 'ergo.png'
tokens_swap.append(create_image_text_block(text=temp_text, image=img))


for i, func in enumerate(tokens_swap):
min_bin = min(bins, key=len)
min_bin.append(func)
print('COMPLETE')
return bins[0], bins[1], bins[2]

@app.callback([Output('mp-stats', 'children'),],
[Input('mp-interval-4', 'n')],
[State('url', 'pathname')])
Expand Down Expand Up @@ -115,7 +154,10 @@ def update_middle(n, pathname):
miner_data['pendingshares'] = 'TBD'
miner_data['price [$]'] = round(priceapi.get()[1], 3)
miner_data['schema'] = 'PPLNS'
miner_data['last_payment'] = miner_data['last_payment']['date'][:10]
try:
miner_data['last_payment'] = miner_data['last_payment']['date'][:10]
except Exception:
miner_data['last_payment'] = 'Keep Mining!'
miner_data['total_paid'] = round(miner_data['total_paid'], 3)

payment_images ={
Expand Down Expand Up @@ -178,7 +220,7 @@ def update_charts(n_intervals, chart, pathname):
for entry in data:
rows.append({
'worker': worker,
'created': datetime.fromisoformat(entry['created'].replace('Z', '+00:00')),
'created': datetime.fromisoformat(entry['timestamp'].replace('Z', '+00:00')),
'hashrate': entry['hashrate'] / 1e6,
'sharesPerSecond': entry['sharesPerSecond']
})
Expand All @@ -187,8 +229,6 @@ def update_charts(n_intervals, chart, pathname):
df = pd.DataFrame(rows)

df.sort_index(inplace=True)
# if not df:
# df = pd.DataFrame(columns=['created', 'hashrate', 'worker'])
try:
miner_performance_chart = px.line(df,
x='created',
Expand Down Expand Up @@ -324,14 +364,20 @@ def get_layout(sharkapi):
dcc.Interval(id='mp-interval-3', interval=60*1000*5, n_intervals=0),
dcc.Interval(id='mp-interval-4', interval=60*1000*5, n_intervals=0),
dcc.Interval(id='mp-interval-5', interval=60*1000*5, n_intervals=0),
dcc.Interval(id='mp-interval-7', interval=60*1000*5, n_intervals=0),

html.H1('ERGO Sigmanaut Mining Pool', style={'color': 'white', 'textAlign': 'center',}),
dbc.Row(id='mp-stats', justify='center',),
# dbc.Row(id='mp-metrics', justify='center', style={'padding': '20px'}),
dbc.Row(justify='center', style={'padding': '20px'}, children=[
dbc.Col(md=md, style={'padding': '7px'}, children=[dbc.Card(style=bottom_row_style, id='s1')],),
dbc.Col(md=md, style={'padding': '7px'}, children=[dbc.Card(style=bottom_row_style, id='s2')],),
dbc.Col(md=md, style={'padding': '7px'}, children=[dbc.Card(style=bottom_row_style, id='s3')],)]),
dbc.Col(md=md, style={'padding': '7px'}, children=[dbc.Card(style=bottom_row_style, id='s3')],),
dbc.Col(md=md, style={'padding': '7px'}, children=[dbc.Card(style=bottom_row_style, id='s4')],),
dbc.Col(md=md, style={'padding': '7px'}, children=[dbc.Card(style=bottom_row_style, id='s5')],),
dbc.Col(md=md, style={'padding': '7px'}, children=[dbc.Card(style=bottom_row_style, id='s6')],),

]),

dbc.Row(id='mp-banners', justify='center'),

Expand Down
23 changes: 23 additions & 0 deletions off-chain/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
Loading

0 comments on commit 8649b3a

Please sign in to comment.