forked from globalzon/yaamp
-
Notifications
You must be signed in to change notification settings - Fork 682
/
users.php
104 lines (82 loc) · 2.54 KB
/
users.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
function BackendUsersUpdate()
{
$t1 = microtime(true);
$list = getdbolist('db_accounts', "coinid IS NULL OR IFNULL(coinsymbol,'') != ''");
foreach($list as $user)
{
$old_usercoinid = $user->coinid;
// debuglog("testing user $user->username, $user->coinsymbol");
if(!empty($user->coinsymbol))
{
$coin = getdbosql('db_coins', "symbol=:symbol", array(':symbol'=>$user->coinsymbol));
$user->coinsymbol = '';
if($coin)
{
if($user->coinid == $coin->id)
{
$user->save();
continue;
}
$remote = new WalletRPC($coin);
$b = $remote->validateaddress($user->username);
if(arraySafeVal($b,'isvalid'))
{
$old_balance = $user->balance;
if($user->balance > 0)
{
$coinref = getdbo('db_coins', $user->coinid);
if(!$coinref) {
if (YAAMP_ALLOW_EXCHANGE)
$coinref = getdbosql('db_coins', "symbol='BTC'");
else
continue;
}
$user->balance = $user->balance * $coinref->price / $coin->price;
}
$user->coinid = $coin->id;
$user->save();
debuglog("{$user->username} converted to {$user->balance} {$coin->symbol} (old: $old_balance)");
continue;
}
}
}
$user->coinid = 0;
$order = YAAMP_ALLOW_EXCHANGE ? "difficulty" : "id";
$coins = getdbolist('db_coins', "enable ORDER BY $order DESC");
foreach($coins as $coin)
{
$remote = new WalletRPC($coin);
$b = $remote->validateaddress($user->username);
if(!arraySafeVal($b,'isvalid')) continue;
if ($old_usercoinid && $old_usercoinid != $coin->id) {
debuglog("{$user->username} set to {$coin->symbol}, balance {$user->balance} reset to 0");
$user->balance = 0;
}
$user->coinid = $coin->id;
break;
}
if (empty($user->coinid)) {
debuglog("{$user->hostaddr} - {$user->username} is an unknown address!");
}
$user->save();
}
// $delay=time()-60*60;
// $list = dborun("UPDATE coins SET dontsell=1 WHERE id in (SELECT coinid FROM accounts WHERE balance>0 OR last_earning>$delay GROUP BY coinid)");
// $list = dborun("UPDATE coins SET dontsell=0 WHERE id not in (SELECT coinid FROM accounts WHERE balance>0 OR last_earning>$delay GROUP BY coinid)");
// $list = getdbolist('db_workers', "dns is null");
// foreach($list as $worker)
// {
// $worker->dns = $worker->ip;
// $res = system("resolveip $worker->ip");
// if($res)
// {
// $a = explode(' ', $res);
// if($a && isset($a[5]))
// $worker->dns = $a[5];
// }
// $worker->save();
// }
$d1 = microtime(true) - $t1;
controller()->memcache->add_monitoring_function(__METHOD__, $d1);
}