diff --git a/sql/2016-02-18-accounts_donation.sql b/sql/2016-02-18-accounts_donation.sql new file mode 100644 index 0000000..81b8ecd --- /dev/null +++ b/sql/2016-02-18-accounts_donation.sql @@ -0,0 +1,4 @@ +-- Recent additions to add after db init (.gz) +-- mysql yaamp -p < file.sql + +ALTER TABLE `accounts` ADD `donation` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER `no_fees`; diff --git a/stratum/client.h b/stratum/client.h index 15d3b31..5ef28a5 100644 --- a/stratum/client.h +++ b/stratum/client.h @@ -90,6 +90,8 @@ public: YAAMP_CLIENT_ALGO algos_subscribed[YAAMP_MAXALGOS]; int job_history[YAAMP_JOB_MAXHISTORY]; + + int donation; }; inline void client_delete(YAAMP_OBJECT *object) diff --git a/stratum/user.cpp b/stratum/user.cpp index e173ce6..6a00239 100644 --- a/stratum/user.cpp +++ b/stratum/user.cpp @@ -24,12 +24,20 @@ void db_add_user(YAAMP_DB *db, YAAMP_CLIENT *client) if(!p) p = strstr(client->password, "s="); if(p) strncpy(symbol, p+2, 15); p = strchr(symbol, ','); - if(p) *p = 0; + if(p) *p = '\0'; + + int gift = -1; +#ifdef ALLOW_CUSTOM_DONATIONS + // donation percent + p = strstr(client->password, "g="); + if(p) gift = atoi(p+2); + if(gift > 100) gift = 100; +#endif db_check_user_input(client->username); -// debuglog("user %s %s\n", client->username, symbol); - db_query(db, "SELECT id, is_locked, logtraffic, coinid FROM accounts WHERE username='%s'", client->username); + // debuglog("user %s %s gives %d %\n", client->username, symbol, gift); + db_query(db, "SELECT id, is_locked, logtraffic, coinid, donation FROM accounts WHERE username='%s'", client->username); MYSQL_RES *result = mysql_store_result(&db->mysql); if(!result) return; @@ -42,23 +50,28 @@ void db_add_user(YAAMP_DB *db, YAAMP_CLIENT *client) client->logtraffic = row[2] && atoi(row[2]); client->coinid = row[3] ? atoi(row[3]) : 0; + if (gift == -1) gift = row[4] ? atoi(row[4]) : 0; // keep current } mysql_free_result(result); db_check_user_input(symbol); + if (gift < 0) gift = 0; + client->donation = gift; + if(client->userid == -1) return; else if(client->userid == 0) { - db_query(db, "INSERT INTO accounts (username, coinsymbol, balance) values ('%s', '%s', 0)", client->username, symbol); + db_query(db, "INSERT INTO accounts (username, coinsymbol, balance, donation) values ('%s', '%s', 0, %d)", + client->username, symbol, gift); client->userid = (int)mysql_insert_id(&db->mysql); } else - db_query(db, "UPDATE accounts SET coinsymbol='%s' WHERE id=%d", symbol, client->userid); + db_query(db, "UPDATE accounts SET coinsymbol='%s', donation=%d WHERE id=%d", symbol, gift, client->userid); } ////////////////////////////////////////////////////////////////////////////////////// diff --git a/web/yaamp/core/backend/blocks.php b/web/yaamp/core/backend/blocks.php index 685d468..8e6bbe2 100644 --- a/web/yaamp/core/backend/blocks.php +++ b/web/yaamp/core/backend/blocks.php @@ -27,6 +27,10 @@ function BackendBlockNew($coin, $db_block) $amount = $reward * $hash_power / $total_hash_power; if(!$user->no_fees) $amount = take_yaamp_fee($amount, $coin->algo); + if(!empty($user->donation)) { + $amount = take_yaamp_fee($amount, $coin->algo, $user->donation); + if ($amount <= 0) continue; + } $earning = new db_earnings; $earning->userid = $user->id; diff --git a/web/yaamp/core/backend/renting.php b/web/yaamp/core/backend/renting.php index 8403b2a..0ce7e6b 100644 --- a/web/yaamp/core/backend/renting.php +++ b/web/yaamp/core/backend/renting.php @@ -112,6 +112,10 @@ function BackendRentingPayout() $earning->amount = $amount * $hash_power / $total_hash_power; if(!$user->no_fees) $earning->amount = take_yaamp_fee($earning->amount, $algo); + if(!empty($user->donation)) { + $earning->amount = take_yaamp_fee($earning->amount, $algo, $user->donation); + if ($earning->amount <= 0) continue; + } $earning->save(); diff --git a/web/yaamp/core/functions/yaamp.php b/web/yaamp/core/functions/yaamp.php index cdfa52a..4968357 100755 --- a/web/yaamp/core/functions/yaamp.php +++ b/web/yaamp/core/functions/yaamp.php @@ -225,9 +225,11 @@ function yaamp_fee($algo) return $fee; } -function take_yaamp_fee($v, $algo) +function take_yaamp_fee($v, $algo, $percent=-1) { - return $v - ($v * yaamp_fee($algo) / 100); + if ($percent == -1) $percent = yaamp_fee($algo); + + return $v - ($v * $percent / 100.0); } function yaamp_hashrate_constant($algo=null) diff --git a/web/yaamp/modules/site/results/miners_results.php b/web/yaamp/modules/site/results/miners_results.php index 806b61b..e7af4e6 100644 --- a/web/yaamp/modules/site/results/miners_results.php +++ b/web/yaamp/modules/site/results/miners_results.php @@ -20,18 +20,22 @@ $total_invalid = dboscalar("select sum(difficulty) * $target / $interval / 1000 WriteBoxHeader("Miners Version ($algo)"); -//echo "
"; -showTableSorter('maintable2'); -echo ""; -echo ""; -echo ""; -echo ""; -echo ""; -echo ""; -echo ""; -echo ""; -echo ""; -echo ""; +//showTableSorter('maintable2'); +echo << +
VersionCountExtranoncePercentHashrate*Reject
+ + + + + + + + + + + +end; $error_tab = array( 20=>'Invalid nonce size', @@ -43,6 +47,8 @@ $error_tab = array( 26=>'Low difficulty share', ); +$total_donators = 0; + $versions = dbolist("select version, count(*) as c, sum(subscribe) as s from workers where algo=:algo group by version order by c desc", array(':algo'=>$algo)); foreach($versions as $item) { @@ -51,16 +57,16 @@ foreach($versions as $item) $extranonce = $item['s']; $hashrate = dboscalar("select sum(difficulty) * $target / $interval / 1000 from shares where valid and time>$delay and - workerid in (select id from workers where algo=:algo and version='$version')", array(':algo'=>$algo)); + workerid IN (select id from workers where algo=:algo and version=:version)", array(':algo'=>$algo, ':version'=>$version)); $invalid = dboscalar("select sum(difficulty) * $target / $interval / 1000 from shares where not valid and time>$delay and - workerid in (select id from workers where algo=:algo and version='$version')", array(':algo'=>$algo)); + workerid IN (select id from workers where algo=:algo and version=:version)", array(':algo'=>$algo, ':version'=>$version)); $title = ''; foreach($error_tab as $i=>$s) { $invalid2 = dboscalar("select sum(difficulty) * $target / $interval / 1000 from shares where error=$i and time>$delay and - workerid in (select id from workers where algo=:algo and version='$version')", array(':algo'=>$algo)); + workerid in (select id from workers where algo=:algo and version=:version)", array(':algo'=>$algo, ':version'=>$version)); if($invalid2) { @@ -69,6 +75,13 @@ foreach($versions as $item) } } + $donators = dboscalar( + "SELECT COUNT(*) AS donators FROM workers W LEFT JOIN accounts A ON A.id = W.userid". + " WHERE W.algo=:algo AND W.version=:version AND A.donation > 0", + array(':algo'=>$algo, ':version'=>$version) + ); + $total_donators += $donators; + $percent = $total_hashrate&&$hashrate? round($hashrate * 100 / $total_hashrate, 2).'%': ''; $bad = ($hashrate+$invalid)? round($invalid*100/($hashrate+$invalid), 1).'%': ''; $hashrate = $hashrate? Itoa2($hashrate).'h/s': ''; @@ -77,6 +90,7 @@ foreach($versions as $item) echo ""; echo ""; echo ""; + echo ""; echo ""; echo ""; echo ""; @@ -105,6 +119,7 @@ $total_hashrate = Itoa2($total_hashrate).'h/s'; echo ""; echo ""; echo ""; +echo ""; echo ""; echo ""; echo ""; diff --git a/web/yaamp/modules/site/results/wallet_results.php b/web/yaamp/modules/site/results/wallet_results.php index b887f81..1ea2034 100644 --- a/web/yaamp/modules/site/results/wallet_results.php +++ b/web/yaamp/modules/site/results/wallet_results.php @@ -132,9 +132,9 @@ echo ""; +echo '
(total pending)'; echo ""; echo ""; @@ -143,7 +143,15 @@ echo ""; -echo ""; +// //////////////////////////////////////////////////////////////////////////// + +$fees_notice = ''; +if ($user->donation > 0) { + $fees_notice = 'Currently donating '.$user->donation.' % of the rewards.'; +} else if ($user->no_fees == 1) { + $fees_notice = 'Currently mining without pool fees.'; +} +echo ''; // //////////////////////////////////////////////////////////////////////////// diff --git a/web/yaamp/modules/site/worker_results.php b/web/yaamp/modules/site/worker_results.php index 050b063..eb9b574 100644 --- a/web/yaamp/modules/site/worker_results.php +++ b/web/yaamp/modules/site/worker_results.php @@ -21,6 +21,7 @@ echo ""; echo ""; echo ""; echo ""; +echo ""; echo ""; echo ""; @@ -52,7 +53,8 @@ foreach($workers as $worker) $coinimg = CHtml::image($coin->image, $coin->symbol, array('width'=>'16')); $coinlink = CHtml::link($coin->name, '/site/coin?id='.$coin->id); } - $name = $user->login; + $name = empty($name) ? $user->login : $name; + $gift = $user->donation; } $dns = !empty($worker->dns)? $worker->dns: $worker->ip; @@ -97,6 +99,7 @@ foreach($workers as $worker) echo ''; echo ''; + echo ''; echo ''; }
VersionCountDonatorsExtranoncePercentHashrate*Reject
$version$count$donators$extranonce$percent$hashrate
Total$total_workers$total_donators$total_extranonce$total_hashrate"; if($refcoin->symbol == 'BTC') echo "$refcoin->name"; else - echo "$refcoin->name"; + echo "$refcoin->name"; -echo "
(total pending)
$unconfirmed$confirmed$total_unsold $refcoin echo "
 
'.$fees_notice.'
Bad%Found
'.$worker_blocs.' / '.$user_blocs.''.$name.''.($gift ? "$gift %" : '').'