Hivepool project introdunction

in #utopian-io6 years ago

Repository

https://github.com/sau412/coinhive_pool

Project details

What is the project about?

This project is a cryptocurrency mining pool based on coinhive embeddable web miner. It is non-profit project, all mined coins are exchanged with actual exchange rates and sent to users in selected coin. All fees is used as transaction fees.

Coinhive miner is embeddable web miner that mines monero in browser. It written in javascript (not by me). I think it was created as form of monetization of popular resources. Also it can be used directy for mining at will. But sometimes it used with malicious intent. That's why it blocked by adblock.

Cryptocurrency mining pools are required when average user cannot reach goal alone. For coinhive there are two goals exists.

First goal is 0.02 monero. After that goal you can receive mined amount minus fee (0.005 monero). Everithing below that limit cannot be payed out. Average PC can do 50 hashes per second.

Calculations:
500 000 000 hashes / 50 hashes per second = 10 000 000 seconds
10 000 000 seconds = 116 days

Second goal is 0.5 monero. When you reach that goal you can receive all your mined without fee. You cannot receive full amount when goal is not reached.

Currently second goal requires to mine 12 billion hashes. It takes more than 7 years with 50 H/s:

Calculations:
12 000 000 000 hashes / 50 hashes per second = 240 000 000 seconds
240 000 000 seconds = 2 778 days
2 778 days = 7.61 years

Pool unites mining power under one coinhive account and provide possibility to reach smaller goal to users. Currently user can receive any amount above pool's payout fee. That fee is transaction fee and it depends on currency. Lowest transaction fee is for nano and banano, basically zero. Bitcoin has biggest transaction fee. I think user cannot reach that amount (but if you do, I'll send you some). Bitcoin added in coin list just for reference.

Summary: project allows to mine and withdraw any amount of currency above currency transaction cost.

Features

  • Calculates user contribution in several coins
  • Payments can be sent automatically (implemended with cryptocurrencies gridcoin, tron and burstcoin)
  • Send emails to admin on withdraw
  • User and admin web interface
  • Monitoring in cacti
  • Bonuses for users (can be added directly in MySQL table now)
  • Archievements - color badges with milestones information

Technology Stack

PHP

Project written in PHP. Test server has PHP 7 while hosting server has PHP 5. Thus project is tested and works with PHP 5 and 7.

Project structure:

  • index.php (link) - entry point for all users. See user interface section below

Libraries:

  • coinhive.php (link) - coinhive API
  • core.php (link) - core functions: balance management, users management, logging
  • db.php (link) - database API (see MySQL secion)
  • email.php (link) - email API (see email section)
  • html.php (link) - HTML-returning functions
  • settings.php (link) - project variables, should be set once (public and private keys, DB credentials, rates and limits)
  • style.css (link) - CSS styles

Tasks (run every hour):

  • send_email.php (link) - send emails from queue
  • update_coinhive_data.php (link) - updates users data in database
  • update_rates.php (link) - updates currency rates in database

Tasks for sending rewards:

  • send_rewards_burst.php (link) - send rewards in burstcoin currency with their API
  • send_rewards_core_wallet.php (link) - send rewards in currency with bitcoin-like API
  • send_rewards_tron.php (link) - send rewards in tron currency with their API

Data for cacti:

  • cacti_data_coinhive.php (link) - provide actual coinhive data for cacti, see cacti section below
  • cacti_data_users.php (link) - provide actual user data for cacti, see cacti section below
MySQL

Project uses MySQL as data storage. All states (balances, logins, payouts) are stored in database. Except for API keys and database credential of course.
MySQL API implemended in library: (link)
Tables described too: (link)

Tables overview:

  • currency - currencies information: symbol, name, API link, image link, exchange rates.
  • email - email sending queue. Admin can see all emails sent by project.
  • log - project log: new users, log in, log out, payments, errors.
  • payouts - payouts data. Currency, amount of that currency, hashes, fees, transaction id.
  • sessions - session data. Each visitor has record here
  • users - user data: login, password, balance data (mined, withdrawn, bonuses), admin flags, timestamps
  • variables - currently contains only price of 1 million hashes from coinhive
Coinhive API

Project uses coinhive API for getting users contribution (hashes amount). Then it used for calculating user rewards.
Coinhive API implemended in library: (link)

Main functions:

  • coinhive_get_user_balance_detail - return detailed information about user balance
  • coinhive_get_user_balance - return only total hashes amount
  • coinhive_reset_user_balance - reset user balance to zero. Currently not used.
  • coinhive_get_payout_info - get payout info. Used in task update_coinhive_data.php
Coingecko API

Coingecko is data collector for cryptocurrency with decent API. For my project I use only small amount of data: actual prices and images.

All interaction implemended in task: (link)

Email API

Project uses smtp2go when sending emails. All email API implemended in one function 'email_send' in email library (link)
Other functions are used as single entry-point to email sending.

Cryptocurrency API: Bitcoin and forks

Many cryptocurrencies forked from bitcoin and has similar API. That API is implemended in send_rewards_core_wallet.php (link)

Easy interface: unlock wallet, send transaction to address, lock wallet.

Functions:

  • wallet_rpc_send_query - send query to wallet
  • wallet_rpc_get_balance - get wallet balance
  • wallet_rpc_unlock_wallet - unlocks wallet with password if wallet uses encryption
  • wallet_rpc_lock_wallet - lock wallet
  • wallet_rpc_validate_address - checks is addresss correct
  • wallet_rpc_send - sends specified amount to specified address

Only difference is coin name.

Cryptocurrency API: Burst and forks of NXT

Burstcoin is forked from coin called NXT. Both has similar API interface. Implemended in send_rewards_burst.php (link)

Burstcoin sending is more complex than bitcoin. You also should check current TX fee and send transaction with specified fee.

Functions here:

  • wallet_rpc_send_query - send query to wallet
  • wallet_rpc_get_balance - get wallet balance
  • wallet_rpc_validate_address - check if address correct. Not used, because new addresses cannot be checked in that way
  • wallet_rpc_send - same as above, sends specified amount to specified address
  • wallet_get_fee - get network fee
    Main difference from previous API: no locking and unlocking (because private key is used)
Cryptocurrency API: Tron

Tron has different API. Tron's transactions is a form of smart-contract. Implemended in send_rewards_tron.php (link)

You should convert addresses to hex, create transaction, sign it with private key, then broadcast.

Functions:

  • base_58_decode - encode address in hex format, because API requires hex format
  • wallet_rpc_send_query - send query to wallet
  • wallet_rpc_validate_address - address validation
  • wallet_rpc_get_balance - get balance
  • wallet_rpc_send - create transaction, sign it, then broadcast
    Also no locking and unlocking. But sending function is more complex.
Cacti monitoring API

Cacti is complete RRDTool-based graphing solution.

Project can be monitored with cacti. There are two files providing actual information to cacti:

  • cacti_data_users.php (link)
  • cacti_data_coinhive.php(link)

As result you can see pool stats in cacti:

These files also available from web, you can add them to your cacti if you have one:

User interface

User interface is visible for all. Currently interface has three screens.

First is page for visitors with project information:

You can register or log in here. If user record not exists, new user created.

Second is page for registered user:

Here you can see your result in each supported coin.

Third page is withdrawing page:

You can write your address here and press withdraw.

Admin interface

Admin interface is visible for user with admin flag in table 'users'. Administrator see two buttons: user mode and admin mode:

In admin mode admin can see active users (active in last hour are green, active in last day are white):

Pending withdrawals and sent payments:

If coin has no automatization, it can be sent in manual mode. Administrator (me) sent specified amount to user address and fill transaction ID as evidence.

Log section, all user actions visible here:

Development history

Project was started as extension of gridcoin reverse pool (my publication). On that page you can mine with coinhive and receive rewards in one cryptocurrency - gridcoin.

Then I did first prototype, it collects exchange data from poloniex (cryptocurrency exchanger) and show all results in one table (my publication). That page wasn't saved.

When first users appeared and asked me for new design I did current version and decided to do it as open-source project (link).

Roadmap

I'm thinking about next features:

  • Automated payments for nano and banano (banano is used by users, nano has similar API).
  • Other non-automated currencies is almost not used, but automatization needed too.
  • Project stats page: financial info and information about whole pool.
  • Transaction checking - sometimes transactions are rejected by network. Transaction status checker should be implemented.
  • News page or just news string - for notifying users about updates.
  • Feedback page
  • User control page, where admin can add bonuses or change user statuses.

How to contribute

There are several things, that I struggle with:

  • Pretty design. Favicon, logo, web-interface design. Changes can be done in html.php and style.css files.
  • Direct pool miner (instead of coinhive miner). Changes can be done in coinhive.php and html.php
  • If you know resource with sending API and low fees. You can add send_rewards_[your_coin].php to project.

Project links

Other links

GitHub Account

My github account: https://github.com/sau412

Sort:  

Thank you for your contribution. A really cool project, and also very nicely explained. How do you increase you hashes if you have newly registered, does it run in the background, if yes then it would be better to show something to the user.


Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

How do you increase you hashes if you have newly registered

Not sure I'm fully understanding question, I'll try to reply to all interpretations:

  1. How new user affects pool mining speed?
    Currently 73 users exists, 48 tried to mine at least once. Only eight users were active in last 24 hours, daily average pool speed was 150 H/s. So average active user speed is about 20 H/s.

  2. What if new user want more hashes?
    Currently only one way exists, mine more hashes with coinhive script. Also mining can be done on tablets and phones, but be careful. Mining produces heat, heat can damage your phone or tablets.
    Also I can add bonus hashes when a user is facing a problem due to my fault. That was once currently, when burstcoin transaction was lost.

does it run in the background

Mining begins only after pressing the button on the miner. No background mining, but user can leave mining in background tab after beginning.

Mining with mining link also requires pressing button to start.

Thank you for your review, @codingdefined! Keep up the good work!

Hi @sau412!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Hey, @sau412!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Coin Marketplace

STEEM 0.18
TRX 0.13
JST 0.028
BTC 58080.30
ETH 3102.16
USDT 1.00
SBD 2.40