-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Joe Looney
authored and
Joe Looney
committed
Oct 7, 2015
0 parents
commit 36a4513
Showing
7 changed files
with
615 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
<?php | ||
//hex input must be in uppercase, with no leading 0x | ||
|
||
define("ADDRESSVERSION","00"); //this is a hex byte | ||
|
||
function decodeHex($hex) | ||
{ | ||
$hex=strtoupper($hex); | ||
$chars="0123456789ABCDEF"; | ||
$return="0"; | ||
for($i=0;$i<strlen($hex);$i++) | ||
{ | ||
$current=(string)strpos($chars,$hex[$i]); | ||
$return=(string)bcmul($return,"16",0); | ||
$return=(string)bcadd($return,$current,0); | ||
} | ||
return $return; | ||
} | ||
|
||
function encodeHex($dec) | ||
{ | ||
$chars="0123456789ABCDEF"; | ||
$return=""; | ||
while (bccomp($dec,0)==1) | ||
{ | ||
$dv=(string)bcdiv($dec,"16",0); | ||
$rem=(integer)bcmod($dec,"16"); | ||
$dec=$dv; | ||
$return=$return.$chars[$rem]; | ||
} | ||
return strrev($return); | ||
} | ||
|
||
function decodeBase58($base58) | ||
{ | ||
$origbase58=$base58; | ||
|
||
$chars="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; | ||
$return="0"; | ||
for($i=0;$i<strlen($base58);$i++) | ||
{ | ||
$current=(string)strpos($chars,$base58[$i]); | ||
$return=(string)bcmul($return,"58",0); | ||
$return=(string)bcadd($return,$current,0); | ||
} | ||
|
||
$return=encodeHex($return); | ||
|
||
//leading zeros | ||
for($i=0;$i<strlen($origbase58)&&$origbase58[$i]=="1";$i++) | ||
{ | ||
$return="00".$return; | ||
} | ||
|
||
if(strlen($return)%2!=0) | ||
{ | ||
$return="0".$return; | ||
} | ||
|
||
return $return; | ||
} | ||
|
||
function encodeBase58($hex) | ||
{ | ||
if(strlen($hex)%2!=0) | ||
{ | ||
die("encodeBase58: uneven number of hex characters"); | ||
} | ||
$orighex=$hex; | ||
|
||
$chars="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; | ||
$hex=decodeHex($hex); | ||
$return=""; | ||
while (bccomp($hex,0)==1) | ||
{ | ||
$dv=(string)bcdiv($hex,"58",0); | ||
$rem=(integer)bcmod($hex,"58"); | ||
$hex=$dv; | ||
$return=$return.$chars[$rem]; | ||
} | ||
$return=strrev($return); | ||
|
||
//leading zeros | ||
for($i=0;$i<strlen($orighex)&&substr($orighex,$i,2)=="00";$i+=2) | ||
{ | ||
$return="1".$return; | ||
} | ||
|
||
return $return; | ||
} | ||
|
||
function hash160ToAddress($hash160,$addressversion=ADDRESSVERSION) | ||
{ | ||
$hash160=$addressversion.$hash160; | ||
$check=pack("H*" , $hash160); | ||
$check=hash("sha256",hash("sha256",$check,true)); | ||
$check=substr($check,0,8); | ||
$hash160=strtoupper($hash160.$check); | ||
return encodeBase58($hash160); | ||
} | ||
|
||
function addressToHash160($addr) | ||
{ | ||
$addr=decodeBase58($addr); | ||
$addr=substr($addr,2,strlen($addr)-10); | ||
return $addr; | ||
} | ||
|
||
function checkAddress($addr) | ||
{ | ||
$addressversion=ADDRESSVERSION; | ||
|
||
$addr=decodeBase58($addr); | ||
if(strlen($addr)!=50) | ||
{ | ||
return false; | ||
} | ||
$version=substr($addr,0,2); | ||
if(hexdec($version)>hexdec($addressversion)) | ||
{ | ||
return false; | ||
} | ||
$check=substr($addr,0,strlen($addr)-8); | ||
$check=pack("H*" , $check); | ||
$check=strtoupper(hash("sha256",hash("sha256",$check,true))); | ||
$check=substr($check,0,8); | ||
return $check==substr($addr,strlen($addr)-8); | ||
} | ||
|
||
function hash160($data) | ||
{ | ||
$data=pack("H*" , $data); | ||
return strtoupper(hash("ripemd160",hash("sha256",$data,true))); | ||
} | ||
|
||
function pubKeyToAddress($pubkey) | ||
{ | ||
return hash160ToAddress(hash160($pubkey)); | ||
} | ||
|
||
function remove0x($string) | ||
{ | ||
if(substr($string,0,2)=="0x"||substr($string,0,2)=="0X") | ||
{ | ||
$string=substr($string,2); | ||
} | ||
return $string; | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
//define database information | ||
$dbserver = ""; | ||
$dbuser = ""; | ||
$dbpassword = ""; | ||
$dbname = "fldcstats"; | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
$filename = $day.".txt"; | ||
|
||
if (!file_exists($filename)) { | ||
|
||
//download folding data from stanford | ||
$url = "http://fah-web.stanford.edu/daily_user_summary.txt.bz2"; | ||
$name = basename($url); | ||
file_put_contents("$name", file_get_contents($url)); | ||
|
||
//$name = "daily_user_summary.txt.bz2"; | ||
$bz = bzopen($name, "r") or die("Couldn't open $name for reading"); | ||
|
||
$data=""; | ||
|
||
$i = 0; | ||
|
||
//read folding data from file | ||
do { | ||
|
||
$line=bzread($bz, 8092); | ||
|
||
if($line!==false) { | ||
|
||
$data[$i] = $line; | ||
|
||
$i++; | ||
|
||
} | ||
|
||
} | ||
while($line); | ||
|
||
bzclose($bz); | ||
|
||
//write data as [TODAY].txt | ||
file_put_contents("$filename", $data); | ||
|
||
$data = null; | ||
|
||
echo $day.".txt download complete!<br>---<br>"; | ||
|
||
} else { | ||
|
||
echo "file already exists<br>--<br>"; | ||
|
||
} | ||
|
||
|
||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
//get current day | ||
$date = new DateTime(); | ||
$date->setTimezone(new DateTimeZone('America/New_York')); | ||
$day = $date->format('Y-m-d'); | ||
|
||
//download from Stanford as txt | ||
include("download.php"); | ||
|
||
//wait 30 seconds between download and parsing | ||
sleep(30); | ||
|
||
//parse foldingcoin users and save in mysql | ||
include("parse.php"); | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
//load database | ||
require_once "db.php"; | ||
|
||
//get daily stats per defined URL 'date' parameter | ||
$tablename=$_GET["date"]; | ||
|
||
$con=mysqli_connect($dbserver, $dbuser, $dbpassword, $dbname); | ||
// Check connection | ||
if (mysqli_connect_errno()) | ||
{ | ||
echo "Failed to connect to MySQL: " . mysqli_connect_error(); | ||
} | ||
|
||
$query = "SELECT * FROM `".$tablename."`"; | ||
|
||
$result = mysqli_query($con, $query); | ||
|
||
$i = 0; | ||
|
||
while($row = @mysqli_fetch_array($result)) | ||
{ | ||
//id name token address totalpts | ||
|
||
$data[$i]['id'] = $row['id']; | ||
$data[$i]['name'] = $row['name']; | ||
$data[$i]['token'] = $row['token']; | ||
$data[$i]['address'] = $row['address']; | ||
$data[$i]['newcredit'] = $row['totalpts']; | ||
|
||
$i++; | ||
|
||
} | ||
|
||
|
||
mysqli_close($con); | ||
|
||
//show daily stats as JSON | ||
echo json_encode($data); | ||
|
||
|
||
?> |
Oops, something went wrong.