Bitcointalk**Search**

It was the Bitcointalk forum that inspired us to create Bitcointalksearch.org - Bitcointalk is an excellent site that should be the default page for anybody dealing in cryptocurrency, since it is a virtual gold-mine of data. However, our experience and user feedback led us create our site; Bitcointalk's search is slow, and difficult to get the results you need, because you need to log in first to find anything useful - furthermore, there are rate limiters for their search functionality.

The aim of our project is to create a faster website that yields more results and faster without having to create an account and eliminate the need to log in - your personal data, therefore, will never be in jeopardy since we are not asking for any of your data and you don't need to provide them to use our site with all of its capabilities.

We created this website with the sole purpose of users being able to search quickly and efficiently in the field of cryptocurrency so they will have access to the latest and most accurate information and thereby assisting the crypto-community at large.

Pages:

Author

nullvoid offline?

Code:

import struct

def SetCompact(nCompact):

"""convert bc compact uint to number"""

nSize = (nCompact >> 24) & 0xFF

tbuf = "\x00\x00\x00" + chr(nSize)

if nSize >= 1:

tbuf += chr((nCompact >> 16) & 0xFF)

if nSize >= 2:

tbuf += chr((nCompact >> 8) & 0xFF)

if nSize >= 3:

tbuf += chr((nCompact >> 0) & 0xFF)

tbuf += "\x00" * (nSize - 3)

return mpi2num(tbuf)

Code:

def uint256_from_compact(c):

nbytes = (c >> 24) & 0xFF

v = (c & 0xFFFFFFL) << (8 * (nbytes - 3))

return v

I confirmed again that both of these produce same output when using 0x1d00ffff

Writing a faster and more pythonic version should be pretty easy, but I can't be arsed right now...

Code:

import struct

def mpi2num(m):

"""convert MPI string to number"""

datasize = struct.unpack(">I", m[0:4])[0]

r = 0

if datasize:

neg_flag = bool(ord(m[4]) & 0x80)

r = ord(m[4]) & 0x7F

for i in xrange(1, datasize):

r <<= 8

r += ord(m[4+i])

if neg_flag:

r = -r

return r

def num2mpi(n):

"""convert number to MPI string"""

if n == 0:

return struct.pack(">I", 0)

r = ""

neg_flag = bool(n < 0)

n = abs(n)

while n:

r = chr(n & 0xFF) + r

n >>= 8

if ord(r[0]) & 0x80:

r = chr(0) + r

if neg_flag:

r = chr(ord(r[0]) | 0x80) + r[1:]

datasize = len(r)

return struct.pack(">I", datasize) + r

def GetCompact(n):

"""convert number to bc compact uint"""

mpi = num2mpi(n)

nSize = len(mpi) - 4

nCompact = (nSize & 0xFF) << 24

if nSize >= 1:

nCompact |= (ord(mpi[4]) << 16)

if nSize >= 2:

nCompact |= (ord(mpi[5]) << 8)

if nSize >= 3:

nCompact |= (ord(mpi[6]) << 0)

return nCompact

def SetCompact(nCompact):

"""convert bc compact uint to number"""

nSize = (nCompact >> 24) & 0xFF

tbuf = "\x00\x00\x00" + chr(nSize)

if nSize >= 1:

tbuf += chr((nCompact >> 16) & 0xFF)

if nSize >= 2:

tbuf += chr((nCompact >> 8) & 0xFF)

if nSize >= 3:

tbuf += chr((nCompact >> 0) & 0xFF)

tbuf += "\x00" * (nSize - 3)

return mpi2num(tbuf)

Code:

CBigNum& SetCompact(unsigned int nCompact) {

unsigned int nSize = nCompact >> 24;

std::vectorvch(4 + nSize);

vch[3] = nSize;

if (nSize >= 1) vch[4] = (nCompact >> 16) & 0xff;

if (nSize >= 2) vch[5] = (nCompact >> 8) & 0xff;

if (nSize >= 3) vch[6] = (nCompact >> 0) & 0xff;

BN_mpi2bn(&vch[0], vch.size(), this);

return *this;

}

With Python equivalent of

Code:

def uint256_from_compact(c):

nbytes = (c >> 24) & 0xFF

v = (c & 0xFFFFFFL) << (8 * (nbytes - 3))

return v

And PHP equvalent of

Code:

function uint256_from_compact($c) {

$nbytes = ($c >> 24) & 0xFF;

return bcmul($c & 0xFFFFFF,bcpow(2,8 * ($nbytes - 3)));

}

then for C++ Getcompact() function

Code:

unsigned int GetCompact() const {

unsigned int nSize = BN_bn2mpi(this, NULL);

std::vectorvch(nSize);

nSize -= 4;

BN_bn2mpi(this, &vch[0]);

unsigned int nCompact = nSize << 24;

if (nSize >= 1) nCompact |= (vch[4] << 16);

if (nSize >= 2) nCompact |= (vch[5] << 8);

if (nSize >= 3) nCompact |= (vch[6] << 0);

return nCompact;

}

how can I produce simplistic code for python/php to produce equivalent function?

My intention is to use the function in this php snippet

Code:

function GetNextWorkRequired($block, $bits, $nActualTimespan) {

$nTargetTimespan = 60 * 60 * 24 * 14; // 2 weeks

if ($nActualTimespan < $nTargetTimespan / 4) { $nActualTimespan = $nTargetTimespan / 4; }

if ($nActualTimespan > $nTargetTimespan * 4) { $nActualTimespan = $nTargetTimespan * 4; }

$bits = uint256_from_compact($bits);

$bits = bcmul($bits,$nActualTimespan);

$bits = bcdiv($bits,$nTargetTimespan);

$bits = uint256_to_compact($bits); // <-- Need to translate C++ code for GetCompact()

return $bits;

}

Code:

bool CBlock::CheckBlock() const

{

...

// Check timestamp

if (nTime > GetAdjustedTime() + 2 * 60 * 60)

return error("CheckBlock() : block timestamp too far in the future");

...

bool CBlock::AcceptBlock()

{

...

// Check timestamp against prev

if (nTime <= pindexPrev->GetMedianTimePast())

return error("AcceptBlock() : block's timestamp is too early");

The timestamp is limited to up to 2 hours in the future. It can be earlier than the previous block, but it must be greater than the median of the last 11 blocks. The reason for doing it that way is so the time can get corrected in the next block if the previous block had the time too far in the future, like what happened.

Code:

-7017 seconds to find block 70719

8153 seconds to find block 70718

49 seconds to find block 70717

524 seconds to find block 70716

Code:

block timestamp

70715 1280275621

70716 1280276145

70717 1280276194

70718 1280284347

70719 1280277330

This doesn't seem to have any effect on things so much other than providing a kind of inaccurate depiction of statistical results every now and then (when a block is claimed to be from the future or the past), however what would happen if either the first or second (whichever one triggers new difficulty being established) of a new set of 2016 blocks is generated to have a timestamp 2+ weeks in the past or the future? If in the past, I presume according to the code in main.cpp: GetNextWorkRequired function that the lowest accepted interval is 3.5 days. And if in the future I presume according to the code the lowest accepted interval is 56 days.

Just imagine how hard it would be to win a block then!!!!!

Hehe, thanks. I could provide more accurate precision, but I think that is good enough.

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);

?>

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 "

";

}

}

?>

Pages:

Jump to: