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 "
Version | "; -echo "Count | "; -echo "Extranonce | "; -echo "Percent | "; -echo "Hashrate* | "; -echo "Reject | "; -echo "
---|
Version | +Count | +Donators | +Extranonce | +Percent | +Hashrate* | +Reject | +|||
---|---|---|---|---|---|---|---|---|---|
$version | "; echo "$count | "; + echo "$donators | "; echo "$extranonce | "; echo "$percent | "; echo "$hashrate | "; @@ -105,6 +119,7 @@ $total_hashrate = Itoa2($total_hashrate).'h/s'; echo "||||
Total | "; echo "$total_workers | "; +echo "$total_donators | "; echo "$total_extranonce | "; echo ""; echo " | $total_hashrate | "; 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 "";
if($refcoin->symbol == 'BTC')
echo "$refcoin->name";
else
- echo "$refcoin->name";
+ echo "$refcoin->name";
-echo " (total pending) | ";
+echo '$unconfirmed | "; echo "$confirmed | "; @@ -143,7 +143,15 @@ echo "$total_unsold $refcoin echo " |
'.$fees_notice.' | Bad | "; echo "% | "; echo "Found | "; 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 ' | '.$worker_blocs.' / '.$user_blocs.' | '; echo ''.$name.' | '; + echo ''.($gift ? "$gift %" : '').' | '; echo ''; }