Bitcoin Forum
May 13, 2024, 09:39:21 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?

1715636361
Hero Member
*
Offline Offline

Posts: 1715636361

View Profile Personal Message (Offline)

Ignore
1715636361
Reply with quote  #2

1715636361
Report to moderator
1715636361
Hero Member
*
Offline Offline

Posts: 1715636361

View Profile Personal Message (Offline)

Ignore
1715636361
Reply with quote  #2

1715636361
Report to moderator
"Bitcoin: mining our own business since 2009" -- Pieter Wuille
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715636361
Hero Member
*
Offline Offline

Posts: 1715636361

View Profile Personal Message (Offline)

Ignore
1715636361
Reply with quote  #2

1715636361
Report to moderator
-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!