Bitcoin Forum
May 14, 2024, 04:36:53 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How to access the calculated difficulty in the code?  (Read 620 times)
nerioseole (OP)
Newbie
*
Offline Offline

Activity: 17
Merit: 500


View Profile
February 21, 2014, 02:27:34 AM
 #1

I am experimenting with some new functions using the Bitcoin code.

I am in main.cpp and would like to do some arithmetic inside the code, using the value of the calculated Difficulty as one of the parameters (the same real value that shows when we ask  "getdifficulty" with the executable client).

I am sorry to say that I am not very good with C++, so I have a little of difficulty resolving the correct syntax. 

I came up with something like that to calculate the difficulty:

double dDiff = (double)0x0000ffff / (double)CBlockIndex* blockindex->nBits & 0x00ffffff;

But can't get it to compile.  Obviously my syntax is wrong... and I most likely not declaring some variables somewhere....

How should I write it?

-ck
Legendary
*
Offline Offline

Activity: 4102
Merit: 1633


Ruu \o/


View Profile WWW
February 22, 2014, 03:39:49 AM
 #2

Check out how I do it in cgminer with the set_blockdiff function

https://github.com/ckolivas/cgminer/blob/master/cgminer.c#L4302

ddiff is the calculated diff as a double

Developer/maintainer for cgminer, ckpool/ckproxy, and the -ck kernel
2% Fee Solo mining at solo.ckpool.org
-ck
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!