-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathupdate-jsonapi.php
More file actions
83 lines (66 loc) · 2.64 KB
/
update-jsonapi.php
File metadata and controls
83 lines (66 loc) · 2.64 KB
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
<?php
/*
* PHP parser for unspent outputs in the protoshares blockchain.
*
* This script creates json api with unspent outputs.
* Usage: $ php update-jsonapi.php > path/to/pts-unspent.json
*
* Donations accepted:
* - BTC 1Bzc7PatbRzXz6EAmvSuBuoWED96qy3zgc
* - PTS PcDLYukq5RtKyRCeC1Gv5VhAJh88ykzfka
*
* Copyright (C) 2014 vertoe <vertoe@qhor.net>
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Get this from: http://jsonrpcphp.org/
require_once "jsonRPCClient.php";
// Enter DB details, make sure the database 'pts_balance' exists
$dbhost='localhost';
$dbuser='root';
$dbpass='dbpass';
$database='pts_balances';
// Enter protoshares rpc details, make sure to set rpcuser, rpcpassword,
// rpcport, rpcallowip and txindex=1 in your protoshares.conf
$rpchost='localhost';
$rpcuser='protosharesrpc';
$rpcpass='superdupersecretphrase';
$rpcport='3838';
////////////////////////////////////////////////////////////////////////////////
$mysqli=new mysqli($dbhost, $dbuser, $dbpass, $database);
if ($mysqli->connect_errno)
throw new Exception("database connection error");
$r=$mysqli->query("select max(block_num) from outputs", MYSQLI_USE_RESULT);
$w=$r->fetch_assoc();
$blocknum=$w["max(block_num)"]+0;
$r->close();
$r=$mysqli->query("select sum(balance) from outputs", MYSQLI_USE_RESULT);
$w=$r->fetch_assoc();
$moneysupply=$w["sum(balance)"]+0;
$r->close();
$pts=new jsonRPCClient("http://".$rpcuser.":".$rpcpass."@".$rpchost.":".$rpcport);
$blockhash=$pts->getblockhash($blocknum);
$blockinfo=$pts->getblock($blockhash);
$blocktime=$blockinfo['time'];
echo "{\"blocknum\":".$blocknum.",\"blocktime\":".$blocktime.",\"moneysupply\":".$moneysupply.",\"balances\":\n";
echo " {\n";
$r=$mysqli->query("select * from outputs group by address order by balance desc", MYSQLI_USE_RESULT);
while ($w=$r->fetch_assoc()) {
echo " \"".$w['address']."\":".$w['balance'].",\n";
}
echo " }\n";
echo "}";
$r->close();
////////////////////////////////////////////////////////////////////////////////
?>