mirror of
https://github.com/LBRYFoundation/pool.git
synced 2025-08-23 17:37:25 +00:00
db: handle custom user donation percents
The setting is set with g=10% in password field its disabled by default, to do maybe per worker... prevent negative donation percents
This commit is contained in:
parent
2022170777
commit
6950057b17
9 changed files with 81 additions and 26 deletions
4
sql/2016-02-18-accounts_donation.sql
Normal file
4
sql/2016-02-18-accounts_donation.sql
Normal file
|
@ -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`;
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -20,18 +20,22 @@ $total_invalid = dboscalar("select sum(difficulty) * $target / $interval / 1000
|
|||
|
||||
WriteBoxHeader("Miners Version ($algo)");
|
||||
|
||||
//echo "<br><table class='dataGrid2'>";
|
||||
showTableSorter('maintable2');
|
||||
echo "<thead>";
|
||||
echo "<tr>";
|
||||
echo "<th>Version</th>";
|
||||
echo "<th align=right>Count</th>";
|
||||
echo "<th align=right>Extranonce</th>";
|
||||
echo "<th align=right>Percent</th>";
|
||||
echo "<th align=right>Hashrate*</th>";
|
||||
echo "<th align=right>Reject</th>";
|
||||
echo "</tr>";
|
||||
echo "</thead><tbody>";
|
||||
//showTableSorter('maintable2');
|
||||
echo <<<end
|
||||
<br/>
|
||||
<table id="maintable2" class="dataGrid2">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Version</th>
|
||||
<th align=right>Count</th>
|
||||
<th align=right>Donators</th>
|
||||
<th align=right>Extranonce</th>
|
||||
<th align=right>Percent</th>
|
||||
<th align=right>Hashrate*</th>
|
||||
<th align=right>Reject</th>
|
||||
</tr>
|
||||
</thead><tbody>
|
||||
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 "<tr class='ssrow'>";
|
||||
echo "<td><b>$version</b></td>";
|
||||
echo "<td align=right>$count</td>";
|
||||
echo "<td align=right>$donators</td>";
|
||||
echo "<td align=right>$extranonce</td>";
|
||||
echo "<td align=right>$percent</td>";
|
||||
echo "<td align=right>$hashrate</td>";
|
||||
|
@ -105,6 +119,7 @@ $total_hashrate = Itoa2($total_hashrate).'h/s';
|
|||
echo "<tr class='ssrow'>";
|
||||
echo "<td><b>Total</b></td>";
|
||||
echo "<td align=right>$total_workers</td>";
|
||||
echo "<td align=right>$total_donators</td>";
|
||||
echo "<td align=right>$total_extranonce</td>";
|
||||
echo "<td align=right></td>";
|
||||
echo "<td align=right>$total_hashrate</td>";
|
||||
|
|
|
@ -132,9 +132,9 @@ echo "<td valign=top><b>";
|
|||
if($refcoin->symbol == 'BTC')
|
||||
echo "$refcoin->name";
|
||||
else
|
||||
echo "<a href='/site/block?id=$refcoin->id'>$refcoin->name</a>";
|
||||
echo "<a href='/site/block?id={$refcoin->id}'>$refcoin->name</a>";
|
||||
|
||||
echo "<br><span style='font-size: .8em;'>(total pending)</span></b></td>";
|
||||
echo '<br/><span style="font-size: .8em;"">(total pending)</span></b></td>';
|
||||
|
||||
echo "<td valign=top align=right style='font-size: .8em;'>$unconfirmed</td>";
|
||||
echo "<td valign=top align=right style='font-size: .8em;'>$confirmed</td>";
|
||||
|
@ -143,7 +143,15 @@ echo "<td valign=top align=right style='font-size: .8em;'>$total_unsold $refcoin
|
|||
|
||||
echo "</tr>";
|
||||
|
||||
echo "<tr><td style='font-size: .7em;'> </td></tr>";
|
||||
// ////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$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 '<tr><td colspan="6" style="text-align:right; font-size: .8em;"><b>'.$fees_notice.'</b></td></tr>';
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ echo "<th>Bad</th>";
|
|||
echo "<th>%</th>";
|
||||
echo "<th>Found</th>";
|
||||
echo "<th></th>";
|
||||
echo "<th></th>";
|
||||
echo "</tr>";
|
||||
echo "</thead><tbody>";
|
||||
|
||||
|
@ -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 '<td>'.$worker_blocs.' / '.$user_blocs.'</td>';
|
||||
echo '<td>'.$name.'</td>';
|
||||
echo '<td>'.($gift ? "$gift %" : '').'</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue