Bitcoin Forum
December 18, 2017, 09:12:01 PM *
News: Latest stable version of Bitcoin Core: 0.15.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: How to access the calculated difficulty in the code?  (Read 525 times)
nerioseole
Hero Member
*****
Offline Offline

Activity: 651


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?

1513631521
Hero Member
*
Offline Offline

Posts: 1513631521

View Profile Personal Message (Offline)

Ignore
1513631521
Reply with quote  #2

1513631521
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1513631521
Hero Member
*
Offline Offline

Posts: 1513631521

View Profile Personal Message (Offline)

Ignore
1513631521
Reply with quote  #2

1513631521
Report to moderator
nerioseole
Hero Member
*****
Offline Offline

Activity: 651


View Profile
February 21, 2014, 09:08:00 PM
 #2

bump
-ck
Staff
Legendary
*
Offline Offline

Activity: 2366


Ruu \o/


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

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

Primary developer/maintainer for cgminer and ckpool/ckproxy.
ZERO FEE Pooled mining at ckpool.org 1% Fee Solo mining at solo.ckpool.org
-ck
nerioseole
Hero Member
*****
Offline Offline

Activity: 651


View Profile
February 22, 2014, 09:36:16 PM
 #4

Thanks a lot!

It allowed me to find a similar code in "rpcblockchain.cpp"

Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!