Bitcoin Forum
May 08, 2024, 05:51:23 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
  Home Help Search Login Register More  
  Show Posts
Pages: « 1 2 3 4 5 6 7 8 [9]
161  Bitcoin / Bitcoin Discussion / gkrellm/conky on: July 28, 2010, 04:55:28 AM
Does anyone have any need/use for any data/information to appear in gkrellm or conky?  If so, perhaps suggest here and I or someone else can offer assistance with implementing types of information to become available.
162  Bitcoin / Development & Technical Discussion / Difficulty on: July 27, 2010, 10:11:51 AM
http://nullvoid.org/bitcoin/difficultiez.php

Code:
<?
header("Content-type: text/html");
require_once 'jsonRPCClient.php';
$data=new jsonRPCClient('http://127.0.0.1:8332');
$blockcount = $data->getblockcount();
$now = date("U");
$blockfile = "blockdata";
$data = file($blockfile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); array_pop($data);
?><html>
 <head>
  <meta http-equiv="refresh" content="100000">
 </head>
 <body>
  <pre>
<?
function humantime($secs) {
if ($secs<0) return false;
$m = (int)($secs / 60); $s = $secs % 60; $s = ($s <= 9) ? "0$s" : $s;
$h = (int)($m / 60); $m = $m % 60; $m = ($m <= 9) ? "0$m" : $m;
$d = (int)($h / 24); $h = $h % 24; $h = ($h <= 9) ? "0$h" : $h;
$d = ($d <= 9) ? "0$d" : $d;
return $d."d $h:$m:$s";
}

// Converted from ArtForz's python code http://bitcointalk.org/index.php?topic=464.msg4080#msg4080
function uint256_from_compact($c) {
$nbytes = ($c >> 24) & 0xFF;
return bcmul($c & 0xFFFFFF,bcpow(2,8 * ($nbytes - 3)));
}

$tblock = 0;
$nTargetTimespan = 60 * 60 * 24 * 14;
bcscale(256);
foreach ($data as $line) {
$blocks = strtok($line, " ");
$date = strtok(" ");
$avghash = strtok(" ");
$bits = strtok(" ");
if ($blocks == 0 || $blocks == $tblock) {
$tblock = $blocks + 2016;
$blocknum = str_repeat(" ", 6 - strlen($blocks)).$blocks;
echo "Block $blocknum was generated at $date (".date("r", $date).")";
if ($blocks != 0) {
$intervalnum = $date - $lastdate;
$interval = str_repeat(" ", 9 - strlen($intervalnum)).$intervalnum;
echo "    $interval seconds interval (".humantime($intervalnum).")";
echo "   Difficulty: ".bcdiv(bcdiv(bcmul(uint256_from_compact(0x1D00FFFF),1000), uint256_from_compact($bits)), 1000);
$lastdate = $date;
}
echo "<br>";
}
}
?>
  </pre>
 </body>
</html>
163  Other / Off-topic / Firefox Disable Ctrl-Q on: July 24, 2010, 11:23:33 PM
Pushing Ctrl-Q terminates Firefox even if "Warn me when closing multiple tabs" is enabled.  I found keyconfig which allows disabling it and it works!  This is very useful for those who have Firefox profiles designated for anonymous surfing and who may accidentally push Ctrl-q and lose their progress.

http://forums.mozillazine.org/viewtopic.php?t=72994
164  Bitcoin / Development & Technical Discussion / List of Bitcoin Repositories on: July 24, 2010, 08:08:26 AM
I created a wiki page to keep track of and promote a list of unofficial repositories in addition to the official one of course.

http://www.bitcoin.org/wiki/doku.php?id=repositories

If helpful, when adding or updating a repository entry, write a description as well.
165  Bitcoin / Development & Technical Discussion / Calculating total bitcoins by number of blocks generated on: July 22, 2010, 01:58:53 AM
I couldn't find a post about this, so I created this.

freenode / #math
Quote
<necrodearia>http://pastebin.com/MJPr8K9d is a PHP script I wrote that calculates the output I'm looking for in http://nullvoid.org/formula.html but I would like to know if there is a one line math formula that can produce the same.
<meingtsla> necrodearia: not sure about a single-line math formula, but you could do the integer division of y by 210000 (call it yQuotient) and use that to compute 210000*(50+25+...+50/2^yInt).  (that's a geometric series.)  then you can take the remainder of that division, call it yRemainder, and find yRemainder * 50/2^(yQuotient+1).
<meingtsla> not gonna flesh it out in code myself, i'll leave that to you :p
<meingtsla> sorry, wherever i said y it should be x.  (integer division of x by 210000.... xQuotient... 50/2^xQuotient... xRemainder)

Here's the script in action:
http://nullvoid.org/bitcoin/blockcalc.php?b=1
http://nullvoid.org/bitcoin/blockcalc.php?b=210000
http://nullvoid.org/bitcoin/blockcalc.php?b=1000000
166  Economy / Marketplace / yellowpages on: July 21, 2010, 08:22:55 AM
Quote
<necrodearia> I think a Bitcoin yellow pages should be established, perhaps as a wiki page?
<Xunie> A "web of trust"?
<Xunie> Yeah.
<necrodearia> Mm, maybe not a wiki page
<Xunie> Then what?
<necrodearia> Perhaps a server side app should be established allowing organizations, businesses, entities, individuals, whatever to submit their information and after being processed it will be listed in a yellowpage-liek database.
<necrodearia> Processing could be automatic or manual
<Xunie> Go ask sirius, he's the server man.
<necrodearia> And perhaps integrating with that database could be comments/feedback and ratings so that the businesses can be rated
<lfm> necrodearia seems like you have dispensed with one central authority for a new one
<necrodearia> hmm
<Xunie> lfm, well no.
<necrodearia> lfm: good point
<Xunie> Actually, no.
<Xunie> It's just a list of honest traders, not a central authority!
<necrodearia> Actually, it's a database of traders, businesses, etc to keep it all organized, togehter, searchable, etc.
<Xunie> Just like the Ebay system, you can give someone "thumbs up" or "thumbs down".
<necrodearia> Reading a forum thread with a huge list can be daunting
<necrodearia> And with user/customer review, they can be ranked accordingly
<necrodearia> however
<necrodearia> the data is still in a central authoritative location
<necrodearia> Perhaps a p2p app can be designed to let the data exist without central authority ^_^
<lfm> who to trust can be more of a social problem than a technical one
<necrodearia> Although, central authority isn't such a bad thing really
<necrodearia> considering for example, yellowpages.com or infospace.com or yp.yahoo.com
<necrodearia> all central authorities with the information
<necrodearia> So, my idea should still be reasonable
<necrodearia> And I recommend several bitcoin-specific yellowpage-liek resources to be available.
<lfm> and it should be ok so long as you allow for other trusted lists
<lfm> so people dont get thrown out for social/politic or other unrelated reasons they still have a chance to maintain their trust on other lists maybe
167  Bitcoin / Development & Technical Discussion / Two instances one computer on: July 19, 2010, 09:00:41 AM
I'm running two instances on one computer in same o/s environment, one instance per system user, and thus separate ~/.bitcoin directories.

One instance is caught up with generated blocks and the other is catching up.  The instance that is caught up is a self-compiled port modified (8339) version.

I tried running the catchup one using `./bitcoin -connect 127.0.0.1:8339` and it eventually connected to the other running instance, but block additions are rather slow; about the same speed as using p2p network.  I wonder why this is.  I would imagine a lan connection or even a local connection would be practically instantaneous.

update: Strange.  I specifically `./bitcoin -connect 127.0.0.1:8339`ed and the client has 3 connections?  I thought it didn't use p2p network when -connect argument was specified.  Perhaps then, the 1 connection that was, wasn't a connection to myself
168  Bitcoin / Development & Technical Discussion / How do you calculate probability? on: July 19, 2010, 03:13:43 AM
.I am trying to correct some PHP code to calculate probability of generating a block for bitbot.  bd_ and llama have provided some debate regarding how to calculate it and I suggest it be moved to forum for further eyes to analyze their findings and to come to a conclusion on best formula to calculate probability.

For now, here's code I've been using:
Code:
		//var p = target*rate*1000/Math.pow(2,256);
//var txt = "<table border='1'>
// <tr style='font-weight:bold'> <td>Probability</td> <td>Time</td></tr>\n"+"
// <tr> <td>Average</td> <td>"+getHumanTime(1/p)+"</td></tr>\n"+getRow(0.50,p)+getRow(0.95,p)+"</table>";
//document.getElementById('answer').innerHTML = txt;
//function getRow(prob,p) { return "<tr><td>"+100*prob+"%</td><td>"+getHumanTime(-Math.log(1-prob)/p)+"</td></tr>\n";

bcscale(256);
$a = bcsub(bcpow(2,256),1);
$b = bcmul(bcpow(2,32),$difficulty);
$target = bcdiv($a,$b); // target
$pph = bcdiv($target,bcpow(2,256)); // probability per hash
if (isset($_GET["r"]) && $_GET["r"] != "") {
$rate = $_GET["r"];
if (is_numeric($rate)) {
function humantime($secs) {
if ($secs<0) return false;
$m = (int)($secs / 60); $s = $secs % 60; $s = ($s <= 9) ? "0$s" : $s;
$h = (int)($m / 60); $m = $m % 60; $m = ($m <= 9) ? "0$m" : $m;
$d = (int)($h / 24); $h = $h % 24;
return $d."d $h:$m:$s";
}
echo "http://bitcointalk.org/index.php?topic=471.0";exit;
// Where does this go?
// <bd_> To compute the number of hashes needed to reach a success probability of P_targ, you'll want n >= log(P_targ)/log(1-P)
// <bd_> So time needed is (log(P_targ)/log(1-P))/rate


// <bd_> To compute the probability per second, you'll want 1-(1-p)^rate, where p is the probability of a single hash being correct
//$pps = bcdiv(bcmul($target,1000),bcpow(2,256)); // probability per second (according to bd_ this is wrong)
bcscale(16); // Next calculation takes too long for higher bits
$pps = bcsub(1,bcpow(bcsub(1,$pph),$rate)); // probability per second
//echo "probabiliy per second == 1-(1-p)^rate == 1-(1-$pph)^$rate == $pps";exit;
// Comment next line for 256-bits of data
bcscale(16);
$ppr = bcmul($pps,$rate);
//$ppr = $pps;
$etaAvg = humantime(bcdiv(1,$ppr));
$eta25 = humantime(bcdiv(-log(.75),$ppr));
$eta50 = humantime(bcdiv(-log(.5),$ppr));
$eta75 = humantime(bcdiv(-log(.25),$ppr));
$eta95 = humantime(bcdiv(-log(.05),$ppr));
$eta99 = humantime(bcdiv(-log(.01),$ppr));
echo "ProbabilityPerSecond($ppr) Avg($etaAvg) 25%($eta25) 50%($eta50) 75%($eta75) 95%($eta95) 99%($eta99)";
} else echo "This command requires either no argument or a numeric argument representing khash/sec.";
}
else {
bcscale(32);
$pph = bcmul($pph,1);
echo "ProbabilityPerHash($pph)";
}

http://nullvoid.org/bitcoin/bc.php?q=gethashprobability&r=2000 where r is your khash/sec
169  Bitcoin / Development & Technical Discussion / Timestamps on: July 18, 2010, 10:16:21 PM
For a few days I have been collecting timestamps of generated blocks the moment my system noticed a new generated block.  A short while ago I learned that I can extract timestamp information from the p2p network itself.  After some manual analysis of my data and the data extracted from the p2p network, I noticed that durations between generated blocks were almost accurate, but in several cases my system's calculations were off by as many as several minutes.  I determined this may be caused due to some blocks being generated by nodes in which it takes longer for information of a block being generated from reaching my or all other nodes, however I am uncertain.
   
To determine timestamp data from the p2p network I used the following:
Code:
cat ~/.bitcoin/debug.log > out
bitcoin -printblock

I executed this at three separate total generated blocks.  Here's some comparing information from the headers of each log.

Code:
68,845 (32963420 bytes total)
Loaded 9173 addresses
LoadBlockIndex(): hashBestChain=00000000000394ae  height=68844
mapBlockIndex.size() = 68880
nBestHeight = 68844

Code:
68,858 (32771350 bytes total)
Loaded 9190 addresses
LoadBlockIndex(): hashBestChain=00000000000052ff  height=68857
mapBlockIndex.size() = 68893
nBestHeight = 68857

Code:
68,943 (32837629 bytes total)
Loaded 9407 addresses
LoadBlockIndex(): hashBestChain=00000000015364ae  height=68942
mapBlockIndex.size() = 68978
nBestHeight = 68942

I determined that in the log datas that each line beginning with "CBlock"  and containing "nTime" were information regarding block generation.  However it seemed strange to me that the output produced from 68,858 was less data than from 68,845.

68,845 log output has 69,402 CBlock lines.  (557 CBlock lines more than blocks generated)
68,858 log output has 68,893 CBlock lines.  (35 CBlock lines more than blocks generated)
68,943 log output has 68,978 CBlock lines.  (35 CBlock lines more than blocks generated)

In both logs for 68,858 and 68,943 the number of CBlock lines matches mapBlockIndex.size(), but not for 68,845.  Is my log data inaccurate or is there another explanation for this?
   
-

After obtaining this data, I parsed it using the following:
Code:
grep CBlock logfile|cut -b 99-108|sort

This provided sequential timestamp information that I used to compare my log data to the official datas produced by Bitcoin p2p system.
As a note, I noticed some of the timestamps were not unique, and duplicated.

Code:
# grep CBlock debug.log.68943 |cut -b 99-108|sort|wc -l
68978
death .bitcoin # grep CBlock debug.log.68943 |cut -b 99-108|sort|uniq|wc -l
68938

However, it is impossible for the log for 68,943 blocks to only have data for 68,938 (less) blocks, so I conclude that some blocks were generated at the same timestamp as a previously generated block and this debunk's gavin's suggestions that timestamps will be unique [ http://bitcointalk.org/index.php?topic=457.msg4042#msg4042 ].

Comparing my system log data to the data output from log data for 68,858 I found a pattern in durations between block generation and was able to match up which timestamp was associated with which block being generated.  The log data from `bitcoin -printblock` does not indicate which block is associated with a timestamp.  Therefore I had to either assume or use my existing data, which I did.  However, because there are more CBlock lines then actual generated blocks in all log files, I am uncertain as to how to proceed in excluding a certain CBlock line from my further analysis to match up timestamps with generated blocks.  I do notice that both logs for 68,858 and 68,943 have only 35 CBlock lines more, and that may be helpful to understanding which CBlocks are unrelated/something else, but for now I ask the community/devs if they can help explain this better.


Quote
<necrodearia> I have determined that some generated blocks have the same timestamp as a previously generated block: http://bitcointalk.org/index.php?topic=464.0
<necrodearia> Where does the timestamp information come from?
<ArtForz> don't forget -printblock also prints "deadend" blocks
<lfm> prolly from the orginating PC clock
<ArtForz> PC clock +- offset averaged from peers
<necrodearia> ArtForz, I didn't know that.  you should answer that question in the thread so others know also
<necrodearia> What is a deadend block?  Or, if you elaborate more in forum thread, I'll read it there.
<ArtForz> well, when 2 clients near-simultaneously find a hash, *both* blocks get spread over the network
<ArtForz> so we have 2 blocks with the same hashPrevBlock
<ArtForz> and basically the overall network "decides" which block is the "real" one, which gets used as hashPrevBlock for the next block
<ArtForz> but those "deadend" blocks still stay in the db, and -printblocks dumps em

ArtForz contributed this chunk of code which extracts timestamp information from blk0001.dat
Code:
#!/usr/bin/env python
import struct
import hashlib

def uint256_deser(s):
r = 0L
for i in xrange(8):
t = struct.unpack("<I", s[i*4:i*4+4])[0]
r += t << (i * 32)
return r

def uint256_ser(u):
rs = ""
for i in xrange(8):
rs += struct.pack("<I", u & 0xFFFFFFFFL)
u >>= 32
return rs

def uint256_from_compact(c):
nbytes = (c >> 24) & 0xFF
v = (c & 0xFFFFFFL) << (8 * (nbytes - 3))
return v

def get_difficulty(c):
return float(uint256_from_compact(0x1D00FFFF) * 1000 // uint256_from_compact(c)) / 1000.

class CBlock:
def deserialize(self, s):
self.nVersion = struct.unpack("<i", s[0:4])[0]
self.hashPrevBlock = uint256_deser(s[4:36])
self.hashMerkleRoot = uint256_deser(s[36:68])
self.nTime = struct.unpack("<I", s[68:72])[0]
self.nBits = struct.unpack("<I", s[72:76])[0]
self.nNonce = struct.unpack("<I", s[76:80])[0]
h1 = hashlib.sha256(s[0:80]).digest()
self.hash = uint256_deser(hashlib.sha256(h1).digest())
if self.hash > uint256_from_compact(self.nBits):
raise ValueError("bad hash in %s" % repr(self))
self.next = []
self.blocknum = -1
def __repr__(self):
return "CBlock{ver=%08x hp=%064x hm=%064x nt=%08x nb=%08x nn=%08x h=%064x, n=%i}" % (self.nVersion, self.hashPrevBlock, self.hashMerkleRoot, self.nTime, self.nBits, self.nNonce, self.hash, self.blocknum)

def get_chain_len(blk):
r = 1
while len(blk.next) == 1:
blk = blk.next[0]
r += 1
if len(blk.next) > 1:
bestchainlen = 0
for nextblk in blk.next:
chainlen = get_chain_len(nextblk)
if chainlen > bestchainlen:
bestchainlen = chainlen
r += bestchainlen
return r


def readblocks(filename):
f = open(filename, "rb")
blocks = []
idxmap = {}
while True:
try:
magic = f.read(4)
if magic != "\xf9\xbe\xb4\xd9":
break
blklen = struct.unpack("<i", f.read(4))[0]
if blklen < 80:
break
blkdata = f.read(blklen)
if len(blkdata) != blklen:
break
except:
break
blk = CBlock()
blk.deserialize(blkdata)
blocks.append(blk)
idxmap[blk.hash] = blk
if blk.hashPrevBlock:
prevblk = idxmap[blk.hashPrevBlock]
blk.prev = prevblk
prevblk.next.append(blk)
f.close()
rootblk = blocks[0]
del blocks
del idxmap
blk = rootblk
curblkidx = 0
while True:
blk.blocknum = curblkidx
if len(blk.next) == 0:
blk.next = None
break
if len(blk.next) > 1:
bestnextblk = None
bestchainlen = 0
for nextblk in blk.next:
chainlen = get_chain_len(nextblk)
if chainlen > bestchainlen:
bestchainlen = chainlen
bestnextblk = nextblk
elif chainlen == bestchainlen:
if nextblk.nTime < bestnextblk.nTime:
bestchainlen = chainlen
bestnextblk = nextblk
blk.next = [bestnextblk]
blk.next = blk.next[0]
curblkidx += 1
blk = blk.next

blk = rootblk
while blk:
#print "%i %i %.3f 0x%08X" % (blk.blocknum, blk.nTime, get_difficulty(blk.nBits), blk.nBits)
avghashes = 2**256 / uint256_from_compact(blk.nBits)
print "%i %i %i" % (blk.blocknum, blk.nTime, avghashes)
blk = blk.next

if __name__ == "__main__":
readblocks("/home/necro/.bitcoin/blk0001.dat")
170  Bitcoin / Development & Technical Discussion / Calculate Hash Target and Probability in PHP on: July 17, 2010, 04:37:09 AM
I am trying to prepare PHP code to calculate exact value for Hash Target similar as to displayed at http://www.alloscomp.com/bitcoin/calculator.php (currently: 1.48501965484E+65).

Can someone help me to refine my code?

http://jsonrpcphp.org/?page=download&lang=en

Calculate current hash target:
Code:
<?
header("Content-type: text/plain");
require_once 'jsonRPCClient.php';
$data=new jsonRPCClient('http://127.0.0.1:8332');
$difficulty = floatval($data->getdifficulty());
//     $a      /         $b
// (2^256 - 1) / (2^32 * difficulty)

bcscale(256);

$a = bcsub(bcpow(2,256),1);
//$a = gmp_strval(gmp_sub(gmp_pow(2,256),1));

$b = bcmul(bcpow(2,32),$difficulty);
//$b = pow(2,32) * $difficulty;

bcscale(0);

$target = bcdiv($a,$b);
//$target = gmp_strval(gmp_div($a,$b));
//$target = bcdiv($a,$b);
//$target = "148504231478890412392775945444335243545681910455595839046778120430";
//$target = "148504231478000000000000000000000000000000000000000000000000000000";
//$target = "148501965484000000000000000000000000000000000000000000000000000000";

//000000000168fd00000000000000000000000000000000000000000000000000
//         168fcfffffee48119ddbfdc811138960d70605cc300000000000000

$targethex = gmp_strval(gmp_sub($target,0),16);

echo "Current Hash Target: Dec($target)    Hex($targethex)";
?>

Calculate probability:
Code:
<?
bcscale(256);
$pph = bcdiv($target,bcpow(2,256)); // probability per hash
if (isset($_GET["r"]) && $_GET["r"] != "") { // user-defined rate
$rate = $_GET["r"];
if (is_numeric($rate)) {
function humantime($secs) {
if ($secs<0) return false;
$m = (int)($secs / 60); $s = $secs % 60; $s = ($s <= 9) ? "0$s" : $s;
$h = (int)($m / 60); $m = $m % 60; $m = ($m <= 9) ? "0$m" : $m;
$d = (int)($h / 24); $h = $h % 24;
return $d."d $h:$m:$s";
}
$pps = bcdiv(bcmul($target,1000),bcpow(2,256)); // probability per second
bcscale(16);
$ppr = bcmul($pps,$rate);
$etaAvg = humantime(bcdiv(1,$ppr));
$eta25 = humantime(bcdiv(-log(.75),$ppr));
$eta50 = humantime(bcdiv(-log(.5),$ppr));
$eta75 = humantime(bcdiv(-log(.25),$ppr));
$eta95 = humantime(bcdiv(-log(.05),$ppr));
$eta99 = humantime(bcdiv(-log(.01),$ppr));
echo "ProbabilityPerSecond($ppr) Avg($etaAvg) 25%($eta25) 50%($eta50) 75%($eta75) 95%($eta95) 99%($eta99)";
} else echo "This requires either no argument or a numeric argument representing khash/sec.";
}
else {
bcscale(32);
$pph = bcmul($pph,1);
echo "ProbabilityPerHash($pph)";
}
?>
171  Bitcoin / Development & Technical Discussion / SMS/Text Messaging Integration? on: July 17, 2010, 12:42:19 AM
is there any usefulness for SMS/Text Messaging integration with Bitcoin in any way?
172  Bitcoin / Development & Technical Discussion / Some Statistics on: July 16, 2010, 05:24:25 AM
http://nullvoid.org/bitcoin/statistix.php
http://nullvoid.org/bitcoin/statistix.php?showallblocks (if you want to see timestamps for all 69,000+ blocks until now) (2.5Mb+ output)
http://jsonrpcphp.org/?page=download&lang=en

statistix.php
Code:
<?
header("Content-type: text/html");
require_once 'jsonRPCClient.php';
$data=new jsonRPCClient('http://127.0.0.1:8332');
$blockcount = $data->getblockcount();
$now = date("U");

$blockfile = "blockdata";
$data = file($blockfile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); array_pop($data);
foreach ($data as $line) {
$blocks = strtok($line, " ");
$date = strtok(" ");
$avghash = strtok(" ");
}
?><html>
 <head>
  <meta http-equiv="refresh" content="100000">
 </head>
 <body><pre>
<?
$data = array_reverse($data);
echo " /-             Statistix             -\\\n";
echo "|            <a href=\"http://bitcointalk.org/index.php?topic=402.msg3395#msg3395\">PHP Source Code</a>            |\n";
echo "|---------------------------------------|\n";
echo "|   Last block discovered in duration   |\n";
echo "|       and when it was discovered      |\n";
echo "|---------------------------------------|\n";
echo "|          Now  $now              |\n";
$lastdate = $now - $date; $lastdate .= ($lastdate == 1) ? " sec" : " secs"; $lastdate .= str_repeat(" ", 10 - strlen($lastdate));
$lastblock = trim($blocks); $lastblock .= str_repeat(" ", 12 - strlen($lastblock));
echo "|   Last Block  $lastdate:$lastblock |\n";
$block = array();
foreach ($data as $line) {
$blocks = strtok($line, " ");
$date = strtok(" ");
$avghash = strtok(" ");
$block[$blocks] = $date;
if (($now - 60) <= $date) { $min01date = $date; $min01blocks = $blocks; }
if (($now - 120) <= $date) { $min02date = $date; $min02blocks = $blocks; }
if (($now - 180) <= $date) { $min03date = $date; $min03blocks = $blocks; }
if (($now - 240) <= $date) { $min04date = $date; $min04blocks = $blocks; }
if (($now - 300) <= $date) { $min05date = $date; $min05blocks = $blocks; }
if (($now - 600) <= $date) { $min10date = $date; $min10blocks = $blocks; }
if (($now - 1200) <= $date) { $min20date = $date; $min20blocks = $blocks; }
if (($now - 1800) <= $date) { $min30date = $date; $min30blocks = $blocks; }
if (($now - 2400) <= $date) { $min40date = $date; $min40blocks = $blocks; }
if (($now - 3000) <= $date) { $min50date = $date; $min50blocks = $blocks; }
if (($now - 3600) <= $date) { $hr01date = $date; $hr01blocks = $blocks; }
if (($now - 7200) <= $date) { $hr02date = $date; $hr02blocks = $blocks; }
if (($now - 10800) <= $date) { $hr03date = $date; $hr03blocks = $blocks; }
if (($now - 14400) <= $date) { $hr04date = $date; $hr04blocks = $blocks; }
if (($now - 18000) <= $date) { $hr05date = $date; $hr05blocks = $blocks; }
if (($now - 21600) <= $date) { $hr06date = $date; $hr06blocks = $blocks; }
if (($now - 51200) <= $date) { $hr12date = $date; $hr12blocks = $blocks; }
if (($now - 102400) <= $date) { $day1date = $date; $day1blocks = $blocks; }
if (($now - 204800) <= $date) { $day2date = $date; $day2blocks = $blocks; }
if (($now - 307200) <= $date) { $day3date = $date; $day3blocks = $blocks; }
if (($now - 409600) <= $date) { $day4date = $date; $day4blocks = $blocks; }
if (($now - 512000) <= $date) { $day5date = $date; $day5blocks = $blocks; }
if (($now - 614400) <= $date) { $day6date = $date; $day6blocks = $blocks; }
if (($now - 716800) <= $date) { $wk01date = $date; $wk01blocks = $blocks; }
if (($now - 1433600) <= $date) { $wk02date = $date; $wk02blocks = $blocks; }
if (($now - 2150400) <= $date) { $wk03date = $date; $wk03blocks = $blocks; }
if (($now - 2867200) <= $date) { $wk04date = $date; $wk04blocks = $blocks; }
if (($now - 5734400) <= $date) { $wk08date = $date; $wk08blocks = $blocks; }
if (($now - 11468800) <= $date) { $wk16date = $date; $wk16blocks = $blocks; }
if (($now - 22937600) <= $date) { $wk32date = $date; $wk32blocks = $blocks; }
if (($now - 37376000) <= $date) { $yr1date = $date; $yr1blocks = $blocks; }
}

if ($min01blocks == "") $min01 = ""; else $min01 = "$min01date:$min01blocks";
if ($min02blocks == "") $min02 = ""; else $min02 = "$min02date:$min02blocks";
if ($min03blocks == "") $min03 = ""; else $min03 = "$min03date:$min03blocks";
if ($min04blocks == "") $min04 = ""; else $min04 = "$min04date:$min04blocks";
if ($min05blocks == "") $min05 = ""; else $min05 = "$min05date:$min05blocks";
if ($min10blocks == "") $min10 = ""; else $min10 = "$min10date:$min10blocks";
if ($min20blocks == "") $min20 = ""; else $min20 = "$min20date:$min20blocks";
if ($min30blocks == "") $min30 = ""; else $min30 = "$min30date:$min30blocks";
if ($min40blocks == "") $min40 = ""; else $min40 = "$min40date:$min40blocks";
if ($min50blocks == "") $min50 = ""; else $min50 = "$min50date:$min50blocks";
if ($hr01blocks == "") $hr01 = ""; else $hr01 = "$hr01date:$hr01blocks";
if ($hr02blocks == "") $hr02 = ""; else $hr02 = "$hr02date:$hr02blocks";
if ($hr03blocks == "") $hr03 = ""; else $hr03 = "$hr03date:$hr03blocks";
if ($hr04blocks == "") $hr04 = ""; else $hr04 = "$hr04date:$hr04blocks";
if ($hr05blocks == "") $hr05 = ""; else $hr05 = "$hr05date:$hr05blocks";
if ($hr06blocks == "") $hr06 = ""; else $hr06 = "$hr06date:$hr06blocks";
if ($hr12blocks == "") $hr12 = ""; else $hr12 = "$hr12date:$hr12blocks";
if ($day1blocks == "") $day1 = ""; else $day1 = "$day1date:$day1blocks";
if ($day2blocks == "") $day2 = ""; else $day2 = "$day2date:$day2blocks";
if ($day3blocks == "") $day3 = ""; else $day3 = "$day3date:$day3blocks";
if ($day4blocks == "") $day4 = ""; else $day4 = "$day4date:$day4blocks";
if ($day5blocks == "") $day5 = ""; else $day5 = "$day5date:$day5blocks";
if ($day6blocks == "") $day6 = ""; else $day6 = "$day6date:$day6blocks";
if ($wk01blocks == "") $wk01 = ""; else $wk01 = "$wk01date:$wk01blocks";
if ($wk02blocks == "") $wk02 = ""; else $wk02 = "$wk02date:$wk02blocks";
if ($wk03blocks == "") $wk03 = ""; else $wk03 = "$wk03date:$wk03blocks";
if ($wk04blocks == "") $wk04 = ""; else $wk04 = "$wk04date:$wk04blocks";
if ($wk08blocks == "") $wk08 = ""; else $wk08 = "$wk08date:$wk08blocks";
if ($wk16blocks == "") $wk16 = ""; else $wk16 = "$wk16date:$wk16blocks";
if ($wk32blocks == "") $wk32 = ""; else $wk32 = "$wk32date:$wk32blocks";
if ($yr1blocks == "") $yr1 = ""; else $yr1 = "$yr1date:$yr1blocks";

echo "|    1min  ago  ".$min01.str_repeat(" ", 24 - strlen($min01))."|\n";
echo "|    2min  ago  ".$min02.str_repeat(" ", 24 - strlen($min02))."|\n";
echo "|    3min  ago  ".$min03.str_repeat(" ", 24 - strlen($min03))."|\n";
echo "|    4min  ago  ".$min04.str_repeat(" ", 24 - strlen($min04))."|\n";
echo "|    5min  ago  ".$min05.str_repeat(" ", 24 - strlen($min05))."|\n";
echo "|   10min  ago  ".$min10.str_repeat(" ", 24 - strlen($min10))."|\n";
echo "|   20min  ago  ".$min20.str_repeat(" ", 24 - strlen($min20))."|\n";
echo "|   30min  ago  ".$min30.str_repeat(" ", 24 - strlen($min30))."|\n";
echo "|   40min  ago  ".$min40.str_repeat(" ", 24 - strlen($min40))."|\n";
echo "|   50min  ago  ".$min50.str_repeat(" ", 24 - strlen($min50))."|\n";
echo "|    1hr   ago  ".$hr01.str_repeat(" ", 24 - strlen($hr01))."|\n";
echo "|    2hrs  ago  ".$hr02.str_repeat(" ", 24 - strlen($hr02))."|\n";
echo "|    3hrs  ago  ".$hr03.str_repeat(" ", 24 - strlen($hr03))."|\n";
echo "|    4hrs  ago  ".$hr04.str_repeat(" ", 24 - strlen($hr04))."|\n";
echo "|    5hrs  ago  ".$hr05.str_repeat(" ", 24 - strlen($hr05))."|\n";
echo "|    6hrs  ago  ".$hr06.str_repeat(" ", 24 - strlen($hr06))."|\n";
echo "|   12hrs  ago  ".$hr12.str_repeat(" ", 24 - strlen($hr12))."|\n";
echo "|    1day  ago  ".$day1.str_repeat(" ", 24 - strlen($day1))."|\n";
echo "|    2days ago  ".$day2.str_repeat(" ", 24 - strlen($day2))."|\n";
echo "|    3days ago  ".$day3.str_repeat(" ", 24 - strlen($day3))."|\n";
echo "|    4days ago  ".$day4.str_repeat(" ", 24 - strlen($day4))."|\n";
echo "|    5days ago  ".$day5.str_repeat(" ", 24 - strlen($day5))."|\n";
echo "|    6days ago  ".$day6.str_repeat(" ", 24 - strlen($day6))."|\n";
echo "|    1wk   ago  ".$wk01.str_repeat(" ", 24 - strlen($wk01))."|\n";
echo "|    2wks  ago  ".$wk02.str_repeat(" ", 24 - strlen($wk02))."|\n";
echo "|    3wks  ago  ".$wk03.str_repeat(" ", 24 - strlen($wk03))."|\n";
echo "|    4wks  ago  ".$wk04.str_repeat(" ", 24 - strlen($wk04))."|\n";
echo "|    8wks  ago  ".$wk08.str_repeat(" ", 24 - strlen($wk08))."|\n";
echo "|   16wks  ago  ".$wk16.str_repeat(" ", 24 - strlen($wk16))."|\n";
echo "|   32wks  ago  ".$wk32.str_repeat(" ", 24 - strlen($wk32))."|\n";
echo "|    1yr   ago  ".$yr1.str_repeat(" ", 24 - strlen($yr1))."|\n";
echo "|---------------------------------------/\n";
if (isset($min01blocks)) $min01c = ($blockcount - $min01blocks); else $min01c = 0; echo "| ".fill(number_format($min01c, 0, ".", ","),9)." blocks in last minute\n";
if (isset($min02blocks)) $min02c = ($blockcount - $min02blocks); else $min02c = 0; echo "| ".fill(number_format($min02c, 0, ".", ","),9)." blocks in last 2 mins\n";
if (isset($min03blocks)) $min03c = ($blockcount - $min03blocks); else $min03c = 0; echo "| ".fill(number_format($min03c, 0, ".", ","),9)." blocks in last 3 mins\n";
if (isset($min04blocks)) $min04c = ($blockcount - $min04blocks); else $min04c = 0; echo "| ".fill(number_format($min04c, 0, ".", ","),9)." blocks in last 4 mins\n";
if (isset($min05blocks)) $min05c = ($blockcount - $min05blocks); else $min05c = 0; echo "| ".fill(number_format($min05c, 0, ".", ","),9)." blocks in last 5 mins\n";
if (isset($min10blocks)) $min10c = ($blockcount - $min10blocks); else $min10c = 0; echo "| ".fill(number_format($min10c, 0, ".", ","),9)." blocks in last 10 mins\n";
if (isset($min20blocks)) $min20c = ($blockcount - $min20blocks); else $min20c = 0; echo "| ".fill(number_format($min20c, 0, ".", ","),9)." blocks in last 20 mins\n";
if (isset($min30blocks)) $min30c = ($blockcount - $min30blocks); else $min30c = 0; echo "| ".fill(number_format($min30c, 0, ".", ","),9)." blocks in last 30 mins\n";
if (isset($min40blocks)) $min40c = ($blockcount - $min40blocks); else $min40c = 0; echo "| ".fill(number_format($min40c, 0, ".", ","),9)." blocks in last 40 mins\n";
if (isset($min50blocks)) $min50c = ($blockcount - $min50blocks); else $min50c = 0; echo "| ".fill(number_format($min50c, 0, ".", ","),9)." blocks in last 50 mins\n";
if (isset($hr01blocks)) $hr01c = ($blockcount - $hr01blocks); else $hr01c = 0; echo "| ".fill(number_format($hr01c, 0, ".", ","),9)." blocks in last hour\n";
if (isset($hr02blocks)) $hr02c = ($blockcount - $hr02blocks); else $hr02c = 0; echo "| ".fill(number_format($hr02c, 0, ".", ","),9)." blocks in last 2 hrs";echo "    blocks/hr avg: ".($hr02c / 2)."\n";
if (isset($hr03blocks)) $hr03c = ($blockcount - $hr03blocks); else $hr03c = 0; echo "| ".fill(number_format($hr03c, 0, ".", ","),9)." blocks in last 3 hrs";echo "    blocks/hr avg: ".($hr03c / 3)."\n";
if (isset($hr04blocks)) $hr04c = ($blockcount - $hr04blocks); else $hr04c = 0; echo "| ".fill(number_format($hr04c, 0, ".", ","),9)." blocks in last 4 hrs";echo "    blocks/hr avg: ".($hr04c / 4)."\n";
if (isset($hr05blocks)) $hr05c = ($blockcount - $hr05blocks); else $hr05c = 0; echo "| ".fill(number_format($hr05c, 0, ".", ","),9)." blocks in last 5 hrs";echo "    blocks/hr avg: ".($hr05c / 5)."\n";
if (isset($hr06blocks)) $hr06c = ($blockcount - $hr06blocks); else $hr06c = 0; echo "| ".fill(number_format($hr06c, 0, ".", ","),9)." blocks in last 6 hrs";echo "    blocks/hr avg: ".($hr06c / 6)."\n";
if (isset($hr12blocks)) $hr12c = ($blockcount - $hr12blocks); else $hr12c = 0; echo "| ".fill(number_format($hr12c, 0, ".", ","),9)." blocks in last 12 hrs";echo "   blocks/hr avg: ".($hr12c / 12)."\n";
if (isset($day1blocks)) $day1c = ($blockcount - $day1blocks); else $day1c = 0; echo "| ".fill(number_format($day1c, 0, ".", ","),9)." blocks in last day";echo "      blocks/hr avg: ".($day1c / 24)."\n";
if (isset($day2blocks)) $day2c = ($blockcount - $day2blocks); else $day2c = 0; echo "| ".fill(number_format($day2c, 0, ".", ","),9)." blocks in last 2 days";echo "   blocks/hr avg: ".($day2c / 48)."\n";
if (isset($day3blocks)) $day3c = ($blockcount - $day3blocks); else $day3c = 0; echo "| ".fill(number_format($day3c, 0, ".", ","),9)." blocks in last 3 days";echo "   blocks/hr avg: ".($day3c / 72)."\n";
if (isset($day4blocks)) $day4c = ($blockcount - $day4blocks); else $day4c = 0; echo "| ".fill(number_format($day4c, 0, ".", ","),9)." blocks in last 4 days";echo "   blocks/hr avg: ".($day4c / 96)."\n";
if (isset($day5blocks)) $day5c = ($blockcount - $day5blocks); else $day5c = 0; echo "| ".fill(number_format($day5c, 0, ".", ","),9)." blocks in last 5 days";echo "   blocks/hr avg: ".($day5c / 120)."\n";
if (isset($day6blocks)) $day6c = ($blockcount - $day6blocks); else $day6c = 0; echo "| ".fill(number_format($day6c, 0, ".", ","),9)." blocks in last 6 days";echo "   blocks/hr avg: ".($day6c / 144)."\n";
if (isset($wk01blocks)) $wk01c = ($blockcount - $wk01blocks); else $wk01c = 0; echo "| ".fill(number_format($wk01c, 0, ".", ","),9)." blocks in last week";echo "     blocks/hr avg: ".($wk01c / 168)."\n";
if (isset($wk02blocks)) $wk02c = ($blockcount - $wk02blocks); else $wk02c = 0; echo "| ".fill(number_format($wk02c, 0, ".", ","),9)." blocks in last 2 wks";echo "    blocks/hr avg: ".($wk02c / 336)."\n";
if (isset($wk03blocks)) $wk03c = ($blockcount - $wk03blocks); else $wk03c = 0; echo "| ".fill(number_format($wk03c, 0, ".", ","),9)." blocks in last 3 wks";echo "    blocks/hr avg: ".($wk03c / 504)."\n";
if (isset($wk04blocks)) $wk04c = ($blockcount - $wk04blocks); else $wk04c = 0; echo "| ".fill(number_format($wk04c, 0, ".", ","),9)." blocks in last 4 wks";echo "    blocks/hr avg: ".($wk04c / 672)."\n";
if (isset($wk08blocks)) $wk08c = ($blockcount - $wk08blocks); else $wk08c = 0; echo "| ".fill(number_format($wk08c, 0, ".", ","),9)." blocks in last 8 wks";echo "    blocks/hr avg: ".($wk08c / 1344)."\n";
if (isset($wk16blocks)) $wk16c = ($blockcount - $wk16blocks); else $wk16c = 0; echo "| ".fill(number_format($wk16c, 0, ".", ","),9)." blocks in last 16 wks";echo "   blocks/hr avg: ".($wk16c / 2688)."\n";
if (isset($wk32blocks)) $wk32c = ($blockcount - $wk32blocks); else $wk32c = 0; echo "| ".fill(number_format($wk32c, 0, ".", ","),9)." blocks in last 32 wks";echo "   blocks/hr avg: ".($wk32c / 5376)."\n";
if (isset($yr1blocks)) $yr1c = ($blockcount - $yr1blocks); else $yr1c = 0; echo "| ".fill(number_format($yr1c, 0, ".", ","),9)." blocks in last year";echo "     blocks/hr avg: ".($yr1c / 8760)."\n";
echo "\----------------------------------------";
if (isset($_GET["showallblocks"])) {
echo "\n\n";
foreach ($block as $key => $num) {
$secs = $block[$key] - $block[$key-1];
$secs .= ($secs == 1) ? " second " : " seconds";
$secs = str_repeat(" ", 14 - strlen($secs)).$secs;
if (isset($block[$key-1])) echo "$secs to find block $key\n";
else echo "  unknown time to find block $key\n";
}
} else {
echo "\\\n   <a href=\"$PHP_SELF?showallblocks\">Timestamp data for all ".number_format($blockcount)." blocks</a>  |\n";
echo "                 ~".number_format(filesize($blockfile) * 1.23175 / 1024 / 1024, 2)."Mb                 |\n";
echo "-----------------------------------------/";
}
function fill($str, $len) { return str_repeat(" ", $len - strlen($str)).$str; }
?>
 </pre></body>
</html>

Additionally, "blockdata" is updated every minute using a cron script written in python.  This python code populates "blockdata" with "<blocknum> <timestamp> <avghashes>"
courtesy of ArtForz

getblockdata.py
Code:
#!/usr/bin/env python
import struct
import hashlib

def uint256_deser(s):
r = 0L
for i in xrange(8):
t = struct.unpack("<I", s[i*4:i*4+4])[0]
r += t << (i * 32)
return r

def uint256_ser(u):
rs = ""
for i in xrange(8):
rs += struct.pack("<I", u & 0xFFFFFFFFL)
u >>= 32
return rs

def uint256_from_compact(c):
nbytes = (c >> 24) & 0xFF
v = (c & 0xFFFFFFL) << (8 * (nbytes - 3))
return v

def get_difficulty(c):
return float(uint256_from_compact(0x1D00FFFF) * 1000 // uint256_from_compact(c)) / 1000.

class CBlock:
def deserialize(self, s):
self.nVersion = struct.unpack("<i", s[0:4])[0]
self.hashPrevBlock = uint256_deser(s[4:36])
self.hashMerkleRoot = uint256_deser(s[36:68])
self.nTime = struct.unpack("<I", s[68:72])[0]
self.nBits = struct.unpack("<I", s[72:76])[0]
self.nNonce = struct.unpack("<I", s[76:80])[0]
h1 = hashlib.sha256(s[0:80]).digest()
self.hash = uint256_deser(hashlib.sha256(h1).digest())
if self.hash > uint256_from_compact(self.nBits):
raise ValueError("bad hash in %s" % repr(self))
self.next = []
self.blocknum = -1
def __repr__(self):
return "CBlock{ver=%08x hp=%064x hm=%064x nt=%08x nb=%08x nn=%08x h=%064x, n=%i}" % (self.nVersion, self.hashPrevBlock, self.hashMerkleRoot, self.nTime, self.nBits, self.nNonce, self.hash, self.blocknum)

def get_chain_len(blk):
r = 1
while len(blk.next) == 1:
blk = blk.next[0]
r += 1
if len(blk.next) > 1:
bestchainlen = 0
for nextblk in blk.next:
chainlen = get_chain_len(nextblk)
if chainlen > bestchainlen:
bestchainlen = chainlen
r += bestchainlen
return r


def readblocks(filename):
f = open(filename, "rb")
blocks = []
idxmap = {}
while True:
try:
magic = f.read(4)
if magic != "\xf9\xbe\xb4\xd9":
break
blklen = struct.unpack("<i", f.read(4))[0]
if blklen < 80:
break
blkdata = f.read(blklen)
if len(blkdata) != blklen:
break
except:
break
blk = CBlock()
blk.deserialize(blkdata)
blocks.append(blk)
idxmap[blk.hash] = blk
if blk.hashPrevBlock:
prevblk = idxmap[blk.hashPrevBlock]
blk.prev = prevblk
prevblk.next.append(blk)
f.close()
rootblk = blocks[0]
del blocks
del idxmap
blk = rootblk
curblkidx = 0
while True:
blk.blocknum = curblkidx
if len(blk.next) == 0:
blk.next = None
break
if len(blk.next) > 1:
bestnextblk = None
bestchainlen = 0
for nextblk in blk.next:
chainlen = get_chain_len(nextblk)
if chainlen > bestchainlen:
bestchainlen = chainlen
bestnextblk = nextblk
elif chainlen == bestchainlen:
if nextblk.nTime < bestnextblk.nTime:
bestchainlen = chainlen
bestnextblk = nextblk
blk.next = [bestnextblk]
blk.next = blk.next[0]
curblkidx += 1
blk = blk.next

blk = rootblk
while blk:
#print "%i %i %.3f 0x%08X" % (blk.blocknum, blk.nTime, get_difficulty(blk.nBits), blk.nBits)
avghashes = 2**256 / uint256_from_compact(blk.nBits)
print "%i %i %i" % (blk.blocknum, blk.nTime, avghashes)
blk = blk.next

if __name__ == "__main__":
print readblocks("/path/to/blk0001.dat")

line for cron
Code:
*/1     *       *       *       *       /path/to/getblockdata.py > /path/to/blockdata
173  Bitcoin / Bitcoin Discussion / Seeking Funding or Hosting on: July 15, 2010, 05:48:07 AM
I'm recently unemployed and have since established much interest in Bitcoin community as well as contributing developmental aspects towards some related things, but I need a job to survive/support myself.  Is anyone hiring?  :3
174  Bitcoin / Bitcoin Discussion / Official Bitcoin Unicode Character? on: July 15, 2010, 03:02:28 AM
I suggest a character representative of symbol for Bitcoin currency be submitted to http://unicode.org/pending/proposals.html

฿ doesn't seem to be worthy considering it already is well established as Thai baht (currency).
Pages: « 1 2 3 4 5 6 7 8 [9]
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!