Hello, I am a newbie here trying to get my head around the hashes mechanism, I am able to call getwork and gotten the:
id
data
hash1
target
midstate
I was looking at an example by "Taro Kudo & friends", and I have two questions:
My question is
1: Why does he do "2809801765-1000000" ?
2: Where did he even get those numbers, how does he "know" the answer of the stnonce before any calculation even began ?
This is his example data:
var midstate:String = "d9dcb3f73ba7083619c3d080e85dace2590fe00398dbbf388579e281cacf233f";
var data:String = "00000001041044ce884d97e1eb77e893d2fa6fdce53faaee42784297000007330000000052c68b98b11cefa06739f5d3a8ffddad25adfac6e0d360a496b8d82f3b40301c4e2581741a0abbcf00000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000";
var hash1:String = "00000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000010000";
var target:String = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000";
This is his example code:
import myClass.BitCoin_Judge;
stop();
var Judge0:BitCoin_Judge = new BitCoin_Judge(midstate,data,target);
var start_time:uint = (new Date().time)/100;
var nonce:uint = 2809801765-1000000;
var stnonce:uint = nonce;
status.text = "Start:" + stnonce;
var timer:Timer = new Timer(1000/12);
timer.addEventListener(TimerEvent.TIMER, onTimer);
var repeat:int = 3000;
var scannedunit:int = 0;
function onTimer(evt:TimerEvent):void
{
for (var ii:int=0; ii<repeat; ii++)
{
if (Judge0.judgement(nonce))
{
hps.text = "solve";
current.text = "nonce= " + nonce;
timer.stop();
removeEventListener(Event.ENTER_FRAME, update);
break;
}
if (nonce == 4294967295)
{
hps.text = "over flow";
timer.stop();
removeEventListener(Event.ENTER_FRAME, update);
break;
}
// Status report for browser
if (nonce % (repeat*10) == 0)
{
var total_time:uint = (new Date().time)/100 - start_time;
hps.text = ((((nonce - stnonce) * 10) / total_time) / 1000).toFixed(2) + " KH/S";
current.text = "Scanned hashes " + Math.round((nonce-stnonce)/1000) + "K";
}
nonce++;
}
}
timer.start();
function zPad(num:String, len:int)
{
var out:String = "" + num;
while (out.length != len)
{
out = "0" + out;
}
return out;
}
addEventListener(Event.ENTER_FRAME, update);
var ms_prev:uint;
var ms_prevS:uint;
var fps:uint;
var timer_c:uint;
var repeatControll:Boolean = true;
var fr:int=(1000/(stage.frameRate*0.5));
function update(e : Event):void
{
timer_c = getTimer();
if (repeatControll)
{
var num:int = repeat * (fr / (timer_c - ms_prev));
if (num>1000)
{
repeat = repeat - (repeat - num) * 0.1;
}
else
{
repeat = 1000;
}
repeatControll = false;
}
else
{
repeatControll = true;
}
if ( timer_c - 1000 > ms_prevS )
{
ms_prevS = timer_c;
fpstx.text = "FPS: " + fps + " / " + stage.frameRate + " X repeat " + repeat;
fps = 0;
}
fps++;
ms_prev = timer_c;
}
Nonce is just a counter that increases. It doesn't matter where it starts, it just has to be higher than your last one. It is recommended to use time in milliseconds since epoc usually.