Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Address a;
- Uv = 0;
- Received = 0;
- Sent = 0;
- For each (output in blockchain):
- If (output is unlock-able by owner of address a):
- Received += output.amount;
- If (output has been spent):
- Sent += output.amount;
- Else:
- Uv += output.amount;
- <?php
- // Method: POST, PUT, GET etc
- // Data: array("param" => "value") ==> index.php?param=value
- function CallAPI($method, $url, $data = false)
- {
- $curl = curl_init();
- switch ($method)
- {
- case "POST":
- curl_setopt($curl, CURLOPT_POST, 1);
- if ($data)
- curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
- break;
- case "PUT":
- curl_setopt($curl, CURLOPT_PUT, 1);
- break;
- default:
- if ($data)
- $url = sprintf("%s?%s", $url, http_build_query($data));
- }
- // Optional Authentication:
- curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
- // curl_setopt($curl, CURLOPT_USERPWD, "username:password");
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
- $result = curl_exec($curl);
- curl_close($curl);
- return $result;
- }
- $address = "1EZK42jGEJVniyBn1wXrUx92wzyUkYB8kJ";
- $offset=0;
- $txs = array();
- while (true)
- {
- $val = json_decode(CallAPI("GET", "https://blockchain.info/address/$address?format=json&limit=10&offset=$offset"), true);
- if (count($val["txs"]) == 0)
- break;
- else
- $txs = array_merge($txs, $val["txs"]);
- $offset += 10;
- }
- $uv = 0;
- $received = 0;
- $sent = 0;
- $nrefs = 0;
- foreach ($txs as $tx)
- {
- $ininputs = false;
- $totalin = 0;
- foreach ($tx["inputs"] as $input)
- {
- if ($input["prev_out"]["addr"] == $address)
- {
- $ininputs = true;
- $nrefs += 1;
- $totalin += $input["prev_out"]["value"];
- }
- }
- $inoutputs = false;
- $totalout = 0;
- foreach ($tx["out"] as $output)
- {
- if ($output["addr"] == $address)
- {
- $inoutputs = true;
- $nrefs += 1;
- $totalout += $output["value"];
- }
- }
- $uv += ($totalout - $totalin);
- // $received += $totalout;
- // $sent += $totalin;
- if ($ininputs && $inoutputs && $totalout >= $totalin)
- {
- $received += $totalout - $totalin;
- }
- else if ($ininputs && $inoutputs && $totalout < $totalin)
- {
- $sent += $totalin - $totalout;
- }
- else if ($inoutputs)
- {
- $received += $totalout;
- }
- else if ($ininputs)
- {
- $sent += $totalin;
- }
- }
- echo "n";
- echo "nrefs : " . $nrefs . "n";
- echo "uv : " . $uv . "n";
- echo "received : " . $received . "n";
- echo "sent : " . $sent . "n";
Add Comment
Please, Sign In to add comment