Skip to content

Commit

Permalink
adding MANO + cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmeszaros committed Jul 9, 2018
1 parent 3e2737b commit 6c540a6
Show file tree
Hide file tree
Showing 14 changed files with 211 additions and 374 deletions.
91 changes: 0 additions & 91 deletions extraPayouts.php

This file was deleted.

122 changes: 0 additions & 122 deletions extraPayoutsSendmany.php

This file was deleted.

71 changes: 42 additions & 29 deletions runStats-bitsend.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function updatePoolHashrate($db) {
// Add stats entry if we have at least 10 entries from each active miner (when block is found the shares are reset causing stats issues)
$active_miners = minerHelper::countMiners($db, $algo_key)['total_count'];

if ($tt_share_check['total_share_count'] > ($active_miners * 15)) {
if ($tt_share_check['total_share_count'] > ($active_miners * 7)) {

$pool_rate = minerHelper::getPoolHashrate($db, $algo);

Expand Down Expand Up @@ -183,9 +183,11 @@ function updateEarnings($db) {
$stmt = $db->prepare("UPDATE blocks SET category = :category, amount = :amount, txhash = :txhash WHERE id = :block_id");
$stmt->execute([':category' => 'immature', ':block_id' => $db_block['id'], ':amount' => $db_block['reward'], ':txhash' => $db_block['tx_hash']]);

$hash_time = time() - 3 * 60;

// Delete shares where we calculated the earnings
$stmt = $db->prepare("DELETE FROM shares WHERE algo = :algo AND coinid = :coin_id");
$stmt->execute([':algo' => minerHelper::miner_getAlgos()[$db_block['coin_id']], ':coin_id' => $db_block['coin_id']]);
$stmt = $db->prepare("DELETE FROM shares WHERE algo = :algo AND coinid = :coin_id AND time < :time_offset");
$stmt->execute([':algo' => minerHelper::miner_getAlgos()[$db_block['coin_id']], ':coin_id' => $db_block['coin_id'], ':time_offset' => $hash_time]);
}
}
// The cron run every minute if more than 1 block is found every minute causing issue so we break after 1 block
Expand Down Expand Up @@ -418,44 +420,55 @@ function sendExtraPayouts($db, $coin_id = 1425, $extra_payout = FALSE) {
}

// Get the accounts which due payout
$stmt = $db->prepare("SELECT * FROM accounts WHERE balance > :min_payout AND coinid = :coin_id ORDER BY balance DESC");
$stmt = $db->prepare("SELECT * FROM accounts WHERE balance > :min_payout AND coinid = :coin_id ORDER BY balance DESC LIMIT 0, 300");
$stmt->execute([
':min_payout' => $min_payout,
':coin_id' => $coin_id
]);

$balances = $stmt->fetchAll(PDO::FETCH_ASSOC);

$accounts = [];
foreach ($balances as $user_account) {
print 'Send payouts: ' . $user_account['id'] . ' -- ' . $user_account['balance'] . "\n";
// Try to clear the balance
$tx = $remote->sendtoaddress($user_account['username'], round($user_account['balance'], 8));

if(!$tx) {
$error = $remote->error;
print "Send payouts ERROR: " . $error . ' -- ' . $user_account['username'] . ' -- ' . $user_account['balance'];
}
else {
// Add entry about the transaction
$stmt = $db->prepare("INSERT INTO payouts(account_id, time, amount, fee, tx, idcoin) VALUES(:account_id, :time, :amount, :fee, :tx, :idcoin)");
$stmt->execute([
':account_id' => $user_account['id'],
':time' => time(),
':amount' => $user_account['balance'],
':fee' => 0,
':tx' => $tx,
':idcoin' => $coin_id
]);
$accounts[$user_account['username']] = round($user_account['balance'], 8);
}

// Deduct user balance
$stmt = $db->prepare("UPDATE accounts SET balance = balance - :payout WHERE id = :userid");
$stmt->execute([
':payout' => $user_account['balance'],
':userid' => $user_account['id']
]);
// Sendmany transaction if we have tx id continue or throw error
$tx = $remote->sendmany('', $accounts, 1, '');
if(!$tx) {
$error = $remote->error;
print "Send payouts ERROR: " . $error . ' -- ' . json_encode($accounts);
}
else {
foreach ($balances as $user_account) {
print 'Sent payout for: ' . $user_account['id'] . '-- ' . $user_account['username'] . ' -- ' . $user_account['balance'] . "\n";

if(!$tx) {
$error = $remote->error;
print "Send payouts ERROR: " . $error . ' -- ' . json_encode($accounts);
}
else {
// Add entry about the transaction
$stmt = $db->prepare("INSERT INTO payouts(account_id, time, amount, fee, tx, idcoin) VALUES(:account_id, :time, :amount, :fee, :tx, :idcoin)");
$stmt->execute([
':account_id' => $user_account['id'],
':time' => time(),
':amount' => $user_account['balance'],
':fee' => 0,
':tx' => $tx,
':idcoin' => $coin_id
]);

// Deduct user balance
$stmt = $db->prepare("UPDATE accounts SET balance = 0 WHERE id = :userid");
$stmt->execute([
':userid' => $user_account['id']
]);
}
}
}


}

/**
Expand Down
2 changes: 1 addition & 1 deletion runStats-bulwark.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,4 +484,4 @@ function updateNetworkHashrate($db, $coin_id = 1425) {
$redis->set('network_info_' . $coin_id, json_encode($data));
}

}
}
14 changes: 8 additions & 6 deletions runStats-lux.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function updatePoolHashrate($db) {
// Add stats entry if we have at least 10 entries from each active miner (when block is found the shares are reset causing stats issues)
$active_miners = minerHelper::countMiners($db, $algo_key)['total_count'];

if ($tt_share_check['total_share_count'] > ($active_miners * 15)) {
if ($tt_share_check['total_share_count'] > ($active_miners * 7)) {

$pool_rate = minerHelper::getPoolHashrate($db, $algo);

Expand Down Expand Up @@ -183,9 +183,11 @@ function updateEarnings($db) {
$stmt = $db->prepare("UPDATE blocks SET category = :category, amount = :amount, txhash = :txhash WHERE id = :block_id");
$stmt->execute([':category' => 'immature', ':block_id' => $db_block['id'], ':amount' => $db_block['reward'], ':txhash' => $db_block['tx_hash']]);

$hash_time = time() - 3 * 60;

// Delete shares where we calculated the earnings
$stmt = $db->prepare("DELETE FROM shares WHERE algo = :algo AND coinid = :coin_id");
$stmt->execute([':algo' => minerHelper::miner_getAlgos()[$db_block['coin_id']], ':coin_id' => $db_block['coin_id']]);
$stmt = $db->prepare("DELETE FROM shares WHERE algo = :algo AND coinid = :coin_id AND time < :time_offset");
$stmt->execute([':algo' => minerHelper::miner_getAlgos()[$db_block['coin_id']], ':coin_id' => $db_block['coin_id'], ':time_offset' => $hash_time]);
}
}
// The cron run every minute if more than 1 block is found every minute causing issue so we break after 1 block
Expand Down Expand Up @@ -371,7 +373,7 @@ function sendPayouts($db, $coin_id = 1425) {
$nextFullMin = date("i", $now + (60 - $now % 60));

$hours_to_process = ['00', '04', '08', '12', '16', '20'];
$minutes_to_process = ['10'];
$minutes_to_process = ['10', '34'];

if (in_array($nextFullHour, $hours_to_process) && in_array($nextFullMin, $minutes_to_process)) {
print 'Activate extra payouts' . "\n";
Expand Down Expand Up @@ -418,7 +420,7 @@ function sendExtraPayouts($db, $coin_id = 1425, $extra_payout = FALSE) {
}

// Get the accounts which due payout
$stmt = $db->prepare("SELECT * FROM accounts WHERE balance > :min_payout AND coinid = :coin_id ORDER BY balance DESC");
$stmt = $db->prepare("SELECT * FROM accounts WHERE balance > :min_payout AND coinid = :coin_id ORDER BY balance DESC LIMIT 0, 300");
$stmt->execute([
':min_payout' => $min_payout,
':coin_id' => $coin_id
Expand Down Expand Up @@ -495,4 +497,4 @@ function updateNetworkHashrate($db, $coin_id = 1425) {
$redis->set('network_info_' . $coin_id, json_encode($data));
}

}
}
Loading

0 comments on commit 6c540a6

Please sign in to comment.